/[irc-logger]/trunk/bin/irc-logger.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/bin/irc-logger.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 59 by dpavlin, Sat Apr 7 22:57:08 2007 UTC revision 84 by dpavlin, Thu Mar 6 18:03:05 2008 UTC
# Line 22  Import log from C<dircproxy> to C<irc-lo Line 22  Import log from C<dircproxy> to C<irc-lo
22    
23  Name of log file  Name of log file
24    
25    =item --follow=file.log
26    
27    Follows new messages in file
28    
29  =back  =back
30    
31  =head1 DESCRIPTION  =head1 DESCRIPTION
# Line 32  log all conversation on irc channel Line 36  log all conversation on irc channel
36    
37  ## CONFIG  ## CONFIG
38    
39  my $HOSTNAME = `hostname`;  my $HOSTNAME = `hostname -f`;
40    chomp($HOSTNAME);
41    
42  my $NICK = 'irc-logger';  my $NICK = 'irc-logger';
43  $NICK .= '-dev' if ($HOSTNAME =~ m/llin/);  $NICK .= '-dev' if ($HOSTNAME =~ m/llin/);
# Line 45  my $CHANNEL = '#razmjenavjestina'; Line 50  my $CHANNEL = '#razmjenavjestina';
50  $CHANNEL = '#irc-logger' if ($HOSTNAME =~ m/llin/);  $CHANNEL = '#irc-logger' if ($HOSTNAME =~ m/llin/);
51  my $IRC_ALIAS = "log";  my $IRC_ALIAS = "log";
52    
53  my %FOLLOWS =  # default log to follow and announce messages
54    (  my $follows_path = 'follows.log';
    ACCESS => "/var/log/apache/access.log",  
    ERROR => "/var/log/apache/error.log",  
   );  
