Changeset 750

Show
Ignore:
Timestamp:
05/15/06 21:43:32
Author:
miyagawa
Message:
  • Filter::FindEnclosures?: find enclosures from $entry->link as well
  • $entry->add_enclosure de-duplicates enclosures with the same URL
Files:

Legend:

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

    r732 r750  
    7272sub add_enclosure { 
    7373    my($self, $enclosure) = @_; 
    74     push @{ $self->{enclosures} }, $enclosure; 
     74 
     75    # don't add enclosure with the same URL again and again 
     76    unless ($enclosure->url && grep { $_->url && $_->url eq $enclosure->url } $self->enclosures) { 
     77        push @{ $self->{enclosures} }, $enclosure; 
     78    } 
    7579} 
    7680 
  • trunk/plagger/lib/Plagger/Plugin/Filter/FindEnclosures.pm

    r749 r750  
    2020    my($self, $context, $args) = @_; 
    2121 
     22    # check $entry->link first, if it links directly to media files 
     23    $self->add_enclosure($args->{entry}, [ 'a', { href => $args->{entry}->link } ], 'href' ); 
     24 
    2225    my $parser = HTML::TokeParser->new(\$args->{entry}->body); 
    2326    while (my $tag = $parser->get_tag('a', 'embed', 'img')) { 
    2427        if ($tag->[0] eq 'a' ) { 
    25             $self->add_enclosure($args, $tag, 'href'); 
     28            $self->add_enclosure($args->{entry}, $tag, 'href'); 
    2629        } elsif ($tag->[0] eq 'embed') { 
    27             $self->add_enclosure($args, $tag, 'src'); 
     30            $self->add_enclosure($args->{entry}, $tag, 'src'); 
    2831        } elsif ($tag->[0] eq 'img') { 
    29             $self->add_enclosure($args, $tag, 'src', 1); 
     32            $self->add_enclosure($args->{entry}, $tag, 'src', 1); 
    3033        } 
    3134    } 
     
    3336 
    3437sub add_enclosure { 
    35     my($self, $args, $tag, $attr, $inline) = @_; 
     38    my($self, $entry, $tag, $attr, $inline) = @_; 
    3639 
    3740    if ($self->is_enclosure($tag, $attr)) { 
     
    4144        $enclosure->auto_set_type; 
    4245        $enclosure->is_inline($inline); 
    43         $args->{entry}->add_enclosure($enclosure); 
     46        $entry->add_enclosure($enclosure); 
    4447    } 
    4548}