#!/usr/bin/perl
# RSS2cisco, An RSS feed to Cisco IP Phone Script version 0.6
# Copyright 2004, Joshua Cantara <[email protected]>
# This program is licensed under the GPL: http://www.gnu.org/licenses/gpl.txt
# Newest version can always be found at: http://dontpokebadgers.com/rss2cisco/
use strict;
use LWP::Simple qw($ua get);;
use CGI;
print "Content-Type: text/xml\n\n";
################################################
# MAIN MENU
################################################
my $query = new CGI;
if (!$query->param('rssurl'))
{
&printmenu;
}
elsif ($query->param('rssurl') ne '')
{
&printfeed;
}
else {
&error;
}
exit;
################################################
# PRINT A MENU OF FEEDS
# Useage: &printmenu;
################################################
sub printmenu {
# Change the following to the location of rss2cisco.pl on your server
my $pathto = 'http://www.yourserver.cc/folder/name';
$pathto = $pathto . '/rss2cisco.pl?rssurl';
# Add/Remove RSS feeds below. There is a max of 64 feeds. Remember to remove the "http://"
print qq|
<CiscoIPPhoneMenu>
<Title>Choose an RSS Feed</Title>
<Prompt>Make a selection</Prompt>
<MenuItem>
<Name>Slashdot</Name>
<URL>$pathto=slashdot.org/index.rss</URL>
</MenuItem>
<MenuItem>
<Name>NHPR</Name>
<URL>$pathto=nhpr.org/view_rss</URL>
</MenuItem>
<MenuItem>
<Name>BBC World</Name>
<URL>$pathto=www.bbc.co.uk/syndication/feeds/news/ukfs_news/world/rss091.xml</URL>
</MenuItem>
<MenuItem>
<Name>Wired News</Name>
<URL>$pathto=www.wired.com/news_drop/netcenter/netcenter.rdf</URL>
</MenuItem>
</CiscoIPPhoneMenu>
|;
}
################################################
# PRINT A SINGLE RSS FEED
# Useage: &printfeed($address);
################################################
sub printfeed {
my $query = new CGI;
my $rssfeed = $query->param('rssurl');
$rssfeed = 'http://' . $rssfeed;
$ua->timeout(15);
my $rssxml = get $rssfeed;
print qq|
<CiscoIPPhoneText>
<Title>RSS2Cisco</Title>
<Prompt></Prompt>
<Text>|;
# For the record, the following is an awful excuse for an XML parser
# but I didn't want to require a whole module just to spit out the
# title and description fields.
my @items = split(/<item/,$rssxml);
foreach my $item (@items)
{
my ($title,$description);
$item =~ s/&#(.*?);//g;
if ($item =~ m@</item>@)
{
if ($item =~ m@<title>(.*?)</title>@)
{
$title = $1;
}
if ($item =~ m@<description>(.*?)</description>@)
{
$description = $1;
}
print "$title\n $description\n\n";
}
}
print qq|</Text>
</CiscoIPPhoneText>
|;
}
###############################################################
# PRINT ERROR MESSAGE
# Useage: &error;
###############################################################
sub error {
print qq|
<CiscoIPPhoneText>
<Title>Error...</Title>
<Prompt></Prompt>
<Text>There was an error.</Text>
</CiscoIPPhoneText>
|;
}