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/; |
use Data::Dump qw/dump/; |
78 |
|
use DateTime::Format::ISO8601; |
79 |
|
|
80 |
my $use_twitter = 1; |
my $use_twitter = 1; |
81 |
eval { require Net::Twitter; }; |
eval { require Net::Twitter; }; |
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 |
|
|
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 } |
*/ |
858 |
a:hover.tag { border: 1px solid #eee } |
.calendar { border: 1px solid red; width: 100%; } |
859 |
hr { border: 1px dashed #ccc; height: 1px; clear: both; } |
.month { border: 0px; width: 100%; } |
860 |
_END_OF_STYLE_ |
_END_OF_STYLE_ |
861 |
|
|
862 |
my $max_color = 4; |
my $max_color = 4; |
863 |
|
|
864 |
|
my @cols = qw( |
865 |
|
#ffcccc #ccffe6 #ccccff #e6ccff #ffccff #ffcce6 #ff9999 #ffcc99 #ffff99 |
866 |
|
#ccff99 #99ff99 #99ffcc #99ccff #9999ff #cc99ff #ff6666 #ffb366 #ffff66 |
867 |
|
#66ff66 #66ffb3 #66b3ff #6666ff #ff3333 #33ff33 #3399ff #3333ff #ff3399 |
868 |
|
#a0a0a0 #ff0000 #ffff00 #80ff00 #0000ff #8000ff #ff00ff #ff0080 #994d00 |
869 |
|
#999900 #009900 #cc0066 #c0c0c0 #ccff99 #99ff33 #808080 #660033 #ffffff |
870 |
|
); |
871 |
|
|
872 |
|
$max_color = 0; |
873 |
|
foreach my $c (@cols) { |
874 |
|
$style .= ".col-${max_color} { background: $c }\n"; |
875 |
|
$max_color++; |
876 |
|
} |
877 |
|
warn "defined $max_color colors for users...\n"; |
878 |
|
|
879 |
my %nick_enumerator; |
my %nick_enumerator; |
880 |
|
|
881 |
sub root_handler { |
sub root_handler { |
909 |
qq{<p>}; |
qq{<p>}; |
910 |
if ($request->url =~ m#/history#) { |
if ($request->url =~ m#/history#) { |
911 |
my $sth = $dbh->prepare(qq{ |
my $sth = $dbh->prepare(qq{ |
912 |
select date(time) as date,count(*) as nr |
select date(time) as date,count(*) as nr,sum(length(message)) as len |
913 |
from log |
from log |
914 |
group by date(time) |
group by date(time) |
915 |
order by date(time) desc |
order by date(time) desc |
916 |
}); |
}); |
917 |
$sth->execute(); |
$sth->execute(); |
918 |
my ($l_yyyy,$l_mm) = (0,0); |
my ($l_yyyy,$l_mm) = (0,0); |
919 |
|
$html .= qq{<table class="calendar"><tr>}; |
920 |
my $cal; |
my $cal; |
921 |
|
my $ord = 0; |
922 |
while (my $row = $sth->fetchrow_hashref) { |
while (my $row = $sth->fetchrow_hashref) { |
923 |
# this is probably PostgreSQL specific, expects ISO date |
# this is probably PostgreSQL specific, expects ISO date |
924 |
my ($yyyy,$mm,$dd) = split(/-/, $row->{date}); |
my ($yyyy,$mm,$dd) = split(/-/, $row->{date}); |
925 |
if ($yyyy != $l_yyyy || $mm != $l_mm) { |
if ($yyyy != $l_yyyy || $mm != $l_mm) { |
926 |
$html .= $cal->as_HTML() if ($cal); |
if ( $cal ) { |
927 |
|
$html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td>}; |
928 |
|
$ord++; |
929 |
|
$html .= qq{</tr><tr>} if ( $ord % 3 == 0 ); |
930 |
|
} |
931 |
$cal = new HTML::CalendarMonthSimple('month'=>$mm,'year'=>$yyyy); |
$cal = new HTML::CalendarMonthSimple('month'=>$mm,'year'=>$yyyy); |
932 |
$cal->border(2); |
$cal->border(1); |
933 |
|
$cal->width('30%'); |
934 |
|
$cal->cellheight('5em'); |
935 |
|
$cal->tableclass('month'); |
936 |
|
#$cal->cellclass('day'); |
937 |
|
$cal->sunday('SUN'); |
938 |
|
$cal->saturday('SAT'); |
939 |
|
$cal->weekdays('MON','TUE','WED','THU','FRI'); |
940 |
($l_yyyy,$l_mm) = ($yyyy,$mm); |
($l_yyyy,$l_mm) = ($yyyy,$mm); |
941 |
} |
} |
942 |
$cal->setcontent($dd, qq{ |
$cal->setcontent($dd, qq{ |
943 |
<a href="/?date=$row->{date}">$row->{nr}</a> |
<a href="/?date=$row->{date}">$row->{nr}</a><br/>$row->{len} |
944 |
}); |
}); |
945 |
|
|
946 |
} |
} |
947 |
$html .= $cal->as_HTML() if ($cal); |
$html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td></tr></table>}; |
948 |
|
|
949 |
} else { |
} else { |
950 |
$html .= join("</p><p>", |
$html .= join("</p><p>", |
967 |
filter => { |
filter => { |
968 |
message => sub { |
message => sub { |
969 |
my $m = shift || return; |
my $m = shift || return; |
970 |
|
|
971 |
|
# protect HTML from wiki modifications |
972 |
|
sub e { |
973 |
|
my $t = shift; |
974 |
|
return 'uri_unescape{' . uri_escape($t) . '}'; |
975 |
|
} |
976 |
|
|
977 |
$m =~ s/($escape_re)/$escape{$1}/gs; |
$m =~ s/($escape_re)/$escape{$1}/gs; |
978 |
$m =~ s#($RE{URI}{HTTP})#<a href="$1">$1</a>#gs; |
$m =~ s#($RE{URI}{HTTP})#e(qq{<a href="$1">$1</a>})#egs; |
979 |
$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; |
980 |
$m =~ s#\*(\w+)\*#<b>$1</b>#gs; |
$m =~ s#\*(\w+)\*#<b>$1</b>#gs; |
981 |
$m =~ s#_(\w+)_#<u>$1</u>#gs; |
$m =~ s#_(\w+)_#<u>$1</u>#gs; |
982 |
$m =~ s#\/(\w+)\/#<i>$1</i>#gs; |
$m =~ s#\/(\w+)\/#<i>$1</i>#gs; |
983 |
|
|
984 |
|
$m =~ s#uri_unescape{([^}]+)}#uri_unescape($1)#egs; |
985 |
return $m; |
return $m; |
986 |
}, |
}, |
987 |
nick => sub { |
nick => sub { |