]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/aggregate.pm
Add modified opengraph plugin.
[git.ikiwiki.info.git] / IkiWiki / Plugin / aggregate.pm
index be7da3a710ec66a6243f414d9de62a49580bf6ad..2069a352ede751eff1597da5d13e960401e5da48 100644 (file)
@@ -513,7 +513,10 @@ sub aggregate (@) {
                        }
                        $feed->{feedurl}=pop @urls;
                }
-               my $ua=useragent();
+               # Using the for_url parameter makes sure we crash if used
+               # with an older IkiWiki.pm that didn't automatically try
+               # to use LWPx::ParanoidAgent.
+               my $ua=useragent(for_url => $feed->{feedurl});
                my $res=URI::Fetch->fetch($feed->{feedurl}, UserAgent=>$ua);
                if (! $res) {
                        $feed->{message}=URI::Fetch->errstr;
@@ -532,6 +535,14 @@ sub aggregate (@) {
                        next;
                }
                my $content=$res->content;
+
+               # This is a hack to support the media:content extension
+               # to RSS. XML::Feed does not support it, but it's the same
+               # as an enclosure, so converting it to that tag will let it
+               # parse.
+               $content=~s/<media:content/<enclosure/g;
+               $content=~s/<\/media:content/<\/enclosure/g;
+
                my $f=eval{XML::Feed->parse(\$content)};
                if ($@) {
                        # One common cause of XML::Feed crashing is a feed
@@ -587,6 +598,10 @@ sub aggregate (@) {
                                title => defined $entry->title ? decode_entities($entry->title) : "untitled",
                                author => defined $entry->author ? decode_entities($entry->author) : "",
                                link => $entry->link,
+                               enclosureurl => defined $entry->enclosure ? $entry->enclosure->url : "",
+                               enclosureimage => (defined $entry->enclosure && $entry->enclosure->type =~ m/image\//) ? "1" : "",
+                               enclosureaudio => (defined $entry->enclosure && $entry->enclosure->type =~ m/audio\//) ? "1" : "",
+                               enclosurevideo => (defined $entry->enclosure && $entry->enclosure->type =~ m/video\//) ? "1" : "",
                                content => (defined $c && defined $c->body) ? $c->body : "",
                                guid => defined $entry->id ? $entry->id : time."_".$feed->{name},
                                ctime => $entry->issued ? ($entry->issued->epoch || time) : time,
@@ -621,11 +636,11 @@ sub add_page (@) {
                # escape slashes and periods in title so it doesn't specify
                # directory name or trigger ".." disallowing code.
                $page=~s!([/.])!"__".ord($1)."__"!eg;
-               $page=$feed->{dir}."/".$page;
-               ($page)=$page=~/$config{wiki_file_regexp}/;
                if (! defined $page || ! length $page) {
                        $page=$feed->{dir}."/item";
                }
+               $page=$feed->{dir}."/".$page;
+               ($page)=$page=~/$config{wiki_file_regexp}/;
                my $c="";
                while (exists $IkiWiki::pagecase{lc $page.$c} ||
                       -e $IkiWiki::Plugin::transient::transientdir."/".htmlfn($page.$c) ||
@@ -697,6 +712,14 @@ sub write_page ($$$$$) {
                if defined $params{copyright} && length $params{copyright};
        $template->param(permalink => IkiWiki::urlabs($params{link}, $feed->{feedurl}))
                if defined $params{link};
+       $template->param(enclosureurl => $params{enclosureurl})
+               if defined $params{enclosureurl} && length $params{enclosureurl};
+       $template->param(enclosureimage => $params{enclosureimage})
+               if defined $params{enclosureimage} && length $params{enclosureimage};
+       $template->param(enclosureaudio => $params{enclosureaudio})
+               if defined $params{enclosureaudio} && length $params{enclosureaudio};
+       $template->param(enclosurevideo => $params{enclosurevideo})
+               if defined $params{enclosurevideo} && length $params{enclosurevideo};
        if (ref $feed->{tags}) {
                $template->param(tags => [map { tag => $_ }, @{$feed->{tags}}]);
        }