Index: community_tags.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/community_tags/community_tags.module,v
retrieving revision 1.36
diff -u -r1.36 community_tags.module
--- community_tags.module	1 Aug 2007 22:37:14 -0000	1.36
+++ community_tags.module	17 Jul 2008 05:31:28 -0000
@@ -19,54 +19,59 @@
   }
 }
 
+/**
+ * Implementation of hook_theme().
+ */
+function community_tags_theme() {
+  return array(
+    'community_tags_form' => array(
+      'arguments' => array('form' => NULL),
+      'file' => 'community_tags.pages.inc',
+    ),
+    'community_tags' => array(
+      'arguments' => array('tags' => NULL),
+    ),    
+  );
+}
 
 /**
  * Implementation of hook_menu().
  */
-function community_tags_menu($may_cache) {
+function community_tags_menu() {
   $items = array();
 
-  if ($may_cache) {
-    $items[] = array(
-      'path' => 'admin/settings/community-tags',
-      'title' => t('Community tags'),
-      'description' => t('Configure community tagging.'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => 'community_tags_settings',
-      'access' => user_access('administer site configuration'),
-    );
-    $items[] = array(
-      'path' => 'community-tags/js',
-      'callback' => 'community_tags_from_js',
-      'access' => user_access('access content') && user_access('tag content'),
-      'type' => MENU_CALLBACK,
-    );
-    $items[] = array(
-      'path' => 'community-tags/user',
-      'callback' => 'community_tags_by_user',
-      'access' => user_access('access content') && user_access('tag content'),
-      'type' => MENU_CALLBACK,
-    );
-  }
-  else {
-    // Add tagging tab, if necessary and supported for this node.
-    if (arg(0) == 'node' && is_numeric(arg(1))) {
-      $node = node_load(arg(1));
-      if ($node) {
-        $tab = variable_get('community_tags_display_'. $node->type, COMMUNITY_TAGS_MODE_TAB) == COMMUNITY_TAGS_MODE_TAB;
-        $vids = community_tags_vids_for_node($node);
-        $items[] = array(
-          'path' => 'node/'. arg(1) .'/tag',
-          'title' => t('Tags'),
-          'callback' => 'community_tags_node_view',
-          'callback arguments' => array(arg(1), FALSE),
-          'access' => (user_access('access content') && user_access('tag content') && count($vids)),
-          'type' => $tab ? MENU_LOCAL_TASK : MENU_CALLBACK,
-          'weight' => 2,
-        );
-      }
-    }
-  }
+  $items['admin/settings/community-tags'] = array(
+    'title' => 'Community tags',
+    'description' => t('Configure community tagging.'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('community_tags_settings'),
+    'access arguments' => array('administer site configuration'),
+    'file' => 'community_tags.pages.inc',
+  );
+
+  $items['community-tags/js'] = array(
+    'page callback' => 'community_tags_from_js',
+    'access callback' => '_community_tags_menu_access',
+    'type' => MENU_CALLBACK,
+    'file' => 'community_tags.pages.inc',  
+  );
+  
+  $items['community-tags/user'] = array(
+    'page callback' => 'community_tags_by_user',
+    'access callback' => '_community_tags_menu_access',
+    'type' => MENU_CALLBACK,
+  );
+
+  $items['node/%node/tag'] = array(
+    'title' => 'Tags',
+    'page callback' => 'community_tags_node_view',
+    'page arguments' => array(1, FALSE),
+    'access callback' => '_community_tags_tag_access',
+    'access arguments' => array(1),
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 2,
+    'file' => 'community_tags.pages.inc',
+  );
 
   return $items;
 }
@@ -161,46 +166,6 @@
 }
 
 /**
- * Community tags callback for node view.
- */
-function community_tags_node_view($node, $inline = TRUE) {
-  global $user;
-  if (is_numeric($node)) {
-    $node = node_load($node);
-  }
-
-  if (!$inline) {
-    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();
-
-  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>';
-  }
-
-  drupal_add_js(array('communityTags' => array('tags' => $names, 'url' => url('community-tags/js/'. $node->nid), 'add' => t('Add'))), 'setting');
-
-  return $output;
-}
-
-/**
  * Implementation of hook_perm().
  */
 function community_tags_perm() {
@@ -225,7 +190,7 @@
       // be one.  Only when using a "quick add" form can we increase the count.
       if (is_array($node->taxonomy['tags'])) {
         global $user;
-        community_tags_taxonomy_node_save($node->nid, $node->taxonomy, TRUE, $user->uid);
+        community_tags_taxonomy_node_save($node, $node->taxonomy, TRUE, $user->uid);
       }
       break;
 
@@ -244,38 +209,9 @@
 }
 
 /**
- * Implementation of hook_settings().
- */
-function community_tags_settings() {
-  $form = array();
-
-  community_tags_rehash();
-
-  // 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');
-  while ($vocabulary = db_fetch_object($vocabs)) {
-    $options[$vocabulary->vid] = $vocabulary->name;
-  }
-  if ($options) {
-    $form['community_tags_vocabularies'] = array(
-      '#type' => 'select',
-      '#multiple' => TRUE,
-      '#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.'),
-    );
-  }
-
-  $form = system_settings_form($form);
-
-  return $form;
-}
-
-/**
  * Implementation of hook_form_alter().
  */
-function community_tags_form_alter($form_id, &$form) {
+function community_tags_form_alter(&$form, &$form_state, $form_id) {
   // Provide option to enable Community Tags per node type.
   if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
     $modes = array(
@@ -307,137 +243,14 @@
 }
 
 /**
- * Quick tag form
- */
-function community_tags_form($edit, $title = NULL) {
-  $form['cloud'] = array(
-    '#type' => 'markup',
-    '#title' => t('All tags'),
-    '#value' => $edit['cloud'],
-  );
-  
-  $access = user_access('tag content');
-
-  $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'),
-    '#access' => $access,
-  );
-  if ($edit['inline']) {
-    $form['tags']['#size'] = 20;
-  }
-  
-  if (!$access) {
-    $destination = drupal_get_destination();
-    $form['login'] = array(
-      '#type' => 'markup',
-      '#value' => '<div>'. t('<a href="@login">Login</a> or <a href="@register">register</a> to tag items', array('@login' => url('user/login', $destination), '@register' => url('user/register', $destination))) .'</div>',
-    );
-  }
-
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Save'),
-  );
-
-  $form['nid'] = array(
-    '#type' => 'value',
-    '#value' => $edit['nid'],
-  );
-
-  $form['vid'] = array(
-    '#type' => 'value',
-    '#value' => $edit['vid'],
-  );
-
-  return $form;
-}
-
-/**
- * Validate the quick tag form.
- */
-function community_tags_form_validate($form_id, $form_values) {
-  if ($form_values['tags'] == '') {
-    form_set_error('tags', t('You must enter at least one tag.'));
-  }
-}
-
-/**
- * Submit callback for quick tag form.
- */
-function community_tags_form_submit($form_id, $form_values) {
-  global $user;
-  
-  community_tags_taxonomy_node_save($form_values['nid'], array('tags' => array($form_values['vid'] => $form_values['tags'])), FALSE, $user->uid);
-
-  return array('node/'. $form_values['nid']);
-}
-
-/**
- * Theme the quick tag form.
- * @ingroup themeable
- */
-function theme_community_tags_form($form) {
-  $output .= theme('form_element', array('#title' => t('All tags')), drupal_render($form['cloud']));
-
-  $output .= drupal_render($form);
-
-  // We add the JS file this late, to ensure it comes after autocomplete.js.
-  drupal_add_css(drupal_get_path('module', 'community_tags') .'/community_tags.css', 'module');
-  drupal_add_js(drupal_get_path('module', 'community_tags') .'/community_tags.js');
-
-  return $output;
-}
-
-/**
- * Helper function for the JS tagger.
- */
-function community_tags_flatten($tags) {
-  $names = array();
-  foreach ($tags as $tag) {
-    $names[] = $tag->name;
-  }
-  return $names;
-}
-
-/**
- * Callback for the JS tagger.
- */
-function community_tags_from_js($nid) {
-  global $user;
-  if (!is_numeric($nid) || !($node = node_load($nid))) {
-    return;
-  }
-
-  $tags = is_array($_POST['tags']) ? $_POST['tags'] : array();
-
-  // 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));
-
-  // Output JSON
-  drupal_set_header('Content-Type: text/javascript; charset=utf-8');
-  print drupal_to_js(array('status' => TRUE, 'tags' => $tags, 'sequence' => $_POST['sequence']));
-}
-
-/**
  * 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($node, $terms, $is_owner, $uid) {
   $community_tagged = variable_get('community_tags_vocabularies', array());
   if (count($community_tagged) == 0) {
     return;
   }
+  $nid = $node->nid;
 
   // 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.
@@ -492,6 +305,7 @@
         $tag_node->nid = $nid;
         $tag_node->uid = $uid;
         $tag_node->date = time();
+        $tag_node->vid = $node->vid;
 
         // 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;
@@ -541,7 +355,7 @@
   // 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);
+    db_query('INSERT INTO {term_node} (nid, tid, vid) VALUES (%d, %d, %d)', $tag_node->nid, $tag_node->tid, $tag_node->vid);
   }
 
   // Match real tags to community tags, if necessary (e.g. after quick tagging).
@@ -555,16 +369,6 @@
 
 }
 
-
-/**
- * Menu callback: 
- */
-function community_tags_mypage($uid = NULL) {
-  $uid = isset($uid) ? $uid : $GLOBALS['uid'];
-
-  _community_tags_get_tag_result('user', 100, $uid);
-}
-
 /**
  * Helper function for retrieving a query result to pass along to the Tagadelic
  * functions prior to theming.
@@ -670,24 +474,17 @@
 
     return $tags;
   }
+}
 
-  /**
-   * Implode a list of tags of a certain vocabulary into a string.
-   */
-  function taxonomy_implode_tags($tags, $vid = NULL) {
-    $typed_tags = array();
-    foreach ($tags as $tag) {
-      // Extract terms belonging to the vocabulary in question.
-      if (is_null($vid) || $tag->vid == $vid) {
-
-        // Commas and quotes in tag names are special cases, so encode 'em.
-        if (strpos($tag->name, ',') !== FALSE || strpos($tag->name, '"') !== FALSE) {
-          $tag->name = '"'. str_replace('"', '""', $tag->name) .'"';
-        }
+/**
+ * Menu access callbacks
+ */
+function _community_tags_menu_access() {
+  return user_access('access content') && user_access('tag content');
+}
 
-        $typed_tags[] = $tag->name;
-      }
-    }
-    return implode(', ', $typed_tags);
-  }
+function _community_tags_tag_access($node) {
+  $vids = community_tags_vids_for_node($node);
+  return _community_tags_menu_access() && count($vids);
 }
+
Index: community_tags.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/community_tags/community_tags.install,v
retrieving revision 1.8
diff -u -r1.8 community_tags.install
--- community_tags.install	3 May 2007 09:13:28 -0000	1.8
+++ community_tags.install	17 Jul 2008 05:31:26 -0000
@@ -2,78 +2,58 @@
 // $Id: community_tags.install,v 1.8 2007/05/03 09:13:28 unconed Exp $
 
 /**
+ * @file
+ * The install file for the community_tags module.
+ */
+
+/**
  * Implementation of hook_install().
  */
 function community_tags_install() {
-  $status = array();
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      $status[] = db_query("CREATE TABLE {community_tags} (
-        tid int(10) unsigned NOT NULL DEFAULT '0',
-        nid int(10) unsigned NOT NULL DEFAULT '0',
-        uid int(10) unsigned NOT NULL DEFAULT '0',
-        date int(10) unsigned NOT NULL DEFAULT '0',
-        PRIMARY KEY  (tid,nid,uid),
-        KEY tid (tid),
-        KEY nid (nid),
-        KEY uid (uid)
-      ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
-      break;
-
-    case 'pgsql':
-      $status[] = db_query("CREATE TABLE {community_tags} (
-        tid integer NOT NULL DEFAULT '0',
-        nid integer NOT NULL DEFAULT '0',
-        uid integer NOT NULL DEFAULT '0',
-        date integer NOT NULL DEFAULT '0',
-        PRIMARY KEY (tid,nid,uid)
-      );");
-      $status[] = db_query("CREATE INDEX {community_tags}_tid_idx ON {community_tags} (tid);");
-      $status[] = db_query("CREATE INDEX {community_tags}_nid_idx ON {community_tags} (nid);");
-      $status[] = db_query("CREATE INDEX {community_tags}_uid_idx ON {community_tags} (uid);");
-      break;
-  }
-
+  // Install schema
+  drupal_install_schema('community_tags');
+  
   // Drop module weight so we act after taxonomy.
   $weight = (int)db_result(db_query("SELECT weight FROM {system} WHERE name = 'taxonomy'"));
   db_query("UPDATE {system} SET weight = %d WHERE name = 'community_tags'", $weight + 1);
-
-  // If there is one FALSE value in the status array, there was an error.
-  if (array_search(FALSE, $status) !== FALSE) {
-    drupal_set_message(t('Table installation for the Community Tags module was unsuccessful. The tables may need to be installed by hand.'), 'error');
-  }
-  else {
-    drupal_set_message(t('Community Tags module installed successfully.'));
-  }
 }
 
 /**
  * Implementation of hook_uninstall().
  */
 function community_tags_uninstall() {
-  db_query('DROP TABLE {community_tags}');
+  drupal_uninstall_schema('community_tags');
+}
+
+/**
+ * Implementation of hook_schema().
+ */
+function community_tags_schema() {
+  $schema['community_tags'] = array(
+    'fields' => array(
+      'tid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+      'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+      'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+      'date' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+    ),
+    'indexes' => array(
+      'tid' => array('tid'),
+      'nid' => array('nid'),
+      'uid' => array('uid'),
+    ),
+    'primary key' => array('tid', 'uid', 'nid'),
+  );
+  return $schema;
 }
 
 /**
  * Update: Add tid column key.
  */
 function community_tags_update_1() {
-  $items = array();
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      $items[] = update_sql('ALTER TABLE {community_tags} ADD KEY tid (tid)');
-      break;
-
-    case 'pgsql':
-      $items[] = update_sql("CREATE INDEX {community_tags}_tid_idx ON {community_tags} (tid);");
-      break;
-  }
-
+  $ret = array();
+  db_add_index($ret, 'community_tags', 'tid', array('tid'));
   community_tags_rehash(TRUE);
-
-  return $items;
+  return $ret;
 }
 
 /**
Index: community_tags.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/community_tags/community_tags.info,v
retrieving revision 1.1
diff -u -r1.1 community_tags.info
--- community_tags.info	11 Apr 2007 12:31:32 -0000	1.1
+++ community_tags.info	17 Jul 2008 05:31:26 -0000
@@ -1,4 +1,5 @@
 ; $Id: community_tags.info,v 1.1 2007/04/11 12:31:32 unconed Exp $
 name = Community Tags
 description = "Allows users to 'tag' other users' content. Weighted tag lists or 'tag clouds' are generated for each piece of content to show the popularity of tags."
-dependencies = tagadelic
+dependencies[] = tagadelic
+core=6.x
\ No newline at end of file
Index: community_tags.pages.inc
===================================================================
RCS file: community_tags.pages.inc
diff -N community_tags.pages.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ community_tags.pages.inc	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,243 @@
+<?php
+// $Id$
+
+/**
+ * Community tags callback for node view.
+ */
+function community_tags_node_view($node, $inline = TRUE) {
+  global $user;
+  if (is_numeric($node)) {
+    $node = node_load($node);
+  }
+
+  if (!$inline) {
+    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();
+  $output = '';
+
+  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: ') . 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;
+}
+
+/**
+ * Quick tag form
+ */
+function community_tags_form($form_state, $edit, $title = NULL) {
+  $form['cloud'] = array(
+    '#type' => 'markup',
+    '#title' => t('All tags'),
+    '#value' => $edit['cloud'],
+  );
+  
+  $access = user_access('tag content');
+
+  $form['tags'] = array(
+    '#type' => 'textfield',
+    '#title' => t('My tags'),
+    '#maxlength' => 100,
+    '#default_value' => $edit['tags'],
+    '#required' => FALSE,
+    '#autocomplete_path' => 'taxonomy/autocomplete/'. $edit['vid'],
+    '#attributes' => array('class' => 'form-tags'),
+    '#access' => $access,
+  );
+  if ($edit['inline']) {
+    $form['tags']['#size'] = 20;
+  }
+  
+  if (!$access) {
+    $destination = drupal_get_destination();
+    $form['login'] = array(
+      '#type' => 'markup',
+      '#value' => '<div>'. t('<a href="@login">Login</a> or <a href="@register">register</a> to tag items', array('@login' => url('user/login', $destination), '@register' => url('user/register', $destination))) .'</div>',
+    );
+  }
+
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save'),
+    '#access' => $access,
+  );
+  
+  $form['node'] = array(
+    '#type' => 'value',
+    '#value' => $edit['node'],
+  );
+  
+  $form['nid'] = array(
+    '#type' => 'value',
+    '#value' => $edit['nid'],
+  );
+
+  $form['vid'] = array(
+    '#type' => 'value',
+    '#value' => $edit['vid'],
+  );
+
+  return $form;
+}
+
+/**
+ * Validate the quick tag form.
+ */
+function community_tags_form_validate($form, &$form_state) {
+  if ($form_state['values']['tags'] == '') {
+    form_set_error('tags', t('You must enter at least one tag.'));
+  }
+}
+
+/**
+ * Submit callback for quick tag form.
+ */
+function community_tags_form_submit($form, &$form_state) {
+  global $user;
+  $form_values = $form_state['values']; 
+  community_tags_taxonomy_node_save($form_values['node'], array('tags' => array($form_values['vid'] => $form_values['tags'])), FALSE, $user->uid);
+
+  $form_state['redirect'] = 'node/'. $form_values['nid']; 
+}
+
+/**
+ * Theme the quick tag form.
+ * @ingroup themeable
+ */
+function theme_community_tags_form($form) {
+  $output = theme('form_element', array('#title' => t('All tags')), drupal_render($form['cloud']));
+
+  $output .= drupal_render($form);
+
+  // We add the JS file this late, to ensure it comes after autocomplete.js.
+  drupal_add_css(drupal_get_path('module', 'community_tags') .'/community_tags.css', 'module');
+  drupal_add_js(drupal_get_path('module', 'community_tags') .'/community_tags.js');
+
+  return $output;
+}
+
+/**
+ * Helper function for the JS tagger.
+ */
+function community_tags_flatten($tags) {
+  $names = array();
+  foreach ($tags as $tag) {
+    $names[] = $tag->name;
+  }
+  return $names;
+}
+
+/**
+ * Callback for the JS tagger.
+ */
+function community_tags_from_js($nid) {
+  global $user;
+  if (!is_numeric($nid) || !($node = node_load($nid))) {
+    return;
+  }
+
+  $tags = (isset($_POST['tags']) && is_array($_POST['tags'])) ? $_POST['tags'] : array();
+
+  // 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, 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));
+
+  // Output JSON
+  drupal_set_header('Content-Type: text/javascript; charset=utf-8');
+  print drupal_to_js(array('status' => TRUE, 'tags' => $tags, 'sequence' => $_POST['sequence']));
+}
+
+
+
+/**
+ * Menu callback: 
+ */
+function community_tags_mypage($uid = NULL) {
+  $uid = isset($uid) ? $uid : $GLOBALS['uid'];
+
+  _community_tags_get_tag_result('user', 100, $uid);
+}
+
+/**
+ * Form builder; Builds the settings form.
+ *
+ * @ingroup forms
+ */
+function community_tags_settings() {
+  $form = array();
+
+  community_tags_rehash();
+
+  // 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');
+  while ($vocabulary = db_fetch_object($vocabs)) {
+    $options[$vocabulary->vid] = $vocabulary->name;
+  }
+  if ($options) {
+    $form['community_tags_vocabularies'] = array(
+      '#type' => 'select',
+      '#multiple' => TRUE,
+      '#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.'),
+    );
+  }
+
+  $form = system_settings_form($form);
+
+  return $form;
+}
+
+// Patch for Drupal 5.x. Remove for 6.x.
+if (!function_exists('taxonomy_explode_tags')) {
+
+  /**
+   * Explode a string of given tags into an array.
+   */
+  function taxonomy_explode_tags($tags) {
+    // This regexp allows the following types of user input:
+    // this, "somecompany, llc", "and ""this"" w,o.rks", foo bar
+    $regexp = '%(?:^|,\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x';
+    preg_match_all($regexp, $tags, $matches);
+    $typed_tags = array_unique($matches[1]);
+
+    $tags = array();
+    foreach ($typed_tags as $tag) {
+      // If a user has escaped a term (to demonstrate that it is a group,
+      // or includes a comma or quote character), we remove the escape
+      // formatting so to save the term into the database as the user intends.
+      $tag = trim(str_replace('""', '"', preg_replace('/^"(.*)"$/', '\1', $tag)));
+      if ($tag != "") {
+        $tags[] = $tag;
+      }
+    }
+
+    return $tags;
+  }
+}
