You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
3.4 KiB
PHTML
95 lines
3.4 KiB
PHTML
14 years ago
|
<?php
|
||
|
/**
|
||
|
* Smarty Internal Plugin Compile Assign
|
||
|
* Compiles the {assign} tag
|
||
13 years ago
|
*
|
||
10 years ago
|
* @package Smarty
|
||
14 years ago
|
* @subpackage Compiler
|
||
10 years ago
|
* @author Uwe Tews
|
||
14 years ago
|
*/
|
||
|
|
||
|
/**
|
||
|
* Smarty Internal Plugin Compile Assign Class
|
||
13 years ago
|
*
|
||
10 years ago
|
* @package Smarty
|
||
13 years ago
|
* @subpackage Compiler
|
||
14 years ago
|
*/
|
||
11 years ago
|
class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
|
||
|
{
|
||
9 years ago
|
/**
|
||
7 years ago
|
* Attribute definition: Overwrites base class.
|
||
|
*
|
||
|
* @var array
|
||
|
* @see Smarty_Internal_CompileBase
|
||
|
*/
|
||
|
public $option_flags = array('nocache', 'noscope');
|
||
|
|
||
|
/**
|
||
9 years ago
|
* Valid scope names
|
||
|
*
|
||
|
* @var array
|
||
|
*/
|
||
7 years ago
|
public $valid_scopes = array('local' => 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);
|
||
9 years ago
|
|
||
14 years ago
|
/**
|
||
|
* Compiles code for the {assign} tag
|
||
13 years ago
|
*
|
||
9 years ago
|
* @param array $args array with attributes from parser
|
||
|
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||
|
* @param array $parameter array with compilation parameter
|
||
10 years ago
|
*
|
||
14 years ago
|
* @return string compiled code
|
||
9 years ago
|
* @throws \SmartyCompilerException
|
||
14 years ago
|
*/
|
||
9 years ago
|
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||
14 years ago
|
{
|
||
14 years ago
|
// the following must be assigned at runtime because it will be overwritten in Smarty_Internal_Compile_Append
|
||
14 years ago
|
$this->required_attributes = array('var', 'value');
|
||
|
$this->shorttag_order = array('var', 'value');
|
||
7 years ago
|
$this->optional_attributes = array('scope');
|
||
|
$this->mapCache = array();
|
||
|
$_nocache = false;
|
||
14 years ago
|
// check and get attributes
|
||
13 years ago
|
$_attr = $this->getAttributes($compiler, $args);
|
||
|
// nocache ?
|
||
7 years ago
|
if ($_var = $compiler->getId($_attr[ 'var' ])) {
|
||
|
$_var = "'{$_var}'";
|
||
|
} else {
|
||
|
$_var = $_attr[ 'var' ];
|
||
|
}
|
||
13 years ago
|
if ($compiler->tag_nocache || $compiler->nocache) {
|
||
7 years ago
|
$_nocache = true;
|
||
14 years ago
|
// create nocache var to make it know for further compiling
|
||
7 years ago
|
$compiler->setNocacheInVariable($_attr[ 'var' ]);
|
||
13 years ago
|
}
|
||
14 years ago
|
// scope setup
|
||
7 years ago
|
if ($_attr[ 'noscope' ]) {
|
||
|
$_scope = - 1;
|
||
|
} else {
|
||
|
$_scope = $compiler->convertScope($_attr, $this->valid_scopes);
|
||
|
}
|
||
|
// optional parameter
|
||
7 years ago
|
$_params = '';
|
||
7 years ago
|
if ($_nocache || $_scope) {
|
||
|
$_params .= ' ,' . var_export($_nocache, true);
|
||
13 years ago
|
}
|
||
7 years ago
|
if ($_scope) {
|
||
|
$_params .= ' ,' . $_scope;
|
||
|
}
|
||
|
if (isset($parameter[ 'smarty_internal_index' ])) {
|
||
9 years ago
|
$output =
|
||
7 years ago
|
"<?php \$_tmp_array = isset(\$_smarty_tpl->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";
|
||
7 years ago
|
$output .= "\$_smarty_tpl->_assignInScope({$_var}, \$_tmp_array{$_params});?>";
|
||
14 years ago
|
} else {
|
||
7 years ago
|
$output = "<?php \$_smarty_tpl->_assignInScope({$_var}, {$_attr['value']}{$_params});?>";
|
||
13 years ago
|
}
|
||
|
return $output;
|
||
|
}
|
||
|
}
|