mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44: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 =====
|
||||
11.10.2011
|
||||
- add runtime checks for not matching {capture}/{/capture} calls (Forum Topic 20120)
|
||||
|
||||
10.10.2011
|
||||
- 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
|
||||
|
@@ -45,13 +45,13 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase {
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
$buffer = isset($_attr['name']) ? $_attr['name'] : "'default'";
|
||||
$assign = isset($_attr['assign']) ? $_attr['assign'] : null;
|
||||
$append = isset($_attr['append']) ? $_attr['append'] : null;
|
||||
$assign = isset($_attr['assign']) ? $_attr['assign'] : 'null';
|
||||
$append = isset($_attr['append']) ? $_attr['append'] : 'null';
|
||||
|
||||
$compiler->_capture_stack[] = array($buffer, $assign, $append, $compiler->nocache);
|
||||
// maybe nocache because of nocache variables
|
||||
$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;
|
||||
}
|
||||
@@ -84,14 +84,12 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase {
|
||||
|
||||
list($buffer, $assign, $append, $compiler->nocache) = array_pop($compiler->_capture_stack);
|
||||
|
||||
$_output = "<?php ";
|
||||
if (isset($assign)) {
|
||||
$_output .= " \$_smarty_tpl->assign($assign, ob_get_contents());";
|
||||
}
|
||||
if (isset($append)) {
|
||||
$_output .= " \$_smarty_tpl->append($append, ob_get_contents());";
|
||||
}
|
||||
$_output .= " Smarty::\$_smarty_vars['capture'][$buffer]=ob_get_clean();?>";
|
||||
$_output = "<?php list(\$_capture_buffer, \$_capture_assign, \$_capture_append) = array_pop(\$_smarty_tpl->_capture_stack);\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";
|
||||
$_output .= " Smarty::\$_smarty_vars['capture'][\$_capture_buffer]=ob_get_clean();\n";
|
||||
$_output .= "} else \$_smarty_tpl->capture_error();?>";
|
||||
return $_output;
|
||||
}
|
||||
|
||||
|
@@ -93,6 +93,11 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
* @var bool
|
||||
*/
|
||||
public $allow_relative_path = false;
|
||||
/**
|
||||
* internal capture runtime stack
|
||||
* @var array
|
||||
*/
|
||||
public $_capture_stack = array();
|
||||
|
||||
/**
|
||||
* Create template data object
|
||||
@@ -551,6 +556,14 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @param string $property_name property name
|
||||
|
@@ -170,6 +170,9 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
||||
throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'");
|
||||
}
|
||||
$_template->properties['unifunc']($_template);
|
||||
if (isset($_template->_capture_stack[0])) {
|
||||
$_template->capture_error();
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
ob_get_clean();
|
||||
throw $e;
|
||||
@@ -262,6 +265,9 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
||||
try {
|
||||
ob_start();
|
||||
$_template->properties['unifunc']($_template);
|
||||
if (isset($_template->_capture_stack[0])) {
|
||||
$_template->capture_error();
|
||||
}
|
||||
$_output = ob_get_clean();
|
||||
} catch (Exception $e) {
|
||||
ob_get_clean();
|
||||
|
Reference in New Issue
Block a user