Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@member.fsf.org>2010-09-12 16:59:11 (GMT)
committer Aleksey Lim <alsroot@member.fsf.org>2010-09-12 16:59:11 (GMT)
commit01c9ccd1dee4c639d68e8447bb11d1b3ecfe4ae1 (patch)
tree7e32b1b5fa37bfad6ead703384b619d040b20c99
parente007ec92c865b8765485007c6264558d22a5994c (diff)
Add searching within all channels
-rwxr-xr-xcgi/search.pl47
-rw-r--r--cgi/template/search.tmpl8
-rw-r--r--lib/IrcLog/WWW.pm1
3 files changed, 34 insertions, 22 deletions
diff --git a/cgi/search.pl b/cgi/search.pl
index 2c2ca8d..c5f235c 100755
--- a/cgi/search.pl
+++ b/cgi/search.pl
@@ -44,9 +44,15 @@ my $dbh = get_dbh();
my @channels;
my $q1 = $dbh->prepare("SELECT DISTINCT channel FROM irclog ORDER BY channel");
$q1->execute();
- my $ch = $q->param('channel') || 'perl6';
- $ch =~ s/^\#//;
- $t->param(CURRENT_CHANNEL => $ch, CHANNEL => $ch);
+ my $ch = $q->param('channel');
+ if ($ch && !($ch eq 'All')) {
+ $ch =~ s/^\#//;
+ $t->param(CURRENT_CHANNEL => ";channel=$ch");
+ push @channels, {CHANNEL => 'All'};
+ } else {
+ $t->param(CURRENT_CHANNEL => '');
+ push @channels, {CHANNEL => 'All', SELECTED => 1};
+ }
while (my @row = $q1->fetchrow_array){
$row[0] =~ s/^\#//;
if ($ch eq $row[0]){
@@ -58,11 +64,6 @@ my $dbh = get_dbh();
# populate the size of the select box with channel names
$t->param(CHANNELS => \@channels);
- if (@channels >= 5 ){
- $t->param(CH_COUNT => 5);
- } else {
- $t->param(CH_COUNT => scalar @channels);
- }
}
my $nick = decode('utf8', $q->param('nick') || '');
@@ -73,18 +74,26 @@ $qs = my_decode($qs);
$t->param(NICK => encode('utf8', $nick));
$t->param(Q => $qs);
-my $short_channel = decode('utf8', $q->param('channel') || 'perl6');
-# guard against old URLs:
-$short_channel =~ s/^#//;
-my $channel = '#' .$short_channel;
+my $channel;
-if (length($nick) or length($qs)){
+my $short_channel = decode('utf8', $q->param('channel'));
+if ($short_channel && !($short_channel eq 'All')) {
+ $short_channel =~ s/^#//;
+ $channel = '#' .$short_channel;
+}
+if (length($nick) or length($qs)){
+ my @sql_conds;
+ my @args;
+ if ($channel) {
+ @sql_conds = ('channel = ? AND NOT spam');
+ @args = ($channel);
+ } else {
+ @sql_conds = ('NOT spam');
+ }
- my @sql_conds = ('channel = ? AND NOT spam');
- my @args = ($channel);
if (length $nick){
push @sql_conds, '(nick = ? OR nick LIKE ?)';
push @args, $nick, "% $nick";
@@ -103,7 +112,7 @@ if (length($nick) or length($qs)){
. "ORDER BY day DESC LIMIT $days_per_page OFFSET $offset");
my $q2 = $dbh->prepare("SELECT id, day FROM irclog "
. $sql_cond . ' AND day = ? ORDER BY id');
- my $q3 = $dbh->prepare('SELECT id, timestamp, nick, line FROM irclog '
+ my $q3 = $dbh->prepare('SELECT id, timestamp, nick, line, channel FROM irclog '
. 'WHERE day = ? AND id >= ? AND id <= ? ORDER BY id ASC');
$q0->execute(@args);
@@ -144,6 +153,9 @@ if (length($nick) or length($qs)){
# retrieve context from database
$q3->execute( $found_day, $lower, $upper );
while (my @r2 = $q3->fetchrow_array){
+ my $short_channel = decode('utf8', $r2[4]);
+ $short_channel =~ s/^#//;
+
my %args = (
id => $r2[0],
nick => decode('utf8', $r2[2]),
@@ -153,7 +165,7 @@ if (length($nick) or length($qs)){
prev_nick => $prev_nick,
colors => \%colors,
link_url => $base_url . "out.pl?channel=$short_channel;date=$row[0]",
- channel => $channel,
+ channel => $short_channel,
date => $found_day,
);
$args{search_found} = 'search_found' if $r2[0] == $found_id;
@@ -165,7 +177,6 @@ if (length($nick) or length($qs)){
}
}
push @days, {
- URL => $base_url . "out.pl?channel=$short_channel;date=$row[0]",
DAY => $row[0],
LINES => \@lines,
};
diff --git a/cgi/template/search.tmpl b/cgi/template/search.tmpl
index 8fe12ed..9afa922 100644
--- a/cgi/template/search.tmpl
+++ b/cgi/template/search.tmpl
@@ -9,7 +9,7 @@
<p><a href="<TMPL_VAR BASE_URL>">Channels</a></p>
<form action="<TMPL_VAR BASE_URL>search.pl" method="get" accept-charset="utf-8">
- <input type="text" size="20" name="q" value="<TMPL_VAR Q>" id="text"/>&nbsp;
+ <input type="text" size="20" name="q" value="<TMPL_VAR Q>" id="text"/>
Nick: <input type="text" size="10" maxlength="30" name="nick" value="<TMPL_VAR NICK>" id="nick"/>
<select id="channel" name="channel">
<TMPL_LOOP CHANNELS>
@@ -24,7 +24,7 @@
<TMPL_IF DAYS>
<p>Result pages:
<TMPL_LOOP RESULT_PAGES>
- <a href="<TMPL_VAR BASE_URL>search.pl?nick=<TMPL_VAR NICK ESCAPE=URL>;channel=<TMPL_VAR CURRENT_CHANNEL ESCAPE=URL>;q=<TMPL_VAR Q>;offset=<TMPL_VAR OFFSET>"><TMPL_VAR PAGE></a>
+ <a href="<TMPL_VAR BASE_URL>search.pl?nick=<TMPL_VAR NICK ESCAPE=URL><TMPL_VAR CURRENT_CHANNEL ESCAPE=URL>;q=<TMPL_VAR Q>;offset=<TMPL_VAR OFFSET>"><TMPL_VAR PAGE></a>
</TMPL_LOOP>
</p>
@@ -32,7 +32,7 @@
DAYS_UPPER>, from overall <TMPL_VAR DAYS_COUNT> days</p>
<TMPL_LOOP DAYS>
- <h2><a href="<TMPL_VAR URL>"><TMPL_VAR DAY></a></h2>
+ <h2><TMPL_VAR DAY></h2>
<table>
<TMPL_LOOP LINES>
<TMPL_INCLUDE line.tmpl>
@@ -41,7 +41,7 @@
</TMPL_LOOP>
<p>Result pages:
<TMPL_LOOP RESULT_PAGES>
- <a href="<TMPL_VAR BASE_URL>search.pl?nick=<TMPL_VAR NAME=NICK ESCAPE=URL>;channel=<TMPL_VAR NAME=CURRENT_CHANNEL ESCAPE=URL>;q=<TMPL_VAR Q>;offset=<TMPL_VAR OFFSET>"><TMPL_VAR PAGE></a>
+ <a href="<TMPL_VAR BASE_URL>search.pl?nick=<TMPL_VAR NAME=NICK ESCAPE=URL><TMPL_VAR NAME=CURRENT_CHANNEL ESCAPE=URL>;q=<TMPL_VAR Q>;offset=<TMPL_VAR OFFSET>"><TMPL_VAR PAGE></a>
</TMPL_LOOP>
</p>
</TMPL_IF>
diff --git a/lib/IrcLog/WWW.pm b/lib/IrcLog/WWW.pm
index 8376571..d37b122 100644
--- a/lib/IrcLog/WWW.pm
+++ b/lib/IrcLog/WWW.pm
@@ -494,6 +494,7 @@ sub message_line {
$args_ref->{nick},
),
LINE_NUMBER => ++$args_ref->{line_number},
+ CHANNEL => $args_ref->{channel},
);
$h{DATE} = $args_ref->{date} if $args_ref->{date};
$h{SEARCH_FOUND} = 'search_found' if ($args_ref->{search_found});