PDA

View Full Version : Pausing RSS scroller JavaScript engine



arcani
10-19-2006, 02:46 AM
1) Script Title:
Pausing RSS scroller
2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex17/rsspausescroller/index.htm
3) Describe problem:

php array association syntax error:(filename:scrollbrigde.php:line74)

writen:
echo "rsscontentdata.$divid" . "[$i]={link:\"" . sla****($item[link]) . "\", title:\"" . sla****($item[title]) . "\", description:\"" . sla****($item[description]) . "\", date:\"" . sla****($item[pubDate]) . "\"}\n";

the script above produce notice that prevent browser to work properly (stop at all).


suppose to be:
echo "rsscontentdata.$divid" . "[$i]={link:\"" . sla****($item["link"]) . "\", title:\"" . sla****($item["title"]) . "\", description:\"" . sla****($item["description"]) . "\", date:\"" . sla****($item["pubDate"]) . "\"}\n";

note: since PHP 4.3 array association with text should be using "" mark, otherwise parser will consider it as constant.

slade24
10-26-2006, 02:44 AM
I suggest that the outputRSS_JS function be revised to the following:



function outputRSS_JS($url, $divid) {
global $rss;
if ($rs = $rss->get($url)){
echo "rsscontentdata.$divid=new Array();\n";
$i=0;
foreach ($rs['items'] as $item) {
echo "rsscontentdata.$divid" . "[$i]={link:\"" . sla****($item['link']) . "\", title:\"" . sla****($item['title']) . "\", description:\"" . sla****($item['description']) . "\", date:\"" . sla****($item['pubDate']) . "\"}\n";
$i++;
}
echo "CurTime = new Date();\n";
if ($rs['items_count'] <= 0) { echo "rsscontentdata.$divid" . "[0]={link:\"" . "" . "\", title:\"" . "Error" . "\", description:\"" . "Sorry, no items found in the RSS file" . "\", date: CurTime}\n"; }
}
else {
echo "rsscontentdata.$divid=new Array();\n";
echo "CurTime = new Date();\n";
echo "rsscontentdata.$divid" . "[0]={link:\"" . "" . "\", title:\"" . "Error" . "\", description:\"" . "Sorry: It's not possible to reach RSS file $url" . "\", date: CurTime}\n";
// All else fails
// Prevents other scrollers from freezing due to incorrect data format being sent to Javascript functions
}
}


The later half (the main "else" statement) has been changed in order to send data to the javascript functions. Without this, any time a single rss file fails to open, all rsspausescrollers on the page will freeze. With this change, only the failed file's scroller will show a problem, which will display error text formatted by the javascript. This should make pages that use multiple scrollers less prone to complete failure.