2009-03-22 16:09:05 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2010-07-08 18:30:03 +00:00
|
|
|
* Smarty Internal Plugin Compile Assign
|
|
|
|
* Compiles the {assign} tag
|
2011-09-16 14:19:56 +00:00
|
|
|
*
|
2014-06-06 02:40:04 +00:00
|
|
|
* @package Smarty
|
2010-07-08 18:30:03 +00:00
|
|
|
* @subpackage Compiler
|
2014-06-06 02:40:04 +00:00
|
|
|
* @author Uwe Tews
|
2010-07-08 18:30:03 +00:00
|
|
|
*/
|
2010-08-17 15:39:51 +00:00
|
|
|
|
2009-03-22 16:09:05 +00:00
|
|
|
/**
|
2010-07-08 18:30:03 +00:00
|
|
|
* Smarty Internal Plugin Compile Assign Class
|
2011-09-16 14:19:56 +00:00
|
|
|
*
|
2014-06-06 02:40:04 +00:00
|
|
|
* @package Smarty
|
2011-09-16 14:19:56 +00:00
|
|
|
* @subpackage Compiler
|
2010-07-08 18:30:03 +00:00
|
|
|
*/
|
2013-07-14 22:15:45 +00:00
|
|
|
class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
|
|
|
|
{
|
2015-11-01 02:02:27 +01:00
|
|
|
/**
|
|
|
|
* Valid scope names
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2016-02-09 01:27:15 +01:00
|
|
|
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true,
|
2016-01-02 02:47:32 +01:00
|
|
|
'tpl_root' => true);
|
2015-11-01 02:02:27 +01:00
|
|
|
|
2009-03-22 16:09:05 +00:00
|
|
|
/**
|
2010-07-08 18:30:03 +00:00
|
|
|
* Compiles code for the {assign} tag
|
2011-09-16 14:19:56 +00:00
|
|
|
*
|
2015-08-06 01:19:11 +02:00
|
|
|
* @param array $args array with attributes from parser
|
|
|
|
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
|
|
|
* @param array $parameter array with compilation parameter
|
2014-06-06 02:40:04 +00:00
|
|
|
*
|
2010-07-08 18:30:03 +00:00
|
|
|
* @return string compiled code
|
2015-08-06 01:19:11 +02:00
|
|
|
* @throws \SmartyCompilerException
|
2010-07-08 18:30:03 +00:00
|
|
|
*/
|
2015-08-06 01:19:11 +02:00
|
|
|
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
2009-03-22 16:09:05 +00:00
|
|
|
{
|
2010-12-28 22:40:13 +00:00
|
|
|
// the following must be assigned at runtime because it will be overwritten in Smarty_Internal_Compile_Append
|
2009-03-22 16:09:05 +00:00
|
|
|
$this->required_attributes = array('var', 'value');
|
2010-11-11 21:34:36 +00:00
|
|
|
$this->shorttag_order = array('var', 'value');
|
2015-11-01 02:02:27 +01:00
|
|
|
$this->optional_attributes = array('scope', 'bubble_up');
|
2009-03-22 16:09:05 +00:00
|
|
|
$_nocache = 'null';
|
|
|
|
// check and get attributes
|
2011-09-16 14:19:56 +00:00
|
|
|
$_attr = $this->getAttributes($compiler, $args);
|
|
|
|
// nocache ?
|
|
|
|
if ($compiler->tag_nocache || $compiler->nocache) {
|
|
|
|
$_nocache = 'true';
|
2010-07-31 13:29:59 +00:00
|
|
|
// create nocache var to make it know for further compiling
|
2015-12-31 02:20:47 +01:00
|
|
|
if (isset($compiler->template->tpl_vars[ trim($_attr[ 'var' ], "'") ])) {
|
|
|
|
$compiler->template->tpl_vars[ trim($_attr[ 'var' ], "'") ]->nocache = true;
|
2012-07-30 20:07:51 +00:00
|
|
|
} else {
|
2015-12-31 02:20:47 +01:00
|
|
|
$compiler->template->tpl_vars[ trim($_attr[ 'var' ], "'") ] = new Smarty_Variable(null, true);
|
2012-07-30 20:07:51 +00:00
|
|
|
}
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
2010-11-11 21:34:36 +00:00
|
|
|
// scope setup
|
2015-11-01 02:02:27 +01:00
|
|
|
$_scope = Smarty::SCOPE_LOCAL;
|
2015-12-31 02:20:47 +01:00
|
|
|
if (isset($_attr[ 'scope' ])) {
|
|
|
|
$_attr[ 'scope' ] = trim($_attr[ 'scope' ], "'\"");
|
|
|
|
if (!isset($this->valid_scopes[ $_attr[ 'scope' ] ])) {
|
|
|
|
$compiler->trigger_template_error("illegal value '{$_attr['scope']}' for \"scope\" attribute", null,
|
|
|
|
true);
|
2015-11-01 02:02:27 +01:00
|
|
|
}
|
2015-12-31 02:20:47 +01:00
|
|
|
if ($_attr[ 'scope' ] != 'local') {
|
|
|
|
if ($_attr[ 'scope' ] == 'parent') {
|
2015-11-01 02:02:27 +01:00
|
|
|
$_scope = Smarty::SCOPE_PARENT;
|
2015-12-31 02:20:47 +01:00
|
|
|
} elseif ($_attr[ 'scope' ] == 'root') {
|
2015-11-01 02:02:27 +01:00
|
|
|
$_scope = Smarty::SCOPE_ROOT;
|
2015-12-31 02:20:47 +01:00
|
|
|
} elseif ($_attr[ 'scope' ] == 'global') {
|
2015-11-01 02:02:27 +01:00
|
|
|
$_scope = Smarty::SCOPE_GLOBAL;
|
2015-12-31 02:20:47 +01:00
|
|
|
} elseif ($_attr[ 'scope' ] == 'tpl_root') {
|
2015-11-01 02:02:27 +01:00
|
|
|
$_scope = Smarty::SCOPE_TPL_ROOT;
|
|
|
|
}
|
2015-12-31 02:20:47 +01:00
|
|
|
$_scope += (isset($_attr[ 'bubble_up' ]) && $_attr[ 'bubble_up' ] == 'false') ? 0 :
|
|
|
|
Smarty::SCOPE_BUBBLE_UP;
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-31 02:20:47 +01:00
|
|
|
if (isset($parameter[ 'smarty_internal_index' ])) {
|
|
|
|
$output = "<?php \$_smarty_tpl->_createLocalArrayVariable({$_attr['var']}, {$_nocache});\n";
|
|
|
|
$output .= "\$_smarty_tpl->tpl_vars[{$_attr['var']}]->value{$parameter['smarty_internal_index']} = {$_attr['value']};\n";
|
|
|
|
if ($_scope != Smarty::SCOPE_LOCAL) {
|
|
|
|
$output .= "\$_smarty_tpl->ext->_updateScope->updateScope(\$_smarty_tpl, {$_attr['var']}, {$_scope});\n";
|
|
|
|
} else {
|
|
|
|
$output .= "if (\$_smarty_tpl->scope & Smarty::SCOPE_BUBBLE_UP) {\n";
|
|
|
|
$output .= "\$_smarty_tpl->ext->_updateScope->updateScope(\$_smarty_tpl, {$_attr['var']});\n}\n";
|
|
|
|
}
|
|
|
|
$output .= '?>';
|
2011-09-16 14:19:56 +00:00
|
|
|
} else {
|
2012-03-27 17:07:32 +00:00
|
|
|
if ($compiler->template->smarty instanceof SmartyBC) {
|
2015-12-31 02:20:47 +01:00
|
|
|
$_smartyBC = 'true';
|
2012-03-27 17:07:32 +00:00
|
|
|
} else {
|
2015-12-31 02:20:47 +01:00
|
|
|
$_smartyBC = 'false';
|
2012-03-27 17:07:32 +00:00
|
|
|
}
|
2015-12-31 02:20:47 +01:00
|
|
|
$output =
|
|
|
|
"<?php \$_smarty_tpl->_assignInScope({$_attr['var']}, {$_attr['value']}, {$_nocache}, {$_scope}, {$_smartyBC});\n?>";
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
}
|