summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruwetews <uwe.tews@googlemail.com>2016-01-02 02:47:32 +0100
committeruwetews <uwe.tews@googlemail.com>2016-01-02 02:47:32 +0100
commit59343127f781446eb0e86001178fc3f8d87f66e6 (patch)
tree499f71ec837ddce94cca5a0725a604be8ccdc5cd
parentbdf9f41da85f6fbe4dffb9f510ddd65454540a97 (diff)
downloadsmarty-59343127f781446eb0e86001178fc3f8d87f66e6.tar.gz
smarty-59343127f781446eb0e86001178fc3f8d87f66e6.tar.bz2
smarty-59343127f781446eb0e86001178fc3f8d87f66e6.zip
- update scope handling
-rw-r--r--change_log.txt3
-rw-r--r--libs/Smarty.class.php4
-rw-r--r--libs/sysplugins/smarty_internal_compile_assign.php4
-rw-r--r--libs/sysplugins/smarty_internal_compile_config_load.php8
-rw-r--r--libs/sysplugins/smarty_internal_compile_include.php13
-rw-r--r--libs/sysplugins/smarty_internal_method_configload.php17
-rw-r--r--libs/sysplugins/smarty_internal_runtime_updatescope.php26
-rw-r--r--libs/sysplugins/smarty_internal_template.php98
8 files changed, 82 insertions, 91 deletions
diff --git a/change_log.txt b/change_log.txt
index aea68376..7bcfd52d 100644
--- a/change_log.txt
+++ b/change_log.txt
@@ -1,4 +1,7 @@
 ===== 3.1.30-dev ===== (xx.xx.xx)
