'. $code .'
';
}
/**
* Do the Digg API request and retrieve the XML feed
* with the top Digg stories for a given domain.
*
* @return $xml
* The XML string as returned by the Digg Web Service
*/
function diggthis_request($query_string) {
$api_url = 'http://services.digg.com/stories';
//$request_url = url($api_url, $options);
$request_url = $api_url . $query_string;
$xml = '';
$cache = cache_get($request_url, 'cache');
if(is_object($cache) && $cache->expire > time()) {
$xml = $cache->data;
}
else {
cache_clear_all($request_url, 'cache');
$response = drupal_http_request($request_url);
if (200 == $response->code) {
// cache the XML string since unserializing simplexml objects does not work
$xml = $response->data;
cache_set($request_url, $xml, 'cache', time() + variable_get('diggthis_cache_lifetime', 43200));
}
else {
watchdog('diggthis', 'Digg top stories could not be retrieved. Server response: "%response"',
array('%response' => var_export($response, TRUE)), WATCHDOG_WARNING);
return FALSE;
}
}
return $xml;
}
/**
* Theme function to markup a single digg story
*
* @param $data
* A PHP SimpleXML object
*
* @return $html
* An HTML string with markup for a Digg story
*/
function theme_diggthis_story($story) {
$html = '';
$digg_link = l(t('Diggs received: !diggs', array('!diggs' => $story['diggs'])),
$story['href'], array('absolute' => TRUE));
$story_link = l($story->title, $story['link'], array('absolute' => TRUE));
$html .= '';
$html .= '
' . $story_link . '
';
$html .= '
' . $story->description . '
';
$html .= '
' . $digg_link . '
';
$html .= '
';
return $html;
}