| 1 |
package Plagger::Plugin::Filter::tDiaryComment; |
|---|
| 2 |
use strict; |
|---|
| 3 |
use base qw( Plagger::Plugin ); |
|---|
| 4 |
|
|---|
| 5 |
our $VERSION = '0.10'; |
|---|
| 6 |
|
|---|
| 7 |
sub register { |
|---|
| 8 |
my($self, $context) = @_; |
|---|
| 9 |
$context->register_hook( |
|---|
| 10 |
$self, |
|---|
| 11 |
'update.feed.fixup' => \&filter, |
|---|
| 12 |
); |
|---|
| 13 |
} |
|---|
| 14 |
|
|---|
| 15 |
sub filter { |
|---|
| 16 |
my($self, $context, $args) = @_; |
|---|
| 17 |
|
|---|
| 18 |
return unless $self->tdiary_magic($args->{feed}); |
|---|
| 19 |
|
|---|
| 20 |
$context->log(debug => "Found tDiary feed " . $args->{feed}->url); |
|---|
| 21 |
|
|---|
| 22 |
for my $entry ($args->{feed}->entries) { |
|---|
| 23 |
if ($entry->link =~ /\.html |
|---|
| 24 |
|
|---|
| 25 |
$context->log(info => "Strip comment " . $entry->link); |
|---|
| 26 |
$args->{feed}->delete_entry($entry); |
|---|
| 27 |
} |
|---|
| 28 |
} |
|---|
| 29 |
} |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
our $FeedMagic = <<'MAGIC'; |
|---|
| 33 |
^<\?xml version="1.0" encoding=".*?"\?> |
|---|
| 34 |
<\?xml-stylesheet href="rss\.css" type="text/css"\?> |
|---|
| 35 |
<rdf:RDF xmlns="http://purl\.org/rss/1\.0/" xmlns:rdf="http://www\.w3\.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl\.org/dc/elements/1\.1/" xmlns:content="http://purl\.org/rss/1\.0/modules/content/" xml:lang=".*?"> |
|---|
| 36 |
MAGIC |
|---|
| 37 |
|
|---|
| 38 |
sub tdiary_magic { |
|---|
| 39 |
my($self, $feed) = @_; |
|---|
| 40 |
|
|---|
| 41 |
my $xml = $feed->source_xml or return; |
|---|
| 42 |
$xml =~ /$FeedMagic/o; |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
1; |
|---|
| 46 |
|
|---|
| 47 |
__END__ |
|---|
| 48 |
|
|---|
| 49 |
=head1 NAME |
|---|
| 50 |
|
|---|
| 51 |
Plagger::Plugin::Filter::tDiaryComment - Rate tDiary comment |
|---|
| 52 |
|
|---|
| 53 |
=head1 SYNOPSIS |
|---|
| 54 |
|
|---|
| 55 |
- module: Filter::tDiaryComment |
|---|
| 56 |
|
|---|
| 57 |
=head1 DESCRIPTION |
|---|
| 58 |
|
|---|
| 59 |
tDiary (L<http://www.tdiary.org/>) RSS feed by default contains |
|---|
| 60 |
comments to the blog as well. They're useful to keep track of the |
|---|
| 61 |
discussion, but sometimes are annoying to read. |
|---|
| 62 |
|
|---|
| 63 |
This plugin strips the comment entries from tDiary RSS feeds. |
|---|
| 64 |
|
|---|
| 65 |
=head1 AUTHOR |
|---|
| 66 |
|
|---|
| 67 |
MATSUNO Tokuhiro E<lt>tokuhiro at mobilefactory.jpE<gt> |
|---|
| 68 |
|
|---|
| 69 |
Tatsuhiko Miyagawa |
|---|
| 70 |
|
|---|
| 71 |
=head1 SEE ALSO |
|---|
| 72 |
|
|---|
| 73 |
L<Plagger> |
|---|
| 74 |
|
|---|
| 75 |
=cut |
|---|