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

Revision 1061 (checked in by miyagawa, 14 years ago)

add link: config attribute to SmartFeed? via http://subtech.g.hatena.ne.jp/otsune/20060428/smartfeeddiff

  • 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
28     $self->{feed} = $feed;
29 }
30
31 sub feed_entry {
32     my($self, $context, $args) = @_;
33
34     my $entry = $args->{entry}->clone;
35     my $feed  = $args->{feed}->clone;
36        $feed->clear_entries;
37     $entry->source($feed); # xxx is it only valid for SmartFeed?
38     $entry->icon($feed->image) if !$entry->icon && $feed->image;
39
40     $self->{feed}->add_entry($entry);
41 }
42
43 sub feed_finalize {
44     my($self, $context, $args) = @_;
45     $context->update->add($self->{feed}) if $self->{feed}->count;
46 }
47
48 1;
Note: See TracBrowser for help on using the browser.