From f59b00c6ddee326aefa7d0bbf8444710cdae2d41 Mon Sep 17 00:00:00 2001 From: uwetews Date: Wed, 27 Jan 2016 04:51:02 +0100 Subject: [PATCH] - bugfix {extends} with relative file path did not work https://github.com/smarty-php/smarty/issues/154 https://github.com/smarty-php/smarty/issues/158 --- change_log.txt | 6 ++++-- libs/Smarty.class.php | 2 +- libs/sysplugins/smarty_internal_compile_block.php | 2 ++ libs/sysplugins/smarty_internal_resource_file.php | 7 ++++++- libs/sysplugins/smarty_internal_runtime_inheritance.php | 7 +++++++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/change_log.txt b/change_log.txt index 230224bf9..4cc246c06 100644 --- a/change_log.txt +++ b/change_log.txt @@ -4,8 +4,10 @@ - bugfix {$smarty.section.customer.loop} did throw compiler error https://github.com/smarty-php/smarty/issues/161 update of yesterdays fix - bugfix string resource could inject code at {block} or inline subtemplates through PHP comments https://github.com/smarty-php/smarty/issues/157 - - bugfix output filters did not observe nocache code flag https://github.com/smarty-php/smarty/issues/160 - + - bugfix output filters did not observe nocache code flhttps://github.com/smarty-php/smarty/issues/154g https://github.com/smarty-php/smarty/issues/160 + - bugfix {extends} with relative file path did not work https://github.com/smarty-php/smarty/issues/154 + https://github.com/smarty-php/smarty/issues/158 + 26.01.2016 - improvement observe Smarty::$_CHARSET in debugging console https://github.com/smarty-php/smarty/issues/169 - bugfix compiling {section} did create warning diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 987993e11..4e9d9ec31 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.30-dev/23'; + const SMARTY_VERSION = '3.1.30-dev/24'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_internal_compile_block.php b/libs/sysplugins/smarty_internal_compile_block.php index 6be501dca..8288fdbf3 100644 --- a/libs/sysplugins/smarty_internal_compile_block.php +++ b/libs/sysplugins/smarty_internal_compile_block.php @@ -200,6 +200,7 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $ if ($compiler->template->compiled->has_nocache_code) { $output .= "\$_smarty_tpl->cached->hashes['{$compiler->template->compiled->nocache_hash}'] = true;\n"; } + $output .= "\$_smarty_tpl->ext->_inheritance->blockNesting++;\n"; if (isset($_assign)) { $output .= "ob_start();\n"; } @@ -213,6 +214,7 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $ $output .= "\$_smarty_tpl->tpl_vars[{$_assign}] = new Smarty_Variable(ob_get_clean());\n"; } //$output .= "/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n"; + $output .= "\$_smarty_tpl->ext->_inheritance->blockNesting--;\n"; $output .= "}\n"; $output .= "}\n"; $output .= "/* {/block '{$_name}'} */\n\n"; diff --git a/libs/sysplugins/smarty_internal_resource_file.php b/libs/sysplugins/smarty_internal_resource_file.php index 8897a1f1f..a7aa50cd8 100644 --- a/libs/sysplugins/smarty_internal_resource_file.php +++ b/libs/sysplugins/smarty_internal_resource_file.php @@ -43,7 +43,12 @@ protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal ) { throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'"); } - $path = dirname($_template->parent->source->filepath) . DS . $file; + // if we are inside an {block} tag the path must be relative to current template + if (isset($_template->ext->_inheritance) && $_template->ext->_inheritance->blockNesting && $_template->parent->parent->_objType == 2) { + $path = dirname($_template->parent->parent->source->filepath) . DS . $file; + } else { + $path = dirname($_template->parent->source->filepath) . DS . $file; + } // normalize path $path = $source->smarty->_realpath($path); // files relative to a template only get one shot diff --git a/libs/sysplugins/smarty_internal_runtime_inheritance.php b/libs/sysplugins/smarty_internal_runtime_inheritance.php index 7e85dd59e..4adb881b5 100644 --- a/libs/sysplugins/smarty_internal_runtime_inheritance.php +++ b/libs/sysplugins/smarty_internal_runtime_inheritance.php @@ -44,6 +44,13 @@ class Smarty_Internal_Runtime_Inheritance */ public $tplIndex = - 1; + /** + * current block nesting level + * + * @var int + */ + public $blockNesting = 0; + /** * Array of source template names * - key template index