From ab5d8d4e07bb3c8230d0285ef8902ef1979fce51 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 18 Oct 2018 02:39:34 +0200 Subject: Updating Smarty --- .../sysplugins/smarty_internal_compile_assign.php | 97 +++++++++++++--------- 1 file changed, 58 insertions(+), 39 deletions(-) (limited to 'lib/smarty/sysplugins/smarty_internal_compile_assign.php') diff --git a/lib/smarty/sysplugins/smarty_internal_compile_assign.php b/lib/smarty/sysplugins/smarty_internal_compile_assign.php index 40e4686..4b99848 100644 --- a/lib/smarty/sysplugins/smarty_internal_compile_assign.php +++ b/lib/smarty/sysplugins/smarty_internal_compile_assign.php @@ -1,77 +1,96 @@ Smarty::SCOPE_LOCAL, 'parent' => Smarty::SCOPE_PARENT, + 'root' => Smarty::SCOPE_ROOT, 'global' => Smarty::SCOPE_GLOBAL, + 'tpl_root' => Smarty::SCOPE_TPL_ROOT, 'smarty' => Smarty::SCOPE_SMARTY + ); /** * Compiles code for the {assign} tag * - * @param array $args array with attributes from parser - * @param object $compiler compiler object - * @param array $parameter array with compilation parameter + * @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 function compile($args, $compiler, $parameter) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) { // the following must be assigned at runtime because it will be overwritten in Smarty_Internal_Compile_Append $this->required_attributes = array('var', 'value'); $this->shorttag_order = array('var', 'value'); $this->optional_attributes = array('scope'); - $_nocache = 'null'; - $_scope = Smarty::SCOPE_LOCAL; + $this->mapCache = array(); + $_nocache = false; // check and get attributes $_attr = $this->getAttributes($compiler, $args); // nocache ? + if ($_var = $compiler->getId($_attr[ 'var' ])) { + $_var = "'{$_var}'"; + } else { + $_var = $_attr[ 'var' ]; + } if ($compiler->tag_nocache || $compiler->nocache) { - $_nocache = 'true'; + $_nocache = true; // create nocache var to make it know for further compiling - $compiler->template->tpl_vars[trim($_attr['var'], "'")] = new Smarty_variable(null, true); + $compiler->setNocacheInVariable($_attr[ 'var' ]); } // scope setup - if (isset($_attr['scope'])) { - $_attr['scope'] = trim($_attr['scope'], "'\""); - if ($_attr['scope'] == 'parent') { - $_scope = Smarty::SCOPE_PARENT; - } elseif ($_attr['scope'] == 'root') { - $_scope = Smarty::SCOPE_ROOT; - } elseif ($_attr['scope'] == 'global') { - $_scope = Smarty::SCOPE_GLOBAL; - } else { - $compiler->trigger_template_error('illegal value for "scope" attribute', $compiler->lex->taglineno); - } - } - // compiled output - if (isset($parameter['smarty_internal_index'])) { - $output = "createLocalArrayVariable($_attr[var], $_nocache, $_scope);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];"; + if ($_attr[ 'noscope' ]) { + $_scope = -1; } else { - $output = "tpl_vars[$_attr[var]] = new Smarty_variable($_attr[value], $_nocache, $_scope);"; + $_scope = $compiler->convertScope($_attr, $this->valid_scopes); } - if ($_scope == Smarty::SCOPE_PARENT) { - $output .= "\nif (\$_smarty_tpl->parent != null) \$_smarty_tpl->parent->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];"; - } elseif ($_scope == Smarty::SCOPE_ROOT || $_scope == Smarty::SCOPE_GLOBAL) { - $output .= "\n\$_ptr = \$_smarty_tpl->parent; while (\$_ptr != null) {\$_ptr->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]]; \$_ptr = \$_ptr->parent; }"; + // optional parameter + $_params = ''; + if ($_nocache || $_scope) { + $_params .= ' ,' . var_export($_nocache, true); } - if ( $_scope == Smarty::SCOPE_GLOBAL) { - $output .= "\nSmarty::\$global_tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];"; + if ($_scope) { + $_params .= ' ,' . $_scope; + } + if (isset($parameter[ 'smarty_internal_index' ])) { + $output = + "tpl_vars[{$_var}]) ? \$_smarty_tpl->tpl_vars[{$_var}]->value : array();\n"; + $output .= "if (!is_array(\$_tmp_array) || \$_tmp_array instanceof ArrayAccess) {\n"; + $output .= "settype(\$_tmp_array, 'array');\n"; + $output .= "}\n"; + $output .= "\$_tmp_array{$parameter['smarty_internal_index']} = {$_attr['value']};\n"; + $output .= "\$_smarty_tpl->_assignInScope({$_var}, \$_tmp_array{$_params});?>"; + } else { + $output = "_assignInScope({$_var}, {$_attr['value']}{$_params});?>"; } - $output .= '?>'; return $output; } - } - -?> \ No newline at end of file -- cgit v1.2.3