You are here

cctags.module in cctags 6

Same filename and directory in other branches
  1. 8 cctags.module
  2. 7 cctags.module

File

cctags.module
View source
<?php

/**
 * Implementation of hook_help
 */
function cctags_help($path, $arg) {
  switch ($path) {
    case 'admin/help#cctags':
      return t('Provides a tag cloud interface and additional processing capabilities dictionaries.');
  }
}

/**
 * Implementation of hook_init
 */
function cctags_init() {
  drupal_add_css(drupal_get_path('module', 'cctags') . '/cctags.css');
}

/**
 * Implementation of hook_menu
 */
function cctags_menu() {
  $items = array();
  $items['admin/settings/cctags'] = array(
    'title' => 'Cctags configuration',
    'description' => 'Configure the Cctags.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'cctags_settings',
    ),
    'access callback' => 'user_access',
    'access arguments' => array(
      'administer site configuration',
    ),
    'file' => 'cctags.admin.inc',
  );
  $items['admin/settings/cctags/list'] = array(
    'title' => 'Cctags configuration',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
  );
  $items['admin/settings/cctags/add'] = array(
    'title' => 'Add cctags item',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'cctags_settings_add_item',
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
    'type' => MENU_LOCAL_TASK,
    'file' => 'cctags.admin.inc',
  );
  $items['admin/settings/cctags/%/edit'] = array(
    'title' => 'Edit cctags item',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'cctags_settings_edit_item',
      3,
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
    'type' => MENU_CALLBACK,
    'file' => 'cctags.admin.inc',
  );
  $items['admin/settings/cctags/%/delete'] = array(
    'title' => 'Delete cctags item',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'cctags_settings_delete_item',
      3,
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
    'type' => MENU_CALLBACK,
    'file' => 'cctags.admin.inc',
  );
  $cctags_items = _cctags_get_settings();
  foreach ($cctags_items as $key => $item) {
    if ($item['page']) {
      $items[$item['page_path']] = array(
        'title' => $item['page_title'] == '<none>' ? $item['name'] : $item['page_title'],
        'page callback' => 'cctags_page',
        'page arguments' => array(
          $item,
        ),
        'access callback' => 'user_access',
        'access arguments' => array(
          'access content',
        ),
        'file' => 'cctags.page.inc',
      );
    }
  }
  $path = variable_get('cctags_users_page_path', 'cctags/users');
  $items[$path] = array(
    'title' => 'Users list',
    'page callback' => 'cctags_users_page',
    'access callback' => 'user_access',
    'access arguments' => array(
      'access content',
    ),
    'file' => 'cctags.page.inc',
  );
  return $items;
}
function cctags_taxonomy($op, $type, $array = NULL) {
  if (($op == 'insert' || $op == 'delete' || $op == 'update') && $type == 'term') {
    _cctags_clear_cache(NULL, 'all', TRUE);
  }
}
function cctags_user($type, &$array, &$user, $category = NULL) {
  if ($type == 'insert' || $type == 'delete' || $type == 'update') {
    _cctags_clear_cache(-3, 'users', TRUE);
  }
}

/**
 * Implementation of hook_nodeapi
 */
function cctags_nodeapi(&$node, $op, $teaser, $page) {
  if ($op == 'load') {
    if (variable_get('cctags_node_load', 0)) {
      $node->tags = cctags_node_get_terms($node);
    }
    if (variable_get('cctags_node_links', 0)) {
      $node->tags = cctags_node_get_terms($node);
      $node->node_links = cctags_get_node_links($node);
    }
  }
  if ($op == 'update' || $op == 'delete') {
    $vocs = variable_get('cctags_node_clear', array());
    if (count($vocs)) {
      $tids = taxonomy_node_get_terms($node, 'tid');
      foreach ($tids as $term) {
        if (in_array($term->vid, $vocs)) {
          cctags_invoke_term_count($term);
          if ($term->count == 0) {
            taxonomy_del_term($term->tid);
            $vocabulary = taxonomy_vocabulary_load($term->vid);
            watchdog('cctags', 'Remove unused term %term from vocabulary %name.', array(
              '%term' => $term->name,
              '%name' => $vocabulary->name,
            ), WATCHDOG_NOTICE);
          }
        }
      }
    }
    _cctags_clear_cache($node->nid, 'node', FALSE);
    _cctags_clear_cache($node->nid, 'nodelinks', FALSE);
    if (variable_get('cctags_node_load', 0)) {
      _cctags_clear_cache(-2, NULL, TRUE);
    }
    if (variable_get('cctags_node_links', 0)) {
      _cctags_clear_cache(-1, NULL, TRUE);
    }
  }
  if ($op == 'insert' || $op == 'update' || $op == 'delete') {
    _cctags_clear_cache(-3, 'users', TRUE);
  }
}

