mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 19:04:27 +02:00
- add runtime checks for not matching {capture}/{/capture} calls (Forum Topic 20120)
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
===== trunk =====
|
===== trunk =====
|
||||||
|
11.10.2011
|
||||||
|
- add runtime checks for not matching {capture}/{/capture} calls (Forum Topic 20120)
|
||||||
|
|
||||||
10.10.2011
|
10.10.2011
|
||||||
- bugfix variable name typo in {html_options} and {html_checkboxes} (Issue #54)
|
- bugfix variable name typo in {html_options} and {html_checkboxes} (Issue #54)
|
||||||
- bugfix <?xml> tag did create wrong output when caching enabled and the tag was in included subtemplate
|
- bugfix <?xml> tag did create wrong output when caching enabled and the tag was in included subtemplate
|
||||||
|
@@ -45,13 +45,13 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase {
|
|||||||
$_attr = $this->getAttributes($compiler, $args);
|
$_attr = $this->getAttributes($compiler, $args);
|
||||||
|
|
||||||
$buffer = isset($_attr['name']) ? $_attr['name'] : "'default'";
|
$buffer = isset($_attr['name']) ? $_attr['name'] : "'default'";
|
||||||
$assign = isset($_attr['assign']) ? $_attr['assign'] : null;
|
$assign = isset($_attr['assign']) ? $_attr['assign'] : 'null';
|
||||||
$append = isset($_attr['append']) ? $_attr['append'] : null;
|
$append = isset($_attr['append']) ? $_attr['append'] : 'null';
|
||||||
|
|
||||||
$compiler->_capture_stack[] = array($buffer, $assign, $append, $compiler->nocache);
|
$compiler->_capture_stack[] = array($buffer, $assign, $append, $compiler->nocache);
|
||||||
// maybe nocache because of nocache variables
|
// maybe nocache because of nocache variables
|
||||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||||
$_output = "<?php ob_start(); ?>";
|
$_output = "<?php \$_smarty_tpl->_capture_stack[] = array($buffer, $assign, $append); ob_start(); ?>";
|
||||||
|
|
||||||
return $_output;
|
return $_output;
|
||||||
}
|
}
|
||||||
@@ -84,14 +84,12 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase {
|
|||||||
|
|
||||||
list($buffer, $assign, $append, $compiler->nocache) = array_pop($compiler->_capture_stack);
|
list($buffer, $assign, $append, $compiler->nocache) = array_pop($compiler->_capture_stack);
|
||||||
|
|
||||||
$_output = "<?php ";
|
$_output = "<?php list(\$_capture_buffer, \$_capture_assign, \$_capture_append) = array_pop(\$_smarty_tpl->_capture_stack);\n";
|
||||||
if (isset($assign)) {
|
$_output .= "if (!empty(\$_capture_buffer)) {\n";
|
||||||
$_output .= " \$_smarty_tpl->assign($assign, ob_get_contents());";
|
$_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";
|
||||||
if (isset($append)) {
|
$_output .= " Smarty::\$_smarty_vars['capture'][\$_capture_buffer]=ob_get_clean();\n";
|
||||||
$_output .= " \$_smarty_tpl->append($append, ob_get_contents());";
|
$_output .= "} else \$_smarty_tpl->capture_error();?>";
|
||||||
}
|
|
||||||
$_output .= " Smarty::\$_smarty_vars['capture'][$buffer]=ob_get_clean();?>";
|
|
||||||
return $_output;
|
return $_output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -93,6 +93,11 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
|||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
public $allow_relative_path = false;
|
public $allow_relative_path = false;
|
||||||
|
/**
|
||||||
|
* internal capture runtime stack
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $_capture_stack = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create template data object
|
* Create template data object
|
||||||
@@ -550,6 +555,14 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* runtime error not matching capture tags
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function capture_error()
|
||||||
|
{
|
||||||
|
throw new SmartyException("Not matching {capture} open/close in \"{$this->template_resource}\"");
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* set Smarty property in template context
|
* set Smarty property in template context
|
||||||
*
|
*
|
||||||
|
@@ -170,6 +170,9 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'");
|
throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'");
|
||||||
}
|
}
|
||||||
$_template->properties['unifunc']($_template);
|
$_template->properties['unifunc']($_template);
|
||||||
|
if (isset($_template->_capture_stack[0])) {
|
||||||
|
$_template->capture_error();
|
||||||
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
ob_get_clean();
|
ob_get_clean();
|
||||||
throw $e;
|
throw $e;
|
||||||
@@ -262,6 +265,9 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
try {
|
try {
|
||||||
ob_start();
|
ob_start();
|
||||||
$_template->properties['unifunc']($_template);
|
$_template->properties['unifunc']($_template);
|
||||||
|
if (isset($_template->_capture_stack[0])) {
|
||||||
|
$_template->capture_error();
|
||||||
|
}
|
||||||
$_output = ob_get_clean();
|
$_output = ob_get_clean();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
ob_get_clean();
|
ob_get_clean();
|
||||||
|
Reference in New Issue
Block a user