Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.409
diff -u -p -r1.409 theme.inc
--- includes/theme.inc	9 Jan 2008 22:01:29 -0000	1.409
+++ includes/theme.inc	11 Jan 2008 03:55:01 -0000
@@ -754,25 +754,33 @@ function drupal_find_theme_functions($ca
 function drupal_find_theme_templates($cache, $extension, $path) {
   $templates = array();
 
-  // Escape the periods in the extension.
-  $regex = str_replace('.', '\.', $extension) .'$';
-
-  // Collect sub-themes for the current theme. This allows base themes to have
-  // sub-themes in its folder hierarchy without affecting the base theme.
-  global $theme;
-  $sub_themes = array();
+  // Build a list of filtered paths. This allows base themes to have sub-themes
+  // in its folder hierarchy without affecting the base theme.
+  $filters = array();
   foreach (list_themes() as $theme_info) {
-    if (!empty($theme_info->base_theme) && $theme_info->base_theme == $theme) {
-      $sub_themes[] = dirname($theme_info->filename);
+    if (!empty($theme_info->base_theme)) {
+      $filters[$theme_info->base_theme][$theme_info->name] = dirname($theme_info->filename);
+    }
+  }
+  foreach ($filters as $parent => $children) {
+    foreach ($children as $child => $child_path) {
+      if (isset($filters[$child])) {
+        $filters[$parent] = array_merge($filters[$parent], $filters[$child]);
+      }
     }
   }
+  // Target filter for the current theme.
+  global $theme;
+  $filter = isset($filters[$theme]) ? $filters[$theme] : array();
 
+  // Escape the periods in the extension.
+  $regex = str_replace('.', '\.', $extension) .'$';
   // Because drupal_system_listing works the way it does, we check for real
   // templates separately from checking for patterns.
   $files = drupal_system_listing($regex, $path, 'name', 0);
   foreach ($files as $template => $file) {
-    // Catch sub-themes and skip.
-    if (strpos($file->filename, str_replace($sub_themes, '', $file->filename)) !== 0) {
+    // Ignore sub-theme templates for the current.
+    if (strpos($file->filename, str_replace($filter, '', $file->filename)) !== 0) {
       continue;
     }
     // Chop off the remaining extensions if there are any. $template already
