#!/usr/bin/perl -w

use strict;

use XML::RSS;
use LWP::Simple;

my $content;

#		'http://stage.dublincore.org/news.rss',
my @remote = (	

		'http://www.ilrt.bristol.ac.uk/discovery/rdf/resources/rss.rdf',
		'http://www.ilrt.bristol.ac.uk/discovery/rdf-dev/roads/cgi-bin/desire/ig2rss?list=www-rdf-interest',
		'http://www.ilrt.bristol.ac.uk/discovery/rdf-dev/roads/cgi-bin/desire/ig2rss?list=www-rdf-logic',
		'http://xmlhack.com/rss10.php?cat=28',
		'http://rdfig.xmlhack.com/index.rss',
		'http://www.blogspace.com/rss/rss10',
		'http://www.slashdot.com/slashdot.rdf',
		'http://www.w3.org/2000/08/w3c-synd/home.rss',
		'http://agents.umbc.edu/awchannel.rdf'
		);


# www annotation list has unpredictable URLs
#
#	'http://www.ilrt.bristol.ac.uk/discovery/rdf-dev/roads/cgi-bin/desire/ig2rss?list=www-annotation',,

# bookmark feed: xml wellformedness errors
#	http://www.ilrt.bristol.ac.uk/discovery/demos/RSSWeb/newitems-daniel.brickley@bristol.ac.uk/',

# TODO: use eval () to recover from XML::RSS errors


print ilrt_header();

print "last update: ".`date`."<br />"; #sigh, can't be bothered to perlman

print <<HTML;  
<table> 
HTML

my @todo=@remote;

print "<div align=\"center\">\n";

my $verbo = 'full'; # verbosity
while  (@todo) {
  my $lhs = shift @todo;
  my $mid = shift @todo;
  my $rhs = shift @todo;
  print "<tr>";
  cell($lhs , $verbo );
  cell($mid , $verbo );
  cell($rhs, $verbo );
  print "</tr>";
}

print "</div>\n\n";

sub cell {
  my $uri=shift;
  my $full =shift;
  if (!$uri) { return; }
  my $rss = new XML::RSS;

#  eval (" 
  my $content = get($uri);
 
  $rss->parse($content);
  print "<td valign=\"top\">\n";
  print_html($rss , $full);
  print "</td>\n";
  return '';
}

print <<HTML;
</tr>
</table>
HTML



print ilrt_footer();


sub ilrt_header {
my $verbosity = shift;

return <<HTML;
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>


<link rel="stylesheet" type="text/css" 
        href="http://www.ilrt.bristol.ac.uk/discovery/2000/10/docstyle/channels.css" />

  <title>ILRT RDF and Metadata channel listing</title>
</head>
<body bgcolor="#ffffff">
<div><a href="/discovery/"><img src="/discovery/images/rudolf-small.gif"
border="0"
alt="RDF hacking" align="right" /></a> <a href="/"><img
src="http://www.ilrt.bris.ac.uk/images/nav_logo.gif"
alt="ILRT Home" border="0" align="right" /></a></div>

<h1>RDF At A Glance...</h1>

<p><strong>Newsfeeds for Semantic Web developers...</strong>
[<a href="#disclaimer">disclaimer!</a>]
</p>

<p>
<small>
W3C RDF: <a href="http://www.w3.org/RDF/">RDF home page</a>, <a href=
"http://www.w3.org/RDF/Interest/">Interest Group</a>, <a
href="http://www.w3.org/TR/REC-rdf-syntax">Model+Syntax spec</a>, <a
href="http://www.w3.org/TR/2000/CR-rdf-schema-20000327">Schema spec</a>,
<a href="http://www.w3.org/2000/01/sw">Semantic Web development</a>
<br />
More RDF info: <a href="resources/">Dave Beckett's Resource Guide</a>, 
<a href="http://www.xml.com/pub/a/2001/01/24/rdf.html">XML.com: What is
RDF?</a>, <a href="http://www.w3.org/1999/11/11-WWWProposal/thenandnow">RDF then and now</a>

<br />
Nearby at ILRT: <a
href="http://www.redland.opensource.ac.uk/">Redland</a>, <a
href="http://swordfish.rdfweb.org/rdfquery/">Rudolf RDFQuery</a>, <a
href="http://www.ilrt.bristol.ac.uk/discovery/demos/xjg/">XJG</a>, <a
href="http://rdfweb.org/">RDFWeb</a>, <a
href="http://rdfviz.org/">RDFViz</a>
 </small>

</p>



HTML
}

sub ilrt_footer {
return <<HTML;

<hr />
<address>
<a href="mailto:danbri\@rdfweb.org">danbri\@rdfweb.org</a>, ILRT Bristol.
</address>


<a name="disclaimer"></a>
<h3>Disclaimer</h3>

<p>Note: this RSS channel viewer should be considered experimental. The
mail-archive based channels need work. The XHTML needs attention: layout,
style and validity... Send channel suggestions to <a
href="mailto:danbri\@rdfweb.org">me</a> for now; eventually it'll read
these from the Web instead.

--dan</p>

</body>
</html>
HTML
}

###################################### RSS 2 HTML code (from xml:rss)

# SUBROUTINES
sub print_html {
    my $rss = shift;
    my $full = shift;

    print <<HTML;
<table bgcolor="#000000" border="0" width="100%"><tr><td>
<TABLE CELLSPACING="1" CELLPADDING="4" BGCOLOR="#DDDDDD" BORDER=0
width="100%">
  <tr>
  <td valign="middle" align="center" bgcolor="#CCCCCC"><font
color="#000000"
face="Arial,Helvetica">
<strong><a
href="$rss->{'channel'}->{'link'}">$rss->{'channel'}->{'title'}</a>
</strong>
</font>
<p>
<em>$rss->{'channel'}->{'description'} </em>
</p>
</td></tr>

<tr><td>
HTML

    # print channel image
    if ($rss->{'image'}->{'link'}) {
	print <<HTML;
<center>
<p><a href="$rss->{'image'}->{'link'}"><img src="$rss->{'image'}->{'url'}" alt="$rss->{'image'}->{'title'}" border="0"
HTML
        print " width=\"$rss->{'image'}->{'width'}\""
	    if $rss->{'image'}->{'width'};
	print " height=\"$rss->{'image'}->{'height'}\""
	    if $rss->{'image'}->{'height'};
	print "></a></center><p>\n";
    }

    # print the channel items
    foreach my $item (@{$rss->{'items'}}) {
	next unless defined($item->{'title'}) && defined($item->{'link'});
	print "<li><p><a href=\"$item->{'link'}\">$item->{'title'}</a><br />\n";

        if ($full && $item->{'description'} ) { 
	  print "<small>";
  	  print $item->{'description'};
	  print "</small></p>"; 
	}

        print "</li>\n";
    }

    # if there's a textinput element
    if ($rss->{'textinput'}->{'title'}) {
	print <<HTML;
<form method="get" action="$rss->{'textinput'}->{'link'}">
$rss->{'textinput'}->{'description'}<br /> 
<input type="text" name="$rss->{'textinput'}->{'name'}"><br />
<input type="submit" value="$rss->{'textinput'}->{'title'}">
</form>
HTML
    }

    # if there's a copyright element
    if ($rss->{'channel'}->{'copyright'}) {
	print <<HTML;
<p><sub>$rss->{'channel'}->{'copyright'}</sub></p>
HTML
    
    return 0;
    }




    print <<HTML;
</td>
</TR>
</TABLE>
</td></tr></table>
HTML
}







