#!/usr/bin/perl # # Name: RSS to HTML converter # Description: Converts a RSS Source into HTML. # Copyright (C) 2000 William R Thomas # Author: William R Thomas (aka Corvar) # Distribution site: http://www.theonering.net/staff/corvar/software/ # # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program 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. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # GPL Reference: http://www.gnu.org/copyleft/gpl.html # 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; print "Content-type: text/html\n\n"; my $sourceurl = 'http://www.theonering.net/cgi-bin/lotr2rdf.cgi'; my $file = 'foo.rss'; my $path = '/tmp'; 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((time() - (stat("$path/$file"))[10]) > (60 * 60)) { getstore($sourceurl,$path."/".$file); } # 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; # } #} sub StartTag { 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/) { print "\n"; $channel = 0; } if( $_ =~ /item/) { $item = 0; print "$titletmp
\n"; $linktmp = ''; $titletmp = ''; } if( $_ =~ /image/) { print "
\n"; print "\"$desctmp\"\n"; print "
\n"; print "$maintitle: $maindesc\n"; print "

\n"; $image = 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; } } 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 = $_; } }