URL:
Extended:
Descirption:
Tags:
Previously Used Tags: $usedTags
htmlCodeBlock;
}
/*
foreach($xml as $post)
{
echo "Site: {$post['description']} at {$post['href']} has the following tag(s): {$post['tag']}\n";
}
*/
function callDelicious($endPoint, $parameters)
{
foreach ($parameters AS $paramater)
{
$endPoint .= $paramater[0] . "=" . $paramater[1] . "&";
}
//echo $endPoint;
$key = md5($endPoint);
$today = date("Y-m-j H:i:s", time() - 5 * 60);
$query = "SELECT `key`, `xml` FROM 11_delicious_cache WHERE `key` = '$key' && `tstamp` > '$today' ORDER BY `tstamp` DESC LIMIT 1";
$result = getAssoc($query, 0);
if (isset($result['$xml']))
{
//echo "Cache copy is valid";
$xml = simplexml_load_string($result['xml']);
}else
{
$xml = baseCall($endPoint);
if ($xml == null)
{
return null;
}else if ($xml == "THROTTLE")
{
// Throttled, get best possible
$query = "SELECT `key`, `xml` FROM 11_delicious_cache WHERE `key` = '$key' ORDER BY `tstamp` DESC LIMIT 1";
$result = getAssoc($query, 0);
if (isset($result['xml']))
{
$safeXML = mysql_real_escape_string($result['xml']);
$insertQuery = "REPLACE INTO 11_delicious_cache (`key`, `xml`, `tstamp`) VALUES (MD5('$endPoint'), '$safeXML', null)";
insertQuery($insertQuery);
$xml = simplexml_load_string($result['xml']);
}else
{
//Wasn't able to locate any cached copy
$xml = null;
}
}else if (is_object($xml))
{
//echo "Couldn't Cache, but I got the goods from the server";
$safeXML = mysql_real_escape_string($xml->asXML());
$insertQuery = "REPLACE INTO 11_delicious_cache (`key`, `xml`, `tstamp`) VALUES (MD5('$endPoint'), '$safeXML', null)";
insertQuery($insertQuery);
}else
{
$xml = null;
}
}
return $xml;
}
function baseCall($endPoint)
{
$authorization = base64_encode("username:password");
$url_info = parse_url($endPoint);
$host = $url_info['host'];
$path = $url_info['path'] . "?" . $url_info['query'];
$data = "";
$fp=fsockopen($host, 80);
fputs($fp, "POST " . $path . " HTTP/1.1\r\n");
fputs($fp, "Host: " . $host ."\r\n");
fputs($fp, "Authorization: Basic $authorization\r\n");
fputs($fp, "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain\r\n");
fputs($fp, "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n");
fputs($fp, "Connection: close\r\n");
fputs($fp, "User-Agent: PReinheimer Test App v0.1\r\n");
fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-Length: " . strlen($data) . "\r\n\r\n");
fputs($fp, "$data");
$response="";
while(!feof($fp))
{
$response.=fgets($fp, 128);
}
fclose($fp);
list($http_headers, $http_content)=explode("\r\n\r\n", $response);
if (strpos($http_headers, "200 OK"))
{
$firstLine = strpos($http_content, "\n");
$http_content = substr($http_content, $firstLine + 1);
$lastLine = strrpos($http_content, ">");
$http_content = substr($http_content, 0, $lastLine + 1);
$xml = simplexml_load_string($http_content);
//echo "$http_content
";
return $xml;
}else if (strpos($http_headers, "503"))
{
return "THROTTLE";
}else
{
return NULL;
}
}
?>