Index: content_taxonomy.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/content_taxonomy/content_taxonomy.module,v
retrieving revision 1.2
diff -u -F^f -r1.2 content_taxonomy.module
--- content_taxonomy.module	16 Feb 2007 09:10:34 -0000	1.2
+++ content_taxonomy.module	6 Nov 2007 20:04:31 -0000
@@ -335,4 +335,51 @@ function content_taxonomy_save(&$node, $
 }
 
 
-?>
\ No newline at end of file
+/**
+ * Implementation of hook_token_list().
+ */
+function content_taxonomy_token_list($type = 'all') {
+  if ($type == 'field' || $type == 'all') {
+    $tokens = array();
+
+    $tokens['content_taxonomy']['term']  = t('Name of top taxonomy term');
+    $tokens['content_taxonomy']['tid']   = t('ID of top taxonomy term');
+    $tokens['content_taxonomy']['vocab'] = t('Name of top terms vocabulary');
+    $tokens['content_taxonomy']['vid']   = t('ID of top terms vocabulary');
+
+    return $tokens;
+  }
+}
+
+/**
+ * Implementation of hook_token_values().
+ */
+function content_taxonomy_token_values($type, $object = NULL) {
+  if ($type == 'field') {
+    // This ugly check is necessary because of some weird things going on
+    // inside the content_taxonomy module: the structure of "content taxonomy
+    // field objects" can vary greatly, depending on the moment. This implies
+    // that the Token module also gets different kinds of objects, which again
+    // implies that we have to take care of that here as well.
+    // Or maybe it's just CCK's fault.
+    if (isset($object['tids'])) {
+      // This one is necessary for submitting content.
+      $tid = reset($object['tids']);
+    }
+    else {
+      // This one is necessary for viewing content.
+      $term = reset($object[0]);
+      $tid = $term->tid;
+    }
+
+    $term = taxonomy_get_term($tid);
+    $vocabulary = taxonomy_get_vocabulary($term->vid);
+
+    $tokens['term']  = $term->name;
+    $tokens['tid']   = $tid;
+    $tokens['vocab'] = $vocabulary->name;
+    $tokens['vid']   = $term->vid;
+
+    return $tokens;
+  }
+}
