/[drupal]/contributions/modules/tagadelic/tagadelic.module
ViewVC logotype

Diff of /contributions/modules/tagadelic/tagadelic.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.47, Thu Nov 13 11:44:20 2008 UTC revision 1.48, Mon Sep 14 19:32:04 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id$  // $Id: tagadelic.module,v 1.40.2.6 2009/05/13 16:56:12 ber Exp $
3    
4  /**  /**
5   * Implementation of hook_help   * Implementation of hook_help
6   */   */
7  function tagadelic_help($path, $arg) {  function tagadelic_help($path, $arg) {
8    switch ($path) {    switch ($path) {
9      case 'admin/help#tagadelic':     case 'admin/help#tagadelic':
10        return t('Tagadelic offers dynamic urls. <br/>Visit example.com/tagadelic/list/2,1,5 to get the vocabularies 2,1 and 5 listed as tag groups. <br/>Visit example.com/tagadelic/chunk/2,1,5 to get a tag cloud of the terms in the vocabularies 2,1 and 5.<br/> Note that we limit to five vocabularies.');        return t('Tagadelic offers dynamic urls. <br/>Visit example.com/tagadelic/list/2,1,5 to get the vocabularies 2,1 and 5 listed as tag groups. <br/>Visit example.com/tagadelic/chunk/2,1,5 to get a tag cloud of the terms in the vocabularies 2,1 and 5.<br/> Note that we limit to five vocabularies.');
11    }    }
12  }  }
# Line 157  function tagadelic_page_list($vocs) { Line 157  function tagadelic_page_list($vocs) {
157      return drupal_not_found();      return drupal_not_found();
158    }    }
159    
160      $stylesheet = drupal_get_path('module', 'tagadelic') .'/tagadelic.css';
161      drupal_add_css($stylesheet, 'all');
162    
163    $output = "<div class=\"wrapper tagadelic\">$output</div>";    $output = "<div class=\"wrapper tagadelic\">$output</div>";
164    return $output;    return $output;
165  }  }
# Line 166  function tagadelic_page_list($vocs) { Line 169  function tagadelic_page_list($vocs) {
169   * @param $node. A node object.   * @param $node. A node object.
170   */   */
171  function tagadelic_node_get_terms($node) {  function tagadelic_node_get_terms($node) {
172      static $vocs;
173    if ($terms = taxonomy_node_get_terms($node, 'tid')) {    if ($terms = taxonomy_node_get_terms($node, 'tid')) {
174        if (!isset($vocs[$node->type])) {
175          $vocs[$node->type] = taxonomy_get_vocabularies($node->type);
176        }
177      $tags = array();      $tags = array();
     $vocs = taxonomy_get_vocabularies($node->type);  
178      foreach ($terms as $tid => $term) {      foreach ($terms as $tid => $term) {
179        if ($vocs[$term->vid]->tags) {        if ($vocs[$node->type][$term->vid]->tags) {
180          $tags[$term->vid][$tid] = $term;          $tags[$term->vid][$tid] = $term;
181        }        }
182      }      }
# Line 207  function tagadelic_tags_lists($node) { Line 213  function tagadelic_tags_lists($node) {
213   */   */
214  function tagadelic_get_weighted_tags($vids, $steps = 6, $size = 60) {  function tagadelic_get_weighted_tags($vids, $steps = 6, $size = 60) {
215    // build the options so we can cache multiple versions    // build the options so we can cache multiple versions
216    $options = implode($vids) .'_'. $steps .'_'. $size;    global $language;
217      $options = implode('_', $vids) .'_'. $language->language .'_'. $steps .'_'. $size;
218    // Check if the cache exists    // Check if the cache exists
219    $cache_name = 'tagadelic_cache_'. $options;    $cache_name = 'tagadelic_cache_'. $options;
220    $cache = cache_get($cache_name);    $cache = cache_get($cache_name, 'cache_page');
221    
222    // make sure cache has data    // make sure cache has data
223    if (isset($cache->data)) {    if (isset($cache->data)) {
# Line 222  function tagadelic_get_weighted_tags($vi Line 228  function tagadelic_get_weighted_tags($vi
228      if (!is_array($vids) || count($vids) == 0) {      if (!is_array($vids) || count($vids) == 0) {
229        return array();        return array();
230      }      }
231      $result = db_query_range('SELECT COUNT(*) AS count, d.tid, d.name, d.vid FROM {term_data} d INNER JOIN {term_node} n ON d.tid = n.tid WHERE d.vid IN ('. substr(str_repeat('%d,', count($vids)), 0, -1) .') GROUP BY d.tid, d.name, d.vid ORDER BY count DESC', $vids, 0, $size);      $result = db_query_range(db_rewrite_sql('SELECT COUNT(*) AS count, td.tid, td.vid, td.name, td.description FROM {term_data} td INNER JOIN {term_node} tn ON td.tid = tn.tid INNER JOIN {node} n ON tn.vid = n.vid WHERE td.vid IN ('. db_placeholders($vids) .') GROUP BY td.tid, td.vid, td.name, td.description HAVING COUNT(*) > 0 ORDER BY count DESC'), $vids, 0, $size);
232    
233      $tags = tagadelic_build_weighted_tags($result, $steps);      $tags = tagadelic_build_weighted_tags($result, $steps);
234    
235      cache_set($cache_name, $tags, 'cache', CACHE_TEMPORARY);      cache_set($cache_name, $tags, 'cache_page', CACHE_TEMPORARY);
236    }    }
237    
238    return $tags;    return $tags;
# Line 295  function _tagadelic_sort_by_title($a, $b Line 301  function _tagadelic_sort_by_title($a, $b
301   * callback for usort, sort by weight   * callback for usort, sort by weight
302   */   */
303  function _tagadelic_sort_by_weight($a, $b) {  function _tagadelic_sort_by_weight($a, $b) {
304      if ($a->weight == $b->weight) {
305        // Ensure correct order when same weight
306        return $a->count > $b->count;
307      }
308    return $a->weight > $b->weight;    return $a->weight > $b->weight;
309  }  }
310    
# Line 305  function _tagadelic_sort_by_weight($a, $ Line 315  function _tagadelic_sort_by_weight($a, $
315  function theme_tagadelic_weighted($terms) {  function theme_tagadelic_weighted($terms) {
316    $output = '';    $output = '';
317    foreach ($terms as $term) {    foreach ($terms as $term) {
318      $output .= l($term->name, taxonomy_term_path($term), array('attributes' => array('class' => "tagadelic level$term->weight", 'rel' => 'tag'))) ." \n";      $output .= l($term->name, taxonomy_term_path($term), array(
319          'attributes' => array(
320            'class' => "tagadelic level$term->weight",
321            'rel' => 'tag',
322            'title'  => $term->description,
323            )
324          )
325        ) ." \n";
326    }    }
327    return $output;    return $output;
328  }  }
# Line 394  function tagadelic_theme() { Line 411  function tagadelic_theme() {
411      'tagadelic_weighted' => array('arguments' => array('terms' => NULL))      'tagadelic_weighted' => array('arguments' => array('terms' => NULL))
412    );    );
413  }  }
414    

Legend:
Removed from v.1.47  
changed lines
  Added in v.1.48

  ViewVC Help
Powered by ViewVC 1.1.2