? dynamic_theme.patch
? files
? maintenance_theme.patch
? restore_maintenance_mode.patch
? profiles/InstallerAutolocale.zip
? sites/logrus.com.x
? sites/all/modules
? sites/all/themes
? sites/default/settings.php
? themes/bluemarine/install_page.tpl.php
? themes/bluemarine/maintenance_page.tpl.php
? themes/garland/maintenance_page.tpl.php
Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.358
diff -u -p -r1.358 theme.inc
--- includes/theme.inc	8 Jun 2007 12:51:58 -0000	1.358
+++ includes/theme.inc	10 Jun 2007 21:11:03 -0000
@@ -454,7 +454,8 @@ function list_theme_engines($refresh = F
  *   files, one at a time, and use the first one
  *   that exists.
  * @param $hook
- *   The name of the theme function to call.
+ *   The name of the theme function to call. May be an array, in which
+ *   case the first existing hook will be used.
  * @param ...
  *   Additional arguments to pass along to the theme function.
  * @return
@@ -470,6 +471,15 @@ function theme() {
     $hooks = theme_get_registry();
   }
 
+  if (is_array($hook)) {
+    foreach ($hook as $candidate) {
+      if (isset($hooks[$candidate])) {
+        break;
+      }
+    }
+    $hook = $candidate;
+  }
+
   if (!isset($hooks[$hook])) {
     return;
   }
@@ -596,6 +606,100 @@ function path_to_theme() {
 }
 
 /**
+ * Find overridden theme functions. Called by themes and/or theme engines to
+ * easily discover theme functions.
+ *
+ * @param $cache
+ *   The existing cache of theme hooks to test against.
+ * @param $prefixes
+ *   An array of prefixes to test, in reverse order of importance.
+ *
+ * @return $templates
+ *   The functions found, suitable for returning from hook_theme;
+ */
+function drupal_find_theme_functions($cache, $prefixes) {
+  $templates = array();
+  $functions = get_defined_functions();
+
+  foreach ($cache as $hook => $info) {
+    foreach ($prefixes as $prefix) {
+      if (!empty($info['pattern'])) {
+        $matches = preg_grep('/^'. $prefix .'_'. $info['pattern'] .'/', $functions['user']);
+        if ($matches) {
+          foreach ($matches as $match) {
+            $new_hook = str_replace($prefix . '_', '', $match);
+            $templates[$new_hook] = array(
+              'function' => $match,
+              'arguments' => $info['arguments'],
+            );
+          }
+        }
+      }
+      if (function_exists($prefix .'_'. $hook)) {
+        $templates[$hook] = array(
+          'function' => $prefix .'_'. $hook,
+        );
+      }
+    }
+  }
+
+  return $templates;
+}
+
+/**
+ * Find overridden theme templates. Called by themes and/or theme engines to
+ * easily discover templates.
+ *
+ * @param $cache
+ *   The existing cache of theme hooks to test against.
+ * @param $extension
+ *   The extension that these templates will have.
+ * @param $path
+ *   The path to search.
+ */
+function drupal_find_theme_templates($cache, $extension, $path) {
+  $templates = array();
+
+  // Escape the dots 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) {
+    // Chop off the extension. We do it this way because $template will
+    // have one extension chopped off, but there might be more than one,
+    // such as with .tpl.php
+    $template = substr($template, 0, strpos($template, '.'));
+    if (isset($cache[$template])) {
+      $templates[$template] = array(
+        'file' => $template,
+        'path' => dirname($file->filename),
+      );
+    }
+  }
+
+  $patterns = array_keys($files);
+
+  foreach ($cache as $hook => $info) {
+    if (!empty($info['pattern'])) {
+      $matches = preg_grep('/^'. $info['pattern'] .'/', $patterns);
+      if ($matches) {
+        foreach ($matches as $match) {
+          $file = substr($match, 0, strpos($match, '.'));
+          $templates[$file] = array(
+            'file' => $file,
+            'path' => dirname($files[$match]->filename),
+            'arguments' => $info['arguments'],
+          );
+        }
+      }
+    }
+  }
+  return $templates;
+}
+
+/**
  * Retrieve an associative array containing the settings for a theme.
  *
  * The final settings are arrived at by merging the default settings,
Index: themes/chameleon/chameleon.theme
===================================================================
RCS file: /cvs/drupal/drupal/themes/chameleon/chameleon.theme,v
retrieving revision 1.65
diff -u -p -r1.65 chameleon.theme
--- themes/chameleon/chameleon.theme	6 May 2007 05:47:52 -0000	1.65
+++ themes/chameleon/chameleon.theme	10 Jun 2007 21:11:03 -0000
@@ -10,16 +10,7 @@
  * Implementation of hook_theme. Auto-discover theme functions.
  */
 function chameleon_theme($existing, $type, $theme, $path) {
-  $templates = array();
-  // Check for function overrides.
-  foreach ($existing as $hook => $info) {
-    if (function_exists($theme .'_'. $hook)) {
-      $templates[$hook] = array(
-        'function' => $theme .'_'. $hook,
-      );
-    }
-  }
-  return $templates;
+  return drupal_find_theme_functions($existing, array($theme));
 }
 
 function chameleon_page($content, $show_blocks = TRUE, $show_messages = TRUE) {
Index: themes/engines/phptemplate/phptemplate.engine
===================================================================
RCS file: /cvs/drupal/drupal/themes/engines/phptemplate/phptemplate.engine,v
retrieving revision 1.65
diff -u -p -r1.65 phptemplate.engine
--- themes/engines/phptemplate/phptemplate.engine	6 May 2007 05:47:52 -0000	1.65
+++ themes/engines/phptemplate/phptemplate.engine	10 Jun 2007 21:11:03 -0000
@@ -20,36 +20,8 @@ function phptemplate_init($template) {
  * we need to.
  */
 function phptemplate_theme($existing, $type, $theme, $path) {
-  $templates = array();
-
-  // Check for template overrides.
-  $files = drupal_system_listing('\.tpl\.php$', $path, 'name', 0);
-
-  foreach ($files as $template => $file) {
-    // chop off the .tpl
-    $template = substr($template, 0, -4);
-    if (isset($existing[$template])) {
-      $templates[$template] = array(
-        'file' => $template,
-        'path' => dirname($file->filename),
-      );
-    }
-  }
-
-  // Check for function overrides.
-  foreach ($existing as $hook => $info) {
-    if (function_exists($theme .'_'. $hook)) {
-      $templates[$hook] = array(
-        'function' => $theme .'_'. $hook,
-      );
-    }
-    else if (function_exists('phptemplate_'. $hook)) {
-      $templates[$hook] = array(
-        'function' => 'phptemplate_'. $hook,
-      );
-    }
-  }
-
+  $templates = drupal_find_theme_functions($existing, array('phptemplate', $theme));
+  $templates += drupal_find_theme_templates($existing, '.tpl.php', $path);
   return $templates;
 }
 
