Changeset 1580

Show
Ignore:
Timestamp:
08/24/06 02:29:30
Author:
miyagawa
Message:

Added Atom textConstruct support to read original content@type in atom:content and atom:summary. Actually the support partial since XML::Atom doesn't return @type of summary, and XML::Feed doesn't handle Atom 1.0 @type very well

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/hackathon-summary/plagger/lib/Plagger/Plugin/Aggregator/Simple.pm

    r1539 r1580  
    77use Plagger::FeedParser; 
    88use Plagger::UserAgent; 
     9use Plagger::Text; 
    910use List::Util qw(first); 
    1011use UNIVERSAL::require; 
     
    136137        $entry->feed_link($feed->link); 
    137138        $entry->id($e->id); 
    138         $entry->body($e->content->body || $e->summary->body); 
    139         if ($e->summary->body) { 
    140             $entry->summary($e->summary->body); 
    141         } 
     139 
     140        my $content = feed_to_text($e, $e->content); 
     141        my $summary = feed_to_text($e, $e->summary); 
     142        $entry->body($content || $summary); 
     143        $entry->summary($summary) if $summary; 
    142144 
    143145        # enclosure support, to be added to XML::Feed 
     
    226228} 
    227229 
     230sub feed_to_text { 
     231    my($e, $content) = @_; 
     232    return unless $content->body; 
     233 
     234    if (ref($e) eq 'XML::Feed::Entry::Atom') { 
     235        # in Atom, be a little strict with TextConstruct 
     236        # TODO: this actually doesn't work since XML::Feed and XML::Atom does the right 
     237        # thing with Atom 1.0 TextConstruct 
     238        if ($content->type eq 'text/plain' || $content->type eq 'text') { 
     239            return Plagger::Text->new(type => 'text', data => $content->body); 
     240        } else { 
     241            return Plagger::Text->new(type => 'html', data => $content->body); 
     242        } 
     243    } elsif (ref($e) eq 'XML::Feed::Entry::RSS') { 
     244        # in RSS there's no explicit way to declare the type. Just guess it 
     245        return Plagger::Text->new_from_text($content->body); 
     246    } else { 
     247        die "Something is wrong: $e"; 
     248    } 
     249} 
     250 
    228251sub _u { 
    229252    my $str = shift; 
  • branches/hackathon-summary/plagger/lib/Plagger/Thing.pm

    r1527 r1580  
    44 
    55use Plagger::Text; 
     6use Scalar::Util qw(blessed); 
    67 
    78sub has_tag { 
     
    5354            if (@_) { 
    5455                my $text = $_[0]; 
    55                 unless (ref($text)) { 
     56                unless ( blessed($text) && $text->isa('Plagger::Text') ) { 
    5657                    $text = Plagger::Text->new_from_text($text); 
    5758                }