root/trunk/plagger/lib/Plagger/Plugin/SmartFeed.pm

Revision 1213 (checked in by miyagawa, 12 years ago)

Publish::Feed: use author <nobody@example.com> in RSS feed to make it a valid feed.

  • Property svn:keywords set to Id Revision
Line 
1 package Plagger::Plugin::SmartFeed;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use Plagger::Tag;
6
7 sub rule_hook { 'smartfeed.entry' }
8
9 sub register {
10     my($self, $context) = @_;
11     $context->register_hook(
12         $self,
13         'smartfeed.init'  => $self->can('feed_init'),
14         'smartfeed.entry' => $self->can('feed_entry'),
15         'smartfeed.finalize' => $self->can('feed_finalize'),
16     );
17 }
18
19 sub feed_init {
20     my($self, $context, $args) = @_;
21
22     my $feed = Plagger::Feed->new;
23     $feed->type('smartfeed');
24     $feed->id( $self->conf->{id} || ('smartfeed:' . $self->rule->id) );
25     $feed->title( $self->conf->{title} || "Entries " . $self->rule->as_title );
26     $feed->link( $self->conf->{link} );
27     $feed->description( $self->conf->{description} || $feed->title );
28
29     $self->{feed} = $feed;
30 }
31
32 sub feed_entry {
33     my($self, $context, $args) = @_;
34
35     my $entry = $args->{entry}->clone;
36     my $feed  = $args->{feed}->clone;
37        $feed->clear_entries;
38     $entry->source($feed); # xxx is it only valid for SmartFeed?
39     $entry->icon($feed->image) if !$entry->icon && $feed->image;
40
41     $self->{feed}->add_entry($entry);
42 }
43
44 sub feed_finalize {
45     my($self, $context, $args) = @_;
46     $context->update->add($self->{feed}) if $self->{feed}->count;
47 }
48
49 1;
Note: See TracBrowser for help on using the browser.