Changeset 7

Show
Ignore:
Timestamp:
02/04/06 17:26:21
Author:
miyagawa
Message:

Added no_sync_api mode to Subscription::Bloglines
Switch subscription.aggregate into aggregator.aggregate
Added dumb aggregator Aggregator::Simple
Added cache to URLBL
Date->parse fix
Renamed condition to "rule"
Gmail tempalte spacing fix

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/config.yaml.sample

    r3 r7  
    2222 
    2323  - module: Publish::Gmail 
    24     condition
     24    rule
    2525      - module: Rating 
    2626        rate:   '>= 0' 
  • trunk/plagger/lib/Plagger.pm

    r3 r7  
    99use UNIVERSAL::require; 
    1010 
     11use base qw( Class::Accessor::Fast ); 
     12__PACKAGE__->mk_accessors( qw(conf stash update subscription) ); 
     13 
    1114use Plagger::Date; 
    1215use Plagger::Entry; 
    1316use Plagger::Feed; 
     17use Plagger::Subscription; 
    1418use Plagger::Update; 
    1519use Template; 
     
    2630        stash => {}, 
    2731        update => Plagger::Update->new, 
     32        subscription => Plagger::Subscription->new, 
    2833    }, $class; 
    2934 
     
    4146    $self->run(); 
    4247} 
    43  
    44 sub conf   { $_[0]->{conf}  } 
    45 sub stash  { $_[0]->{stash} } 
    46 sub update { $_[0]->{update} } 
    4748 
    4849sub load_plugins { 
     
    8687    for my $action (@{ $self->{hooks}->{$hook} }) { 
    8788        my $plugin = $action->{plugin}; 
    88         if ( $plugin->condition->dispatch(@args) ) { 
     89        if ( $plugin->rule->dispatch(@args) ) { 
    8990            $action->{callback}->($plugin, $self, @args); 
    9091        } 
     
    9697 
    9798    $self->run_hook('subscription.load'); 
    98     $self->run_hook('subscription.aggregate'); 
     99    $self->run_hook('aggregator.aggregate'); 
    99100 
    100101    for my $feed ($self->update->feeds) { 
  • trunk/plagger/lib/Plagger/Date.pm

    r2 r7  
    55use UNIVERSAL::require; 
    66 
    7 sub rebless { 
    8     my($class, $dt) = @_; 
     7sub 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 
    917    bless $dt, $class; 
    1018} 
  • trunk/plagger/lib/Plagger/Entry.pm

    r3 r7  
    88 
    99sub 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; 
    1711    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}, 
    2512        rate   => 0, 
    2613        widgets => [], 
  • trunk/plagger/lib/Plagger/Feed.pm

    r2 r7  
    33 
    44use base qw( Class::Accessor::Fast ); 
    5 __PACKAGE__->mk_accessors(qw( title link image description language webmaster tags stash )); 
     5__PACKAGE__->mk_accessors(qw( title link url image description language author updated tags stash )); 
    66 
    77sub new { 
    8     my($class, $feed) = @_
     8    my $class = shift
    99    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}, 
    1610        stash => {}, 
    1711        tags  => [], 
     
    3024} 
    3125 
     26sub count { 
     27    my $self = shift; 
     28    scalar @{ $self->{entries} }; 
     29} 
     30 
    32311; 
  • trunk/plagger/lib/Plagger/Plugin.pm

    r3 r7  
    22use strict; 
    33 
    4 use Plagger::Condition
    5 use Plagger::Condition::Compound; 
     4use Plagger::Rule
     5use Plagger::Rule::Compound; 
    66 
    77sub new { 
     
    99    my $self = bless { 
    1010        conf => $opt->{config} || {}, 
    11         condition => $opt->{condition}, 
     11        rule => $opt->{rule}, 
    1212        stash => {}, 
    1313    }, $class; 
     
    1818sub init { 
    1919    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); 
    2323    } else { 
    24         $self->{condition} = Plagger::Condition->new({ module => 'Always' }); 
     24        $self->{rule} = Plagger::Rule->new({ module => 'Always' }); 
    2525    } 
    2626} 
    2727 
    28 sub conf      { $_[0]->{conf} } 
    29 sub condition { $_[0]->{condition} } 
     28sub conf { $_[0]->{conf} } 
     29sub rule { $_[0]->{rule} } 
    3030 
    31311; 
  • trunk/plagger/lib/Plagger/Plugin/Filter/URLBL.pm

    r3 r7  
    2424        sub { 
    2525            my($uri, $orig_uri) = @_; 
    26             push @urls, $uri; 
     26            if ($orig_uri =~ m!^https?://!) { 
     27                push @urls, $uri; 
     28            } 
    2729            return $orig_uri; 
    2830        }, 
     
    3941        $domain =~ s/^www\.//; 
    4042 
     43        next if $self->{__done}->{$domain}++; 
     44 
    4145        for my $dns (@$dnsbl) { 
    4246            $context->log(debug => "looking up $domain.$dns"); 
  • trunk/plagger/lib/Plagger/Plugin/Subscription/Bloglines.pm

    r6 r7  
    88sub register { 
    99    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'    => \&notifier, 
     22            'aggregator.aggregate' => \&sync, 
     23        ); 
     24    } 
    1525} 
    1626 
    17 sub load
     27sub getsubs
    1828    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 
     38sub 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 
     52sub init_bloglines { 
     53    my $self = shift; 
    1954    $self->{bloglines} = WebService::Bloglines->new( 
    2055        username => $self->conf->{username}, 
    2156        password => $self->conf->{password}, 
    2257    ); 
     58} 
     59 
     60sub notifier { 
     61    my($self, $context) = @_; 
    2362 
    2463    my $count = $self->{bloglines}->notify(); 
     
    2766} 
    2867 
    29 sub aggregate
     68sub sync
    3069    my($self, $context) = @_; 
    3170 
     
    3675 
    3776    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}; 
    4087 
    4188        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); 
    43101        } 
    44102 
  • trunk/plagger/lib/Plagger/Rule.pm

    r3 r7  
    1 package Plagger::Condition
     1package Plagger::Rule
    22use strict; 
    33use UNIVERSAL::require; 
     
    77 
    88    my $module = delete $config->{module}; 
    9     $module = "Plagger::Condition::$module"; 
     9    $module = "Plagger::Rule::$module"; 
    1010    $module->require or die $@; 
    1111 
  • trunk/plagger/lib/Plagger/Rule/Always.pm

    r3 r7  
    1 package Plagger::Condition::Always; 
    2 use base qw( Plagger::Condition ); 
     1package Plagger::Rule::Always; 
     2use base qw( Plagger::Rule ); 
    33 
    44sub dispatch { 1 } 
  • trunk/plagger/lib/Plagger/Rule/Compound.pm

    r3 r7  
    1 package Plagger::Condition::Compound; 
     1package Plagger::Rule::Compound; 
    22use strict; 
    33 
    44sub new { 
    5     my($class, @cond) = @_; 
     5    my($class, @rules) = @_; 
    66    bless { 
    7         conditions => [ map Plagger::Condition->new($_), @cond ], 
     7        rules => [ map Plagger::Rule->new($_), @rules ], 
    88    }, $class; 
    99} 
     
    1313 
    1414    my $bool = 1; 
    15     for my $condition (@{ $self->{conditions} }) { 
    16         $bool = 0 unless $condition->dispatch(@args); # AND mode 
     15    for my $rule (@{ $self->{rules} }) { 
     16        $bool = 0 unless $rule->dispatch(@args); # AND mode 
    1717    } 
    1818 
  • trunk/plagger/lib/Plagger/Rule/Rating.pm

    r3 r7  
    1 package Plagger::Condition::Rating; 
     1package Plagger::Rule::Rating; 
    22use strict; 
    3 use base qw( Plagger::Condition ); 
     3use base qw( Plagger::Rule ); 
    44 
    55my %ops = ( 
  • trunk/plagger/lib/Plagger/Update.pm

    r3 r7  
    44sub new { 
    55    my $class = shift; 
    6     bless { feeds => [] }, $class; 
     6    bless { feeds => [], by_tags => {} }, $class; 
    77} 
    88 
     
    1010    my($self, $feed) = @_; 
    1111    push @{ $self->{feeds} }, $feed; 
     12    for my $tag ( @{$feed->tags} ) { 
     13        push @{ $self->{by_tags}->{$tag} }, $feed; 
     14    } 
    1215} 
    1316 
     
    1720} 
    1821 
     22sub feeds_by_tag { 
     23    my($self, $tag) = @_; 
     24    my @feeds = @{ $self->{by_tags}->{$tag} || [] }; 
     25    wantarray ? @feeds : \@feeds; 
     26} 
     27 
     28sub tags { 
     29    my $self = shift; 
     30    keys %{ $self->{by_tags} }; 
     31} 
     32 
    19331; 
  • trunk/plagger/templates/plugins/gmail_notify.tt

    r5 r7  
    99[% IF item.body.match('(?i)^<p[ >]') %][% item.body %][% ELSE %]<div style="padding: 1em 0">[% item.body %]</div>[% END %] 
    1010[% 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> 
    1212</div>