error_reporting(0);
// local filename
$blogroll_xml_file = '/home/sites/site123/web/favorites.xml';
// remote file url
$blogroll_xml_source = 'http://blo.gs/5332/favorites.xml';
// something that will always appear in the remote file if it returns any of your favorites
$blogroll_xml_test = 'evhead';
// fresh enough to use? give it a sniff
if ( filemtime($blogroll_xml_file) < (time()-3600) ) {
if ( $blogroll_local_fq = fopen($blogroll_xml_file,"w") ){
$blogroll_remote_fp = fopen($blogroll_xml_source,"r");
$blogroll_remote_data = fread($blogroll_remote_fp, 100000);
if (stristr($blogroll_remote_data, $blogroll_xml_test)){
if ($blogroll_remote_fp && $blogroll_local_fq){
fwrite($blogroll_local_fq,$blogroll_remote_data);
}
}
fclose($blogroll_remote_fp);
fclose($blogroll_local_fq);
}
}
// forget the old filemtime
clearstatcache();
// what to write before the first link or option
$blogroll_html_header = '
';
// what to write after the last link or option
$blogroll_html_footer = '
';
$blogroll_open_tags = array(
'WEBLOGUPDATES' => '',
'WEBLOG' => '');
$blogroll_close_tags = array(
'WEBLOGUPDATES' => '');
function blogrollStartElement($parser, $name, $attrs=''){
global $blogroll_open_tags, $blogroll_temp, $blogroll_current_tag, $blogroll_weblog_index;
$blogroll_current_tag = $name;
if ($format = $blogroll_open_tags[$name]){
switch($name){
case 'WEBLOGUPDATES':
//starting to parse
$blogroll_weblog_index = -1;
break;
case 'WEBLOG':
//indivdual blog
$blogroll_weblog_index++;
$blogroll_temp[$blogroll_weblog_index]['name'] = htmlentities(addslashes((strlen($attrs['NAME']) > 19) ? substr($attrs['NAME'], 0, 17) . "..." : $attrs['NAME']));
$blogroll_temp[$blogroll_weblog_index]['url'] = $attrs['URL'];
break;
default:
break;
}
}
}
function blogrollEndElement($parser, $name, $attrs=''){
global $blogroll_close_tags, $blogroll_temp, $blogroll_current_tag;
if ($format = $blogroll_close_tags[$name]){
switch($name){
case 'WEBLOGUPDATES':
blogrollWriteLinks();
break;
default:
break;
}
}
}
function blogrollWriteLinks(){
global $blogroll_temp, $blogroll_html_header, $blogroll_html_footer, $timestamp;
echo $blogroll_html_header . "\n";
for($i = 0; $i < sizeof($blogroll_temp); $i++){
$blogroll_temp[$i]['name'] = stripslashes(stripslashes($blogroll_temp[$i]['name']));
echo "" . $blogroll_temp[$i]['name'] . " " . strftime($timestamp,
$blogroll_temp[$i]['when']) . "\n";
}
echo $blogroll_html_footer . "\n";
}
// declare the character set - UTF-8 is the default
$blogroll_type = 'ISO-8859-1';
// create our parser
$blogroll_xml_parser = xml_parser_create($blogroll_type);
// set some parser options
xml_parser_set_option($blogroll_xml_parser, XML_OPTION_CASE_FOLDING, true);
xml_parser_set_option($blogroll_xml_parser, XML_OPTION_TARGET_ENCODING, $blogroll_type);
// this tells PHP what functions to call when it finds an element
// these funcitons also handle the element's attributes
xml_set_element_handler($blogroll_xml_parser, 'blogrollStartElement','blogrollEndElement');
if ($blogroll_fp = @fopen($blogroll_xml_file, 'r')) {
// loop through the file and parse baby!
while ($blogroll_data = fread($blogroll_fp, 4096)) {
if (!xml_parse($blogroll_xml_parser, $blogroll_data, feof($blogroll_fp))) {
die(sprintf( "XML error: %s at line %d\n\n",
xml_error_string(xml_get_error_code($blogroll_xml_parser)),
xml_get_current_line_number($blogroll_xml_parser)));
}
}
}
else {
echo"";
}
xml_parser_free($blogroll_xml_parser);
?>