We have a GL site and somebody wanted to sydicate the news with javascipt because they could not run any server side stuff. I whipped this up for them pretty quick, so I thought others might like it as well.
To put your news on another page via javascript use the following code on the page.
Text Formatted Code
<script src="http://yoururl.com/javascriptnewsfeed.php">
</script>
Text Formatted Code
<?php
require_once('lib-common.php');
function COM_rdfexportforjavascript( $rdfurl )
{
global $_TABLES, $RDFinsideitem, $RDFtag, $RDFtitle, $RDFlink, $RDFheadlines;
$RDFinsideitem = false;
$RDFtag = '';
$RDFtitle = '';
$RDFlink = '';
$RDFheadlines = array();
clearstatcache();
$rdferror = false;
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, 'COM_rdfStartElement', 'COM_rdfEndElement');
xml_set_character_data_handler( $xml_parser, 'COM_rdfCharacterData' );
if( $fp = fopen( $rdfurl, 'r' ))
{
while( $data = fread( $fp, 4096 ))
{
//echo htmlentities($data) ;
if( !xml_parse( $xml_parser, $data, feof( $fp )))
{
$errmsg = sprintf(
"Parse error in %s: %s at line %d",
$rdfurl,
xml_error_string( xml_get_error_code( $xml_parser )),
xml_get_current_line_number( $xml_parser )
);
//COM_errorLog( $errmsg, 1 );
echo $errmsg ;
$rdferror = true;
break;
}
}
fclose( $fp );
xml_parser_free( $xml_parser );
if( !$rdferror )
{
foreach($RDFheadlines as $headline)
{
$javascript .= "document.write('" . addslashes(stripslashes($headline)) . '<br>r')' ."r" ;
}
$RDFheadlines = array();
echo $javascript ;
}
}
else
{
$rdferror = true;
COM_errorLog( "Can not reach $rdfurl", 1 );
echo
"GeekLog can not reach the supplied RDF file at $update. "
. "Please double check the URL provided. Make sure your url is correctly entered and it begins with "
. "http://. GeekLog will try in one hour to fetch the file again." ;
}
}
COM_rdfexportforjavascript($_CONF['rdf_file'] )
?>