| 1 | package Plagger::Plugin::Summary::TrackbackRDF; | ||
| 2 | use strict; | ||
| 3 | use base qw( Plagger::Plugin ); | ||
| 4 | |||
| 5 | use HTML::Entities; | ||
| 6 | use Plagger::UserAgent; | ||
| 7 | |||
| 8 | sub register { | ||
| 9 | my($self, $context) = @_; | ||
| 10 | $context->register_hook( | ||
| 11 | $self, | ||
| 12 | 'summarizer.summarize' => \&summarize, | ||
| 13 | ); | ||
| 14 | } | ||
| 15 | |||
| 16 | sub summarize { | ||
| 17 | my($self, $context, $args) = @_; | ||
| 18 | |||
| 19 | # XXX share fetched content with EntryFullText. #387 | ||
| 20 | my $url = $args->{entry}->permalink; | ||
| 21 | my $agent = Plagger::UserAgent->new; | ||
| 22 | $agent->parse_head(0); | ||
| 23 | my $res = $agent->fetch($url, $self, { NoNetwork => 12 * 3600 }); | ||
| 24 | |||
| 25 | if ($res->is_error) { | ||
| 26 | $context->log(error => "Fetch $url failed: " . $res->status); | ||
| 27 | } | ||
| 28 | |||
| 29 | my $content = Plagger::Util::decode_content($res->content); | ||
| 30 | while ($content =~ m!(<rdf:RDF.*?</rdf:RDF>)!sg) { | ||
| 31 | my $rdf = $1; | ||
| 32 | if ($rdf =~ /\s*dc:description="(.*?)"\s*/) { | ||
| 33 | return HTML::Entities::decode($1); | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | 1; | ||
| 39 | __END__ |