2 # Copyright (C) 2003, 2004 Alex Schroeder <alex@emacswiki.org>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the
16 # Free Software Foundation, Inc.
17 # 59 Temple Place, Suite 330
18 # Boston, MA 02111-1307 USA
20 use CGI qw
/:standard/;
21 use CGI
::Carp
qw(fatalsToBrowser);
26 my $wikins = 'http://purl.org/rss/1.0/modules/wiki/';
27 my $rdfns = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
30 if (not param
('url')) {
32 start_html
('RSS Simplification'),
33 h1
('RSS Simplification'),
34 p
('Translates any RSS feed to Really Simple Syndication ', $output,
35 'It understands ModWiki, and will use wiki:diff as the link,',
36 'and it will add dc:contributor to the description.'),
37 start_form
(-method
=>'GET'),
38 p
('RSS feed: ', textfield
('url', '', 70)),
45 print header
(-type
=>'text/plain; charset=UTF-8');
46 my $rss = new XML
::RSS
(output
=>$output);
47 my $ua = new LWP
::UserAgent
;
48 my $request = HTTP
::Request
->new('GET', param
('url'));
49 my $response = $ua->request($request);
50 my $data = $response->content;
52 local $SIG{__DIE__
} = sub { parse_rss3
(); }; # parsing errors -> try RSS 3.0!
58 foreach my $i (@
{$rss->{items
}}) {
59 if ($i->{dc
}->{contributor
}) {
60 if ($i->{description
}) {
61 $i->{description
} = $i->{description
} . ' -- ' . $i->{dc
}->{contributor
};
63 $i->{description
} = '-- ' .$i->{dc
}->{contributor
};
66 if ($i->{$wikins}->{diff
}) {
67 $i->{link} = $i->{$wikins}->{diff
};
70 print $rss->as_string();
73 # perl simplify.pl 'url=http://localhost/cgi-bin/wiki.pl?search=foo%3braw=1'
78 uri
=> 'http://purl.org/rss/1.0/modules/wiki/'
81 foreach my $entry (split(/\n\n+/, $data)) {
83 while ($entry =~ /(\S+?): (.*?)(?=\n[^\t]|\Z)/sg) {
84 my ($key, $value) = ($1, $2);
85 $value =~ s/\n\t/\n/g;
86 $entry{$key} = $value if $value;
88 push(@entries, \
%entry);
90 # the first entry is the channel
91 my %entry = %{shift(@entries)};
92 $rss->channel(%entry);
95 my %entry = %{shift(@entries)};
96 my %dc = (date
=> $entry{'last-modified'},
97 contributor
=> $entry{generator
},);
98 my %wiki = (size
=> $entry{size
},);
100 $entry{wiki
} = %wiki;
101 for my $key qw(last-modified generator size) { delete $entry{$key}; }
102 $rss->add_item(%entry);
104 print $rss->as_string();