--- token_filter.module	2010-10-22 14:23:50.000000000 -0400
+++ token_filterNew.module	2010-10-22 14:17:13.000000000 -0400
@@ -31,7 +31,7 @@ function token_filter_filter($op, $delta
         return $text;
       }
       else {        
-        $output = preg_replace_callback("|\[token ([^ ]*) ([^]]*)\]|i", 'token_filter_replacetoken', $text);
+        $output = preg_replace_callback(":\[token (global|user) ([^]]+)\]:i", 'token_filter_replacetoken', $text);
         return $output;
       }
       break;
@@ -41,10 +41,44 @@ function token_filter_filter($op, $delta
 }
 
 /**
+ * Implementation of hook_filter_tips()
+ */
+function token_filter_filter_tips($delta, $format, $long = FALSE) {
+  return t('You substitute tokens by enclosing the word token, the token type and the token name in brackets. For example, [token global site-name] will substitute the site name in the text, and [token user user-name] will substitute the logged in user\'s name. Only global and user tokens are supported. See below for available tokens. If you are using the <a href="!url">Tokenize Request Parameters</a> module, the token syntax is [token global get-param-xxx] or [token global post-param-xxx], where xxx is the name of an allowed URL request variable.', array('!url' => url('http://drupal.org/project/token_request_params'), )) . theme('token_filter_tips');
+}
+
+/**
+ * Implementation of hook_theme().
+ */
+function token_filter_theme() {
+  return array(
+    'token_filter_tips' => array(
+      'arguments' => array(),
+    ),
+  );
+}
+
+/**
+ * Theme function for a token_filter tips help.
+ */
+function theme_token_filter_tips() {
+  $fieldset = array(
+    '#type' => 'fieldset',
+    '#title' => t('Available tokens'),
+    '#value' => theme('token_help', array('global', 'user')),
+    '#attributes' => array('class' => 'token_filter_tip_tokens'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+  return theme('fieldset', $fieldset);
+}
+
+/**
  * Helper function for preg_replace_callback to generate the html for each token filter
  */
-function token_filter_replacetoken($matches) {  
+function token_filter_replacetoken($matches) {
   global $user;
+  $expression = $matches[0];
   $type  = $matches[1];
   $token = $matches[2];
   switch ($type) {
@@ -52,14 +86,16 @@ function token_filter_replacetoken($matc
       $object = $user;
       break;
     case 'global':
-    default:
       $object = NULL;
       break;
-  } 
+    default:
+      // If we don't know the type, return the expression unchanged
+      return $expression;
+  }
   
   // add [ ] to the token so str_replace correctly replaces token values
   // if not, a token like 'custom_text' won't be properly replaced if another token like 'custom' exists  
-  $token = '['.$token.']';
+  $token = '[' . $token . ']';
     
   $output = token_replace($token, $type, $object, '[', ']');  
   return $output;
