? ctags_vids_ajax.patch
Index: community_tags.ajax.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/community_tags/community_tags.ajax.inc,v
retrieving revision 1.2
diff -u -p -r1.2 community_tags.ajax.inc
--- community_tags.ajax.inc	4 Dec 2009 22:24:56 -0000	1.2
+++ community_tags.ajax.inc	14 May 2010 18:35:03 -0000
@@ -15,18 +15,23 @@
 /**
  * Callback for the JS tagger.
  */
-function community_tags_from_js($node) {
+function community_tags_from_js($node,$vid=NULL) {
   global $user;
 
   $tags = (isset($_POST['tags']) && is_array($_POST['tags'])) ? $_POST['tags'] : array();
 
   // Merge in new tag and save.
   $tags = array_unique(array_merge($tags, drupal_explode_tags($_POST['add'])));
-  $vid = array_shift(community_tags_vids_for_node($node));
+  
+  //There should always be $vid, but if not, this will make a best guess.
+  if(!$vid){
+    $vid = array_shift(community_tags_vids_for_node($node));
+  }
+  
   community_tags_taxonomy_node_save($node, 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.
   print drupal_json(array('status' => TRUE, 'tags' => $tags, 'sequence' => $_POST['sequence']));
Index: community_tags.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/community_tags/community_tags.js,v
retrieving revision 1.5
diff -u -p -r1.5 community_tags.js
--- community_tags.js	4 Dec 2009 22:24:56 -0000	1.5
+++ community_tags.js	14 May 2010 18:35:04 -0000
@@ -34,7 +34,8 @@ Drupal.behaviors.communityTags = functio
 
       // Fetch settings.
       var nid = $('input[name=nid]', this.form).val();
-      var o = Drupal.settings.communityTags['n_' + nid];
+      var vid = $('input[name=vid]', this.form).val();
+      var o = Drupal.settings.communityTags['n_' + nid]['v_' + vid];
 
       var sequence = 0;
 
Index: community_tags.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/community_tags/community_tags.module,v
retrieving revision 1.38.2.1
diff -u -p -r1.38.2.1 community_tags.module
--- community_tags.module	14 May 2010 04:43:35 -0000	1.38.2.1
+++ community_tags.module	14 May 2010 18:35:04 -0000
@@ -247,9 +247,9 @@ function community_tags_form_alter(&$for
 /**
  * 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;
   }
@@ -272,7 +272,7 @@ function community_tags_taxonomy_node_sa
   // 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 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;
   }
@@ -281,14 +281,20 @@ function community_tags_taxonomy_node_sa
   $inserted_tids = array();
 
   $tids = array();
+  $vids = array(); // Future support for multiple vocabularies to be used in the same form
+
+  // Process the entries from the quick tag form
+
   // Free tagging vocabularies do not send their tids in the form,
   // so we'll detect them here and process them independently.
   if (isset($terms['tags'])) {
     $typed_input = $terms['tags'];
     unset($terms['tags']);
     
-      foreach ($typed_input as $vid=>$vid_value) {
-        if (isset($community_tagged[$vid])) {
+    foreach ($typed_input as $vid=>$vid_value) {
+      if (isset($community_tagged[$vid])) {
+        // http://groups.google.com/group/tickets-cakephp/browse_thread/thread/7f5f9ab54795a4d3
+        $vids[$vid] = true;
 
         $typed_terms = is_array($vid_value)?$vid_value:drupal_explode_tags($vid_value);
         foreach ($typed_terms as $typed_term) {
@@ -299,6 +305,7 @@ function community_tags_taxonomy_node_sa
           foreach ($possibilities as $possibility) {
             if ($possibility->vid == $vid) {
               $typed_term_tid = $possibility->tid;
+              break; // Stop at the first one
             }
           }
     
@@ -340,7 +347,8 @@ function community_tags_taxonomy_node_sa
       if ($is_owner && isset($inserted_tids[$old_tag->tid]) && $old_tag->uid != $uid) {
         $tag_nodes[] = $old_tag;
       }
-      elseif (!$is_owner && $old_tag->uid != $uid) {
+      // Otherwise, re-insert if it's another user's or another vid
+      elseif (!$is_owner && ($old_tag->uid != $uid || !isset($vids[$old_tag->vid]))) {
         $tag_nodes[] = $old_tag;
       }
     }
@@ -468,30 +476,32 @@ function community_tags_node_view($node,
 
   //!/  $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();
-  $output = '';
-  
+  $vids = community_tags_vids_for_node($node);
   module_load_include('inc', 'community_tags', 'community_tags.pages');
+  $output = '';
+  foreach ($vids as $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('node' => $node,/* //!/ '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('node' => $node,/* //!/'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: ') .'</p>';
+    }
 
-  if (!count($tags)) {
-    // User has not yet added tags to this node yet. Show form.
-    $output .= drupal_get_form('community_tags_form', array('node' => $node,/* //!/ '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('node' => $node,/* //!/'cloud' => $cloud,*/ 'nid' => $node->nid, 'vid' => $vid, 'tags' => $tags, 'inline' => $inline));
+    // TODO might want to optimise this call
+    drupal_add_js(array('communityTags' => array('n_'. $node->nid => array('v_'. $vid => 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: ') .'</p>';
-  }
-
-  drupal_add_js(array('communityTags' => array('n_'. $node->nid => array('tags' => $names, 'url' => url('community-tags/js/'. $node->nid), 'add' => t('Add')))), 'setting');
 
   return $output;
 }
Index: community_tags.pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/community_tags/community_tags.pages.inc,v
retrieving revision 1.2
diff -u -p -r1.2 community_tags.pages.inc
--- community_tags.pages.inc	4 Dec 2009 22:24:56 -0000	1.2
+++ community_tags.pages.inc	14 May 2010 18:35:04 -0000
@@ -15,6 +15,7 @@
  * Quick tag form.
  */
 function community_tags_form($form_state, $edit, $title = NULL) {
+  $vocabulary = taxonomy_vocabulary_load($edit['vid']);
   
 /* //!/ $form['cloud'] = array(
     '#type' => 'markup',
@@ -27,12 +28,12 @@ function community_tags_form($form_state
 
   $form['tags'] = 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'],
-    '#attributes' => array('class' => 'form-tags'),
+    '#attributes' => array('class' => 'form-tags form-tags-'. $edit['vid']),
     '#access' => $access,
   );
   if ($edit['inline']) {
@@ -65,7 +66,7 @@ function community_tags_form($form_state
   );
 
   $form['vid'] = array(
-    '#type' => 'value',
+    '#type' => 'hidden',
     '#value' => $edit['vid'],
   );
 
@@ -128,18 +129,17 @@ function community_tags_settings() {
 
   // Build list of available free-tagging vocabularies
   $options = array();
-  $vocabs = db_query('SELECT v.vid, v.name FROM {vocabulary} v WHERE v.tags = 1 ORDER BY v.weight, v.name');
+  $vocabs = db_query('SELECT v.vid, v.name FROM {vocabulary} v ORDER BY v.weight, v.name');
   while ($vocabulary = db_fetch_object($vocabs)) {
     $options[$vocabulary->vid] = $vocabulary->name;
   }
   if ($options) {
     $form['community_tags_vocabularies'] = array(
-      '#type' => 'select',
-      '#multiple' => TRUE,
+      '#type' => 'checkboxes',
       '#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?'),
     );
   }
 
