? token_filter_node_tokens.patch
Index: token_filter.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/token_filter/token_filter.module,v
retrieving revision 1.1.4.5
diff -u -p -r1.1.4.5 token_filter.module
--- token_filter.module	13 Jun 2009 19:08:00 -0000	1.1.4.5
+++ token_filter.module	22 Jan 2010 23:23:14 -0000
@@ -52,9 +52,11 @@ function token_filter_replacetoken($matc
       $object = $user;
       break;
     case 'global':
-    default:
       $object = NULL;
       break;
+    default:
+      $object = _token_filter_cached_object($type);
+      break;
   } 
   
   // add [ ] to the token so str_replace correctly replaces token values
@@ -64,3 +66,67 @@ function token_filter_replacetoken($matc
   $output = token_replace($token, $type, $object, '[', ']');  
   return $output;
 }
+
+/**
+ * Store or retrieve a Drupal object used for tokens, e.g., a node.
+ */
+function _token_filter_cached_object($object_type = NULL, $object = NULL, $reset = FALSE) {
+  static $cached_object = array();
+  if ($reset) {
+    if ($type) {
+      unset($cached_object[$object_type]);
+    }
+    else {
+      $cached_object = array();
+    }
+  }
+  elseif ($object_type && $object) {
+    $cached_object[$object_type] = $object;
+  }
+  else {
+    return isset($cached_object[$object_type]) ? $cached_object[$object_type] : NULL;
+  }
+}
+
+/**
+ * Implementation of hook_nodeapi().
+ */
+function token_filter_nodeapi(&$node, $op, $teaser, $page) {
+  switch ($op) {
+    case 'view':
+      _token_filter_node($node);
+      break;
+  }
+}
+
+/**
+ * Iterate through the fields of a node and send for filtering.
+ */
+function _token_filter_node(&$node) {
+  // Set the node as the cached object.
+  _token_filter_cached_object('node', $node);
+
+  if (module_exists('content')) {
+    $fields = content_fields(NULL, $node->type);
+    foreach ($fields as $field) {
+      // Determine if the field is of type text and if it has a format set.
+      // ....
+
+        // Get a complete list of filters for this format.
+        $filters = filter_list_format($format);
+
+        // Give filters the chance to escape HTML-like data such as code or formulas.
+        foreach ($filters as $filter) {
+          if ($filter->module == 'token_filter') {
+            // Send field for processing.
+            // ....
+
+          }
+        }
+    }
+  }
+
+  // Clear the cached node.
+  _token_filter_cached_object('node', NULL, TRUE);
+  
+}
