summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/DB/Discussions.pm21
-rw-r--r--lib/VNDB/Handler/Discussions.pm119
-rw-r--r--lib/VNDB/Util/FormHTML.pm3
3 files changed, 130 insertions, 13 deletions
diff --git a/lib/VNDB/DB/Discussions.pm b/lib/VNDB/DB/Discussions.pm
index 574560a0..723170e2 100644
--- a/lib/VNDB/DB/Discussions.pm
+++ b/lib/VNDB/DB/Discussions.pm
@@ -8,7 +8,7 @@ use Exporter 'import';
our @EXPORT = qw|dbThreadGet dbThreadEdit dbThreadAdd dbPostGet dbPostEdit dbPostAdd dbThreadCount|;
-# Options: id, type, iid, results, page, what, notusers, sort, reverse
+# Options: id, type, iid, results, page, what, notusers, search, sort, reverse
# What: boards, boardtitles, firstpost, lastpost
# Sort: id lastpost
sub dbThreadGet {
@@ -17,19 +17,26 @@ sub dbThreadGet {
$o{page} ||= 1;
$o{what} ||= '';
- my %where = (
+ my @where = (
$o{id} ? (
't.id = ?' => $o{id} ) : (),
!$o{id} ? (
't.hidden = FALSE' => 0 ) : (),
$o{type} && !$o{iid} ? (
- 't.id IN(SELECT tid FROM threads_boards WHERE type = ?)' => $o{type} ) : (),
+ 't.id IN(SELECT tid FROM threads_boards WHERE type IN(!l))' => [ ref $o{type} ? $o{type} : [ $o{type} ] ] ) : (),
$o{type} && $o{iid} ? (
'tb.type = ?' => $o{type}, 'tb.iid = ?' => $o{iid} ) : (),
$o{notusers} ? (
't.id NOT IN(SELECT tid FROM threads_boards WHERE type = \'u\')' => 1) : (),
);
+ if($o{search}) {
+ for (split /[ -,._]/, $o{search}) {
+ s/%//g;
+ push @where, 't.title ilike ?', "%$_%" if length($_) > 0;
+ }
+ }
+
my @select = (
qw|t.id t.title t.count t.locked t.hidden|,
$o{what} =~ /firstpost/ ? ('tpf.uid AS fuid', q|EXTRACT('epoch' from tpf.date) AS fdate|, 'uf.username AS fusername') : (),
@@ -60,7 +67,7 @@ sub dbThreadGet {
!s
!W
ORDER BY !s|,
- join(', ', @select), join(' ', @join), \%where, $order
+ join(', ', @select), join(' ', @join), \@where, $order
);
if($o{what} =~ /(boards|boardtitles)/ && $#$r >= 0) {
@@ -158,7 +165,7 @@ sub dbThreadCount {
}
-# Options: tid, num, what, uid, mindate, hide, page, results, sort, reverse
+# Options: tid, num, what, uid, mindate, hide, search, type, page, results, sort, reverse
# what: user thread
sub dbPostGet {
my($self, %o) = @_;
@@ -179,6 +186,10 @@ sub dbPostGet {
'tp.hidden = FALSE' => 1 ) : (),
$o{hide} && $o{what} =~ /thread/ ? (
't.hidden = FALSE' => 1 ) : (),
+ $o{search} ? (
+ q{to_tsvector('english', strip_bb_tags(msg)) @@ to_tsquery(?)} => $o{search}) : (),
+ $o{type} ? (
+ 'tp.tid = ANY(ARRAY(SELECT tid FROM threads_boards WHERE type IN(!l)))' => [ ref $o{type} ? $o{type} : [ $o{type} ] ] ) : (),
);
my @select = (
diff --git a/lib/VNDB/Handler/Discussions.pm b/lib/VNDB/Handler/Discussions.pm
index 755d14c9..d416d26b 100644
--- a/lib/VNDB/Handler/Discussions.pm
+++ b/lib/VNDB/Handler/Discussions.pm
@@ -3,7 +3,7 @@ package VNDB::Handler::Discussions;
use strict;
use warnings;
-use TUWF ':html', 'xml_escape';
+use TUWF ':html', 'xml_escape', 'uri_escape';
use POSIX 'ceil';
use VNDB::Func;
@@ -15,6 +15,7 @@ TUWF::register(
qr{t([1-9]\d*)/reply} => \&edit,
qr{t([1-9]\d*)\.([1-9]\d*)/edit} => \&edit,
qr{t/(db|an|ge|[vpu])([1-9]\d*)?/new} => \&edit,
+ qr{t/search} => \&search,
qr{t} => \&index,
);
@@ -341,12 +342,18 @@ sub index {
my $self = shift;
$self->htmlHeader(title => mt('_disindex_title'), noindex => 1, feeds => [ 'posts', 'announcements' ]);
- div class => 'mainbox';
- h1 mt '_disindex_title';
- p class => 'browseopts';
- a href => '/t/all', mt '_disboard_item_all';
- a href => '/t/'.$_, mt "_dboard_$_"
- for (@{$self->{discussion_boards}});
+ form action => '/t/search', method => 'get';
+ div class => 'mainbox';
+ h1 mt '_disindex_title';
+ fieldset class => 'search';
+ input type => 'text', name => 'bq', id => 'bq', class => 'text';
+ input type => 'submit', class => 'submit', value => mt '_searchbox_submit';
+ end 'fieldset';
+ p class => 'browseopts';
+ a href => '/t/all', mt '_disboard_item_all';
+ a href => '/t/'.$_, mt "_dboard_$_"
+ for (@{$self->{discussion_boards}});
+ end;
end;
end;
@@ -368,6 +375,104 @@ sub index {
}
+sub search {
+ my $self = shift;
+
+ my $frm = $self->formValidate(
+ { get => 'bq', required => 0, maxlength => 100 },
+ { get => 'b', required => 0, multi => 1, enum => $self->{discussion_boards} },
+ { get => 't', required => 0 },
+ { get => 'p', required => 0, default => 1, template => 'int' },
+ );
+ return $self->resNotFound if $frm->{_err};
+
+ $self->htmlHeader(title => mt('_dissearch_title'), noindex => 1);
+ $self->htmlForm({ frm => $frm, action => '/t/search', method => 'get', nosubmit => 1 }, 'boardsearch' => [mt('_dissearch_title'),
+ [ input => short => 'bq', name => mt('_dissearch_query') ],
+ [ check => short => 't', name => mt('_dissearch_titleonly') ],
+ [ select => short => 'b', name => mt('_dissearch_boards'), multi => 1, size => scalar @{$self->{discussion_boards}},
+ options => [ map [$_,mt("_dboard_$_")], @{$self->{discussion_boards}} ] ],
+ [ static => content => sub {
+ input type => 'submit', class => 'submit', tabindex => 10, value => mt '_searchbox_submit';
+ } ],
+ ]);
+ return $self->htmlFooter if !$frm->{bq};
+
+ my %boards = map +($_,1), @{$frm->{b}};
+ %boards = () if keys %boards == @{$self->{discussion_boards}};
+
+ my($l, $np);
+ if($frm->{t}) {
+ ($l, $np) = $self->dbThreadGet(
+ keys %boards ? ( type => [keys %boards] ) : (),
+ search => $frm->{bq},
+ results => 50,
+ page => $frm->{p},
+ what => 'firstpost lastpost boardtitles',
+ sort => 'lastpost', reverse => 1,
+ );
+ } else {
+ # TODO: Allow or-matching too. But what syntax?
+ (my $ts = $frm->{bq}) =~ y{+|&:*()="';!?$%^\\[]{}<>~` }{ }s;
+ $ts =~ s/ / & /g;
+ $ts =~ y/-/!/;
+ ($l, $np) = $self->dbPostGet(
+ keys %boards ? ( type => [keys %boards] ) : (),
+ search => $ts,
+ results => 20,
+ page => $frm->{p},
+ hide => 1,
+ what => 'thread user',
+ sort => 'date', reverse => 1,
+ );
+ }
+
+ my $url = '/t/search?'.join ';', 'bq='.uri_escape($frm->{bq}), $frm->{t} ? 't=1' : (), map "b=$_", keys %boards;
+ if(!@$l) {
+ div class => 'mainbox';
+ h1 mt '_dissearch_noresults_title';
+ p mt '_dissearch_noresults_msg';
+ end;
+ } elsif($frm->{t}) {
+ _threadlist($self, $l, $frm, $np, $url, 'all');
+ } else {
+ $self->htmlBrowse(
+ items => $l,
+ options => $frm,
+ nextpage => $np,
+ pageurl => $url,
+ class => 'postsearch',
+ header => [
+ sub { td class => 'tc1_1', ''; td class => 'tc1_2', ''; },
+ [ mt '_dissearch_col_date' ],
+ [ mt '_dissearch_col_user' ],
+ [ mt '_dissearch_col_msg' ],
+ ],
+ row => sub {
+ my($s, $n, $l) = @_;
+ my $link = "/t$l->{tid}.$l->{num}";
+ Tr;
+ td class => 'tc1_1'; a href => $link, 't'.$l->{tid}; end;
+ td class => 'tc1_2'; a href => $link, '.'.$l->{num}; end;
+ td class => 'tc2', $self->{l10n}->date($l->{date});
+ td class => 'tc3'; lit $self->{l10n}->userstr($l->{uid}, $l->{username}); end;
+ td class => 'tc4';
+ div class => 'title';
+ a href => $link, $l->{title};
+ end;
+ # TODO: ts_headline() or something like it.
+ div class => 'thread';
+ lit bb2html($l->{msg}, 300);
+ end;
+ end;
+ end;
+ }
+ );
+ }
+ $self->htmlFooter;
+}
+
+
sub _threadlist {
my($self, $list, $f, $np, $url, $board) = @_;
$self->htmlBrowse(
diff --git a/lib/VNDB/Util/FormHTML.pm b/lib/VNDB/Util/FormHTML.pm
index 4a63a9b7..041d5a14 100644
--- a/lib/VNDB/Util/FormHTML.pm
+++ b/lib/VNDB/Util/FormHTML.pm
@@ -168,6 +168,7 @@ sub htmlFormPart {
# Generates a form, first argument is a hashref with global options, keys:
# frm => the $frm as returned by formValidate,
# action => The location the form should POST to (also used as form id)
+# method => post/get
# upload => 1/0, adds an enctype.
# nosubmit => 1/0, hides the submit button
# editsum => 1/0, adds an edit summary field before the submit button
@@ -178,7 +179,7 @@ sub htmlFormPart {
# automatically calls htmlFormError and adds a 'formcode' field.
sub htmlForm {
my($self, $options, @subs) = @_;
- form action => '/nospam?'.$options->{action}, method => 'post', 'accept-charset' => 'utf-8',
+ form action => '/nospam?'.$options->{action}, method => $options->{method}||'post', 'accept-charset' => 'utf-8',
$options->{upload} ? (enctype => 'multipart/form-data') : ();
div class => 'hidden';