#!/usr/bin/perl # Copyright (C) 2000-2003 William R Thomas # Last Changed by: $Author: corvar $ # on: $Date: 2003/04/11 09:39:00 $ # Version: $Revision: 1.1 $ # Maintainer: William R Thomas # Keywords: convenience # This file is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License # as published by the Free Software Foundation. # This file is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # Revision History: # 1.0 Initial version; Format RSS datasources for convenient display # in a Mozilla browser's sidebar. # 1.1 3 years worth of misc bug fixes. None of major note. Logic to deal # with RSS Version 0.92 and RSS Version 2.0 # Requirements: # LWP::Simple # CGI # URI::Escape # Recommended: # XML::Parser use LWP::Simple; # Uncomment the following line if you are going to use the XML::Parser # Module. This is the recommened method use XML::Parser; use CGI; use CGI::Carp qw(fatalsToBrowser); use URI::Escape; $newStyle=< END $page = new CGI; print $page->header(-Refresh=>'900'); print $page->start_html(-title=>'TheOneRing.net | Sidebar', -author=>'Corvar@theonering.net', 'bgcolor'=>'#FFFFFF', 'target'=>'_content', 'style'=>{-code=>$newStyle}); my $sourceurl = 'http://www.theonering.net/cgi-bin/lotr2rdf.cgi'; my $file = 'foo.rss'; my $path = '/tmp'; my $version = 0; my $channel = 0; my $image = 0; my $item = 0; my $textinput = 0; my $title = 0; my $link = 0; my $description = 0; my $url = 0; my $height = 0; my $width = 0; my($titletmp,$width,$height,$desctmp,$urltmp,$heighttmp,$widthtmp,$linktmp); my($maintitle, $mainlink, $maindesc); if($page->param('site') && $page->param('path')) { if($page->param('path') =~ /^\//) { $sourceurl = "http://".$page->param('site').$page->param('path'); } else { $sourceurl = "http://".$page->param('site')."/".$page->param('path'); } } $file = $sourceurl; $file =~ s/[^a-zA-Z0-9]//g; if((time() - (stat("$path/$file"))[10]) > (60 * 60)) { # print STDERR "Got new\n"; unlink($path."/".$file); getstore($sourceurl,$path."/".$file); open(FILE,$path."/".$file); open(TMP,">".$path."/".$file.".tmp"); while() { if(/(.*)<\/title>/) { print TMP "<title>".uri_escape($1,"\x00-\x1f\x7f-\xff")."\n"; } else { print TMP $_; } } close(FILE); close(TMP); unlink($path."/".$file); link($path."/".$file.".tmp",$path."/".$file); unlink($path."/".$file.".tmp"); } else { # print STDERR "Kept old\n"; } # Uncomment the following two lines if you are going to use the XML::Parser # Module. This is the recommened method $p1 = new XML::Parser(Style => 'Stream'); $p1->parsefile("$path/$file"); # Uncomment the following 22 lines if you are no going to use the XML::Parser # Modules. This method is not recommened. #open(FOO,"<$path/$file"); #while() { # $start = ''; # $text = ''; # $end = ''; # # if(/^$/) { # next; # } # if(/^<(\w+)>(.*)<\/(\w+)>$/) { # $start = $1; # $text=$2; # $end=$3; # $_ = $1; # &StartTag; # $_ = $2; # &Text; # $_ = $3; # &EndTag; # } elsif( /^<(\w+)>$/) { # $_ = $1; # &StartTag; # } elsif( /^<\/(\w+)>$/) { # $_ = $1; # &EndTag; # } #} print ""; print $page->end_html; sub StartTag { if( $_ =~ /rss version.*0.91/) { $version = '0.91'; } if( $_ =~ /rss version.*0.92/) { $version = '0.92'; } if( $_ =~ /rss version.*2.0/) { $version = '2.0'; } if( $_ =~ /channel/) { $channel = 1; } if( $_ =~ /item/) { $item = 1; } if( $_ =~ /image/) { $image = 1; } if( $_ =~ /textinput/) { $textinput = 1; } if( $_ =~ /title/) { $title = 1; } if( $_ =~ /link/) { $link = 1; } if( $_ =~ /description/) { $description = 1; } if( $_ =~ /url/) { $url = 1; } if( $_ =~ /height/) { $height = 1; } if( $_ =~ /width/) { $width = 1; } } sub EndTag { if( $_ =~ /channel/) { $channel = 0; } if( $_ =~ /title/) { $title = 0; } if( $_ =~ /link/) { $link = 0; } if( $_ =~ /description/) { $description = 0; } if( $_ =~ /url/) { $url = 0; } if( $_ =~ /height/) { $height = 0; } if( $_ =~ /width/) { $width = 0; } if($channel && ($version != '0.91' && $version != '0.92' && $version != '2.0')) { return;} if( $_ =~ /item/) { $item = 0; print qq(\n); print "•\n"; print qq(\n); print "".$titletmp."
\n"; print qq(\n); $linktmp = ''; $titletmp = ''; } if( $_ =~ /image/) { print qq(\n); print qq(\n\n); $image = 0; } } sub Text { if($title) { $titletmp = $_; if($channel && !$image && !$link && !$testinput) { $maintitle = $titletmp; } } if($description) { $desctmp = $_; if($channel && !$image && !$link && !$testinput) { $maindesc = $desctmp; } } if($link) { $linktmp = $_; if($channel && !$image && !$link && !$testinput) { $mainlink = $linktmp; } } if($url) { $urltmp = $_; } if($height) { $heighttmp = $_; } if($width) { $widthtmp = $_; } }
\n); print "
\n"; print "\"$desctmp\"\n"; print "
\n"; if(length($maindesc) > 50) { $maindesc = substr($maindesc,0,50)."..."; } print "".uri_unescape($maintitle).": $maindesc\n"; print qq(