mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
add test for valid scope name
This commit is contained in:
@@ -16,6 +16,14 @@
|
|||||||
*/
|
*/
|
||||||
class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
|
class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Valid scope names
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true,
|
||||||
|
'smarty' => true, 'tpl_root' => true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiles code for the {assign} tag
|
* Compiles code for the {assign} tag
|
||||||
*
|
*
|
||||||
@@ -31,9 +39,8 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
|
|||||||
// the following must be assigned at runtime because it will be overwritten in Smarty_Internal_Compile_Append
|
// the following must be assigned at runtime because it will be overwritten in Smarty_Internal_Compile_Append
|
||||||
$this->required_attributes = array('var', 'value');
|
$this->required_attributes = array('var', 'value');
|
||||||
$this->shorttag_order = array('var', 'value');
|
$this->shorttag_order = array('var', 'value');
|
||||||
$this->optional_attributes = array('scope');
|
$this->optional_attributes = array('scope', 'bubble_up');
|
||||||
$_nocache = 'null';
|
$_nocache = 'null';
|
||||||
$_scope = Smarty::SCOPE_LOCAL;
|
|
||||||
// check and get attributes
|
// check and get attributes
|
||||||
$_attr = $this->getAttributes($compiler, $args);
|
$_attr = $this->getAttributes($compiler, $args);
|
||||||
// nocache ?
|
// nocache ?
|
||||||
@@ -47,31 +54,36 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// scope setup
|
// scope setup
|
||||||
|
$_scope = Smarty::SCOPE_LOCAL;
|
||||||
if (isset($_attr['scope'])) {
|
if (isset($_attr['scope'])) {
|
||||||
$_attr['scope'] = trim($_attr['scope'], "'\"");
|
$_attr['scope'] = trim($_attr['scope'], "'\"");
|
||||||
if ($_attr['scope'] == 'parent') {
|
if (!isset($this->valid_scopes[$_attr['scope']])) {
|
||||||
$_scope = Smarty::SCOPE_PARENT;
|
$compiler->trigger_template_error("illegal value '{$_attr['scope']}' for \"scope\" attribute", null, true);
|
||||||
} elseif ($_attr['scope'] == 'root') {
|
}
|
||||||
$_scope = Smarty::SCOPE_ROOT;
|
if ($_attr['scope'] != 'local') {
|
||||||
} elseif ($_attr['scope'] == 'global') {
|
if ($_attr['scope'] == 'parent') {
|
||||||
$_scope = Smarty::SCOPE_GLOBAL;
|
$_scope = Smarty::SCOPE_PARENT;
|
||||||
} elseif ($_attr['scope'] == 'smarty') {
|
} elseif ($_attr['scope'] == 'root') {
|
||||||
$_scope = Smarty::SCOPE_SMARTY;
|
$_scope = Smarty::SCOPE_ROOT;
|
||||||
} elseif ($_attr['scope'] == 'tpl_root') {
|
} elseif ($_attr['scope'] == 'global') {
|
||||||
$_scope = Smarty::SCOPE_TPL_ROOT;
|
$_scope = Smarty::SCOPE_GLOBAL;
|
||||||
} else {
|
} elseif ($_attr['scope'] == 'smarty') {
|
||||||
$compiler->trigger_template_error('illegal value for "scope" attribute', null, true);
|
$_scope = Smarty::SCOPE_SMARTY;
|
||||||
|
} elseif ($_attr['scope'] == 'tpl_root') {
|
||||||
|
$_scope = Smarty::SCOPE_TPL_ROOT;
|
||||||
|
}
|
||||||
|
$_scope += (isset($_attr['bubble_up']) && $_attr['bubble_up'] == 'false') ? 0 : Smarty::SCOPE_BUBBLE_UP;
|
||||||
}
|
}
|
||||||
$_scope += (isset($_attr['bubble_up']) && $_attr['bubble_up'] == 'false') ? 0 : Smarty::SCOPE_BUBBLE_UP;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// compiled output
|
// compiled output
|
||||||
if (isset($parameter['smarty_internal_index'])) {
|
if (isset($parameter['smarty_internal_index'])) {
|
||||||
$output = "<?php \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, $_attr[var], $_nocache);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];";
|
$output =
|
||||||
|
"<?php \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, $_attr[var], $_nocache);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];";
|
||||||
} else {
|
} else {
|
||||||
// implement Smarty2's behaviour of variables assigned by reference
|
// implement Smarty2's behaviour of variables assigned by reference
|
||||||
if ($compiler->template->smarty instanceof SmartyBC) {
|
if ($compiler->template->smarty instanceof SmartyBC) {
|
||||||
$output = "<?php if (isset(\$_smarty_tpl->tpl_vars[$_attr[var]])) {\$_smarty_tpl->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";
|
$output =
|
||||||
|
"<?php if (isset(\$_smarty_tpl->tpl_vars[$_attr[var]])) {\$_smarty_tpl->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";
|
||||||
$output .= "\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value = $_attr[value]; \$_smarty_tpl->tpl_vars[$_attr[var]]->nocache = $_nocache;";
|
$output .= "\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value = $_attr[value]; \$_smarty_tpl->tpl_vars[$_attr[var]]->nocache = $_nocache;";
|
||||||
$output .= "\n} else \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_Variable($_attr[value], $_nocache);";
|
$output .= "\n} else \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_Variable($_attr[value], $_nocache);";
|
||||||
} else {
|
} else {
|
||||||
|
@@ -53,6 +53,14 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
|||||||
*/
|
*/
|
||||||
public $optional_attributes = array('_any');
|
public $optional_attributes = array('_any');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Valid scope names
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true,
|
||||||
|
'smarty' => true, 'tpl_root' => true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiles code for the {include} tag
|
* Compiles code for the {include} tag
|
||||||
*
|
*
|
||||||
@@ -104,23 +112,29 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
|||||||
$_assign = $_attr['assign'];
|
$_assign = $_attr['assign'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$_parent_scope = Smarty::SCOPE_LOCAL;
|
// scope setup
|
||||||
|
$_scope = Smarty::SCOPE_LOCAL;
|
||||||
if (isset($_attr['scope'])) {
|
if (isset($_attr['scope'])) {
|
||||||
$_attr['scope'] = trim($_attr['scope'], "'\"");
|
$_attr['scope'] = trim($_attr['scope'], "'\"");
|
||||||
if ($_attr['scope'] == 'parent') {
|
if (!isset($this->valid_scopes[$_attr['scope']])) {
|
||||||
$_parent_scope = Smarty::SCOPE_PARENT;
|
$compiler->trigger_template_error("illegal value '{$_attr['scope']}' for \"scope\" attribute", null, true);
|
||||||
} elseif ($_attr['scope'] == 'root') {
|
}
|
||||||
$_parent_scope = Smarty::SCOPE_ROOT;
|
if ($_attr['scope'] != 'local') {
|
||||||
} elseif ($_attr['scope'] == 'global') {
|
if ($_attr['scope'] == 'parent') {
|
||||||
$_parent_scope = Smarty::SCOPE_GLOBAL;
|
$_scope = Smarty::SCOPE_PARENT;
|
||||||
} elseif ($_attr['scope'] == 'smarty') {
|
} elseif ($_attr['scope'] == 'root') {
|
||||||
$_parent_scope = Smarty::SCOPE_SMARTY;
|
$_scope = Smarty::SCOPE_ROOT;
|
||||||
} elseif ($_attr['scope'] == 'tpl_root') {
|
} elseif ($_attr['scope'] == 'global') {
|
||||||
$_parent_scope = Smarty::SCOPE_TPL_ROOT;
|
$_scope = Smarty::SCOPE_GLOBAL;
|
||||||
|
} elseif ($_attr['scope'] == 'smarty') {
|
||||||
|
$_scope = Smarty::SCOPE_SMARTY;
|
||||||
|
} elseif ($_attr['scope'] == 'tpl_root') {
|
||||||
|
$_scope = Smarty::SCOPE_TPL_ROOT;
|
||||||
|
}
|
||||||
|
if ($_attr['bubble_up'] === true) {
|
||||||
|
$_scope = $_scope + Smarty::SCOPE_BUBBLE_UP;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if ($_attr['bubble_up'] === true) {
|
|
||||||
$_parent_scope = $_parent_scope + Smarty::SCOPE_BUBBLE_UP;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set flag to cache subtemplate object when called within loop or template name is variable.
|
// set flag to cache subtemplate object when called within loop or template name is variable.
|
||||||
@@ -226,7 +240,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
|||||||
// remaining attributes must be assigned as smarty variable
|
// remaining attributes must be assigned as smarty variable
|
||||||
$_vars_nc = '';
|
$_vars_nc = '';
|
||||||
if (!empty($_attr)) {
|
if (!empty($_attr)) {
|
||||||
if ($_parent_scope == Smarty::SCOPE_LOCAL) {
|
if ($_scope == Smarty::SCOPE_LOCAL) {
|
||||||
$_pairs = array();
|
$_pairs = array();
|
||||||
// create variables
|
// create variables
|
||||||
foreach ($_attr as $key => $value) {
|
foreach ($_attr as $key => $value) {
|
||||||
@@ -255,7 +269,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
|||||||
if (isset($_assign)) {
|
if (isset($_assign)) {
|
||||||
$_output .= "ob_start();\n";
|
$_output .= "ob_start();\n";
|
||||||
}
|
}
|
||||||
$_output .= "\$_smarty_tpl->smarty->ext->_subtemplate->render(\$_smarty_tpl, {$fullResourceName}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_parent_scope}, {$_cache_tpl}, '{$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['uid']}', '{$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['func']}');\n";
|
$_output .= "\$_smarty_tpl->smarty->ext->_subtemplate->render(\$_smarty_tpl, {$fullResourceName}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_scope}, {$_cache_tpl}, '{$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['uid']}', '{$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['func']}');\n";
|
||||||
if (isset($_assign)) {
|
if (isset($_assign)) {
|
||||||
$_output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n";
|
$_output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n";
|
||||||
}
|
}
|
||||||
@@ -278,7 +292,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
|||||||
if (isset($_assign)) {
|
if (isset($_assign)) {
|
||||||
$_output .= "ob_start();\n";
|
$_output .= "ob_start();\n";
|
||||||
}
|
}
|
||||||
$_output .= "\$_smarty_tpl->smarty->ext->_subtemplate->render(\$_smarty_tpl, {$fullResourceName}, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope, {$_cache_tpl});\n";
|
$_output .= "\$_smarty_tpl->smarty->ext->_subtemplate->render(\$_smarty_tpl, {$fullResourceName}, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_scope, {$_cache_tpl});\n";
|
||||||
if (isset($_assign)) {
|
if (isset($_assign)) {
|
||||||
$_output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n";
|
$_output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user