diff -u -b -r taxonomy_redirect.orig/taxonomy_redirect.install taxonomy_redirect/taxonomy_redirect.install
--- taxonomy_redirect.orig/taxonomy_redirect.install	2007-11-19 06:50:39.000000000 +0000
+++ taxonomy_redirect/taxonomy_redirect.install	2008-04-30 12:46:08.000000000 +0100
@@ -24,3 +24,8 @@
 function taxonomy_redirect_update_2() {
   db_query("UPDATE {taxonomy_redirect} SET path = concat(path, '/!tid') WHERE path NOT LIKE '%/!tid'");
 }
+function taxonomy_redirect_update_3() {
+  db_query("ALTER TABLE `taxonomy_redirect` CHANGE `path` `path` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL");
+  db_query("ALTER TABLE `taxonomy_redirect` ADD `filter` INT( 4 ) NULL");
+}
+ 
\ No newline at end of file
diff -u -b -r taxonomy_redirect.orig/taxonomy_redirect.module taxonomy_redirect/taxonomy_redirect.module
--- taxonomy_redirect.orig/taxonomy_redirect.module	2007-11-19 06:50:39.000000000 +0000
+++ taxonomy_redirect/taxonomy_redirect.module	2008-04-30 12:46:07.000000000 +0100
@@ -2,24 +2,31 @@
 // $Id: taxonomy_redirect.module,v 1.7 2007/11/19 06:50:39 agileware Exp $
 
 function taxonomy_redirect_term_path($term) {
-  $path = db_result(db_query("SELECT path FROM {taxonomy_redirect} WHERE vid='%d'", $term->vid));
-  if (is_null($path))
+  static $_path;
+  if( $_path[$term->vid] ) {
+    return t($_path[$term->vid],array('!tid' => $term->tid, '!name' => $term->name));
+  }
+  $redirect = db_fetch_object(db_query("SELECT path,filter FROM {taxonomy_redirect} WHERE vid='%d'", $term->vid));
+
+  if (is_null($redirect) || is_null($redirect->path)) {
+    $_path[$term->vid] = 'taxonomy/term/' . $term->tid;
     return 'taxonomy/term/' . $term->tid;
+  }
 
-  if (function_exists('taxonomy_redirect_custom_term_path'))
+  if (function_exists('taxonomy_redirect_custom_term_path')) {
     return taxonomy_redirect_custom_term_path($term, $path);
+  }
+  $_path[$term->vid] = trim(_taxonomy_redirect_exec_filter($redirect->path,
+    $redirect->filter));
+//   drupal_set_message($_path[$term->vid]);
+  return t($_path[$term->vid],array('!tid' => $term->tid, '!name' => $term->name));
 
-  return taxonomy_redirect_default_term_path($term, $path);
-}
-
-function taxonomy_redirect_default_term_path($term, $path) {
-  return t($path, array('!tid' => $term->tid, '!name' => $term->name));
 }
 
 function taxonomy_redirect_help($section) { 
   switch ($section) {
     case 'admin/build/taxonomy_redirect':
-      return t('On this form you may tell Drupal where taxonomy terms should link to. By default, modules handled by the taxonomy modules link to <b>taxonomy/term/!tid</b>; however, there are many instances where a user may want to override this behavior and provide custom content. Include the variables !tid and !name to include the term id and name in the path.');
+      return t('On this form you may tell Drupal where taxonomy terms should link to. By default, modules handled by the taxonomy modules link to <b>taxonomy/term/!tid</b>; however, there are many instances where a user may want to override this behavior and provide custom content. Include the variables !tid and !name to include the term id and name in the path. You can also usePHP code to create flexible paths.');
   }
 }
 
@@ -27,7 +34,7 @@
   $items = array();
 
   if ($may_cache) {
-    $items[] = array('path' => 'admin/build/taxonomy_redirect', 
+    $items[] = array('path' => 'admin/settings/taxonomy_redirect',
       'title' => t('Taxonomy redirect'),
       'description' => t('Override the default url paths for taxonomy terms.'),
       'callback' => 'drupal_get_form',
@@ -45,7 +52,6 @@
   while ($redir = db_fetch_object($result)) {
     $voc[$redir->vid] = $redir;
   }
-
   $vocabs = taxonomy_get_vocabularies();
 
   $form = array();
@@ -89,29 +95,79 @@
         '#type' => 'markup',
         '#value' => $v->path,
       );
+      $form['voc'][$i]['filter'] = array(
+        '#type' => 'markup',
+        '#value' => _taxonomy_redirect_get_filters($v->filter)
+      );
+
+//         '#value' => filter_resolve_format($v->filter),
+      $form['voc'][$i]['preview'] = array(
+        '#type' => 'markup',
+        '#value' => _taxonomy_redirect_exec_filter($v->path,$v->filter)
+      );
+      $form['voc'][$i]['load'] = array(
+        '#type' => 'markup',
+        '#value' => l('load path','',array('onclick' => 'document.getElementById(\'edit-path\').value = decodeURIComponent( \''.rawurlencode($v->path).'\'); document.getElementById(\'edit-filter\').value = \''.$v->filter.'\'; return false;')));
+    }
     }
 
