Changeset 238

Show
Ignore:
Timestamp:
08/25/06 13:41:23 (2 years ago)
Author:
miya
Message:

merge revision 1600

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plagger/trunk/lib/Plagger/Entry.pm

    r107 r238  
    33 
    44use base qw( Plagger::Thing ); 
    5 __PACKAGE__->mk_accessors(qw( title author tags date link feed_link id summary body rate icon meta source enclosure )); 
     5__PACKAGE__->mk_accessors(qw( title author tags link feed_link id summary body rate icon meta source )); 
     6__PACKAGE__->mk_date_accessors(qw( date )); 
    67 
    78use Digest::MD5; 
     
    1314    my $class = shift; 
    1415    bless { 
    15         rate      => 0, 
    16         widgets   => [], 
    17         tags      => [], 
    18         meta      => {}, 
    19         enclosure => [], 
     16        rate    => 0, 
     17        widgets => [], 
     18        tags    => [], 
     19        meta    => {}, 
     20        enclosures => [], 
    2021    }, $class; 
    2122} 
     
    6768sub body_text { 
    6869    my $self = shift; 
    69     Plagger::Util::strip_html($self->body); 
     70    Plagger::Util::strip_html($self->body || ''); 
    7071} 
    7172 
    7273sub add_enclosure { 
    7374    my($self, $enclosure) = @_; 
    74     push @{ $self->{enclosure} }, $enclosure; 
     75 
     76    # don't add enclosure with the same URL again and again 
     77    unless ($enclosure->url && grep { $_->url && $_->url eq $enclosure->url } $self->enclosures) { 
     78        push @{ $self->{enclosures} }, $enclosure; 
     79    } 
     80
     81 
     82sub enclosure { 
     83    my $self = shift; 
     84    wantarray ? @{$self->{enclosures}} : $self->{enclosures}->[0]; 
     85
     86 
     87sub enclosures { 
     88    my $self = shift; 
     89    wantarray ? @{$self->{enclosures}} : $self->{enclosures}; 
     90
     91 
     92sub has_enclosure { 
     93    my $self = shift; 
     94    scalar @{$self->{enclosures}} > 0; 
     95
     96 
     97sub digest { 
     98    my $self = shift; 
     99    my $data = $self->title . ($self->body || ''); 
     100    Encode::_utf8_off($data); 
     101    Digest::MD5::md5_hex($data); 
    75102} 
    76103