mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 19:04:27 +02:00
- bugfix {capture} tags around recursive {include} calls did throw exception (Forum Topic 20549)
- bugfix $auto_literal = false did not work with { block} tags in child templates (Forum Topic 20581) - bugfix template inheritance: do not include code of {include} in overloaded {block} into compiled parent template (Issue 66} - bugfix template inheritance: {$smarty.block.child} in nested child {block} tags did not return expected result (Forum Topic 20564)
This commit is contained in:
@@ -1,4 +1,12 @@
|
||||
===== trunk =====
|
||||
9.12.2011
|
||||
- bugfix {capture} tags around recursive {include} calls did throw exception (Forum Topic 20549)
|
||||
- bugfix $auto_literal = false did not work with { block} tags in child templates (Forum Topic 20581)
|
||||
- bugfix template inheritance: do not include code of {include} in overloaded {block} into compiled
|
||||
parent template (Issue 66}
|
||||
- bugfix template inheritance: {$smarty.block.child} in nested child {block} tags did not return expected
|
||||
result (Forum Topic 20564)
|
||||
|
||||
===== Smarty-3.1.6 =====
|
||||
30.11.2011
|
||||
- bugfix is_cache() for individual cached subtemplates with $smarty->caching = CACHING_OFF did produce
|
||||
|
@@ -50,7 +50,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
$save = array($_attr, $compiler->parser->current_buffer, $compiler->nocache, $compiler->smarty->merge_compiled_includes);
|
||||
$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;
|
||||
@@ -77,22 +77,43 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
|
||||
{
|
||||
$_rdl = preg_quote($template->smarty->right_delimiter);
|
||||
$_ldl = preg_quote($template->smarty->left_delimiter);
|
||||
|
||||
if (0 == preg_match("!({$_ldl}block\s+)(name=)?(\w+|'.*'|\".*\")(\s*?)?((append|prepend|nocache)?(\s*)?(hide)?)?(\s*{$_rdl})!", $block_tag, $_match)) {
|
||||
if ($template->smarty->auto_literal) {
|
||||
$al = '\s*';
|
||||
} else {
|
||||
$al = '';
|
||||
}
|
||||
if (0 == preg_match("!({$_ldl}{$al}block\s+)(name=)?(\w+|'.*'|\".*\")(\s*?)?((append|prepend|nocache)?(\s*)?(hide)?)?(\s*{$_rdl})!", $block_tag, $_match)) {
|
||||
$error_text = 'Syntax Error in template "' . $template->source->filepath . '" "' . htmlspecialchars($block_tag) . '" illegal options';
|
||||
throw new SmartyCompilerException($error_text);
|
||||
} else {
|
||||
$_name = trim($_match[3], '\'"');
|
||||
if ($_match[8] != 'hide' || isset($template->block_data[$_name])) { // replace {$smarty.block.child}
|
||||
if (strpos($block_content, $template->smarty->left_delimiter . '$smarty.block.child' . $template->smarty->right_delimiter) !== false) {
|
||||
// do we have {$smart.block.child} in nested {block} tags?
|
||||
if (0 != preg_match_all("!({$_ldl}{$al}block\s+)(name=)?(\w+|'.*'|\".*\")([\s\S]*?{$_rdl})([\s\S]*?)({$_ldl}{$al}\\\$smarty\.block\.child{$_rdl})([\s\S]*?{$_ldl}{$al}/block{$_rdl})!", $block_content, $_match2)) {
|
||||
foreach($_match2[3] as $name) {
|
||||
// get it's replacement
|
||||
$_name2 = trim($name, '\'"');
|
||||
if (isset($template->block_data[$_name2])) {
|
||||
$replacement = $template->block_data[$_name2]['source'];
|
||||
} else {
|
||||
$replacement = '';
|
||||
}
|
||||
// replace {$smarty.block.child} tag
|
||||
$search = array("%({$_ldl}{$al}block[\s\S]*?{$name}[\s\S]*?{$_rdl})([\s\S]*?)({$_ldl}{$al}\\\$smarty\.block\.child{$_rdl})([\s\S]*?{$_ldl}{$al}/block{$_rdl})%","/<2F><><EFBFBD>child<6C><64><EFBFBD>/");
|
||||
$replace = array('\2<><32><EFBFBD>child<6C><64><EFBFBD>', $replacement);
|
||||
$block_content = preg_replace($search, $replace , $block_content);
|
||||
}
|
||||
}
|
||||
// do we have not nested {$smart.block.child}
|
||||
if (0 != preg_match("/({$_ldl}{$al}\\\$smarty\.block\.child{$_rdl})/", $block_content, $_match2)) {
|
||||
// get child replacement for this block
|
||||
if (isset($template->block_data[$_name])) {
|
||||
$block_content = str_replace($template->smarty->left_delimiter . '$smarty.block.child' . $template->smarty->right_delimiter,
|
||||
$template->block_data[$_name]['source'], $block_content);
|
||||
$replacement = $template->block_data[$_name]['source'];
|
||||
unset($template->block_data[$_name]);
|
||||
} else {
|
||||
$block_content = str_replace($template->smarty->left_delimiter . '$smarty.block.child' . $template->smarty->right_delimiter,
|
||||
'', $block_content);
|
||||
$replacement = '';
|
||||
}
|
||||
$block_content = preg_replace("/({$_ldl}{$al}\\\$smarty\.block\.child{$_rdl})/", $replacement, $block_content);
|
||||
}
|
||||
if (isset($template->block_data[$_name])) {
|
||||
if (strpos($template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
|
||||
@@ -213,6 +234,11 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
|
||||
$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
|
||||
$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'])) {
|
||||
|
@@ -48,10 +48,10 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase {
|
||||
$assign = isset($_attr['assign']) ? $_attr['assign'] : 'null';
|
||||
$append = isset($_attr['append']) ? $_attr['append'] : 'null';
|
||||
|
||||
$compiler->_capture_stack[] = array($buffer, $assign, $append, $compiler->nocache);
|
||||
$compiler->_capture_stack[0][] = array($buffer, $assign, $append, $compiler->nocache);
|
||||
// maybe nocache because of nocache variables
|
||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||
$_output = "<?php \$_smarty_tpl->_capture_stack[] = array($buffer, $assign, $append); ob_start(); ?>";
|
||||
$_output = "<?php \$_smarty_tpl->_capture_stack[0][] = array($buffer, $assign, $append); ob_start(); ?>";
|
||||
|
||||
return $_output;
|
||||
}
|
||||
@@ -82,9 +82,9 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase {
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
|
||||
list($buffer, $assign, $append, $compiler->nocache) = array_pop($compiler->_capture_stack);
|
||||
list($buffer, $assign, $append, $compiler->nocache) = array_pop($compiler->_capture_stack[0]);
|
||||
|
||||
$_output = "<?php list(\$_capture_buffer, \$_capture_assign, \$_capture_append) = array_pop(\$_smarty_tpl->_capture_stack);\n";
|
||||
$_output = "<?php list(\$_capture_buffer, \$_capture_assign, \$_capture_append) = array_pop(\$_smarty_tpl->_capture_stack[0]);\n";
|
||||
$_output .= "if (!empty(\$_capture_buffer)) {\n";
|
||||
$_output .= " if (isset(\$_capture_assign)) \$_smarty_tpl->assign(\$_capture_assign, ob_get_contents());\n";
|
||||
$_output .= " if (isset( \$_capture_append)) \$_smarty_tpl->append( \$_capture_append, ob_get_contents());\n";
|
||||
|
@@ -97,7 +97,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
* internal capture runtime stack
|
||||
* @var array
|
||||
*/
|
||||
public $_capture_stack = array();
|
||||
public $_capture_stack = array(0 => array());
|
||||
|
||||
/**
|
||||
* Create template data object
|
||||
|
@@ -173,10 +173,16 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
||||
if (empty($_template->properties['unifunc']) || !is_callable($_template->properties['unifunc'])) {
|
||||
throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'");
|
||||
}
|
||||
array_unshift($_template->_capture_stack,array());
|
||||
//
|
||||
// render compiled template
|
||||
//
|
||||
$_template->properties['unifunc']($_template);
|
||||
if (isset($_template->_capture_stack[0])) {
|
||||
// any unclosed {capture} tags ?
|
||||
if (isset($_template->_capture_stack[0][0])) {
|
||||
$_template->capture_error();
|
||||
}
|
||||
array_shift($_template->_capture_stack);
|
||||
} catch (Exception $e) {
|
||||
ob_get_clean();
|
||||
throw $e;
|
||||
@@ -268,10 +274,16 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
||||
}
|
||||
try {
|
||||
ob_start();
|
||||
array_unshift($_template->_capture_stack,array());
|
||||
//
|
||||
// render cached template
|
||||
//
|
||||
$_template->properties['unifunc']($_template);
|
||||
if (isset($_template->_capture_stack[0])) {
|
||||
// any unclosed {capture} tags ?
|
||||
if (isset($_template->_capture_stack[0][0])) {
|
||||
$_template->capture_error();
|
||||
}
|
||||
array_shift($_template->_capture_stack);
|
||||
$_output = ob_get_clean();
|
||||
} catch (Exception $e) {
|
||||
ob_get_clean();
|
||||
|
Reference in New Issue
Block a user