/**
 * API that returns a multidimensional array with tags given a node
 * @param $node. A node object.
 */
function cctags_node_get_terms($node) {
  $cache_name = "cctags_cache_node_{$node->nid}";
  $cache = cache_get($cache_name);
  $tags = array();
  if (isset($cache->data)) {
    $tags = $cache->data;
  }
  else {
    if ($terms = taxonomy_node_get_terms($node, 'tid')) {
      $tags = array();
      $vocs = taxonomy_get_vocabularies($node->type);
      foreach ($terms as $tid => $term) {
        if ($vocs[$term->vid]->tags) {
          cctags_invoke_term_count($term);
          $term->path = taxonomy_term_path($term);
          $tags[$term->vid][$tid] = $term;
        }
      }
      cache_set($cache_name, $tags, 'cache', CACHE_PERMANENT);
    }
  }
  return $tags;
}

/**
 * API function that returns the tags of a node in fancy titled lists
 * @param $node. A node object.
 */
function cctags_tags_lists($node) {
  if (is_array($node->tags)) {
    $output = '';
    foreach ($node->tags as $vid => $terms) {
      $items = array();
      foreach ($terms as $term) {
        $items[] = l($term->name, $term->path, array(
          'attributes' => array(
            'title' => t('view all posts tagged with "@tag"', array(
              '@tag' => $term->name,
            )),
          ),
        ));
      }
      $output .= theme('item_list', $items);
    }
    return $output;
  }
}
function cctags_get_node_links($node) {
  $nodes = array();
  $cache_name = "cctags_cache_nodelinks_{$node->nid}";
  $cache = cache_get($cache_name);
  if (isset($cache->data)) {
    $nodes = $cache->data;
  }
  else {
    $terms = taxonomy_node_get_terms($node, 'tid');
    $tids = array();
    foreach ($terms as $tid => $value) {
      $tids[] = $tid;
    }
    if (is_array($tids) && ($stids = implode(',', $tids))) {
      $sql = 'SELECT DISTINCT(n.nid) AS nid, n.sticky, n.title, n.created FROM {node} n INNER JOIN {term_node} tn ON n.vid = tn.vid WHERE tn.tid IN (' . $stids . ') AND n.status = 1 ORDER BY n.sticky DESC,n.created DESC';
      $sql = db_rewrite_sql($sql);
      $result = db_query($sql);
      while ($n = db_fetch_object($result)) {
        $nodes[$n->nid] = $n;
      }
      cache_set($cache_name, $nodes, 'cache', CACHE_PERMANENT);
    }
  }
  return $nodes;
}
function cctags_get_users($level, $amount, $sort, $mode = 'block') {
  $users = array();
  if ($mode == 'block') {
    $cache_name = 'cctags_cache_users';
  }
  else {
    $cache_name = 'cctags_cache_users_page';
  }
  $cache = cache_get($cache_name);
  if (isset($cache->data)) {
    $users = $cache->data;
  }
  else {
    $sql = 'SELECT DISTINCT(u.uid) AS uid, u.name FROM {users} u WHERE u.status<>0 AND u.access<>0 AND u.uid>1';
    $result = db_query($sql);
    while ($u = db_fetch_object($result)) {
      $user = user_load($u->uid);
      cctags_invoke_user_weight($user);
      $users[$u->uid] = $user;
    }
    $users = cctags_build_level_users($users, $level);
    $users = _cctags_sort($users, 'level', 'desc');
    $cnt = 0;
    $u = array();
    foreach ($users as $uid => $user) {
      if ($cnt < $amount || $amount == 0 || $mode == 'page') {
        $u[$uid] = $user;
      }
      $cnt++;
    }
    list($s, $o) = explode(',', $sort);
    $users = _cctags_sort($u, $s, $o);
    $users['count'] = $cnt;
    cache_set($cache_name, $users, 'cache', CACHE_PERMANENT);
  }
  return $users;
}
function cctags_build_level_users($users, $steps = 6) {
  $tags = array();
  foreach ($users as $nid => $user) {
    $user->weight = log($user->weight + 1);
    $min = min($min, $user->weight);
    $max = max($max, $user->weight);
    $users[$nid]->weight = $user->weight;
  }
  $range = max(0.01, $max - $min) * 1.0001;
  foreach ($users as $nid => $user) {
    $users[$nid]->level = 1 + floor($steps * ($user->weight - $min) / $range);
  }
  return $users;
}

/**
 * Invoke a hook_term_count() operation in all modules.
 *
 * @param &$term
 *   A tags object.
 * @return
 *   none.
 * example hook_term_count:
 * function mymodyle_term_count(&$term) {
 *   if ($term->tid == 356) {
 *   $term->count = 10;
 *   return TRUE;
 *   }
 *   else {
 *   return FALSE;
 *   }
 *  }
 */
