| 1 |
<?php
|
| 2 |
// $Id: cumulus.module,v 1.1.4.3 2008/11/07 18:27:48 lut4rp Exp $
|
| 3 |
/**
|
| 4 |
* @file
|
| 5 |
* Provides a Flash-based 3D tag cloud.
|
| 6 |
* Based on WP-Cumulus for WordPress, by Roy Tanck.
|
| 7 |
*/
|
| 8 |
/**
|
| 9 |
* Implementation of hook_block().
|
| 10 |
*/
|
| 11 |
function cumulus_block($op = 'list', $delta = 0, $edit = array()) {
|
| 12 |
switch ($op) {
|
| 13 |
case 'list':
|
| 14 |
$blocks[0] = array(
|
| 15 |
'info' => t('Cumulus Tag Cloud'),
|
| 16 |
);
|
| 17 |
return $blocks;
|
| 18 |
case 'configure':
|
| 19 |
$form['vid'] = array(
|
| 20 |
'#type' => 'textfield',
|
| 21 |
'#title' => t('Vocabulary ID'),
|
| 22 |
'#default_value' => variable_get('cumulus_vid', 1),
|
| 23 |
'#maxlength' => 3,
|
| 24 |
'#description' => t('The ID of the vocabulary to display.'),
|
| 25 |
);
|
| 26 |
$form['tagadelic_step'] = array(
|
| 27 |
'#type' => 'textfield',
|
| 28 |
'#title' => t('Tag size interval'),
|
| 29 |
'#default_value' => variable_get('cumulus_tagadelic_step', 6),
|
| 30 |
'#maxlength' => 2,
|
| 31 |
'#description' => t('The number of tag sizes you want to use.'),
|
| 32 |
);
|
| 33 |
$form['tagadelic_limit'] = array(
|
| 34 |
'#type' => 'textfield',
|
| 35 |
'#title' => t('Number of tags to display'),
|
| 36 |
'#default_value' => variable_get('cumulus_tagadelic_limit', 24),
|
| 37 |
'#maxlength' => 2,
|
| 38 |
'#description' => t('The number of tags to display.'),
|
| 39 |
);
|
| 40 |
$form['flash_width'] = array(
|
| 41 |
'#type' => 'textfield',
|
| 42 |
'#title' => t('Width of cumulus'),
|
| 43 |
'#default_value' => variable_get('cumulus_flash_width', 200),
|
| 44 |
'#maxlength' => 3,
|
| 45 |
'#description' => t('The width of the cumulus in pixels.'),
|
| 46 |
);
|
| 47 |
$form['flash_height'] = array(
|
| 48 |
'#type' => 'textfield',
|
| 49 |
'#title' => t('Height of cumulus'),
|
| 50 |
'#default_value' => variable_get('cumulus_flash_height', 150),
|
| 51 |
'#maxlength' => 3,
|
| 52 |
'#description' => t('The height of the cumulus in pixels.'),
|
| 53 |
);
|
| 54 |
$form['flash_background'] = array(
|
| 55 |
'#type' => 'textfield',
|
| 56 |
'#title' => t('Background color of cumulus'),
|
| 57 |
'#default_value' => variable_get('cumulus_flash_background', 'ffffff'),
|
| 58 |
'#maxlength' => 6,
|
| 59 |
'#description' => t('The hex color value for the background of the cumulus. E.g. ffffff. If "Background transparency" is enabled this option has no effect.'),
|
| 60 |
);
|
| 61 |
$form['flash_transparency'] = array(
|
| 62 |
'#type' => 'select',
|
| 63 |
'#title' => t('Background transparency'),
|
| 64 |
'#default_value' => variable_get('cumulus_flash_transparency', 'false'),
|
| 65 |
'#options' => array(
|
| 66 |
'false' => t('no'),
|
| 67 |
'true' => t('yes'),
|
| 68 |
),
|
| 69 |
'#description' => t('Enabling background transparency might cause issues with some (mostly older) browsers. Under Linux, transparency doesn\'t work at all due to a known limitation in the Flash player.'),
|
| 70 |
);
|
| 71 |
$form['flash_color'] = array(
|
| 72 |
'#type' => 'textfield',
|
| 73 |
'#title' => t('Font color of cumulus'),
|
| 74 |
'#default_value' => variable_get('cumulus_flash_color', '000000'),
|
| 75 |
'#maxlength' => 6,
|
| 76 |
'#description' => t('The hex color value you would like to use for the tags. E.g. 000000.'),
|
| 77 |
);
|
| 78 |
$form['flash_speed'] = array(
|
| 79 |
'#type' => 'textfield',
|
| 80 |
'#title' => t('Rotation speed'),
|
| 81 |
'#default_value' => variable_get('cumulus_flash_speed', 150),
|
| 82 |
'#maxlength' => 3,
|
| 83 |
'#description' => t('Set the speed of the cumulus. Options between 25 and 500 work best.'),
|
| 84 |
);
|
| 85 |
$form['flash_distribute'] = array(
|
| 86 |
'#type' => 'select',
|
| 87 |
'#title' => t('Distribute tags evenly on cumulus'),
|
| 88 |
'#default_value' => variable_get('cumulus_flash_distribute', 'true'),
|
| 89 |
'#options' => array(
|
| 90 |
'false' => t('no'),
|
| 91 |
'true' => t('yes'),
|
| 92 |
),
|
| 93 |
'#description' => t('When enabled, the movie will attempt to distribute the tags evenly over the surface of the cumulus.'),
|
| 94 |
);
|
| 95 |
$form['flash_font_size'] = array(
|
| 96 |
'#type' => 'textfield',
|
| 97 |
'#title' => t('Font size'),
|
| 98 |
'#default_value' => variable_get('cumulus_flash_font_size', 10),
|
| 99 |
'#maxlength' => 2,
|
| 100 |
'#description' => t('Set the font size of the tag with the lowest tag-size in pixels (level 1).'),
|
| 101 |
);
|
| 102 |
$form['flash_font_size_interval'] = array(
|
| 103 |
'#type' => 'textfield',
|
| 104 |
'#title' => t('Font size interval'),
|
| 105 |
'#default_value' => variable_get('cumulus_flash_font_size_interval', 2),
|
| 106 |
'#maxlength' => 1,
|
| 107 |
'#description' => t('Set the font size interval used for the different tag-sizes (level 2 and higher).'),
|
| 108 |
);
|
| 109 |
return $form;
|
| 110 |
case 'save':
|
| 111 |
variable_set('cumulus_vid', $edit['vid']);
|
| 112 |
variable_set('cumulus_tagadelic_step', $edit['tagadelic_step']);
|
| 113 |
variable_set('cumulus_tagadelic_limit', $edit['tagadelic_limit']);
|
| 114 |
variable_set('cumulus_flash_width', $edit['flash_width']);
|
| 115 |
variable_set('cumulus_flash_height', $edit['flash_height']);
|
| 116 |
variable_set('cumulus_flash_background', $edit['flash_background']);
|
| 117 |
variable_set('cumulus_flash_transparency', $edit['flash_transparency']);
|
| 118 |
variable_set('cumulus_flash_color', $edit['flash_color']);
|
| 119 |
variable_set('cumulus_flash_speed', $edit['flash_speed']);
|
| 120 |
variable_set('cumulus_flash_distribute', $edit['flash_distribute']);
|
| 121 |
variable_set('cumulus_flash_font_size', $edit['flash_font_size']);
|
| 122 |
variable_set('cumulus_flash_font_size_interval', $edit['flash_font_size_interval']);
|
| 123 |
return;
|
| 124 |
case 'view':
|
| 125 |
// Tagadelic API
|
| 126 |
$tags = tagadelic_get_weighted_tags(array(variable_get('cumulus_vid', 1)), variable_get('cumulus_tagadelic_step', 6), variable_get('cumulus_tagadelic_limit', 24));
|
| 127 |
$tags = tagadelic_sort_tags($tags);
|
| 128 |
// theme tags for cumulus: tags tag, font size, link, encode
|
| 129 |
$tags_formatted_flash = theme('cumulus_weighted', $tags);
|
| 130 |
// alternate content if flash or JS are disabled
|
| 131 |
$tags_formatted_alt = theme('tagadelic_weighted', $tags);
|
| 132 |
// JS for Flash
|
| 133 |
$js = drupal_get_path('module', 'cumulus') . '/cumulus.js';
|
| 134 |
if (file_exists($js)) {
|
| 135 |
drupal_add_js($js);
|
| 136 |
} else {
|
| 137 |
drupal_set_message(t('The file @folder is missing. Please download it from http://pratul.in/files/cumulus.js, and add it to the Cumulus module folder! See README.txt for further instructions.', array('@folder' => $js)), 'error');
|
| 138 |
}
|
| 139 |
// Flash params
|
| 140 |
$param = array(
|
| 141 |
'path_to_flash' => base_path() . drupal_get_path('module', 'cumulus') . '/cumulus.swf',
|
| 142 |
'width' => variable_get('cumulus_flash_width', 1),
|
| 143 |
'height' => variable_get('cumulus_flash_height', 1),
|
| 144 |
'background' => variable_get('cumulus_flash_background', 'ffffff'),
|
| 145 |
'color' => '0x' . variable_get('cumulus_flash_color', '000000'),
|
| 146 |
'speed' => variable_get('cumulus_flash_speed', 220),
|
| 147 |
'distribute' => variable_get('cumulus_flash_distribute', 'true'),
|
| 148 |
);
|
| 149 |
if (variable_get('cumulus_flash_transparency', 'false') == 'true' ){
|
| 150 |
$param['transparency'] = 'widget_so.addParam("wmode", "transparent");';
|
| 151 |
}
|
| 152 |
// link to view with additional tags
|
| 153 |
$links['more'] = l(t('more tags'), 'tagadelic/chunk/' . variable_get('cumulus_vid', 1));
|
| 154 |
// output content
|
| 155 |
$blocks['subject'] = t('Cumulus Tag Cloud');
|
| 156 |
// param with value 9 indicates required version of flash player - see http://blog.deconcept.com/swfobject/
|
| 157 |
$blocks['content'] = <<<EOT
|
| 158 |
<div id="tags">
|
| 159 |
{$tags_formatted_alt}
|
| 160 |
<script type="text/javascript">
|
| 161 |
var rnumber = Math.floor(Math.random()*9999999);
|
| 162 |
var widget_so = new SWFObject("{$param['path_to_flash']}?r="+rnumber, "cumulusflash", "{$param['width']}", "{$param['height']}", "9", "{$param['background']}");
|
| 163 |
{$param['transparency']}
|
| 164 |
widget_so.addParam("allowScriptAccess", "always");
|
| 165 |
widget_so.addVariable("tcolor", "{$param['color']}");
|
| 166 |
widget_so.addVariable("tspeed", "{$param['speed']}");
|
| 167 |
widget_so.addVariable("distr", "{$param['distribute']}");
|
| 168 |
widget_so.addVariable("mode", "tags");
|
| 169 |
widget_so.addVariable("tagcloud", "{$tags_formatted_flash}");
|
| 170 |
widget_so.write("tags");
|
| 171 |
</script>
|
| 172 |
</div>
|
| 173 |
<div class="more-link">{$links['more']}</div>
|
| 174 |
EOT;
|
| 175 |
return $blocks;
|
| 176 |
}
|
| 177 |
}
|
| 178 |
/**
|
| 179 |
* Theme function
|
| 180 |
*/
|
| 181 |
function theme_cumulus_weighted($terms) {
|
| 182 |
$output = '<tags>';
|
| 183 |
foreach ($terms as $term) {
|
| 184 |
// assign font size
|
| 185 |
$font_size = (intval($term->weight) * variable_get('cumulus_flash_font_size_interval', 2)) + (variable_get('cumulus_flash_font_size', 10) - variable_get('cumulus_flash_font_size_interval', 2));
|
| 186 |
$output .= l($term->name, taxonomy_term_path($term), array('style' => '"font-size: ' . $font_size . 'px;"')) . " \n";
|
| 187 |
}
|
| 188 |
$output .= '</tags>';
|
| 189 |
$output = urlencode($output);
|
| 190 |
return $output;
|
| 191 |
}
|