root/lang/perl/plagger/lib/Plagger/Plugin/Filter/BreakEntriesToSubscriptions.pm

Revision 473, 1.9 kB (checked in by mattn, 11 months ago)

lang/perl/plagger/lib/Plagger/Plugin/Filter/BreakEntriesToSubscriptions.pm: Added.

Line 
1package Plagger::Plugin::Filter::BreakEntriesToSubscriptions;
2use strict;
3use base qw( Plagger::Plugin );
4
5sub register {
6    my($self, $context) = @_;
7    $context->register_hook(
8        $self,
9        'update.feed.fixup' => \&break,
10    );
11}
12
13sub break {
14    my($self, $context, $args) = @_;
15
16    for my $entry ($args->{feed}->entries) {
17        my $feed = $args->{feed}->clone;
18        $feed->clear_entries;
19
20        $feed->add_entry($entry);
21        $feed->link($entry->link);
22        $feed->url($entry->link);
23        eval {
24            use HTML::TokeParser;
25            my $agent = Plagger::UserAgent->new;
26            my $res = $agent->fetch($entry->link, $self);
27            my $parser = HTML::TokeParser->new(\$res->content);
28            while (my $token = $parser->get_tag("link")) {
29                my $attr = $token->[1];
30                if ($attr->{rel} eq 'alternate'
31                        && ($attr->{type} eq 'application/rss+xml'
32                         or $attr->{type} eq 'application/atom+xml')) {
33                    $feed->url(URI->new_abs($attr->{href}, $entry->link)-> as_string);
34                    last;
35                }
36            }
37        } if $self->conf->{use_auto_discovery};
38        $feed->title($entry->title)
39            if $self->conf->{use_entry_title};
40        $context->subscription->add($feed);
41    }
42
43    $context->subscription->delete_feed($args->{feed});
44}
45
461;
47
48__END__
49
50=head1 NAME
51
52Plagger::Plugin::Filter::BreakEntriesToSubscriptions - some entry = 1 subscription
53
54=head1 SYNOPSIS
55
56  - module: Filter::BreakEntriesToSubscriptions
57
58=head1 DESCRIPTION
59
60This plugin breaks all the subscription entries into a single feed. This is
61a fairly hackish plugin but it's helpful for make OPML from feeds.
62
63=head1 CONFIG
64
65=over 4
66
67=item use_entry_title
68
69Use subscription's title as a newly generated feed title. Defaults to 0.
70
71=back
72
73=head1 AUTHOR
74
75Yasuhiro Matsumoto
76
77=head1 THANKS
78
79Tatsuhiko Miyagawa
80
81=head1 SEE ALSO
82
83L<Plagger>
84
85=cut
Note: See TracBrowser for help on using the browser.