Skip to content
Snippets Groups Projects
Commit 9ad29e52 authored by Neil Drumm's avatar Neil Drumm :wave:
Browse files

#51845 by olav, avoid code duplication in phptemplate derived theme engines

parent 133617cb
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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
}
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment