Does anyone understand why the code below does not work? Please help.
Thanks
....................................................................................................................................................................
<?php
header("Content-type: text/xml");
$arr = array();
$currentElements = array();
$newsArray = array();
$cnt=0;
$num=0;
$type=0;
$start_date='';
$title='';
$link='';
$descr='';
$author='';
$image='';
$all_titles=array();
$output_cache='';
init_rules();
$titles=array();
$sources[0]['url']="http://news.google.com/news?
tab=mn&ned=us&hl=en&ned=us&q=food&ie=UTF-8&nolr=1&output=rss";
$sources[0]['img']="http://www.fanofans.com/czech.jpg";
$sources[1]['url']="http://news.google.com/news?
tab=mn&ned=us&hl=en&ned=us&q=eat&ie=UTF-8&nolr=1&output=rss";
$sources[1]['img']="http://www.fanofans.com/portugal.jpg";
$sources[2]['url']="http://news.google.com/news?
tab=mn&ned=us&hl=en&ned=us&q=milk&ie=UTF-8&nolr=1&output=rss";
$sources[2]['img']="http://www.fanofans.com/switzerland.jpg";
echo "<data>\n";
for ($i=0;$i<sizeof($sources); $i++)
{
$all_titles=array();
$xmlParser = xml_parser_create();
xml_parser_set_option($xmlParser, XML_OPTION_CASE_FOLDING, TRUE);
xml_set_element_handler($xmlParser, startElement, endElement);
xml_set_character_data_handler($xmlParser, characterData);
$fp = fopen($sources[$i]['url'], "rb");
$data = '';
while($newdata = fread($fp, 4096)){
$data .= $newdata;
}
fclose($fp);
xml_parse($xmlParser, $data, 1);
xml_parser_free($xmlParser);
foreach(array_keys($all_titles) as $title) {
$item = ereg_replace("QQQ", $sources[$i]['img'], $all_titles[$title]
['event']);
echo $item."\n";
}
}
echo "</data>\n";
function init_rules() {
add_rule('ITEM', func_item);
add_rule('PUBDATE', func_pubdate);
add_rule('TITLE', func_title);
add_rule('LINK', func_link);
add_rule('DESCRIPTION', func_descr);
add_rule('AUTHOR', func_author);
}
function add_rule($tag, $func) {
global $arr;
$cnt = count($arr);
$arr[$cnt]['rule']=$tag;
$arr[$cnt]['func']=$func;
}
function startElement($parser, $name, $attrs) {
global $currentElements, $cnt, $newsArray, $num, $type, $image;
if ($name=='ENCLOSURE')
{
$image=$attrs["URL"];
}
array_push($currentElements, $name);
$cnt++;
$newsArray[$cnt-1] = '';
}
function characterData($parser, $data) {
global $currentElements, $newsArray, $cnt;
$newsArray[$cnt-1] .= $data;
}
function endElement($parser, $name) {
global $currentElements, $cnt, $newsArray, $trace;
apply_rules();
if($currentElements[$cnt-1] == $name){
array_pop($currentElements);
}
$cnt--;
}
function apply_rules() {
global $arr, $currentElements, $cnt, $newsArray;
$found=0;
for ($i=0; $i<count($arr); $i++) {
if ($arr[$i]['rule'] == $currentElements[$cnt-1]) {
$found=1;
break;
}
}
if ($found) {
$str = $arr[$i]['func']($newsArray[$cnt-1]);
if ($cnt>1) {
$newsArray[$cnt-2].= $str;
}
}
}
function func_item($data) {
global $start_date, $title, $link, $descr, $author, $all_titles,
$output_cache, $image, $titles;
// $icon='http://simile.mit.edu/timeline/api/images/blue-
circle.png';
$icon='http://alexeysmirnov.name/dot1.jpg';
$color='blue';
if (ereg('Pownce', $title)) {
$icon='http://simile.mit.edu/timeline/api/images/green-
circle.png';
$color='green';
} else if (ereg('del.icio.us', $title)) {
$icon='http://simile.mit.edu/timeline/api/images/red-
circle.png';
$color='red';
} else if (ereg('dugg', $title)) {
$icon='http://simile.mit.edu/timeline/api/images/dark-green-
circle.png';
$color='darkgreen';
}
if (ereg('a site on del.icio.us', $title)) {
$title = ereg_replace('a site on del.icio.us', "'".$descr."'",
$title);
}
if (strlen($author)>0) {
$title=ereg_replace($author, 'I', $title);
}
$title=ereg_replace('I posted a new blog entry:', '', $title);
//if (!isset($all_titles[$title]['num'])) {
if (!isset($titles[$title])) {
$titles[$title]=1;
$icon='QQQ';
$all_titles[$title]['event']= "<event\n start=\"" .
$start_date."\"\n" .
" title=\"" . $title."\"\n".
" link=\"" . $link."\"\n" .
" icon=\"" . $icon."\"\n" .
" color=\"" . $color."\"\n" .
" image=\"" . $image . "\"\n" .
">\n" . $descr."\n" . "</event>\n\n";
}
}
function func_title($data) {
global $title, $author, $in_blog;
if (ereg('a new blog entry', $title)) {
$in_blog=1;
} else {
$in_blog=0;
}
if (strlen($author)>0) {
$title=ereg_replace($author, 'I', $data);
} else {
$title=$data;
}
$title=ereg_replace("\"", "'", $title);
}
function func_pubdate($data) {
global $start_date;
$start_date=$data;
}
function func_link($data) {
global $link;
$link=$data;
$link=ereg_replace("&", "&", $link);
}
function func_descr($data) {
global $descr, $link, $in_blog;
preg_match("#a href=\"([^\"]+)\"#", $data, $matches,
PREG_OFFSET_CAPTURE);
if (sizeof($matches)>0) {
$link = $matches[1][0];
$link=ereg_replace("&", "&", $link);
}
$descr=strip_tags($data);
$descr=ereg_replace("»", "", $descr);
}
function func_author($data) {
global $author;
$author=$data;
}
function func_entity($data) {
return $data;
}
?>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"SIMILE Widgets" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/simile-widgets?hl=en
-~----------~----~----~----~------~----~------~--~---