diff --git a/change_log.txt b/change_log.txt index 4785e61d..5de594bf 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,7 +1,8 @@ ===== 3.1.31-dev ===== (xx.xx.xx) 11.09.2016 - improvement {math} misleading E_USER_WARNING messages when parameter value = null https://github.com/smarty-php/smarty/issues/288 - + - improvement move often used code snippets into methods + 09.09.2016 - bugfix/optimization {foreach} did not execute the {foreachelse} when iterating empty objects https://github.com/smarty-php/smarty/pull/287 - bugfix {foreach} must keep the @properties when restoring a saved $item variable as the properties might be used outside {foreach} https://github.com/smarty-php/smarty/issues/267 diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 323f8a9f..a77a1daa 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -114,7 +114,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.31-dev/16'; + const SMARTY_VERSION = '3.1.31-dev/17'; /** * define variable scopes @@ -1243,6 +1243,16 @@ class Smarty extends Smarty_Internal_TemplateBase $this->_cache[ 'tplObjects' ] = array(); } + /** + * Get Smarty object + * + * @return Smarty + */ + public function _getSmartyObj() + { + return $this; + } + /** * @param boolean $compile_check */ diff --git a/libs/sysplugins/smarty_internal_data.php b/libs/sysplugins/smarty_internal_data.php index 62366085..fd9c3020 100644 --- a/libs/sysplugins/smarty_internal_data.php +++ b/libs/sysplugins/smarty_internal_data.php @@ -14,7 +14,8 @@ * @package Smarty * @subpackage Template * - * @property int $scope + * @property int $scope + * @property Smarty $smarty * The following methods will be dynamically loaded by the extension handler when they are called. * They are located in a corresponding Smarty_Internal_Method_xxxx class * @@ -100,7 +101,7 @@ class Smarty_Internal_Data } } else { if ($tpl_var != '') { - if ($this->_objType == 2) { + if ($this->_objType === 2) { /** @var Smarty_Internal_Template $this */ $this->_assignInScope($tpl_var, $value, $nocache); } else { @@ -228,6 +229,46 @@ class Smarty_Internal_Data } } + /** + * Return true if this instance is a Data obj + * + * @return bool + */ + public function _isDataObj() + { + return $this->_objType === 4; + } + + /** + * Return true if this instance is a template obj + * + * @return bool + */ + public function _isTplObj() + { + return $this->_objType === 2; + } + + /** + * Return true if this instance is a Smarty obj + * + * @return bool + */ + public function _isSmartyObj() + { + return $this->_objType === 1; + } + + /** + * Get Smarty object + * + * @return Smarty + */ + public function _getSmartyObj() + { + return $this->smarty; + } + /** * Handle unknown class methods * diff --git a/libs/sysplugins/smarty_internal_debug.php b/libs/sysplugins/smarty_internal_debug.php index fb837e78..f16bd3fb 100644 --- a/libs/sysplugins/smarty_internal_debug.php +++ b/libs/sysplugins/smarty_internal_debug.php @@ -52,7 +52,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data */ public function start_template(Smarty_Internal_Template $template, $mode = null) { - if (isset($mode) && (!isset($template->parent) || $template->parent->_objType !== 2)) { + if (isset($mode) && !$template->_isSubTpl()) { $this->index ++; $this->offset ++; $this->template_data[ $this->index ] = null; @@ -201,11 +201,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data $savedIndex = $this->index; $this->index = 9999; } - if ($obj->_objType == 1) { - $smarty = $obj; - } else { - $smarty = $obj->smarty; - } + $smarty = $obj->_getSmartyObj(); // create fresh instance of smarty for displaying the debug console // to avoid problems if the application did overload the Smarty class $debObj = new Smarty(); @@ -240,7 +236,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data $debugging = $smarty->debugging; $_template = new Smarty_Internal_Template($debObj->debug_tpl, $debObj); - if ($obj->_objType == 2) { + if ($obj->_isTplObj()) { $_template->assign('template_name', $obj->source->type . ':' . $obj->source->name); } if ($obj->_objType == 1 || $full) { @@ -274,9 +270,9 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data $config_vars = array(); foreach ($obj->config_vars as $key => $var) { $config_vars[ $key ][ 'value' ] = $var; - if ($obj->_objType == 2) { + if ($obj->_isTplObj()) { $config_vars[ $key ][ 'scope' ] = $obj->source->type . ':' . $obj->source->name; - } elseif ($obj->_objType == 4) { + } elseif ($obj->_isDataObj()) { $tpl_vars[ $key ][ 'scope' ] = $obj->dataObjectName; } else { $config_vars[ $key ][ 'scope' ] = 'Smarty object'; @@ -299,9 +295,9 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data } } } - if ($obj->_objType == 2) { + if ($obj->_isTplObj()) { $tpl_vars[ $key ][ 'scope' ] = $obj->source->type . ':' . $obj->source->name; - } elseif ($obj->_objType == 4) { + } elseif ($obj->_isDataObj()) { $tpl_vars[ $key ][ 'scope' ] = $obj->dataObjectName; } else { $tpl_vars[ $key ][ 'scope' ] = 'Smarty object'; diff --git a/libs/sysplugins/smarty_internal_extension_handler.php b/libs/sysplugins/smarty_internal_extension_handler.php index 9368b0e2..9215f2db 100644 --- a/libs/sysplugins/smarty_internal_extension_handler.php +++ b/libs/sysplugins/smarty_internal_extension_handler.php @@ -77,7 +77,7 @@ class Smarty_Internal_Extension_Handler - 1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE))); $this->_property_info[ $prop ] = property_exists($data, $pn) ? 1 : - ($data->_objType == 2 && property_exists($smarty, $pn) ? 2 : 0); + ($data->_isTplObj() && property_exists($smarty, $pn) ? 2 : 0); } if ($this->_property_info[ $prop ]) { $pn = $this->resolvedProperties[ $prop ]; diff --git a/libs/sysplugins/smarty_internal_method_addautoloadfilters.php b/libs/sysplugins/smarty_internal_method_addautoloadfilters.php index 67ce1a9b..3eef8a28 100644 --- a/libs/sysplugins/smarty_internal_method_addautoloadfilters.php +++ b/libs/sysplugins/smarty_internal_method_addautoloadfilters.php @@ -28,7 +28,7 @@ class Smarty_Internal_Method_AddAutoloadFilters extends Smarty_Internal_Method_S */ public function addAutoloadFilters(Smarty_Internal_TemplateBase $obj, $filters, $type = null) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); if ($type !== null) { $this->_checkFilterType($type); if (!empty($smarty->autoload_filters[ $type ])) { diff --git a/libs/sysplugins/smarty_internal_method_adddefaultmodifiers.php b/libs/sysplugins/smarty_internal_method_adddefaultmodifiers.php index 4cd01da0..afb0b68d 100644 --- a/libs/sysplugins/smarty_internal_method_adddefaultmodifiers.php +++ b/libs/sysplugins/smarty_internal_method_adddefaultmodifiers.php @@ -31,7 +31,7 @@ class Smarty_Internal_Method_AddDefaultModifiers */ public function addDefaultModifiers(Smarty_Internal_TemplateBase $obj, $modifiers) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); if (is_array($modifiers)) { $smarty->default_modifiers = array_merge($smarty->default_modifiers, $modifiers); } else { diff --git a/libs/sysplugins/smarty_internal_method_append.php b/libs/sysplugins/smarty_internal_method_append.php index b89aacfd..af693591 100644 --- a/libs/sysplugins/smarty_internal_method_append.php +++ b/libs/sysplugins/smarty_internal_method_append.php @@ -65,7 +65,7 @@ class Smarty_Internal_Method_Append $data->tpl_vars[ $tpl_var ]->value[] = $value; } } - if ($data->_objType == 2 && $data->scope) { + if ($data->_isTplObj() && $data->scope) { $data->ext->_updateScope->_updateScope($data, $tpl_var); } } diff --git a/libs/sysplugins/smarty_internal_method_appendbyref.php b/libs/sysplugins/smarty_internal_method_appendbyref.php index 64190d19..532ac950 100644 --- a/libs/sysplugins/smarty_internal_method_appendbyref.php +++ b/libs/sysplugins/smarty_internal_method_appendbyref.php @@ -41,7 +41,7 @@ class Smarty_Internal_Method_AppendByRef } else { $data->tpl_vars[ $tpl_var ]->value[] = &$value; } - if ($data->_objType == 2 && $data->scope) { + if ($data->_isTplObj() && $data->scope) { $data->ext->_updateScope->_updateScope($data, $tpl_var); } } diff --git a/libs/sysplugins/smarty_internal_method_assignbyref.php b/libs/sysplugins/smarty_internal_method_assignbyref.php index 5e2a2a69..0060bbc5 100644 --- a/libs/sysplugins/smarty_internal_method_assignbyref.php +++ b/libs/sysplugins/smarty_internal_method_assignbyref.php @@ -27,7 +27,7 @@ class Smarty_Internal_Method_AssignByRef if ($tpl_var != '') { $data->tpl_vars[ $tpl_var ] = new Smarty_Variable(null, $nocache); $data->tpl_vars[ $tpl_var ]->value = &$value; - if ($data->_objType == 2 && $data->scope) { + if ($data->_isTplObj() && $data->scope) { $data->ext->_updateScope->_updateScope($data, $tpl_var); } } diff --git a/libs/sysplugins/smarty_internal_method_assignglobal.php b/libs/sysplugins/smarty_internal_method_assignglobal.php index aae3ed7e..3c2b2604 100644 --- a/libs/sysplugins/smarty_internal_method_assignglobal.php +++ b/libs/sysplugins/smarty_internal_method_assignglobal.php @@ -33,7 +33,7 @@ class Smarty_Internal_Method_AssignGlobal if ($varName != '') { Smarty::$global_tpl_vars[ $varName ] = new Smarty_Variable($value, $nocache); $ptr = $data; - while ($ptr->_objType == 2) { + while ($ptr->_isTplObj()) { $ptr->tpl_vars[ $varName ] = clone Smarty::$global_tpl_vars[ $varName ]; $ptr = $ptr->parent; } diff --git a/libs/sysplugins/smarty_internal_method_configload.php b/libs/sysplugins/smarty_internal_method_configload.php index 401b0df9..2e142b79 100644 --- a/libs/sysplugins/smarty_internal_method_configload.php +++ b/libs/sysplugins/smarty_internal_method_configload.php @@ -66,7 +66,7 @@ class Smarty_Internal_Method_ConfigLoad $confObj->source->scope = $scope; $confObj->compiled = Smarty_Template_Compiled::load($confObj); $confObj->compiled->render($confObj); - if ($data->_objType == 2) { + if ($data->_isTplObj()) { $data->compiled->file_dependency[ $confObj->source->uid ] = array($confObj->source->filepath, $confObj->source->getTimeStamp(), $confObj->source->type); } @@ -91,13 +91,13 @@ class Smarty_Internal_Method_ConfigLoad return; } } - if ($tpl->parent->_objType == 2 && ($tagScope || $tpl->parent->scope)) { + if ($tpl->parent->_isTplObj() && ($tagScope || $tpl->parent->scope)) { $mergedScope = $tagScope | $tpl->scope; if ($mergedScope) { // update scopes foreach ($tpl->smarty->ext->_updateScope->_getAffectedScopes($tpl->parent, $mergedScope) as $ptr) { $this->_assignConfigVars($ptr->config_vars, $tpl, $new_config_vars); - if ($tagScope && $ptr->_objType == 2 && isset($tpl->_cache[ 'varStack' ])) { + if ($tagScope && $ptr->_isTplObj() && isset($tpl->_cache[ 'varStack' ])) { $this->_updateVarStack($tpl, $new_config_vars); } } diff --git a/libs/sysplugins/smarty_internal_method_createdata.php b/libs/sysplugins/smarty_internal_method_createdata.php index 600bc777..43ce8943 100644 --- a/libs/sysplugins/smarty_internal_method_createdata.php +++ b/libs/sysplugins/smarty_internal_method_createdata.php @@ -34,7 +34,7 @@ class Smarty_Internal_Method_CreateData public function createData(Smarty_Internal_TemplateBase $obj, Smarty_Internal_Data $parent = null, $name = null) { /* @var Smarty $smarty */ - $smarty = isset($this->smarty) ? $this->smarty : $obj; + $smarty = $obj->_getSmartyObj(); $dataObj = new Smarty_Data($parent, $smarty, $name); if ($smarty->debugging) { Smarty_Internal_Debug::register_data($dataObj); diff --git a/libs/sysplugins/smarty_internal_method_getautoloadfilters.php b/libs/sysplugins/smarty_internal_method_getautoloadfilters.php index 87d4604a..d945a01e 100644 --- a/libs/sysplugins/smarty_internal_method_getautoloadfilters.php +++ b/libs/sysplugins/smarty_internal_method_getautoloadfilters.php @@ -27,7 +27,7 @@ class Smarty_Internal_Method_GetAutoloadFilters extends Smarty_Internal_Method_S */ public function getAutoloadFilters(Smarty_Internal_TemplateBase $obj, $type = null) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); if ($type !== null) { $this->_checkFilterType($type); return isset($smarty->autoload_filters[ $type ]) ? $smarty->autoload_filters[ $type ] : array(); diff --git a/libs/sysplugins/smarty_internal_method_getdebugtemplate.php b/libs/sysplugins/smarty_internal_method_getdebugtemplate.php index 40696c65..52073c14 100644 --- a/libs/sysplugins/smarty_internal_method_getdebugtemplate.php +++ b/libs/sysplugins/smarty_internal_method_getdebugtemplate.php @@ -29,7 +29,7 @@ class Smarty_Internal_Method_GetDebugTemplate */ public function getDebugTemplate(Smarty_Internal_TemplateBase $obj) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); return $smarty->debug_tpl; } } \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_getdefaultmodifiers.php b/libs/sysplugins/smarty_internal_method_getdefaultmodifiers.php index 32e0cc41..f65ab791 100644 --- a/libs/sysplugins/smarty_internal_method_getdefaultmodifiers.php +++ b/libs/sysplugins/smarty_internal_method_getdefaultmodifiers.php @@ -29,7 +29,7 @@ class Smarty_Internal_Method_GetDefaultModifiers */ public function getDefaultModifiers(Smarty_Internal_TemplateBase $obj) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); return $smarty->default_modifiers; } } \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_getregisteredobject.php b/libs/sysplugins/smarty_internal_method_getregisteredobject.php index 872dbd80..c5c06466 100644 --- a/libs/sysplugins/smarty_internal_method_getregisteredobject.php +++ b/libs/sysplugins/smarty_internal_method_getregisteredobject.php @@ -32,7 +32,7 @@ class Smarty_Internal_Method_GetRegisteredObject */ public function getRegisteredObject(Smarty_Internal_TemplateBase $obj, $object_name) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); if (!isset($smarty->registered_objects[ $object_name ])) { throw new SmartyException("'$object_name' is not a registered object"); } diff --git a/libs/sysplugins/smarty_internal_method_gettags.php b/libs/sysplugins/smarty_internal_method_gettags.php index ea727fdb..5718b69e 100644 --- a/libs/sysplugins/smarty_internal_method_gettags.php +++ b/libs/sysplugins/smarty_internal_method_gettags.php @@ -33,10 +33,10 @@ class Smarty_Internal_Method_GetTags public function getTags(Smarty_Internal_TemplateBase $obj, $template = null) { /* @var Smarty $smarty */ - $smarty = isset($this->smarty) ? $this->smarty : $obj; - if ($obj->_objType == 2 && !isset($template)) { + $smarty = $obj->_getSmartyObj(); + if ($obj->_isTplObj() && !isset($template)) { $tpl = clone $obj; - } elseif (isset($template) && $template->_objType == 2) { + } elseif (isset($template) && $template->_isTplObj()) { $tpl = clone $template; } elseif (isset($template) && is_string($template)) { /* @var Smarty_Internal_Template $tpl */ diff --git a/libs/sysplugins/smarty_internal_method_loadfilter.php b/libs/sysplugins/smarty_internal_method_loadfilter.php index 4fdbdac3..d092d876 100644 --- a/libs/sysplugins/smarty_internal_method_loadfilter.php +++ b/libs/sysplugins/smarty_internal_method_loadfilter.php @@ -41,7 +41,7 @@ class Smarty_Internal_Method_LoadFilter */ public function loadFilter(Smarty_Internal_TemplateBase $obj, $type, $name) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); $this->_checkFilterType($type); $_plugin = "smarty_{$type}filter_{$name}"; $_filter_name = $_plugin; diff --git a/libs/sysplugins/smarty_internal_method_mustcompile.php b/libs/sysplugins/smarty_internal_method_mustcompile.php index 718b0a10..0950ba9c 100644 --- a/libs/sysplugins/smarty_internal_method_mustcompile.php +++ b/libs/sysplugins/smarty_internal_method_mustcompile.php @@ -31,7 +31,7 @@ class Smarty_Internal_Method_MustCompile public function mustCompile(Smarty_Internal_Template $_template) { if (!$_template->source->exists) { - if (isset($_template->parent) && $_template->parent->_objType == 2) { + if ($_template->_isSubTpl()) { $parent_resource = " in '$_template->parent->template_resource}'"; } else { $parent_resource = ''; diff --git a/libs/sysplugins/smarty_internal_method_registercacheresource.php b/libs/sysplugins/smarty_internal_method_registercacheresource.php index a3ab426a..ae387272 100644 --- a/libs/sysplugins/smarty_internal_method_registercacheresource.php +++ b/libs/sysplugins/smarty_internal_method_registercacheresource.php @@ -33,7 +33,7 @@ class Smarty_Internal_Method_RegisterCacheResource public function registerCacheResource(Smarty_Internal_TemplateBase $obj, $name, Smarty_CacheResource $resource_handler) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); $smarty->registered_cache_resources[ $name ] = $resource_handler; return $obj; } diff --git a/libs/sysplugins/smarty_internal_method_registerclass.php b/libs/sysplugins/smarty_internal_method_registerclass.php index de89b4c0..5469b98a 100644 --- a/libs/sysplugins/smarty_internal_method_registerclass.php +++ b/libs/sysplugins/smarty_internal_method_registerclass.php @@ -34,7 +34,7 @@ class Smarty_Internal_Method_RegisterClass */ public function registerClass(Smarty_Internal_TemplateBase $obj, $class_name, $class_impl) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); // test if exists if (!class_exists($class_impl)) { throw new SmartyException("Undefined class '$class_impl' in register template class"); diff --git a/libs/sysplugins/smarty_internal_method_registerdefaultconfighandler.php b/libs/sysplugins/smarty_internal_method_registerdefaultconfighandler.php index 370aa38d..43088a1d 100644 --- a/libs/sysplugins/smarty_internal_method_registerdefaultconfighandler.php +++ b/libs/sysplugins/smarty_internal_method_registerdefaultconfighandler.php @@ -31,7 +31,7 @@ class Smarty_Internal_Method_RegisterDefaultConfigHandler */ public function registerDefaultConfigHandler(Smarty_Internal_TemplateBase $obj, $callback) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); if (is_callable($callback)) { $smarty->default_config_handler_func = $callback; } else { diff --git a/libs/sysplugins/smarty_internal_method_registerdefaultpluginhandler.php b/libs/sysplugins/smarty_internal_method_registerdefaultpluginhandler.php index 80b801ce..d9aecb4a 100644 --- a/libs/sysplugins/smarty_internal_method_registerdefaultpluginhandler.php +++ b/libs/sysplugins/smarty_internal_method_registerdefaultpluginhandler.php @@ -32,7 +32,7 @@ class Smarty_Internal_Method_RegisterDefaultPluginHandler */ public function registerDefaultPluginHandler(Smarty_Internal_TemplateBase $obj, $callback) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); if (is_callable($callback)) { $smarty->default_plugin_handler_func = $callback; } else { diff --git a/libs/sysplugins/smarty_internal_method_registerdefaulttemplatehandler.php b/libs/sysplugins/smarty_internal_method_registerdefaulttemplatehandler.php index 73e8f627..569ea106 100644 --- a/libs/sysplugins/smarty_internal_method_registerdefaulttemplatehandler.php +++ b/libs/sysplugins/smarty_internal_method_registerdefaulttemplatehandler.php @@ -31,7 +31,7 @@ class Smarty_Internal_Method_RegisterDefaultTemplateHandler */ public function registerDefaultTemplateHandler(Smarty_Internal_TemplateBase $obj, $callback) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); if (is_callable($callback)) { $smarty->default_template_handler_func = $callback; } else { diff --git a/libs/sysplugins/smarty_internal_method_registerfilter.php b/libs/sysplugins/smarty_internal_method_registerfilter.php index 7c8a12ac..ea8f75a8 100644 --- a/libs/sysplugins/smarty_internal_method_registerfilter.php +++ b/libs/sysplugins/smarty_internal_method_registerfilter.php @@ -42,7 +42,7 @@ class Smarty_Internal_Method_RegisterFilter */ public function registerFilter(Smarty_Internal_TemplateBase $obj, $type, $callback, $name = null) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); $this->_checkFilterType($type); $name = isset($name) ? $name : $this->_getFilterName($callback); if (!is_callable($callback)) { diff --git a/libs/sysplugins/smarty_internal_method_registerobject.php b/libs/sysplugins/smarty_internal_method_registerobject.php index dcebd92b..ba699b21 100644 --- a/libs/sysplugins/smarty_internal_method_registerobject.php +++ b/libs/sysplugins/smarty_internal_method_registerobject.php @@ -47,7 +47,7 @@ class Smarty_Internal_Method_RegisterObject public function registerObject(Smarty_Internal_TemplateBase $obj, $object_name, $object, $allowed_methods_properties = array(), $format = true, $block_methods = array()) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); // test if allowed methods callable if (!empty($allowed_methods_properties)) { foreach ((array) $allowed_methods_properties as $method) { diff --git a/libs/sysplugins/smarty_internal_method_registerplugin.php b/libs/sysplugins/smarty_internal_method_registerplugin.php index b86abbfa..91f06592 100644 --- a/libs/sysplugins/smarty_internal_method_registerplugin.php +++ b/libs/sysplugins/smarty_internal_method_registerplugin.php @@ -38,7 +38,7 @@ class Smarty_Internal_Method_RegisterPlugin public function registerPlugin(Smarty_Internal_TemplateBase $obj, $type, $name, $callback, $cacheable = true, $cache_attr = null) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); if (isset($smarty->registered_plugins[ $type ][ $name ])) { throw new SmartyException("Plugin tag \"{$name}\" already registered"); } elseif (!is_callable($callback)) { diff --git a/libs/sysplugins/smarty_internal_method_registerresource.php b/libs/sysplugins/smarty_internal_method_registerresource.php index 31555b3a..44534b73 100644 --- a/libs/sysplugins/smarty_internal_method_registerresource.php +++ b/libs/sysplugins/smarty_internal_method_registerresource.php @@ -36,7 +36,7 @@ class Smarty_Internal_Method_RegisterResource */ public function registerResource(Smarty_Internal_TemplateBase $obj, $name, $resource_handler) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); $smarty->registered_resources[ $name ] = $resource_handler instanceof Smarty_Resource ? $resource_handler : array($resource_handler, false); return $obj; diff --git a/libs/sysplugins/smarty_internal_method_setautoloadfilters.php b/libs/sysplugins/smarty_internal_method_setautoloadfilters.php index 04a901a0..df5ca640 100644 --- a/libs/sysplugins/smarty_internal_method_setautoloadfilters.php +++ b/libs/sysplugins/smarty_internal_method_setautoloadfilters.php @@ -41,7 +41,7 @@ class Smarty_Internal_Method_SetAutoloadFilters */ public function setAutoloadFilters(Smarty_Internal_TemplateBase $obj, $filters, $type = null) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); if ($type !== null) { $this->_checkFilterType($type); $smarty->autoload_filters[ $type ] = (array) $filters; diff --git a/libs/sysplugins/smarty_internal_method_setdebugtemplate.php b/libs/sysplugins/smarty_internal_method_setdebugtemplate.php index 4ff5d7f8..76c87deb 100644 --- a/libs/sysplugins/smarty_internal_method_setdebugtemplate.php +++ b/libs/sysplugins/smarty_internal_method_setdebugtemplate.php @@ -31,7 +31,7 @@ class Smarty_Internal_Method_SetDebugTemplate */ public function setDebugTemplate(Smarty_Internal_TemplateBase $obj, $tpl_name) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); if (!is_readable($tpl_name)) { throw new SmartyException("Unknown file '{$tpl_name}'"); } diff --git a/libs/sysplugins/smarty_internal_method_setdefaultmodifiers.php b/libs/sysplugins/smarty_internal_method_setdefaultmodifiers.php index 5a707287..81434b96 100644 --- a/libs/sysplugins/smarty_internal_method_setdefaultmodifiers.php +++ b/libs/sysplugins/smarty_internal_method_setdefaultmodifiers.php @@ -31,7 +31,7 @@ class Smarty_Internal_Method_SetDefaultModifiers */ public function setDefaultModifiers(Smarty_Internal_TemplateBase $obj, $modifiers) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); $smarty->default_modifiers = (array) $modifiers; return $obj; } diff --git a/libs/sysplugins/smarty_internal_method_unloadfilter.php b/libs/sysplugins/smarty_internal_method_unloadfilter.php index 3ca0eaee..9aa1d229 100644 --- a/libs/sysplugins/smarty_internal_method_unloadfilter.php +++ b/libs/sysplugins/smarty_internal_method_unloadfilter.php @@ -26,7 +26,7 @@ class Smarty_Internal_Method_UnloadFilter extends Smarty_Internal_Method_LoadFil */ public function unloadFilter(Smarty_Internal_TemplateBase $obj, $type, $name) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); $this->_checkFilterType($type); if (isset($smarty->registered_filters[ $type ])) { $_filter_name = "smarty_{$type}filter_{$name}"; diff --git a/libs/sysplugins/smarty_internal_method_unregistercacheresource.php b/libs/sysplugins/smarty_internal_method_unregistercacheresource.php index 11680578..1a157ffb 100644 --- a/libs/sysplugins/smarty_internal_method_unregistercacheresource.php +++ b/libs/sysplugins/smarty_internal_method_unregistercacheresource.php @@ -31,7 +31,7 @@ class Smarty_Internal_Method_UnregisterCacheResource */ public function unregisterCacheResource(Smarty_Internal_TemplateBase $obj, $name) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); if (isset($smarty->registered_cache_resources[ $name ])) { unset($smarty->registered_cache_resources[ $name ]); } diff --git a/libs/sysplugins/smarty_internal_method_unregisterfilter.php b/libs/sysplugins/smarty_internal_method_unregisterfilter.php index ec69c553..c5b88f57 100644 --- a/libs/sysplugins/smarty_internal_method_unregisterfilter.php +++ b/libs/sysplugins/smarty_internal_method_unregisterfilter.php @@ -26,7 +26,7 @@ class Smarty_Internal_Method_UnregisterFilter extends Smarty_Internal_Method_Reg */ public function unregisterFilter(Smarty_Internal_TemplateBase $obj, $type, $callback) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); $this->_checkFilterType($type); if (isset($smarty->registered_filters[ $type ])) { $name = is_string($callback) ? $callback : $this->_getFilterName($callback); diff --git a/libs/sysplugins/smarty_internal_method_unregisterobject.php b/libs/sysplugins/smarty_internal_method_unregisterobject.php index 56c531ed..76d48661 100644 --- a/libs/sysplugins/smarty_internal_method_unregisterobject.php +++ b/libs/sysplugins/smarty_internal_method_unregisterobject.php @@ -31,7 +31,7 @@ class Smarty_Internal_Method_UnregisterObject */ public function unregisterObject(Smarty_Internal_TemplateBase $obj, $object_name) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); if (isset($smarty->registered_objects[ $object_name ])) { unset($smarty->registered_objects[ $object_name ]); } diff --git a/libs/sysplugins/smarty_internal_method_unregisterplugin.php b/libs/sysplugins/smarty_internal_method_unregisterplugin.php index 3fd8b147..b5f0d505 100644 --- a/libs/sysplugins/smarty_internal_method_unregisterplugin.php +++ b/libs/sysplugins/smarty_internal_method_unregisterplugin.php @@ -32,7 +32,7 @@ class Smarty_Internal_Method_UnregisterPlugin */ public function unregisterPlugin(Smarty_Internal_TemplateBase $obj, $type, $name) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); if (isset($smarty->registered_plugins[ $type ][ $name ])) { unset($smarty->registered_plugins[ $type ][ $name ]); } diff --git a/libs/sysplugins/smarty_internal_method_unregisterresource.php b/libs/sysplugins/smarty_internal_method_unregisterresource.php index f53d9bc4..ed4801d4 100644 --- a/libs/sysplugins/smarty_internal_method_unregisterresource.php +++ b/libs/sysplugins/smarty_internal_method_unregisterresource.php @@ -31,7 +31,7 @@ class Smarty_Internal_Method_UnregisterResource */ public function unregisterResource(Smarty_Internal_TemplateBase $obj, $type) { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); if (isset($smarty->registered_resources[ $type ])) { unset($smarty->registered_resources[ $type ]); } diff --git a/libs/sysplugins/smarty_internal_nocache_insert.php b/libs/sysplugins/smarty_internal_nocache_insert.php index 6762c289..65fc143c 100644 --- a/libs/sysplugins/smarty_internal_nocache_insert.php +++ b/libs/sysplugins/smarty_internal_nocache_insert.php @@ -43,7 +43,7 @@ class Smarty_Internal_Nocache_Insert $_output .= "echo {$_function}(" . var_export($_attr, true) . ",\$_smarty_tpl);?>"; } $_tpl = $_template; - while (isset($_tpl->parent) && $_tpl->parent->_objType == 2) { + while ($_tpl->_isSubTpl()) { $_tpl = $_tpl->parent; } diff --git a/libs/sysplugins/smarty_internal_resource_file.php b/libs/sysplugins/smarty_internal_resource_file.php index 197fa2e3..a58771a1 100644 --- a/libs/sysplugins/smarty_internal_resource_file.php +++ b/libs/sysplugins/smarty_internal_resource_file.php @@ -35,7 +35,7 @@ class Smarty_Internal_Resource_File extends Smarty_Resource return is_file($file) ? $file : false; } // go relative to a given template? - if ($file[ 0 ] == '.' && $_template && isset($_template->parent) && $_template->parent->_objType == 2 && + if ($file[ 0 ] == '.' && $_template && $_template->_isSubTpl() && preg_match('#^[.]{1,2}[\\\/]#', $file) ) { if ($_template->parent->source->type != 'file' && $_template->parent->source->type != 'extends' && diff --git a/libs/sysplugins/smarty_internal_resource_php.php b/libs/sysplugins/smarty_internal_resource_php.php index 3cff7813..52e7096b 100644 --- a/libs/sysplugins/smarty_internal_resource_php.php +++ b/libs/sysplugins/smarty_internal_resource_php.php @@ -71,9 +71,8 @@ class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File throw new SmartyException("PHP templates are disabled"); } if (!$source->exists) { - $parentIsTpl = isset($this->parent) && $this->parent->_objType == 2; throw new SmartyException("Unable to load template {$source->type} '{$source->name}'" . - ($parentIsTpl ? " in '{$this->parent->template_resource}'" : '')); + ($_template->_isSubTpl() ? " in '{$_template->parent->template_resource}'" : '')); } // prepare variables diff --git a/libs/sysplugins/smarty_internal_runtime_tplfunction.php b/libs/sysplugins/smarty_internal_runtime_tplfunction.php index f75028a8..5cedca13 100644 --- a/libs/sysplugins/smarty_internal_runtime_tplfunction.php +++ b/libs/sysplugins/smarty_internal_runtime_tplfunction.php @@ -67,7 +67,7 @@ class Smarty_Internal_Runtime_TplFunction $this->tplFunctions = array_merge($this->tplFunctions, $tplFunctions); $ptr = $tpl; // make sure that the template functions are known in parent templates - while (isset($ptr->parent) && $ptr->parent->_objType === 2 && !isset($ptr->ext->_tplFunction)) { + while ($ptr->_isTplObj() && !isset($ptr->ext->_tplFunction)) { $ptr->ext->_tplFunction = $this; $ptr = $ptr->parent; } diff --git a/libs/sysplugins/smarty_internal_runtime_updatecache.php b/libs/sysplugins/smarty_internal_runtime_updatecache.php index 77d790e0..ceee3b71 100644 --- a/libs/sysplugins/smarty_internal_runtime_updatecache.php +++ b/libs/sysplugins/smarty_internal_runtime_updatecache.php @@ -93,7 +93,7 @@ class Smarty_Internal_Runtime_UpdateCache $this->removeNoCacheHash($cached, $_template, $no_output_filter); $compile_check = $_template->smarty->compile_check; $_template->smarty->compile_check = false; - if (isset($_template->parent) && $_template->parent->_objType == 2) { + if ($_template->_isSubTpl()) { $_template->compiled->unifunc = $_template->parent->compiled->unifunc; } if (!$_template->cached->processed) { diff --git a/libs/sysplugins/smarty_internal_runtime_updatescope.php b/libs/sysplugins/smarty_internal_runtime_updatescope.php index 04f2d3da..79885321 100644 --- a/libs/sysplugins/smarty_internal_runtime_updatescope.php +++ b/libs/sysplugins/smarty_internal_runtime_updatescope.php @@ -34,7 +34,7 @@ class Smarty_Internal_Runtime_UpdateScope // update scopes foreach ($this->_getAffectedScopes($tpl, $mergedScope) as $ptr) { $this->_updateVariableInOtherScope($ptr->tpl_vars, $tpl, $varName); - if($tagScope && $ptr->_objType == 2 && isset($tpl->_cache[ 'varStack' ])) { + if($tagScope && $ptr->_isTplObj() && isset($tpl->_cache[ 'varStack' ])) { $this->_updateVarStack($ptr, $varName); } } } @@ -52,7 +52,7 @@ class Smarty_Internal_Runtime_UpdateScope { $_stack = array(); $ptr = $tpl->parent; - if ($mergedScope && isset($ptr) && $ptr->_objType == 2) { + if ($mergedScope && isset($ptr) && $ptr->_isTplObj()) { $_stack[] = $ptr; $mergedScope = $mergedScope & ~Smarty::SCOPE_PARENT; if (!$mergedScope) { @@ -61,7 +61,7 @@ class Smarty_Internal_Runtime_UpdateScope } $ptr = $ptr->parent; } - while (isset($ptr) && $ptr->_objType == 2) { + while (isset($ptr) && $ptr->_isTplObj()) { $_stack[] = $ptr; $ptr = $ptr->parent; } @@ -71,7 +71,7 @@ class Smarty_Internal_Runtime_UpdateScope } } elseif ($mergedScope & Smarty::SCOPE_ROOT) { while (isset($ptr)) { - if ($ptr->_objType != 2) { + if (!$ptr->_isTplObj()) { $_stack[] = $ptr; break; } diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index 01eedb8a..bb747a82 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -151,7 +151,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase */ public function render($no_output_filter = true, $display = null) { - $parentIsTpl = isset($this->parent) && $this->parent->_objType == 2; if ($this->smarty->debugging) { if (!isset($this->smarty->_debug)) { $this->smarty->_debug = new Smarty_Internal_Debug(); @@ -161,7 +160,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase // checks if template exists if (!$this->source->exists) { throw new SmartyException("Unable to load template '{$this->source->type}:{$this->source->name}'" . - ($parentIsTpl ? " in '{$this->parent->template_resource}'" : '')); + ($this->_isSubTpl() ? " in '{$this->parent->template_resource}'" : '')); } // disable caching for evaluated code if ($this->source->handler->recompiled) { @@ -212,7 +211,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase $this->smarty->_debug->display_debug($this, true); } } - if ($parentIsTpl) { + if ($this->_isSubTpl()) { foreach ($this->compiled->required_plugins as $code => $tmp1) { foreach ($tmp1 as $name => $tmp) { foreach ($tmp as $type => $data) { @@ -309,7 +308,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase // check if template object should be cached if ($forceTplCache || (isset($smarty->_cache[ 'subTplInfo' ][ $tpl->template_resource ]) && $smarty->_cache[ 'subTplInfo' ][ $tpl->template_resource ] > 1) || - ($tpl->_isParentTemplate() && isset($smarty->_cache[ 'tplObjects' ][ $tpl->parent->templateId ])) + ($tpl->_isSubTpl() && isset($smarty->_cache[ 'tplObjects' ][ $tpl->parent->templateId ])) ) { $smarty->_cache[ 'tplObjects' ][ $tpl->templateId ] = $tpl; } @@ -368,13 +367,13 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase } /** - * Check if parent is template object + * Check if this is a sub template * - * @return bool true if parent is template + * @return bool true is sub template */ - public function _isParentTemplate() + public function _isSubTpl() { - return isset($this->parent) && $this->parent->_objType == 2; + return isset($this->parent) && $this->parent->_isTplObj(); } /** diff --git a/libs/sysplugins/smarty_internal_templatebase.php b/libs/sysplugins/smarty_internal_templatebase.php index 0b123f6c..39d53a27 100644 --- a/libs/sysplugins/smarty_internal_templatebase.php +++ b/libs/sysplugins/smarty_internal_templatebase.php @@ -14,7 +14,7 @@ * @package Smarty * @subpackage Template * - * @property Smarty $smarty + * @property int $_objType * * The following methods will be dynamically loaded by the extension handler when they are called. * They are located in a corresponding Smarty_Internal_Method_xxxx class @@ -42,6 +42,7 @@ * @method Smarty_Internal_TemplateBase unregisterPlugin(string $type, string $name) * @method Smarty_Internal_TemplateBase unregisterFilter(string $type, mixed $callback) * @method Smarty_Internal_TemplateBase unregisterResource(string $name) + * @method Smarty _getSmartyObj() */ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data { @@ -147,16 +148,16 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data */ private function _execute($template, $cache_id, $compile_id, $parent, $function) { - $smarty = $this->_objType == 1 ? $this : $this->smarty; + $smarty = $this->_getSmartyObj(); $saveVars = true; if ($template === null) { - if ($this->_objType != 2) { + if (!$this->_isTplObj()) { throw new SmartyException($function . '():Missing \'$template\' parameter'); } else { $template = $this; } } elseif (is_object($template)) { - if (!isset($template->_objType) || $template->_objType != 2) { + if (!isset($template->_objType) || !$template->_isTplObj()) { throw new SmartyException($function . '():Template object expected'); } } else { diff --git a/libs/sysplugins/smarty_resource.php b/libs/sysplugins/smarty_resource.php index 9b4246b3..ea673ead 100644 --- a/libs/sysplugins/smarty_resource.php +++ b/libs/sysplugins/smarty_resource.php @@ -209,13 +209,13 @@ abstract class Smarty_Resource */ public static function getUniqueTemplateName($obj, $template_resource) { - $smarty = $obj->_objType == 2 ? $obj->smarty : $obj; + $smarty = $obj->_getSmartyObj(); list($name, $type) = self::parseResourceName($template_resource, $smarty->default_resource_type); // TODO: optimize for Smarty's internal resource types $resource = Smarty_Resource::load($smarty, $type); // go relative to a given template? $_file_is_dotted = $name[ 0 ] == '.' && ($name[ 1 ] == '.' || $name[ 1 ] == '/'); - if ($obj->_objType == 2 && $_file_is_dotted && + if ($obj->_isTplObj() && $_file_is_dotted && ($obj->source->type == 'file' || $obj->parent->source->type == 'extends') ) { $name = $smarty->_realpath(dirname($obj->parent->source->filepath) . $smarty->ds . $name);