Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/community_tags/README.txt,v
retrieving revision 1.3.4.1
diff -u -r1.3.4.1 README.txt
--- README.txt	11 Apr 2007 12:36:57 -0000	1.3.4.1
+++ README.txt	3 May 2007 00:40:40 -0000
@@ -23,7 +23,7 @@
 
      Administer > Site Building > Modules
 
-4. Create a free tagging vocabulary by going to:
+4. Create a vocabulary by going to:
 
      Administer > Content > Categories
 
Index: community_tags.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/community_tags/community_tags.module,v
retrieving revision 1.32
diff -u -r1.32 community_tags.module
--- community_tags.module	11 Apr 2007 12:31:32 -0000	1.32
+++ community_tags.module	3 May 2007 00:46:31 -0000
@@ -14,7 +14,7 @@
 function community_tags_help($section) {
   switch ($section) {
     case 'admin/settings/community-tags':
-      return t('To set up community tagging, you must first <a href="@taxonomy">create a normal free tagged vocabulary</a>. Then activate community tagging on such a vocabulary below, and set the <a href="@workflow">workflow options</a> for node types to control how users can tag nodes.', array('@taxonomy' => url('admin/content/taxonomy'), '@workflow' => url('admin/content/types')));
+      return t('To set up community tagging, you must first <a href="@taxonomy">create a normal vocabulary</a>. Then activate community tagging on such a vocabulary below, and set the <a href="@workflow">workflow options</a> for node types to control how users can tag nodes.', array('@taxonomy' => url('admin/content/taxonomy'), '@workflow' => url('admin/content/types')));
       break;
   }
 }
@@ -127,18 +127,20 @@
   $cloud = theme('community_tags', 'node', NULL, $node->nid);
 
   $vid = array_shift(community_tags_for_node($node));
+  $vocabulary = taxonomy_get_vocabulary($vid);
+
   $tags = community_tags_get_user_node_tags($user->uid, $node->nid);
   $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));
+    $output .= drupal_get_form('community_tags_form', array('cloud' => $cloud, 'nid' => $node->nid, 'vid' => $vid, 'taxonomy' => 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));
+    $taxonomy = $vocabulary->tags ? array('tags' => taxonomy_implode_tags($tags)) : array_keys($tags);
+    $output .= drupal_get_form('community_tags_form', array('cloud' => $cloud, 'nid' => $node->nid, 'vid' => $vid, 'taxonomy' => $taxonomy, 'inline' => $inline));
   }
   else {
     // Sorry, no more adding tags for you!
@@ -202,7 +204,7 @@
   $form = array();
 
   // Build list of available free-tagging vocabularies
-  $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;
   }
