<rss "http://meatballwiki.org/wiki/action=rss&days=1">
See MeatBall:RssInclusion for a discussion on the impact on online communities.
Make sure you set your HttpCharset to either "UTF-8" or "ISO-8859-1". Any other charset results in undefined behaviour -- you should check the StoreRss? subroutine first, before doing it.
In CommonMarkup, add a new rule for the rss tag after the nowiki, pre and code tags:
if ($doLines < 2) { # 2 = do line-oriented only # The <nowiki> tag stores text with no markup (except quoting HTML) s/\<nowiki\>((.|\n)*?)\<\/nowiki\>/&StoreRaw($1)/ige; # The <pre> tag wraps the stored text with the HTML <pre> tag s/\<pre\>((.|\n)*?)\<\/pre\>/&StorePre($1, "pre")/ige; s/\<code\>((.|\n)*?)\<\/code\>/&StorePre($1, "code")/ige; # The <rss "uri..."> stores the parsed RSS of the given URI s/\<rss +"(.*)"\>/&StoreRss($1)/ige;
Add a new subroutine after StoreRaw:
sub StoreRss { require XML::RSS2; require LWP::UserAgent; my ($uri) = @_; my $rss = new XML::RSS; my $ua = LWP::UserAgent->new; my $request = HTTP::Request->new('GET', $uri); my $response = $ua->request($request); my $data = $response->content; my $maxitems = 15; # recommended max. by the validator eval { $rss->parse($data); }; if ($@) { return "[RSS parsing failed for $uri]"; } else { my $counter = 0; my $str .= "<ul>\n"; for my $i (@{$rss->{items}}) { $counter++; last if $counter == $maxitems; $str .= qq{<li><a href="$i->{'link'}">[$i->{'title'}]</a>}; $str .= qq{ -- $i->{'description'}} if $i->{'description'}; } $str .= "</ul>\n"; if ($HttpCharset eq '' or $HttpCharset eq 'UTF-8') { return &StoreRaw($str); } elsif ($HttpCharset eq "ISO-8859-1") { require Unicode::String; my $u = Unicode::String->new($str); return &StoreRaw($u->latin1); } else { # FIXME: This is perhaps broken. require Unicode::String; require Unicode::Map8; my $u = Unicode::String->new($str); my $m = Unicode::Map8->new($HttpCharset); return &StoreRaw($m->to8($u->ucs2)); } } }
Q: Could anyone fix the bug in this patch? (require XML::RSS2 and my new=XML::RSS ?)
use XML::RSS
and $rss=XML::RSS->new
quite happily both on Perl 5.6.1/XML::RSS 0.97 and Perl 5.8/XML::RSS 1.02.
horus@offler: ~ $ testrss https://www.usemod.org/cgi-bin/wiki.pl?action=rss 'https://www.usemod.org/cgi-bin/wiki.pl?SiteList' 'SiteList''new server url for wikiuniverse (ns propagation in progress)' 'https://www.usemod.org/cgi-bin/wiki.pl?SandBox' 'SandBox' horus@offler: ~ $
Thanx for help. --BernhardZechmann
<rss "http://..." maxitems = 10 >
.
$i->{'description'}
may contain HTMLish tags that must be encoded as entities.
<rss...>
tags on one line are still working. That's a mess when using tables for two-colomn output. The pattern was to greedy."
Here's the updated patch to 1.0 (press edit page and copy from edit view):
*** wiki 2003-11-01 12:16:19.000000000 +0000 --- testwiki 2003-11-01 12:11:19.000000000 +0000 *************** *** 1608,1613 **** --- 1608,1615 ---- # The <pre> tag wraps the stored text with the HTML <pre> tag s/\<pre\>((.|\n)*?)\<\/pre\>/&StorePre($1, "pre")/ige; s/\<code\>((.|\n)*?)\<\/code\>/&StorePre($1, "code")/ige; + # The <rss "uri..."> stores the parsed RSS of the given URI + s/\<rss +"([^"]*)"\s*(?:maxitems\s*=\s*(\d+))?\s*\>/&StoreRss($1, $2)/ige; if ($EarlyRules ne '') { $_ = &EvalLocalRules($EarlyRules, $_, !$useImage); } *************** *** 1888,1893 **** --- 1890,1937 ---- return $FS . $SaveUrlIndex++ . $FS; } + sub StoreRss { + require XML::RSS; + require LWP::UserAgent; + my ($uri, $maxitems) = @_; + my $rss = XML::RSS->new; + my $ua = LWP::UserAgent->new; + my $request = HTTP::Request->new('GET', $uri); + my $response = $ua->request($request); + my $data = $response->content; + $maxitems ||= 15; # recommended max. by the validator + eval { + $rss->parse($data); + }; + if ($@) { + return "[RSS parsing failed for $uri]"; + } else { + my $counter = 0; + my $str .= "<ul>\n"; + for my $i (@{$rss->{items}}) { + $counter++; + last if $counter > $maxitems; + $str .= qq{<li><a href="$i->{'link'}">[$i->{'title'}]</a>}; + $str .= QuoteHtml(qq{ -- $i->{'description'}}) if $i->{'description'}; + } + $str .= "</ul>\n"; + if ($HttpCharset eq '' or $HttpCharset eq 'UTF-8') { + return &StoreRaw($str); + } elsif ($HttpCharset eq "ISO-8859-1") { + require Unicode::String; + my $u = Unicode::String->new($str); + return &StoreRaw($u->latin1); + } else { + # FIXME: This is perhaps broken. + require Unicode::String; + require Unicode::Map8; + my $u = Unicode::String->new($str); + my $m = Unicode::Map8->new($HttpCharset); + return &StoreRaw($m->to8($u->ucs2)); + } + } + } + sub StorePre { my ($html, $tag) = @_;