59 |
|
|
60 |
my $sleep_on_error = 5; |
my $sleep_on_error = 5; |
61 |
|
|
62 |
|
# number of last tags to keep in circular buffer |
63 |
|
my $last_x_tags = 50; |
64 |
|
|
65 |
my $http_port = $NICK =~ m/-dev/ ? 8001 : 8000; |
my $http_port = $NICK =~ m/-dev/ ? 8001 : 8000; |
66 |
|
|
67 |
my $url = "http://$HOSTNAME:$http_port"; |
my $url = "http://$HOSTNAME:$http_port"; |
486 |
|
|
487 |
=cut |
=cut |
488 |
|
|
|
my $last_x_tags = 5; |
|
489 |
my @last_tags; |
my @last_tags; |
490 |
|
|
491 |
sub add_tag { |
sub add_tag { |
975 |
|
|
976 |
my $search = $q->param('search') || $q->param('grep') || ''; |
my $search = $q->param('search') || $q->param('grep') || ''; |
977 |
|
|
978 |
if ($request->url =~ m#/rss#i) { |
if ($request->url =~ m#/rss(?:/(tags|last-tag?)\w+(?:=(\d+))?)?#i) { |
979 |
|
my $show = lc($1); |
980 |
|
my $nr = $2; |
981 |
|
|
982 |
my $type = 'RSS'; # Atom |
my $type = 'RSS'; # Atom |
983 |
|
|
984 |
$response->content_type( 'application/' . lc($type) . '+xml' ); |
$response->content_type( 'application/' . lc($type) . '+xml' ); |
988 |
|
|
989 |
my $feed = XML::Feed->new( $type ); |
my $feed = XML::Feed->new( $type ); |
990 |
|
|
991 |
$feed->title( "last $last_x_tags from $CHANNEL" ); |
if ( $show eq 'tags' ) { |
992 |
$feed->link( $url ); |
$nr ||= 50; |
993 |
$feed->description( "collects messages which have tags// in them" ); |
$feed->title( "tags from $CHANNEL" ); |
994 |
|
$feed->link( "$url/tags" ); |
995 |
foreach my $m ( @last_tags ) { |
$feed->description( "tag cloud created from messages on channel $CHANNEL which have tags// in them" ); |
|
# warn dump( $m ); |
|
|
#my $tags = join(' ', @{$m->{tags}} ); |
|
996 |
my $feed_entry = XML::Feed::Entry->new($type); |
my $feed_entry = XML::Feed::Entry->new($type); |
997 |
$feed_entry->title( $m->{nick} . '@' . $m->{time} ); |
$feed_entry->title( "$nr tags from $CHANNEL" ); |
998 |
$feed_entry->author( $m->{nick} ); |
$feed_entry->author( $NICK ); |
999 |
$feed_entry->link( '/#' . $m->{id} ); |
$feed_entry->link( '/#tags' ); |
|
$feed_entry->issued( DateTime::Format::Flexible->build( $m->{time} ) ); |
|
|
|
|
|
my $message = $filter->{message}->( $m->{message} ); |
|
|
$message .= "<br/>\n" unless $message =~ m!<(/p|br/?)>!; |
|
|
warn "## message = $message\n"; |
|
|
from_to( $message, $ENCODING, 'UTF-8' ); |
|
1000 |
|
|
|
#$feed_entry->summary( |
|
1001 |
$feed_entry->content( |
$feed_entry->content( |
1002 |
"<![CDATA[$message]]>" |
qq{<![CDATA[<style type="text/css">} |
1003 |
|
. $cloud->css |
1004 |
|
. qq{</style>} |
1005 |
|
. $cloud->html( $nr ) |
1006 |
|
. qq{]]>} |
1007 |
); |
); |
|
$feed_entry->category( join(', ', @{$m->{tags}}) ); |
|
1008 |
$feed->add_entry( $feed_entry ); |
$feed->add_entry( $feed_entry ); |
1009 |
|
|
1010 |
|
} elsif ( $show eq 'last-tag' ) { |
1011 |
|
|
1012 |
|
$nr ||= $last_x_tags; |
1013 |
|
|
1014 |
|
$feed->title( "last $nr tagged messages from $CHANNEL" ); |
1015 |
|
$feed->link( $url ); |
1016 |
|
$feed->description( "collects messages which have tags// in them" ); |
1017 |
|
|
1018 |
|
foreach my $m ( @last_tags ) { |
1019 |
|
# warn dump( $m ); |
1020 |
|
#my $tags = join(' ', @{$m->{tags}} ); |
1021 |
|
my $feed_entry = XML::Feed::Entry->new($type); |
1022 |
|
$feed_entry->title( $m->{nick} . '@' . $m->{time} ); |
1023 |
|
$feed_entry->author( $m->{nick} ); |
1024 |
|
$feed_entry->link( '/#' . $m->{id} ); |
1025 |
|
$feed_entry->issued( DateTime::Format::Flexible->build( $m->{time} ) ); |
1026 |
|
|
1027 |
|
my $message = $filter->{message}->( $m->{message} ); |
1028 |
|
$message .= "<br/>\n" unless $message =~ m!<(/p|br/?)>!; |
1029 |
|
# warn "## message = $message\n"; |
1030 |
|
from_to( $message, $ENCODING, 'UTF-8' ); |
1031 |
|
|
1032 |
|
#$feed_entry->summary( |
1033 |
|
$feed_entry->content( |
1034 |
|
"<![CDATA[$message]]>" |
1035 |
|
); |
1036 |
|
$feed_entry->category( join(', ', @{$m->{tags}}) ); |
1037 |
|
$feed->add_entry( $feed_entry ); |
1038 |
|
|
1039 |
|
$nr--; |
1040 |
|
last if $nr <= 0; |
1041 |
|
|
1042 |
|
} |
1043 |
|
|
1044 |
|
} else { |
1045 |
|
warn "!! unknown rss request for $show\n"; |
1046 |
|
return RC_DENY; |
1047 |
} |
} |
1048 |
|
|
1049 |
$response->content( $feed->as_xml ); |
$response->content( $feed->as_xml ); |
1057 |
$response->content_type("text/html; charset=$ENCODING"); |
$response->content_type("text/html; charset=$ENCODING"); |
1058 |
|
|
1059 |
my $html = |
my $html = |
1060 |
qq{<html><head><title>$NICK</title><style type="text/css">$style} . |
qq{<html><head><title>$NICK</title><style type="text/css">$style} |
1061 |
$cloud->css . |
. $cloud->css |
1062 |
qq{</style></head><body>} . |
. qq{</style></head><body>} |
1063 |
qq{ |
. qq{ |
1064 |
<form method="post" class="search" action="/"> |
<form method="post" class="search" action="/"> |
1065 |
<input type="text" name="search" value="$search" size="10"> |
<input type="text" name="search" value="$search" size="10"> |
1066 |
<input type="submit" value="search"> |
<input type="submit" value="search"> |
1067 |
</form> |
</form> |
1068 |
} . |
} |
1069 |
$cloud->html(500) . |
. $cloud->html(500) |
1070 |
qq{<p>}; |
. qq{<p>}; |
1071 |
if ($request->url =~ m#/history#) { |
|
1072 |
|
if ($request->url =~ m#/tags?#) { |
1073 |
|
# nop |
1074 |
|
} elsif ($request->url =~ m#/history#) { |
1075 |
my $sth = $dbh->prepare(qq{ |
my $sth = $dbh->prepare(qq{ |
1076 |
select date(time) as date,count(*) as nr,sum(length(message)) as len |
select date(time) as date,count(*) as nr,sum(length(message)) as len |
1077 |
from log |
from log |
1103 |
$cal->weekdays('MON','TUE','WED','THU','FRI'); |
$cal->weekdays('MON','TUE','WED','THU','FRI'); |
1104 |
($l_yyyy,$l_mm) = ($yyyy,$mm); |
($l_yyyy,$l_mm) = ($yyyy,$mm); |
1105 |
} |
} |
1106 |
$cal->setcontent($dd, qq{ |
$cal->setcontent($dd, qq[ |
1107 |
<a href="$url?date=$row->{date}">$row->{nr}</a><br/>$row->{len} |
<a href="$url?date=$row->{date}">$row->{nr}</a><br/>$row->{len} |
1108 |
}); |
]); |
1109 |
|
|
1110 |
} |
} |
1111 |
$html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td></tr></table>}; |
$html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td></tr></table>}; |