| 1 |
package Plagger::Plugin::Filter::FeedBurnerPermalink; |
|---|
| 2 |
use strict; |
|---|
| 3 |
use base qw( Plagger::Plugin ); |
|---|
| 4 |
|
|---|
| 5 |
sub register { |
|---|
| 6 |
my($self, $context) = @_; |
|---|
| 7 |
$context->register_hook( |
|---|
| 8 |
$self, |
|---|
| 9 |
'aggregator.entry.fixup' => \&fixup, |
|---|
| 10 |
'update.entry.fixup' => \&filter, |
|---|
| 11 |
); |
|---|
| 12 |
} |
|---|
| 13 |
|
|---|
| 14 |
sub fixup { |
|---|
| 15 |
my($self, $context, $args) = @_; |
|---|
| 16 |
|
|---|
| 17 |
my $fbns = 'http://rssnamespace.org/feedburner/ext/1.0'; |
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
if (ref($args->{orig_entry}) =~ /RSS/) { |
|---|
| 21 |
if (my $orig_link = $args->{orig_entry}->{entry}->{$fbns}->{origLink}) { |
|---|
| 22 |
$args->{entry}->permalink($orig_link); |
|---|
| 23 |
$context->log(info => "Permalink rewritten to $orig_link"); |
|---|
| 24 |
} |
|---|
| 25 |
} |
|---|
| 26 |
|
|---|
| 27 |
elsif (ref($args->{orig_entry}) =~ /Atom/) { |
|---|
| 28 |
my $ns = XML::Atom::Namespace->new(feedburner => $fbns); |
|---|
| 29 |
if (my $orig_link = $args->{orig_entry}->{entry}->get($ns, 'origLink')) { |
|---|
| 30 |
$args->{entry}->permalink($orig_link); |
|---|
| 31 |
$context->log(info => "Permalink rewritten to $orig_link"); |
|---|
| 32 |
} |
|---|
| 33 |
} |
|---|
| 34 |
} |
|---|
| 35 |
|
|---|
| 36 |
sub filter { |
|---|
| 37 |
my($self, $context, $args) = @_; |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
my $entry = $args->{entry}; |
|---|
| 41 |
if ($entry->permalink =~ m!^http://feeds\.feedburner\.(com|jp)/!) { |
|---|
| 42 |
$entry->permalink( $entry->id . "" ); |
|---|
| 43 |
$context->log(info => "Permalink rewritten to " . $entry->permalink); |
|---|
| 44 |
} |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
1; |
|---|
| 48 |
|
|---|
| 49 |
__END__ |
|---|
| 50 |
|
|---|
| 51 |
=head1 NAME |
|---|
| 52 |
|
|---|
| 53 |
Plagger::Plugin::Filter::FeedBurnerPermalink - Fix FeedBurner's permalink |
|---|
| 54 |
|
|---|
| 55 |
=head1 SYNOPSIS |
|---|
| 56 |
|
|---|
| 57 |
- module: Filter::FeedBurnerPermalink |
|---|
| 58 |
|
|---|
| 59 |
=head1 DESCRIPTION |
|---|
| 60 |
|
|---|
| 61 |
Entries in FeedBurner feeds contain links to feedburner's URL |
|---|
| 62 |
redirector and that breaks some plugins like social bookmarks |
|---|
| 63 |
integration. |
|---|
| 64 |
|
|---|
| 65 |
This plugin updates the C<< $entry->permalink >> with I<guid> value in |
|---|
| 66 |
FeedBurner's feed, so it actually points to the permalink, rather than |
|---|
| 67 |
redirector. |
|---|
| 68 |
|
|---|
| 69 |
Note that C<< $entry->link >> will still point to the redirector. |
|---|
| 70 |
|
|---|
| 71 |
=head1 AUTHOR |
|---|
| 72 |
|
|---|
| 73 |
Masahiro Nagano |
|---|
| 74 |
|
|---|
| 75 |
Tatsuhiko Miyagawa |
|---|
| 76 |
|
|---|
| 77 |
=head1 SEE ALSO |
|---|
| 78 |
|
|---|
| 79 |
L<Plagger>, L<http://www.feedburner.com/> |
|---|
| 80 |
|
|---|
| 81 |
=cut |
|---|