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

Revision 284 (checked in by miyagawa, 15 years ago)

add SmartFeed?::All thanks to Casey West

  • Property svn:keywords set to Id Revision
Line 
1 package Plagger::Plugin::SmartFeed::All;
2 use strict;
3 use base qw( Plagger::Plugin::SmartFeed );
4
5 sub rule_hook { 'smartfeed.entry' }
6
7 sub register {
8     my($self, $context) = @_;
9     $context->register_hook(
10         $self,
11         'smartfeed.init'  => \&feed_init,
12         'smartfeed.entry' => \&feed_entry,
13         'smartfeed.finalize' => \&feed_finalize,
14     );
15 }
16
17 sub feed_init {
18     my($self, $context, $args) = @_;
19
20     my $feed = Plagger::Feed->new;
21     $feed->type('smartfeed');
22     $feed->id( $self->conf->{id} || ('smartfeed:all') );
23     $feed->title( $self->conf->{title} || "All Entries " );
24
25     $self->{feed} = $feed;
26 }
27
28 sub feed_entry {
29     my($self, $context, $args) = @_;
30     $self->{feed}->add_entry($args->{entry}->clone);
31 }
32
33 sub feed_finalize {
34     my($self, $context, $args) = @_;
35
36     # because it's "All" you have to dedupe the entries
37     my(%seen, @delete);
38     for my $entry ($self->{feed}->entries) {
39         if ($seen{$entry->permalink}++) {
40             push @delete, $entry;
41         }
42     }
43     $self->{feed}->delete_entry($_) for @delete;
44     $self->{feed}->sort_entries;
45
46     $context->update->add($self->{feed}) if $self->{feed}->count;
47 }
48
49 1;
50
Note: See TracBrowser for help on using the browser.