/[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 133 by dpavlin, Sat Apr 5 21:08:27 2008 UTC revision 149 by dpavlin, Sat Oct 8 18:33:36 2011 UTC
# Line 18  use Carp qw/confess/; Line 18  use Carp qw/confess/;
18  use XML::Feed;  use XML::Feed;
19  use DateTime::Format::Flexible;  use DateTime::Format::Flexible;
20  use Encode;  use Encode;
21    #use Redis 2.0;
22    
23  =head1 NAME  =head1 NAME
24    
# Line 139  my $filter = { Line 140  my $filter = {
140                  # protect HTML from wiki modifications                  # protect HTML from wiki modifications
141                  sub e {                  sub e {
142                          my $t = shift;                          my $t = shift;
143                          return 'uri_unescape{' . uri_escape($t, '^a-zA-Z0-9') . '}';                          eval { $t = 'uri_unescape{' . uri_escape($t, '^a-zA-Z0-9') . '}'; };
144                            return $t;
145                  }                  }
146    
147                  $m =~ s/($escape_re)/$escape{$1}/gs;                  $m =~ s/($escape_re)/$escape{$1}/gs;
148                  $m =~ s#($RE{URI}{HTTP})#e(qq{<a href="$1">$1</a>})#egs;                  $m =~ s#($RE{URI}{HTTP})#e(qq{<a href="$1">$1</a>})#egs;
149                  $m =~ s#\/(\w+)\/#<i>$1</i>#gs;  #               $m =~ s#\/(\w+)\/#<i>$1</i>#gs;
150                  $m =~ s#$tag_regex#e(qq{<a href="$url?tag=$1" class="tag">$1</a>})#egs;                  $m =~ s#$tag_regex#e(qq{<a href="$url?tag=$1" class="tag">$1</a>})#egs;
151                  $m =~ s#\*(\w+)\*#<b>$1</b>#gs;                  $m =~ s#\*(\w+)\*#<b>$1</b>#gs;
152                  $m =~ s#_(\w+)_#<u>$1</u>#gs;                  $m =~ s#_(\w+)_#<u>$1</u>#gs;
# Line 255  sub meta { Line 257  sub meta {
257    
258                  eval { $sth->execute( $value, $nick, $channel, $name ) };                  eval { $sth->execute( $value, $nick, $channel, $name ) };
259    
260                  # error or no result                  if ( $@ ) {
261                  if ( $@ || ! $sth->rows ) {                          # error
262                            _log("META ERROR: $@");
263                    } elsif ( ! $sth->rows ) {
264                            # no result -> add new
265                          $sth = $dbh->prepare(qq{ insert into meta (value,nick,channel,name,changed) values (?,?,?,?,now()) });                          $sth = $dbh->prepare(qq{ insert into meta (value,nick,channel,name,changed) values (?,?,?,?,now()) });
266                          $sth->execute( $value, $nick, $channel, $name );                          eval { $sth->execute( $value, $nick, $channel, $name ); };
267                          warn "## created $nick/$channel/$name = $value\n";                          if ( $@ ) {
268                                    _log "META ERROR: $@";
269                            } else {
270                                    _log "META: created $nick/$channel/$name = $value\n";
271                            }
272                  } else {                  } else {
273                          warn "## updated $nick/$channel/$name = $value\n";                          _log "META: updated $nick/$channel/$name = $value\n";
274                  }                  }
275    
276                  return $value;                  return $value;
# Line 556  sub save_message { Line 565  sub save_message {
565                  " " . $a->{message};                  " " . $a->{message};
566    
567          eval { $sth_insert_log->execute($a->{channel}, $a->{me}, $a->{nick}, $a->{message}, $a->{time}); };          eval { $sth_insert_log->execute($a->{channel}, $a->{me}, $a->{nick}, $a->{message}, $a->{time}); };
568          _log "ERROR: can't archive ", $a->{message} if $@;  
569          $cloud->add_tag( id => $dbh->last_insert_id(undef,undef,"log",undef), %$a );          eval {
570            my @channel = ( 'channel' , $a->{channel}, $a->{nick} );
571            push @channel, 'me' if $a->{me};
572    #       my $redis = Redis->new( server => '192.168.1.61:6379' );
573    #       $redis->publish( join(' ',@channel), $a->{message} );
574            };
575    
576            if ( $@ ) {
577                    _log "ERROR: can't archive ", $a->{message};
578            } else {
579                    $cloud->add_tag( id => $dbh->last_insert_id(undef,undef,"log",undef), %$a );
580            }
581  }  }
582    
583    
# Line 626  sub rss_parse_xml { Line 646  sub rss_parse_xml {
646    
647          warn "## RSS fetch first $send_rss_msgs items from", $args->{url} if $debug;          warn "## RSS fetch first $send_rss_msgs items from", $args->{url} if $debug;
648    
649          my $feed = XML::Feed->parse( \$args->{xml} );          my $feed;
650            eval { $feed = XML::Feed->parse( \$args->{xml} ) };
651          if ( ! $feed ) {          if ( ! $feed ) {
652                  _log "can't fetch RSS ", $args->{url}, XML::Feed->errstr;                  _log "can't fetch RSS ", $args->{url}, XML::Feed->errstr;
653                  return;                  return;
# Line 1161  sub root_handler { Line 1182  sub root_handler {
1182    
1183          return RC_OK if $request->uri =~ m/favicon.ico$/;          return RC_OK if $request->uri =~ m/favicon.ico$/;
1184    
1185            if ( $request->uri =~ m/robots.txt$/ ) {
1186                    $response->content_type( 'text/plain' );
1187                    $response->content( qq{
1188    
1189    User-Agent: *
1190    Disallow: /
1191    
1192                    });
1193                    return RC_OK;
1194            }
1195    
1196          my $q;          my $q;
1197    
1198          if ( $request->method eq 'POST' ) {          if ( $request->method eq 'POST' ) {
# Line 1283  sub root_handler { Line 1315  sub root_handler {
1315                          $rc = RC_DENY;                          $rc = RC_DENY;
1316                  }                  }
1317    
1318                  $response->content( $feed->as_xml );                  eval { $response->content( $feed->as_xml ); };
1319                    $rc = RC_INTERNAL_SERVER_ERROR if $@;
1320                  return $rc;                  return $rc;
1321          }          }
1322    
# Line 1296  sub root_handler { Line 1329  sub root_handler {
1329          my $html =          my $html =
1330                  qq{<html><head><title>$NICK</title><style type="text/css">$style}                  qq{<html><head><title>$NICK</title><style type="text/css">$style}
1331                  . $cloud->css                  . $cloud->css
1332                  . qq{</style></head><body>}                  . qq{</style>
1333                    <meta name="google-site-verification" content="oe-LvUiNiQRPpc_uB-3rY4MWvFifkmLf276WzAvTL5U" />  
1334                    </head><body>}
1335                  . qq{                  . qq{
1336                  <form method="post" class="search" action="/">                  <form method="post" class="search" action="/">
1337                  <input type="text" name="search" value="$search" size="10">                  <input type="text" name="search" value="$search" size="10">
# Line 1350  sub root_handler { Line 1385  sub root_handler {
1385          } else {          } else {
1386                  $html .= join("</p><p>",                  $html .= join("</p><p>",
1387                          get_from_log(                          get_from_log(
1388                                  limit => ( $q->param('last') || $q->param('date') ) ? undef : 100,                                  limit => ( $q->param('date') ? undef : $q->param('last') || 100 ),
1389                                  search => $search || undef,                                  search => $search || undef,
1390                                  tag => $q->param('tag') || undef,                                  tag => $q->param('tag') || undef,
1391                                  date => $q->param('date') || undef,                                  date => $q->param('date') || undef,
# Line 1375  sub root_handler { Line 1410  sub root_handler {
1410          <p>See <a href="/history">history</a> of all messages.</p>          <p>See <a href="/history">history</a> of all messages.</p>
1411          </body></html>};          </body></html>};
1412    
1413          $response->content( decode('utf-8',$html) );          $response->content( $html );
1414          warn "<< ", $request->method, " ", $request->uri, " created ", length($html), " bytes\n";          warn "<< ", $request->method, " ", $request->uri, " created ", length($html), " bytes\n";
1415          return RC_OK;          return RC_OK;
1416  }  }
# Line 1415  sub html { Line 1450  sub html {
1450          }          }
1451    
1452    my $html = qq{<div id="htmltagcloud">};    my $html = qq{<div id="htmltagcloud">};
1453    foreach my $tag (@tags) {    foreach my $tag ( sort { lc($a->{name}) cmp lc($b->{name}) } @tags) {
1454      $html .=  sprintf(qq{<span class="tag tagcloud%d"><a href="%s" title="%s">%s</a></span>\n},      $html .=  sprintf(qq{<span class="tag tagcloud%d"><a href="%s" title="%s">%s</a></span>\n},
1455                  $tag->{level}, $tag->{url}, $tag->{count}, $tag->{name}                  $tag->{level}, $tag->{url}, $tag->{count}, $tag->{name}
1456          );          );

Legend:
Removed from v.133  
changed lines
  Added in v.149

  ViewVC Help
Powered by ViewVC 1.1.26