55    
56  my $DSN = 'DBI:Pg:dbname=' . $NICK;  my $DSN = 'DBI:Pg:dbname=' . $NICK;
57    
# Line 58  my $TIMESTAMP = '%Y-%m-%d %H:%M:%S'; Line 60  my $TIMESTAMP = '%Y-%m-%d %H:%M:%S';
60    
61  my $sleep_on_error = 5;  my $sleep_on_error = 5;
62    
63    # number of last tags to keep in circular buffer
64    my $last_x_tags = 50;
65    
66    my $http_port = $NICK =~ m/-dev/ ? 8001 : 8000;
67    
68    my $url = "http://$HOSTNAME:$http_port";
69    
70  ## END CONFIG  ## END CONFIG
71    
72    
# Line 73  use POSIX qw/strftime/; Line 82  use POSIX qw/strftime/;
82  use HTML::CalendarMonthSimple;  use HTML::CalendarMonthSimple;
83  use Getopt::Long;  use Getopt::Long;
84  use DateTime;  use DateTime;
85    use URI::Escape;
86  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
87    use DateTime::Format::ISO8601;
88    use Carp qw/confess/;
89    use XML::Feed;
90    use DateTime::Format::Flexible;
91    
92  my $use_twitter = 1;  my $use_twitter = 1;
93  eval { require Net::Twitter; };  eval { require Net::Twitter; };
# Line 83  my $import_dircproxy; Line 97  my $import_dircproxy;
97  my $log_path;  my $log_path;
98  GetOptions(  GetOptions(
99          'import-dircproxy:s' => \$import_dircproxy,          'import-dircproxy:s' => \$import_dircproxy,
100            'follows:s' => \$follows_path,
101          'log:s' => \$log_path,          'log:s' => \$log_path,
102  );  );
103    
104    $SIG{__DIE__} = sub {
105            confess "fatal error";
106    };
107    
108  open(STDOUT, '>', $log_path) || warn "can't redirect log to $log_path: $!";  open(STDOUT, '>', $log_path) || warn "can't redirect log to $log_path: $!";
109    
110  sub _log {  sub _log {
111          print strftime($TIMESTAMP,localtime()), ' ', join(" ",@_), $/;          print strftime($TIMESTAMP,localtime()), ' ', join(" ",@_), $/;
112  }  }
113    
114    # LOG following
115    
116    my %FOLLOWS =
117      (
118    #   ACCESS => "/var/log/apache/access.log",
119    #   ERROR => "/var/log/apache/error.log",
120      );
121    
122    sub add_follow_path {
123            my $path = shift;
124            my $name = $path;
125            $name =~ s/\..*$//;
126            warn "# using $path to announce messages from $name\n";
127            $FOLLOWS{$name} = $path;
128    }
129    
130    add_follow_path( $follows_path ) if ( -e $follows_path );
131    
132    # HTML formatters
133    
134    my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');
135    my $escape_re  = join '|' => keys %escape;
136    
137    my $tag_regex = '\b([\w-_]+)//';
138    
139    my %nick_enumerator;
140    my $max_color = 0;
141    
142    my $filter = {
143            message => sub {
144                    my $m = shift || return;
145    
146                    # protect HTML from wiki modifications
147                    sub e {
148                            my $t = shift;
149                            return 'uri_unescape{' . uri_escape($t) . '}';
150                    }
151    
152                    $m =~ s/($escape_re)/$escape{$1}/gs;
153                    $m =~ s#($RE{URI}{HTTP})#e(qq{<a href="$1">$1</a>})#egs ||
154                    $m =~ s#\/(\w+)\/#<i>$1</i>#gs;
155                    $m =~ s#$tag_regex#e(qq{<a href="$url?tag=$1" class="tag">$1</a>})#egs;
156                    $m =~ s#\*(\w+)\*#<b>$1</b>#gs;
157                    $m =~ s#_(\w+)_#<u>$1</u>#gs;
158    
159                    $m =~ s#uri_unescape{([^}]+)}#uri_unescape($1)#egs;
160                    return $m;
161            },
162            nick => sub {
163                    my $n = shift || return;
164                    if (! $nick_enumerator{$n})  {
165                            my $max = scalar keys %nick_enumerator;
166                            $nick_enumerator{$n} = $max + 1;
167                    }
168                    return '<span class="nick col-' .
169                            ( $nick_enumerator{$n} % $max_color ) .
170                            '">' . $n . '</span>';
171            },
172    };
173    
174  my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr;  my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr;
175    
176  my $sql_schema = {  my $sql_schema = {
# Line 191  values (?,?,?,?,?) Line 270  values (?,?,?,?,?)
270    
271    
272  my $tags;  my $tags;
 my $tag_regex = '\b([\w-_]+)//';  
273    
274  =head2 get_from_log  =head2 get_from_log
275    
# Line 228  C<me>, C<nick> and C<message> keys. Line 306  C<me>, C<nick> and C<message> keys.
306  sub get_from_log {  sub get_from_log {
307          my $args = {@_};          my $args = {@_};
308    
309          $args->{fmt} ||= {          if ( ! $args->{fmt} ) {
310                  date => '[%s] ',                  $args->{fmt} = {
311                  time => '{%s} ',                          date => '[%s] ',
312                  time_channel => '{%s %s} ',                          time => '{%s} ',
313                  nick => '%s: ',                          time_channel => '{%s %s} ',
314                  me_nick => '***%s ',                          nick => '%s: ',
315                  message => '%s',                          me_nick => '***%s ',
316          };                          message => '%s',
317                    };
318            }
319    
320          my $sql_message = qq{          my $sql_message = qq{
321                  select                  select
# Line 258  sub get_from_log { Line 338  sub get_from_log {
338    
339          my $sql = $context ? $sql_context : $sql_message;          my $sql = $context ? $sql_context : $sql_message;
340    
341          $sql .= " where message ilike ? or nick ilike ? " if ($args->{search});          sub check_date {
342          $sql .= " where id in (" . join(",", @{ $tags->{ $args->{tag} } }) . ") " if ($args->{tag} && $tags->{ $args->{tag} });                  my $date = shift || return;
343          $sql .= " where date(time) = ? " if ($args->{date});                  my $new_date = eval { DateTime::Format::ISO8601->parse_datetime( $date )->ymd; };
344          $sql .= " order by log.time desc";                  if ( $@ ) {
345          $sql .= " limit " . $args->{limit} if ($args->{limit});                          warn "invalid date $date\n";
346                            $new_date = DateTime->now->ymd;
347                    }
348                    return $new_date;
349            }
350    
351            my @where;
352            my @args;
353    
         my $sth = $dbh->prepare( $sql );  
354          if (my $search = $args->{search}) {          if (my $search = $args->{search}) {
355                  $search =~ s/^\s+//;                  $search =~ s/^\s+//;
356                  $search =~ s/\s+$//;                  $search =~ s/\s+$//;
357                  $sth->execute( ( '%' . $search . '%' ) x 2 );                  push @where, 'message ilike ? or nick ilike ?';
358                  _log "search for '$search' returned ", $sth->rows, " results ", $context || '';                  push @args, ( ( '%' . $search . '%' ) x 2 );
359          } elsif (my $tag = $args->{tag}) {                  _log "search for '$search'";
360                  $sth->execute();          }
361                  _log "tag '$tag' returned ", $sth->rows, " results ", $context || '';  
362          } elsif (my $date = $args->{date}) {          if ($args->{tag} && $tags->{ $args->{tag} }) {
363                  $sth->execute($date);                  push @where, 'id in (' . join(',', @{ $tags->{ $args->{tag} } }) . ')';
364                  _log "found ", $sth->rows, " messages for date $date ", $context || '';                  _log "search for tags $args->{tag}";
         } else {  
                 $sth->execute();  
365          }          }
366    
367            if (my $date = $args->{date} ) {
368                    $date = check_date( $date );
369                    push @where, 'date(time) = ?';
370                    push @args, $date;
371                    _log "search for date $date";
372            }
373    
374            $sql .= " where " . join(" and ", @where) if @where;
375    
376            $sql .= " order by log.time desc";
377            $sql .= " limit " . $args->{limit} if ($args->{limit});
378    
379            #warn "### sql: $sql ", dump( @args );
380    
381            my $sth = $dbh->prepare( $sql );
382            eval { $sth->execute( @args ) };
383            return if $@;
384    
385          my $last_row = {          my $last_row = {
386                  date => '',                  date => '',
387                  time => '',                  time => '',
# Line 399  my $cloud = HTML::TagCloud->new; Line 502  my $cloud = HTML::TagCloud->new;
502    
503  =head2 add_tag  =head2 add_tag
504    
505   add_tag( id => 42, message => 'irc message' );   add_tag( id => 42, message => 'irc message', nick => 'foobar' [, me => 1 ] );
506    
507  =cut  =cut
508    
509    my @last_tags;
510    
511  sub add_tag {  sub add_tag {
512          my $arg = {@_};          my $arg = {@_};
513    
# Line 411  sub add_tag { Line 516  sub add_tag {
516          my $m = $arg->{message};          my $m = $arg->{message};
517          from_to('UTF-8', 'iso-8859-2', $m) if (is_utf8($m));          from_to('UTF-8', 'iso-8859-2', $m) if (is_utf8($m));
518    
519            my @tags;
520    
521          while ($m =~ s#$tag_regex##s) {          while ($m =~ s#$tag_regex##s) {
522                  my $tag = $1;                  my $tag = $1;
523                  next if (! $tag || $tag =~ m/https?:/i);                  next if (! $tag || $tag =~ m/https?:/i);
524                  push @{ $tags->{$tag} }, $arg->{id};                  push @{ $tags->{$tag} }, $arg->{id};
525                  #warn "+tag $tag: $arg->{id}\n";                  #warn "+tag $tag: $arg->{id}\n";
526                  $cloud->add($tag, "?tag=$tag", scalar @{$tags->{$tag}} + 1);                  $cloud->add($tag, "$url?tag=$tag", scalar @{$tags->{$tag}} + 1);
527                    push @tags, $tag;
528    
529          }          }
530    
531            if ( @tags ) {
532                    pop @last_tags if $#last_tags == $last_x_tags;
533                    unshift @last_tags, { tags => [ @tags ], %$arg };
534            }
535    
536  }  }
537    
538  =head2 seed_tags  =head2 seed_tags
# Line 427  Read all tags from database and create i Line 542  Read all tags from database and create i
542  =cut  =cut
543    
544  sub seed_tags {  sub seed_tags {
545          my $sth = $dbh->prepare(qq{ select id,message from log where message like '%//%' });          my $sth = $dbh->prepare(qq{ select id,message,nick,me,time from log where message like '%//%' order by time asc });
546          $sth->execute;          $sth->execute;
547          while (my $row = $sth->fetchrow_hashref) {          while (my $row = $sth->fetchrow_hashref) {
548                  add_tag( %$row );                  add_tag( %$row );
549          }          }
550    
551          foreach my $tag (keys %$tags) {          foreach my $tag (keys %$tags) {
552                  $cloud->add($tag, "?tag=$tag", scalar @{$tags->{$tag}} + 1);                  $cloud->add($tag, "$url?tag=$tag", scalar @{$tags->{$tag}} + 1);
553          }          }
554  }  }
555    
# Line 447  seed_tags; Line 562  seed_tags;
562          channel => '#foobar',          channel => '#foobar',
563          me => 0,          me => 0,
564          nick => 'dpavlin',          nick => 'dpavlin',
565          msg => 'test message',          message => 'test message',
566          time => '2006-06-25 18:57:18',          time => '2006-06-25 18:57:18',
567    );    );
568    
# Line 459  C<me> if not specified will be C<0> (not Line 574  C<me> if not specified will be C<0> (not
574    
575  sub save_message {  sub save_message {
576          my $a = {@_};          my $a = {@_};
577            confess "have msg" if $a->{msg};
578          $a->{me} ||= 0;          $a->{me} ||= 0;
579          $a->{time} ||= strftime($TIMESTAMP,localtime());          $a->{time} ||= strftime($TIMESTAMP,localtime());
580    
581          _log          _log
582                  $a->{channel}, " ",                  $a->{channel}, " ",
583                  $a->{me} ? "***" . $a->{nick} : "<" . $a->{nick} . ">",                  $a->{me} ? "***" . $a->{nick} : "<" . $a->{nick} . ">",
584                  " " . $a->{msg};                  " " . $a->{message};
585    
586          from_to($a->{msg}, 'UTF-8', $ENCODING);          from_to($a->{message}, 'UTF-8', $ENCODING);
587    
588          $sth->execute($a->{channel}, $a->{me}, $a->{nick}, $a->{msg}, $a->{time});          $sth->execute($a->{channel}, $a->{me}, $a->{nick}, $a->{message}, $a->{time});
589          add_tag( id => $dbh->last_insert_id(undef,undef,"log",undef),          add_tag( id => $dbh->last_insert_id(undef,undef,"log",undef), %$a );
                 message => $a->{msg});  
590  }  }
591    
592    
593  if ($import_dircproxy) {  if ($import_dircproxy) {
594          open(my $l, $import_dircproxy) || die "can't open $import_dircproxy: $!";          open(my $l, $import_dircproxy) || die "can't open $import_dircproxy: $!";
595          warn "importing $import_dircproxy...\n";          warn "importing $import_dircproxy...\n";
596          my $tz_offset = 2 * 60 * 60;    # TZ GMT+2          my $tz_offset = 1 * 60 * 60;    # TZ GMT+2
597          while(<$l>) {          while(<$l>) {
598                  chomp;                  chomp;
599                  if (/^@(\d+)\s(\S+)\s(.+)$/) {                  if (/^@(\d+)\s(\S+)\s(.+)$/) {
# Line 496  if ($import_dircproxy) { Line 611  if ($import_dircproxy) {
611                                  channel => $CHANNEL,                                  channel => $CHANNEL,
612                                  me => $me,                                  me => $me,
613                                  nick => $nick,                                  nick => $nick,
614                                  msg => $msg,                                  message => $msg,
615                                  time => $dt->ymd . " " . $dt->hms,                                  time => $dt->ymd . " " . $dt->hms,
616                          ) if ($nick !~ m/^-/);                          ) if ($nick !~ m/^-/);
617    
# Line 529  POE::Session->create( inline_states => Line 644  POE::Session->create( inline_states =>
644                  $_[KERNEL]->post($IRC_ALIAS => join => $CHANNEL);                  $_[KERNEL]->post($IRC_ALIAS => join => $CHANNEL);
645                  $_[KERNEL]->post($IRC_ALIAS => join => '#logger');                  $_[KERNEL]->post($IRC_ALIAS => join => '#logger');
646                  $_[KERNEL]->yield("heartbeat"); # start heartbeat                  $_[KERNEL]->yield("heartbeat"); # start heartbeat
647  #               $_[KERNEL]->yield("my_add", $_) for keys %FOLLOWS;                  $_[KERNEL]->yield("my_add", $_) for keys %FOLLOWS;
648                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" );                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" );
649      },      },
650      irc_public => sub {      irc_public => sub {
# Line 538  POE::Session->create( inline_states => Line 653  POE::Session->create( inline_states =>
653                  my $channel = $_[ARG1]->[0];                  my $channel = $_[ARG1]->[0];
654                  my $msg = $_[ARG2];                  my $msg = $_[ARG2];
655    
656                  save_message( channel => $channel, me => 0, nick => $nick, msg => $msg);                  save_message( channel => $channel, me => 0, nick => $nick, message => $msg);
657                  meta( $nick, $channel, 'last-msg', $msg );                  meta( $nick, $channel, 'last-msg', $msg );
658      },      },
659      irc_ctcp_action => sub {      irc_ctcp_action => sub {
# Line 547  POE::Session->create( inline_states => Line 662  POE::Session->create( inline_states =>
662                  my $channel = $_[ARG1]->[0];                  my $channel = $_[ARG1]->[0];
663                  my $msg = $_[ARG2];                  my $msg = $_[ARG2];
664    
665                  save_message( channel => $channel, me => 1, nick => $nick, msg => $msg);                  save_message( channel => $channel, me => 1, nick => $nick, message => $msg);
666    
667                  if ( $use_twitter ) {                  if ( $use_twitter ) {
668                          if ( my $twitter = meta( $nick, $NICK, 'twitter' ) ) {                          if ( my $twitter = meta( $nick, $NICK, 'twitter' ) ) {
# Line 560  POE::Session->create( inline_states => Line 675  POE::Session->create( inline_states =>
675    
676      },      },
677          irc_ping => sub {          irc_ping => sub {
678                  warn "pong ", $_[ARG0], $/;                  _log( "pong ", $_[ARG0] );
679                  $ping->{ $_[ARG0] }++;                  $ping->{ $_[ARG0] }++;
680          },          },
681          irc_invite => sub {          irc_invite => sub {
# Line 766  POE::Session->create( inline_states => Line 881  POE::Session->create( inline_states =>
881                       Filename => $FOLLOWS{$trailing},                       Filename => $FOLLOWS{$trailing},
882                       InputEvent => 'got_line',                       InputEvent => 'got_line',
883                      );                      );
884                                    warn "+++ following $trailing at $FOLLOWS{$trailing}\n";
885              },              },
886              got_line => sub {              got_line => sub {
887                $_[KERNEL]->post($session => my_tailed =>                                  warn "+++ $trailing : $_[ARG0]\n";
888                                 time, $trailing, $_[ARG0]);                                  $_[KERNEL]->post($session => my_tailed => time, $trailing, $_[ARG0]);
889              },              },
890             },             },
891            );            );
# Line 820  POE::Session->create( inline_states => Line 936  POE::Session->create( inline_states =>
936  # http server  # http server
937    
938  my $httpd = POE::Component::Server::HTTP->new(  my $httpd = POE::Component::Server::HTTP->new(
939          Port => $NICK =~ m/-dev/ ? 8001 : 8000,          Port => $http_port,
940            PreHandler => {
941                    '/' => sub {
942                            $_[0]->header(Connection => 'close')
943                    }
944            },
945          ContentHandler => { '/' => \&root_handler },          ContentHandler => { '/' => \&root_handler },
946          Headers        => { Server => 'irc-logger' },          Headers        => { Server => 'irc-logger' },
947  );  );
948    
 my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');  
 my $escape_re  = join '|' => keys %escape;  
   
949  my $style = <<'_END_OF_STYLE_';  my $style = <<'_END_OF_STYLE_';
950  p { margin: 0; padding: 0.1em; }  p { margin: 0; padding: 0.1em; }
951  .time, .channel { color: #808080; font-size: 60%; }  .time, .channel { color: #808080; font-size: 60%; }
# Line 835  p { margin: 0; padding: 0.1em; } Line 953  p { margin: 0; padding: 0.1em; }
953  .nick { color: #000000; font-size: 80%; padding: 2px; font-family: courier, courier new, monospace ; }  .nick { color: #000000; font-size: 80%; padding: 2px; font-family: courier, courier new, monospace ; }
954  .message { color: #000000; font-size: 100%; }  .message { color: #000000; font-size: 100%; }
955  .search { float: right; }  .search { float: right; }
956    a:link.tag, a:visited.tag { border: 1px dashed #ccc; backgound: #ccc; text-decoration: none }
957    a:hover.tag { border: 1px solid #eee }
958    hr { border: 1px dashed #ccc; height: 1px; clear: both; }
959    /*
960  .col-0 { background: #ffff66 }  .col-0 { background: #ffff66 }
961  .col-1 { background: #a0ffff }  .col-1 { background: #a0ffff }
962  .col-2 { background: #99ff99 }  .col-2 { background: #99ff99 }
963  .col-3 { background: #ff9999 }  .col-3 { background: #ff9999 }
964  .col-4 { background: #ff66ff }  .col-4 { background: #ff66ff }
965  a:link.tag, a:visited.tag { border: 1px dashed #ccc; backgound: #ccc; text-decoration: none }  */
966  a:hover.tag { border: 1px solid #eee }  .calendar { border: 1px solid red; width: 100%; }
967  hr { border: 1px dashed #ccc; height: 1px; clear: both; }  .month { border: 0px; width: 100%; }
968  _END_OF_STYLE_  _END_OF_STYLE_
969    
970  my $max_color = 4;  $max_color = 0;
971    
972  my %nick_enumerator;  my @cols = qw(
973            #ffcccc #ccffe6 #ccccff #e6ccff #ffccff #ffcce6 #ff9999 #ffcc99 #ffff99
974            #ccff99 #99ff99 #99ffcc #99ccff #9999ff #cc99ff #ff6666 #ffb366 #ffff66
975            #66ff66 #66ffb3 #66b3ff #6666ff #ff3333 #33ff33 #3399ff #3333ff #ff3399
976            #a0a0a0 #ff0000 #ffff00 #80ff00 #0000ff #8000ff #ff00ff #ff0080 #994d00
977            #999900 #009900 #cc0066 #c0c0c0 #ccff99 #99ff33 #808080 #660033 #ffffff
978    );
979    
980    foreach my $c (@cols) {
981            $style .= ".col-${max_color} { background: $c }\n";
982            $max_color++;
983    }
984    warn "defined $max_color colors for users...\n";
985    
986  sub root_handler {  sub root_handler {
987          my ($request, $response) = @_;          my ($request, $response) = @_;
988          $response->code(RC_OK);          $response->code(RC_OK);
989          $response->content_type("text/html; charset=$ENCODING");  
990            # this doesn't seem to work, so moved to PreHandler
991            #$response->header(Connection => 'close');
992    
993            return RC_OK if $request->uri =~ m/favicon.ico$/;
994    
995          my $q;          my $q;
996    
# Line 866  sub root_handler { Line 1004  sub root_handler {
1004    
1005          my $search = $q->param('search') || $q->param('grep') || '';          my $search = $q->param('search') || $q->param('grep') || '';
1006    
1007            if ($request->url =~ m#/rss(?:/(tags|last-tag)\w*(?:=(\d+))?)?#i) {
1008                    my $show = lc($1);
1009                    my $nr = $2;
1010    
1011                    my $type = 'RSS';       # Atom
1012    
1013                    $response->content_type( 'application/' . lc($type) . '+xml' );
1014    
1015                    my $html = '<!-- error -->';
1016                    #warn "create $type feed from ",dump( @last_tags );
1017    
1018                    my $feed = XML::Feed->new( $type );
1019    
1020                    if ( $show eq 'tags' ) {
1021                            $nr ||= 50;
1022                            $feed->title( "tags from $CHANNEL" );
1023                            $feed->link( "$url/tags" );
1024                            $feed->description( "tag cloud created from messages on channel $CHANNEL which have tags// in them" );
1025                            my $feed_entry = XML::Feed::Entry->new($type);
1026                            $feed_entry->title( "$nr tags from $CHANNEL" );
1027                            $feed_entry->author( $NICK );
1028                            $feed_entry->link( '/#tags'  );
1029    
1030                            $feed_entry->content(
1031                                    qq{<![CDATA[<style type="text/css">}
1032                                    . $cloud->css
1033                                    . qq{</style>}
1034                                    . $cloud->html( $nr )
1035                                    . qq{]]>}
1036                            );
1037                            $feed->add_entry( $feed_entry );
1038    
1039                    } elsif ( $show eq 'last-tag' ) {
1040    
1041                            $nr ||= $last_x_tags;
1042                            $nr = $last_x_tags if $nr > $last_x_tags;
1043    
1044                            $feed->title( "last $nr tagged messages from $CHANNEL" );
1045                            $feed->link( $url );
1046                            $feed->description( "collects messages which have tags// in them" );
1047    
1048                            foreach my $m ( @last_tags ) {
1049    #                               warn dump( $m );
1050                                    #my $tags = join(' ', @{$m->{tags}} );
1051                                    my $feed_entry = XML::Feed::Entry->new($type);
1052                                    $feed_entry->title( $m->{nick} . '@' . $m->{time} );
1053                                    $feed_entry->author( $m->{nick} );
1054                                    $feed_entry->link( '/#' . $m->{id}  );
1055                                    $feed_entry->issued( DateTime::Format::Flexible->build( $m->{time} ) );
1056    
1057                                    my $message = $filter->{message}->( $m->{message} );
1058                                    $message .= "<br/>\n" unless $message =~ m!<(/p|br/?)>!;
1059    #                               warn "## message = $message\n";
1060                                    from_to( $message, $ENCODING, 'UTF-8' );
1061    
1062                                    #$feed_entry->summary(
1063                                    $feed_entry->content(
1064                                            "<![CDATA[$message]]>"
1065                                    );
1066                                    $feed_entry->category( join(', ', @{$m->{tags}}) );
1067                                    $feed->add_entry( $feed_entry );
1068    
1069                                    $nr--;
1070                                    last if $nr <= 0;
1071    
1072                            }
1073    
1074                    } else {
1075                            warn "!! unknown rss request for $show\n";
1076                            return RC_DENY;
1077                    }
1078    
1079                    $response->content( $feed->as_xml );
1080                    return RC_OK;
1081            }
1082    
1083            if ( $@ ) {
1084                    warn "$@";
1085            }
1086    
1087            $response->content_type("text/html; charset=$ENCODING");
1088    
1089          my $html =          my $html =
1090                  qq{<html><head><title>$NICK</title><style type="text/css">$style} .                  qq{<html><head><title>$NICK</title><style type="text/css">$style}
1091                  $cloud->css .                  . $cloud->css
1092                  qq{</style></head><body>} .                  . qq{</style></head><body>}
1093                  qq{                  . qq{
1094                  <form method="post" class="search" action="/">                  <form method="post" class="search" action="/">
1095                  <input type="text" name="search" value="$search" size="10">                  <input type="text" name="search" value="$search" size="10">
1096                  <input type="submit" value="search">                  <input type="submit" value="search">
1097                  </form>                  </form>
1098                  } .                  }
1099                  $cloud->html(500) .                  . $cloud->html(500)
1100                  qq{<p>};                  . qq{<p>};
1101          if ($request->url =~ m#/history#) {  
1102            if ($request->url =~ m#/tags?#) {
1103                    # nop
1104            } elsif ($request->url =~ m#/history#) {
1105                  my $sth = $dbh->prepare(qq{                  my $sth = $dbh->prepare(qq{
1106                          select date(time) as date,count(*) as nr                          select date(time) as date,count(*) as nr,sum(length(message)) as len
1107                                  from log                                  from log
1108                                  group by date(time)                                  group by date(time)
1109                                  order by date(time) desc                                  order by date(time) desc
1110                  });                  });
1111                  $sth->execute();                  $sth->execute();
1112                  my ($l_yyyy,$l_mm) = (0,0);                  my ($l_yyyy,$l_mm) = (0,0);
1113                    $html .= qq{<table class="calendar"><tr>};
1114                  my $cal;                  my $cal;
1115                    my $ord = 0;
1116                  while (my $row = $sth->fetchrow_hashref) {                  while (my $row = $sth->fetchrow_hashref) {
1117                          # this is probably PostgreSQL specific, expects ISO date                          # this is probably PostgreSQL specific, expects ISO date
1118                          my ($yyyy,$mm,$dd) = split(/-/, $row->{date});                          my ($yyyy,$mm,$dd) = split(/-/, $row->{date});
1119                          if ($yyyy != $l_yyyy || $mm != $l_mm) {                          if ($yyyy != $l_yyyy || $mm != $l_mm) {
1120                                  $html .= $cal->as_HTML() if ($cal);                                  if ( $cal ) {
1121                                            $html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td>};
1122                                            $ord++;
1123                                            $html .= qq{</tr><tr>} if ( $ord % 3 == 0 );
1124                                    }
1125                                  $cal = new HTML::CalendarMonthSimple('month'=>$mm,'year'=>$yyyy);                                  $cal = new HTML::CalendarMonthSimple('month'=>$mm,'year'=>$yyyy);
1126                                  $cal->border(2);                                  $cal->border(1);
1127                                    $cal->width('30%');
1128                                    $cal->cellheight('5em');
1129                                    $cal->tableclass('month');
1130                                    #$cal->cellclass('day');
1131                                    $cal->sunday('SUN');
1132                                    $cal->saturday('SAT');
1133                                    $cal->weekdays('MON','TUE','WED','THU','FRI');
1134                                  ($l_yyyy,$l_mm) = ($yyyy,$mm);                                  ($l_yyyy,$l_mm) = ($yyyy,$mm);
1135                          }                          }
1136                          $cal->setcontent($dd, qq{                          $cal->setcontent($dd, qq[
1137                                  <a href="/?date=$row->{date}">$row->{nr}</a>                                  <a href="$url?date=$row->{date}">$row->{nr}</a><br/>$row->{len}
1138                          });                          ]);
1139                            
1140                  }                  }
1141                  $html .= $cal->as_HTML() if ($cal);                  $html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td></tr></table>};
1142    
1143          } else {          } else {
1144                  $html .= join("</p><p>",                  $html .= join("</p><p>",
1145                          get_from_log(                          get_from_log(
1146                                  limit => $q->param('last') || $q->param('date') ? undef : 100,                                  limit => ( $q->param('last') || $q->param('date') ) ? undef : 100,
1147                                  search => $search || undef,                                  search => $search || undef,
1148                                  tag => $q->param('tag') || undef,                                  tag => $q->param('tag') || undef,
1149                                  date => $q->param('date') || undef,                                  date => $q->param('date') || undef,
1150                                  fmt => {                                  fmt => {
1151                                          date => sub {                                          date => sub {
1152                                                  my $date = shift || return;                                                  my $date = shift || return;
1153                                                  qq{<hr/><div class="date"><a href="/?date=$date">$date</a></div>};                                                  qq{<hr/><div class="date"><a href="$url?date=$date">$date</a></div>};
1154                                          },                                          },
1155                                          time => '<span class="time">%s</span> ',                                          time => '<span class="time">%s</span> ',
1156                                          time_channel => '<span class="channel">%s %s</span> ',                                          time_channel => '<span class="channel">%s %s</span> ',
# Line 921  sub root_handler { Line 1158  sub root_handler {
1158                                          me_nick => '***%s&nbsp;',                                          me_nick => '***%s&nbsp;',
1159                                          message => '<span class="message">%s</span>',                                          message => '<span class="message">%s</span>',
1160                                  },                                  },
1161                                  filter => {                                  filter => $filter,
                                         message => sub {  
                                                 my $m = shift || return;  
                                                 $m =~ s/($escape_re)/$escape{$1}/gs;  
                                                 $m =~ s#($RE{URI}{HTTP})#<a href="$1">$1</a>#gs;  
                                                 $m =~ s#$tag_regex#<a href="?tag=$1" class="tag">$1</a>#g;  
                                                 $m =~ s#\*(\w+)\*#<b>$1</b>#gs;  
                                                 $m =~ s#_(\w+)_#<u>$1</u>#gs;  
                                                 $m =~ s#\/(\w+)\/#<i>$1</i>#gs;  
                                                 return $m;  
                                         },  
                                         nick => sub {  
                                                 my $n = shift || return;  
                                                 if (! $nick_enumerator{$n})  {  
                                                         my $max = scalar keys %nick_enumerator;  
                                                         $nick_enumerator{$n} = $max + 1;  
                                                 }  
                                                 return '<span class="nick col-' .  
                                                         ( $nick_enumerator{$n} % $max_color ) .  
                                                         '">' . $n . '</span>';  
                                         },  
                                 },  
1162                          )                          )
1163                  );                  );
1164          }          }
# Line 953  sub root_handler { Line 1169  sub root_handler {
1169          </body></html>};          </body></html>};
1170    
1171          $response->content( $html );          $response->content( $html );
1172            warn "<< ", $request->method, " ", $request->uri, " created ", length($html), " bytes\n";
1173          return RC_OK;          return RC_OK;
1174  }  }
1175    

Legend:
Removed from v.59  
changed lines
  Added in v.84

  ViewVC Help
Powered by ViewVC 1.1.26