| 1 |
<?php
|
| 2 |
// $Id: diggthis.pages.inc,v 1.1 2008/09/03 12:12:47 yaph Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Pages for the diggthis module.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Do the Digg API request and retrieve the XML feed
|
| 11 |
* with the top Digg stories for a given domain.
|
| 12 |
*
|
| 13 |
* @return $html
|
| 14 |
* An HTML string with markup for the Digg stories or
|
| 15 |
* an empty string if an error occurred
|
| 16 |
*
|
| 17 |
* @todo replace hard coded urls
|
| 18 |
*/
|
| 19 |
function diggthis_top_stories() {
|
| 20 |
$html = '';
|
| 21 |
|
| 22 |
$domain = trim(variable_get('diggthis_stories_domain', ''));
|
| 23 |
if (empty($domain)) {
|
| 24 |
drupal_set_message(t('There is no domain entered in the diggthis settings.'));
|
| 25 |
return $html;
|
| 26 |
}
|
| 27 |
|
| 28 |
$appkey = url($_GET['q'], array('absolute' => TRUE));
|
| 29 |
$domain = drupal_urlencode($domain);
|
| 30 |
//$options = array(
|
| 31 |
// 'query' => array('count' => 10,
|
| 32 |
// 'appkey' => $appkey,
|
| 33 |
// 'domain' => $domain,
|
| 34 |
// 'type' => 'php',
|
| 35 |
// 'sort' => 'digg_count-desc'),
|
| 36 |
// 'absolute' => TRUE
|
| 37 |
//);
|
| 38 |
// ugly but calling url() twice does not work due to urlencodeing
|
| 39 |
$query_string = '?count=10&sort=digg_count-desc&type=xml&appkey=' . $appkey . '&domain=' . $domain;
|
| 40 |
$xml = diggthis_request($query_string);
|
| 41 |
if ($xml) {
|
| 42 |
$data = simplexml_load_string($xml);
|
| 43 |
foreach ($data->story as $story) {
|
| 44 |
$html .= theme('diggthis_story', $story);
|
| 45 |
}
|
| 46 |
}
|
| 47 |
else {
|
| 48 |
drupal_set_message(t('An error occurred. Digg top stories could not be retrieved.'));
|
| 49 |
}
|
| 50 |
return $html;
|
| 51 |
}
|