Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.371
diff -u -p -r1.371 theme.inc
--- includes/theme.inc	26 Aug 2007 07:46:10 -0000	1.371
+++ includes/theme.inc	26 Aug 2007 18:20:58 -0000
@@ -229,6 +229,11 @@ function _theme_process_registry(&$cache
     foreach ($result as $hook => $info) {
       $result[$hook]['type'] = $type;
       $result[$hook]['theme path'] = $path;
+      if (!isset($result[$hook]['theme paths'])) {
+        $result[$hook]['theme paths'] = array();
+      }
+      $result[$hook]['theme paths'][] = $path;
+
       // if function and file are left out, default to standard naming
       // conventions.
       if (!isset($info['template']) && !isset($info['function'])) {
@@ -256,6 +261,10 @@ function _theme_process_registry(&$cache
       if (!isset($info['arguments']) && isset($cache[$hook])) {
         $result[$hook]['arguments'] = $cache[$hook]['arguments'];
       }
+      // Likewise with theme paths
+      if (!isset($info['theme paths']) && isset($cache[$hook])) {
+        $result[$hook]['theme paths'] = $cache[$hook]['theme paths'];
+      }
       // Check for default _preprocess_ functions. Ensure arrayness.
       if (!isset($info['preprocess functions']) || !is_array($info['preprocess functions'])) {
         $info['preprocess functions'] = array();
@@ -572,7 +581,7 @@ function theme() {
     }
 
     if ($suggestions) {
-      $template_file = drupal_discover_template($suggestions, $extension);
+      $template_file = drupal_discover_template(array_reverse($hooks[$hook]['theme paths']), $suggestions, $extension);
     }
 
     if (empty($template_file)) {
@@ -592,14 +601,18 @@ function theme() {
  * Choose which template file to actually render; these are all
  * suggested templates from the theme.
  */
-function drupal_discover_template($suggestions, $extension = '.tpl.php') {
+function drupal_discover_template($paths, $suggestions, $extension = '.tpl.php') {
   global $theme_engine;
 
   // Loop through any suggestions in FIFO order.
   $suggestions = array_reverse($suggestions);
   foreach ($suggestions as $suggestion) {
-    if (!empty($suggestion) && file_exists($file = path_to_theme() .'/'. $suggestion . $extension)) {
-      return $file;
+    if (!empty($suggestion)) {
+      foreach ($paths as $path) {
+        if (file_exists($file = $path .'/'. $suggestion . $extension)) {
+          return $file;
+        }
+      }
     }
   }
 }