function cctags_invoke_term_count(&$term) {
  if (!module_invoke_all('term_count', $term)) {
    $term->count = taxonomy_term_count_nodes($term->tid, 0);
  }
}

/**
 * Invoke a hook_user_weight() operation in all modules.
 * or if defined function get_user_weight(&$user)
 * set the $user->weight
 * @param &$user
 *   A user object.
 * @return
 *   none.
 * example hook_user_weight:
 * function mymodyle_user_weight(&$user) {
 *   if ($user->uid == 3) {
 *   $user->weight = 10;
 *   return TRUE;
 *   }
 *   else {
 *   return FALSE;
 *   }
 *  }
 */
function cctags_invoke_user_weight(&$user) {
  $nodes = db_fetch_object(db_query("SELECT COUNT(uid) AS node_count FROM {node} WHERE status=1 AND uid=%d", $user->uid));
  $comments = db_fetch_object(db_query("SELECT COUNT(uid) AS comments_count FROM {comments} WHERE status=0 AND uid=%d", $user->uid));
  $user->node_count = isset($nodes) ? $nodes->node_count : 0;
  $user->comments_count = isset($comments) ? $comments->comments_count : 0;
  if (!module_invoke_all('user_weight', $user)) {
    $user->weight = cctags_get_user_weight($user);
  }
  if (function_exists('get_user_weight')) {
    call_user_func('get_user_weight', $user);
  }
}
function cctags_get_user_weight($user) {
  $weight = $user->node_count * 3 + $user->comments_count;
  return $weight;
}
function cctags_build_level_tags($terms, $steps = 6) {
  $tags = array();
  foreach ($terms as $key => $term) {
    $term->weight = log($term->count + 1);
    $min = min($min, $term->weight);
    $max = max($max, $term->weight);
    $tags[$term->vid][$term->tid] = $term;
  }
  $range = max(0.01, $max - $min) * 1.0001;
  foreach ($tags as $vid => $terms) {
    $vocabulary = taxonomy_vocabulary_load($vid);
    $tags[$vid]['vocname'] = $vocabulary->name;
    foreach ($terms as $key => $value) {
      $tags[$vid][$key]->level = 1 + floor($steps * ($value->weight - $min) / $range);
    }
  }
  return $tags;
}
function cctags_sort_tags($terms, $sort, $mode = 'mixed') {
  list($sort, $order) = explode(',', $sort);
  $tags = array();
  $vocname = array();
  $tcount = array();
  $tvid = array();
  if ($mode == 'mixed') {
    foreach ($terms as $vid => $tag) {
      $vocname[] = $terms[$vid]['vocname'];
      $tcount[] = count($tag);
      $tvid[] = $vid;
      foreach ($tag as $tid => $term) {
        if (is_numeric($tid)) {
          $tags[$tid] = $term;
        }
      }
    }
    $tags = _cctags_sort($tags, $sort, $order);
    $terms = array();
    foreach ($tags as $t => $tag) {
      $terms[0][$tag->tid] = $tag;
    }
    $terms[0]['vocname'] = $vocname;
    $terms[0]['terms'] = $tcount;
    $terms[0]['vid'] = $tvid;
  }
  else {
    foreach ($terms as $vid => $tags) {
      $vocname = $tags['vocname'];
      unset($tags['vocname']);
      $terms[$vid] = _cctags_sort($tags, $sort, $order);
      $terms[$vid]['vocname'] = array(
        $vocname,
      );
      $terms[$vid]['terms'] = array(
        count($tags),
      );
      $terms[$vid]['vid'] = array(
        $vid,
      );
    }
  }
  return $terms;
}
function _cctags_sort($tags, $sort, $order) {
  switch ($sort) {
    case 'title':
      usort($tags, "_cctags_sort_by_title");
      break;
    case 'level':
      usort($tags, "_cctags_sort_by_level");
      break;
    case 'random':
      shuffle($tags);
      break;
  }
  if ($order == 'desc') {
    $tags = array_reverse($tags);
  }
  return $tags;
}

/**
 * callback for usort, sort by count
 */
function _cctags_sort_by_title($a, $b) {
  return strnatcasecmp($a->name, $b->name);
}

/**
 * callback for usort, sort by weight
 */
function _cctags_sort_by_level($a, $b) {
  if ($a->weight == $b->weight) {
    return strnatcasecmp($a->name, $b->name);
  }
  return $a->weight > $b->weight;
}

