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
|
|
|
|
*
|
|
|
|
* @package Smarty
|
|
|
|
* @subpackage Compiler
|
|
|
|
* @author Uwe Tews
|
|
|
|
*/
|
2009-03-22 16:09:05 +00:00
|
|
|
/**
|
2010-07-08 18:30:03 +00:00
|
|
|
* Smarty Internal Plugin Compile Assign Class
|
|
|
|
*/
|
2009-03-22 16:09:05 +00:00
|
|
|
class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase {
|
|
|
|
/**
|
2010-07-08 18:30:03 +00:00
|
|
|
* Compiles code for the {assign} tag
|
|
|
|
*
|
|
|
|
* @param array $args array with attributes from parser
|
|
|
|
* @param object $compiler compiler object
|
|
|
|
* @return string compiled code
|
|
|
|
*/
|
2009-03-22 16:09:05 +00:00
|
|
|
public function compile($args, $compiler)
|
|
|
|
{
|
|
|
|
$this->compiler = $compiler;
|
|
|
|
$this->required_attributes = array('var', 'value');
|
2009-12-15 00:02:10 +00:00
|
|
|
$this->optional_attributes = array('scope', 'nocache', 'smarty_internal_index');
|
2009-03-22 16:09:05 +00:00
|
|
|
|
|
|
|
$_nocache = 'null';
|
2009-04-07 16:22:31 +00:00
|
|
|
$_scope = 'null';
|
2009-03-22 16:09:05 +00:00
|
|
|
// check for nocache attribute before _get_attributes because
|
|
|
|
// it shall not controll caching of the compiled code, but is a parameter
|
|
|
|
if (isset($args['nocache'])) {
|
|
|
|
if ($args['nocache'] == 'true') {
|
|
|
|
$_nocache = 'true';
|
|
|
|
$_nocache_boolean = true;
|
|
|
|
}
|
|
|
|
unset($args['nocache']);
|
|
|
|
}
|
|
|
|
// check and get attributes
|
|
|
|
$_attr = $this->_get_attributes($args);
|
|
|
|
|
2009-04-07 16:22:31 +00:00
|
|
|
if (isset($_attr['scope'])) {
|
2009-04-10 12:33:51 +00:00
|
|
|
if ($_attr['scope'] == '\'parent\'') {
|
|
|
|
$_scope = SMARTY_PARENT_SCOPE;
|
|
|
|
} elseif ($_attr['scope'] == '\'root\'') {
|
|
|
|
$_scope = SMARTY_ROOT_SCOPE;
|
2010-07-08 18:30:03 +00:00
|
|
|
} elseif ($_attr['scope'] == '\'global\'') {
|
2009-04-10 12:33:51 +00:00
|
|
|
$_scope = SMARTY_GLOBAL_SCOPE;
|
|
|
|
}
|
2009-03-22 16:09:05 +00:00
|
|
|
}
|
|
|
|
// compiled output
|
2009-12-15 00:02:10 +00:00
|
|
|
if (isset($_attr['smarty_internal_index'])) {
|
2010-07-08 18:30:03 +00:00
|
|
|
return "<?php if (!isset(\$_smarty_tpl->tpl_vars[$_attr[var]]) || !is_array(\$_smarty_tpl->tpl_vars[$_attr[var]]->value)) \$_smarty_tpl->createLocalArrayVariable($_attr[var], $_nocache, $_scope);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$_attr[smarty_internal_index] = $_attr[value];?>";
|
2009-04-03 15:59:40 +00:00
|
|
|
} else {
|
2010-07-08 18:30:03 +00:00
|
|
|
return "<?php \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_variable($_attr[value], $_nocache, $_scope);?>";
|
2009-04-03 15:59:40 +00:00
|
|
|
}
|
2009-03-22 16:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-08 18:30:03 +00:00
|
|
|
?>
|