The directory structure I have set up is:
demo.htm
js/rssticker.js
lastrss/lastRSS.php
lastrss/bridge.php
lastrss/cache/
Here is my bridge.php
Code:
<?php
/*
======================================================================
LastRSS bridge script- By Dynamic Drive (http://www.dynamicdrive.com)
Communicates between LastRSS.php to Advanced Ajax ticker script using Ajax. Returns RSS feed in XML format
Created: Feb 9th, 2006. Updated: Feb 9th, 2006
======================================================================
*/
header('Content-type: text/xml');
// include lastRSS
include "lastRSS.php"; //path to lastRSS.php on your server from this script ("bridge.php")
// Create lastRSS object
$rss = new lastRSS;
$rss->cache_dir = 'cache'; //path to cache directory on your server from this script. Chmod 777!
$rss->date_format = 'M d, Y g:i:s A'; //date format of RSS item. See PHP date() function for possible input.
// List of RSS URLs
$rsslist=array(
"LRC_News" => "http://ntcclibrary.wordpress.com/feed/",
"CNN" => "http://rss.cnn.com/rss/cnn_topstories.rss",
"BBC" => "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml",
"news.com" => "http://news.com.com/2547-1_3-0-5.xml",
"slashdot" => "http://rss.slashdot.org/Slashdot/slashdot",
"dynamicdrive" => "http://www.dynamicdrive.com/export.php?type=new"
);
////Beginners don't need to configure past here////////////////////
$rssid=$_GET['id'];
$rssurl=isset($rsslist[$rssid])? $rsslist[$rssid] : die("Error: Can't find requested RSS in list.");
// -------------------------------------------------------------------
// outputRSS_XML()- Outputs the "title", "link", "description", and "pubDate" elements of an RSS feed in XML format
// -------------------------------------------------------------------
function outputRSS_XML($url) {
global $rss;
$cacheseconds=(int) $_GET["cachetime"]; //typecast "cachetime" parameter as integer (0 or greater)
$rss->cache_time = $cacheseconds;
if ($rs = $rss->get($url)) {
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<rss version=\"2.0\">\n<channel>\n";
foreach ($rs['items'] as $item) {
echo "<item>\n<link>$item[link]</link>\n<title>$item[title]</title>\n<description>$item[description]</description>\n<pubDate>$item[pubDate]</pubDate>\n</item>\n\n";
}
echo "</channel></rss>";
if ($rs['items_count'] <= 0) { echo "<li>Sorry, no items found in the RSS file :-(</li>"; }
}
else {
echo "Sorry: It's not possible to reach RSS file $url\n<br />";
// you will probably hide this message in a live version
}
}
// ===============================================================================
outputRSS_XML($rssurl);
?>
Here is the code for demo.htm:
Code:
<!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" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Advanced RSS Ticker (Ajax invocation) demo</title>
<script src="js/rssticker.js" type="text/javascript">
/***********************************************
* Advanced RSS Ticker (Ajax invocation)- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for this script and 100s more
***********************************************/
</script>
<style type="text/css">
/*Sample CSS to style the two tickers in the demo*/
.cnnclass{
width: 22%;
padding: 5px;
background-color: #F3F3F3;
border: 1px solid black;
margin-bottom: 1em;
filter:progid:DXImageTransform.Microsoft.alpha(opacity=80); /*Specify fade effect in IE. Remove if desired.*/
-moz-opacity: 0.8; /*Specify fade effect in Firefox. Remove if desired.*/
}
.cnnclass a{
text-decoration: none;
}
.bbcclass{
width: 22%;
padding: 6px;
background-color: lightyellow;
border: 1px solid #004A00;
filter:progid:DXImageTransform.Microsoft.alpha(opacity=80); /*Specify fade effect in IE. Remove if desired.*/
-moz-opacity: 0.8; /*Specify fade effect in Firefox. Remove if desired.*/
}
.rsstitle{ /*shared class for all title elements in an RSS feed*/
font-weight: bold;
}
.rssdate{ /*shared class for all date elements in an RSS feed*/
color: gray;
font-size: 85%;
}
.rssdescription{ /*shared class for all description elements in an RSS feed*/
}
</style>
</head>
<body>
<div style="height: 225px">
<script type="text/javascript">
//rssticker_ajax(RSS_id, cachetime, divId, divClass, delay, optionalswitch)
//1) RSS_id: "Array key of RSS feed in PHP script"
//2) cachetime: Time to cache the feed in minutes (0 for no cache)
//3) divId: "ID of DIV to display ticker in. DIV dynamically created"
//4) divClass: "Class name of this ticker, for styling purposes"
//5) delay: delay between message change, in milliseconds
//6) optionalswitch: "optional arbitrary" string to create additional logic in call back function
document.write("LRC News:")
new rssticker_ajax("LRC_News", 0, "lrcbox", "cnnclass", 3000, "date")
//document.write("<br />BBC News: (Title+date+description shown)")
new rssticker_ajax("BBC", 1200, "ddbox", "bbcclass", 3500, "date+description")
document.write("<br />News:")
new rssticker_ajax("news.com", 1200, "newsbox", "cnnclass", 3000, "date")
</script>
</div>
<a href="http://www.dynamicdrive.com/dynamicindex17/rsstickerajax/">Advanced RSS Ticker</a>.
</body>
</html>
The only line I changed in rssticker.js is the URL.
Code:
//Relative URL syntax:
var lastrssbridgeurl="../lastrss/bridge.php"
I did not make any changes to lastRSS.php but I can post the code for it and all of rssticker.js if you feel that they would be helpful.
The feed I tried adding is http://ntcclibrary.wordpress.com/feed/
Thanks.
Bookmarks