+  _taxonomy_redirect_admin_footer($voc,$form);
+
+  return $form;
+}
+function _taxonomy_redirect_admin_footer($voc,&$form) {
+  static $_footer_added;
+  if($_footer_added)
+    return;
+  $_footer_added = true;
     $form['action'] = array(
       '#type' => 'select',
       '#title' => t('Action'),
-      '#options' => array("submit" => t("Override all checked vocabularies, setting them to the given path."), "revert" => t("Revert all checked vocabularies to their original state.")),
+        '#options' => array(
+        "submit" => t("Override all checked vocabularies, setting them to the given path."),
+        "revert" => t("Revert all checked vocabularies to their original state.")),
       '#description' => t('What action to take.'),
     );
 
+  $form['filter'] = array(
+        '#type' => 'select',
+        '#title' => t('Filter'),
+        '#options' => _taxonomy_redirect_get_filters(),
+        '#description' => t('Select an input format for the term path. If using PHP use opening and closing brackets'),
+  );
+
     $form['path'] = array(
-      '#type' => 'textfield',
-      '#title' => t('Destination'),
-      '#size' => 30,
-      '#maxlength' => 128,
-      '#description' => t('Enter the path to redirect all checked vocabulary terms to. If reverting, this field is irrelevant. Do not place a leading or trailing /. !tid will be replaced with the term id, and !name will be replaced with the term name. Define the function taxonomy_redirect_custom_term_path($term, $path) to customise further.'),
+    '#type' => 'textarea',
+    '#cols' => 60,
+    '#rows' => 6,
+      '#description' => t('Enter the path to redirect all checked vocabulary terms to. If reverting, this field is irrelevant. Do not place a leading or trailing /. !tid will be replaced with the term id, and !name will be replaced with the term name. You can also enter PHP code (use enclosing PHP tags) to create the string. Or, define the function taxonomy_redirect_custom_term_path($term, $path) to customise further.'),
     );
+
     $form['save'] = array(
       '#type' => 'submit',
       '#value' => t("Submit"),
     );
-  }
 
-  return $form;
+}
+function _taxonomy_redirect_get_filters($i=NULL) {
+  $f = array(
+    "0" => t("Plain text"),
+    "1" => t("PHP"));
+  if(isset($i)) {
+    return $f[$i];
+  }
+  return $f;
+}
+function _taxonomy_redirect_exec_filter($text,$filter) {
+  switch($filter) {
+    case 1:
+      //return $text;
+      // should thsi be set to a constant? what is the constant for PHP
+      return check_markup($text,2,FALSE);
+    case 0:
+    default:
+      return $text;
+  }
 }
 
 function theme_taxonomy_redirect_admin($form) {
@@ -123,26 +179,33 @@
         drupal_render($form['voc'][$i]['handler']),
         drupal_render($form['voc'][$i]['module']),
         drupal_render($form['voc'][$i]['path']),
+        drupal_render($form['voc'][$i]['filter']),
+        drupal_render($form['voc'][$i]['preview']),
+        drupal_render($form['voc'][$i]['load']),
       );
     }
   }
   if (!$rows)
     $rows[] = array(array('data' => t("This view currently has no fields defined."), 'colspan' => 6));
 
-  $output .= theme('table', array(t('Op'), t('Vocabulary'), t('Current controller'), t('Original Controller'), t('Redirected to')), $rows);
-
+  $output .= theme('table', array(t('Op'), t('Vocabulary'), t('Current controller'), t('Original Controller'), t('Redirected to'),t('Filter'),t('Preview'),t('Load into editor')), $rows);
   $output .= drupal_render($form);
   return $output;
 }
 
 function taxonomy_redirect_admin_validate($formid, $form) {
-  if ($form['action'] != 'revert' && !$form['path']) {
-    form_set_error('destination', t("Path cannot be blank if overriding paths!"));
+  if ($form['action'] == 'submit' && $form['path']) {
+     if(!filter_access($form['format'])) {
+        form_set_error("format",t("no permission to use this input format"));
+     }
+     /* avoid a situation where code gets put in and breaks the site */
+     $demo = _taxonomy_redirect_exec_filter($v->path,$v->filter);
   }
 }
 
 function taxonomy_redirect_admin_submit($formid, $form) {
-  if ($form['action'] == 'revert') {
+  switch ($form['action']) {
+  case 'revert':
     foreach($form['voc'] as $vid => $voc) {
       if ($voc['override']) {
         $orig = isset($voc['orig']) ? $voc['orig'] : 'taxonomy';
@@ -152,8 +215,8 @@
         drupal_set_message(t("Reverting taxonomy/term for $vocab->name to control by @s", array('@s' => $voc['orig'])));
       }
     }
-  }
-  else {
+    break;
+  case 'submit':
     foreach($form['voc'] as $vid => $voc) {
       if ($voc['override']) {
         $vocab = taxonomy_get_vocabulary($vid);
@@ -162,17 +225,25 @@
         $vocab->module = 'taxonomy_redirect';
         db_query("UPDATE {vocabulary} SET module='taxonomy_redirect' WHERE vid='%d'", $vid);
 
+        $path = trim($form['path']);
+        $filter = (int)trim($form['filter']);
+
         if ($orig == 'taxonomy_redirect') {
           // already in database, so we can update
-          db_query("UPDATE {taxonomy_redirect} SET path='%s' WHERE vid='%d'", $form['path'], $vid);
+          db_query("UPDATE {taxonomy_redirect}
+            SET path='%s',filter='%d'
+             WHERE vid='%d'", $path, $filter, $vid);
         }
         else {
-          db_query("INSERT INTO {taxonomy_redirect} (vid, module, path) VALUES ('%d', '%s', '%s')",
-            $vid, $orig, $form['path']);
+          db_query("INSERT INTO {taxonomy_redirect}
+          (vid, module, path, filter)
+          VALUES ('%d', '%s', '%s', '%d')",
+            $vid, $orig, $path, $filter);
         }
-        drupal_set_message(t("Overriding taxonomy/term for $vocab->name to @s", array('@s' => $form['path'])));
+        drupal_set_message(t("Overriding taxonomy/term for $vocab->name to @s", array('@s' => _taxonomy_redirect_exec_filter($path,$filter))));
       }
     }
+    break;
   }
   return 'admin/build/taxonomy_redirect';
 }
