mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-09 12:54:26 +02:00
- added global variable scope SMARTY_GLOBAL_SCOPE
- enable 'variable' filter by default
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
04/10/2009
|
04/10/2009
|
||||||
|
- added global variable scope SMARTY_GLOBAL_SCOPE
|
||||||
|
- enable 'variable' filter by default
|
||||||
- fixed {$smarty.block.parent.foo}
|
- fixed {$smarty.block.parent.foo}
|
||||||
- implementation of a 'variable' filter as replacement for default modifier
|
- implementation of a 'variable' filter as replacement for default modifier
|
||||||
|
|
||||||
|
@@ -45,6 +45,7 @@ if (!defined('SMARTY_DIR')) {
|
|||||||
define('SMARTY_LOCAL_SCOPE', 0);
|
define('SMARTY_LOCAL_SCOPE', 0);
|
||||||
define('SMARTY_PARENT_SCOPE', 1);
|
define('SMARTY_PARENT_SCOPE', 1);
|
||||||
define('SMARTY_ROOT_SCOPE', 2);
|
define('SMARTY_ROOT_SCOPE', 2);
|
||||||
|
define('SMARTY_GLOBAL_SCOPE', 3);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* load required base class for creation of the smarty object
|
* load required base class for creation of the smarty object
|
||||||
@@ -156,12 +157,12 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
// autoload filter
|
// autoload filter
|
||||||
public $autoload_filters = array();
|
public $autoload_filters = array();
|
||||||
// status of filter on variable output
|
// status of filter on variable output
|
||||||
public $variable_filter = false;
|
public $variable_filter = true;
|
||||||
// cache resorce objects
|
// cache resorce objects
|
||||||
public $cache_resource_objects = array();
|
public $cache_resource_objects = array();
|
||||||
// write file object
|
// write file object
|
||||||
public $write_file_object = null;
|
public $write_file_object = null;
|
||||||
// global smarty vars
|
// global internal smarty vars
|
||||||
public $_smarty_vars = array();
|
public $_smarty_vars = array();
|
||||||
// start time for execution time calculation
|
// start time for execution time calculation
|
||||||
public $start_time = 0;
|
public $start_time = 0;
|
||||||
|
@@ -41,7 +41,13 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase {
|
|||||||
$_attr = $this->_get_attributes($args);
|
$_attr = $this->_get_attributes($args);
|
||||||
|
|
||||||
if (isset($_attr['scope'])) {
|
if (isset($_attr['scope'])) {
|
||||||
$_scope = trim($_attr['scope'],'\'');
|
if ($_attr['scope'] == '\'parent\'') {
|
||||||
|
$_scope = SMARTY_PARENT_SCOPE;
|
||||||
|
} elseif ($_attr['scope'] == '\'root\'') {
|
||||||
|
$_scope = SMARTY_ROOT_SCOPE;
|
||||||
|
} elseif ($_attr['scope'] == '\'global\'') {
|
||||||
|
$_scope = SMARTY_GLOBAL_SCOPE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_attr['index'])) {
|
if (isset($_attr['index'])) {
|
||||||
|
@@ -1,47 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Smarty Internal Plugin Compile Assign
|
|
||||||
*
|
|
||||||
* Compiles the {assign} tag
|
|
||||||
*
|
|
||||||
* @package Smarty
|
|
||||||
* @subpackage Compiler
|
|
||||||
* @author Uwe Tews
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Smarty Internal Plugin Compile Assign Global Class
|
|
||||||
*/
|
|
||||||
class Smarty_Internal_Compile_Assign_Global extends Smarty_Internal_CompileBase {
|
|
||||||
/**
|
|
||||||
* Compiles code for the {assign_global} tag
|
|
||||||
*
|
|
||||||
* @param array $args array with attributes from parser
|
|
||||||
* @param object $compiler compiler object
|
|
||||||
* @return string compiled code
|
|
||||||
*/
|
|
||||||
public function compile($args, $compiler)
|
|
||||||
{
|
|
||||||
$this->compiler = $compiler;
|
|
||||||
$this->required_attributes = array('var', 'value');
|
|
||||||
$this->optional_attributes = array('nocache');
|
|
||||||
|
|
||||||
$_nocache = 'false';
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
// compiled output
|
|
||||||
return "<?php \$_smarty_tpl->smarty->assign_global($_attr[var],$_attr[value],$_nocache);?>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
@@ -40,6 +40,8 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase {
|
|||||||
$_parent_scope = SMARTY_PARENT_SCOPE;
|
$_parent_scope = SMARTY_PARENT_SCOPE;
|
||||||
} elseif ($_attr['scope'] == '\'root\'') {
|
} elseif ($_attr['scope'] == '\'root\'') {
|
||||||
$_parent_scope = SMARTY_ROOT_SCOPE;
|
$_parent_scope = SMARTY_ROOT_SCOPE;
|
||||||
|
} elseif ($_attr['scope'] == '\'global\'') {
|
||||||
|
$_parent_scope = SMARTY_GLOBAL_SCOPE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -80,8 +80,6 @@ class Smarty_Internal_Compile_Smarty extends Smarty_Internal_CompileBase {
|
|||||||
|
|
||||||
case 'config':
|
case 'config':
|
||||||
return "\$_smarty_tpl->getConfigVariable($_index[1])";
|
return "\$_smarty_tpl->getConfigVariable($_index[1])";
|
||||||
case 'global':
|
|
||||||
return "\$_smarty_tpl->smarty->getGlobalVariable($_index[1])->value";
|
|
||||||
case 'block':
|
case 'block':
|
||||||
if ($_index[1] == '\'parent\'') {
|
if ($_index[1] == '\'parent\'') {
|
||||||
return "'" . addcslashes($compiler->template->block_data[trim($_index[2], "'")]['source'], "'") . "'";
|
return "'" . addcslashes($compiler->template->block_data[trim($_index[2], "'")]['source'], "'") . "'";
|
||||||
|
@@ -553,17 +553,34 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
|||||||
} else {
|
} else {
|
||||||
// create variable in parent
|
// create variable in parent
|
||||||
$this->parent->tpl_vars[$_key] = clone $_value;
|
$this->parent->tpl_vars[$_key] = clone $_value;
|
||||||
|
$this->smarty->tpl_vars[$_key]->scope = SMARTY_LOCAL_SCOPE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($scope == SMARTY_ROOT_SCOPE || $this->tpl_vars[$_key]->scope == SMARTY_ROOT_SCOPE) {
|
if ($scope == SMARTY_ROOT_SCOPE || $this->tpl_vars[$_key]->scope == SMARTY_ROOT_SCOPE) {
|
||||||
if (isset($this->smarty->tpl_vars[$_key])) {
|
$_ptr = $this;
|
||||||
|
// find root
|
||||||
|
while ($_ptr->parent != null) {
|
||||||
|
$_ptr = $_ptr->parent;
|
||||||
|
}
|
||||||
|
if (isset($_ptr->tpl_vars[$_key])) {
|
||||||
// variable is already defined in root, copy value
|
// variable is already defined in root, copy value
|
||||||
$this->smarty->tpl_vars[$_key]->value = $this->tpl_vars[$_key]->value;
|
$_ptr->tpl_vars[$_key]->value = $this->tpl_vars[$_key]->value;
|
||||||
} else {
|
} else {
|
||||||
// create variable in root
|
// create variable in root
|
||||||
$this->smarty->tpl_vars[$_key] = clone $_value;
|
$_ptr->tpl_vars[$_key] = clone $_value;
|
||||||
|
$_ptr->tpl_vars[$_key]->scope = SMARTY_LOCAL_SCOPE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($scope == SMARTY_GLOBAL_SCOPE || $this->tpl_vars[$_key]->scope == SMARTY_GLOBAL_SCOPE) {
|
||||||
|
if (isset($this->smarty->global_tpl_vars[$_key])) {
|
||||||
|
// variable is already defined in root, copy value
|
||||||
|
$this->smarty->global_tpl_vars[$_key]->value = $this->tpl_vars[$_key]->value;
|
||||||
|
} else {
|
||||||
|
// create variable in root
|
||||||
|
$this->smarty->global_tpl_vars[$_key] = clone $_value;
|
||||||
|
}
|
||||||
|
$this->smarty->global_tpl_vars[$_key]->scope = SMARTY_LOCAL_SCOPE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -193,7 +193,8 @@ class Smarty_Internal_TemplateBase {
|
|||||||
{
|
{
|
||||||
if ($_ptr === null) {
|
if ($_ptr === null) {
|
||||||
$_ptr = $this;
|
$_ptr = $this;
|
||||||
} while ($_ptr !== null) {
|
}
|
||||||
|
while ($_ptr !== null) {
|
||||||
if (isset($_ptr->tpl_vars[$variable])) {
|
if (isset($_ptr->tpl_vars[$variable])) {
|
||||||
// found it, return it
|
// found it, return it
|
||||||
return $_ptr->tpl_vars[$variable];
|
return $_ptr->tpl_vars[$variable];
|
||||||
@@ -205,6 +206,11 @@ class Smarty_Internal_TemplateBase {
|
|||||||
$_ptr = null;
|
$_ptr = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$_ptr = Smarty::instance();
|
||||||
|
if (isset($_ptr->global_tpl_vars[$variable])) {
|
||||||
|
// found it, return it
|
||||||
|
return $_ptr->global_tpl_vars[$variable];
|
||||||
|
}
|
||||||
if (Smarty::$error_unassigned) {
|
if (Smarty::$error_unassigned) {
|
||||||
throw new Exception('Undefined Smarty variable "' . $variable . '"');
|
throw new Exception('Undefined Smarty variable "' . $variable . '"');
|
||||||
} else {
|
} else {
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -47,6 +47,11 @@ class Smarty_Method_Get_Template_Vars extends Smarty_Internal_Base {
|
|||||||
$_ptr = null;
|
$_ptr = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($search_parents) {
|
||||||
|
foreach ($this->smarty->global_tpl_vars AS $key => $var) {
|
||||||
|
$_result[$key] = $var->value;
|
||||||
|
}
|
||||||
|
}
|
||||||
return $_result;
|
return $_result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user