/[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

trunk/irc-logger.pl revision 40 by dpavlin, Tue Oct 24 12:50:41 2006 UTC trunk/bin/irc-logger.pl revision 64 by dpavlin, Fri Jun 8 12:12:45 2007 UTC
# Line 18  irc-logger.pl Line 18  irc-logger.pl
18    
19  Import log from C<dircproxy> to C<irc-logger> database  Import log from C<dircproxy> to C<irc-logger> database
20    
21    =item --log=irc-logger.log
22    
23    Name of log file
24    
25    =back
26    
27  =head1 DESCRIPTION  =head1 DESCRIPTION
28    
29  log all conversation on irc channel  log all conversation on irc channel
# Line 50  my $DSN = 'DBI:Pg:dbname=' . $NICK; Line 56  my $DSN = 'DBI:Pg:dbname=' . $NICK;
56  my $ENCODING = 'ISO-8859-2';  my $ENCODING = 'ISO-8859-2';
57  my $TIMESTAMP = '%Y-%m-%d %H:%M:%S';  my $TIMESTAMP = '%Y-%m-%d %H:%M:%S';
58    
59    my $sleep_on_error = 5;
60    
61  ## END CONFIG  ## END CONFIG
62    
63    
# Line 65  use POSIX qw/strftime/; Line 73  use POSIX qw/strftime/;
73  use HTML::CalendarMonthSimple;  use HTML::CalendarMonthSimple;
74  use Getopt::Long;  use Getopt::Long;
75  use DateTime;  use DateTime;
76    use URI::Escape;
77    use Data::Dump qw/dump/;
78    use DateTime::Format::ISO8601;
79    
80    my $use_twitter = 1;
81    eval { require Net::Twitter; };
82    $use_twitter = 0 if ($@);
83    
84  my $import_dircproxy;  my $import_dircproxy;
85    my $log_path;
86  GetOptions(  GetOptions(
87          'import-dircproxy:s' => \$import_dircproxy,          'import-dircproxy:s' => \$import_dircproxy,
88            'log:s' => \$log_path,
89  );  );
90    
91  my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr;  open(STDOUT, '>', $log_path) || warn "can't redirect log to $log_path: $!";
92    
93  eval {  sub _log {
94          $dbh->do(qq{ select count(*) from log });          print strftime($TIMESTAMP,localtime()), ' ', join(" ",@_), $/;
95  };  }
96    
97  if ($@) {  my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr;
         warn "creating database table in $DSN\n";  
         $dbh->do(<<'_SQL_SCHEMA_');  
98    
99    my $sql_schema = {
100            log => '
101  create table log (  create table log (
102          id serial,          id serial,
103          time timestamp default now(),          time timestamp default now(),
# Line 94  create table log ( Line 111  create table log (
111  create index log_time on log(time);  create index log_time on log(time);
112  create index log_channel on log(channel);  create index log_channel on log(channel);
113  create index log_nick on log(nick);  create index log_nick on log(nick);
114            ',
115            meta => '
116    create table meta (
117            nick text not null,
118            channel text not null,
119            name text not null,
120            value text,
121            changed timestamp default now(),
122            primary key(nick,channel,name)
123    );
124            ',
125    };
126    
127  _SQL_SCHEMA_  foreach my $table ( keys %$sql_schema ) {
128    
129            eval {
130                    $dbh->do(qq{ select count(*) from $table });
131            };
132    
133            if ($@) {
134                    warn "creating database table $table in $DSN\n";
135                    $dbh->do( $sql_schema->{ $table } );
136            }
137  }  }
138    
139    
140    =head2 meta
141    
142    Set or get some meta data into database
143    
144            meta('nick','channel','var_name', $var_value );
145    
146            $var_value = meta('nick','channel','var_name');
147            ( $var_value, $changed ) = meta('nick','channel','var_name');
148    
149    =cut
150    
151    sub meta {
152            my ($nick,$channel,$name,$value) = @_;
153    
154            # normalize channel name
155            $channel =~ s/^#//;
156    
157            if (defined($value)) {
158    
159                    my $sth = $dbh->prepare(qq{ update meta set value = ?, changed = now() where nick = ? and channel = ? and name = ? });
160    
161                    eval { $sth->execute( $value, $nick, $channel, $name ) };
162    
163                    # error or no result
164                    if ( $@ || ! $sth->rows ) {
165                            $sth = $dbh->prepare(qq{ insert into meta (value,nick,channel,name,changed) values (?,?,?,?,now()) });
166                            $sth->execute( $value, $nick, $channel, $name );
167                            _log "created $nick/$channel/$name = $value";
168                    } else {
169                            _log "updated $nick/$channel/$name = $value ";
170                    }
171    
172                    return $value;
173    
174            } else {
175    
176                    my $sth = $dbh->prepare(qq{ select value,changed from meta where nick = ? and channel = ? and name = ? });
177                    $sth->execute( $nick, $channel, $name );
178                    my ($v,$c) = $sth->fetchrow_array;
179                    _log "fetched $nick/$channel/$name = $v [$c]";
180                    return ($v,$c) if wantarray;
181                    return $v;
182    
183            }
184    }
185    
186    
187    
188  my $sth = $dbh->prepare(qq{  my $sth = $dbh->prepare(qq{
189  insert into log  insert into log
190          (channel, me, nick, message, time)          (channel, me, nick, message, time)
191  values (?,?,?,?,?)  values (?,?,?,?,?)
192  });  });
193    
194    
195  my $tags;  my $tags;
196  my $tag_regex = '\b([\w-_]+)//';  my $tag_regex = '\b([\w-_]+)//';
197    
# Line 126  my $tag_regex = '\b([\w-_]+)//'; Line 214  my $tag_regex = '\b([\w-_]+)//';
214                  }                  }
215          },          },
216          context => 5,          context => 5,
217            full_rows => 1,
218   );   );
219    
220  Order is important. Fields are first passed through C<filter> (if available) and  Order is important. Fields are first passed through C<filter> (if available) and
# Line 133  then throgh C<< sprintf($fmt->{message}, Line 222  then throgh C<< sprintf($fmt->{message},
222    
223  C<context> defines number of messages around each search hit for display.  C<context> defines number of messages around each search hit for display.
224    
225    C<full_rows> will return database rows for each result with C<date>, C<time>, C<channel>,
226    C<me>, C<nick> and C<message> keys.
227    
228  =cut  =cut
229    
230  sub get_from_log {  sub get_from_log {
# Line 170  sub get_from_log { Line 262  sub get_from_log {
262    
263          $sql .= " where message ilike ? or nick ilike ? " if ($args->{search});          $sql .= " where message ilike ? or nick ilike ? " if ($args->{search});
264          $sql .= " where id in (" . join(",", @{ $tags->{ $args->{tag} } }) . ") " if ($args->{tag} && $tags->{ $args->{tag} });          $sql .= " where id in (" . join(",", @{ $tags->{ $args->{tag} } }) . ") " if ($args->{tag} && $tags->{ $args->{tag} });
265          $sql .= " where date(time) = ? " if ($args->{date});          if ($args->{date}) {
266                    my $date = eval { DateTime::Format::ISO8601->parse_datetime( $args->{date} )->ymd; };
267                    if ( $@ ) {
268                            warn "invalid date ", $args->{date}, $/;
269                            $date = DateTime->now->ymd;
270                    }
271                    $sql .= " where date(time) = ? ";
272                    $args->{date} = $date;
273            }
274          $sql .= " order by log.time desc";          $sql .= " order by log.time desc";
275          $sql .= " limit " . $args->{limit} if ($args->{limit});          $sql .= " limit " . $args->{limit} if ($args->{limit});
276    
# Line 179  sub get_from_log { Line 279  sub get_from_log {
279                  $search =~ s/^\s+//;                  $search =~ s/^\s+//;
280                  $search =~ s/\s+$//;                  $search =~ s/\s+$//;
281                  $sth->execute( ( '%' . $search . '%' ) x 2 );                  $sth->execute( ( '%' . $search . '%' ) x 2 );
282                  warn "search for '$search' returned ", $sth->rows, " results ", $context || '', "\n";                  _log "search for '$search' returned ", $sth->rows, " results ", $context || '';
283          } elsif (my $tag = $args->{tag}) {          } elsif (my $tag = $args->{tag}) {
284                  $sth->execute();                  $sth->execute();
285                  warn "tag '$tag' returned ", $sth->rows, " results ", $context || '', "\n";                  _log "tag '$tag' returned ", $sth->rows, " results ", $context || '';
286          } elsif (my $date = $args->{date}) {          } elsif (my $date = $args->{date}) {
287                  $sth->execute($date);                  $sth->execute($date);
288                  warn "found ", $sth->rows, " messages for date $date ", $context || '', "\n";                  _log "found ", $sth->rows, " messages for date $date ", $context || '';
289          } else {          } else {
290                  $sth->execute();                  $sth->execute();
291          }          }
# Line 202  sub get_from_log { Line 302  sub get_from_log {
302                  unshift @rows, $row;                  unshift @rows, $row;
303          }          }
304    
305            # normalize nick names
306            map {
307                    $_->{nick} =~ s/^_*(.*?)_*$/$1/
308            } @rows;
309    
310            return @rows if ($args->{full_rows});
311    
312          my @msgs = (          my @msgs = (
313                  "Showing " . ($#rows + 1) . " messages..."                  "Showing " . ($#rows + 1) . " messages..."
314          );          );
# Line 258  sub get_from_log { Line 365  sub get_from_log {
365                  my $append = 1;                  my $append = 1;
366    
367                  my $nick = $row->{nick};                  my $nick = $row->{nick};
368                  if ($nick =~ s/^_*(.*?)_*$/$1/) {  #               if ($nick =~ s/^_*(.*?)_*$/$1/) {
369                          $row->{nick} = $nick;  #                       $row->{nick} = $nick;
370                  }  #               }
371    
372                  if ($last_row->{nick} ne $nick) {                  if ($last_row->{nick} ne $nick) {
373                          # obfu way to find format for me_nick if needed or fallback to default                          # obfu way to find format for me_nick if needed or fallback to default
# Line 365  sub save_message { Line 472  sub save_message {
472          $a->{me} ||= 0;          $a->{me} ||= 0;
473          $a->{time} ||= strftime($TIMESTAMP,localtime());          $a->{time} ||= strftime($TIMESTAMP,localtime());
474    
475          print          _log
                 $a->{time}, " ",  
476                  $a->{channel}, " ",                  $a->{channel}, " ",
477                  $a->{me} ? "***" . $a->{nick} : "<" . $a->{nick} . ">",                  $a->{me} ? "***" . $a->{nick} : "<" . $a->{nick} . ">",
478                  " " . $a->{msg} . "\n";                  " " . $a->{msg};
479    
480          from_to($a->{msg}, 'UTF-8', $ENCODING);          from_to($a->{msg}, 'UTF-8', $ENCODING);
481    
# Line 378  sub save_message { Line 484  sub save_message {
484                  message => $a->{msg});                  message => $a->{msg});
485  }  }
486    
487    
488  if ($import_dircproxy) {  if ($import_dircproxy) {
489          open(my $l, $import_dircproxy) || die "can't open $import_dircproxy: $!";          open(my $l, $import_dircproxy) || die "can't open $import_dircproxy: $!";
490          warn "importing $import_dircproxy...\n";          warn "importing $import_dircproxy...\n";
# Line 404  if ($import_dircproxy) { Line 511  if ($import_dircproxy) {
511                          ) if ($nick !~ m/^-/);                          ) if ($nick !~ m/^-/);
512    
513                  } else {                  } else {
514                          warn "can't parse: $_\n";                          _log "can't parse: $_";
515                  }                  }
516          }          }
517          close($l);          close($l);
# Line 419  if ($import_dircproxy) { Line 526  if ($import_dircproxy) {
526    
527  my $SKIPPING = 0;               # if skipping, how many we've done  my $SKIPPING = 0;               # if skipping, how many we've done
528  my $SEND_QUEUE;                 # cache  my $SEND_QUEUE;                 # cache
529    my $ping;                                               # ping stats
530    
531  POE::Component::IRC->new($IRC_ALIAS);  POE::Component::IRC->new($IRC_ALIAS);
532    
# Line 441  POE::Session->create( inline_states => Line 549  POE::Session->create( inline_states =>
549                  my $msg = $_[ARG2];                  my $msg = $_[ARG2];
550    
551                  save_message( channel => $channel, me => 0, nick => $nick, msg => $msg);                  save_message( channel => $channel, me => 0, nick => $nick, msg => $msg);
552                    meta( $nick, $channel, 'last-msg', $msg );
553      },      },
554      irc_ctcp_action => sub {      irc_ctcp_action => sub {
555                  my $kernel = $_[KERNEL];                  my $kernel = $_[KERNEL];
# Line 449  POE::Session->create( inline_states => Line 558  POE::Session->create( inline_states =>
558                  my $msg = $_[ARG2];                  my $msg = $_[ARG2];
559    
560                  save_message( channel => $channel, me => 1, nick => $nick, msg => $msg);                  save_message( channel => $channel, me => 1, nick => $nick, msg => $msg);
561    
562                    if ( $use_twitter ) {
563                            if ( my $twitter = meta( $nick, $NICK, 'twitter' ) ) {
564                                    my ($login,$passwd) = split(/\s+/,$twitter,2);
565                                    _log("sending twitter for $nick/$login on $channel ");
566                                    my $bot = Net::Twitter->new( username=>$login, password=>$passwd );
567                                    $bot->update("<${channel}> $msg");
568                            }
569                    }
570    
571      },      },
572            irc_ping => sub {
573                    warn "pong ", $_[ARG0], $/;
574                    $ping->{ $_[ARG0] }++;
575            },
576            irc_invite => sub {
577                    my $kernel = $_[KERNEL];
578                    my $nick = (split /!/, $_[ARG0])[0];
579                    my $channel = $_[ARG1];
580    
581                    warn "invited to $channel by $nick";
582    
583                    $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, "how nice of you to invite me to $channel, I'll be right there..." );
584                    $_[KERNEL]->post($IRC_ALIAS => join => $channel);
585    
586            },
587          irc_msg => sub {          irc_msg => sub {
588                  my $kernel = $_[KERNEL];                  my $kernel = $_[KERNEL];
589                  my $nick = (split /!/, $_[ARG0])[0];                  my $nick = (split /!/, $_[ARG0])[0];
590                  my $msg = $_[ARG2];                  my $msg = $_[ARG2];
591                    my $channel = $_[ARG1]->[0];
592                  from_to($msg, 'UTF-8', $ENCODING);                  from_to($msg, 'UTF-8', $ENCODING);
593    
594                  my $res = "unknown command '$msg', try /msg $NICK help!";                  my $res = "unknown command '$msg', try /msg $NICK help!";
595                  my @out;                  my @out;
596    
597                  print "<< $msg\n";                  _log "<< $msg";
598    
599                  if ($msg =~ m/^help/i) {                  if ($msg =~ m/^help/i) {
600    
# Line 467  POE::Session->create( inline_states => Line 602  POE::Session->create( inline_states =>
602    
603                  } elsif ($msg =~ m/^msg\s+(\S+)\s+(.*)$/i) {                  } elsif ($msg =~ m/^msg\s+(\S+)\s+(.*)$/i) {
604    
605                          print ">> /msg $1 $2\n";                          _log ">> /msg $1 $2";
606                          $_[KERNEL]->post( $IRC_ALIAS => privmsg => $1, $2 );                          $_[KERNEL]->post( $IRC_ALIAS => privmsg => $1, $2 );
607                          $res = '';                          $res = '';
608    
# Line 477  POE::Session->create( inline_states => Line 612  POE::Session->create( inline_states =>
612    
613                          my $sth = $dbh->prepare(qq{                          my $sth = $dbh->prepare(qq{
614                                  select                                  select
615                                          nick,                                          trim(both '_' from nick) as nick,
616                                          count(*) as count,                                          count(*) as count,
617                                          sum(length(message)) as len                                          sum(length(message)) as len
618                                  from log                                  from log
619                                  group by nick                                  group by trim(both '_' from nick)
620                                  order by len desc,count desc                                  order by len desc,count desc
621                                  limit $nr                                  limit $nr
622                          });                          });
# Line 494  POE::Session->create( inline_states => Line 629  POE::Session->create( inline_states =>
629                          $res .= join(" | ", @users);                          $res .= join(" | ", @users);
630                  } elsif ($msg =~ m/^last.*?\s*(\d*)/i) {                  } elsif ($msg =~ m/^last.*?\s*(\d*)/i) {
631    
632                          foreach my $res (get_from_log( limit => ($1 || 100) )) {                          my $limit = $1 || meta( $nick, $channel, 'last-size' ) || 10;
633                                  print "last: $res\n";  
634                            foreach my $res (get_from_log( limit => $limit )) {
635                                    _log "last: $res";
636                                  from_to($res, $ENCODING, 'UTF-8');                                  from_to($res, $ENCODING, 'UTF-8');
637                                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );                                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );
638                          }                          }
# Line 510  POE::Session->create( inline_states => Line 647  POE::Session->create( inline_states =>
647                                          limit => 20,                                          limit => 20,
648                                          search => $what,                                          search => $what,
649                                  )) {                                  )) {
650                                  print "search [$what]: $res\n";                                  _log "search [$what]: $res";
651                                  from_to($res, $ENCODING, 'UTF-8');                                  from_to($res, $ENCODING, 'UTF-8');
652                                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );                                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );
653                          }                          }
654    
655                          $res = '';                          $res = '';
656    
657                    } elsif ($msg =~ m/^(?:count|poll)\s+(.*)(?:\s+(\d+))?\s*$/i) {
658    
659                            my ($what,$limit) = ($1,$2);
660                            $limit ||= 100;
661    
662                            my $stat;
663    
664                            foreach my $res (get_from_log(
665                                            limit => $limit,
666                                            search => $what,
667                                            full_rows => 1,
668                                    )) {
669                                    while ($res->{message} =~ s/\Q$what\E(\+|\-)//) {
670                                            $stat->{vote}->{$1}++;
671                                            $stat->{from}->{ $res->{nick} }++;
672                                    }
673                            }
674    
675                            my @nicks;
676                            foreach my $nick (sort { $stat->{from}->{$a} <=> $stat->{from}->{$b} } keys %{ $stat->{from} }) {
677                                    push @nicks, $nick . ( $stat->{from}->{$nick} == 1 ? '' :
678                                            "(" . $stat->{from}->{$nick} . ")"
679                                    );
680                            }
681    
682                            $res =
683                                    "$what ++ " . ( $stat->{vote}->{'+'} || 0 ) .
684                                    " : " . ( $stat->{vote}->{'-'} || 0 ) . " --" .
685                                    " from " . ( join(", ", @nicks) || 'nobody' );
686    
687                            $_[KERNEL]->post( $IRC_ALIAS => notice => $nick, $res );
688    
689                    } elsif ($msg =~ m/^ping/) {
690                            $res = "ping = " . dump( $ping );
691                    } elsif ($msg =~ m/^conf(?:ig)*\s*(last-size|twitter)*\s*(.*)/) {
692                            if ( ! defined( $1 ) ) {
693                                    my $sth = $dbh->prepare(qq{ select name,value,changed from meta where nick = ? and channel = ? });
694                                    $sth->execute( $nick, $channel );
695                                    $res = "config for $nick on $channel";
696                                    while ( my ($n,$v) = $sth->fetchrow_array ) {
697                                            $res .= " | $n = $v";
698                                    }
699                            } elsif ( ! $2 ) {
700                                    my $val = meta( $nick, $channel, $1 );
701                                    $res = "current $1 = " . ( $val ? $val : 'undefined' );
702                            } else {
703                                    my $validate = {
704                                            'last-size' => qr/^\d+/,
705                                            'twitter' => qr/^\w+\s+\w+/,
706                                    };
707    
708                                    my ( $op, $val ) = ( $1, $2 );
709    
710                                    if ( my $regex = $validate->{$op} ) {
711                                            if ( $val =~ $regex ) {
712                                                    meta( $nick, $channel, $op, $val );
713                                                    $res = "saved $op = $val";
714                                            } else {
715                                                    $res = "config option $op = $val doesn't validate against $regex";
716                                            }
717                                    } else {
718                                            $res = "config option $op doesn't exist";
719                                    }
720                            }
721                  }                  }
722    
723                  if ($res) {                  if ($res) {
724                          print ">> [$nick] $res\n";                          _log ">> [$nick] $res";
725                          from_to($res, $ENCODING, 'UTF-8');                          from_to($res, $ENCODING, 'UTF-8');
726                          $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );                          $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );
727                  }                  }
728    
729          },          },
730          irc_477 => sub {          irc_477 => sub {
731                  print "# irc_477: ",$_[ARG1], "\n";                  _log "# irc_477: ",$_[ARG1];
732                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "register $NICK" );                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "register $NICK" );
733          },          },
734          irc_505 => sub {          irc_505 => sub {
735                  print "# irc_505: ",$_[ARG1], "\n";                  _log "# irc_505: ",$_[ARG1];
736                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "register $NICK" );                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "register $NICK" );
737  #               $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "set hide email on" );  #               $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "set hide email on" );
738  #               $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "set email dpavlin\@rot13.org" );  #               $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "set email dpavlin\@rot13.org" );
739          },          },
740          irc_registered => sub {          irc_registered => sub {
741                  warn "## indetify $NICK\n";                  _log "## registrated $NICK";
742                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" );                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" );
743          },          },
744            irc_disconnected => sub {
745                    _log "## disconnected, reconnecting again";
746                    $_[KERNEL]->post($IRC_ALIAS => connect => $CONNECT);
747            },
748            irc_socketerr => sub {
749                    _log "## socket error... sleeping for $sleep_on_error seconds and retry";
750                    sleep($sleep_on_error);
751                    $_[KERNEL]->post($IRC_ALIAS => connect => $CONNECT);
752            },
753  #       irc_433 => sub {  #       irc_433 => sub {
754  #               print "# irc_433: ",$_[ARG1], "\n";  #               print "# irc_433: ",$_[ARG1], "\n";
755  #               warn "## indetify $NICK\n";  #               warn "## indetify $NICK\n";
# Line 547  POE::Session->create( inline_states => Line 757  POE::Session->create( inline_states =>
757  #       },  #       },
758      _child => sub {},      _child => sub {},
759      _default => sub {      _default => sub {
760                  printf "%s #%s %s %s\n",                  _log sprintf "sID:%s %s %s",
761                          strftime($TIMESTAMP,localtime()), $_[SESSION]->ID, $_[ARG0],                          $_[SESSION]->ID, $_[ARG0],
762                          ref($_[ARG1]) eq "ARRAY"        ?       join(",", map { ref($_) eq "ARRAY" ? join(";", @{$_}) : $_ } @{ $_[ARG1] })     :                          ref($_[ARG1]) eq "ARRAY"        ?       join(",", map { ref($_) eq "ARRAY" ? join(";", @{$_}) : $_ } @{ $_[ARG1] })     :
763                          $_[ARG1]                                        ?       $_[ARG1]                                        :                          $_[ARG1]                                        ?       $_[ARG1]                                        :
764                          "";                          "";
# Line 635  p { margin: 0; padding: 0.1em; } Line 845  p { margin: 0; padding: 0.1em; }
845  .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 ; }
846  .message { color: #000000; font-size: 100%; }  .message { color: #000000; font-size: 100%; }
847  .search { float: right; }  .search { float: right; }
848    a:link.tag, a:visited.tag { border: 1px dashed #ccc; backgound: #ccc; text-decoration: none }
849    a:hover.tag { border: 1px solid #eee }
850    hr { border: 1px dashed #ccc; height: 1px; clear: both; }
851    /*
852  .col-0 { background: #ffff66 }  .col-0 { background: #ffff66 }
853  .col-1 { background: #a0ffff }  .col-1 { background: #a0ffff }
854  .col-2 { background: #99ff99 }  .col-2 { background: #99ff99 }
855  .col-3 { background: #ff9999 }  .col-3 { background: #ff9999 }
856  .col-4 { background: #ff66ff }  .col-4 { background: #ff66ff }
857  a:link.tag, a:visited.tag { border: 1px dashed #ccc; backgound: #ccc; text-decoration: none }  */
 a:hover.tag { border: 1px solid #eee }  
 hr { border: 1px dashed #ccc; height: 1px; clear: both; }  
858  _END_OF_STYLE_  _END_OF_STYLE_
859    
860  my $max_color = 4;  my $max_color = 4;
861    
862    my @cols = qw(
863            #ffcccc #ccffe6 #ccccff #e6ccff #ffccff #ffcce6 #ff9999 #ffcc99 #ffff99
864            #ccff99 #99ff99 #99ffcc #99ccff #9999ff #cc99ff #ff6666 #ffb366 #ffff66
865            #66ff66 #66ffb3 #66b3ff #6666ff #ff3333 #33ff33 #3399ff #3333ff #ff3399
866            #a0a0a0 #ff0000 #ffff00 #80ff00 #0000ff #8000ff #ff00ff #ff0080 #994d00
867            #999900 #009900 #cc0066 #c0c0c0 #ccff99 #99ff33 #808080 #660033 #ffffff
868    );
869    
870    $max_color = 0;
871    foreach my $c (@cols) {
872            $style .= ".col-${max_color} { background: $c }\n";
873            $max_color++;
874    }
875    warn "defined $max_color colors for users...\n";
876    
877  my %nick_enumerator;  my %nick_enumerator;
878    
879  sub root_handler {  sub root_handler {
# Line 724  sub root_handler { Line 951  sub root_handler {
951                                  filter => {                                  filter => {
952                                          message => sub {                                          message => sub {
953                                                  my $m = shift || return;                                                  my $m = shift || return;
954    
955                                                    # protect HTML from wiki modifications
956                                                    sub e {
957                                                            my $t = shift;
958                                                            return 'uri_unescape{' . uri_escape($t) . '}';
959                                                    }
960    
961                                                  $m =~ s/($escape_re)/$escape{$1}/gs;                                                  $m =~ s/($escape_re)/$escape{$1}/gs;
962                                                  $m =~ s#($RE{URI}{HTTP})#<a href="$1">$1</a>#gs;                                                  $m =~ s#($RE{URI}{HTTP})#e(qq{<a href="$1">$1</a>})#egs;
963                                                  $m =~ s#$tag_regex#<a href="?tag=$1" class="tag">$1</a>#g;                                                  $m =~ s#$tag_regex#e(qq{<a href="?tag=$1" class="tag">$1</a>})#egs;
964                                                    $m =~ s#\*(\w+)\*#<b>$1</b>#gs;
965                                                    $m =~ s#_(\w+)_#<u>$1</u>#gs;
966                                                    $m =~ s#\/(\w+)\/#<i>$1</i>#gs;
967    
968                                                    $m =~ s#uri_unescape{([^}]+)}#uri_unescape($1)#egs;
969                                                  return $m;                                                  return $m;
970                                          },                                          },
971                                          nick => sub {                                          nick => sub {

Legend:
Removed from v.40  
changed lines
  Added in v.64

  ViewVC Help
Powered by ViewVC 1.1.26