You are here

function tagadelic_block in Tagadelic 6

Same name and namespace in other branches
  1. 5 tagadelic.module \tagadelic_block()

Implements hook_block().

File

./tagadelic.module, line 446

Code

function tagadelic_block($op = 'list', $delta = 0, $edit = array()) {
  $blocks = array();
  if ($op == 'view') {
    if ($voc = taxonomy_vocabulary_load($delta)) {
      $blocks['subject'] = variable_get('tagadelic_block_title_' . $delta, t('Tags in @voc', array(
        '@voc' => $voc->name,
      )));
      $tags = tagadelic_get_weighted_tags(array(
        $voc->vid,
      ), variable_get('tagadelic_levels', 6), variable_get('tagadelic_block_tags_' . $delta, 12));
      $tags = tagadelic_sort_tags($tags);

      // Return a chunk of 12 tags
      $blocks['content'] = theme('tagadelic_weighted', $tags);
      if (count($tags) >= variable_get('tagadelic_block_tags_' . $delta, 12)) {

        // Add more link
        $blocks['content'] .= theme('tagadelic_more', $voc->vid);
      }
    }
    elseif ($delta == 'all') {
      $blocks['subject'] = t('Tags');
      $tags = tagadelic_get_weighted_tags(array_keys(taxonomy_get_vocabularies()), variable_get('tagadelic_levels', 6), variable_get('tagadelic_block_tags_' . $delta, 12));
      $tags = tagadelic_sort_tags($tags);
      $blocks['content'] = theme('tagadelic_weighted', $tags);
      if (count($tags) >= variable_get('tagadelic_block_tags_' . $delta, 12)) {

        // Add more link
        $blocks['content'] .= theme('tagadelic_more');
      }
    }
    elseif (arg(0) == 'node' && is_numeric(arg(1)) && ($node = node_load(arg(1)))) {
      $blocks['subject'] = t('Tags for @title', array(
        '@title' => $node->title,
      ));
      $blocks['content'] = tagadelic_tags_lists($node);
    }
    return $blocks;
  }
  elseif ($op == 'list') {
    foreach (taxonomy_get_vocabularies() as $voc) {
      $blocks[$voc->vid]['info'] = t('Tags in @voc', array(
        '@voc' => $voc->name,
      ));
      $blocks[$voc->vid]['cache'] = BLOCK_CACHE_GLOBAL;
    }
    $blocks[0]['info'] = t('Tags for the current post');
    $blocks[0]['cache'] = BLOCK_CACHE_PER_PAGE;
    $blocks['all']['info'] = t('Tags for all vocabularies');
    $blocks['all']['cache'] = BLOCK_CACHE_GLOBAL;
    return $blocks;
  }
  elseif ($op == 'configure') {
    $voc = taxonomy_vocabulary_load($delta);
    $form = array();
    $form['tags'] = array(
      '#type' => 'textfield',
      '#title' => t('Tags to show'),
      '#default_value' => variable_get('tagadelic_block_tags_' . $delta, 12),
      '#maxlength' => 3,
      '#description' => t('The number of tags to show in this block.'),
    );
    return $form;
  }
  elseif ($op == 'save') {
    variable_set('tagadelic_block_tags_' . $delta, $edit['tags']);
    return;
  }
}