Changeset 128

Show
Ignore:
Timestamp:
02/23/06 23:35:44
Author:
miyagawa
Message:

Support $entry->icon in Frepa as well. Refs #55

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Plugin/CustomFeed/Frepa.pm

    r41 r128  
    7171        } 
    7272 
     73        if ($self->conf->{show_icon} && !$blocked) { 
     74            my $item = $self->fetch_icon($msg->{user_link}); 
     75            if ($item && $item->{image} !~ /no_photo/) { 
     76                $entry->icon({ 
     77                    title => decode('euc-jp', $item->{name}), 
     78                    url   => $item->{image}, 
     79                    link  => $msg->{user_link}, 
     80                }); 
     81            } 
     82        } 
     83 
    7384        $feed->add_entry($entry); 
    7485    } 
    7586 
    7687    $context->update->add($feed); 
     88} 
     89 
     90sub fetch_icon { 
     91    my($self, $url) = @_; 
     92 
     93    unless ($self->{__icon_cache}->{$url}) { 
     94        Plagger->context->log(info => "Fetch icon from $url"); 
     95        $self->{__icon_cache}->{$url} = $self->{frepa}->get_top($url); 
     96    } 
     97 
     98    $self->{__icon_cache}->{$url}; 
    7799} 
    78100 
     
    145167        $item = +{description => $7}; 
    146168    } 
     169 
     170    return $item; 
     171} 
     172 
     173sub get_top { 
     174    my $self = shift; 
     175    my $link = shift; 
     176 
     177    my $item; 
     178    my $res = $self->{mecha}->get($link); 
     179    return $item unless $self->{mecha}->success; 
     180 
     181    my $html = $self->{mecha}->content; 
     182 
     183    chomp( my $re  = $self->top_re ); 
     184    if ($html =~ /$re/s) { 
     185        $item->{image} = $1; 
     186        $item->{name}  = $2; 
     187    } 
     188 
    147189    return $item; 
    148190} 
     
    185227} 
    186228 
     229sub top_re { 
     230    return <<'RE'; 
     231<a href="http://frepa\.livedoor\.com/.*?/"><img src="(http://img\d+\.ico\.frepa\.livedoor\.com/member_photo/.*?\.(?:jpe?g|JPE?G|gif|GIF))" border="0"></a> 
     232</small> 
     233.*? 
     234<div id="namebody"><small><strong>(.*?)....</strong> 
     235RE 
     236} 
     237 
    1872381; 
    188239__END__