You are here

function cumulus_block in Cumulus 6

Same name and namespace in other branches
  1. 5 cumulus.module \cumulus_block()

Implementation of hook_block().

File

./cumulus.module, line 20
The brain of Cumulus.

Code

function cumulus_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      $blocks[0]['info'] = t('Cumulus Tag Cloud');
      $blocks[0]['cache'] = BLOCK_NO_CACHE;
      return $blocks;
    case 'configure':
      return cumulus_block_configure();
    case 'save':
      variable_set('cumulus_vid', $edit['vid']);
      variable_set('cumulus_tagadelic_step', $edit['tagadelic_step']);
      variable_set('cumulus_tagadelic_limit', $edit['tagadelic_limit']);
      variable_set('cumulus_flash_width', $edit['flash_width']);
      variable_set('cumulus_flash_height', $edit['flash_height']);
      variable_set('cumulus_flash_background', $edit['flash_background']);
      variable_set('cumulus_flash_transparency', $edit['flash_transparency']);
      variable_set('cumulus_flash_color', $edit['flash_color']);
      variable_set('cumulus_flash_color2', $edit['flash_color2']);
      variable_set('cumulus_flash_hicolor', $edit['flash_hicolor']);
      variable_set('cumulus_flash_speed', $edit['flash_speed']);
      variable_set('cumulus_flash_distribute', $edit['flash_distribute']);
      variable_set('cumulus_flash_font_size', $edit['flash_font_size']);
      variable_set('cumulus_flash_font_size_interval', $edit['flash_font_size_interval']);
      return;
    case 'view':
      $vocs = variable_get('cumulus_vid', 1);
      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, variable_get('cumulus_tagadelic_step', 6), variable_get('cumulus_tagadelic_limit', 24));
      $tags = tagadelic_sort_tags($tags);
      $tags_formatted_flash = theme('cumulus_weighted', $tags);
      $tags_formatted_alt = theme('tagadelic_weighted', $tags);
      $js = drupal_get_path('module', 'cumulus') . '/cumulus.js';
      if (file_exists($js)) {
        drupal_add_js($js, 'module', 'header', FALSE, TRUE, FALSE);
      }
      else {
        drupal_set_message(t('The file @folder is missing. Please download it from !link, and add it to the Cumulus module folder!', array(
          '@folder' => $js,
          '!link' => l('http://pratul.in/files/cumulus.js', 'http://pratul.in/files/cumulus.js'),
        )), 'error');
      }
      if (!variable_get('cumulus_vid', 1)) {
        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/build/block/configure/cumulus/0'),
        )), 'warning');
      }

      // Flash params
      $param = array(
        'path_to_flash' => base_path() . drupal_get_path('module', 'cumulus') . '/cumulus.swf',
        'width' => variable_get('cumulus_flash_width', 1),
        'height' => variable_get('cumulus_flash_height', 1),
        'background' => variable_get('cumulus_flash_background', 'ffffff'),
        'color' => '0x' . variable_get('cumulus_flash_color', '000000'),
        'color2' => '0x' . variable_get('cumulus_flash_color2', 'ff0000'),
        'hicolor' => '0x' . variable_get('cumulus_flash_hicolor', '666666'),
        'speed' => variable_get('cumulus_flash_speed', 220),
        'distribute' => variable_get('cumulus_flash_distribute', 'true'),
      );
      if (variable_get('cumulus_flash_transparency', 'false') == 'true') {
        $param['transparency'] = 'widget_so.addParam("wmode", "transparent");';
      }

      // link to view with additional tags
      $links['more'] = l(t('more tags'), 'tagadelic/chunk/' . variable_get('cumulus_vid', 1));

      // 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;
  }
}