| 1 | package Plagger::Plugin::Filter::BreakEntriesToSubscriptions; |
|---|
| 2 | use strict; |
|---|
| 3 | use base qw( Plagger::Plugin ); |
|---|
| 4 | |
|---|
| 5 | sub register { |
|---|
| 6 | my($self, $context) = @_; |
|---|
| 7 | $context->register_hook( |
|---|
| 8 | $self, |
|---|
| 9 | 'update.feed.fixup' => \&break, |
|---|
| 10 | ); |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | sub 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 | |
|---|
| 46 | 1; |
|---|
| 47 | |
|---|
| 48 | __END__ |
|---|
| 49 | |
|---|
| 50 | =head1 NAME |
|---|
| 51 | |
|---|
| 52 | Plagger::Plugin::Filter::BreakEntriesToSubscriptions - some entry = 1 subscription |
|---|
| 53 | |
|---|
| 54 | =head1 SYNOPSIS |
|---|
| 55 | |
|---|
| 56 | - module: Filter::BreakEntriesToSubscriptions |
|---|
| 57 | |
|---|
| 58 | =head1 DESCRIPTION |
|---|
| 59 | |
|---|
| 60 | This plugin breaks all the subscription entries into a single feed. This is |
|---|
| 61 | a 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 | |
|---|
| 69 | Use subscription's title as a newly generated feed title. Defaults to 0. |
|---|
| 70 | |
|---|
| 71 | =back |
|---|
| 72 | |
|---|
| 73 | =head1 AUTHOR |
|---|
| 74 | |
|---|
| 75 | Yasuhiro Matsumoto |
|---|
| 76 | |
|---|
| 77 | =head1 THANKS |
|---|
| 78 | |
|---|
| 79 | Tatsuhiko Miyagawa |
|---|
| 80 | |
|---|
| 81 | =head1 SEE ALSO |
|---|
| 82 | |
|---|
| 83 | L<Plagger> |
|---|
| 84 | |
|---|
| 85 | =cut |
|---|