Index: tagadelic.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/tagadelic/tagadelic.info,v
retrieving revision 1.4
diff -u -r1.4 tagadelic.info
--- tagadelic.info	1 May 2008 12:48:05 -0000	1.4
+++ tagadelic.info	7 Apr 2010 21:17:40 -0000
@@ -1,6 +1,7 @@
 ; $Id: tagadelic.info,v 1.4 2008/05/01 12:48:05 ber Exp $
 name = Tagadelic
 description = Tagadelic makes weighted tag clouds from your taxonomy terms.
-core = 6.x
+core = 7.x
 dependencies[] = taxonomy
 package = "Taxonomy"
+files[] = "tagadelic.module"
Index: tagadelic.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/tagadelic/tagadelic.module,v
retrieving revision 1.48
diff -u -r1.48 tagadelic.module
--- tagadelic.module	14 Sep 2009 19:32:04 -0000	1.48
+++ tagadelic.module	7 Apr 2010 21:17:41 -0000
@@ -1,30 +1,30 @@
 <?php
-// $Id: tagadelic.module,v 1.48 2009/09/14 19:32:04 ber Exp $
+// $Id$
 
 /**
- * Implementation of hook_help
+ * Implements hook_help().
  */
 function tagadelic_help($path, $arg) {
   switch ($path) {
-   case 'admin/help#tagadelic':
+    case 'admin/help#tagadelic':
       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.');
   }
 }
 
 /**
- * Implementation of hook_init
+ * Implements hook_init().
  */
 function tagadelic_init() {
-  drupal_add_css(drupal_get_path('module', 'tagadelic') .'/tagadelic.css');
+  drupal_add_css(drupal_get_path('module', 'tagadelic') . '/tagadelic.css');
 }
 
 /**
- * Implementation of hook_menu
+ * Implements hook_menu().
  */
 function tagadelic_menu() {
   $items = array();
 
-  $items['admin/settings/tagadelic'] = array(
+  $items['admin/config/user-interface/tagadelic'] = array(
     'title' => 'Tagadelic configuration',
     'description' => 'Configure the tag clouds. Set the order, the number of tags, and the depth of the clouds.',
     'page callback' => 'drupal_get_form',
@@ -36,7 +36,7 @@
     'title' => 'Tags',
     'page callback' => 'tagadelic_page_chunk',
     'page arguments' => array(NULL),
-    'access callback' => 'user_access',      
+    'access callback' => 'user_access',
     'access arguments' => array('access content'),
     'type' => MENU_SUGGESTED_ITEM,
   );
@@ -60,12 +60,11 @@
 }
 
 /**
- * Implementation of hook_nodeapi
- * You will have a nice variable in $node available for processing tags!
+ * Implements hook_node_load().
  */
-function tagadelic_nodeapi(&$node, $op, $teaser, $page) {
-  if ($op == 'load') {
-     $node->tags = tagadelic_node_get_terms($node);
+function tagadelic_node_load($nodes, $types) {
+  foreach ($nodes as $node) {
+    $node->tags = tagadelic_node_get_terms($node);
   }
 }
 
@@ -99,7 +98,7 @@
 }
 
 /**
- * menu wildcard callback
+ * Menu wildcard callback
  */
 function tagadelic_vocs_load($vocs) {
   if (is_numeric($vocs)) {
@@ -112,7 +111,7 @@
 }
 
 /**
- * menu callback renders a tagadelic page
+ * Menu callback renders a tagadelic page
  */
 function tagadelic_page_chunk($vocs) {
 
@@ -124,7 +123,7 @@
 
   $tags = tagadelic_get_weighted_tags($vocs, variable_get('tagadelic_levels', 6), variable_get('tagadelic_page_amount', '60'));
   $tags = tagadelic_sort_tags($tags);
-  $output = theme('tagadelic_weighted', $tags);
+  $output = theme('tagadelic_weighted', array('terms' => $tags));
 
   if (!$output) {
     return drupal_not_found();
@@ -136,7 +135,7 @@
 }
 
 /**
- * menu callback renders a tagadelic page with listed items: each voc
+ * Menu callback renders a tagadelic page with listed items: each voc
  */
 function tagadelic_page_list($vocs) {
 
@@ -150,14 +149,14 @@
     $tags = tagadelic_get_weighted_tags(array($vocabulary->vid), variable_get('tagadelic_levels', 6), variable_get('tagadelic_page_amount', '60'));
     $tags = tagadelic_sort_tags($tags);
 
-    $output .= theme('tagadelic_list_box', $vocabulary, $tags);
+    $output .= theme('tagadelic_list_box', array('vocabulary' => $vocabulary, 'tags' => $tags));
   }
 
   if (!$output) {
     return drupal_not_found();
   }
 
-  $stylesheet = drupal_get_path('module', 'tagadelic') .'/tagadelic.css';
+  $stylesheet = drupal_get_path('module', 'tagadelic') . '/tagadelic.css';
   drupal_add_css($stylesheet, 'all');
 
   $output = "<div class=\"wrapper tagadelic\">$output</div>";
@@ -169,43 +168,61 @@
  * @param $node. A node object.
  */
 function tagadelic_node_get_terms($node) {
-  static $vocs;
-  if ($terms = taxonomy_node_get_terms($node, 'tid')) {
-    if (!isset($vocs[$node->type])) {
-      $vocs[$node->type] = taxonomy_get_vocabularies($node->type);
-    }
-    $tags = array();
-    foreach ($terms as $tid => $term) {
-      if ($vocs[$node->type][$term->vid]->tags) {
-        $tags[$term->vid][$tid] = $term;
-      }
-    }
-    return $tags;
+  $tags = array();
+  $result = db_query('SELECT ti.tid AS tid, td.vid AS vid, td.name AS name, td.description AS description, td.weight AS weight FROM {taxonomy_index} ti INNER JOIN {taxonomy_term_data} td ON ti.tid = td.tid INNER JOIN {taxonomy_vocabulary} tv ON td.vid = tv.vid WHERE ti.nid = :nid ORDER BY tv.weight, td.weight, td.name', array(':nid' => $node->nid));
+  foreach ($result as $term) {
+    $tags[$term->tid] = $term;
   }
+  return $tags;
 }
 
-
 /**
  * API function that returns the tags of a node in fancy titled lists
  * @param $node. A node object.
  */
 function tagadelic_tags_lists($node) {
-  if (is_array($node->tags)) {
+  $tags = tagadelic_node_tags($node);
+  if (!empty($tags)) {
     $output = '';
-    foreach ($node->tags as $vid => $terms) {
+    foreach ($tags as $vid => $terms) {
       $vocabulary = taxonomy_vocabulary_load($vid);
       $title = l($vocabulary->name, "tagadelic/chunk/$vid");
       $items = array();
       foreach ($terms as $term) {
-        $items[] = l($term->name, taxonomy_term_path($term), array('attributes' => array('title' => t('view all posts tagged with "@tag"', array('@tag' => $term->name)))));
+        $items[] = l($term->name, 'taxonomy/term/' . $term->tid, array('attributes' => array('title' => t('view all posts tagged with "@tag"', array('@tag' => $term->name)))));
       }
-      $output .= theme('item_list', $items, $title);
+      $output .= theme('item_list', array('items' => $items, 'title' => $title));
     }
     return $output;
   }
 }
 
 /**
+ * Returns an array of all terms with which a node is tagged,
+ * grouped by vocabulary
+ */
+function tagadelic_node_tags($node) {
+ // Get a list of all term reference fields attached to this node type
+  $term_reference_fields = db_query("SELECT fc.field_name FROM {field_config_instance} fci JOIN {field_config} fc ON fci.field_id = fc.id WHERE fci.bundle = :type AND fc.type = 'taxonomy_term_reference'", array(':type' => $node->type))->fetchCol();
+
+  $tags = array();
+  // Loop through each vocabulary attached to this node type
+  foreach ($term_reference_fields as $term_reference_field) {
+    // Check if the node contains any taxonomy terms from this vocabulary
+    if (!empty($node->$term_reference_field)) {
+      // Get the vocabulary object
+      $taxonomy_tags = $node->$term_reference_field;
+      // Loop through each term attached to the node
+      foreach ($taxonomy_tags['und'] as $term) {
+        // Add each term to the array
+        $tags[$term['taxonomy_term']->vid][$term['tid']] = $term['taxonomy_term'];
+      }
+    }
+  }
+  return $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.
  * @param $vids. Vocabulary IDs representing the vocabularies where you want the tags from.
  * @param $steps. The amount of tag-sizes you will be using. If you give "12" you sill get six different "weights". Defaults to 6 and is optional.
@@ -214,27 +231,39 @@
 function tagadelic_get_weighted_tags($vids, $steps = 6, $size = 60) {
   // build the options so we can cache multiple versions
   global $language;
-  $options = implode('_', $vids) .'_'. $language->language .'_'. $steps .'_'. $size;
+  $options = implode('_', $vids) . '_' . $language->language . '_' . $steps . '_' . $size;
   // Check if the cache exists
-  $cache_name = 'tagadelic_cache_'. $options;
+  $cache_name = 'tagadelic_cache_' . $options;
   $cache = cache_get($cache_name, 'cache_page');
-  
+
   // make sure cache has data
   if (isset($cache->data)) {
     $tags = $cache->data;
   }
   else {
-  
     if (!is_array($vids) || count($vids) == 0) {
       return array();
     }
-    $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);
-    
+
+    $query = db_select('taxonomy_term_data', 'td')
+      ->fields('td', array('tid', 'vid', 'name', 'description'))
+      ->join('taxonomy_index', 'ti', 'td.tid = ti.tid')
+      ->join('node', 'n', 'ti.nid = n.nid')
+      ->condition('td.vid', $vids, 'IN')
+      ->groupBy('td.tid')
+      ->groupBy('td.vid')
+      ->groupBy('td.name')
+      ->groupBy('td.description')
+      ->addExpression('COUNT(*)', 'count')
+      ->orderBy('count', 'DESC')
+      ->range(0, $size);
+    $result = $query->execute();
+
     $tags = tagadelic_build_weighted_tags($result, $steps);
 
     cache_set($cache_name, $tags, 'cache_page', CACHE_TEMPORARY);
   }
-  
+
   return $tags;
 }
 
@@ -250,7 +279,7 @@
   $tags = array();
   $min = 1e9;
   $max = -1e9;
-  while ($tag = db_fetch_object($result)) {
+  foreach ($result as $tag) {
     $tag->number_of_posts = $tag->count;
     $tag->count = log($tag->count);
     $min = min($min, $tag->count);
@@ -270,7 +299,7 @@
 /**
  * API funtion to order a set of tags.
  * @todo If you feel like making this more modular, please send me patches.
- **/
+ */
 function tagadelic_sort_tags($tags) {
   list($sort, $order) = explode(',', variable_get('tagadelic_sort_order', 'title,asc'));
   switch ($sort) {
@@ -291,14 +320,14 @@
 }
 
 /**
- * callback for usort, sort by count
+ * Callback for usort, sort by count
  */
 function _tagadelic_sort_by_title($a, $b) {
   return strnatcasecmp($a->name, $b->name);
 }
 
 /**
- * callback for usort, sort by weight
+ * Callback for usort, sort by weight
  */
 function _tagadelic_sort_by_weight($a, $b) {
   if ($a->weight == $b->weight) {
@@ -309,32 +338,28 @@
 }
 
 /**
- * theme function that renders the HTML for the tags
+ * Theme function that renders the HTML for the tags
  * @ingroup themable
  */
-function theme_tagadelic_weighted($terms) {
+function theme_tagadelic_weighted($variables) {
+  $terms = $variables['terms'];
   $output = '';
   foreach ($terms as $term) {
-    $output .= l($term->name, taxonomy_term_path($term), array(
-      'attributes' => array(
-        'class' => "tagadelic level$term->weight",
-        'rel' => 'tag',
-        'title'  => $term->description,
-        )
-      )
-    ) ." \n";
+    $output .= l($term->name, "taxonomy/term/$term->tid", array('attributes' => array('class' => array("tagadelic level$term->weight"), 'rel' => 'tag', 'title'  => $term->description, ))) . ' ';
   }
   return $output;
 }
 
 /**
- * theme function that renders an entry in tagadelic/list/ views
+ * Theme function that renders an entry in tagadelic/list/ views
  * @param $vocabulary, a full vocabulary object
  * @param $tags, an array with weigthed tag objects
  * @ingroup themable
  */
-function theme_tagadelic_list_box($vocabulary, $tags) {
-  $content = theme('tagadelic_weighted', $tags);
+function theme_tagadelic_list_box($variables) {
+$vocabulary = $variables['vocabulary'];
+  $tags = $variables['tags'];
+  $content = theme('tagadelic_weighted', array('terms' => $tags));
   if ($vocabulary->description) {
     $content = theme("box", NULL, $vocabulary->description) . $content;
   }
@@ -344,71 +369,68 @@
 }
 
 /**
- * theme function to provide a more link
+ * Theme function to provide a more link
  * @param $vid - vocab id for which more link is wanted
  * @ingroup themable
  */
-function theme_tagadelic_more($vid) {
-  return "<div class='more-link'>". l(t('more tags'), "tagadelic/chunk/$vid") ."</div>";
+function theme_tagadelic_more($variables) {
+  $vid = $variables['vid'];
+  return "<div class='more-link'>" . l(t('more tags'), "tagadelic/chunk/$vid") . "</div>";
 }
 
-/**
- * implementation of hook_block
- */
-function tagadelic_block($op = 'list', $delta = 0, $edit = array()) {
+function tagadelic_block_view($delta = '') {
   $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);
-      $blocks['content'] = theme('tagadelic_weighted', $tags);//return a chunk of 12 tags
-      if (count($tags) >= variable_get('tagadelic_block_tags_'. $delta, 12)) {
-        $blocks['content'] .= theme('tagadelic_more', $voc->vid);//add more link
-      }
-
-    }
-    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);
+  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);
+    $blocks['content'] = theme('tagadelic_weighted', array('terms' => $tags));//return a chunk of 12 tags
+    if (count($tags) >= variable_get('tagadelic_block_tags_' . $delta, 12)) {
+      $blocks['content'] .= theme('tagadelic_more', array('vid' => $voc->vid));//add more link
     }
-    return $blocks;
   }
-  elseif ($op == 'list') {
-    foreach (taxonomy_get_vocabularies() as $voc) {
-      $blocks[$voc->vid]['info'] = variable_get('tagadelic_block_title_'. $voc->vid, 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;
-    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;
+  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;
+}
+
+function tagadelic_block_info() {
+  $blocks = array();
+  foreach (taxonomy_get_vocabularies() as $voc) {
+    $blocks[$voc->vid]['info'] = variable_get('tagadelic_block_title_' . $voc->vid, t('Tags in @voc', array('@voc' => $voc->name)));
+    $blocks[$voc->vid]['cache'] = DRUPAL_CACHE_GLOBAL;
   }
+  $blocks[0]['info'] = t('Tags for the current post');
+  $blocks[0]['cache'] = DRUPAL_CACHE_PER_PAGE;
+  return $blocks;
+}
+
+function tagadelic_block_save($delta = '', $edit = array()) {
+  variable_set('tagadelic_block_tags_' . $delta, $edit['tags']);
+}
+
+function tagadelic_block_configure($delta = '') {
+  $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;
 }
 
 /**
- * Implementation of hook_theme
+ * Implements hook_theme().
  */
 function tagadelic_theme() {
   return array(
-    'tagadelic_list_box' => array('arguments' => array('vocabulary' => NULL, 'tags' => NULL)),
-    'tagadelic_more' => array('arguments' => array('vid' => NULL)),
-    'tagadelic_weighted' => array('arguments' => array('terms' => NULL))
+    'tagadelic_list_box' => array('variables' => array('vocabulary' => NULL, 'tags' => NULL)),
+    'tagadelic_more' => array('variables' => array('vid' => NULL)),
+    'tagadelic_weighted' => array('variables' => array('terms' => NULL))
   );
 }
-
Index: .project
===================================================================
RCS file: .project
diff -N .project
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ .project	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>Tagadelic DRUPAL-7--1</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+	</buildSpec>
+	<natures>
+	</natures>
+</projectDescription>
