--- trunk/bin/irc-logger.pl 2008/04/01 19:04:32 132 +++ trunk/bin/irc-logger.pl 2008/06/07 13:10:15 139 @@ -7,7 +7,6 @@ use DBI; use Regexp::Common qw /URI/; use CGI::Simple; -use HTML::TagCloud; use POSIX qw/strftime/; use HTML::CalendarMonthSimple; use Getopt::Long; @@ -128,7 +127,7 @@ my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); my $escape_re = join '|' => keys %escape; -my $tag_regex = '\b([\w-_]+)//'; +my $tag_regex = '\b([\w\-_]+)//'; my %nick_enumerator; my $max_color = 0; @@ -526,62 +525,8 @@ # tags support -my $cloud = HTML::TagCloud->new; - -=head2 add_tag - - add_tag( id => 42, message => 'irc message', nick => 'foobar' [, me => 1 ] ); - -=cut - -my @last_tags; - -sub add_tag { - my $arg = {@_}; - - return unless ($arg->{id} && $arg->{message}); - - my $m = $arg->{message}; - - my @tags; - - while ($m =~ s#$tag_regex##s) { - my $tag = $1; - next if (! $tag || $tag =~ m/https?:/i); - push @{ $tags->{$tag} }, $arg->{id}; - #warn "+tag $tag: $arg->{id}\n"; - $cloud->add($tag, "$url?tag=$tag", scalar @{$tags->{$tag}} + 1); - push @tags, $tag; - - } - - if ( @tags ) { - pop @last_tags if $#last_tags == $last_x_tags; - unshift @last_tags, { tags => [ @tags ], %$arg }; - } - -} - -=head2 seed_tags - -Read all tags from database and create in-memory cache for tags - -=cut - -sub seed_tags { - my $sth = $dbh->prepare(qq{ select id,message,nick,me,time from log where message like '%//%' order by time asc }); - $sth->execute; - while (my $row = $sth->fetchrow_hashref) { - add_tag( %$row ); - } - - foreach my $tag (keys %$tags) { - $cloud->add($tag, "$url?tag=$tag", scalar @{$tags->{$tag}} + 1); - } -} - -seed_tags; - +my $cloud = TagCloud->new; +$cloud->seed_tags; =head2 save_message @@ -612,7 +557,7 @@ eval { $sth_insert_log->execute($a->{channel}, $a->{me}, $a->{nick}, $a->{message}, $a->{time}); }; _log "ERROR: can't archive ", $a->{message} if $@; - add_tag( id => $dbh->last_insert_id(undef,undef,"log",undef), %$a ); + $cloud->add_tag( id => $dbh->last_insert_id(undef,undef,"log",undef), %$a ); } @@ -1241,7 +1186,7 @@ $response->content_type( 'application/' . lc($type) . '+xml' ); my $html = ''; - #warn "create $type feed from ",dump( @last_tags ); + #warn "create $type feed from ",dump( $cloud->last_tags ); my $feed = XML::Feed->new( $type ); $feed->link( $url ); @@ -1275,7 +1220,7 @@ $feed->title( "last $nr tagged messages from $CHANNEL" ); $feed->description( "collects messages which have tags// in them" ); - foreach my $m ( @last_tags ) { + foreach my $m ( $cloud->last_tags ) { # warn dump( $m ); #my $tags = join(' ', @{$m->{tags}} ); my $feed_entry = XML::Feed::Entry->new($type); @@ -1405,7 +1350,7 @@ } else { $html .= join("
", get_from_log( - limit => ( $q->param('last') || $q->param('date') ) ? undef : 100, + limit => ( $q->param('date') ? undef : $q->param('last') || 100 ), search => $search || undef, tag => $q->param('tag') || undef, date => $q->param('date') || undef, @@ -1430,9 +1375,116 @@
See history of all messages.