diff -purN -x '*.svn' pathfilter/pathfilter.module pathfilter-new/pathfilter.module
--- pathfilter/pathfilter.module	2008-02-19 11:56:53.000000000 -0800
+++ pathfilter-new/pathfilter.module	2009-04-17 13:58:29.000000000 -0700
@@ -15,6 +15,7 @@
  * [1] http://api.drupal.org/api/4.7/function/url
  *
  * Author:  Ray Zimmerman (drupal.org user "RayZ")
+ * Author:  George Montana Harkin (auto internalization)
  *
  */
 
@@ -92,5 +93,130 @@ function _pathfilter_settings() {
     '#default_value' => variable_get('pathfilter_link_type', 'absolute'),
     '#description' => t('Should internal paths be transformed to absolute URLs, such as %absolute or relative paths, like %relative. Note that your changes may not appear until the cache has been cleared.', array('%absolute' => 'http://www.example.com/my-page', '%relative' => '/my-page')),
   );
+  $form['pathfilter']['pathfilter_process_all'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Enable automatic url processing for attributes.'),
+    '#default_value' => variable_get('pathfilter_process_all', 1),
+    '#description' => t('When this option is enabled, all %element_list elements will automatically have the servername and base path of their src, href, and action urls replaced with %internal. On editing of these elements, all instances of %internal will be replaced with the site\'s base path (%current_base_path).', array('%element_list' => '<img>, <a>, <script>, <object>, and <form>', '%internal' => '\'internal:\'', '%current_base_path' => base_path())),
+  );
   return $form;
-}
\ No newline at end of file
+}
+
+/**
+ * Modifies submitted node body values. Replaces base_path() in images, hrefs, 
+ * etc with 'internal:' on save. When editing a node, the body's 'internal:' 
+ * strings are replaced with 'base_path()'.
+ */
+function pathfilter_nodeapi( &$node, $op )
+{
+  switch ($op) {
+    case 'prepare':
+      _replace_links($node, '_replace_internal');
+      break;
+    case 'presave':
+      /* We do more when we look for what to replace with 'internal:'
+      - Only want to replace items that are links, not text or data
+      - Check to see if they specified the hostname of the server 
+      - Make sure to accept items that have multiple slashes.*/
+      _replace_links($node, '_normalize_and_internalize');
+      break;
+  }
+}
+
+
+/**
+ * Replaces the links in select node properties (body, teaser, and any 
+ * textfields that have formatting defined for them)
+ *
+ * $node      : StdClass Object
+ * $func_name : String           Can be either _normalize_and_interalize or _replace_internal
+ *                               both functions replace links, one is before saving and one is 
+ *                               before viewing
+ */
+function _replace_links( &$node, $func_name ){
+    
+    //if we have our pathfilter variable defined lets replace otherwise bail out
+    if (variable_get('pathfilter_process_all', 1)) {
+         
+        //lets get all the pathfilters we have defined and their corresponding formats 
+        $result = db_query("SELECT format FROM {filters} WHERE module = 'pathfilter'"); 
+        while ($row = db_fetch_object($result)) {
+            $defined_formats[] = $row->format;
+        }
+                
+        //iterate through our objects properties looking for body, teaser, and any fields that have
+        //formatting defined for them
+        foreach($node as $key => &$value) {
+            //if this is the body or teaser lets run our replaces
+            if ($key == "body" || $key == "teaser") {
+                $func_name($value);
+            }
+            elseif (is_array($value)) { 
+                //look at the rest of the fields...if they have a format from our defined formats list 
+                //and we have a value that is a string run our replace...otherwise ignore them
+                if (!empty($value[0]['format']) && in_array($value[0]['format'], $defined_formats) && 
+                    !empty($value[0]['value']) && is_string($value[0]['value'])) {
+                    $func_name($value[0]['value']);
+                }
+            }
+        }
+        
+    }
+}
+
+
+/**
+ * Replaces the internal: in elements with the url for it
+ */
+function _replace_internal( &$item ){
+      $absolute = (variable_get('pathfilter_link_type', 'absolute') == 'absolute' ? 'TRUE' : 'FALSE');
+      $url = url('',array('absolute' => $absolute));
+      $item = preg_replace('/internal:/', $url, $item);
+}
+
+/**
+ * Normalizes and Internalizes all urls in a item, key 
+ */
+function _normalize_and_internalize( &$item ) {
+  // First we find all of the items that look like they need to be replaced.
+  $pattern = '/(<img|<a|<script|<object|<form)[^\>]*>/i';
+  preg_match_all( $pattern, $item, $matches );
+  // Then we normalize the links of the items that matched and do
+  // 'internal:' replacement.
+  foreach ( $matches[0] as $match ) {
+    preg_match( '/(src=|href=|action=)(\'|")([^\'"]*)(\'|"|>)/', $match, $url );
+    // Do replacement with 'internal:' 
+    $base_url_re = _base_url_re();
+    $replaced_path = preg_replace( $base_url_re, 'internal:', $url[3], 1 );
+    // Update original string with changes, if needed.
+    if ($replaced_path != $url[3]) { 
+      $item = preg_replace( '/(src=|href=|action=)(\'|")('.preg_quote($url[3], '/').')(\'|"|>)/', 
+                            '$1$2'.$replaced_path.'$4', 
+                            $item, 1);
+    }
+  }
+}
+
+/**
+ * Generates the regular expression that will be used to find a url that should
+ * have 'internal:'.
+ */
+function _base_url_re() {
+  static $base_re;
+
+  if ($base_re!= '') {
+    return $base_re;
+  }
+
+  global $base_url;
+  $base_path = base_path();
+
+  if ($base_path != '/') {
+      $tmp_base_url = str_replace($base_path, '', $base_url.'/');
+  } else {
+      $tmp_base_url = $base_url;
+  }
+
+  $base_re = '/^('.preg_quote($tmp_base_url, '/').')?'.preg_quote($base_path, '/').'/';
+  return $base_re;
+}
