| 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 | |
|---|
| | 49 | sub encode_html { |
|---|
| | 50 | HTML::Entities::encode($_[0], q("<>&)); |
|---|