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 { |
916 |
|
|
917 |
my $httpd = POE::Component::Server::HTTP->new( |
my $httpd = POE::Component::Server::HTTP->new( |
918 |
Port => $http_port, |
Port => $http_port, |
919 |
|
PreHandler => { |
920 |
|
'/' => sub { |
921 |
|
$_[0]->header(Connection => 'close') |
922 |
|
} |
923 |
|
}, |
924 |
ContentHandler => { '/' => \&root_handler }, |
ContentHandler => { '/' => \&root_handler }, |
925 |
Headers => { Server => 'irc-logger' }, |
Headers => { Server => 'irc-logger' }, |
926 |
); |
); |
966 |
my ($request, $response) = @_; |
my ($request, $response) = @_; |
967 |
$response->code(RC_OK); |
$response->code(RC_OK); |
968 |
|
|
969 |
|
# this doesn't seem to work, so moved to PreHandler |
970 |
|
#$response->header(Connection => 'close'); |
971 |
|
|
972 |
return RC_OK if $request->uri =~ m/favicon.ico$/; |
return RC_OK if $request->uri =~ m/favicon.ico$/; |
973 |
|
|
974 |
my $q; |
my $q; |
983 |
|
|
984 |
my $search = $q->param('search') || $q->param('grep') || ''; |
my $search = $q->param('search') || $q->param('grep') || ''; |
985 |
|
|
986 |
if ($request->url =~ m#/rss#i) { |
if ($request->url =~ m#/rss(?:/(tags|last-tag)\w*(?:=(\d+))?)?#i) { |
987 |
|
my $show = lc($1); |
988 |
|
my $nr = $2; |
989 |
|
|
990 |
my $type = 'RSS'; # Atom |
my $type = 'RSS'; # Atom |
991 |
|
|
992 |
$response->content_type( 'application/' . lc($type) . '+xml' ); |
$response->content_type( 'application/' . lc($type) . '+xml' ); |
996 |
|
|
997 |
my $feed = XML::Feed->new( $type ); |
my $feed = XML::Feed->new( $type ); |
998 |
|
|
999 |
$feed->title( "last $last_x_tags from $CHANNEL" ); |
if ( $show eq 'tags' ) { |
1000 |
$feed->link( $url ); |
$nr ||= 50; |
1001 |
$feed->description( "collects messages which have tags// in them" ); |
$feed->title( "tags from $CHANNEL" ); |
1002 |
|
$feed->link( "$url/tags" ); |
1003 |
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}} ); |
|
1004 |
my $feed_entry = XML::Feed::Entry->new($type); |
my $feed_entry = XML::Feed::Entry->new($type); |
1005 |
$feed_entry->title( $m->{nick} . '@' . $m->{time} ); |
$feed_entry->title( "$nr tags from $CHANNEL" ); |
1006 |
$feed_entry->author( $m->{nick} ); |
$feed_entry->author( $NICK ); |
1007 |
$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' ); |
|
1008 |
|
|
|
#$feed_entry->summary( |
|
1009 |
$feed_entry->content( |
$feed_entry->content( |
1010 |
"<![CDATA[$message]]>" |
qq{<![CDATA[<style type="text/css">} |
1011 |
|
. $cloud->css |
1012 |
|
. qq{</style>} |
1013 |
|
. $cloud->html( $nr ) |
1014 |
|
. qq{]]>} |
1015 |
); |
); |
|
$feed_entry->category( join(', ', @{$m->{tags}}) ); |
|
1016 |
$feed->add_entry( $feed_entry ); |
$feed->add_entry( $feed_entry ); |
1017 |
|
|
1018 |
|
} elsif ( $show eq 'last-tag' ) { |
1019 |
|
|
1020 |
|
$nr ||= $last_x_tags; |
1021 |
|
$nr = $last_x_tags if $nr > $last_x_tags; |
1022 |
|
|
1023 |
|
$feed->title( "last $nr tagged messages from $CHANNEL" ); |
1024 |
|
$feed->link( $url ); |
1025 |
|
$feed->description( "collects messages which have tags// in them" ); |
1026 |
|
|
1027 |
|
foreach my $m ( @last_tags ) { |
1028 |
|
# warn dump( $m ); |
1029 |
|
#my $tags = join(' ', @{$m->{tags}} ); |
1030 |
|
my $feed_entry = XML::Feed::Entry->new($type); |
1031 |
|
$feed_entry->title( $m->{nick} . '@' . $m->{time} ); |
1032 |
|
$feed_entry->author( $m->{nick} ); |
1033 |
|
$feed_entry->link( '/#' . $m->{id} ); |
1034 |
|
$feed_entry->issued( DateTime::Format::Flexible->build( $m->{time} ) ); |
1035 |
|
|
1036 |
|
my $message = $filter->{message}->( $m->{message} ); |
1037 |
|
$message .= "<br/>\n" unless $message =~ m!<(/p|br/?)>!; |
1038 |
|
# warn "## message = $message\n"; |
1039 |
|
from_to( $message, $ENCODING, 'UTF-8' ); |
1040 |
|
|
1041 |
|
#$feed_entry->summary( |
1042 |
|
$feed_entry->content( |
1043 |
|
"<![CDATA[$message]]>" |
1044 |
|
); |
1045 |
|
$feed_entry->category( join(', ', @{$m->{tags}}) ); |
1046 |
|
$feed->add_entry( $feed_entry ); |
1047 |
|
|
1048 |
|
$nr--; |
1049 |
|
last if $nr <= 0; |
1050 |
|
|
1051 |
|
} |
1052 |
|
|
1053 |
|
} else { |
1054 |
|
warn "!! unknown rss request for $show\n"; |
1055 |
|
return RC_DENY; |
1056 |
} |
} |
1057 |
|
|
1058 |
$response->content( $feed->as_xml ); |
$response->content( $feed->as_xml ); |
1066 |
$response->content_type("text/html; charset=$ENCODING"); |
$response->content_type("text/html; charset=$ENCODING"); |
1067 |
|
|
1068 |
my $html = |
my $html = |
1069 |
qq{<html><head><title>$NICK</title><style type="text/css">$style} . |
qq{<html><head><title>$NICK</title><style type="text/css">$style} |
1070 |
$cloud->css . |
. $cloud->css |
1071 |
qq{</style></head><body>} . |
. qq{</style></head><body>} |
1072 |
qq{ |
. qq{ |
1073 |
<form method="post" class="search" action="/"> |
<form method="post" class="search" action="/"> |
1074 |
<input type="text" name="search" value="$search" size="10"> |
<input type="text" name="search" value="$search" size="10"> |
1075 |
<input type="submit" value="search"> |
<input type="submit" value="search"> |
1076 |
</form> |
</form> |
1077 |
} . |
} |
1078 |
$cloud->html(500) . |
. $cloud->html(500) |
1079 |
qq{<p>}; |
. qq{<p>}; |
1080 |
|
|
1081 |
if ($request->url =~ m#/tags?#) { |
if ($request->url =~ m#/tags?#) { |
1082 |
# nop |
# nop |
1112 |
$cal->weekdays('MON','TUE','WED','THU','FRI'); |
$cal->weekdays('MON','TUE','WED','THU','FRI'); |
1113 |
($l_yyyy,$l_mm) = ($yyyy,$mm); |
($l_yyyy,$l_mm) = ($yyyy,$mm); |
1114 |
} |
} |
1115 |
$cal->setcontent($dd, qq{ |
$cal->setcontent($dd, qq[ |
1116 |
<a href="$url?date=$row->{date}">$row->{nr}</a><br/>$row->{len} |
<a href="$url?date=$row->{date}">$row->{nr}</a><br/>$row->{len} |
1117 |
}); |
]); |
1118 |
|
|
1119 |
} |
} |
1120 |
$html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td></tr></table>}; |
$html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td></tr></table>}; |