#!/usr/bin/perl

# Copyright (C) 2000-2003 William R Thomas <corvar@theonering.net>
# Last Changed by: $Author: corvar $
# on: $Date: 2003/04/11 09:42:00 $
# Version: $Revision: 1.1 $

# Maintainer: William R Thomas <corvar@theonering.net>
# 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;  Allow for simple installation of RSS data sources
#     into Mozilla browser sidebar.  
# 1.1 3 years worth of misc bug fixes.  Dealing with a more expansive set
#     of domain names than the original version is the major improvement.

# Requirements:
# LWP::Simple
# CGI
# URI::Escape
# XML::Parser

use LWP::Simple;
use XML::RSS;
use URI::Escape;
use CGI;

$page = new CGI;

$DISPLAY = "http://www.theonering.net/staff/corvar/cgi-bin/sidebar.pl";
$SELF = "http://www.theonering.net/staff/corvar/cgi-bin/sidebar-inst.pl";
$tmppath = "/tmp";

# some XUL, if we've generated it 
if($page->param('url')) {
    print $page->header();
    print $page->start_html(-title=>'Mozilla RSS Sidebar Installer',
                            -author=>'Corvar@theonering.net',
                            'bgcolor'=>'#FFFFFF');
    $url = uri_escape($page->param('url'));
    $url =~ s/&/%26/g;
    if( $url =~ /http%3A%2F%2F([A-Za-z0-9\-.]*)%2F(.*)/){
	$site = $1;
	$path = $2;
	$file = uri_unescape("http://".$site.$path);
	$file =~ s/[^a-zA-Z0-9]//g;
	print qq(<table border="0">\n);
	print qq(<tr>\n);
	print qq(<td width="150">\n);
	print qq(<iframe src="$DISPLAY?site=$site&amp;path=/$path" width="150" height="500"></iframe>\n);
	print qq(</td><td width="100%" valign="top">\n);
	$p1 = new XML::RSS;
	print STDERR "$file\n";
	eval { $p1->parsefile($tmppath."/".$file) };
	$title = uri_unescape($p1->channel('title'));
	print "Title: $title<br>\n";
	print qq(<font size="1">\(Note if Title is empty, but the preview displays correctly please hit reload before installing.  This is a small bug in the script which I am too lazy to fix.\)</font>\n);
	print "<p>To the left is an example of what the sidebar will look similar to.  If you wish to install this source into your sidebar, you can click the button below.</P>";
	my $javascript_title = $title;
	$javascript_title =~ s|'|\\'|g;

	print qq(<input type="submit" name="install" value="Install in sidebar" onclick="javascript:sidebar.addPanel('$javascript_title','$DISPLAY?site=$site&path=/$path','')">\n);

	print qq(<br><br><a href="$SELF">Back to Sidebar Installer Start</a>);
    
	print qq(</td></tr></table>\n);
	print $page->end_html;
	exit;
    } else {
	print "A valid url is of the form http://hostname/path/to/file, not $url<br><br>\n";
    }
}

if(! $page->param('url') ) {
    print $page->header();
    print $page->start_html(-title=>'Mozilla RSS Sidebar Installer',
                            -author=>'Corvar@theonering.net',
                            'bgcolor'=>'#FFFFFF');
}

print <<EO_FORM;
<h1>Install a Mozilla Sidebar</h1>
<p>
This installer will evaluate a RSS data source, and if it is valid give you a preview and allow you to install that source as a Mozilla Sidebar.
</p>
<p><font color="red">$msg</font></p>
<form action="$SELF" method="get">
<strong>RSS Data Source</strong>
<br>
<input type="text" name="url" size="35" maxlength="170">
<br>
<p/>
<input type="submit" value="Preview">
</form>

