? .svn
? community_tags_debug_bak.js
? multiple_vids.patch
Index: community_tags.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/community_tags/community_tags.js,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 community_tags.js
--- community_tags.js	1 Aug 2007 22:38:49 -0000	1.1.2.2
+++ community_tags.js	11 Dec 2007 16:18:54 -0000
@@ -27,12 +27,13 @@
 if (Drupal.jsEnabled) {
   $(document).ready(function () {
     // Note: all tag fields are autocompleted, and have already been initialized at this point.
+    var communityTagsSettings = Drupal.settings.communityTags;
     $('input.form-tags').each(function () {
       // Hide submit buttons.
       $('input[@type=submit]', this.form).hide();
 
       // Fetch settings.
-      var o = Drupal.settings.communityTags;
+      var o = communityTagsSettings.shift();
       var sequence = 0;
 
       // Patch for drupal_to_js() bug in Drupal 5.1
Index: community_tags.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/community_tags/community_tags.module,v
retrieving revision 1.32.2.2
diff -u -r1.32.2.2 community_tags.module
--- community_tags.module	1 Aug 2007 22:38:49 -0000	1.32.2.2
+++ community_tags.module	11 Dec 2007 16:18:55 -0000
@@ -173,30 +173,30 @@
     drupal_set_title(check_plain($node->title));
   }
 
-  $cloud = community_tags_display('node', NULL, $node->nid);
-
-  $vid = array_shift(community_tags_vids_for_node($node));
-  $tags = community_tags_get_user_node_tags($user->uid, $node->nid);
-  $names = array();
+  $vids = community_tags_vids_for_node($node);
+  foreach ($vids as $vid) {
+    $cloud = community_tags_display('node', NULL, $node->nid, $vid);
+    $tags = community_tags_get_user_node_tags($user->uid, $node->nid, $vid);
+    $names = array();
+  
+    if (!count($tags)) {
+      // User has not yet added tags to this node yet. Show form.
+      $output .= drupal_get_form('community_tags_form', array('cloud' => $cloud, 'nid' => $node->nid, 'vid' => $vid, 'tags' => NULL, 'inline' => $inline));
+    }
+    elseif (user_access('edit own tags')) {
+      // User has already tagged this node, but can edit their tags. Show form
+      // with the user's tags pre-populated.
+      $names = community_tags_flatten($tags);
+      $tags = taxonomy_implode_tags($tags);
+      $output .= drupal_get_form('community_tags_form', array('cloud' => $cloud, 'nid' => $node->nid, 'vid' => $vid, 'tags' => $tags, 'inline' => $inline));
+    }
+    else {
+      // Sorry, no more adding tags for you!
+      $output .= '<p>'. t('You have already tagged this post. Your tags: ') . theme('community_tags', 'user_node', NULL, $user->uid, $node->nid) .'</p>';
+    }
 
-  if (!count($tags)) {
-    // User has not yet added tags to this node yet. Show form.
-    $output .= drupal_get_form('community_tags_form', array('cloud' => $cloud, 'nid' => $node->nid, 'vid' => $vid, 'tags' => NULL, 'inline' => $inline));
-  }
-  elseif (user_access('edit own tags')) {
-    // User has already tagged this node, but can edit their tags. Show form
-    // with the user's tags pre-populated.
-    $names = community_tags_flatten($tags);
-    $tags = taxonomy_implode_tags($tags);
-    $output .= drupal_get_form('community_tags_form', array('cloud' => $cloud, 'nid' => $node->nid, 'vid' => $vid, 'tags' => $tags, 'inline' => $inline));
+    drupal_add_js(array('communityTags' => array(array('tags' => $names, 'url' => url('community-tags/js/'. $node->nid .'/'. $vid), 'add' => t('Add')))), 'setting');
   }
-  else {
-    // Sorry, no more adding tags for you!
-    $output .= '<p>'. t('You have already tagged this post. Your tags: ') . theme('community_tags', 'user_node', NULL, $user->uid, $node->nid) .'</p>';
-  }
-
-  drupal_add_js(array('communityTags' => array('tags' => $names, 'url' => url('community-tags/js/'. $node->nid), 'add' => t('Add'))), 'setting');
-
   return $output;
 }
 
@@ -228,7 +228,11 @@
         community_tags_taxonomy_node_save($node->nid, $node->taxonomy, TRUE, $user->uid);
       }
       break;
-
+      
+    case 'delete':
+      community_tags_taxonomy_node_delete($node->nid);
+      break;
+      
     case 'view':
       global $user;
       // Show quick tag form for this node if we're on a node page view and the
@@ -263,7 +267,7 @@
       '#title' => t('Community vocabularies'),
       '#default_value' => variable_get('community_tags_vocabularies', array()),
       '#options' => $options,
-      '#description' => t('Which vocabularies should community tagging use? Note: only one community tagged vocabulary per node type is supported.'),
+      '#description' => t('Which vocabularies should community tagging use?'),
     );
   }
 
@@ -296,9 +300,9 @@
 /**
  * Retrieve list of tags for a given node that belong to a user.
  */
-function community_tags_get_user_node_tags($uid, $nid) {
+function community_tags_get_user_node_tags($uid, $nid, $vid) {
   $tags = array();
-  $result = db_query("SELECT t.tid, t.name, c.uid, c.nid FROM {term_data} t INNER JOIN {community_tags} c ON c.tid = t.tid WHERE c.nid = %d AND c.uid = %d ORDER BY t.name", $nid, $uid);
+  $result = db_query("SELECT t.tid, t.name, c.uid, c.nid FROM {term_data} t INNER JOIN {community_tags} c ON c.tid = t.tid WHERE c.nid = %d AND c.uid = %d AND t.vid = %d ORDER BY t.name", $nid, $uid, $vid);
   while ($term = db_fetch_object($result)) {
     $tags[$term->tid] = $term;
   }
@@ -310,27 +314,29 @@
  * Quick tag form
  */
 function community_tags_form($edit, $title = NULL) {
+  $vocabulary = taxonomy_get_vocabulary($edit['vid']);
+  
   $form['cloud'] = array(
     '#type' => 'markup',
-    '#title' => t('All tags'),
+    '#title' => t('All !name', array('!name' => $vocabulary->name)),
     '#value' => $edit['cloud'],
   );
   
   $access = user_access('tag content');
 
-  $form['tags'] = array(
+  $form['tags-'. $edit['vid']] = array(
     '#type' => 'textfield',
-    '#title' => t('My tags'),
+    '#title' => t('My !name', array('!name' => $vocabulary->name)),
     '#maxlength' => 100,
     '#default_value' => $edit['tags'],
     '#required' => FALSE,
     '#autocomplete_path' => 'taxonomy/autocomplete/'. $edit['vid'],
     '#description' => t('<span class="no-js">A comma-separated list of terms describing this content. </span>Example: funny, bungee jumping, "Company, Inc.".'),
-    '#attributes' => array('class' => 'form-tags'),
+    '#attributes' => array('class' => 'form-tags form-tags-'. $edit['vid']),
     '#access' => $access,
   );
   if ($edit['inline']) {
-    $form['tags']['#size'] = 20;
+    $form['tags-'. $edit['vid']]['#size'] = 20;
   }
   
   if (!$access) {
@@ -384,7 +390,7 @@
  * @ingroup themeable
  */
 function theme_community_tags_form($form) {
-  $output .= theme('form_element', array('#title' => t('All tags')), drupal_render($form['cloud']));
+  $output .= theme('form_element', array('#title' => $form['cloud']['#title']), drupal_render($form['cloud']));
 
   $output .= drupal_render($form);
 
@@ -409,7 +415,7 @@
 /**
  * Callback for the JS tagger.
  */
-function community_tags_from_js($nid) {
+function community_tags_from_js($nid, $vid) {
   global $user;
   if (!is_numeric($nid) || !($node = node_load($nid))) {
     return;
@@ -419,11 +425,10 @@
 
   // Merge in new tag and save
   $tags = array_unique(array_merge($tags, taxonomy_explode_tags($_POST['add'])));
-  $vid = array_shift(community_tags_vids_for_node($node));
   community_tags_taxonomy_node_save($node->nid, array('tags' => array($vid => $tags)), FALSE, $user->uid);
 
   // Fetch updated list
-  $tags = community_tags_flatten(community_tags_get_user_node_tags($user->uid, $node->nid));
+  $tags = community_tags_flatten(community_tags_get_user_node_tags($user->uid, $node->nid, $vid));
 
   // Output JSON
   drupal_set_header('Content-Type: text/javascript; charset=utf-8');
@@ -431,6 +436,13 @@
 }
 
 /**
+ * Delete community_tags term associations for a given node.
+ */
+function community_tags_taxonomy_node_delete($nid) {
+  db_query('DELETE FROM {community_tags} WHERE nid = %d', $nid);
+}
+
+/**
  * Save community_tags term associations and counts for a given node.
  */
 function community_tags_taxonomy_node_save($nid, $terms, $is_owner, $uid) {
@@ -444,7 +456,7 @@
   // If not, we at least want the existing counts to update them.
 
   $old_tags_by_uid = array();
-  $result = db_query('SELECT * FROM {community_tags} ttn WHERE nid = %d', $nid);
+  $result = db_query('SELECT ttn.*, td.vid FROM {community_tags} ttn JOIN {term_data} td ON td.tid = ttn.tid WHERE ttn.nid = %d', $nid);
   while ($old_tag_node = db_fetch_object($result)) {
     $old_tags_by_uid[$old_tag_node->uid][$old_tag_node->tid] = $old_tag_node;
   }
@@ -452,6 +464,7 @@
   $tag_nodes = array();
   $inserted_tids = array();
 
+  $vids = array();
   $tids = array();
   // Free tagging vocabularies do not send their tids in the form,
   // so we'll detect them here and process them independently.
@@ -460,6 +473,7 @@
     unset($terms['tags']);
 
     foreach ($typed_input as $vid => $vid_value) {
+      $vids[] = $vid;
       $typed_terms = is_array($vid_value) ? $vid_value : taxonomy_explode_tags($vid_value);
       foreach ($typed_terms as $typed_term) {
         // See if the term exists in the chosen vocabulary
@@ -508,7 +522,8 @@
       if ($is_owner && isset($inserted_tids[$old_tag->tid]) && $old_tag->uid != $uid) {
         $tag_nodes[] = $old_tag;
       }
-      elseif (!$is_owner && $old_tag->uid != $uid) {
+      // Else reinsert other people's existing tags and existing tags of other vocabularies.
+      elseif (!$is_owner && ($old_tag->uid != $uid || !in_array($old_tag->vid, $vids))) {
         $tag_nodes[] = $old_tag;
       }
     }
@@ -594,8 +609,12 @@
   switch ($type) {
     case 'node':
       $arg1 = (int)$arg1;
-      $arg2 = NULL;
-      $sql = "SELECT COUNT(c.tid) AS count, t.tid, t.name, t.vid FROM {term_data} t INNER JOIN {community_tags} c ON c.tid = t.tid WHERE c.nid = %d GROUP BY c.tid ORDER BY count DESC";
+      if ($arg2) {
+        $sql = "SELECT COUNT(c.tid) AS count, t.tid, t.name, t.vid FROM {term_data} t INNER JOIN {community_tags} c ON c.tid = t.tid WHERE c.nid = %d AND t.vid = %d GROUP BY c.tid ORDER BY count DESC";
+      }
+      else {
+        $sql = "SELECT COUNT(c.tid) AS count, t.tid, t.name, t.vid FROM {term_data} t INNER JOIN {community_tags} c ON c.tid = t.tid WHERE c.nid = %d GROUP BY c.tid ORDER BY count DESC";
+      }
       break;
     case 'type':
       $arg1 = (int)$arg1;
