Index: pathauto.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto.module,v
retrieving revision 1.126.2.14
diff -u -p -r1.126.2.14 pathauto.module
--- pathauto.module	19 Feb 2010 05:40:29 -0000	1.126.2.14
+++ pathauto.module	19 Feb 2010 17:56:19 -0000
@@ -100,6 +100,42 @@ function pathauto_path_alias_types() {
   return $objects;
 }
 
+/**
+ * Load an URL alias pattern by entity, bundle, and language.
+ *
+ * @param $entity
+ *   An entity (e.g. node, taxonomy, user, etc.)
+ * @param $bundle
+ *   A bundle (e.g. node type, vocabulary ID, etc.)
+ * @param $language
+ *   An optional language code.
+ */
+function pathauto_pattern_load_by_entity($entity, $bundle = '', $language = '') {
+  static $patterns = array();
+
+  $pattern_id = "$entity:$bundle:$language";
+  if (!isset($patterns[$pattern_id])) {
+    $variables = array();
+    if ($language) {
+      $variables[] = "pathauto_{$entity}_{$bundle}_{$language}_pattern";
+    }
+    if ($bundle) {
+      $variables[] = "pathauto_{$entity}_{$bundle}_pattern";
+    }
+    $variables[] = "pathauto_{$entity}_pattern";
+
+    foreach ($variables as $variable) {
+      if ($pattern = trim(variable_get($variable, ''))) {
+        break;
+      }
+    }
+
+    $patterns[$pattern_id] = $pattern;
+  }
+
+  return $patterns[$pattern_id];
+}
+
 //==============================================================================
 // Some node related functions.
 
@@ -123,19 +159,9 @@ function pathauto_nodeapi(&$node, $op, $
       break;
     case 'insert':
     case 'update':
-      _pathauto_include();
-      // Get the specific pattern or the default
-      if (variable_get('language_content_type_'. $node->type, 0)) {
-        $pattern = trim(variable_get('pathauto_node_'. $node->type .'_'. $node->language .'_pattern', FALSE));
-      }
-      if (empty($pattern)) {
-        $pattern = trim(variable_get('pathauto_node_'. $node->type .'_pattern', FALSE));
-        if (empty($pattern)) {
-          $pattern = trim(variable_get('pathauto_node_pattern', FALSE));
-        }
-      }
-      // Only do work if there's a pattern
-      if ($pattern) {
+      $language = variable_get('language_content_type_' . $node->type, 0) ? $node->language : '';
+      if ($pattern = pathauto_pattern_load_by_entity('node', $node->type, $language)) {
+        _pathauto_include();
         // Only create an alias if the checkbox was not provided or if the checkbox was provided and is checked
         if (!isset($node->pathauto_perform_alias) || $node->pathauto_perform_alias) {
           $placeholders = pathauto_get_placeholders('node', $node);
@@ -167,16 +193,7 @@ function pathauto_form_alter(&$form, $fo
     $pattern = FALSE;
 
     // Find if there is an automatic alias pattern for this node type.
-    if (isset($form['language'])) {
-      $language = isset($form['language']['#value']) ? $form['language']['#value'] : $form['language']['#default_value'];
-      $pattern = trim(variable_get('pathauto_node_'. $form['type']['#value'] .'_'. $language .'_pattern', ''));
-    }
-    if (!$pattern) {
-      $pattern = trim(variable_get('pathauto_node_'. $form['type']['#value'] .'_pattern', ''));
-      if (!$pattern) {
-        $pattern = trim(variable_get('pathauto_node_pattern', ''));
-      }
-    }
+    $pattern = pathauto_pattern_load_by_entity('node', $node->type, $node->language);
 
     // If there is a pattern, show the automatic alias checkbox.
     if ($pattern) {
@@ -271,18 +288,20 @@ function pathauto_taxonomy($op, $type, $
       switch ($op) {
         case 'insert':
         case 'update':
-          _pathauto_include();
-          // Use the category info to automatically create an alias
+          // Only do work if there's a pattern
           $category = (object) $object;
-          if ($category->name) {
-            $count = _taxonomy_pathauto_alias($category, $op);
+          if ($pattern = pathauto_pattern_load_by_entity('taxonomy', $category->vid)) {
+            // Use the category info to automatically create an alias
+            _pathauto_include();
+            if ($category->name) {
+              $count = _taxonomy_pathauto_alias($category, $op);
+            }
+
+            // For all children generate new alias (important if [catpath] used)
+            foreach (taxonomy_get_tree($category->vid, $category->tid) as $subcategory) {
+              $count = _taxonomy_pathauto_alias($subcategory, $op);
+            }
           }
-
-          // For all children generate new alias (important if [catpath] used)
-          foreach (taxonomy_get_tree($category->vid, $category->tid) as $subcategory) {
-            $count = _taxonomy_pathauto_alias($subcategory, $op);
-          }
-
           break;
         case 'delete':
           // If the category is deleted, remove the path aliases
Index: pathauto_taxonomy.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto_taxonomy.inc,v
retrieving revision 1.41
diff -u -p -r1.41 pathauto_taxonomy.inc
--- pathauto_taxonomy.inc	28 Aug 2008 16:14:06 -0000	1.41
+++ pathauto_taxonomy.inc	19 Feb 2010 17:56:20 -0000
@@ -57,15 +57,9 @@ function taxonomy_pathauto_bulkupdate() 
   // From all node types, only attempt to update those with patterns
   $pattern_vids = array();
   foreach (taxonomy_get_vocabularies() as $vid => $info) {
-    $pattern = trim(variable_get('pathauto_taxonomy_'. $vid .'_pattern', ''));
-
-    // If it's not set, check the default
     // TODO - if there's a default we shouldn't do this crazy where statement because all vocabs get aliases
     // TODO - special casing to exclude the forum vid (and the images vid and...?)
-    if (empty($pattern)) {
-      $pattern = trim(variable_get('pathauto_taxonomy_pattern', ''));
-    }
-    if (!empty($pattern)) {
+    if (pathauto_pattern_load_by_entity('taxonomy', $vid)) {
       $pattern_vids[] = $vid;
       if (empty($vid_where)) {
         $vid_where = " AND (vid = '%s' ";
