summaryrefslogtreecommitdiff
path: root/themes/engines/phptemplate/phptemplate.engine
diff options
context:
space:
mode:
authorNeil Drumm <drumm@3064.no-reply.drupal.org>2006-05-04 10:10:19 +0000
committerNeil Drumm <drumm@3064.no-reply.drupal.org>2006-05-04 10:10:19 +0000
commit9ad29e527f19fe919e858141d5a7252bb6a03b3e (patch)
treec411d52fec436b37183131e60c693479868d42f5 /themes/engines/phptemplate/phptemplate.engine
parent133617cb13c22e0b16119d69b257cd62602e0138 (diff)
downloadbrdo-9ad29e527f19fe919e858141d5a7252bb6a03b3e.tar.gz
brdo-9ad29e527f19fe919e858141d5a7252bb6a03b3e.tar.bz2
#51845 by olav, avoid code duplication in phptemplate derived theme engines
Diffstat (limited to 'themes/engines/phptemplate/phptemplate.engine')
-rw-r--r--themes/engines/phptemplate/phptemplate.engine49
1 files changed, 29 insertions, 20 deletions
diff --git a/themes/engines/phptemplate/phptemplate.engine b/themes/engines/phptemplate/phptemplate.engine
index 569e86ecd..63fb960a9 100644
--- a/themes/engines/phptemplate/phptemplate.engine
+++ b/themes/engines/phptemplate/phptemplate.engine
@@ -52,23 +52,27 @@ function phptemplate_regions() {
* The HTML generated by the template system.
*/
function _phptemplate_callback($hook, $variables = array(), $file = NULL) {
+ global $theme_engine;
$variables = array_merge($variables, _phptemplate_default_variables($hook, $variables));
// Allow specified variables to be overridden
- if (function_exists('_phptemplate_variables')) {
- $variables = array_merge($variables, _phptemplate_variables($hook, $variables));
+ $variables_function = '_'. $theme_engine .'_variables';
+ if (function_exists($variables_function)) {
+ $variables = array_merge($variables, call_user_func($variables_function, $hook, $variables));
}
if (isset($variables['template_file'])) {
$file = $variables['template_file'];
}
- if (function_exists('_phptemplate_' . $hook)) {
- return call_user_func('_phptemplate_' . $hook, $variables, $file);
+ $hook_function = '_'. $theme_engine .'_'. $hook;
+ $default_function = '_'. $theme_engine .'_default';
+ if (function_exists($hook_function)) {
+ return call_user_func($hook_function, $variables, $file);
}
- elseif (function_exists('_phptemplate_default')) {
- return call_user_func('_phptemplate_default', $hook, $variables, $file);
+ elseif (function_exists($default_function)) {
+ return call_user_func($default_function, $hook, $variables, $file);
}
}
@@ -309,35 +313,40 @@ function phptemplate_box($title, $content, $region = 'main') {
* @param $file
* A suggested template file to use.
*/
-function _phptemplate_default($hook, $variables, $file = NULL) {
- if (!empty($file) && file_exists(path_to_theme() . "/$file.tpl.php")) {
- $file = path_to_theme() . "/$file.tpl.php";
+function _phptemplate_default($hook, $variables, $file = NULL, $extension = '.tpl.php') {
+ global $theme_engine;
+
+ if (!empty($file) && file_exists(path_to_theme() ."/$file$extension")) {
+ $file = path_to_theme() ."/$file$extension";
}
else {
- if (file_exists(path_to_theme() . "/$hook.tpl.php")) {
- $file = path_to_theme() . "/$hook.tpl.php";
+ if (file_exists(path_to_theme() ."/$hook$extension")) {
+ $file = path_to_theme() ."/$hook$extension";
}
else {
if (in_array($hook, array('node', 'block', 'box', 'comment'))) {
- $file = "themes/engines/phptemplate/$hook.tpl.php";
+ $file = "themes/engines/$theme_engine/$hook$extension";
}
else {
$variables['hook'] = $hook;
- watchdog('error', t('PHPTemplate was instructed to override the %name theme function, but no valid template file was found.', array('%name' => theme('placeholder', $hook))));
- $file = 'themes/engines/phptemplate/default.tpl.php';
+ watchdog('error', t('%engine.engine was instructed to override the %name theme function, but no valid template file was found.', array('%engine' => $theme_engine, '%name' => theme('placeholder', $hook))));
+ $file = "themes/engines/$theme_engine/default$extension";
}
}
}
if (isset($file)) {
- extract($variables, EXTR_SKIP); // Extract the variables to a local namespace
- ob_start(); // Start output buffering
- include "./$file"; // Include the file
- $contents = ob_get_contents(); // Get the contents of the buffer
- ob_end_clean(); // End buffering and discard
- return $contents; // Return the contents
+ return call_user_func('_'. $theme_engine .'_render', $file, $variables);
}
+}
+function _phptemplate_render($file, $variables) {
+ extract($variables, EXTR_SKIP); // Extract the variables to a local namespace
+ ob_start(); // Start output buffering
+ include "./$file"; // Include the file
+ $contents = ob_get_contents(); // Get the contents of the buffer
+ ob_end_clean(); // End buffering and discard
+ return $contents; // Return the contents
}
?>