cumulus.module in Cumulus 7
Same filename and directory in other branches
The brain of Cumulus.
Provides a Flash-based 3D tag cloud. Based on WP-Cumulus for WordPress, by Roy Tanck.
File
cumulus.moduleView source
<?php
/**
* @file
* The brain of Cumulus.
*
* Provides a Flash-based 3D tag cloud.
* Based on WP-Cumulus for WordPress, by Roy Tanck.
*/
/**
* Implements hook_enable().
*/
function cumulus_enable() {
drupal_set_message(t('Cumulus has now been enabled. You need to !configure the Cumulus block settings before you use it.', array(
'!configure' => l(t('configure and save'), 'admin/structure/block'),
)));
}
/**
* Returns the configuration for the requested block delta.
*
* @param $delta
* string The delta that uniquely identifies the block in the block system. If
* not specified, the default configuration will be returned.
* @return
* array An associated array of configuration options.
*/
function cumulus_get_config($delta = NULL) {
$config = cumulus_default_config();
$config['delta'] = $delta;
// Get the block configuration options.
if ($delta) {
static $blocks;
if (!isset($blocks)) {
$blocks = module_invoke_all('cumulus_blocks');
}
if (!empty($blocks[$delta])) {
// Merge the default values.
$config = $blocks[$delta] + $config;
// Set the delta.
$config['delta'] = $delta;
// Flag the block as exported.
$config['exported_to_code'] = TRUE;
}
foreach (array_keys(cumulus_default_config()) as $paramter) {
$config[$paramter] = cumulus_variable_get($paramter, $delta, $config[$paramter]);
}
}
return $config;
}
function cumulus_default_config() {
return array(
'info' => variable_get('cumulus_info', NULL),
'vid' => variable_get('cumulus_vid', 1),
'tagadelic_step' => variable_get('cumulus_tagadelic_step', 6),
'tagadelic_limit' => variable_get('cumulus_tagadelic_limit', 24),
'flash_width' => variable_get('cumulus_flash_width', 200),
'flash_height' => variable_get('cumulus_flash_height', 150),
'flash_background' => variable_get('cumulus_flash_background', 'ffffff'),
'flash_transparency' => variable_get('cumulus_flash_transparency', 'false'),
'flash_color' => variable_get('cumulus_flash_color', 'ff0000'),
'flash_color2' => variable_get('cumulus_flash_color2', '000000'),
'flash_hicolor' => variable_get('cumulus_flash_hicolor', '666666'),
'flash_speed' => variable_get('cumulus_flash_speed', 100),
'flash_distribute' => variable_get('cumulus_flash_distribute', 'true'),
'flash_font_size' => variable_get('cumulus_flash_font_size', 10),
'flash_font_size_interval' => variable_get('cumulus_flash_font_size_interval', 2),
);
}
/**
* Implements hook_block_info().
*/
function cumulus_block_info() {
module_load_include('inc', 'cumulus', 'cumulus.admin');
return _cumulus_block_info();
}
/**
* Implements hook_block_configure().
*/
function cumulus_block_configure($delta = '') {
module_load_include('inc', 'cumulus', 'cumulus.admin');
return _cumulus_block_configure($delta);
}
/**
* Implements hook_block_save().
*/
function cumulus_block_save($delta = '', $edit = array()) {
module_load_include('inc', 'cumulus', 'cumulus.admin');
return _cumulus_block_save($delta, $edit);
}
/**
* Implements hook_form_block_admin_display_form_alter().
*/
function cumulus_form_block_admin_display_form_alter(&$form, $form_state) {
module_load_include('inc', 'cumulus', 'cumulus.admin');
return _cumulus_form_block_admin_display_form_alter($form, $form_state);
}
/**
* Implements hook_block_view().
*/
function cumulus_block_view($delta) {
$config = cumulus_get_config($delta);
$vocs = $config['vid'];
if (is_numeric($vocs)) {
$vocs = array(
$vocs,
);
}
elseif (preg_match('/^([0-9]+,){1,5}[0-9]+$/', $vocs)) {
$vocs = explode(',', $vocs);
}
else {
$vocs = array(
1,
);
}
$tags = tagadelic_get_weighted_tags($vocs, $config['tagadelic_step'], $config['tagadelic_limit']);
$tags = tagadelic_sort_tags($tags);
$tags_formatted_flash = theme('cumulus_weighted', array(
'terms' => $tags,
'config' => $config,
));
$tags_formatted_alt = theme('tagadelic_weighted', array(
'terms' => $tags,
));
$js = drupal_get_path('module', 'cumulus') . '/cumulus.js';
if (file_exists($js)) {
drupal_add_js($js, array(
'preprocess' => FALSE,
));
}
else {
drupal_set_message(t('The file @folder is missing. Please download swfobject v1.x and add it to the Cumulus module folder! Download links are listed in the README.txt', array(
'@folder' => $js,
)), 'error');
}
if (!$config['vid']) {
drupal_set_message(t('You haven\'t yet configured and saved the Cumulus settings on !link. Cumulus might not work properly!', array(
'!link' => l('your blocks configuration page', 'admin/structure/block/configure/cumulus/0'),
)), 'warning');
}
// Flash params
$param = array(
'path_to_flash' => base_path() . drupal_get_path('module', 'cumulus') . '/cumulus.swf',
'width' => $config['flash_width'],
'height' => $config['flash_height'],
'background' => $config['flash_background'],
'color' => '0x' . $config['flash_color'],
'color2' => '0x' . $config['flash_color2'],
'hicolor' => '0x' . $config['flash_hicolor'],
'speed' => $config['flash_speed'],
'distribute' => $config['flash_distribute'],
'transparency' => $config['flash_transparency'],
);
if ($config['flash_transparency'] == 'true') {
$param['transparency'] = 'widget_so.addParam("wmode", "transparent");';
}
// link to view with additional tags
$links['more'] = l(t('more tags'), 'tagadelic/chunk/' . $config['vid']);
// output content
$blocks['subject'] = t('Cumulus Tag Cloud');
// param with value 9 indicates required version of flash player - see http://blog.deconcept.com/swfobject/
$blocks['content'] = <<<EOT
<div id="tags">
{<span class="php-variable">$tags_formatted_alt</span>}
<script type="text/javascript">
var rnumber = Math.floor(Math.random()*9999999);
var widget_so = new SWFObject("{<span class="php-variable">$param</span>[<span class="php-string">'path_to_flash'</span>]}?r="+rnumber, "cumulusflash", "{<span class="php-variable">$param</span>[<span class="php-string">'width'</span>]}", "{<span class="php-variable">$param</span>[<span class="php-string">'height'</span>]}", "9", "{<span class="php-variable">$param</span>[<span class="php-string">'background'</span>]}");
{<span class="php-variable">$param</span>[<span class="php-string">'transparency'</span>]}
widget_so.addParam("allowScriptAccess", "always");
widget_so.addVariable("tcolor", "{<span class="php-variable">$param</span>[<span class="php-string">'color'</span>]}");
widget_so.addVariable("tcolor2", "{<span class="php-variable">$param</span>[<span class="php-string">'color2'</span>]}");
widget_so.addVariable("hicolor", "{<span class="php-variable">$param</span>[<span class="php-string">'hicolor'</span>]}");
widget_so.addVariable("tspeed", "{<span class="php-variable">$param</span>[<span class="php-string">'speed'</span>]}");
widget_so.addVariable("distr", "{<span class="php-variable">$param</span>[<span class="php-string">'distribute'</span>]}");
widget_so.addVariable("mode", "tags");
widget_so.addVariable("tagcloud", "{<span class="php-variable">$tags_formatted_flash</span>}");
widget_so.write("tags");
</script>
</div>
<div class="more-link">{<span class="php-variable">$links</span>[<span class="php-string">'more'</span>]}</div>
EOT;
return $blocks;
}
/**
* Implements hook_theme().
*/
function cumulus_theme() {
return array(
'cumulus_weighted' => array(
'variables' => array(
'terms' => NULL,
'config' => cumulus_default_config(),
),
),
);
}
/**
* Themeing function.
*/
function theme_cumulus_weighted($variables) {
$terms = $variables['terms'];
$config = $variables['config'];
$output = '<tags>';
foreach ($terms as $term) {
// assign font size
$font_size = intval($term->weight) * $config['flash_font_size_interval'] + ($config['flash_font_size'] - $config['flash_font_size_interval']);
$uri = taxonomy_term_uri($term);
$output .= l($term->name, $uri['path'], array(
'absolute' => TRUE,
'attributes' => array(
'style' => '"font-size: ' . $font_size . 'px;"',
),
)) . " \n";
}
$output .= '</tags>';
$output = urlencode($output);
return $output;
}
/**
* Implements hook_help().
*/
function cumulus_help($path, $arg) {
switch ($path) {
case 'admin/help#cumulus':
$output = '<p>' . t('Cumulus allows you to display a taxonomy\'s terms using a Flash movie that rotates them in 3D. This way, you can set it up like a 3D tag cloud. It works just like a regular tag cloud, but is more visually exciting!') . '</p>';
$output .= '<p>' . '<strong>' . t('Configuring Cumulus: ') . '</strong>' . '<br />';
$output .= t('By default, Cumulus is rendered as a block. You need to enable and configure that block to see it. If you don\'t configure and save the Cumulus block settings once, it will not work! Do that before wondering what\'s wrong :-)') . '</p>';
return $output;
}
}
/**
* Implements hook_menu().
*/
function cumulus_menu() {
module_load_include('inc', 'cumulus', 'cumulus.admin');
return _cumulus_menu();
}
/**
* Implements hook_settings().
*/
function cumulus_admin_settings($form, &$form_state) {
$form['settings'] = array(
'#type' => 'fieldset',
'#title' => t('Clear the Cumulus cache'),
'#description' => t('If you see older terms, or are unable to see terms from newly added vocabularies, try clearing the cache.<br />This will only clear the Cumulus related data from the cache. It will not clear the full Drupal cache.'),
);
$form['settings']['clear_cache'] = array(
'#type' => 'submit',
'#value' => t('Click to clear'),
'#submit' => array(
'cumulus_clear_cache',
),
);
return system_settings_form($form);
}
/**
* Clear the cache of all Cumulus (in effect, Tagadelic) data.
*/
function cumulus_clear_cache() {
$cid = "tagadelic";
$table = "cache";
$wildcard = TRUE;
cache_clear_all($cid, $table, $wildcard);
drupal_set_message(t('The module\'s cache has been cleared'), 'status');
}
/**
* Implements hook_permission().
*/
function cumulus_permission() {
return array(
'administer cumulus' => array(
'title' => t('administer cumulus'),
'description' => t('TODO Add a description for \'administer cumulus\''),
),
);
}
/**
* Get single variable
*/
function cumulus_variable_get($name, $delta, $default = NULL) {
return variable_get('cumulus_' . $delta . '_' . $name, $default);
}
/**
* Set single variable
*/
function cumulus_variable_set($name, $delta, $default = NULL) {
return variable_set('cumulus_' . $delta . '_' . $name, $default);
}
/**
* Delete single variable
*/
function cumulus_variable_del($name, $delta) {
return variable_del('cumulus_' . $delta . '_' . $name);
}
Functions
Name![]() |
Description |
---|---|
cumulus_admin_settings | Implements hook_settings(). |
cumulus_block_configure | Implements hook_block_configure(). |
cumulus_block_info | Implements hook_block_info(). |
cumulus_block_save | Implements hook_block_save(). |
cumulus_block_view | Implements hook_block_view(). |
cumulus_clear_cache | Clear the cache of all Cumulus (in effect, Tagadelic) data. |
cumulus_default_config | |
cumulus_enable | Implements hook_enable(). |
cumulus_form_block_admin_display_form_alter | Implements hook_form_block_admin_display_form_alter(). |
cumulus_get_config | Returns the configuration for the requested block delta. |
cumulus_help | Implements hook_help(). |
cumulus_menu | Implements hook_menu(). |
cumulus_permission | Implements hook_permission(). |
cumulus_theme | Implements hook_theme(). |
cumulus_variable_del | Delete single variable |
cumulus_variable_get | Get single variable |
cumulus_variable_set | Set single variable |
theme_cumulus_weighted | Themeing function. |