-17,
'languages' => -16,
'organization' => -15,
'process' => -14,
'sector' => -13,
'subject' => -12,
'technologies_facilities' => -11,
'Africa' => -6,
'Asia_Pacific' => -5,
'Europe' => -4,
'Latin_America_Caribbean' => -3,
'Middle_East' => -2,
'North_America' => -1,
);
$w1 = isset($bundle_weight[$b1]) ? $bundle_weight[$b1] : 0;
$w2 = isset($bundle_weight[$b2]) ? $bundle_weight[$b2] : 0;
return $w1 - $w2;
}
// render tags array in a delicioustylia
function theme_tags($tags_array, $max_tag_posts, &$max_posts, &$max_tags) {
$tot_posts = 0;
$tot_tags = 0;
foreach($tags_array as $tag => $posts) {
$output[] = theme_tag($tag, $posts, $max_tag_posts);
$tot_posts += $posts;
$tot_tags++;
}
if($tot_posts > $max_posts) $max_posts = $tot_posts;
if($tot_tags > $max_tags) $max_tags = $tot_tags;
$ul_html = '
';
return implode("\n", $output);
}
// render a single tags with correct fontsize in a delicioustylia
function theme_tag($tag, $posts, $max_post) {
$font_size = ($max_post) ? ((int)($posts / $max_post * (DFONT_MAX-DFONT_MIN)) + DFONT_MIN) : DFONT_MIN;
$output[] = '- ';
$output[] = '' . $tag . '';
$output[] = '
';
return implode("\n", $output);
}
// Add main edito javascript
$script_src = 'fileadmin/scripts/jquery/jquery-1.2.3.min.js';
$GLOBALS['TSFE']->additionalHeaderData[] = '';
// Toggle script
$script_src = 'fileadmin/templates/e-agriculture/phpinc/delicious_bundle_toggler.js';
$GLOBALS['TSFE']->additionalHeaderData[] = '';
// Add style for toggler
$css = array();
$css[] = '';
$GLOBALS['TSFE']->additionalHeaderData[] = implode("\n", $css);
$options = array(
'cacheDir' => '/tmp/',
'lifeTime' => 8640000,
'automaticSerialization' => true,
'pearErrorMode' => CACHE_LITE_ERROR_DIE
);
$cache = new Cache_Lite($options);
// create Services_Delicious object
$dlc = &new Services_Delicious('e_agriculture', 'oscar2K8');
$output = array();
$now = time();
// get last check from cache
if (!($last_check = $cache->get('delicious.lastcheck'))) {
$last_check = $now;
$cache->save($last_check, 'delicious.lastcheck');
}
// get last update from cache (OR update after DCHECK seconds)
if (!($last_update = $cache->get('delicious.lastupdate')) || ($now - $last_check > DCHECK) ) {
$last_updateRAW = $dlc->getLastUpdate();
$last_update = strtotime(strtr($last_updateRAW, 'TZ', ' '));
$cache->save($last_update, 'delicious.lastupdate');
$now = time() + 1;
}
$last_update_str = strftime('%D', $last_update);
// get tags and bundle from cache (OR update if lastupdate changed)
if (!($tags_all = $cache->get('delicious.tags')) || ($last_update > $last_check) ) {
while(time()<$now);
$tags_all = $dlc->getTags();
$now = time() + 1;
if(!PEAR::isError($tags_all)) $cache->save($tags_all, 'delicious.tags');
}
if (!($bundle_tags = $cache->get('delicious.bundle')) || ($last_update > $last_check) ) {
while(time()<$now);
$bundle_tags = $dlc->getTagsBundles();
if(!PEAR::isError($bundle_tags)) $cache->save($bundle_tags, 'delicious.bundle');
}
/*
// get all tags
while(time()<$now);
$tags_all = $dlc->getTags();
$now = time() + 3;
// get all tag bundles
while(time()<$now);
$bundle_tags = $dlc->getTagsBundles();
*/
// combine tag bundle and post number
if( PEAR::isError($bundle_tags) || PEAR::isError($tags_all) ) {
$output[] = "Sorry, del.icio.us services are not available at the moment. It's a del.icio.us problem!";
}
elseif( empty($bundle_tags) ) {
$output[] = "No tags on del.icio.us at the moment.";
} else {
$max_posts = 0;
$max_tags = 0;
uksort($bundle_tags, "cmp");
foreach($bundle_tags as $bundle => $tags_string) {
// $tags is a string we have to explode in array
$tags = explode(' ', $tags_string);
$tags_out = array();
$max_tag_posts = 0;
foreach($tags as $tag) {
$tags_out[$tag] = $tags_all[$tag];
$overall_posts += $tags_all[$tag];
$overall_tags++;
if($tags_all[$tag] > $max_tag_posts) $max_tag_posts = $tags_all[$tag];
}
// prepare output
$output[] = '' . $bundle . '
';
$output[] = '';
$output[] = theme_tags($tags_out, $max_tag_posts, $max_posts, $max_tags);
$output[] = '
';
}
$div_html = '';
array_unshift($output, $div_html);
$output[] = '
';
$output[] = "del.icio.us last updated on $last_update_str
";
}
print(implode("\n", $output));
?>