/[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 64 by dpavlin, Fri Jun 8 12:12:45 2007 UTC revision 67 by dpavlin, Sat Sep 29 13:13:41 2007 UTC
# Line 260  sub get_from_log { Line 260  sub get_from_log {
260    
261          my $sql = $context ? $sql_context : $sql_message;          my $sql = $context ? $sql_context : $sql_message;
262    
263          $sql .= " where message ilike ? or nick ilike ? " if ($args->{search});          sub check_date {
264          $sql .= " where id in (" . join(",", @{ $tags->{ $args->{tag} } }) . ") " if ($args->{tag} && $tags->{ $args->{tag} });                  my $date = shift;
265          if ($args->{date}) {                  $date = eval { DateTime::Format::ISO8601->parse_datetime( $args->{date} )->ymd; };
                 my $date = eval { DateTime::Format::ISO8601->parse_datetime( $args->{date} )->ymd; };  
266                  if ( $@ ) {                  if ( $@ ) {
267                          warn "invalid date ", $args->{date}, $/;                          warn "invalid date ", $args->{date}, $/;
268                          $date = DateTime->now->ymd;                          $date = DateTime->now->ymd;
269                  }                  }
270                    return $date;
271            }
272    
273            $sql .= " where message ilike ? or nick ilike ? " if ($args->{search});
274            $sql .= " where id in (" . join(",", @{ $tags->{ $args->{tag} } }) . ") " if ($args->{tag} && $tags->{ $args->{tag} });
275            if ($args->{date}) {
276                  $sql .= " where date(time) = ? ";                  $sql .= " where date(time) = ? ";
277                  $args->{date} = $date;                  $args->{date} = check_date( $args->{date} );
278          }          }
279          $sql .= " order by log.time desc";          $sql .= " order by log.time desc";
280          $sql .= " limit " . $args->{limit} if ($args->{limit});          $sql .= " limit " . $args->{limit} if ($args->{limit});
# Line 284  sub get_from_log { Line 289  sub get_from_log {
289                  $sth->execute();                  $sth->execute();
290                  _log "tag '$tag' returned ", $sth->rows, " results ", $context || '';                  _log "tag '$tag' returned ", $sth->rows, " results ", $context || '';
291          } elsif (my $date = $args->{date}) {          } elsif (my $date = $args->{date}) {
292                  $sth->execute($date);                  $sth->execute( check_date($date) );
293                  _log "found ", $sth->rows, " messages for date $date ", $context || '';                  _log "found ", $sth->rows, " messages for date $date ", $context || '';
294          } else {          } else {
295                  $sth->execute();                  $sth->execute();
# Line 855  hr { border: 1px dashed #ccc; height: 1p Line 860  hr { border: 1px dashed #ccc; height: 1p
860  .col-3 { background: #ff9999 }  .col-3 { background: #ff9999 }
861  .col-4 { background: #ff66ff }  .col-4 { background: #ff66ff }
862  */  */
863    .calendar { border: 1px solid red; width: 100%; }
864    .month { border: 0px; width: 100%; }
865  _END_OF_STYLE_  _END_OF_STYLE_
866    
867  my $max_color = 4;  my $max_color = 4;
# Line 907  sub root_handler { Line 914  sub root_handler {
914                  qq{<p>};                  qq{<p>};
915          if ($request->url =~ m#/history#) {          if ($request->url =~ m#/history#) {
916                  my $sth = $dbh->prepare(qq{                  my $sth = $dbh->prepare(qq{
917                          select date(time) as date,count(*) as nr                          select date(time) as date,count(*) as nr,sum(length(message)) as len
918                                  from log                                  from log
919                                  group by date(time)                                  group by date(time)
920                                  order by date(time) desc                                  order by date(time) desc
921                  });                  });
922                  $sth->execute();                  $sth->execute();
923                  my ($l_yyyy,$l_mm) = (0,0);                  my ($l_yyyy,$l_mm) = (0,0);
924                    $html .= qq{<table class="calendar"><tr>};
925                  my $cal;                  my $cal;
926                    my $ord = 0;
927                  while (my $row = $sth->fetchrow_hashref) {                  while (my $row = $sth->fetchrow_hashref) {
928                          # this is probably PostgreSQL specific, expects ISO date                          # this is probably PostgreSQL specific, expects ISO date
929                          my ($yyyy,$mm,$dd) = split(/-/, $row->{date});                          my ($yyyy,$mm,$dd) = split(/-/, $row->{date});
930                          if ($yyyy != $l_yyyy || $mm != $l_mm) {                          if ($yyyy != $l_yyyy || $mm != $l_mm) {
931                                  $html .= $cal->as_HTML() if ($cal);                                  if ( $cal ) {
932                                            $html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td>};
933                                            $ord++;
934                                            $html .= qq{</tr><tr>} if ( $ord % 3 == 0 );
935                                    }
936                                  $cal = new HTML::CalendarMonthSimple('month'=>$mm,'year'=>$yyyy);                                  $cal = new HTML::CalendarMonthSimple('month'=>$mm,'year'=>$yyyy);
937                                  $cal->border(2);                                  $cal->border(1);
938                                    $cal->width('30%');
939                                    $cal->cellheight('5em');
940                                    $cal->tableclass('month');
941                                    #$cal->cellclass('day');
942                                    $cal->sunday('SUN');
943                                    $cal->saturday('SAT');
944                                    $cal->weekdays('MON','TUE','WED','THU','FRI');
945                                  ($l_yyyy,$l_mm) = ($yyyy,$mm);                                  ($l_yyyy,$l_mm) = ($yyyy,$mm);
946                          }                          }
947                          $cal->setcontent($dd, qq{                          $cal->setcontent($dd, qq{
948                                  <a href="/?date=$row->{date}">$row->{nr}</a>                                  <a href="/?date=$row->{date}">$row->{nr}</a><br/>$row->{len}
949                          });                          });
950                            
951                  }                  }
952                  $html .= $cal->as_HTML() if ($cal);                  $html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td></tr></table>};
953    
954          } else {          } else {
955                  $html .= join("</p><p>",                  $html .= join("</p><p>",
# Line 936  sub root_handler { Line 957  sub root_handler {
957                                  limit => $q->param('last') || $q->param('date') ? undef : 100,                                  limit => $q->param('last') || $q->param('date') ? undef : 100,
958                                  search => $search || undef,                                  search => $search || undef,
959                                  tag => $q->param('tag') || undef,                                  tag => $q->param('tag') || undef,
960                                  date => $q->param('date') || undef,                                  date => check_date( $q->param('date') ),
961                                  fmt => {                                  fmt => {
962                                          date => sub {                                          date => sub {
963                                                  my $date = shift || return;                                                  my $date = shift || return;

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

  ViewVC Help
Powered by ViewVC 1.1.26