20
|| ((filemtime($cache_file) + $cache_time - $time[1]) + $cache_time_rnd < 0)
|| (filemtime(__FILE__) > filemtime($cache_file))
) {
$c = curl_init($api_url);
curl_setopt($c, CURLOPT_RETURNTRANSFER,1);
curl_setopt($c, CURLOPT_USERPWD,"$user:$pass");
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($c, CURLOPT_TIMEOUT, 4);
curl_setopt($c, CURLOPT_USERAGENT, "del.icio.us WordPress Plugin v1.0 http://linuxbrit.co.uk/");
$response = curl_exec($c);
$info = curl_getinfo($c);
$_curl_error_code = $info['http_code'];
curl_close($c);
if ($_curl_error_code == 200) {
$_fpwrite = fopen($cache_file_tmp, 'w');
if($_fpwrite) {
# parse the XML, then write out includable html to the cache file.
if (!($xml_parser = xml_parser_create()))
die("Couldn't create parser.");
xml_set_element_handler($xml_parser,
"_delicious_startelem",
"_delicious_endelem");
fputs($_fpwrite, "
\n");
xml_parse($xml_parser, $response);
if ($display_metalinks) {
fputs($_fpwrite, "- more | "
.""
."feed
");
}
fputs($_fpwrite, "
\n");
xml_parser_free($xml_parser);
fclose($_fpwrite);
# be atomic
rename($cache_file_tmp, $cache_file);
}
}
}
if ((file_exists($cache_file)) && filesize($cache_file) > 20) {
include($cache_file);
} elseif ($_curl_error_code) {
echo "- No links (error $_curl_error_code)
";
} else {
echo "";
}
}
function _delicious_startelem ($parser,$name,$attrib) {
global $_fpwrite;
global $_del_user;
switch ($name) {
case $name=="POST" : {
$href = $attrib["HREF"];
$desc = $attrib["DESCRIPTION"];
$extended = $attrib["EXTENDED"];
$tag = $attrib["TAG"];
$time = $attrib["TIME"];
$time = preg_replace("/[TZ]/", " ", $time);
$line = "\n";
$line .= " $desc\n";
if ($_display_extended && $extended && $extended != $desc) {
$line .= " $extended
\n";
}
if ($_display_tags) {
$line .= " \n";
foreach (split(" ", $tag) as $t) {
$line .= " - $t
\n";
}
$line .= "
\n";
}
$line .= "\n";
fputs($_fpwrite, $line);
break;
}
}
}
function _delicious_endelem ($parser,$name){
}
?>