/*
*  $cctid -- id cctags item or $node->nid
*  $mode == block|page|node|nodelinks|users  all = block+page
*  $block if TRUE clear cache_block table
*/
function _cctags_clear_cache($cctid = NULL, $mode = 'all', $block = FALSE) {
  if ($mode == 'block') {
    $cache_name = "cctags_cache_block_{$cctid}";
    db_query("DELETE FROM {cache} WHERE cid LIKE '%s%%'", $cahe_name);
  }
  elseif ($mode == 'page') {
    $cache_name = "cctags_cache_page_{$cctid}";
    db_query("DELETE FROM {cache} WHERE cid LIKE '%s%%'", $cahe_name);
  }
  elseif ($mode == 'node') {
    $cache_name = "cctags_cache_node_{$cctid}";
    db_query("DELETE FROM {cache} WHERE cid LIKE '%s%%'", $cahe_name);
  }
  elseif ($mode == 'nodelinks') {
    $cache_name = "cctags_cache_nodelinks_{$cctid}";
    db_query("DELETE FROM {cache} WHERE cid LIKE '%s%%'", $cahe_name);
  }
  elseif ($mode == 'users') {
    $cache_name = "cctags_cache_users";
    db_query("DELETE FROM {cache} WHERE cid LIKE '%s%%'", $cahe_name);
  }
  elseif ($mode == 'all') {
    $cache_name = "cctags_cache_block_{$cctid}";
    db_query("DELETE FROM {cache} WHERE cid LIKE '%s%%'", $cahe_name);
    $cache_name = "cctags_cache_page_{$cctid}";
    db_query("DELETE FROM {cache} WHERE cid LIKE '%s%%'", $cahe_name);
  }
  if ($block) {
    $cahe_name = "cctags:{$cctid}";
    db_query("DELETE FROM {cache_block} WHERE cid LIKE '%s%%'", $cahe_name);
  }
}

/**
 * Implementation of hook_cron
 */
function cctags_cron() {
  $delcount = 0;
  $vocs = variable_get('cctags_cron_clear', array());
  foreach ($vocs as $voc => $value) {
    if ($value != 0) {
      $tids = taxonomy_get_tree($value);
      foreach ($tids as $term) {
        cctags_invoke_term_count($term);
        if ($term->count == 0) {
          $delcount++;
          taxonomy_del_term($term->tid);
        }
      }
      if ($delcount) {
        watchdog('cctags', 'Remove unused terms in the cron from vocabulary %name %count terms.', array(
          '%name' => $vocabulary->name,
          '%count' => $delcount,
        ), WATCHDOG_NOTICE);
      }
    }
  }
  if ($delcount) {
    _cctags_clear_cache(NULL, 'all', TRUE);
  }
}

/**
 * Function that gets the information from the database, passes it along to the weight builder and returns these weighted tags. Note that the tags are unordered at this stage, hence they need orndering either by calling our api or by your own ordering data.
 * @param $cctid. Cctags IDs items.
 * @param $mode. block or page parameters settings.
 * @return An <em>unordered</em> array with tags-objects, containing the attribute $tag->weight,$tags->level ...;
 */
