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 |
|
|
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; |
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; |
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 $redis = Redis->new( server => '192.168.1.61:6379' ); |
571 |
|
my @channel = ( 'channel' , $a->{channel}, $a->{nick} ); |
572 |
|
push @channel, 'me' if $a->{me}; |
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 |
|
|
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; |
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' ) { |
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 |
|
|
1448 |
} |
} |
1449 |
|
|
1450 |
my $html = qq{<div id="htmltagcloud">}; |
my $html = qq{<div id="htmltagcloud">}; |
1451 |
foreach my $tag (@tags) { |
foreach my $tag ( sort { lc($a->{name}) cmp lc($b->{name}) } @tags) { |
1452 |
$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}, |
1453 |
$tag->{level}, $tag->{url}, $tag->{count}, $tag->{name} |
$tag->{level}, $tag->{url}, $tag->{count}, $tag->{name} |
1454 |
); |
); |