@@ -258,26 +260,37 @@
  * Quick tag form
  */
 function community_tags_form($edit, $title = NULL) {
-  $form['cloud'] = array(
-    '#type' => 'markup',
-    '#title' => t('All tags'),
-    '#value' => $edit['cloud'],
-  );
-
-  $form['tags'] = array(
-    '#type' => 'textfield',
-    '#title' => t('My tags'),
-    '#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'),
-  );
-  if ($edit['inline']) {
-    $form['tags']['#size'] = 20;
+  if ($edit['cloud']) {
+    $form['cloud'] = array(
+      '#type' => 'markup',
+      '#title' => t('All tags'),
+      '#value' => $edit['cloud'],
+    );
   }
 
+  $vocabulary = taxonomy_get_vocabulary($edit['vid']);
+
+  if ($vocabulary->tags) {
+    $form['taxonomy'] = array(
+      '#tree' => TRUE,
+    );
+    $form['taxonomy']['tags'] = array(
+      '#type' => 'textfield',
+      '#title' => t('My tags'),
+      '#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'),
+    );
+    if ($edit['inline']) {
+      $form['taxonomy']['tags']['#size'] = 20;
+    }
+  }
+  else {
+    $form['taxonomy'] = taxonomy_form($edit['vid'], $edit['taxonomy'], t('Add tags to this post'));
+  }
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Save'),
@@ -300,17 +313,25 @@
  * Validate the quick tag form.
  */
 function community_tags_form_validate($form_id, $form_values) {
-  if ($form_values['tags'] == '') {
+  if (isset($form_values['taxonomy']['tags']) && $form_values['taxonomy']['tags'] == '') {
     form_set_error('tags', t('You must enter at least one tag.'));
   }
+  if (isset($form_values['taxonomy']) && empty($form_values['taxonomy'])) {
+    form_set_error('tags', t('You must select at least one tag.'));
+  }
 }
 
 /**
- * Submit callback for quick tag form.
+ * Submit callback for tag form.
  */
 function community_tags_form_submit($form_id, $form_values) {
+  // If a single select value has been submitted we need to translate it
+  // into an array.
+  if (is_numeric($form_values['taxonomy'])) {
+    $form_values['taxonomy'] = array($form_values['taxonomy']);
+  }
   global $user;
-  community_tags_taxonomy_node_save($form_values['nid'], array('tags' => array($form_values['vid'] => $form_values['tags'])), FALSE, $user->uid);
+  community_tags_taxonomy_node_save($form_values['nid'], $form_values['taxonomy'], FALSE, $user->uid);
   
   return array('node/'. $form_values['nid']);
 }
@@ -367,121 +388,134 @@
 /**
  * Save community_tags term associations and counts for a given node.
  */
-function community_tags_taxonomy_node_save($nid, $terms, $is_owner, $uid) {
+function community_tags_taxonomy_node_save($nid, $taxonomy, $is_owner, $uid) {
+
+  // Process free tagging values if present.
+  if (isset($taxonomy['tags'])) {
+    // If we're adding tags from the node add/edit page, then we want to delete
+    // any tags that aren't entered to allow admins to remove node tags.
+    // 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);
+    while ($old_tag_node = db_fetch_object($result)) {
+      $old_tags_by_uid[$old_tag_node->uid][$old_tag_node->tid] = $old_tag_node;
+    }
+
+    $tag_nodes = array();
+    $inserted_tids = array();
 
-  // If we're adding tags from the node add/edit page, then we want to delete
-  // any tags that aren't entered to allow admins to remove node tags.
-  // 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);
-  while ($old_tag_node = db_fetch_object($result)) {
-    $old_tags_by_uid[$old_tag_node->uid][$old_tag_node->tid] = $old_tag_node;
-  }
-
-  $tag_nodes = array();
-  $inserted_tids = array();
-
-  $tids = array();
-  // 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) {
-      $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
-        // and return the tid, otherwise, add a new record.
-        $possibilities = taxonomy_get_term_by_name($typed_term);
-        $typed_term_tid = NULL; // tid match if any.
-        foreach ($possibilities as $possibility) {
-          if ($possibility->vid == $vid) {
-            $typed_term_tid = $possibility->tid;
+    $tids = array();
+    // 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) {
+        $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
+          // and return the tid, otherwise, add a new record.
+          $possibilities = taxonomy_get_term_by_name($typed_term);
+          $typed_term_tid = NULL; // tid match if any.
+          foreach ($possibilities as $possibility) {
+            if ($possibility->vid == $vid) {
+              $typed_term_tid = $possibility->tid;
+            }
           }
-        }
 
-        if (!$typed_term_tid) {
-          $edit = array('vid' => $vid, 'name' => $typed_term);
-          $status = taxonomy_save_term($edit);
-          $typed_term_tid = $edit['tid'];
+          if (!$typed_term_tid) {
+            $edit = array('vid' => $vid, 'name' => $typed_term);
+            $status = taxonomy_save_term($edit);
+            $typed_term_tid = $edit['tid'];
+  
+            // Add only new terms to return value
+            $tids[$typed_term_tid] = $typed_term;
+          }
 
-          // Add only new terms to return value
-          $tids[$typed_term_tid] = $typed_term;
-        }
+          // If we already added this term in this cycle, skip this duplicate.
+          if (isset($inserted_tids[$typed_term_tid])) {
+            continue;
+          }
 
-        // If we already added this term in this cycle, skip this duplicate.
-        if (isset($inserted_tids[$typed_term_tid])) {
-          continue;
+          // If there was an existing tag by this user, load that data.
+          $tag_node = new StdClass();
+          $tag_node->tid = $typed_term_tid;
+          $tag_node->nid = $nid;
+          $tag_node->uid = $uid;
+          $tag_node->date = time();
+
+          // So we don't add this tag again on this run or re-insert the old tag for this user.
+          $inserted_tids[$typed_term_tid] = $typed_term_tid;
+          $tag_nodes[] = $tag_node;
         }
+      }
+    }
 
-        // If there was an existing tag by this user, load that data.
-        $tag_node = new StdClass();
-        $tag_node->tid = $typed_term_tid;
-        $tag_node->nid = $nid;
-        $tag_node->uid = $uid;
-        $tag_node->date = time();
-
-        // So we don't add this tag again on this run or re-insert the old tag for this user.
-        $inserted_tids[$typed_term_tid] = $typed_term_tid;
-        $tag_nodes[] = $tag_node;
+    // Re-insert the existing tags we haven't already added back in (incl. other users' tags).
+    foreach ($old_tags_by_uid as $old_uid => $old_tags) {
+      foreach ($old_tags as $old_tag) {
+        // If we're editing as the owner, only re-insert this other user's old tag
+        // when I've kept this tag in the node edit form.
+        if ($is_owner && isset($inserted_tids[$old_tag->tid]) && $old_tag->uid != $uid) {
+          $tag_nodes[] = $old_tag;
+        }
+        elseif (!$is_owner && $old_tag->uid != $uid) {
+          $tag_nodes[] = $old_tag;
+        }
       }
     }
-  }
 
-  // Re-insert the existing tags we haven't already added back in (incl. other users' tags).
-  foreach ($old_tags_by_uid as $old_uid => $old_tags) {
-    foreach ($old_tags as $old_tag) {
-      // If we're editing as the owner, only re-insert this other user's old tag
-      // when I've kept this tag in the node edit form.
-      if ($is_owner && isset($inserted_tids[$old_tag->tid]) && $old_tag->uid != $uid) {
-        $tag_nodes[] = $old_tag;
+    // Get existing term-node associations to see if we need to re-insert a term-node
+    // relation for each old tag we're putting back in since we're acting after
+    // taxonomy.module has done its business.
+    $result = db_query('SELECT tid FROM {term_node} WHERE nid = %d', $nid);
+    $existing_term_nodes = array();
+    $add_term_nodes = array();
+    while ($term_node = db_fetch_object($result)) {
+      $existing_term_nodes[$term_node->tid] = TRUE;
+    }
+
+    // Re-insert tag-node-user associations and term-node if not existing.
+    db_lock_table('{community_tags}');
+    db_query('DELETE FROM {community_tags} WHERE nid = %d', $nid);
+    foreach ($tag_nodes as $tag_node) {
+      db_query('INSERT INTO {community_tags} (tid, nid, uid, date) VALUES (%d, %d, %d, %d)', $tag_node->tid, $tag_node->nid, $tag_node->uid, $tag_node->date);
+
+      // Remember to insert term-node relation into term_node table if it doesn't exist already.
+      if (!isset($existing_term_nodes[$tag_node->tid])) {
+        $add_term_nodes[] = $tag_node;
+        $existing_term_nodes[$tag_node->tid] = TRUE;
       }
-      elseif (!$is_owner && $old_tag->uid != $uid) {
-        $tag_nodes[] = $old_tag;
+    }
+    db_unlock_tables();
+
+    // Avoid locking term_node so we loop again.
+    foreach ($add_term_nodes as $tag_node) {
+      // Insert term-node relation into term_node table since it doesn't exist already.
+      db_query('INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)', $tag_node->nid, $tag_node->tid);
+    }
+
+    // Match real tags to community tags, if necessary (e.g. after quick tagging).
+    if (!$is_owner) {
+      $result = db_query('SELECT n.tid, n.nid FROM {term_node} n LEFT JOIN {community_tags} c ON n.tid = c.tid AND n.nid = c.nid WHERE n.nid = %d AND c.nid IS NULL', $nid);
+      while ($tag = db_fetch_object($result)) {
+        db_query('DELETE FROM {term_node} WHERE nid = %d AND tid = %d', $tag->nid, $tag->tid);
       }
     }
+    unset($taxonomy['tags']);
   }
 
-  // Get existing term-node associations to see if we need to re-insert a term-node
-  // relation for each old tag we're putting back in since we're acting after
-  // taxonomy.module has done its business.
-  $result = db_query('SELECT tid FROM {term_node} WHERE nid = %d', $nid);
-  $existing_term_nodes = array();
-  $add_term_nodes = array();
-  while ($term_node = db_fetch_object($result)) {
-    $existing_term_nodes[$term_node->tid] = TRUE;
-  }
-
-  // Re-insert tag-node-user associations and term-node if not existing.
-  db_lock_table('{community_tags}');
-  db_query('DELETE FROM {community_tags} WHERE nid = %d', $nid);
-  foreach ($tag_nodes as $tag_node) {
-    db_query('INSERT INTO {community_tags} (tid, nid, uid, date) VALUES (%d, %d, %d, %d)', $tag_node->tid, $tag_node->nid, $tag_node->uid, $tag_node->date);
-
-    // Remember to insert term-node relation into term_node table if it doesn't exist already.
-    if (!isset($existing_term_nodes[$tag_node->tid])) {
-      $add_term_nodes[] = $tag_node;
-      $existing_term_nodes[$tag_node->tid] = TRUE;
-    }
-  }
-  db_unlock_tables();
-
-  // Avoid locking term_node so we loop again.
-  foreach ($add_term_nodes as $tag_node) {
-    // Insert term-node relation into term_node table since it doesn't exist already.
-    db_query('INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)', $tag_node->nid, $tag_node->tid);
-  }
-
-  // Match real tags to community tags, if necessary (e.g. after quick tagging).
-  if (!$is_owner) {
-    $result = db_query('SELECT n.tid, n.nid FROM {term_node} n LEFT JOIN {community_tags} c ON n.tid = c.tid AND n.nid = c.nid WHERE n.nid = %d AND c.nid IS NULL', $nid);
-    while ($tag = db_fetch_object($result)) {
-      db_query('DELETE FROM {term_node} WHERE nid = %d AND tid = %d', $tag->nid, $tag->tid);
+  // Process an array of tids for a regular taxonomy, if present.
+  if (is_array($taxonomy)) {
+    // Delete terms by this user.
+    db_query('DELETE FROM {community_tags} WHERE nid = %d AND uid = %d', $nid, $uid);
+    foreach ($taxonomy as $tid) {
+      db_query('INSERT INTO {community_tags} (tid, nid, uid, date) VALUES (%d, %d, %d, %d)', $tid, $nid, $uid, time());
     }
+    $tids = $taxonomy;
   }
-
   return $tids;
 }
 
