Changeset 7
- Timestamp:
- 02/04/06 17:26:21
- Files:
-
- trunk/plagger/config.yaml.sample (modified) (1 diff)
- trunk/plagger/lib/Plagger.pm (modified) (5 diffs)
- trunk/plagger/lib/Plagger/Date.pm (modified) (1 diff)
- trunk/plagger/lib/Plagger/Entry.pm (modified) (1 diff)
- trunk/plagger/lib/Plagger/Feed.pm (modified) (2 diffs)
- trunk/plagger/lib/Plagger/Plugin.pm (modified) (3 diffs)
- trunk/plagger/lib/Plagger/Plugin/Aggregator (added)
- trunk/plagger/lib/Plagger/Plugin/Aggregator/Simple.pm (added)
- trunk/plagger/lib/Plagger/Plugin/Filter/URLBL.pm (modified) (2 diffs)
- trunk/plagger/lib/Plagger/Plugin/Subscription/Bloglines.pm (modified) (3 diffs)
- trunk/plagger/lib/Plagger/Rule (moved) (moved from trunk/plagger/lib/Plagger/Condition)
- trunk/plagger/lib/Plagger/Rule.pm (moved) (moved from trunk/plagger/lib/Plagger/Condition.pm) (2 diffs)
- trunk/plagger/lib/Plagger/Rule/Always.pm (modified) (1 diff)
- trunk/plagger/lib/Plagger/Rule/Compound.pm (modified) (2 diffs)
- trunk/plagger/lib/Plagger/Rule/Rating.pm (modified) (1 diff)
- trunk/plagger/lib/Plagger/Subscription.pm (added)
- trunk/plagger/lib/Plagger/Update.pm (modified) (3 diffs)
- trunk/plagger/templates/plugins/gmail_notify.tt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/plagger/config.yaml.sample
r3 r7 22 22 23 23 - module: Publish::Gmail 24 condition:24 rule: 25 25 - module: Rating 26 26 rate: '>= 0' trunk/plagger/lib/Plagger.pm
r3 r7 9 9 use UNIVERSAL::require; 10 10 11 use base qw( Class::Accessor::Fast ); 12 __PACKAGE__->mk_accessors( qw(conf stash update subscription) ); 13 11 14 use Plagger::Date; 12 15 use Plagger::Entry; 13 16 use Plagger::Feed; 17 use Plagger::Subscription; 14 18 use Plagger::Update; 15 19 use Template; … … 26 30 stash => {}, 27 31 update => Plagger::Update->new, 32 subscription => Plagger::Subscription->new, 28 33 }, $class; 29 34 … … 41 46 $self->run(); 42 47 } 43 44 sub conf { $_[0]->{conf} }45 sub stash { $_[0]->{stash} }46 sub update { $_[0]->{update} }47 48 48 49 sub load_plugins { … … 86 87 for my $action (@{ $self->{hooks}->{$hook} }) { 87 88 my $plugin = $action->{plugin}; 88 if ( $plugin-> condition->dispatch(@args) ) {89 if ( $plugin->rule->dispatch(@args) ) { 89 90 $action->{callback}->($plugin, $self, @args); 90 91 } … … 96 97 97 98 $self->run_hook('subscription.load'); 98 $self->run_hook(' subscription.aggregate');99 $self->run_hook('aggregator.aggregate'); 99 100 100 101 for my $feed ($self->update->feeds) { trunk/plagger/lib/Plagger/Date.pm
r2 r7 5 5 use UNIVERSAL::require; 6 6 7 sub rebless { 8 my($class, $dt) = @_; 7 sub parse { 8 my($class, $format, $date) = @_; 9 my $module = "DateTime::Format::$format"; 10 $module->require or die $@; 11 my $dt = $module->parse_datetime($date); 12 13 if (my $context = Plagger->context) { 14 $dt->set_time_zone($context->conf->{timezone}); 15 } 16 9 17 bless $dt, $class; 10 18 } trunk/plagger/lib/Plagger/Entry.pm
r3 r7 8 8 9 9 sub new { 10 my($class, $item) = @_; 11 12 my @subject = $item->{dc}->{subject} ? ($item->{dc}->{subject}) : (); 13 14 my $date = DateTime::Format::Mail->parse_datetime($item->{pubDate}); 15 $date = Plagger::Date->rebless($date); 16 10 my $class = shift; 17 11 bless { 18 title => $item->{title},19 author => $item->{dc}->{creator},20 tags => \@subject,21 date => $date,22 link => $item->{link},23 id => $item->{guid},24 body => $item->{description},25 12 rate => 0, 26 13 widgets => [], trunk/plagger/lib/Plagger/Feed.pm
r2 r7 3 3 4 4 use base qw( Class::Accessor::Fast ); 5 __PACKAGE__->mk_accessors(qw( title link image description language webmastertags stash ));5 __PACKAGE__->mk_accessors(qw( title link url image description language author updated tags stash )); 6 6 7 7 sub new { 8 my ($class, $feed) = @_;8 my $class = shift; 9 9 bless { 10 title => $feed->{title},11 link => $feed->{link},12 image => $feed->{image},13 description => $feed->{description},14 language => $feed->{language},15 webmaster => $feed->{webmaster},16 10 stash => {}, 17 11 tags => [], … … 30 24 } 31 25 26 sub count { 27 my $self = shift; 28 scalar @{ $self->{entries} }; 29 } 30 32 31 1; trunk/plagger/lib/Plagger/Plugin.pm
r3 r7 2 2 use strict; 3 3 4 use Plagger:: Condition;5 use Plagger:: Condition::Compound;4 use Plagger::Rule; 5 use Plagger::Rule::Compound; 6 6 7 7 sub new { … … 9 9 my $self = bless { 10 10 conf => $opt->{config} || {}, 11 condition => $opt->{condition},11 rule => $opt->{rule}, 12 12 stash => {}, 13 13 }, $class; … … 18 18 sub init { 19 19 my $self = shift; 20 if (my $ cond = $self->{condition}) {21 $ cond = [ $cond ] if ref($cond) eq 'HASH';22 $self->{ condition} = Plagger::Condition::Compound->new(@$cond);20 if (my $rule = $self->{rule}) { 21 $rule = [ $rule ] if ref($rule) eq 'HASH'; 22 $self->{rule} = Plagger::Rule::Compound->new(@$rule); 23 23 } else { 24 $self->{ condition} = Plagger::Condition->new({ module => 'Always' });24 $self->{rule} = Plagger::Rule->new({ module => 'Always' }); 25 25 } 26 26 } 27 27 28 sub conf { $_[0]->{conf} }29 sub condition { $_[0]->{condition} }28 sub conf { $_[0]->{conf} } 29 sub rule { $_[0]->{rule} } 30 30 31 31 1; trunk/plagger/lib/Plagger/Plugin/Filter/URLBL.pm
r3 r7 24 24 sub { 25 25 my($uri, $orig_uri) = @_; 26 push @urls, $uri; 26 if ($orig_uri =~ m!^https?://!) { 27 push @urls, $uri; 28 } 27 29 return $orig_uri; 28 30 }, … … 39 41 $domain =~ s/^www\.//; 40 42 43 next if $self->{__done}->{$domain}++; 44 41 45 for my $dns (@$dnsbl) { 42 46 $context->log(debug => "looking up $domain.$dns"); trunk/plagger/lib/Plagger/Plugin/Subscription/Bloglines.pm
r6 r7 8 8 sub register { 9 9 my($self, $context) = @_; 10 $context->register_hook( 11 $self, 12 'subscription.load' => \&load, 13 'subscription.aggregate' => \&aggregate, 14 ); 10 11 $self->init_bloglines(); 12 13 if ($self->conf->{no_sync_api}) { 14 $context->register_hook( 15 $self, 16 'subscription.load' => \&getsubs, 17 ); 18 } else { 19 $context->register_hook( 20 $self, 21 'subscription.load' => \¬ifier, 22 'aggregator.aggregate' => \&sync, 23 ); 24 } 15 25 } 16 26 17 sub load{27 sub getsubs { 18 28 my($self, $context) = @_; 29 my $subscription = $self->{bloglines}->listsubs(); 30 31 for my $folder ($subscription->folders) { 32 $self->add_subscription($context, $subscription, $folder->{BloglinesSubId}, $folder->{title}); 33 } 34 35 $self->add_subscription($context, $subscription, 0); 36 } 37 38 sub add_subscription { 39 my($self, $context, $subscription, $subid, $title) = @_; 40 41 my @feeds = $subscription->feeds_in_folder($subid); 42 for my $source (@feeds) { 43 my $feed = Plagger::Feed->new; 44 $feed->title($source->{title}); 45 $feed->link($source->{htmlUrl}); 46 $feed->url($source->{xmlUrl} ); 47 $feed->tags([ $title ]) if $title; 48 $context->subscription->add($feed); 49 } 50 } 51 52 sub init_bloglines { 53 my $self = shift; 19 54 $self->{bloglines} = WebService::Bloglines->new( 20 55 username => $self->conf->{username}, 21 56 password => $self->conf->{password}, 22 57 ); 58 } 59 60 sub notifier { 61 my($self, $context) = @_; 23 62 24 63 my $count = $self->{bloglines}->notify(); … … 27 66 } 28 67 29 sub aggregate{68 sub sync { 30 69 my($self, $context) = @_; 31 70 … … 36 75 37 76 for my $update (@updates) { 38 my $feed = Plagger::Feed->new($update->feed); 39 $feed->stash->{bloglines_id} = $update->feed->{bloglines}->{siteid}; 77 my $source = $update->feed; 78 79 my $feed = Plagger::Feed->new; 80 $feed->title($source->{title}); 81 $feed->link($source->{link}); 82 $feed->image($source->{image}); 83 $feed->description($source->{description}); 84 $feed->language($source->{language}); 85 $feed->author($source->{webmaster}); 86 $feed->stash->{bloglines_id} = $source->{bloglines}->{siteid}; 40 87 41 88 for my $item ( $update->items ) { 42 $feed->add_entry( Plagger::Entry->new($item) ); 89 my $entry = Plagger::Entry->new; 90 91 $entry->title($item->{title}); 92 $entry->author($item->{dc}->{creator}); 93 $entry->tags([ $item->{dc}->{subject} ]) 94 if $item->{dc}->{subject}; 95 $entry->date( Plagger::Date->parse('Mail', $item->{pubDate}) ); 96 $entry->link($item->{link}); 97 $entry->id($item->{guid}); 98 $entry->body($item->{description}); 99 100 $feed->add_entry($entry); 43 101 } 44 102 trunk/plagger/lib/Plagger/Rule.pm
r3 r7 1 package Plagger:: Condition;1 package Plagger::Rule; 2 2 use strict; 3 3 use UNIVERSAL::require; … … 7 7 8 8 my $module = delete $config->{module}; 9 $module = "Plagger:: Condition::$module";9 $module = "Plagger::Rule::$module"; 10 10 $module->require or die $@; 11 11 trunk/plagger/lib/Plagger/Rule/Always.pm
r3 r7 1 package Plagger:: Condition::Always;2 use base qw( Plagger:: Condition);1 package Plagger::Rule::Always; 2 use base qw( Plagger::Rule ); 3 3 4 4 sub dispatch { 1 } trunk/plagger/lib/Plagger/Rule/Compound.pm
r3 r7 1 package Plagger:: Condition::Compound;1 package Plagger::Rule::Compound; 2 2 use strict; 3 3 4 4 sub new { 5 my($class, @ cond) = @_;5 my($class, @rules) = @_; 6 6 bless { 7 conditions => [ map Plagger::Condition->new($_), @cond],7 rules => [ map Plagger::Rule->new($_), @rules ], 8 8 }, $class; 9 9 } … … 13 13 14 14 my $bool = 1; 15 for my $ condition (@{ $self->{conditions} }) {16 $bool = 0 unless $ condition->dispatch(@args); # AND mode15 for my $rule (@{ $self->{rules} }) { 16 $bool = 0 unless $rule->dispatch(@args); # AND mode 17 17 } 18 18 trunk/plagger/lib/Plagger/Rule/Rating.pm
r3 r7 1 package Plagger:: Condition::Rating;1 package Plagger::Rule::Rating; 2 2 use strict; 3 use base qw( Plagger:: Condition);3 use base qw( Plagger::Rule ); 4 4 5 5 my %ops = ( trunk/plagger/lib/Plagger/Update.pm
r3 r7 4 4 sub new { 5 5 my $class = shift; 6 bless { feeds => [] }, $class;6 bless { feeds => [], by_tags => {} }, $class; 7 7 } 8 8 … … 10 10 my($self, $feed) = @_; 11 11 push @{ $self->{feeds} }, $feed; 12 for my $tag ( @{$feed->tags} ) { 13 push @{ $self->{by_tags}->{$tag} }, $feed; 14 } 12 15 } 13 16 … … 17 20 } 18 21 22 sub feeds_by_tag { 23 my($self, $tag) = @_; 24 my @feeds = @{ $self->{by_tags}->{$tag} || [] }; 25 wantarray ? @feeds : \@feeds; 26 } 27 28 sub tags { 29 my $self = shift; 30 keys %{ $self->{by_tags} }; 31 } 32 19 33 1; trunk/plagger/templates/plugins/gmail_notify.tt
r5 r7 9 9 [% IF item.body.match('(?i)^<p[ >]') %][% item.body %][% ELSE %]<div style="padding: 1em 0">[% item.body %]</div>[% END %] 10 10 [% ELSE %]<br />[% END %] 11 <div style="font-size:0.8em">[% IF item.date %]Posted on [% item.date.format('Mail') %][% END %] | <a href="[% link | html %]">permalink</a> | <a href="[% feed.link | html %]">[% feed.title | html %]</a>[% FOREACH widget = item.widgets %] | [% widget.html %][% END %]<br clear="all" /></div>11 <div style="font-size:0.8em">[% IF item.date %]Posted on [% item.date.format('Mail') %][% END %] | <a href="[% link | html %]">permalink</a> | <a href="[% feed.link | html %]">[% feed.title | html %]</a>[% FOREACH widget = item.widgets %] | [% widget.html %][% END %]<br clear="all" /></div> 12 12 </div>
