root/trunk/plagger/lib/Plagger/Plugin/Summary/TrackbackRDF.pm

Revision 1741 (checked in by miyagawa, 14 years ago)

merge from hackathon-summary

Line 
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__
40
41 =head1 NAME
42
43 Plagger::Plugin::Summary::TrackbackRDF - Extract description from Trackback RDF
44
45 =head1 SYNOPSIS
46
47   - module: Summary::TrackbackRDF
48
49 =head1 DESCRIPTION
50
51 This plugin fetches individual permalink and extracts dc:description
52 tag in Trackback RDF, to use as summary.
53
54 =head1 AUTHOR
55
56 Tatsuhiko Miyagawa
57
58 =head1 SEE ALSO
59
60 L<Plagger>
61
62 =cut
Note: See TracBrowser for help on using the browser.