mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 10:54:27 +02:00
- bugfix template inheritance nesting problem (forum topic 24387)
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
===== trunk =====
|
===== trunk =====
|
||||||
|
26.07.2013
|
||||||
|
- bugfix template inheritance nesting problem (forum topic 24387)
|
||||||
|
|
||||||
15.7.2013
|
15.7.2013
|
||||||
- update code generated by PSR-2 standards fixer which introduced PHP 5.4 incompatibilities of 14.7.2013
|
- update code generated by PSR-2 standards fixer which introduced PHP 5.4 incompatibilities of 14.7.2013
|
||||||
|
|
||||||
|
@@ -1,138 +1,160 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
|
||||||
* Smarty Internal Plugin Compile Block
|
|
||||||
*
|
|
||||||
* Compiles the {block}{/block} tags
|
|
||||||
*
|
|
||||||
* @package Smarty
|
|
||||||
* @subpackage Compiler
|
|
||||||
* @author Uwe Tews
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Smarty Internal Plugin Compile Block Class
|
|
||||||
*
|
|
||||||
* @package Smarty
|
|
||||||
* @subpackage Compiler
|
|
||||||
*/
|
|
||||||
class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
|
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Attribute definition: Overwrites base class.
|
* Smarty Internal Plugin Compile Block
|
||||||
*
|
*
|
||||||
* @var array
|
* Compiles the {block}{/block} tags
|
||||||
* @see Smarty_Internal_CompileBase
|
*
|
||||||
*/
|
* @package Smarty
|
||||||
public $required_attributes = array('name');
|
* @subpackage Compiler
|
||||||
|
* @author Uwe Tews
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attribute definition: Overwrites base class.
|
* Smarty Internal Plugin Compile Block Class
|
||||||
*
|
*
|
||||||
* @var array
|
* @package Smarty
|
||||||
* @see Smarty_Internal_CompileBase
|
* @subpackage Compiler
|
||||||
*/
|
*/
|
||||||
public $shorttag_order = array('name', 'hide');
|
class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
|
||||||
|
|
||||||
/**
|
|
||||||
* Attribute definition: Overwrites base class.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
* @see Smarty_Internal_CompileBase
|
|
||||||
*/
|
|
||||||
public $optional_attributes = array('hide');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compiles code for the {block} tag
|
|
||||||
*
|
|
||||||
* @param array $args array with attributes from parser
|
|
||||||
* @param object $compiler compiler object
|
|
||||||
* @return boolean true
|
|
||||||
*/
|
|
||||||
public function compile($args, $compiler)
|
|
||||||
{
|
{
|
||||||
// check and get attributes
|
/**
|
||||||
$_attr = $this->getAttributes($compiler, $args);
|
* Attribute definition: Overwrites base class.
|
||||||
$save = array($_attr, $compiler->parser->current_buffer, $compiler->nocache, $compiler->smarty->merge_compiled_includes, $compiler->merged_templates, $compiler->smarty->merged_templates_func, $compiler->template->properties, $compiler->template->has_nocache_code);
|
*
|
||||||
$this->openTag($compiler, 'block', $save);
|
* @var array
|
||||||
if ($_attr['nocache'] == true) {
|
* @see Smarty_Internal_CompileBase
|
||||||
$compiler->nocache = true;
|
*/
|
||||||
|
public $required_attributes = array('name');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attribute definition: Overwrites base class.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @see Smarty_Internal_CompileBase
|
||||||
|
*/
|
||||||
|
public $shorttag_order = array('name', 'hide');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attribute definition: Overwrites base class.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @see Smarty_Internal_CompileBase
|
||||||
|
*/
|
||||||
|
public $optional_attributes = array('hide');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compiles code for the {block} tag
|
||||||
|
*
|
||||||
|
* @param array $args array with attributes from parser
|
||||||
|
* @param object $compiler compiler object
|
||||||
|
* @return boolean true
|
||||||
|
*/
|
||||||
|
public function compile($args, $compiler)
|
||||||
|
{
|
||||||
|
// check and get attributes
|
||||||
|
$_attr = $this->getAttributes($compiler, $args);
|
||||||
|
$save = array($_attr, $compiler->parser->current_buffer, $compiler->nocache, $compiler->smarty->merge_compiled_includes, $compiler->merged_templates, $compiler->smarty->merged_templates_func, $compiler->template->properties, $compiler->template->has_nocache_code);
|
||||||
|
$this->openTag($compiler, 'block', $save);
|
||||||
|
if ($_attr['nocache'] == true) {
|
||||||
|
$compiler->nocache = true;
|
||||||
|
}
|
||||||
|
// set flag for {block} tag
|
||||||
|
$compiler->inheritance = true;
|
||||||
|
// must merge includes
|
||||||
|
$compiler->smarty->merge_compiled_includes = true;
|
||||||
|
|
||||||
|
$compiler->parser->current_buffer = new _smarty_template_buffer($compiler->parser);
|
||||||
|
$compiler->has_code = false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
// set flag for {block} tag
|
|
||||||
$compiler->inheritance = true;
|
|
||||||
// must merge includes
|
|
||||||
$compiler->smarty->merge_compiled_includes = true;
|
|
||||||
|
|
||||||
$compiler->parser->current_buffer = new _smarty_template_buffer($compiler->parser);
|
/**
|
||||||
$compiler->has_code = false;
|
* Save or replace child block source by block name during parsing
|
||||||
|
*
|
||||||
return true;
|
* @param string $block_content block source content
|
||||||
}
|
* @param string $block_tag opening block tag
|
||||||
|
* @param object $template template object
|
||||||
/**
|
* @param string $filepath filepath of template source
|
||||||
* Save or replace child block source by block name during parsing
|
*/
|
||||||
*
|
static function saveBlockData($block_content, $block_tag, $template, $filepath)
|
||||||
* @param string $block_content block source content
|
{
|
||||||
* @param string $block_tag opening block tag
|
$nesting = array();
|
||||||
* @param object $template template object
|
$hide_level = 0;
|
||||||
* @param string $filepath filepath of template source
|
$child_flag = false;
|
||||||
*/
|
$_rdl = preg_quote($template->smarty->right_delimiter);
|
||||||
static function saveBlockData($block_content, $block_tag, $template, $filepath)
|
$_ldl = preg_quote($template->smarty->left_delimiter);
|
||||||
{
|
if (!$template->smarty->auto_literal) {
|
||||||
$_rdl = preg_quote($template->smarty->right_delimiter);
|
$al = '\s*';
|
||||||
$_ldl = preg_quote($template->smarty->left_delimiter);
|
} else {
|
||||||
if (!$template->smarty->auto_literal) {
|
$al = '';
|
||||||
$al = '\s*';
|
}
|
||||||
} else {
|
if (0 == preg_match("!({$_ldl}{$al}block\s+)(name=)?(\w+|'.*'|\".*\")(\s*?)?((append|prepend|nocache)?(\s*)?(hide)?)?(\s*{$_rdl})!", $block_tag, $_match)) {
|
||||||
$al = '';
|
$error_text = 'Syntax Error in template "' . $template->source->filepath . '" "' . $block_tag . '" illegal options';
|
||||||
}
|
throw new SmartyCompilerException($error_text);
|
||||||
if (0 == preg_match("!({$_ldl}{$al}block\s+)(name=)?(\w+|'.*'|\".*\")(\s*?)?((append|prepend|nocache)?(\s*)?(hide)?)?(\s*{$_rdl})!", $block_tag, $_match)) {
|
} else {
|
||||||
$error_text = 'Syntax Error in template "' . $template->source->filepath . '" "' . $block_tag . '" illegal options';
|
$_name = trim($_match[3], '\'"');
|
||||||
throw new SmartyCompilerException($error_text);
|
// replace {$smarty.block.child}
|
||||||
} else {
|
|
||||||
$_name = trim($_match[3], '\'"');
|
|
||||||
if ($_match[8] != 'hide' || isset($template->block_data[$_name])) { // replace {$smarty.block.child}
|
|
||||||
// get nested block tags
|
// get nested block tags
|
||||||
if (0 != preg_match_all("!({$_ldl}{$al}block\s+)(name=)?(\w+|'.*'|\".*\")([\s\S]*?)(hide)?(\s*{$_rdl})([\s\S]*?)(.*)?({$_ldl}{$al}/block\s*{$_rdl})!", $block_content, $_match2)) {
|
preg_match_all("%({$_ldl}{$al}block\s+)(name=)?(\w+|'.*?'|\".*?\")([\s\S]*?)(hide)?(\s*{$_rdl})|({$_ldl}{$al}/block\s*{$_rdl})|({$_ldl}{$al}\\\$smarty\.block\.child\s*{$_rdl})|({$_ldl}|{$_rdl})|([\s\S]*?(?=({$_ldl}|{$_rdl})))%", $block_tag.$block_content."{$template->smarty->left_delimiter}/block{$template->smarty->right_delimiter}", $_match2);
|
||||||
foreach ($_match2[3] as $key => $name) {
|
$block_content = '';
|
||||||
// get it's replacement
|
foreach ($_match2[0] as $key => $text) {
|
||||||
$_name2 = trim($name, '\'"');
|
// {block} tag
|
||||||
if ($_match2[5][$key] != 'hide' || isset($template->block_data[$_name2])) {
|
if (!empty($_match2[3][$key])) {
|
||||||
if (isset($template->block_data[$_name2])) {
|
$name = trim($_match2[3][$key], '\'"');
|
||||||
$replacement = $template->block_data[$_name2]['source'];
|
array_push($nesting, array($name, $block_content, $child_flag));
|
||||||
} else {
|
$block_content = '';
|
||||||
$replacement = '';
|
// hide option
|
||||||
}
|
if (!empty($_match2[5][$key]) && $hide_level == 0 && !isset($template->block_data[$name])) {
|
||||||
// replace {$smarty.block.child} tag
|
$hide_level = count($nesting);
|
||||||
if (preg_match("!{$_ldl}{$al}\\\$smarty\.block\.child\s*{$_rdl}!",$_match2[7][$key])) {
|
|
||||||
$replacement = preg_replace("!({$_ldl}{$al}\\\$smarty\.block\.child\s*{$_rdl})!", $replacement, $_match2[7][$key]);
|
|
||||||
$block_content = preg_replace("!(({$_ldl}{$al}block)(.*)?{$name}(.*)?({$_rdl}[\s\S]*?{$_ldl}{$al}/block\s*{$_rdl}))!", $replacement, $block_content);
|
|
||||||
}
|
|
||||||
if (preg_match("!{$_ldl}{$al}\\\$smarty\.block\.child\s*{$_rdl}!",$_match2[8][$key])) {
|
|
||||||
$replacement = preg_replace("!{$_ldl}{$al}\\\$smarty\.block\.child\s*{$_rdl}!", $replacement, $_match2[8][$key]);
|
|
||||||
$block_content = preg_replace("!(({$_ldl}{$al}block)(.*)?{$name}(.*)?({$_rdl})(.*)?({$_ldl}{$al}/block\s*{$_rdl}))!", $replacement, $block_content);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// remove hidden blocks
|
|
||||||
$block_content = preg_replace("!(({$_ldl}{$al}block)(.*)?{$name}(.*)?({$_rdl}[\s\S]*?{$_ldl}{$al}/block\s*{$_rdl}))!", '', $block_content);
|
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
// {/block} tag
|
||||||
// do we have not nested {$smart.block.child}
|
if (!empty($_match2[7][$key])) {
|
||||||
if (0 != preg_match("!({$_ldl}{$al}\\\$smarty\.block\.child\s*{$_rdl})!", $block_content, $_match2)) {
|
list($name, $content, $cf) = array_pop($nesting);
|
||||||
// get child replacement for this block
|
if (isset($template->block_data[$name]) && !$child_flag) {
|
||||||
if (isset($template->block_data[$_name])) {
|
if ($template->block_data[$name]['mode'] == 'prepend') {
|
||||||
$replacement = $template->block_data[$_name]['source'];
|
$block_content = $content . $template->block_data[$name]['source'] . $block_content;
|
||||||
unset($template->block_data[$_name]);
|
} elseif ($template->block_data[$name]['mode'] == 'append') {
|
||||||
} else {
|
$block_content = $content . $block_content . $template->block_data[$name]['source'];
|
||||||
$replacement = '';
|
} else {
|
||||||
|
// check if {$smarty.block.parent} will be later replaced
|
||||||
|
if (strpos($template->block_data[$name]['source'], '%%%%SMARTY_PARENT%%%%') === false) {
|
||||||
|
$block_content = $content . $template->block_data[$name]['source'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$block_content = $content . $block_content;
|
||||||
|
$cf = true;
|
||||||
|
}
|
||||||
|
$child_flag = $cf;
|
||||||
|
if (count($nesting) < $hide_level) {
|
||||||
|
$hide_level = 0;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
$block_content = preg_replace("!({$_ldl}{$al}\\\$smarty\.block\.child\s*{$_rdl})!", $replacement, $block_content);
|
// hide option active
|
||||||
|
if ($hide_level && $hide_level <= count($nesting)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// {$smarty.block.child} tag
|
||||||
|
if (!empty($_match2[8][$key])) {
|
||||||
|
list($name, $content, $cf) = end($nesting);
|
||||||
|
if (isset($template->block_data[$name])) {
|
||||||
|
$child_flag = true;
|
||||||
|
$block_content .= $template->block_data[$name]['source'];
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$block_content .= $_match2[0][$key];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// $block_content = preg_replace_callback("%({$_ldl}{$al}block\s+)(name=)?(\w+|'.*?'|\".*?\")([\s\S]*?)(hide)?(\s*{$_rdl})|({$_ldl}{$al}/block\s*{$_rdl})|({$_ldl}{$al}\\\$smarty\.block\.child\s*{$_rdl})|({$_ldl}|{$_rdl})|([\s\S]*?(?=({$_ldl}|{$_rdl})))%", array('Smarty_Internal_Compile_Block', 'replaceBlockChild'), $block_tag.$block_content."{$template->smarty->left_delimiter}/block{$template->smarty->right_delimiter}");
|
||||||
if (isset($template->block_data[$_name])) {
|
if (isset($template->block_data[$_name])) {
|
||||||
if (strpos($template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
|
if (strpos($template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
|
||||||
$template->block_data[$_name]['source'] =
|
$template->block_data[$_name]['source'] =
|
||||||
str_replace('%%%%SMARTY_PARENT%%%%', $block_content, $template->block_data[$_name]['source']);
|
str_replace('%%%%SMARTY_PARENT%%%%', $block_content, $template->block_data[$_name]['source']);
|
||||||
} elseif ($template->block_data[$_name]['mode'] == 'prepend') {
|
} elseif ($template->block_data[$_name]['mode'] == 'prepend') {
|
||||||
$template->block_data[$_name]['source'] .= $block_content;
|
$template->block_data[$_name]['source'] .= $block_content;
|
||||||
} elseif ($template->block_data[$_name]['mode'] == 'append') {
|
} elseif ($template->block_data[$_name]['mode'] == 'append') {
|
||||||
@@ -142,6 +164,10 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
|
|||||||
$template->block_data[$_name]['source'] = $block_content;
|
$template->block_data[$_name]['source'] = $block_content;
|
||||||
$template->block_data[$_name]['file'] = $filepath;
|
$template->block_data[$_name]['file'] = $filepath;
|
||||||
}
|
}
|
||||||
|
if ($child_flag) {
|
||||||
|
$template->block_data[$_name]['source'] = $block_content;
|
||||||
|
$template->block_data[$_name]['file'] = $filepath;
|
||||||
|
}
|
||||||
if ($_match[6] == 'append') {
|
if ($_match[6] == 'append') {
|
||||||
$template->block_data[$_name]['mode'] = 'append';
|
$template->block_data[$_name]['mode'] = 'append';
|
||||||
} elseif ($_match[6] == 'prepend') {
|
} elseif ($_match[6] == 'prepend') {
|
||||||
@@ -151,138 +177,137 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compile saved child block source
|
||||||
|
*
|
||||||
|
* @param object $compiler compiler object
|
||||||
|
* @param string $_name optional name of child block
|
||||||
|
* @return string compiled code of schild block
|
||||||
|
*/
|
||||||
|
static function compileChildBlock($compiler, $_name = null)
|
||||||
|
{
|
||||||
|
$_output = '';
|
||||||
|
// if called by {$smarty.block.child} we must search the name of enclosing {block}
|
||||||
|
if ($_name == null) {
|
||||||
|
$stack_count = count($compiler->_tag_stack);
|
||||||
|
while (--$stack_count >= 0) {
|
||||||
|
if ($compiler->_tag_stack[$stack_count][0] == 'block') {
|
||||||
|
$_name = trim($compiler->_tag_stack[$stack_count][1][0]['name'], "'\"");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// flag that child is already compile by {$smarty.block.child} inclusion
|
||||||
|
$compiler->template->block_data[$_name]['compiled'] = true;
|
||||||
|
}
|
||||||
|
if ($_name == null) {
|
||||||
|
$compiler->trigger_template_error('{$smarty.block.child} used out of context', $compiler->lex->taglineno);
|
||||||
|
}
|
||||||
|
// undefined child?
|
||||||
|
if (!isset($compiler->template->block_data[$_name]['source'])) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
$_tpl = new Smarty_Internal_template('string:' . $compiler->template->block_data[$_name]['source'], $compiler->smarty, $compiler->template, $compiler->template->cache_id,
|
||||||
|
$compiler->template->compile_id, $compiler->template->caching, $compiler->template->cache_lifetime);
|
||||||
|
$_tpl->variable_filters = $compiler->template->variable_filters;
|
||||||
|
$_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
|
||||||
|
$_tpl->source->filepath = $compiler->template->block_data[$_name]['file'];
|
||||||
|
$_tpl->allow_relative_path = true;
|
||||||
|
if ($compiler->nocache) {
|
||||||
|
$_tpl->compiler->forceNocache = 2;
|
||||||
|
} else {
|
||||||
|
$_tpl->compiler->forceNocache = 1;
|
||||||
|
}
|
||||||
|
$_tpl->compiler->suppressHeader = true;
|
||||||
|
$_tpl->compiler->suppressFilter = true;
|
||||||
|
$_tpl->compiler->suppressTemplatePropertyHeader = true;
|
||||||
|
$_tpl->compiler->suppressMergedTemplates = true;
|
||||||
|
if (strpos($compiler->template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
|
||||||
|
$_output = str_replace('%%%%SMARTY_PARENT%%%%', $compiler->parser->current_buffer->to_smarty_php(), $_tpl->compiler->compileTemplate($_tpl));
|
||||||
|
} elseif ($compiler->template->block_data[$_name]['mode'] == 'prepend') {
|
||||||
|
$_output = $_tpl->compiler->compileTemplate($_tpl) . $compiler->parser->current_buffer->to_smarty_php();
|
||||||
|
} elseif ($compiler->template->block_data[$_name]['mode'] == 'append') {
|
||||||
|
$_output = $compiler->parser->current_buffer->to_smarty_php() . $_tpl->compiler->compileTemplate($_tpl);
|
||||||
|
} elseif (!empty($compiler->template->block_data[$_name])) {
|
||||||
|
$_output = $_tpl->compiler->compileTemplate($_tpl);
|
||||||
|
}
|
||||||
|
$compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $_tpl->properties['file_dependency']);
|
||||||
|
$compiler->template->properties['function'] = array_merge($compiler->template->properties['function'], $_tpl->properties['function']);
|
||||||
|
$compiler->merged_templates = array_merge($compiler->merged_templates, $_tpl->compiler->merged_templates);
|
||||||
|
$compiler->template->variable_filters = $_tpl->variable_filters;
|
||||||
|
if ($_tpl->has_nocache_code) {
|
||||||
|
$compiler->template->has_nocache_code = true;
|
||||||
|
}
|
||||||
|
foreach ($_tpl->required_plugins as $key => $tmp1) {
|
||||||
|
if ($compiler->nocache && $compiler->template->caching) {
|
||||||
|
$code = 'nocache';
|
||||||
|
} else {
|
||||||
|
$code = $key;
|
||||||
|
}
|
||||||
|
foreach ($tmp1 as $name => $tmp) {
|
||||||
|
foreach ($tmp as $type => $data) {
|
||||||
|
$compiler->template->required_plugins[$code][$name][$type] = $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset($_tpl);
|
||||||
|
|
||||||
|
return $_output;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compile saved child block source
|
* Smarty Internal Plugin Compile BlockClose Class
|
||||||
*
|
*
|
||||||
* @param object $compiler compiler object
|
* @package Smarty
|
||||||
* @param string $_name optional name of child block
|
* @subpackage Compiler
|
||||||
* @return string compiled code of schild block
|
*/
|
||||||
*/
|
class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase
|
||||||
public static function compileChildBlock($compiler, $_name = null)
|
|
||||||
{
|
{
|
||||||
$_output = '';
|
/**
|
||||||
// if called by {$smarty.block.child} we must search the name of enclosing {block}
|
* Compiles code for the {/block} tag
|
||||||
if ($_name == null) {
|
*
|
||||||
$stack_count = count($compiler->_tag_stack);
|
* @param array $args array with attributes from parser
|
||||||
while (--$stack_count >= 0) {
|
* @param object $compiler compiler object
|
||||||
if ($compiler->_tag_stack[$stack_count][0] == 'block') {
|
* @return string compiled code
|
||||||
$_name = trim($compiler->_tag_stack[$stack_count][1][0]['name'], "'\"");
|
*/
|
||||||
break;
|
public function compile($args, $compiler)
|
||||||
}
|
{
|
||||||
}
|
$compiler->has_code = true;
|
||||||
// flag that child is already compile by {$smarty.block.child} inclusion
|
// check and get attributes
|
||||||
$compiler->template->block_data[$_name]['compiled'] = true;
|
$_attr = $this->getAttributes($compiler, $args);
|
||||||
}
|
$saved_data = $this->closeTag($compiler, array('block'));
|
||||||
if ($_name == null) {
|
$_name = trim($saved_data[0]['name'], "\"'");
|
||||||
$compiler->trigger_template_error('{$smarty.block.child} used out of context', $compiler->lex->taglineno);
|
if (isset($compiler->template->block_data[$_name]) && !isset($compiler->template->block_data[$_name]['compiled'])) {
|
||||||
}
|
// restore to status before {block} tag as new subtemplate code of parent {block} is not needed
|
||||||
// undefined child?
|
// TODO: Below code was disabled in 3.1.8 because of problems with {include} in nested {block} tags in child templates
|
||||||
if (!isset($compiler->template->block_data[$_name]['source'])) {
|
// combined with append/prepend or $smarty.block.parent
|
||||||
return '';
|
// For later versions it should be checked under which conditions it could run for optimisation
|
||||||
}
|
//
|
||||||
$_tpl = new Smarty_Internal_template('string:' . $compiler->template->block_data[$_name]['source'], $compiler->smarty, $compiler->template, $compiler->template->cache_id,
|
//$compiler->merged_templates = $saved_data[4];
|
||||||
$compiler->template->compile_id, $compiler->template->caching, $compiler->template->cache_lifetime);
|
//$compiler->smarty->merged_templates_func = $saved_data[5];
|
||||||
$_tpl->variable_filters = $compiler->template->variable_filters;
|
//$compiler->template->properties = $saved_data[6];
|
||||||
$_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
|
//$compiler->template->has_nocache_code = $saved_data[7];
|
||||||
$_tpl->source->filepath = $compiler->template->block_data[$_name]['file'];
|
$_output = Smarty_Internal_Compile_Block::compileChildBlock($compiler, $_name);
|
||||||
$_tpl->allow_relative_path = true;
|
|
||||||
if ($compiler->nocache) {
|
|
||||||
$_tpl->compiler->forceNocache = 2;
|
|
||||||
} else {
|
|
||||||
$_tpl->compiler->forceNocache = 1;
|
|
||||||
}
|
|
||||||
$_tpl->compiler->suppressHeader = true;
|
|
||||||
$_tpl->compiler->suppressFilter = true;
|
|
||||||
$_tpl->compiler->suppressTemplatePropertyHeader = true;
|
|
||||||
$_tpl->compiler->suppressMergedTemplates = true;
|
|
||||||
if (strpos($compiler->template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
|
|
||||||
$_output = str_replace('%%%%SMARTY_PARENT%%%%', $compiler->parser->current_buffer->to_smarty_php(), $_tpl->compiler->compileTemplate($_tpl));
|
|
||||||
} elseif ($compiler->template->block_data[$_name]['mode'] == 'prepend') {
|
|
||||||
$_output = $_tpl->compiler->compileTemplate($_tpl) . $compiler->parser->current_buffer->to_smarty_php();
|
|
||||||
} elseif ($compiler->template->block_data[$_name]['mode'] == 'append') {
|
|
||||||
$_output = $compiler->parser->current_buffer->to_smarty_php() . $_tpl->compiler->compileTemplate($_tpl);
|
|
||||||
} elseif (!empty($compiler->template->block_data[$_name])) {
|
|
||||||
$_output = $_tpl->compiler->compileTemplate($_tpl);
|
|
||||||
}
|
|
||||||
$compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $_tpl->properties['file_dependency']);
|
|
||||||
$compiler->template->properties['function'] = array_merge($compiler->template->properties['function'], $_tpl->properties['function']);
|
|
||||||
$compiler->merged_templates = array_merge($compiler->merged_templates, $_tpl->compiler->merged_templates);
|
|
||||||
$compiler->template->variable_filters = $_tpl->variable_filters;
|
|
||||||
if ($_tpl->has_nocache_code) {
|
|
||||||
$compiler->template->has_nocache_code = true;
|
|
||||||
}
|
|
||||||
foreach ($_tpl->required_plugins as $key => $tmp1) {
|
|
||||||
if ($compiler->nocache && $compiler->template->caching) {
|
|
||||||
$code = 'nocache';
|
|
||||||
} else {
|
} else {
|
||||||
$code = $key;
|
if (isset($saved_data[0]['hide']) && !isset($compiler->template->block_data[$_name]['source'])) {
|
||||||
}
|
$_output = '';
|
||||||
foreach ($tmp1 as $name => $tmp) {
|
} else {
|
||||||
foreach ($tmp as $type => $data) {
|
$_output = $compiler->parser->current_buffer->to_smarty_php();
|
||||||
$compiler->template->required_plugins[$code][$name][$type] = $data;
|
|
||||||
}
|
}
|
||||||
|
unset($compiler->template->block_data[$_name]['compiled']);
|
||||||
}
|
}
|
||||||
|
// reset flags
|
||||||
|
$compiler->parser->current_buffer = $saved_data[1];
|
||||||
|
$compiler->nocache = $saved_data[2];
|
||||||
|
$compiler->smarty->merge_compiled_includes = $saved_data[3];
|
||||||
|
// reset flag for {block} tag
|
||||||
|
$compiler->inheritance = false;
|
||||||
|
// $_output content has already nocache code processed
|
||||||
|
$compiler->suppressNocacheProcessing = true;
|
||||||
|
|
||||||
|
return $_output;
|
||||||
}
|
}
|
||||||
unset($_tpl);
|
|
||||||
|
|
||||||
return $_output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Smarty Internal Plugin Compile BlockClose Class
|
|
||||||
*
|
|
||||||
* @package Smarty
|
|
||||||
* @subpackage Compiler
|
|
||||||
*/
|
|
||||||
class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Compiles code for the {/block} tag
|
|
||||||
*
|
|
||||||
* @param array $args array with attributes from parser
|
|
||||||
* @param object $compiler compiler object
|
|
||||||
* @return string compiled code
|
|
||||||
*/
|
|
||||||
public function compile($args, $compiler)
|
|
||||||
{
|
|
||||||
$compiler->has_code = true;
|
|
||||||
// check and get attributes
|
|
||||||
$_attr = $this->getAttributes($compiler, $args);
|
|
||||||
$saved_data = $this->closeTag($compiler, array('block'));
|
|
||||||
$_name = trim($saved_data[0]['name'], "\"'");
|
|
||||||
if (isset($compiler->template->block_data[$_name]) && !isset($compiler->template->block_data[$_name]['compiled'])) {
|
|
||||||
// restore to status before {block} tag as new subtemplate code of parent {block} is not needed
|
|
||||||
// TODO: Below code was disabled in 3.1.8 because of problems with {include} in nested {block} tags in child templates
|
|
||||||
// combined with append/prepend or $smarty.block.parent
|
|
||||||
// For later versions it should be checked under which conditions it could run for optimisation
|
|
||||||
//
|
|
||||||
//$compiler->merged_templates = $saved_data[4];
|
|
||||||
//$compiler->smarty->merged_templates_func = $saved_data[5];
|
|
||||||
//$compiler->template->properties = $saved_data[6];
|
|
||||||
//$compiler->template->has_nocache_code = $saved_data[7];
|
|
||||||
$_output = Smarty_Internal_Compile_Block::compileChildBlock($compiler, $_name);
|
|
||||||
} else {
|
|
||||||
if (isset($saved_data[0]['hide']) && !isset($compiler->template->block_data[$_name]['source'])) {
|
|
||||||
$_output = '';
|
|
||||||
} else {
|
|
||||||
$_output = $compiler->parser->current_buffer->to_smarty_php();
|
|
||||||
}
|
|
||||||
unset($compiler->template->block_data[$_name]['compiled']);
|
|
||||||
}
|
|
||||||
// reset flags
|
|
||||||
$compiler->parser->current_buffer = $saved_data[1];
|
|
||||||
$compiler->nocache = $saved_data[2];
|
|
||||||
$compiler->smarty->merge_compiled_includes = $saved_data[3];
|
|
||||||
// reset flag for {block} tag
|
|
||||||
$compiler->inheritance = false;
|
|
||||||
// $_output content has already nocache code processed
|
|
||||||
$compiler->suppressNocacheProcessing = true;
|
|
||||||
|
|
||||||
return $_output;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user