function cctags_get_level_tags($cctid, $mode = 'page') {
  $terms = array();
  if ($mode == 'page') {
    $cache_name = "cctags_cache_page_{$cctid}";
    $cache = cache_get($cache_name);
  }
  if ($mode == 'block') {
    $cache_name = "cctags_cache_block_{$cctid}";
    $cache = cache_get($cache_name);
  }

  // make sure cache has data
  if (isset($cache->data)) {
    $terms = $cache->data;
  }
  else {
    $items = _cctags_get_settings($cctid);
    $item = $items[0];
    $tree = array();
    if ($item['page'] && $mode == 'page' || $item['block'] && $mode == 'block') {
      foreach ($item['item_data']['vocs'] as $key => $value) {
        if (is_numeric($key) && $value == 1) {
          $tree = taxonomy_get_tree($key);
          foreach ($item['item_data']['level'][$key] as $k => $v) {
            if ($v == 1) {
              foreach ($tree as $t => $vt) {
                if ($vt->depth == $k) {
                  $term = $tree[$t];
                  cctags_invoke_term_count($term);
                  $term->path = taxonomy_term_path($term);
                  $terms[] = $term;
                }
              }
            }
          }
        }
      }
      if ($mode == 'page') {
        $terms = cctags_build_level_tags($terms, $item['page_level'] + 1);
        $terms = cctags_sort_tags($terms, $item['page_sort'], $item['page_mode']);
      }
      else {
        $settings_block = unserialize(variable_get('cctags_settings_block', ''));
        $sort = isset($settings_block[$cctid]['tags_sort']) ? $settings_block[$cctid]['tags_sort'] : 'title,asc';
        $level = isset($settings_block[$cctid]['level']) ? $settings_block[$cctid]['level'] : 6;
        $level++;
        $cnt = isset($settings_block[$cctid]['tags']) ? $settings_block[$cctid]['tags'] : 2;
        $c = _cctags_get_select_list('numtags');
        $amount = $c[$cnt];
        $terms = cctags_build_level_tags($terms, $level);
        $terms = cctags_sort_tags($terms, 'level,desc', 'mixed');
        $count = 0;
        foreach ($terms as $key => $value) {
          foreach ($value as $tid => $term) {
            if ($amount > 0) {
              $block_terms[0][$tid] = $term;
            }
            $amount--;
            $count++;
          }
        }
        $terms = cctags_sort_tags($block_terms, $sort, 'mixed');
        $terms['count'] = $count;
      }
    }
    cache_set($cache_name, $terms, 'cache', CACHE_TEMPORARY);
  }
  return $terms;
}
function _cctags_get_settings($cctid = NULL) {
  $items = array();
  if ($cctid == NULL) {
    $sql = db_query("SELECT cctid,name,block,block_name,page,page_title,page_path,page_level,page_amount,page_sort,page_mode,page_vocname,item_data FROM {cctags} ORDER BY cctid");
  }
  else {
    $sql = db_query("SELECT cctid,name,block,block_name,page,page_title,page_path,page_level,page_amount,page_sort,page_mode,page_vocname,item_data FROM {cctags} WHERE cctid = %d", $cctid);
  }
  $amounts = _cctags_get_select_list('amount_tags');
  while ($cctags = db_fetch_object($sql)) {
    $items[] = array(
      'cctid' => $cctags->cctid,
      'name' => $cctags->name,
      'block' => $cctags->block,
      'block_name' => $cctags->block_name,
      'page' => $cctags->page,
      'page_title' => $cctags->page_title,
      'page_path' => $cctags->page_path,
      'page_level' => $cctags->page_level,
      'page_amount' => $cctags->page_amount,
      'page_sort' => $cctags->page_sort,
      'page_mode' => $cctags->page_mode,
      'page_vocname' => $cctags->page_vocname,
      'item_data' => unserialize($cctags->item_data),
    );
  }
  return $items;
}

/**
 * implementation of hook_block
 */