+ 02.01.2016
+ - update scope handling
+
01.01.2016
- remove Smarty::$resource_cache_mode property
diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php
index 4dfd8794..ac99307c 100644
--- a/libs/Smarty.class.php
+++ b/libs/Smarty.class.php
@@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
- const SMARTY_VERSION = '3.1.30-dev/15';
+ const SMARTY_VERSION = '3.1.30-dev/16';
/**
* define variable scopes
@@ -134,8 +134,6 @@ class Smarty extends Smarty_Internal_TemplateBase
const SCOPE_ROOT = 8;
- const SCOPE_SMARTY = 16;
-
const SCOPE_GLOBAL = 32;
const SCOPE_BUBBLE_UP = 64;
diff --git a/libs/sysplugins/smarty_internal_compile_assign.php b/libs/sysplugins/smarty_internal_compile_assign.php
index 3b2eb614..46f17733 100644
--- a/libs/sysplugins/smarty_internal_compile_assign.php
+++ b/libs/sysplugins/smarty_internal_compile_assign.php
@@ -22,7 +22,7 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
* @var array
*/
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true,
- 'smarty' => true, 'tpl_root' => true);
+ 'tpl_root' => true);
/**
* Compiles code for the {assign} tag
@@ -68,8 +68,6 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
$_scope = Smarty::SCOPE_ROOT;
} elseif ($_attr[ 'scope' ] == 'global') {
$_scope = Smarty::SCOPE_GLOBAL;
- } elseif ($_attr[ 'scope' ] == 'smarty') {
- $_scope = Smarty::SCOPE_SMARTY;
} elseif ($_attr[ 'scope' ] == 'tpl_root') {
$_scope = Smarty::SCOPE_TPL_ROOT;
}
diff --git a/libs/sysplugins/smarty_internal_compile_config_load.php b/libs/sysplugins/smarty_internal_compile_config_load.php
index d2e50a08..e957086d 100644
--- a/libs/sysplugins/smarty_internal_compile_config_load.php
+++ b/libs/sysplugins/smarty_internal_compile_config_load.php
@@ -45,8 +45,8 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
*
* @var array
*/
- public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true,
- 'smarty' => true, 'tpl_root' => true);
+ public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true,
+ 'tpl_root' => true);
/**
* Compiles code for the {config_load} tag
@@ -84,10 +84,6 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
$_scope = Smarty::SCOPE_PARENT;
} elseif ($_attr['scope'] == 'root') {
$_scope = Smarty::SCOPE_ROOT;
- } elseif ($_attr['scope'] == 'global') {
- $_scope = Smarty::SCOPE_GLOBAL;
- } elseif ($_attr['scope'] == 'smarty') {
- $_scope = Smarty::SCOPE_SMARTY;
} elseif ($_attr['scope'] == 'tpl_root') {
$_scope = Smarty::SCOPE_TPL_ROOT;
}
diff --git a/libs/sysplugins/smarty_internal_compile_include.php b/libs/sysplugins/smarty_internal_compile_include.php
index 53971a82..a87fbed8 100644
--- a/libs/sysplugins/smarty_internal_compile_include.php
+++ b/libs/sysplugins/smarty_internal_compile_include.php
@@ -58,8 +58,8 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
*
* @var array
*/
- public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true,
- 'smarty' => true, 'tpl_root' => true);
+ public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true,
+ 'tpl_root' => true);
/**
* Compiles code for the {include} tag
@@ -124,16 +124,11 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$_scope = Smarty::SCOPE_PARENT;
} elseif ($_attr['scope'] == 'root') {
$_scope = Smarty::SCOPE_ROOT;
- } elseif ($_attr['scope'] == 'global') {
- $_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;
- }
+ $_scope += (isset($_attr[ 'bubble_up' ]) && $_attr[ 'bubble_up' ] == 'false') ? 0 :
+ Smarty::SCOPE_BUBBLE_UP;
}
}
diff --git a/libs/sysplugins/smarty_internal_method_configload.php b/libs/sysplugins/smarty_internal_method_configload.php
index 7b99e35c..b7d4283e 100644
--- a/libs/sysplugins/smarty_internal_method_configload.php
+++ b/libs/sysplugins/smarty_internal_method_configload.php
@@ -83,10 +83,17 @@ class Smarty_Internal_Method_ConfigLoad
{
$this->_assignConfigVars($tpl->parent, $tpl, $_config_vars);
$scope = $tpl->source->scope;
- if (!$scope && !$tpl->scope) {
+ $scopes = array();
+ if ($scope) {
+ $scopes[] = $scope;
+ }
+ if ($tpl->scope) {
+ $scopes[] = $tpl->scope;
+ }
+ if (empty($scopes)) {
return;
}
- foreach (array($scope, $tpl->scope) as $s) {
+ foreach ($scopes as $s) {
$s = ($bubble_up = $s >= Smarty::SCOPE_BUBBLE_UP) ? $s - Smarty::SCOPE_BUBBLE_UP : $s;
if ($bubble_up && $s) {
$ptr = $tpl->parent->parent;
@@ -103,15 +110,11 @@ class Smarty_Internal_Method_ConfigLoad
}
if ($s == Smarty::SCOPE_TPL_ROOT) {
continue;
- } elseif ($s == Smarty::SCOPE_SMARTY) {
- $this->_assignConfigVars($tpl->smarty, $tpl, $_config_vars);
- } elseif ($s == Smarty::SCOPE_GLOBAL) {
- $this->_assignConfigVars($tpl->smarty, $tpl, $_config_vars);
} elseif ($s == Smarty::SCOPE_ROOT) {
while (isset($ptr->parent)) {
$ptr = $ptr->parent;
+ $this->_assignConfigVars($ptr, $tpl, $_config_vars);
}
- $this->_assignConfigVars($ptr, $tpl, $_config_vars);
}
}
}
diff --git a/libs/sysplugins/smarty_internal_runtime_updatescope.php b/libs/sysplugins/smarty_internal_runtime_updatescope.php
index b99acf42..5c236c6c 100644
--- a/libs/sysplugins/smarty_internal_runtime_updatescope.php
+++ b/libs/sysplugins/smarty_internal_runtime_updatescope.php
@@ -34,12 +34,25 @@ class Smarty_Internal_Runtime_UpdateScope
foreach ($scopes as $s) {
$s = ($bubble_up = $s >= Smarty::SCOPE_BUBBLE_UP) ? $s - Smarty::SCOPE_BUBBLE_UP : $s;
if ($bubble_up && $s) {
- if (isset($tpl->parent)) {
+ $oldGlobal = null;
+ if ($s == Smarty::SCOPE_GLOBAL) {
+ $oldGlobal =
+ isset(Smarty::$global_tpl_vars[ $varName ]) ? Smarty::$global_tpl_vars[ $varName ] : null;
+ Smarty::$global_tpl_vars[ $varName ] = $tpl->tpl_vars[ $varName ];
+ }
+ if (isset($tpl->parent) && $tpl->parent->_objType == 2) {
$ptr = $tpl->parent;
+ if ($s == Smarty::SCOPE_GLOBAL && isset($oldGlobal) && isset($ptr->tpl_vars[ $varName ]) &&
+ $ptr->tpl_vars[ $varName ] !== $oldGlobal
+ ) {
+ continue;
+ }
$ptr->tpl_vars[ $varName ] = $tpl->tpl_vars[ $varName ];
if (isset($ptr->parent)) {
$ptr = $ptr->parent;
}
+ } elseif (isset($tpl->parent)) {
+ $ptr = $tpl->parent;
}
if ($s == Smarty::SCOPE_PARENT) {
continue;
@@ -50,15 +63,10 @@ class Smarty_Internal_Runtime_UpdateScope
}
if ($s == Smarty::SCOPE_TPL_ROOT) {
continue;
- } elseif ($s == Smarty::SCOPE_SMARTY) {
- $tpl->smarty->tpl_vars[ $varName ] = $tpl->tpl_vars[ $varName ];
- } elseif ($s == Smarty::SCOPE_GLOBAL) {
- Smarty::$global_tpl_vars[ $varName ] = $tpl->tpl_vars[ $varName ];
- } elseif ($s == Smarty::SCOPE_ROOT) {
- while (isset($ptr->parent)) {
- $ptr = $ptr->parent;
- }
+ }
+ while (isset($ptr) && $s != Smarty::SCOPE_GLOBAL) {
$ptr->tpl_vars[ $varName ] = $tpl->tpl_vars[ $varName ];
+ $ptr = isset($ptr->parent) ? $ptr->parent : null;
}
}
}
diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php
index fea9012e..1adc102d 100644
--- a/libs/sysplugins/smarty_internal_template.php
+++ b/libs/sysplugins/smarty_internal_template.php
@@ -119,7 +119,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
/**
* render template
*
- * @param bool $no_output_filter if true do not run output filter
+ * @param bool $no_output_filter if true do not run output filter
* @param null|bool $display true: display, false: fetch null: sub-template
*
* @return string
@@ -168,8 +168,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
isset($content) ? $content : ob_get_clean());
} else {
if ((!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) &&
- !$no_output_filter && (isset($this->smarty->autoload_filters['output']) ||
- isset($this->smarty->registered_filters['output']))
+ !$no_output_filter && (isset($this->smarty->autoload_filters[ 'output' ]) ||
+ isset($this->smarty->registered_filters[ 'output' ]))
) {
echo $this->smarty->ext->_filterHandler->runFilter('output', ob_get_clean(), $this);
} else {
@@ -197,14 +197,15 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
foreach ($this->compiled->required_plugins as $code => $tmp1) {
foreach ($tmp1 as $name => $tmp) {
foreach ($tmp as $type => $data) {
- $this->parent->compiled->required_plugins[$code][$name][$type] = $data;
+ $this->parent->compiled->required_plugins[ $code ][ $name ][ $type ] = $data;
}
}
}
}
if (!$no_output_filter &&
(!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) &&
- (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))
+ (isset($this->smarty->autoload_filters[ 'output' ]) ||
+ isset($this->smarty->registered_filters[ 'output' ]))
) {
return $this->smarty->ext->_filterHandler->runFilter('output', ob_get_clean(), $this);
}
@@ -266,8 +267,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
if (isset($tpl->compiled->file_dependency[ $uid ])) {
list($filepath, $timestamp, $type) = $tpl->compiled->file_dependency[ $uid ];
$tpl->source =
- new Smarty_Template_Source(isset($tpl->smarty->_cache['resource_handlers'][$type]) ?
- $tpl->smarty->_cache['resource_handlers'][$type] :
+ new Smarty_Template_Source(isset($tpl->smarty->_cache[ 'resource_handlers' ][ $type ]) ?
+ $tpl->smarty->_cache[ 'resource_handlers' ][ $type ] :
Smarty_Resource::load($tpl->smarty, $type), $tpl->smarty,
$filepath, $type, $filepath);
$tpl->source->filepath = $filepath;
@@ -295,30 +296,22 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
// set template scope
$tpl->scope = $scope;
$scopePtr = false;
- if ($scope & ~Smarty::SCOPE_BUBBLE_UP) {
- if ($scope == Smarty::SCOPE_GLOBAL) {
- $tpl->tpl_vars = Smarty::$global_tpl_vars;
- $tpl->config_vars = $tpl->smarty->config_vars;
- $scopePtr = true;
+ $scope = $scope & ~Smarty::SCOPE_BUBBLE_UP;
+ if ($scope) {
+ if ($scope == Smarty::SCOPE_PARENT) {
+ $scopePtr = $this;
} else {
- if ($scope == Smarty::SCOPE_PARENT) {
- $scopePtr = $this;
- } elseif ($scope == Smarty::SCOPE_SMARTY) {
- $scopePtr = $tpl->smarty;
- } else {
- $scopePtr = $tpl;
- while (isset($scopePtr->parent)) {
- if (!$scopePtr->_isParentTemplate() && $scope & Smarty::SCOPE_TPL_ROOT) {
- break;
- }
- $scopePtr = $scopePtr->parent;
+ $scopePtr = $tpl;
+ while (isset($scopePtr->parent)) {
+ if (!$scopePtr->_isParentTemplate() && $scope & Smarty::SCOPE_TPL_ROOT) {
+ break;
}
+ $scopePtr = $scopePtr->parent;
}
- $tpl->tpl_vars = $scopePtr->tpl_vars;
- $tpl->config_vars = $scopePtr->config_vars;
}
+ $tpl->tpl_vars = $scopePtr->tpl_vars;
+ $tpl->config_vars = $scopePtr->config_vars;
}
-
if (!isset($tpl->smarty->_cache[ 'tplObjects' ][ $tpl->templateId ]) && !$tpl->source->handler->recompiled) {
// if template is called multiple times set flag to to cache template objects
$forceTplCache = $forceTplCache ||
@@ -326,7 +319,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
$tpl->smarty->_cache[ 'subTplInfo' ][ $tpl->template_resource ] > 1);
// check if template object should be cached
if ($tpl->_isParentTemplate() && isset($tpl->smarty->_cache[ 'tplObjects' ][ $tpl->parent->templateId ]) ||
- $forceTplCache) {
+ $forceTplCache
+ ) {
$tpl->smarty->_cache[ 'tplObjects' ][ $tpl->templateId ] = $tpl;
}
}
@@ -358,13 +352,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
}
}
if ($scopePtr) {
- if ($scope == Smarty::SCOPE_GLOBAL) {
- Smarty::$global_tpl_vars = $tpl->tpl_vars;
- $tpl->smarty->config_vars = $tpl->config_vars;
- } else {
- $scopePtr->tpl_vars = $tpl->tpl_vars;
- $scopePtr->config_vars = $tpl->config_vars;
- }
+ $scopePtr->tpl_vars = $tpl->tpl_vars;
+ $scopePtr->config_vars = $tpl->config_vars;
}
}
@@ -453,27 +442,29 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
public function _decodeProperties(Smarty_Internal_Template $tpl, $properties, $cache = false)
{
$is_valid = true;
- if (Smarty::SMARTY_VERSION != $properties['version']) {
+ if (Smarty::SMARTY_VERSION != $properties[ 'version' ]) {
// new version must rebuild
$is_valid = false;
- } elseif ($is_valid && !empty($properties['file_dependency']) &&
+ } elseif ($is_valid && !empty($properties[ 'file_dependency' ]) &&
((!$cache && $tpl->smarty->compile_check) || $tpl->smarty->compile_check == 1)
) {
// check file dependencies at compiled code
- foreach ($properties['file_dependency'] as $_file_to_check) {
- if ($_file_to_check[2] == 'file' || $_file_to_check[2] == 'extends' || $_file_to_check[2] == 'php') {
- if ($tpl->source->filepath == $_file_to_check[0]) {
+ foreach ($properties[ 'file_dependency' ] as $_file_to_check) {
+ if ($_file_to_check[ 2 ] == 'file' || $_file_to_check[ 2 ] == 'extends' ||
+ $_file_to_check[ 2 ] == 'php'
+ ) {
+ if ($tpl->source->filepath == $_file_to_check[ 0 ]) {
// do not recheck current template
continue;
//$mtime = $tpl->source->getTimeStamp();
} else {
// file and php types can be checked without loading the respective resource handlers
- $mtime = is_file($_file_to_check[0]) ? filemtime($_file_to_check[0]) : false;
+ $mtime = is_file($_file_to_check[ 0 ]) ? filemtime($_file_to_check[ 0 ]) : false;
}
- } elseif ($_file_to_check[2] == 'string') {
+ } elseif ($_file_to_check[ 2 ] == 'string') {
continue;
} else {
- $handler = Smarty_Resource::load($tpl->smarty, $_file_to_check[2]);
+ $handler = Smarty_Resource::load($tpl->smarty, $_file_to_check[ 2 ]);
if ($handler->checkTimestamps()) {
$source = Smarty_Template_Source::load($tpl, $tpl->smarty, $_file_to_check[ 0 ]);
$mtime = $source->getTimeStamp();
@@ -481,7 +472,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
continue;
}
}
- if (!$mtime || $mtime > $_file_to_check[1]) {
+ if (!$mtime || $mtime > $_file_to_check[ 1 ]) {
$is_valid = false;
break;
}
@@ -489,32 +480,31 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
}
if ($cache) {
// CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc
- if ($tpl->caching === Smarty::CACHING_LIFETIME_SAVED && $properties['cache_lifetime'] >= 0 &&
- (time() > ($tpl->cached->timestamp + $properties['cache_lifetime']))
+ if ($tpl->caching === Smarty::CACHING_LIFETIME_SAVED && $properties[ 'cache_lifetime' ] >= 0 &&
+ (time() > ($tpl->cached->timestamp + $properties[ 'cache_lifetime' ]))
) {
$is_valid = false;
}
- $tpl->cached->cache_lifetime = $properties['cache_lifetime'];
+ $tpl->cached->cache_lifetime = $properties[ 'cache_lifetime' ];
$tpl->cached->valid = $is_valid;
$resource = $tpl->cached;
} else {
$tpl->mustCompile = !$is_valid;
$resource = $tpl->compiled;
- $resource->includes = isset($properties['includes']) ? $properties['includes'] : array();
+ $resource->includes = isset($properties[ 'includes' ]) ? $properties[ 'includes' ] : array();
}
if ($is_valid) {
- $resource->unifunc = $properties['unifunc'];
- $resource->has_nocache_code = $properties['has_nocache_code'];
+ $resource->unifunc = $properties[ 'unifunc' ];
+ $resource->has_nocache_code = $properties[ 'has_nocache_code' ];
// $tpl->compiled->nocache_hash = $properties['nocache_hash'];
- $resource->file_dependency = $properties['file_dependency'];
- if (isset($properties['tpl_function'])) {
- $tpl->tpl_function = $properties['tpl_function'];
+ $resource->file_dependency = $properties[ 'file_dependency' ];
+ if (isset($properties[ 'tpl_function' ])) {
+ $tpl->tpl_function = $properties[ 'tpl_function' ];
}
}
- return $is_valid && !function_exists($properties['unifunc']);
+ return $is_valid && !function_exists($properties[ 'unifunc' ]);
}
-
/**
* Compiles the template
* If the template is not evaluated the compiled template is saved on disk