From 99c1f4c87c7b014e305613a4dc8eeb5730678799 Mon Sep 17 00:00:00 2001 From: onli Date: Sun, 27 Apr 2014 20:23:56 +0200 Subject: [PATCH] Fix fallback chain Engine: default in info.txt will now lead to the template to use template/default as fallback before the default-template (2k11 currently). An approach to fix #130 Also, template_engine is not automatically set to default, as this was implicitly always the case --- include/admin/templates.inc.php | 7 ++++- include/functions_config.inc.php | 11 +++---- include/serendipity_smarty_class.inc.php | 39 +++++++++--------------- 3 files changed, 26 insertions(+), 31 deletions(-) diff --git a/include/admin/templates.inc.php b/include/admin/templates.inc.php index 75933e67..7d13e4db 100644 --- a/include/admin/templates.inc.php +++ b/include/admin/templates.inc.php @@ -71,7 +71,12 @@ if ($serendipity['GET']['adminAction'] == 'install' ) { serendipity_plugin_api::hook_event('backend_templates_install', $serendipity['GET']['theme'], $themeInfo); serendipity_set_config_var('template', htmlspecialchars($serendipity['GET']['theme'])); - serendipity_set_config_var('template_engine', isset($themeInfo['engine']) ? $themeInfo['engine'] : 'default'); + + // template_engine was set by default to default, which screws up the fallback chain (to the default-template first) + serendipity_set_config_var('template_engine', null); + if ($themeInfo['engine']) { + serendipity_set_config_var('template_engine', $themeInfo['engine']); + } serendipity_set_config_var('last_template_change', time()); $data["adminAction"] = "install"; diff --git a/include/functions_config.inc.php b/include/functions_config.inc.php index 65b38747..ed57aec5 100644 --- a/include/functions_config.inc.php +++ b/include/functions_config.inc.php @@ -88,7 +88,6 @@ function serendipity_remove_config_var($name, $authorid = 0) { * @param string The name of the configuration value * @param string The value of the configuration item * @param int The ID of the owner of the config value (0: global) - * @return null */ function serendipity_set_config_var($name, $val, $authorid = 0) { global $serendipity; @@ -263,11 +262,11 @@ function serendipity_getTemplateFile($file, $key = 'serendipityHTTPPath') { $directories = array(); $directories[] = isset($serendipity['template']) ? $serendipity['template'] . '/' : ''; - if (isset($serendipity['template_engine']) && (stristr($file, 'admin/') === false || $serendipity['template_engine'] != 'default')) { - $p = explode(',', $serendipity['template_engine']); - foreach($p AS $te) { - $directories[] = trim($te) . '/'; - } + if (isset($serendipity['template_engine'])) { + $p = explode(',', $serendipity['template_engine']); + foreach($p AS $te) { + $directories[] = trim($te) . '/'; + } } $directories[] = $serendipity['defaultTemplate'] .'/'; diff --git a/include/serendipity_smarty_class.inc.php b/include/serendipity_smarty_class.inc.php index 77b3c535..b590ec5c 100644 --- a/include/serendipity_smarty_class.inc.php +++ b/include/serendipity_smarty_class.inc.php @@ -117,33 +117,24 @@ class Serendipity_Smarty extends Smarty Set all directory setters Smarty will always use the first template found in order of the given array. Move the least significant directory to the end. */ - - // initiate templateDir setter - $this->setTemplateDir(array(S9Y_TEMPLATE_USERDEFAULT)); - // set addTemplate array with the blogs used template anyway - $serendipity['addTemplateDir'] = array($serendipity['serendipityPath'] . $serendipity['templatePath'] . $serendipity['defaultTemplate']); - /* - Note: Ian - BEWARE: Bulletproof and default template do not have any engine settings, so the next will be empty. This is why adding defaultTemplate was necessary. - */ - // merge engine only templates to addTemplate array - $p = explode(',', $serendipity['template_engine']); - foreach($p AS $te) { - $serendipity['addTemplateDir'][] = $serendipity['serendipityPath'] . $serendipity['templatePath'] . $te; - } + $template_engine = serendipity_get_config_var('template_engine'); + $template_dirs = array(); + if ($template_engine) { + $template_dirs[] = $serendipity['serendipityPath'] . $serendipity['templatePath'] . $template_engine; + } + $template_dirs[] = $serendipity['serendipityPath'] . $serendipity['templatePath'] . $serendipity['defaultTemplate']; // add secure dir to template path, in case engine did have entries - $serendipity['addTemplateDir'][] = S9Y_TEMPLATE_SECUREDIR; - // disable plugin dir as added template dir is not adviced, if set security is enabled (backend & frontend need access to fetch plugin templates) - $serendipity['addTemplateDir'][] = $serendipity['serendipityPath'] . 'plugins'; - // add default template to addTemplate array, if not already set in engine - $serendipity['addTemplateDir'][] = S9Y_TEMPLATE_FALLBACK; + if (S9Y_TEMPLATE_SECUREDIR != $serendipity['serendipityPath'] . $serendipity['templatePath']) { + $template_dirs[] = S9Y_TEMPLATE_SECUREDIR; + } - // expand smarty objects (add)TemplateDir setter with $serendipity['addTemplateDir'] as is - $this->addTemplateDir($serendipity['addTemplateDir']); - - // setTemplateDir again to unified getTemplateDir() to avoid doubles for (engine, default and main templates) - $this->setTemplateDir(array_values(array_unique($this->getTemplateDir()))); // reset keys to be unique + // disable plugin dir as added template dir is not adviced, if set security is enabled (backend & frontend need access to fetch plugin templates) + $template_dirs[] = $serendipity['serendipityPath'] . 'plugins'; + // add default template to addTemplate array, if not already set in engine + $template_dirs[] = S9Y_TEMPLATE_FALLBACK; + + $this->setTemplateDir($template_dirs); $this->setCompileDir($serendipity['serendipityPath'] . PATH_SMARTY_COMPILE);