function cctags_block($op = 'list', $delta = 0, $edit = array()) {
  $blocks = array();
  if ($op == 'view') {
    $settings_block = unserialize(variable_get('cctags_settings_block', ''));
    $c = _cctags_get_select_list('numtags');
    $item = $items[0];
    if (count($items = _cctags_get_settings($delta))) {
      $tags = isset($settings_block[$delta]['tags']) ? $settings_block[$delta]['tags'] : 2;
      $tags = $c[$tags];
      $tags_more = isset($settings_block[$delta]['tags_more']) ? $settings_block[$delta]['tags_more'] : 1;
      $blocks['subject'] = t('Cloud of tags');
      $blocks['content'] = theme('cctags_block', $delta, $tags, $tags_more);
    }
    elseif ($delta == -3 && variable_get('cctags_users_load', 0)) {
      $amount = isset($settings_block[$delta]['tags']) ? $settings_block[$delta]['tags'] : 2;
      $users_more = isset($settings_block[$delta]['tags_more']) ? $settings_block[$delta]['tags_more'] : 1;
      $users_sort = isset($settings_block[$delta]['tags_sort']) ? $settings_block[$delta]['tags_sort'] : 1;
      $level = isset($settings_block[$delta]['level']) ? $settings_block[$delta]['level'] : 6;
      $level++;
      $u = _cctags_get_select_list('amount_user');
      $amount = $u[$amount];
      $users = cctags_get_users($level, $amount, $users_sort, 'block');
      $blocks['subject'] = t('Cloud of users');
      $blocks['content'] = theme('cctags_user_block', $users, $amount, $users_more);
    }
    if (arg(0) == 'node' && is_numeric(arg(1)) && ($node = node_load(arg(1)))) {
      if ($delta == -2 && variable_get('cctags_node_load', 0)) {
        $blocks['subject'] = t('Tags for @title', array(
          '@title' => $node->title,
        ));
        $blocks['content'] = cctags_tags_lists($node);
      }
      if ($delta == -1 && variable_get('cctags_node_links', 0)) {
        $tags = isset($settings_block[$delta]['tags']) ? $settings_block[$delta]['tags'] : 2;
        $tags = $c[$tags];
        $blocks['subject'] = t('Links for @title', array(
          '@title' => $node->title,
        ));
        $node->node_links = cctags_get_node_links($node);
        if (count($node->node_links)) {
          $blocks['content'] = theme('cctags_node_links_block', $node, $tags);
        }
      }
    }
    return $blocks;
  }
  elseif ($op == 'list') {
    $items = _cctags_get_settings($cctid = NULL);
    foreach ($items as $key => $item) {
      if ($item['block']) {
        $blocks[$item['cctid']]['info'] = $item['block_name'];
        $blocks[$item['cctid']]['cache'] = BLOCK_CACHE_GLOBAL;
      }
    }
    if (variable_get('cctags_node_links', 0)) {
      $blocks[-1]['info'] = variable_get('cctags_node_links_block_name', '');
      $blocks[-1]['cache'] = BLOCK_CACHE_PER_PAGE;
    }
    if (variable_get('cctags_node_load', 0)) {
      $blocks[-2]['info'] = variable_get('cctags_node_block_name', '');
      $blocks[-2]['cache'] = BLOCK_CACHE_PER_PAGE;
    }
    if (variable_get('cctags_users_load', 0)) {
      $blocks[-3]['info'] = variable_get('cctags_users_block_name', '');
      $blocks[-3]['cache'] = BLOCK_CACHE_GLOBAL;
    }
    return $blocks;
  }
  elseif ($op == 'configure') {
    $form = array();
    $settings_block = unserialize(variable_get('cctags_settings_block', ''));
    $tags = isset($settings_block[$delta]['tags']) ? $settings_block[$delta]['tags'] : 2;
    $tags_more = isset($settings_block[$delta]['tags_more']) ? $settings_block[$delta]['tags_more'] : 1;
    $tags_sort = isset($settings_block[$delta]['tags_sort']) ? $settings_block[$delta]['tags_sort'] : 'title,asc';
    $level = isset($settings_block[$delta]['level']) ? $settings_block[$delta]['level'] : 6;
    $swf = isset($settings_block[$delta]['swf']) ? $settings_block[$delta]['swf'] : 0;
    $swf_width = isset($settings_block[$delta]['swf_width']) ? $settings_block[$delta]['swf_width'] : 200;
    $swf_height = isset($settings_block[$delta]['swf_height']) ? $settings_block[$delta]['swf_height'] : 200;
    if ($delta == -1) {
      $form['tags'] = array(
        '#type' => 'select',
        '#title' => t('Node links to show'),
        '#options' => _cctags_get_select_list('numtags'),
        '#default_value' => $tags,
        '#maxlength' => 3,
        '#description' => t('The number of links to show in this block.'),
      );
    }
    if ($delta >= 1 || $delta == -3) {
      $form['level'] = array(
        '#type' => 'select',
        '#options' => _cctags_get_select_list('level'),
        '#title' => t('Number of levels fonts metrics'),
        '#default_value' => $level,
        '#description' => t('The number of levels between the least popular tags and the most popular ones. Different levels will be assigned a different class to be themed in cctags.css'),
      );
      $form['tags'] = array(
        '#type' => 'select',
        '#title' => $delta == -3 ? t('Users to show') : t('Tags to show'),
        '#options' => $delta == -3 ? _cctags_get_select_list('amount_user') : _cctags_get_select_list('numtags'),
        '#default_value' => $tags,
        '#maxlength' => 3,
        '#description' => $delta == -3 ? t('The number of users to show in this block.') : t('The number of tags to show in this block.'),
      );
      $op_sort = array(
        'level,asc' => t('by level, ascending'),
        'level,desc' => t('by level, descending'),
        'title,asc' => t('by title, ascending'),
        'title,desc' => t('by title, descending'),
        'random,none' => t('random'),
      );
      $form['tags_sort'] = array(
        '#type' => 'radios',
        '#title' => t('Tags sort order'),
        '#options' => $op_sort,
        '#default_value' => $tags_sort,
      );
      $form['tags_more'] = array(
        '#type' => 'checkbox',
        '#title' => t('Enable more link of end block'),
        '#default_value' => $tags_more,
      );
    }
    return $form;
  }
  elseif ($op == 'save') {
    $settings_block = unserialize(variable_get('cctags_settings_block', ''));
    $settings_block[$delta]['tags'] = $edit['tags'];
    $settings_block[$delta]['tags_sort'] = $edit['tags_sort'];
    $settings_block[$delta]['tags_more'] = $edit['tags_more'];
    $settings_block[$delta]['level'] = $edit['level'];
    variable_set('cctags_settings_block', serialize($settings_block));
    _cctags_clear_cache($delta, 'block', TRUE);
    return;
  }
}
function _cctags_get_select_list($type) {
  $list = array();
  switch ($type) {
    case 'numtags':
      $list = array(
        0,
        4,
        6,
        8,
        10,
        12,
        14,
        16,
        18,
        20,
        24,
        28,
        32,
        40,
        50,
        60,
        100,
      );
      break;
    case 'level':
      $list = array(
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9,
        10,
      );
      break;
    case 'amount_tags':
      $list = array(
        0,
        6,
        12,
        14,
        16,
        18,
        20,
        24,
        28,
        32,
        40,
        50,
        60,
        100,
        120,
        150,
        200,
        300,
        400,
        500,
        600,
        900,
        1400,
      );
      break;
    case 'amount_user':
      $list = array(
        0,
        5,
        10,
        15,
        20,
        30,
        40,
        50,
        70,
        100,
        150,
        200,
        350,
        300,
      );
      break;
  }
  return $list;
}
function cctags_theme() {
  return array(
    'cctags_settings' => array(
      'file' => 'cctags.admin.inc',
      'arguments' => array(
        'form' => NULL,
      ),
    ),
    'cctags_settings_add_item' => array(
      'file' => 'cctags.admin.inc',
      'arguments' => array(
        'form' => NULL,
      ),
    ),
    'cctags_settings_edit_item' => array(
      'file' => 'cctags.admin.inc',
      'arguments' => array(
        'form' => NULL,
      ),
    ),
    'cctags_settings_item' => array(
      'file' => 'cctags.admin.inc',
      'arguments' => array(
        'form' => NULL,
      ),
    ),
    'cctags_more' => array(
      'arguments' => array(
        'cctid' => NULL,
      ),
    ),
    'cctags_block' => array(
      'arguments' => array(
        'cctid' => NULL,
        'amount' => 0,
        'more_link' => TRUE,
      ),
    ),
    'cctags_level' => array(
      'file' => 'cctags.page.inc',
      'arguments' => array(
        'terms' => NULL,
        'amount' => 0,
        'page' => 0,
        'mode' => 'mixed',
        'vocname' => 0,
      ),
    ),
    'cctags_term' => array(
      'template' => 'cctags-term',
      'arguments' => array(
        'term' => NULL,
        'mode' => NULL,
      ),
    ),
    'cctags_vocname' => array(
      'template' => 'cctags-vocname',
      'arguments' => array(
        'vocname' => NULL,
        'vid' => NULL,
        'terms' => 0,
      ),
    ),
    'cctags_page' => array(
      'file' => 'cctags.page.inc',
      'template' => 'cctags-page',
      'arguments' => array(
        'cctid' => NULL,
        'content' => NULL,
        'pager' => NULL,
      ),
    ),
    'cctags_node_links_block' => array(
      'arguments' => array(
        'node' => NULL,
        $amount => 0,
      ),
    ),
    'cctags_user' => array(
      'template' => 'cctags-user',
      'arguments' => array(
        'cuser' => NULL,
      ),
    ),
    'cctags_user_item' => array(
      'template' => 'cctags-user-item',
      'arguments' => array(
        'cuser' => NULL,
      ),
    ),
    'cctags_user_page' => array(
      'template' => 'cctags-user-page',
      'arguments' => array(
        'content' => NULL,
        'pager' => NULL,
      ),
    ),
    'cctags_user_page_content' => array(
      'file' => 'cctags.page.inc',
      'arguments' => array(
        'users' => array(),
        'amount' => 0,
        'page' => 0,
      ),
    ),
    'cctags_user_more' => array(
      'arguments' => array(),
    ),
    'cctags_user_block' => array(
      'arguments' => array(
        'users' => NULL,
        'amount' => 0,
        'more_link' => TRUE,
      ),
    ),
  );
}
function theme_cctags_level($terms, $amount = 0, $page = 0, $mode = 'mixed', $vocname = 0, $out = 'page') {
  $output = '';
  $start_term = $amount * $page;
  $end_term = $start_term + $amount;
  $cur_term = 0;
  foreach ($terms as $voc => $tags) {
    if ($out == 'page') {
      if (!$vocname) {
        unset($terms[$voc]['vocname']);
      }
      $output .= theme('cctags_vocname', $terms[$voc]['vocname'], $terms[$voc]['vid'], $terms[$voc]['terms']);
    }
    if (is_numeric($voc)) {
      foreach ($tags as $term) {
        if ($cur_term >= $start_term && $cur_term < $end_term || $amount == 0) {
          $output .= theme('cctags_term', $term, $out);
        }
        $cur_term++;
      }
    }
  }
  return $output;
}
function theme_cctags_more($cctid) {
  $items = _cctags_get_settings($cctid);
  $page_path = $items[0]['page_path'];
  return '<div class="more-link">' . l(t('more tags'), $page_path) . '</div>';
}
function theme_cctags_node_links_block($node, $amount) {
  $output = '';
  if (isset($node->node_links) && is_array($node->node_links)) {
    if ($amount < count($node->node_links) - 1 && $amount > 0) {
      foreach ($node->taxonomy as $tid => $value) {
        $tids[] = $tid;
      }
      $path = 'taxonomy/term/' . implode('+', $tids);
      $more_links = '<div class="more-link">' . l(t('more nodes'), $path) . '</div>';
    }
    $cnt = 1;
    foreach ($node->node_links as $key => $values) {
      if ($amount < $cnt && $amount != 0) {
        break;
      }
      if ($values->nid != $node->nid) {
        $items[] = l($values->title, "node/{$key}", array(
          'attributes' => array(
            'class' => "cctags cctags-nodelinks ccfilter tooltip",
          ),
        ));
        $cnt++;
      }
    }
    $output .= theme('item_list', $items);
    $output .= $more_links;
  }
  if ($cnt == 1) {
    $output = NULL;
  }
  return $output;
}
function template_preprocess_cctags_term(&$variables) {
  $term = (object) $variables['term'];
  $mode = $variables['mode'];
  if ($term->count) {
    $term->link = l($term->name, $term->path, array(
      'attributes' => array(
        'class' => "cctags cctags-{$mode} vid-{$term->vid} level-{$term->level} depth-{$term->depth} count-{$term->count} ccfilter tooltip",
        'title' => $term->description,
        'rel' => 'tag',
      ),
    ));
  }
  else {
    $term->link = "<span class=\"cctags cctags-{$mode} vid-{$term->vid} level-{$term->level} depth-{$term->depth} count-{$term->count}\">{$term->name}</span>";
  }
  $variables['term'] = $term;
}
function theme_cctags_block($cctid, $amount, $more_link) {
  $terms = cctags_get_level_tags($cctid, 'block');
  $count = $terms['count'];
  unset($terms['count']);
  $output .= '<div class="cctags cctags-block wrapper">';
  $output .= theme('cctags_level', $terms, $amount, 0, 'mixed', 0, 'block');
  $output .= '</div>';
  if ($more_link && $count > $amount) {
    $output .= theme('cctags_more', $cctid);
  }
  return $output;
}
function template_preprocess_cctags_user(&$variables) {
  $cuser = (object) $variables['cuser'];
  $cuser->link = l($cuser->name, "user/{$cuser->uid}", array(
    'attributes' => array(
      'class' => "cctags cctags-block cctags-user level-{$cuser->level} ccfilter tooltip",
      'title' => t('%name profile', array(
        '%name' => $cuser->name,
      )),
    ),
  ));
  $variables['user'] = $cuser;
  unset($variables['cuser']);
}
function template_preprocess_cctags_user_item(&$variables) {
  $cuser = (object) $variables['cuser'];
  $cuser->link = l($cuser->name, "user/{$cuser->uid}", array(
    'attributes' => array(
      'class' => "cctags cctags-page cctags-user level-{$cuser->level} ccfilter tooltip",
      'title' => t('%name profile', array(
        '%name' => $cuser->name,
      )),
    ),
  ));
  $variables['user'] = $cuser;
  $variables['name'] = theme('username', $cuser);
  unset($variables['cuser']);
}
function theme_cctags_user_more() {
  return '<div class="more-link">' . l(t('more users'), 'cctags/users') . '</div>';
}
function theme_cctags_user_block($users, $amount, $more_link) {
  $count = $users['count'];
  unset($users['count']);
  $output .= '<div id="cctags-usercloud" class="cctags cctags-block cctags-users wrapper">';
  foreach ($users as $uid => $ccuser) {
    $output .= theme('cctags_user', $ccuser);
  }
  $output .= '</div>';
  if ($more_link && $count > $amount) {
    $output .= theme('cctags_user_more');
  }
  return $output;
}

