Reading " . $from_xml_file . "


"; } // fresh enough to use? give it a sniff if ( filemtime($from_xml_file) < (time()-($timeoutSync)) ) { $from_remote_fp = fopen($from_xml_source, "rb"); $from_remote_data = ''; while (!feof($from_remote_fp)) { $from_remote_data .= fread($from_remote_fp, 1024); } fclose($from_remote_fp); $from_local_fq = fopen($from_xml_file,"w"); if ($from_remote_fp && $from_local_fq) { fwrite($from_local_fq,$from_remote_data); } fclose($from_remote_fp); fclose($from_local_fq); } // forget the old filemtime clearstatcache(); $file = $from_xml_file; $depth = array(); function startElement($parser, $name, $attrs) { global $depth, $SHOWDEBUG, $toID, $toPW, $toDN; $name = ''; for ($i = 0; $i < $depth[$parser]; $i++) { $desc = urlencode($attrs['DESCRIPTION']); $extd = urlencode($attrs['EXTENDED']); $url = urlencode($attrs['HREF']); $tags = urlencode($attrs['TAG']); $hash = urlencode($attrs['HASH']); $time = $attrs['TIME']; // ugly date hack $time = str_replace("T", " ", $time); $time = str_replace("Z", " ", $time); $time = urlencode($time); if ($tags == '') { $tag = 'system:unfiled'; } $addurl = sprintf ("http://%s:%s@%s/scuttle/api/posts/add?url=%s&description=%s&extended=%s&tags=%s&dt=%s&replace=no", $toID, $toPW, $toDN, $url, $desc, $extd, $tags, $time); if ($SHOWDEBUG) { printf ("

" . "href: %s
" . "title: %s
" . "extended: %s
" . "time: %s
" . "tags: %s
" . "command: %s" . "

", $attrs['HREF'], $attrs['DESCRIPTION'], $attrs['EXTENDED'], $attrs['TIME'], $attrs['TAG'], $addurl); } $ch = curl_init($addurl); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); // If you wish to silence the curl output, use the following instead: // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // And then, // $curl_output=curl_exec($ch); } $depth[$parser]++; } function endElement($parser, $name) { $name = ''; global $depth; $depth[$parser]--; } $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); if (!($fp = fopen($file, "r"))) { die("could not open XML input"); } while ($data = fread($fp, 4096)) { if (!xml_parse($xml_parser, $data, feof($fp))) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } } xml_parser_free($xml_parser); ?>