<p>
Or, rather than type a URL in above, you can choose from a number of my favorite RSS sources.
<ul>
<li><a href="$SELF?url=http://www.theonering.net/cgi-bin/lotr2rdf.cgi">TheOneRing.net</a>
<li><a href="$SELF?url=http://slashdot.org/slashdot.rdf">Slashdot</a>
<li><a href="$SELF?url=http://freshmeat.net/backend/fm.rdf">Freshmeat</a>
<li><a href="$SELF?url=http://search.cpan.org/recent.rdf">Recent CPAN Uploads</a>
<li><a href="$SELF?url=http://scriptingnews.userland.com/xml/rss.xml">Scripting News</a>
<li><a href="$SELF?url=http://www.debianplanet.org/debianplanet/backend.php">Debian Planet</a>
<li><a href="$SELF?url=http://www.debianhelp.orgbackend.php">DebianHelp</a>
<li><a href="$SELF?url=http://www.w3.org/2000/08/w3c-synd/home.rss">W3C</a>
<li><a href="$SELF?url=http://www.xmlhack.com/rsscat.php">XMLHack</a>
<li><a href="$SELF?url=http://www.xenite.org/channels/lordoftherings.rss">Xenite.org's Lord of the Rings Channel</a>
<li><a href="$SELF?url=http://www.itn.co.uk/itn.rdf">ITN Online</a>
<li><a href="$SELF?url=http://www.cnn.com/cnn.rss">CNN</a>
<li><a href="$SELF?url=http://newsforge.com/newsforge.rss">Newsforge</a>
<li><a href="$SELF?url=http://www.fool.com/xml/foolnews_rss091.xml">The Motley Fool</a>
<li><a href="$SELF?url=http://p.moreover.com/cgi-local/page?c=Top%20stories%26o=rss">Top News Stories</a>
<li><a href="$SELF?url=http://www.wired.com/news_drop/netcenter/netcenter.rdf">Wired</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/uk/rss091.xml">BBC UK Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/england/rss091.xml">BBC England Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/scotland/rss091.xml">BBC Scotland Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/northern_ireland/rss091.xml">BBC Northern Ireland Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/wales/rss091.xml">BBC Wales Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/world/rss091.xml">BBC World Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/world/americas/rss091.xml">BBC Europe Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/world/europe/rss091.xml">BBC Europe Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/world/africa/rss091.xml">BBC Africa Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/world/asia-pacific/rss091.xml">BBC Asia-Pacific Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/world/middle_east/rss091.xml">BBC Middle East Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/world/south_asia/rss091.xml">BBC South Asia Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/entertainment/rss091.xml">BBC Entertainment Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/entertainment/music/rss091.xml">BBC Music Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/entertainment/film/rss091.xml">BBC Film Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/entertainment/tv_and_radio/rss091.xml">BBC TV and Radio Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/entertainment/showbiz/rss091.xml">BBC Showbiz Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/entertainment/rss091.xml">BBC Arts Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/entertainment/reviews/rss091.xml">BBC Reviews Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/education/rss091.xml">BBC Education Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/education/hot_topics/rss091.xml">BBC Hot Topics Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/education/uk_systems/rss091.xml">BBC UK Systems Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/education/league_tables/rss091.xml">BBC League Tables Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/education/features/rss091.xml">BBC Features Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/business/rss091.xml">BBC Business Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/business/market_data/rss091.xml">BBC Market Data Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/business/your_money/rss091.xml">BBC Your Money Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/business/e-commerce/rss091.xml">BBC E-Commerce Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/business/economy/rss091.xml">BBC Economy Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/business/companies/rss091.xml">BBC Companies Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/business/business_basics/rss091.xml">BBC Business Basics Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/front_page/rss091.xml">BBC Front Page Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/technology/rss091.xml">BBC Technology Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/uk_politics/rss091.xml">BBC UK politics Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/health/rss091.xml">BBC Health Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/sci/tech/rss091.xml">BBC Sci/Tech Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/talking_point/rss091.xml">BBC Talking Point Feed</a>
<li><a href="$SELF?url=http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/programmes/rss091.xml">BBC Programmes Feed</a>


<li><a href="http://www.theonering.net/staff/corvar/cgi-bin/lj-sidebar.pl">LiveJournal Sidebar Installer</a> (this is not an RSS source, it is a different installer)
</ul>
</p>
<p><font color="red">Tips on finding RSS Sources</font>: There are a number of resources to find the URL of the RSS sources you are looking for.  The above list is short and highly subjective (i.e. what I am interested in).  If you are looking for a RSS feed of a different nature, try <a href="http://www.xmltree.com/">XMLTree</a> and <a href="http://my.userland.com/choose">my.userland.com</a> (Userland requires you to register).  The more people who add a particular feed, the more likely I will add a direct link to the feed. 
</p>
<p>
The author, <a href="http://www.theonering.net/staff/corvar/">Corvar</a>, welcomes
<a href="mailto:corvar\@theonering.net">comments</a>.</p>
<p>This script owes quite a bit to the work of DJ Adams on his <a href="http://www.pipetree.com/~dj/cgi-bin/mysidebar.pl">mysidebar.pl</a> script.
EO_FORM

exit;





