I know there is nothing that an internet forum hates more than some newb coming in and asking a question before contributing, but I'm in a jam so I'm going to give it a try.
I'm creating a news ticker that (should) display multiple RSS feeds in a scrolling box. Problem is, the script I'm using, is only updating the title and not the headlines/stories. I didn't even notice up until now, but the issue is clear to see here: http://www.kurtgiessler.com/symbiance
Most of the code I got by merging different online freeware scripts. Most importantly, rsslib.php from www.2rss.com . Here is the code (all of it, so you can see the other things that make it work):
newsticker.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="symbiance.css" type="text/css">
<title>Symbiance</title>
<script type="text/javascript">
/***********************************************
* Cross browser Marquee II- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
var delayb4scroll=500 //Specify initial delay before marquee starts to scroll on page (2000=2 seconds)
var marqueespeed=1 //Specify marquee scroll speed (larger is faster 1-10)
var pauseit=1 //Pause marquee onMousever (0=no. 1=yes)?
////NO NEED TO EDIT BELOW THIS LINE////////////
var copyspeed=marqueespeed
var pausespeed=(pauseit==0)? copyspeed: 0
var actualheight=''
function scrollmarquee(){
if (parseInt(cross_marquee.style.top)>(actualheight*(-1)+8))
cross_marquee.style.top=parseInt(cross_marquee.style.top)-copyspeed+"px"
else
cross_marquee.style.top=parseInt(marqueeheight)+8+"px"
}
function initializemarquee(){
cross_marquee=document.getElementById("vmarquee")
cross_marquee.style.top=0
marqueeheight=document.getElementById("marqueecontainer").offsetHeight
actualheight=cross_marquee.offsetHeight
if (window.opera || navigator.userAgent.indexOf("Netscape/7")!=-1){ //if Opera or Netscape 7x, add scrollbars to scroll and exit
cross_marquee.style.height=marqueeheight+"px"
cross_marquee.style.overflow="scroll"
return
}
setTimeout('lefttime=setInterval("scrollmarquee()",30)', delayb4scroll)
}
if (window.addEventListener)
window.addEventListener("load", initializemarquee, false)
else if (window.attachEvent)
window.attachEvent("onload", initializemarquee)
else if (document.getElementById)
window.onload=initializemarquee
</script>
</head>
<body>
<div id="marqueecontainer" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed"><div id="vmarquee" style="position: absolute; width: 98%;"><?php
error_reporting(0);
print "<link rel='stylesheet' href='rsslib.css' type='text/css'>\n";
include_once("rsslib.php");
$m=10;
$ch=80;
$t="_blank";
$css="rsslib";
$url="http://www.medicalnewstoday.com/rss/pharma_industry.xml";
rss2html($url,$m,$ch,$t,$css);
$url2="http://www.drugtopics.com/drugtopics/drugtopics.rss?id=10239";
rss2html($url2,$m,$ch,$t,$css);
?></div></div>
</body>
</html>
rsslib.php
<?php
// RSSlib @ 2RSS.com :: RSS directory, RSS scripts, RSS articles, RSS software
// This scripts are distributed for free and are provided "AS IS". Read docs.htm
// Copyright: Ovi Crisan @ www.2RSS.com
// parameters used for caching
$use_cache=false;
$cache_folder="tmp";
$cache_valid=60; // minutes
$display_channel_name=true; // set to false to hide channel name & link
$channel[]=array("","","","","","");
// ***********************************
function rss2html($url,$m=0,$w=0,$target="_blank",$cssprefix="rsslib") {
global $channel,$items,$display_channel_name;
getrss($url);
if($display_channel_name) {
if($channel[1])
print "<a href='{$channel[1]}' target='{$target}' class='{$cssprefix}channel'>";
else
print "<span class='{$cssprefix}channel'>";
print $channel[0];
if($channel[1])
print "</a><br>";
else
print "</span><br>";
}
if($m==0) $m=count($items);
for($i=0;$i<$m;$i++) {
// display items
if($items[$i][1])
print "<a href='{$items[$i][1]}' target='{$target}' class='{$cssprefix}item'>";
else
print "<div class='{$cssprefix}item'>";
print $items[$i][0];
if($items[$i][1])
print "</a><br>";
else
print "</div>";
if($items[$i][2]) {
print "<div class='{$cssprefix}desc'>";
if(($w)&&($w<strlen($items[$i][2])))
print substr($items[$i][2],0,strpos($items[$i][2]," ",$w))." ...";
else
print $items[$i][2];
print "</div>\n";
}
}
if($channel[4]) print "<div class='{$cssprefix}editor'>By {$channel[4]}</div>\n";
if($channel[5]) print "<div class='{$cssprefix}date'>{$channel[5]}</div>\n";
if($channel[3]) print "<div class='{$cssprefix}copyright'>{$channel[3]}</div>\n";
print "<div class='{$cssprefix}copyright'></div><br>\n";
} //end function rss2html
// ***********************************
function getrss($url) {
global $channel,$items;
global $use_cache,$cache_folder,$cache_valid;
if($use_cache) {
$cache_filename=$cache_folder."/".md5($url).".rss";
if(file_exists($cache_filename)) {
$t=filemtime($cache_filename);
$cache_create=((!$t)||($t<strtotime("now")-60*$cache_valid)); }
else
$cache_create=true;
if($cache_create) {
//cache not valid - create it again
$simple = file($url);
$f=fopen($cache_filename,"w");
for($i=0;$i<count($simple);$i++)
fwrite($f,$simple[$i]);
fclose($f);
$simple=implode('',$simple);
}
else
$simple = implode('',file($cache_filename));
}
else
$simple = implode('',file($url));
$p = xml_parser_create();
xml_parse_into_struct($p,$simple,$vals,$index);
xml_parser_free($p);
$type=0;
$tmp[]=array("","","");
$id=0;
for($i=0;$i<count($vals);$i++) {
if(($vals[$i]['tag']=="CHANNEL")&&($vals[$i]['type']=="open")) $id=$vals[$i]['level']+1;
if(($type==0)&&($id==$vals[$i]['level']))
switch($vals[$i]['tag']) {
case "TITLE": $channel[0]=$vals[$i]['value']; break;
case "LINK": $channel[1]=$vals[$i]['value']; break;
case "DESCRIPTION":
case "CONTENT:ENCODED": $channel[2]=$vals[$i]['value']; break;
case "COPYRIGHT":
case "DC:RIGHTS": $channel[3]=$vals[$i]['value']; break;
case "MANAGINGEDITOR":
case "DC:PUBLISHER": $channel[4]=$vals[$i]['value']; break;
case "PUBDATE":
case "DC:DATE": $channel[5]=$vals[$i]['value']; break;
}
else switch($vals[$i]['tag']) {
case "TITLE": $tmp[0]=$vals[$i]['value']; break;
case "LINK": $tmp[1]=$vals[$i]['value']; break;
case "DESCRIPTION":
case "CONTENT:ENCODED": $tmp[2]=$vals[$i]['value']; break;
}
if($vals[$i]['tag']=="ITEM") {
if(($vals[$i]['type']=="open")&&($type==0)) $type=1;
if($vals[$i]['type']=="close") {
$items[]=$tmp;
$tmp[0]="";
$tmp[1]="";
$tmp[2]="";
}
}
}
//print_r($channel);
//print_r($items);
} // end function getrss
?>
I'm not sure exactly why the second instance of the rss2html function is hanging on to only some of the values of the first (notice the title is changing). I've tried calling unset() on different combinations of variables inside the functions of rsslib.php, but to no avail. I even used an unset-all-variables function at different places. Nothing seems to work.
I definitely don't understand the XML conversion process, its why I found a canned script instead of writing one. Perhaps there is something there I'm missing?
Any help is greatly appreciated...
Thanks,
Kurt