--- trunk/irc-logger.pl 2006/03/13 12:56:26 15 +++ trunk/irc-logger.pl 2006/03/13 16:43:18 16 @@ -18,7 +18,7 @@ ## CONFIG -my $NICK = 'irc-logger'; +my $NICK = 'irc-logger-dev'; my $CONNECT = {Server => 'irc.freenode.net', Nick => $NICK, @@ -46,6 +46,7 @@ use DBI; use Encode qw/from_to/; use Regexp::Common qw /URI/; +use CGI::Simple; my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr; @@ -122,7 +123,8 @@ my $sth = $dbh->prepare( $sql ); if ($args->{search}) { - $sth->execute( $args->{search} ); + warn "search for '$args->{search}' returned ", $sth->rows, " results\n"; + $sth->execute( '%' . $args->{search} . '%' ); } else { $sth->execute(); } @@ -139,7 +141,9 @@ unshift @rows, $row; } - my @msgs; + my @msgs = ( + "Showing " . ($#rows + 1) . " messages..." + ); foreach my $row (@rows) { @@ -265,7 +269,7 @@ my $what = $2; - foreach my $res (get_from_log( limit => 20, search => "%${what}%" )) { + foreach my $res (get_from_log( limit => 20, search => $what )) { print "search [$what]: $res\n"; from_to($res, $ENCODING, 'UTF-8'); $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); @@ -399,21 +403,42 @@ ); my $style = <<'_END_OF_STYLE_'; +p { margin: 0; padding: 0.1em; } .time, .channel { color: #808080; font-size: 60%; } .nick { color: #0000ff; font-size: 80%; } .message { color: #000000; font-size: 100%; } +.search { float: right; } _END_OF_STYLE_ sub root_handler { my ($request, $response) = @_; $response->code(RC_OK); $response->content_type("text/html; charset=$ENCODING"); + + my $q; + + if ( $request->method eq 'POST' ) { + $q = new CGI::Simple( $request->content ); + } elsif ( $request->uri =~ /\?(.+)$/ ) { + $q = new CGI::Simple( $1 ); + } else { + $q = new CGI::Simple; + } + + my $search = $q->param('search') || $q->param('grep') || ''; + $response->content( - qq{$NICK} . - "irc-logger url: " . $request->uri . '
' . - join("
", + qq{$NICK + +

+ } . + join("

", get_from_log( - limit => 100, + limit => $q->param('limit') || 100, + search => $q->param('search') || $q->param('grep') || undef, fmt => { time => '%s ', time_channel => '%s %s ', @@ -427,7 +452,7 @@ }, ) ) . - qq{} + qq{

} ); return RC_OK; }