diff --git a/change_log.txt b/change_log.txt index a120bdbf..7b03504c 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,6 +1,7 @@  ===== 3.1.28-dev===== (xx.xx.2015) 02.08.2015 - optimization and code cleanup of {foreach} and {section} compiler + - rework {capture} compiler 01.08.2015 - update DateTime object can be instance of DateTimeImmutable since PHP5.5 https://github.com/smarty-php/smarty/pull/75 diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 8a27854c..28548b11 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.28-dev/37'; + const SMARTY_VERSION = '3.1.28-dev/38'; /** * define variable scopes @@ -688,13 +688,6 @@ class Smarty extends Smarty_Internal_TemplateBase */ public $escape_html = false; - /** - * global internal smarty vars - * - * @var array - */ - public static $_smarty_vars = array(); - /** * start time for execution time calculation * diff --git a/libs/sysplugins/smarty_internal_compile_capture.php b/libs/sysplugins/smarty_internal_compile_capture.php index 34728e47..91f37c6f 100644 --- a/libs/sysplugins/smarty_internal_compile_capture.php +++ b/libs/sysplugins/smarty_internal_compile_capture.php @@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase */ public $shorttag_order = array('name'); + /** * Attribute definition: Overwrites base class. * @@ -34,12 +35,12 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase /** * Compiles code for the {capture} tag * - * @param array $args array with attributes from parser - * @param object $compiler compiler object + * @param array $args array with attributes from parser + * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * * @return string compiled code */ - public function compile($args, $compiler) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) { // check and get attributes $_attr = $this->getAttributes($compiler, $args); @@ -55,6 +56,27 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase return $_output; } + + /** + * Compiles code for the {$smarty.capture.xxx} + * + * @param array $args array with attributes from parser + * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object + * @param array $parameter array with compilation parameter + * + * @return string compiled code + * @throws \SmartyCompilerException + */ + public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) + { + // make all lower case + $parameter = array_map('strtolower', $parameter); + $tag = trim($parameter[0], '"\''); + if (!isset($parameter[1]) || false === $name = $compiler->getId($parameter[1])) { + $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", $compiler->lex->taglineno); + } + return "isset(\$_smarty_tpl->_cache['__smarty_capture']['{$name}']) ? \$_smarty_tpl->_cache['__smarty_capture']['{$name}'] : null"; + } } /** @@ -68,12 +90,12 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase /** * Compiles code for the {/capture} tag * - * @param array $args array with attributes from parser - * @param object $compiler compiler object + * @param array $args array with attributes from parser + * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * * @return string compiled code */ - public function compile($args, $compiler) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) { // check and get attributes $_attr = $this->getAttributes($compiler, $args); @@ -88,7 +110,7 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase $_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 .= "\$_smarty_tpl->_cache['__smarty_capture'][\$_capture_buffer]=ob_get_clean();\n"; $_output .= "} else \$_smarty_tpl->capture_error();?>"; return $_output; diff --git a/libs/sysplugins/smarty_internal_compile_private_special_variable.php b/libs/sysplugins/smarty_internal_compile_private_special_variable.php index d734aa84..44602300 100644 --- a/libs/sysplugins/smarty_internal_compile_private_special_variable.php +++ b/libs/sysplugins/smarty_internal_compile_private_special_variable.php @@ -41,7 +41,10 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C case 'section': return Smarty_Internal_Compile_Private_ForeachSection::compileSpecialVariable(array(), $compiler, $_index); case 'capture': - return "Smarty::\$_smarty_vars$parameter"; + if (class_exists('Smarty_Internal_Compile_Capture')) { + return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index); + } + return ''; case 'now': return 'time()'; case 'cookies': @@ -116,13 +119,7 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C $compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is invalid'); break; } - if (isset($_index[1])) { - array_shift($_index); - foreach ($_index as $_ind) { - $compiled_ref = $compiled_ref . "[$_ind]"; - } - } } - return $compiled_ref; + return ''; } } diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index 16f442ce..c9892ab7 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -305,6 +305,12 @@ abstract class Smarty_Internal_TemplateCompilerBase */ public $cache = array(); + /** + * Stack during {capture} compilation + * + * @var array + */ + public $_capture_stack = array(); /** * Strip preg pattern *