Functions

Namesort descending Description
cctags_block implementation of hook_block
cctags_build_level_tags
cctags_build_level_users
cctags_cron Implementation of hook_cron
cctags_get_level_tags Function that gets the information from the database, passes it along to the weight builder and returns these weighted tags. Note that the tags are unordered at this stage, hence they need orndering either by calling our api or by your own ordering data.
cctags_get_node_links
cctags_get_users
cctags_get_user_weight
cctags_help Implementation of hook_help
cctags_init Implementation of hook_init
cctags_invoke_term_count Invoke a hook_term_count() operation in all modules.
cctags_invoke_user_weight Invoke a hook_user_weight() operation in all modules. or if defined function get_user_weight(&$user) set the $user->weight
cctags_menu Implementation of hook_menu
cctags_nodeapi Implementation of hook_nodeapi
cctags_node_get_terms API that returns a multidimensional array with tags given a node
cctags_sort_tags
cctags_tags_lists API function that returns the tags of a node in fancy titled lists
cctags_taxonomy
cctags_theme
cctags_user
template_preprocess_cctags_term
template_preprocess_cctags_user
template_preprocess_cctags_user_item
theme_cctags_block
theme_cctags_level
theme_cctags_more
theme_cctags_node_links_block
theme_cctags_user_block
theme_cctags_user_more
_cctags_clear_cache
_cctags_get_select_list
_cctags_get_settings
_cctags_sort
_cctags_sort_by_level callback for usort, sort by weight
_cctags_sort_by_title callback for usort, sort by count