Changeset 108

Show
Ignore:
Timestamp:
02/22/06 18:59:08
Author:
miyagawa
Message:

Fixes Odeo's bad OPML. Refs #43

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Plugin/Subscription/Odeo.pm

    r106 r108  
    22use strict; 
    33use base qw( Plagger::Plugin::Subscription::OPML ); 
     4 
     5use URI::Escape; 
     6use HTML::Entities; 
    47 
    58sub register { 
     
    1922 
    2023    my $uri = URI->new("http://www.odeo.com/profile/$account/opml.xml"); 
    21     $self->load_opml($context, $uri); 
     24    $context->log(debug => "Fetch remote OPML from $uri"); 
     25 
     26    my $response = Plagger::UserAgent->new->get($uri); 
     27    unless ($response->is_success) { 
     28        $context->error("Fetch $uri failed: ". $response->status_line); 
     29    } 
     30 
     31    my $xml = $response->content; 
     32 
     33    # fix Odeo's bad OPML 
     34    $xml =~ s{<outline text="(.*?)" type="link" url="(http://.*?)" count="(\d+)"/>}{ 
     35        my($title, $url, $count) = ($1, $2, $3); 
     36 
     37        $title = uri_unescape($title); 
     38        $title =~ s/\r\n//g; 
     39        $title =~ tr/\+/ /; 
     40        $title = encode_html($title); 
     41        $url   = encode_html($url); 
     42 
     43        qq(<outline text="$title" type="rss" xmlUrl="$url" count="$count"/>) 
     44    }eg; 
     45 
     46    $self->load_opml($context, \$xml); 
     47
     48 
     49sub encode_html { 
     50    HTML::Entities::encode($_[0], q("<>&)); 
    2251} 
    2352