mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 10:54:27 +02:00
- allow multiple template inheritance branches starting in subtemplates
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
08/09/2010
|
||||
- allow multiple template inheritance branches starting in subtemplates
|
||||
|
||||
07/09/2010
|
||||
- bugfix {counter} and {cycle} plugin assigned result to smarty variable not in local(template) scope
|
||||
- bugfix templates containing just {strip} {/strip} tags did produce an error
|
||||
|
@@ -223,9 +223,6 @@ class Smarty extends Smarty_Internal_Data {
|
||||
public $_dir_perms = 0771;
|
||||
// smarty object reference
|
||||
public $smarty = null;
|
||||
// block data at template inheritance
|
||||
public $block_data = array();
|
||||
public $block_data_stack = array();
|
||||
// block tag hierarchy
|
||||
public $_tag_stack = array();
|
||||
// plugins
|
||||
@@ -308,8 +305,6 @@ class Smarty extends Smarty_Internal_Data {
|
||||
// get default Smarty data object
|
||||
$parent = $this;
|
||||
}
|
||||
array_push($this->block_data_stack, $this->block_data);
|
||||
$this->block_data = array();
|
||||
// create template object if necessary
|
||||
($template instanceof $this->template_class)? $_template = $template :
|
||||
$_template = $this->createTemplate ($template, $cache_id, $compile_id, $parent);
|
||||
@@ -352,11 +347,9 @@ class Smarty extends Smarty_Internal_Data {
|
||||
if ($this->debugging) {
|
||||
Smarty_Internal_Debug::display_debug($this);
|
||||
}
|
||||
$this->block_data = array_pop($this->block_data_stack);
|
||||
return;
|
||||
} else {
|
||||
// return fetched content
|
||||
$this->block_data = array_pop($this->block_data_stack);
|
||||
return $_output;
|
||||
}
|
||||
}
|
||||
|
@@ -66,10 +66,10 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
|
||||
$this->compiler->trigger_template_error('mismatching name attributes "' . $saved_data[0]['name'] . '" and "' . $_attr['name'] . '"');
|
||||
}
|
||||
$_name = trim($saved_data[0]['name'], "\"'");
|
||||
if (isset($this->smarty->block_data[$_name])) {
|
||||
$_tpl = $this->smarty->createTemplate('string:' . $this->smarty->block_data[$_name]['source'], null, null, $compiler->template);
|
||||
if (isset($compiler->template->block_data[$_name])) {
|
||||
$_tpl = $this->smarty->createTemplate('string:' . $compiler->template->block_data[$_name]['source'], null, null, $compiler->template);
|
||||
$_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
|
||||
$_tpl->template_filepath = $this->smarty->block_data[$_name]['file'];
|
||||
$_tpl->template_filepath = $compiler->template->block_data[$_name]['file'];
|
||||
if ($compiler->nocache) {
|
||||
$_tpl->forceNocache = 2;
|
||||
} else {
|
||||
@@ -77,13 +77,13 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
|
||||
}
|
||||
$_tpl->suppressHeader = true;
|
||||
$_tpl->suppressFileDependency = true;
|
||||
if (strpos($this->smarty->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
|
||||
if (strpos($compiler->template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
|
||||
$_output = str_replace('%%%%SMARTY_PARENT%%%%', $compiler->parser->current_buffer->to_smarty_php(), $_tpl->getCompiledTemplate());
|
||||
} elseif ($this->smarty->block_data[$_name]['mode'] == 'prepend') {
|
||||
} elseif ($compiler->template->block_data[$_name]['mode'] == 'prepend') {
|
||||
$_output = $_tpl->getCompiledTemplate() . $compiler->parser->current_buffer->to_smarty_php();
|
||||
} elseif ($this->smarty->block_data[$_name]['mode'] == 'append') {
|
||||
} elseif ($compiler->template->block_data[$_name]['mode'] == 'append') {
|
||||
$_output = $compiler->parser->current_buffer->to_smarty_php() . $_tpl->getCompiledTemplate();
|
||||
} elseif (!empty($this->smarty->block_data[$_name])) {
|
||||
} elseif (!empty($compiler->template->block_data[$_name])) {
|
||||
$_output = $_tpl->getCompiledTemplate();
|
||||
}
|
||||
$compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $_tpl->properties['file_dependency']);
|
||||
|
@@ -79,35 +79,35 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase {
|
||||
$_name = trim($_match[3], '\'"');
|
||||
// replace {$smarty.block.child}
|
||||
if (strpos($block_content, $this->smarty->left_delimiter . '$smarty.block.child' . $this->smarty->right_delimiter) !== false) {
|
||||
if (isset($this->smarty->block_data[$_name])) {
|
||||
if (isset($template->block_data[$_name])) {
|
||||
$block_content = str_replace($this->smarty->left_delimiter . '$smarty.block.child' . $this->smarty->right_delimiter,
|
||||
$this->smarty->block_data[$_name]['source'], $block_content);
|
||||
unset($this->smarty->block_data[$_name]);
|
||||
$template->block_data[$_name]['source'], $block_content);
|
||||
unset($template->block_data[$_name]);
|
||||
} else {
|
||||
$block_content = str_replace($this->smarty->left_delimiter . '$smarty.block.child' . $this->smarty->right_delimiter,
|
||||
'', $block_content);
|
||||
}
|
||||
}
|
||||
if (isset($this->smarty->block_data[$_name])) {
|
||||
if (strpos($this->smarty->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
|
||||
$this->smarty->block_data[$_name]['source'] =
|
||||
str_replace('%%%%SMARTY_PARENT%%%%', $block_content, $this->smarty->block_data[$_name]['source']);
|
||||
} elseif ($this->smarty->block_data[$_name]['mode'] == 'prepend') {
|
||||
$this->smarty->block_data[$_name]['source'] .= $block_content;
|
||||
} elseif ($this->smarty->block_data[$_name]['mode'] == 'append') {
|
||||
$this->smarty->block_data[$_name]['source'] = $block_content . $this->smarty->block_data[$_name]['source'];
|
||||
if (isset($template->block_data[$_name])) {
|
||||
if (strpos($template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
|
||||
$template->block_data[$_name]['source'] =
|
||||
str_replace('%%%%SMARTY_PARENT%%%%', $block_content, $template->block_data[$_name]['source']);
|
||||
} elseif ($template->block_data[$_name]['mode'] == 'prepend') {
|
||||
$template->block_data[$_name]['source'] .= $block_content;
|
||||
} elseif ($template->block_data[$_name]['mode'] == 'append') {
|
||||
$template->block_data[$_name]['source'] = $block_content . $template->block_data[$_name]['source'];
|
||||
}
|
||||
} else {
|
||||
$this->smarty->block_data[$_name]['source'] = $block_content;
|
||||
$template->block_data[$_name]['source'] = $block_content;
|
||||
}
|
||||
if (preg_match('/(.?)(append)(.*)/', $block_tag, $_match) != 0) {
|
||||
$this->smarty->block_data[$_name]['mode'] = 'append';
|
||||
$template->block_data[$_name]['mode'] = 'append';
|
||||
} elseif (preg_match('/(.?)(prepend)(.*)/', $block_tag, $_match) != 0) {
|
||||
$this->smarty->block_data[$_name]['mode'] = 'prepend';
|
||||
$template->block_data[$_name]['mode'] = 'prepend';
|
||||
} else {
|
||||
$this->smarty->block_data[$_name]['mode'] = 'replace';
|
||||
$template->block_data[$_name]['mode'] = 'replace';
|
||||
}
|
||||
$this->smarty->block_data[$_name]['file'] = $template->getTemplateFilepath();
|
||||
$template->block_data[$_name]['file'] = $template->getTemplateFilepath();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -119,7 +119,7 @@ class Smarty_Internal_Resource_Extends {
|
||||
}
|
||||
$_block_content = str_replace($this->smarty->left_delimiter . '$smarty.block.parent' . $this->smarty->right_delimiter, '%%%%SMARTY_PARENT%%%%',
|
||||
substr($_content, $_result[0][$_start][1] + strlen($_result[0][$_start][0]), $_result[0][$_start + $_end][1] - $_result[0][$_start][1] - + strlen($_result[0][$_start][0])));
|
||||
$this->saveBlockData($_block_content, $_result[0][$_start][0], $_filepath);
|
||||
$this->saveBlockData($_block_content, $_result[0][$_start][0], $_filepath, $_template);
|
||||
$_start = $_start + $_end + 1;
|
||||
}
|
||||
} else {
|
||||
@@ -133,7 +133,7 @@ class Smarty_Internal_Resource_Extends {
|
||||
/**
|
||||
* saveBlockData
|
||||
*/
|
||||
protected function saveBlockData($block_content, $block_tag, $_filepath)
|
||||
protected function saveBlockData($block_content, $block_tag, $_filepath, $_template)
|
||||
{
|
||||
if (0 == preg_match("!(.?)(name=)(.*?)(?=(\s|{$this->_rdl}))!", $block_tag, $_match)) {
|
||||
$this->smarty->trigger_error("'{$block_tag}' missing name attribute in file '$_filepath'");
|
||||
@@ -141,35 +141,35 @@ class Smarty_Internal_Resource_Extends {
|
||||
$_name = trim($_match[3], '\'"');
|
||||
// replace {$smarty.block.child}
|
||||
if (strpos($block_content, $this->smarty->left_delimiter . '$smarty.block.child' . $this->smarty->right_delimiter) !== false) {
|
||||
if (isset($this->smarty->block_data[$_name])) {
|
||||
if (isset($_template->block_data[$_name])) {
|
||||
$block_content = str_replace($this->smarty->left_delimiter . '$smarty.block.child' . $this->smarty->right_delimiter,
|
||||
$this->smarty->block_data[$_name]['source'], $block_content);
|
||||
unset($this->smarty->block_data[$_name]);
|
||||
$_template->block_data[$_name]['source'], $block_content);
|
||||
unset($_template->block_data[$_name]);
|
||||
} else {
|
||||
$block_content = str_replace($this->smarty->left_delimiter . '$smarty.block.child' . $this->smarty->right_delimiter,
|
||||
'', $block_content);
|
||||
}
|
||||
}
|
||||
if (isset($this->smarty->block_data[$_name])) {
|
||||
if (strpos($this->smarty->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
|
||||
$this->smarty->block_data[$_name]['source'] =
|
||||
str_replace('%%%%SMARTY_PARENT%%%%', $block_content, $this->smarty->block_data[$_name]['source']);
|
||||
} elseif ($this->smarty->block_data[$_name]['mode'] == 'prepend') {
|
||||
$this->smarty->block_data[$_name]['source'] .= $block_content;
|
||||
} elseif ($this->smarty->block_data[$_name]['mode'] == 'append') {
|
||||
$this->smarty->block_data[$_name]['source'] = $block_content . $this->smarty->block_data[$_name]['source'];
|
||||
if (isset($_template->block_data[$_name])) {
|
||||
if (strpos($_template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
|
||||
$_template->block_data[$_name]['source'] =
|
||||
str_replace('%%%%SMARTY_PARENT%%%%', $block_content, $_template->block_data[$_name]['source']);
|
||||
} elseif ($_template->block_data[$_name]['mode'] == 'prepend') {
|
||||
$_template->block_data[$_name]['source'] .= $block_content;
|
||||
} elseif ($_template->block_data[$_name]['mode'] == 'append') {
|
||||
$_template->block_data[$_name]['source'] = $block_content . $_template->block_data[$_name]['source'];
|
||||
}
|
||||
} else {
|
||||
$this->smarty->block_data[$_name]['source'] = $block_content;
|
||||
$_template->block_data[$_name]['source'] = $block_content;
|
||||
}
|
||||
if (preg_match('/(.?)(append)(.*)/', $block_tag, $_match) != 0) {
|
||||
$this->smarty->block_data[$_name]['mode'] = 'append';
|
||||
$_template->block_data[$_name]['mode'] = 'append';
|
||||
} elseif (preg_match('/(.?)(prepend)(.*)/', $block_tag, $_match) != 0) {
|
||||
$this->smarty->block_data[$_name]['mode'] = 'prepend';
|
||||
$_template->block_data[$_name]['mode'] = 'prepend';
|
||||
} else {
|
||||
$this->smarty->block_data[$_name]['mode'] = 'replace';
|
||||
$_template->block_data[$_name]['mode'] = 'replace';
|
||||
}
|
||||
$this->smarty->block_data[$_name]['file'] = $_filepath;
|
||||
$_template->block_data[$_name]['file'] = $_filepath;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -68,6 +68,8 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
public $security = false;
|
||||
public $saved_modifier = null;
|
||||
public $smarty = null;
|
||||
// blocks for template inheritance
|
||||
public $block_data = array();
|
||||
/**
|
||||
* Create template data object
|
||||
*
|
||||
|
Reference in New Issue
Block a user