mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
- bugfix multiple {include} with relative filepath within {block}{/block} could fail https://github.com/smarty-php/smarty/issues/246
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
===== 3.1.30-dev ===== (xx.xx.xx)
|
===== 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
|
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 {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
|
- bugfix modifier on plugins like {plugin|modifier ... } did fail when the plugin does return an array https://github.com/smarty-php/smarty/issues/228
|
||||||
|
@@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* smarty version
|
* smarty version
|
||||||
*/
|
*/
|
||||||
const SMARTY_VERSION = '3.1.30-dev/84';
|
const SMARTY_VERSION = '3.1.30-dev/85';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* define variable scopes
|
* define variable scopes
|
||||||
|
@@ -65,13 +65,6 @@ class Smarty_Internal_Block
|
|||||||
*/
|
*/
|
||||||
public $tplIndex = 0;
|
public $tplIndex = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* Nesting level of called sub-templates
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $subTemplateNesting = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty_Internal_Block constructor.
|
* Smarty_Internal_Block constructor.
|
||||||
* - if outer level {block} of child template ($state == 1) save it as child root block
|
* - if outer level {block} of child template ($state == 1) save it as child root block
|
||||||
|
@@ -99,7 +99,7 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh
|
|||||||
private function compileEndChild(Smarty_Internal_TemplateCompilerBase $compiler)
|
private function compileEndChild(Smarty_Internal_TemplateCompilerBase $compiler)
|
||||||
{
|
{
|
||||||
$compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag($compiler->parser,
|
$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");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -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}'");
|
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
|
// 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
|
// files relative to a template only get one shot
|
||||||
return is_file($path) ? $path : false;
|
return is_file($path) ? $path : false;
|
||||||
}
|
}
|
||||||
|
@@ -53,11 +53,11 @@ class Smarty_Internal_Runtime_Inheritance
|
|||||||
public $sources = array();
|
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
|
* Initialize inheritance
|
||||||
@@ -75,6 +75,9 @@ class Smarty_Internal_Runtime_Inheritance
|
|||||||
$tpl->inheritance->init($tpl, $initChild, $blockNames);
|
$tpl->inheritance->init($tpl, $initChild, $blockNames);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
$this->tplIndex ++;
|
||||||
|
$this->sources[ $this->tplIndex ] = $tpl->source;
|
||||||
|
|
||||||
// start of child sub template(s)
|
// start of child sub template(s)
|
||||||
if ($initChild) {
|
if ($initChild) {
|
||||||
$this->state = 1;
|
$this->state = 1;
|
||||||
@@ -83,13 +86,8 @@ class Smarty_Internal_Runtime_Inheritance
|
|||||||
ob_start();
|
ob_start();
|
||||||
}
|
}
|
||||||
$this->inheritanceLevel ++;
|
$this->inheritanceLevel ++;
|
||||||
$tpl->startRenderCallbacks[ 'inheritance' ] = array($this, 'subTemplateStart');
|
// $tpl->startRenderCallbacks[ 'inheritance' ] = array($this, 'subTemplateStart');
|
||||||
$tpl->endRenderCallbacks[ 'inheritance' ] = array($this, 'subTemplateEnd');
|
// $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;
|
|
||||||
}
|
}
|
||||||
// if state was waiting for parent change state to parent
|
// if state was waiting for parent change state to parent
|
||||||
if ($this->state == 2) {
|
if ($this->state == 2) {
|
||||||
@@ -101,9 +99,8 @@ class Smarty_Internal_Runtime_Inheritance
|
|||||||
* End of child template(s)
|
* End of child template(s)
|
||||||
* - if outer level is reached flush output buffer and switch to wait for parent template state
|
* - 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 --;
|
$this->inheritanceLevel --;
|
||||||
if (!$this->inheritanceLevel) {
|
if (!$this->inheritanceLevel) {
|
||||||
@@ -162,10 +159,7 @@ class Smarty_Internal_Runtime_Inheritance
|
|||||||
$this->callParent($tpl, $block);
|
$this->callParent($tpl, $block);
|
||||||
}
|
}
|
||||||
if ($block->callsChild || !isset($block->child) || ($block->child->hide && !isset($block->child->child))) {
|
if ($block->callsChild || !isset($block->child) || ($block->child->hide && !isset($block->child->child))) {
|
||||||
$block->subTemplateNesting = 0;
|
$this->callBlock($block, $tpl);
|
||||||
$this->blockCallStack[] = $block;
|
|
||||||
$block->callBlock($tpl);
|
|
||||||
array_pop($this->blockCallStack);
|
|
||||||
} else {
|
} else {
|
||||||
$this->process($tpl, $block->child, $block);
|
$this->process($tpl, $block->child, $block);
|
||||||
}
|
}
|
||||||
@@ -175,10 +169,7 @@ class Smarty_Internal_Runtime_Inheritance
|
|||||||
if ($block->callsChild || !isset($block->child) ||
|
if ($block->callsChild || !isset($block->child) ||
|
||||||
($block->child->hide && !isset($block->child->child))
|
($block->child->hide && !isset($block->child->child))
|
||||||
) {
|
) {
|
||||||
$block->subTemplateNesting = 0;
|
$this->callBlock($block, $tpl);
|
||||||
$this->blockCallStack[] = $block;
|
|
||||||
$block->callBlock($tpl);
|
|
||||||
array_pop($this->blockCallStack);
|
|
||||||
} else {
|
} else {
|
||||||
$this->process($tpl, $block->child, $block);
|
$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)
|
public function callParent(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block)
|
||||||
{
|
{
|
||||||
if (isset($block->parent)) {
|
if (isset($block->parent)) {
|
||||||
$block->parent->subTemplateNesting = 0;
|
$this->callBlock($block->parent, $tpl);
|
||||||
$this->blockCallStack[] = $block->parent;
|
|
||||||
$block->parent->callBlock($tpl);
|
|
||||||
array_pop($this->blockCallStack);
|
|
||||||
} else {
|
} 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}'");
|
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
|
* @param \Smarty_Internal_Block $block
|
||||||
*
|
* @param \Smarty_Internal_Template $tpl
|
||||||
* @return bool|string filepath or false
|
|
||||||
*/
|
*/
|
||||||
public function getBlockFilepath()
|
public function callBlock(Smarty_Internal_Block $block, Smarty_Internal_Template $tpl)
|
||||||
{
|
{
|
||||||
$count = count($this->blockCallStack);
|
$this->sourceStack[] = $tpl->source;
|
||||||
if ($count && $this->blockCallStack[ $count - 1 ]->subTemplateNesting === 0) {
|
$tpl->source = $this->sources[ $block->tplIndex ];
|
||||||
return $this->sources[ $this->blockCallStack[ $count - 1 ]->tplIndex ]->filepath;
|
$block->callBlock($tpl);
|
||||||
}
|
$tpl->source = array_pop($this->sourceStack);
|
||||||
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
|
|
||||||
*/
|
|
||||||
public function subTemplateEnd()
|
|
||||||
{
|
|
||||||
$count = count($this->blockCallStack);
|
|
||||||
if ($count && $this->blockCallStack[ $count - 1 ]->subTemplateNesting) {
|
|
||||||
$this->blockCallStack[ $count - 1 ]->subTemplateNesting --;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -218,12 +218,7 @@ abstract class Smarty_Resource
|
|||||||
if ($obj->_objType == 2 && $_file_is_dotted &&
|
if ($obj->_objType == 2 && $_file_is_dotted &&
|
||||||
($obj->source->type == 'file' || $obj->parent->source->type == 'extends')
|
($obj->source->type == 'file' || $obj->parent->source->type == 'extends')
|
||||||
) {
|
) {
|
||||||
$parentPath = $obj->parent->source->filepath;
|
$name = $smarty->_realpath(dirname($obj->parent->source->filepath) . DS . $name);
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
return $resource->buildUniqueResourceName($smarty, $name);
|
return $resource->buildUniqueResourceName($smarty, $name);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user