summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--change_log.txt3
-rw-r--r--libs/Smarty.class.php2
-rw-r--r--libs/sysplugins/smarty_internal_block.php7
-rw-r--r--libs/sysplugins/smarty_internal_compile_extends.php2
-rw-r--r--libs/sysplugins/smarty_internal_resource_file.php7
-rw-r--r--libs/sysplugins/smarty_internal_runtime_inheritance.php74
-rw-r--r--libs/sysplugins/smarty_resource.php7
7 files changed, 26 insertions, 76 deletions
diff --git a/change_log.txt b/change_log.txt
index 55015cfc..39bbfe6d 100644
--- a/change_log.txt
+++ b/change_log.txt
@@ -1,4 +1,7 @@
 ===== 3.1.30-dev ===== (xx.xx.xx)
+ 19.07.2016
+ - bugfix multiple {include} with relative filepath within {block}{/block} could fail https://github.com/smarty-php/smarty/issues/246
+
18.07.2016
- bugfix {foreach} if key variable and item@key attribute have been used both the key variable was not updated https://github.com/smarty-php/smarty/issues/254
- bugfix modifier on plugins like {plugin|modifier ... } did fail when the plugin does return an array https://github.com/smarty-php/smarty/issues/228
diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php
index 3030ba39..98eeddbe 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/84';
+ const SMARTY_VERSION = '3.1.30-dev/85';
/**
* define variable scopes
diff --git a/libs/sysplugins/smarty_internal_block.php b/libs/sysplugins/smarty_internal_block.php
index 476befc2..a33ad1b1 100644
--- a/libs/sysplugins/smarty_internal_block.php
+++ b/libs/sysplugins/smarty_internal_block.php
@@ -66,13 +66,6 @@ class Smarty_Internal_Block
public $tplIndex = 0;
/**
- * Nesting level of called sub-templates
- *
- * @var int
- */
- public $subTemplateNesting = 0;
-
- /**
* Smarty_Internal_Block constructor.
* - if outer level {block} of child template ($state == 1) save it as child root block
* - otherwise process inheritance and render
diff --git a/libs/sysplugins/smarty_internal_compile_extends.php b/libs/sysplugins/smarty_internal_compile_extends.php
index ccbb54fa..949875c5 100644
--- a/libs/sysplugins/smarty_internal_compile_extends.php
+++ b/libs/sysplugins/smarty_internal_compile_extends.php
@@ -99,7 +99,7 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh
private function compileEndChild(Smarty_Internal_TemplateCompilerBase $compiler)
{
$compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag($compiler->parser,
- "<?php \$_smarty_tpl->inheritance->endChild(\$_smarty_tpl);\n?>\n");
+ "<?php \$_smarty_tpl->inheritance->endChild();\n?>\n");
}
/**
diff --git a/libs/sysplugins/smarty_internal_resource_file.php b/libs/sysplugins/smarty_internal_resource_file.php
index 2901b87a..d763e449 100644
--- a/libs/sysplugins/smarty_internal_resource_file.php
+++ b/libs/sysplugins/smarty_internal_resource_file.php
@@ -43,13 +43,8 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
) {
throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'");
}
- $parentPath = $_template->parent->source->filepath;
- // if we are inside an {block} tag the path must be relative to template of {block}
- if (isset($_template->inheritance) && $path = $_template->inheritance->getBlockFilepath()) {
- $parentPath = $path;
- }
// normalize path
- $path = $source->smarty->_realpath(dirname($parentPath) . DS . $file);
+ $path = $source->smarty->_realpath(dirname($_template->parent->source->filepath) . DS . $file);
// files relative to a template only get one shot
return is_file($path) ? $path : false;
}
diff --git a/libs/sysplugins/smarty_internal_runtime_inheritance.php b/libs/sysplugins/smarty_internal_runtime_inheritance.php
index 66e81463..36e8ab35 100644
--- a/libs/sysplugins/smarty_internal_runtime_inheritance.php
+++ b/libs/sysplugins/smarty_internal_runtime_inheritance.php
@@ -53,11 +53,11 @@ class Smarty_Internal_Runtime_Inheritance
public $sources = array();
/**
- * Call stack of block objects
+ * Stack of source objects while executing block code
*
- * @var Smarty_Internal_Block[]
+ * @var Smarty_Template_Source[]
*/
- public $blockCallStack = array();
+ public $sourceStack = array();
/**
* Initialize inheritance
@@ -75,6 +75,9 @@ class Smarty_Internal_Runtime_Inheritance
$tpl->inheritance->init($tpl, $initChild, $blockNames);
return;
}
+ $this->tplIndex ++;
+ $this->sources[ $this->tplIndex ] = $tpl->source;
+
// start of child sub template(s)
if ($initChild) {
$this->state = 1;
@@ -83,13 +86,8 @@ class Smarty_Internal_Runtime_Inheritance
ob_start();
}
$this->inheritanceLevel ++;
- $tpl->startRenderCallbacks[ 'inheritance' ] = array($this, 'subTemplateStart');
- $tpl->endRenderCallbacks[ 'inheritance' ] = array($this, 'subTemplateEnd');
- }
- // in parent state {include} will not increment template index
- if ($this->state != 3) {
- $this->tplIndex ++;
- $this->sources[ $this->tplIndex ] = $tpl->source;
+ // $tpl->startRenderCallbacks[ 'inheritance' ] = array($this, 'subTemplateStart');
+ // $tpl->endRenderCallbacks[ 'inheritance' ] = array($this, 'subTemplateEnd');
}
// if state was waiting for parent change state to parent
if ($this->state == 2) {
@@ -101,9 +99,8 @@ class Smarty_Internal_Runtime_Inheritance
* End of child template(s)
* - if outer level is reached flush output buffer and switch to wait for parent template state
*
- * @param \Smarty_Internal_Template $tpl template object of caller
*/
- public function endChild(Smarty_Internal_Template $tpl)
+ public function endChild()
{
$this->inheritanceLevel --;
if (!$this->inheritanceLevel) {
@@ -162,10 +159,7 @@ class Smarty_Internal_Runtime_Inheritance
$this->callParent($tpl, $block);
}
if ($block->callsChild || !isset($block->child) || ($block->child->hide && !isset($block->child->child))) {
- $block->subTemplateNesting = 0;
- $this->blockCallStack[] = $block;
- $block->callBlock($tpl);
- array_pop($this->blockCallStack);
+ $this->callBlock($block, $tpl);
} else {
$this->process($tpl, $block->child, $block);
}
@@ -175,10 +169,7 @@ class Smarty_Internal_Runtime_Inheritance
if ($block->callsChild || !isset($block->child) ||
($block->child->hide && !isset($block->child->child))
) {
- $block->subTemplateNesting = 0;
- $this->blockCallStack[] = $block;
- $block->callBlock($tpl);
- array_pop($this->blockCallStack);
+ $this->callBlock($block, $tpl);
} else {
$this->process($tpl, $block->child, $block);
}
@@ -211,48 +202,21 @@ class Smarty_Internal_Runtime_Inheritance
public function callParent(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block)
{
if (isset($block->parent)) {
- $block->parent->subTemplateNesting = 0;
- $this->blockCallStack[] = $block->parent;
- $block->parent->callBlock($tpl);
- array_pop($this->blockCallStack);
+ $this->callBlock($block->parent, $tpl);
} else {
throw new SmartyException("inheritance: illegal {\$smarty.block.parent} or {block append/prepend} used in parent template '{$tpl->inheritance->sources[$block->tplIndex]->filepath}' block '{$block->name}'");
}
}
/**
- * Return source filepath of current {block} if not in sub-template
- *
- * @return bool|string filepath or false
- */
- public function getBlockFilepath()
- {
- $count = count($this->blockCallStack);
- if ($count && $this->blockCallStack[ $count - 1 ]->subTemplateNesting === 0) {
- return $this->sources[ $this->blockCallStack[ $count - 1 ]->tplIndex ]->filepath;
- }
- return false;
- }
-
- /**
- * Increment sub-template nesting count in current block object
- */
- public function subTemplateStart()
- {
- $count = count($this->blockCallStack);
- if ($count) {
- $this->blockCallStack[ $count - 1 ]->subTemplateNesting ++;
- }
- }
-
- /**
- * Decrement sub-template nesting count in current block object
+ * @param \Smarty_Internal_Block $block
+ * @param \Smarty_Internal_Template $tpl
*/
- public function subTemplateEnd()
+ public function callBlock(Smarty_Internal_Block $block, Smarty_Internal_Template $tpl)
{
- $count = count($this->blockCallStack);
- if ($count && $this->blockCallStack[ $count - 1 ]->subTemplateNesting) {
- $this->blockCallStack[ $count - 1 ]->subTemplateNesting --;
- }
+ $this->sourceStack[] = $tpl->source;
+ $tpl->source = $this->sources[ $block->tplIndex ];
+ $block->callBlock($tpl);
+ $tpl->source = array_pop($this->sourceStack);
}
}
diff --git a/libs/sysplugins/smarty_resource.php b/libs/sysplugins/smarty_resource.php
index a9253e12..0c9ba75f 100644
--- a/libs/sysplugins/smarty_resource.php
+++ b/libs/sysplugins/smarty_resource.php
@@ -218,12 +218,7 @@ abstract class Smarty_Resource
if ($obj->_objType == 2 && $_file_is_dotted &&
($obj->source->type == 'file' || $obj->parent->source->type == 'extends')
) {
- $parentPath = $obj->parent->source->filepath;
- // if we are inside an {block} tag the path must be relative to template of {block}
- if (isset($obj->inheritance) && $path = $obj->inheritance->getBlockFilepath()) {
- $parentPath = $path;
- }
- $name = $smarty->_realpath(dirname($parentPath) . DS . $name);
+ $name = $smarty->_realpath(dirname($obj->parent->source->filepath) . DS . $name);
}
return $resource->buildUniqueResourceName($smarty, $name);
}