diff --git a/change_log.txt b/change_log.txt index ebea9959..0a82eb75 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,6 +1,10 @@  ===== 3.1.28-dev===== (xx.xx.2015) + xx.xx.2015 + - introduce Smarty::$resource_cache_mode and cache template object of {include} inside loop + - load seldom used Smarty API methods dynamically to reduce memory footprint + 06.08.2015 - - avoid possible circular object referances caused by parser/lexer objects + - avoid possible circular object references caused by parser/lexer objects - rewrite compileAll... utility methods - commit several internal improvements - bugfix Smarty failed when compile_id did contain "|" diff --git a/lexer/smarty_internal_templateparser.y b/lexer/smarty_internal_templateparser.y index c57bcda8..eab44464 100644 --- a/lexer/smarty_internal_templateparser.y +++ b/lexer/smarty_internal_templateparser.y @@ -877,19 +877,19 @@ variable(res) ::= object(o). { // config variable variable(res) ::= HATCH ID(i) HATCH. { - res = '$_smarty_tpl->getConfigVariable( \''. i .'\')'; + res = '$_smarty_tpl->_getConfigVariable( \''. i .'\')'; } variable(res) ::= HATCH ID(i) HATCH arrayindex(a). { - res = '(is_array($tmp = $_smarty_tpl->getConfigVariable( \''. i .'\')) ? $tmp'.a.' :null)'; + res = '(is_array($tmp = $_smarty_tpl->_getConfigVariable( \''. i .'\')) ? $tmp'.a.' :null)'; } variable(res) ::= HATCH variable(v) HATCH. { - res = '$_smarty_tpl->getConfigVariable( '. v .')'; + res = '$_smarty_tpl->_getConfigVariable( '. v .')'; } variable(res) ::= HATCH variable(v) HATCH arrayindex(a). { - res = '(is_array($tmp = $_smarty_tpl->getConfigVariable( '. v .')) ? $tmp'.a.' : null)'; + res = '(is_array($tmp = $_smarty_tpl->_getConfigVariable( '. v .')) ? $tmp'.a.' : null)'; } varindexed(res) ::= DOLLARID(i) arrayindex(a). { @@ -1075,7 +1075,7 @@ function(res) ::= ns1(f) OPENP params(p) CLOSEP. { $this->compiler->trigger_template_error ('Illegal number of paramer in "isset()"'); } $par = implode(',',p); - if (strncasecmp($par,'$_smarty_tpl->getConfigVariable',strlen('$_smarty_tpl->getConfigVariable')) === 0) { + if (strncasecmp($par,'$_smarty_tpl->_getConfigVariable',strlen('$_smarty_tpl->_getConfigVariable')) === 0) { self::$prefix_number++; $this->compiler->prefix_code[] = ''; $isset_par = '$_tmp'.self::$prefix_number; diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 8351e4f0..b8a7c209 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -102,6 +102,12 @@ require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_resource_base.php'; * This is the main Smarty class * * @package Smarty + * + * @method int clearAllCache(int $exp_time = null, string $type = null) + * @method int clearCache(string $template_name, string $cache_id = null, string $compile_id = null, int $exp_time = null, string $type = null) + * @method int compileAllTemplates(Smarty $smarty, string $extension = '.tpl', bool $force_compile = false, int $time_limit = 0, int $max_errors = null) + * @method int compileAllConfig(Smarty $smarty, string $extension = '.conf', bool $force_compile = false, int $time_limit = 0, int $max_errors = null) + * */ class Smarty extends Smarty_Internal_TemplateBase { @@ -112,7 +118,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.28-dev/45'; + const SMARTY_VERSION = '3.1.28-dev/47'; /** * define variable scopes @@ -728,6 +734,13 @@ class Smarty extends Smarty_Internal_TemplateBase */ public $_parserdebug = false; + /** + * This object type (Smarty = 1, template = 2, data = 4) + * + * @var int + */ + public $_objType = 1; + /** * removed properties * @@ -735,6 +748,13 @@ class Smarty extends Smarty_Internal_TemplateBase */ public $obsoleteProperties = array('resource_caching', 'template_resource_caching'); + /** + * Extension object cache + * + * @var array + */ + public static $extObjCache = array(); + /**#@-*/ /** @@ -851,43 +871,6 @@ class Smarty extends Smarty_Internal_TemplateBase } } - /** - * Empty cache folder - * - * @param integer $exp_time expiration time - * @param string $type resource type - * - * @return integer number of cache files deleted - */ - public function clearAllCache($exp_time = null, $type = null) - { - // load cache resource and call clearAll - $_cache_resource = Smarty_CacheResource::load($this, $type); - Smarty_CacheResource::invalidLoadedCache($this); - - return $_cache_resource->clearAll($this, $exp_time); - } - - /** - * Empty cache for a specific template - * - * @param string $template_name template name - * @param string $cache_id cache id - * @param string $compile_id compile id - * @param integer $exp_time expiration time - * @param string $type resource type - * - * @return integer number of cache files deleted - */ - public function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null) - { - // load cache resource and call clear - $_cache_resource = Smarty_CacheResource::load($this, $type); - Smarty_CacheResource::invalidLoadedCache($this); - - return $_cache_resource->clear($this, $template_name, $cache_id, $compile_id, $exp_time); - } - /** * Loads security class and enables security * @@ -1184,119 +1167,6 @@ class Smarty extends Smarty_Internal_TemplateBase } } - /** - * Set default modifiers - * - * @param array|string $modifiers modifier or list of modifiers to set - * - * @return Smarty current Smarty instance for chaining - */ - public function setDefaultModifiers($modifiers) - { - $this->default_modifiers = (array) $modifiers; - - return $this; - } - - /** - * Add default modifiers - * - * @param array|string $modifiers modifier or list of modifiers to add - * - * @return Smarty current Smarty instance for chaining - */ - public function addDefaultModifiers($modifiers) - { - if (is_array($modifiers)) { - $this->default_modifiers = array_merge($this->default_modifiers, $modifiers); - } else { - $this->default_modifiers[] = $modifiers; - } - - return $this; - } - - /** - * Get default modifiers - * - * @return array list of default modifiers - */ - public function getDefaultModifiers() - { - return $this->default_modifiers; - } - - /** - * Set autoload filters - * - * @param array $filters filters to load automatically - * @param string $type "pre", "output", … specify the filter type to set. Defaults to none treating $filters' - * keys as the appropriate types - * - * @return Smarty current Smarty instance for chaining - */ - public function setAutoloadFilters($filters, $type = null) - { - Smarty_Internal_Extension_AutoLoadFilter::setAutoloadFilters($this, $filters, $type); - return $this; - } - - /** - * Add autoload filters - * - * @param array $filters filters to load automatically - * @param string $type "pre", "output", … specify the filter type to set. Defaults to none treating $filters' - * keys as the appropriate types - * - * @return Smarty current Smarty instance for chaining - */ - public function addAutoloadFilters($filters, $type = null) - { - Smarty_Internal_Extension_AutoLoadFilter::addAutoloadFilters($this, $filters, $type); - return $this; - } - - /** - * Get autoload filters - * - * @param string $type type of filter to get autoloads for. Defaults to all autoload filters - * - * @return array array( 'type1' => array( 'filter1', 'filter2', … ) ) or array( 'filter1', 'filter2', …) if $type - * was specified - */ - public function getAutoloadFilters($type = null) - { - return Smarty_Internal_Extension_AutoLoadFilter::getAutoloadFilters($this, $type); - } - - /** - * return name of debugging template - * - * @return string - */ - public function getDebugTemplate() - { - return $this->debug_tpl; - } - - /** - * set the debug template - * - * @param string $tpl_name - * - * @return Smarty current Smarty instance for chaining - * @throws SmartyException if file is not readable - */ - public function setDebugTemplate($tpl_name) - { - if (!is_readable($tpl_name)) { - throw new SmartyException("Unknown file '{$tpl_name}'"); - } - $this->debug_tpl = $tpl_name; - - return $this; - } - /** * creates a template object * @@ -1384,74 +1254,6 @@ class Smarty extends Smarty_Internal_TemplateBase return $path; } - /** - * Compile all template files - * - * @param string $extension file extension - * @param bool $force_compile force all to recompile - * @param int $time_limit - * @param int $max_errors - * - * @return integer number of template files recompiled - */ - public function compileAllTemplates($extension = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null) - { - return Smarty_Internal_Extension_CompileAll::compileAll($extension, $force_compile, $time_limit, $max_errors, $this); - } - - /** - * Compile all config files - * - * @param string $extension file extension - * @param bool $force_compile force all to recompile< - * @param int $time_limit - * @param int $max_errors - * - * @return integer number of template files recompiled - */ - public function compileAllConfig($extension = '.conf', $force_compile = false, $time_limit = 0, $max_errors = null) - { - return Smarty_Internal_Extension_CompileAll::compileAll($extension, $force_compile, $time_limit, $max_errors, $this, true); - } - - /** - * Delete compiled template file - * - * @param string $resource_name template name - * @param string $compile_id compile id - * @param integer $exp_time expiration time - * - * @return integer number of template files deleted - */ - public function clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null) - { - return Smarty_Internal_Extension_ClearCompiled::clearCompiledTemplate($this, $resource_name, $compile_id, $exp_time); - } - - /** - * Return array of tag/attributes of all tags used by an template - * - * @param Smarty_Internal_Template $template - * - * @return array of tag/attributes - */ - public function getTags(Smarty_Internal_Template $template) - { - return Smarty_Internal_Utility::getTags($template); - } - - /** - * Run installation test - * - * @param array $errors Array to write errors into, rather than outputting them - * - * @return boolean true if setup is fine, false if something is wrong - */ - public function testInstall(&$errors = null) - { - return Smarty_Internal_TestInstall::testInstall($this, $errors); - } - /** * @param boolean $compile_check */ @@ -1468,38 +1270,6 @@ class Smarty extends Smarty_Internal_TemplateBase $this->use_sub_dirs = $use_sub_dirs; } - /** - * @param boolean $caching - */ - public function setCaching($caching) - { - $this->caching = $caching; - } - - /** - * @param int $cache_lifetime - */ - public function setCacheLifetime($cache_lifetime) - { - $this->cache_lifetime = $cache_lifetime; - } - - /** - * @param string $compile_id - */ - public function setCompileId($compile_id) - { - $this->compile_id = $compile_id; - } - - /** - * @param string $cache_id - */ - public function setCacheId($cache_id) - { - $this->cache_id = $cache_id; - } - /** * @param int $error_reporting */ @@ -1596,6 +1366,32 @@ class Smarty extends Smarty_Internal_TemplateBase $this->compile_locking = $compile_locking; } + /** + * @param string $default_resource_type + */ + public function setDefaultResourceType($default_resource_type) + { + $this->default_resource_type = $default_resource_type; + } + + /** + * @param string $caching_type + */ + public function setCachingType($caching_type) + { + $this->caching_type = $caching_type; + } + + /** + * Test install + * + * @param null $errors + */ + public function testInstall(&$errors = null) + { + Smarty_Internal_TestInstall::testInstall($this, $errors); + } + /** * Class destructor */ @@ -1647,7 +1443,11 @@ class Smarty extends Smarty_Internal_TemplateBase } elseif (in_array($name, $this->obsoleteProperties)) { return; } else { - trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE); + if (is_object($value) && method_exists($value, $name)) { + $this->$name = $value; + } else { + trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE); + } } } diff --git a/libs/sysplugins/smarty_cacheresource.php b/libs/sysplugins/smarty_cacheresource.php index 98e873e7..36008b9e 100644 --- a/libs/sysplugins/smarty_cacheresource.php +++ b/libs/sysplugins/smarty_cacheresource.php @@ -73,8 +73,8 @@ abstract class Smarty_CacheResource { if ($_template->cached->handler->process($_template)) { ob_start(); - $_template->cached->unifunc($_template); - + $unifunc = $_template->cached->unifunc; + $unifunc($_template); return ob_get_clean(); } diff --git a/libs/sysplugins/smarty_cacheresource_custom.php b/libs/sysplugins/smarty_cacheresource_custom.php index 33238210..4521daab 100644 --- a/libs/sysplugins/smarty_cacheresource_custom.php +++ b/libs/sysplugins/smarty_cacheresource_custom.php @@ -139,7 +139,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource */ $_smarty_tpl = $_template; eval("?>" . $content); - + $cached->content = null; return true; } @@ -190,7 +190,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource */ public function clearAll(Smarty $smarty, $exp_time = null) { - return $this->delete(null, null, null, $exp_time); + return $this->delete(null, null, null, $exp_time); } /** diff --git a/libs/sysplugins/smarty_data.php b/libs/sysplugins/smarty_data.php index 8074513d..ecd88c11 100644 --- a/libs/sysplugins/smarty_data.php +++ b/libs/sysplugins/smarty_data.php @@ -30,12 +30,20 @@ class Smarty_Data extends Smarty_Internal_Data * @var string */ public $dataObjectName = ''; + /** * Smarty object * * @var Smarty */ public $smarty = null; + + /** + * This object type (Smarty = 1, template = 2, data = 4) + * + * @var int + */ + public $_objType = 4; /** * create Smarty data object diff --git a/libs/sysplugins/smarty_internal_compile_config_load.php b/libs/sysplugins/smarty_internal_compile_config_load.php index dbbc7bde..69c44882 100644 --- a/libs/sysplugins/smarty_internal_compile_config_load.php +++ b/libs/sysplugins/smarty_internal_compile_config_load.php @@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase */ public $required_attributes = array('file'); + /** * Attribute definition: Overwrites base class. * @@ -30,6 +31,7 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase */ public $shorttag_order = array('file', 'section'); + /** * Attribute definition: Overwrites base class. * @@ -41,7 +43,7 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase /** * Compiles code for the {config_load} tag * - * @param array $args array with attributes from parser + * @param array $args array with attributes from parser * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * * @return string compiled code @@ -75,7 +77,7 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase } } // create config object - $_output = ""; + $_output = "configLoad($conf_file, $section, '$scope');?>"; return $_output; } diff --git a/libs/sysplugins/smarty_internal_compile_private_special_variable.php b/libs/sysplugins/smarty_internal_compile_private_special_variable.php index 39dc57d4..42741408 100644 --- a/libs/sysplugins/smarty_internal_compile_private_special_variable.php +++ b/libs/sysplugins/smarty_internal_compile_private_special_variable.php @@ -99,9 +99,9 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C case 'config': if (isset($_index[2])) { - return "(is_array(\$tmp = \$_smarty_tpl->getConfigVariable($_index[1])) ? \$tmp[$_index[2]] : null)"; + return "(is_array(\$tmp = \$_smarty_tpl->_getConfigVariable($_index[1])) ? \$tmp[$_index[2]] : null)"; } else { - return "\$_smarty_tpl->getConfigVariable($_index[1])"; + return "\$_smarty_tpl->_getConfigVariable($_index[1])"; } case 'ldelim': $_ldelim = $compiler->smarty->left_delimiter; diff --git a/libs/sysplugins/smarty_internal_config_file_compiler.php b/libs/sysplugins/smarty_internal_config_file_compiler.php index a783b056..d334936c 100644 --- a/libs/sysplugins/smarty_internal_config_file_compiler.php +++ b/libs/sysplugins/smarty_internal_config_file_compiler.php @@ -143,7 +143,7 @@ class Smarty_Internal_Config_File_Compiler strftime("%Y-%m-%d %H:%M:%S") . "\n"; $template_header .= " compiled from \"" . $this->template->source->filepath . "\" */ ?>\n"; - $code = 'config_data, true) . '); ?>'; return $template_header . Smarty_Internal_Extension_CodeFrame::create($this->template, $code); } diff --git a/libs/sysplugins/smarty_internal_data.php b/libs/sysplugins/smarty_internal_data.php index b27f8478..ea948256 100644 --- a/libs/sysplugins/smarty_internal_data.php +++ b/libs/sysplugins/smarty_internal_data.php @@ -13,6 +13,15 @@ * * @package Smarty * @subpackage Template + * + * @method mixed getConfigVars(string $varname = null, bool $search_parents = true) + * @method mixed getStreamVariable(string $variable) + * @local_method mixed getTemplateVars(string $varname = null, Smarty_Internal_Data $_ptr = null, bool $search_parents = true) + * @method Smarty_Internal_Data clearAssign(mixed $tpl_var) + * @method Smarty_Internal_Data clearAllAssign() + * @method Smarty_Internal_Data clearConfig(string $varname = null) + * @method Smarty_Internal_Data configLoad(string $config_file, mixed $sections = null, string $scope = 'local') + * @property int $_objType */ class Smarty_Internal_Data { @@ -33,7 +42,7 @@ class Smarty_Internal_Data /** * parent template (if any) * - * @var Smarty_Internal_Template + * @var Smarty|Smarty_Internal_Template|Smarty_Internal_Data */ public $parent = null; @@ -51,6 +60,16 @@ class Smarty_Internal_Data */ public $_cache = array(); + /** + * Cache for property information from generic getter/setter + * Preloaded with names which should not use with generic getter/setter + * + * @var array + */ + private $_property_info = array('AutoloadFilters' => 0, 'DefaultModifiers' => 0, 'ConfigVars' => 0, + 'DebugTemplate' => 0, 'RegisteredObject' => 0, 'StreamVariable' => 0, + 'TemplateVars' => 0,); + /** * assigns a Smarty variable * @@ -78,6 +97,57 @@ class Smarty_Internal_Data return $this; } + /** + * appends values to template variables + * + * @api Smarty::append() + * @link http://www.smarty.net/docs/en/api.append.tpl + * + * @param array|string $tpl_var the template variable name(s) + * @param mixed $value the value to append + * @param bool $merge flag if array elements shall be merged + * @param bool $nocache if true any output of this variable will + * be not cached + * + * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty + */ + public function append($tpl_var, $value = null, $merge = false, $nocache = false) + { + if (is_array($tpl_var)) { + // $tpl_var is an array, ignore $value + foreach ($tpl_var as $_key => $_val) { + if ($_key != '') { + $this->append($_key, $_val, $merge, $nocache); + } + } + } else { + if ($tpl_var != '' && isset($value)) { + if (!isset($this->tpl_vars[$tpl_var])) { + $tpl_var_inst = $this->_getVariable($tpl_var, null, true, false); + if ($tpl_var_inst instanceof Smarty_Undefined_Variable) { + $this->tpl_vars[$tpl_var] = new Smarty_Variable(null, $nocache); + } else { + $this->tpl_vars[$tpl_var] = clone $tpl_var_inst; + } + } + if (!(is_array($this->tpl_vars[$tpl_var]->value) || + $this->tpl_vars[$tpl_var]->value instanceof ArrayAccess) + ) { + settype($this->tpl_vars[$tpl_var]->value, 'array'); + } + if ($merge && is_array($value)) { + foreach ($value as $_mkey => $_mval) { + $this->tpl_vars[$tpl_var]->value[$_mkey] = $_mval; + } + } else { + $this->tpl_vars[$tpl_var]->value[] = $value; + } + } + } + + return $this; + } + /** * assigns a global Smarty variable * @@ -98,7 +168,22 @@ class Smarty_Internal_Data $ptr = $ptr->parent; } } + return $this; + } + /** + * appends values to template variables by reference + * + * @param string $tpl_var the template variable name + * @param mixed &$value the referenced value to append + * @param boolean $merge flag if array elements shall be merged + * + * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for + * chaining + */ + public function appendByRef($tpl_var, &$value, $merge = false) + { + Smarty_Internal_Method_AppendByRef::appendByRef($this, $tpl_var, $value, $merge); return $this; } @@ -122,167 +207,173 @@ class Smarty_Internal_Data return $this; } - /** - * appends values to template variables - * - * @param array|string $tpl_var the template variable name(s) - * @param mixed $value the value to append - * @param boolean $merge flag if array elements shall be merged - * @param boolean $nocache if true any output of this variable will be not cached - * - * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for - * chaining - */ - public function append($tpl_var, $value = null, $merge = false, $nocache = false) - { - Smarty_Internal_Extension_Append::append($this, $tpl_var, $value, $merge, $nocache); - return $this; - } - - /** - * appends values to template variables by reference - * - * @param string $tpl_var the template variable name - * @param mixed &$value the referenced value to append - * @param boolean $merge flag if array elements shall be merged - * - * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for - * chaining - */ - public function appendByRef($tpl_var, &$value, $merge = false) - { - Smarty_Internal_Extension_Append::appendByRef($this, $tpl_var, $value, $merge); - return $this; - } - /** * Returns a single or all template variables * - * @param string $varname variable name or null - * @param object $_ptr optional pointer to data object - * @param boolean $search_parents include parent templates? + * @api Smarty::getTemplateVars() + * @link http://www.smarty.net/docs/en/api.get.template.vars.tpl * - * @return string variable value or or array of variables + * @param string $varname variable name or null + * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object + * @param bool $search_parents include parent templates? + * + * @return mixed variable value or or array of variables */ - public function getTemplateVars($varname = null, $_ptr = null, $search_parents = true) + public function getTemplateVars($varname = null, Smarty_Internal_Data $_ptr = null, $search_parents = true) { - return Smarty_Internal_Extension_GetVars::getTemplateVars($this, $varname, $_ptr, $search_parents); - } - - /** - * clear the given assigned template variable. - * - * @param string|array $tpl_var the template variable(s) to clear - * - * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for - * chaining - */ - public function clearAssign($tpl_var) - { - if (is_array($tpl_var)) { - foreach ($tpl_var as $curr_var) { - unset($this->tpl_vars[$curr_var]); + if (isset($varname)) { + $_var = $this->_getVariable($varname, $_ptr, $search_parents, false); + if (is_object($_var)) { + return $_var->value; + } else { + return null; } } else { - unset($this->tpl_vars[$tpl_var]); + $_result = array(); + if ($_ptr === null) { + $_ptr = $this; + } + while ($_ptr !== null) { + foreach ($_ptr->tpl_vars AS $key => $var) { + if (!array_key_exists($key, $_result)) { + $_result[$key] = $var->value; + } + } + // not found, try at parent + if ($search_parents) { + $_ptr = $_ptr->parent; + } else { + $_ptr = null; + } + } + if ($search_parents && isset(Smarty::$global_tpl_vars)) { + foreach (Smarty::$global_tpl_vars AS $key => $var) { + if (!array_key_exists($key, $_result)) { + $_result[$key] = $var->value; + } + } + } + return $_result; } - - return $this; } - - /** - * clear all the assigned template variables. - * - * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for - * chaining - */ - public function clearAllAssign() - { - $this->tpl_vars = array(); - - return $this; - } - - /** - * load a config file, optionally load just selected sections - * - * @param string $config_file filename - * @param mixed $sections array of section names, single section or null - * - * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for - * chaining - */ - public function configLoad($config_file, $sections = null) - { - // load Config class - Smarty_Internal_Extension_Config::configLoad($this, $config_file, $sections); - return $this; - } - /** * gets the object of a Smarty variable * - * @param string $variable the name of the Smarty variable - * @param object $_ptr optional pointer to data object - * @param boolean $search_parents search also in parent data - * @param bool $error_enable + * @param string $variable the name of the Smarty variable + * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object + * @param bool $search_parents search also in parent data + * @param bool $error_enable * - * @return object the object of the variable + * @return \Smarty_Variable */ - public function getVariable($variable, $_ptr = null, $search_parents = true, $error_enable = true) + public function _getVariable($variable, Smarty_Internal_Data $_ptr = null, $search_parents = true, $error_enable = true) { - return Smarty_Internal_Extension_GetVars::getVariable($this, $variable, $_ptr, $search_parents, $error_enable); + if ($_ptr === null) { + $_ptr = $this; + } + while ($_ptr !== null) { + if (isset($_ptr->tpl_vars[$variable])) { + // found it, return it + return $_ptr->tpl_vars[$variable]; + } + // not found, try at parent + if ($search_parents) { + $_ptr = $_ptr->parent; + } else { + $_ptr = null; + } + } + if (isset(Smarty::$global_tpl_vars[$variable])) { + // found it, return it + return Smarty::$global_tpl_vars[$variable]; + } + /* @var \Smarty $smarty */ + $smarty = isset($this->smarty) ? $this->smarty : $this; + if ($smarty->error_unassigned && $error_enable) { + // force a notice + $x = $$variable; + } + + return new Smarty_Undefined_Variable; } /** - * gets a config variable + * gets a config variable value * * @param string $variable the name of the config variable * @param bool $error_enable * * @return mixed the value of the config variable */ - public function getConfigVariable($variable, $error_enable = true) + public function _getConfigVariable($variable, $error_enable = true) { - return Smarty_Internal_Extension_Config::getConfigVariable($this, $variable, $error_enable = true); + $_ptr = $this; + while ($_ptr !== null) { + if (isset($_ptr->config_vars[$variable])) { + // found it, return it + return $_ptr->config_vars[$variable]; + } + // not found, try at parent + $_ptr = $_ptr->parent; + } + /* @var \Smarty $smarty */ + $smarty = isset($this->smarty) ? $this->smarty : $this; + if ($smarty->error_unassigned && $error_enable) { + // force a notice + $x = $$variable; + } + return null; } /** - * Returns a single or all config variables + * Handle unknown class methods * - * @param string $varname variable name or null - * @param bool $search_parents - * - * @return string variable value or or array of variables - */ - public function getConfigVars($varname = null, $search_parents = true) - { - return Smarty_Internal_Extension_Config::getConfigVars($this, $varname, $search_parents); - } - - /** - * Deassigns a single or all config variables - * - * @param string $varname variable name or null - * - * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for - * chaining - */ - public function clearConfig($varname = null) - { - return Smarty_Internal_Extension_Config::clearConfig($this, $varname); - } - - /** - * gets a stream variable - * - * @param string $variable the stream of the variable + * @param string $name unknown method-name + * @param array $args argument array * + * @return mixed * @throws SmartyException - * @return mixed the value of the stream variable */ - public function getStreamVariable($variable) + public function __call($name, $args) { - return Smarty_Internal_Extension_GetStreamVar::getStreamVariable($this, $variable); + static $_resolved_property_name = array(); + + if (!isset(Smarty::$extObjCache[$name])) { + + $class = 'Smarty_Internal_Method_' . ucfirst($name); + if (preg_match('/^(set|get)([A-Z].*)$/', $name, $match)) { + if (!isset($this->_property_info[$prop = $match[2]])) { + $smarty = isset($this->smarty) ? $this->smarty : $this; + if (!isset($this->_property_info[$prop])) { + // convert camel case to underscored name + $_resolved_property_name[$prop] = $pn = strtolower(join('_', preg_split('/([A-Z][^A-Z]*)/', $prop, - 1, PREG_SPLIT_NO_EMPTY | + PREG_SPLIT_DELIM_CAPTURE))); + $this->_property_info[$prop] = property_exists($this, $pn) ? 1 : ($this->_objType == 2 && + property_exists($smarty, $pn) ? 2 : 0); + } + } + if ($this->_property_info[$prop]) { + $pn = $_resolved_property_name[$prop]; + if ($match[1] == 'get') { + return $this->_property_info[$prop] == 1 ? $this->$pn : $this->smarty->$pn; + } else { + return $this->_property_info[$prop] == + 1 ? $this->$pn = $args[0] : $this->smarty->$pn = $args[0]; + } + } elseif (!class_exists($class)) { + throw new SmartyException("property '$pn' does not exist."); + } + } + if (class_exists($class)) { + $callback = array(Smarty::$extObjCache[$name] = new $class(), $name); + } + } else { + $callback = array(Smarty::$extObjCache[$name], $name); + } + if (isset($callback) && $callback[0]->objMap | $this->_objType) { + array_unshift($args, $this); + return call_user_func_array($callback, $args); + } + throw new SmartyException("method '$name' does not exist."); } } diff --git a/libs/sysplugins/smarty_internal_extension_config.php b/libs/sysplugins/smarty_internal_extension_config.php deleted file mode 100644 index c97e3d6d..00000000 --- a/libs/sysplugins/smarty_internal_extension_config.php +++ /dev/null @@ -1,160 +0,0 @@ -smarty) ? $obj->smarty : $obj; - $confObj = new $smarty->template_class($config_file, $smarty, $obj); - $confObj->caching = Smarty::CACHING_OFF; - $confObj->source = Smarty_Template_Config::load($confObj); - $confObj->source->config_sections = $sections; - $confObj->source->scope = $scope; - $confObj->compiled = Smarty_Template_Compiled::load($confObj); - if ($confObj->smarty->debugging) { - Smarty_Internal_Debug::start_render($confObj); - } - $confObj->compiled->render($confObj); - if ($confObj->smarty->debugging) { - Smarty_Internal_Debug::end_render($confObj); - } - if ($obj instanceof Smarty_Internal_Template) { - $obj->compiled->file_dependency[$confObj->source->uid] = array($confObj->source->filepath, $confObj->source->getTimeStamp(), $confObj->source->type); - } - } - - /** - * load config variables - * - * @param mixed $sections array of section names, single section or null - * @param string $scope global,parent or local - * - * @throws Exception - */ - static function loadConfigVars($_template, $_config_vars) - { - $scope = $_template->source->scope; - // pointer to scope (local scope is parent of template object - $scope_ptr = $_template->parent; - if ($scope == 'parent') { - if (isset($_template->parent->parent)) { - $scope_ptr = $_template->parent->parent; - } - } elseif ($scope == 'root' || $scope == 'global') { - while (isset($scope_ptr->parent)) { - $scope_ptr = $scope_ptr->parent; - } - } - // copy global config vars - foreach ($_config_vars['vars'] as $variable => $value) { - if ($_template->smarty->config_overwrite || !isset($scope_ptr->config_vars[$variable])) { - $scope_ptr->config_vars[$variable] = $value; - } else { - $scope_ptr->config_vars[$variable] = array_merge((array) $scope_ptr->config_vars[$variable], (array) $value); - } - } - // scan sections - $sections = $_template->source->config_sections; - if (!empty($sections)) { - foreach ((array) $sections as $_template_section) { - if (isset($_config_vars['sections'][$_template_section])) { - foreach ($_config_vars['sections'][$_template_section]['vars'] as $variable => $value) { - if ($_template->smarty->config_overwrite || !isset($scope_ptr->config_vars[$variable])) { - $scope_ptr->config_vars[$variable] = $value; - } else { - $scope_ptr->config_vars[$variable] = array_merge((array) $scope_ptr->config_vars[$variable], (array) $value); - } - } - } - } - } - } - - /** - * Returns a single or all config variables - * - * @param string $varname variable name or null - * @param bool $search_parents - * - * @return string variable value or or array of variables - */ - static function getConfigVars($obj, $varname = null, $search_parents = true) - { - $_ptr = $obj; - $var_array = array(); - while ($_ptr !== null) { - if (isset($varname)) { - if (isset($_ptr->config_vars[$varname])) { - return $_ptr->config_vars[$varname]; - } - } else { - $var_array = array_merge($_ptr->config_vars, $var_array); - } - // not found, try at parent - if ($search_parents) { - $_ptr = $_ptr->parent; - } else { - $_ptr = null; - } - } - if (isset($varname)) { - return ''; - } else { - return $var_array; - } - } - - /** - * gets a config variable - * - * @param string $variable the name of the config variable - * @param bool $error_enable - * - * @return mixed the value of the config variable - */ - static function getConfigVariable($obj, $variable, $error_enable = true) - { - $_ptr = $obj; - while ($_ptr !== null) { - if (isset($_ptr->config_vars[$variable])) { - // found it, return it - return $_ptr->config_vars[$variable]; - } - // not found, try at parent - $_ptr = $_ptr->parent; - } - if ($obj->error_unassigned && $error_enable) { - // force a notice - $x = $$variable; - } - - return null; - } - - /** - * remove a single or all config variables - * - * @param string $name variable name or null - * - * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining - */ - static function clearConfig($obj, $name = null) - { - if (isset($name)) { - unset($obj->config_vars[$name]); - } else { - $obj->config_vars = array(); - } - return $obj; - } -} diff --git a/libs/sysplugins/smarty_internal_extension_defaulttemplatehandler.php b/libs/sysplugins/smarty_internal_extension_defaulttemplatehandler.php deleted file mode 100644 index 1f58f04f..00000000 --- a/libs/sysplugins/smarty_internal_extension_defaulttemplatehandler.php +++ /dev/null @@ -1,84 +0,0 @@ -isConfig) { - $default_handler = $_template->smarty->default_config_handler_func; - } else { - $default_handler = $_template->smarty->default_template_handler_func; - } - $_content = $_timestamp = null; - $_return = call_user_func_array($default_handler, - array($source->type, $source->name, &$_content, &$_timestamp, $source->smarty)); - if (is_string($_return)) { - $source->exists = is_file($_return); - if ($source->exists) { - $source->timestamp = filemtime($_return); - } - $source->filepath = $_return; - } elseif ($_return === true) { - $source->content = $_content; - $source->timestamp = $_timestamp; - $source->exists = true; - $source->recompiled = true; - $source->filepath = false; - } - } - - /** - * register template default handler - * - * @param Smarty $smarty - * @param mixed $callback - * - * @throws SmartyException - */ - static function registerDefaultTemplateHandler(Smarty $smarty, $callback) - { - if (is_callable($callback)) { - $smarty->default_template_handler_func = $callback; - } else { - throw new SmartyException("Default template handler not callable"); - } - } - - /** - * register config default handler - * - * @param Smarty $smarty - * @param mixed $callback - * - * @throws SmartyException - */ - static function registerDefaultConfigHandler(Smarty $smarty, $callback) - { - if (is_callable($callback)) { - $smarty->default_config_handler_func = $callback; - } else { - throw new SmartyException("Default config handler not callable"); - } - } -} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_extension_filter.php b/libs/sysplugins/smarty_internal_extension_filter.php deleted file mode 100644 index 1fd8fcaf..00000000 --- a/libs/sysplugins/smarty_internal_extension_filter.php +++ /dev/null @@ -1,150 +0,0 @@ - true, 'post' => true, 'output' => true, 'variable' => true); - - /** - * Registers a filter function - * - * @param \Smarty_Internal_Template|\Smarty $obj - * @param string $type filter type - * @param callback $callback - * @param string|null $name optional filter name - * - * @throws \SmartyException - */ - static function registerFilter($obj, $type, $callback, $name) - { - self::_checkFilterType($type); - $name = isset($name) ? $name : self::_getFilterName($callback); - if (!is_callable($callback)) { - throw new SmartyException("{$type}filter \"{$name}\" not callable"); - } - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; - $smarty->registered_filters[$type][$name] = $callback; - } - - /** - * Unregisters a filter function - * - * @param \Smarty_Internal_Template|\Smarty $obj - * @param string $type filter type - * @param callback|string $callback - * - */ - static function unregisterFilter($obj, $type, $callback) - { - self::_checkFilterType($type); - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; - if (isset($smarty->registered_filters[$type])) { - $name = is_string($callback) ? $callback : self::_getFilterName($callback); - if (isset($smarty->registered_filters[$type][$name])) { - unset($smarty->registered_filters[$type][$name]); - if (empty($smarty->registered_filters[$type])) { - unset($smarty->registered_filters[$type]); - } - } - } - } - - /** - * load a filter of specified type and name - * - * @param \Smarty_Internal_Template|\Smarty $obj - * @param string $type filter type - * @param string $name filter name - * - * @return bool - * @throws SmartyException if filter could not be loaded - */ - static function loadFilter($obj, $type, $name) - { - self::_checkFilterType($type); - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; - $_plugin = "smarty_{$type}filter_{$name}"; - $_filter_name = $_plugin; - if ($smarty->loadPlugin($_plugin)) { - if (class_exists($_plugin, false)) { - $_plugin = array($_plugin, 'execute'); - } - if (is_callable($_plugin)) { - $smarty->registered_filters[$type][$_filter_name] = $_plugin; - return true; - } - } - throw new SmartyException("{$type}filter \"{$name}\" not callable"); - } - - /** - * unload a filter of specified type and name - * - * @param \Smarty_Internal_Template|\Smarty $obj - * @param string $type filter type - * @param string $name filter name - * - */ - static function unloadFilter($obj, $type, $name) - { - self::_checkFilterType($type); - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; - if (isset($smarty->registered_filters[$type])) { - $_filter_name = "smarty_{$type}filter_{$name}"; - if (isset($smarty->registered_filters[$type][$_filter_name])) { - unset ($smarty->registered_filters[$type][$_filter_name]); - if (empty($smarty->registered_filters[$type])) { - unset($smarty->registered_filters[$type]); - } - } - } - } - - /** - * Return internal filter name - * - * @param callback $function_name - * - * @return string internal filter name - */ - static function _getFilterName($function_name) - { - if (is_array($function_name)) { - $_class_name = (is_object($function_name[0]) ? get_class($function_name[0]) : $function_name[0]); - - return $_class_name . '_' . $function_name[1]; - } elseif (is_string($function_name)) { - return $function_name; - } else { - return 'closure'; - } - } - - /** - * Check if filter type is valid - * - * @param string $type - * - * @throws \SmartyException - */ - static function _checkFilterType($type) - { - if (!isset(self::$filterTypes[$type])) { - throw new SmartyException("Illegal filter type \"{$type}\""); - } - } -} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_extension_getvars.php b/libs/sysplugins/smarty_internal_extension_getvars.php deleted file mode 100644 index c2d0d9d4..00000000 --- a/libs/sysplugins/smarty_internal_extension_getvars.php +++ /dev/null @@ -1,103 +0,0 @@ -value; - } else { - return null; - } - } else { - $_result = array(); - if ($_ptr === null) { - $_ptr = $obj; - } - while ($_ptr !== null) { - foreach ($_ptr->tpl_vars AS $key => $var) { - if (!array_key_exists($key, $_result)) { - $_result[$key] = $var->value; - } - } - // not found, try at parent - if ($search_parents) { - $_ptr = $_ptr->parent; - } else { - $_ptr = null; - } - } - if ($search_parents && isset(Smarty::$global_tpl_vars)) { - foreach (Smarty::$global_tpl_vars AS $key => $var) { - if (!array_key_exists($key, $_result)) { - $_result[$key] = $var->value; - } - } - } - - return $_result; - } - } - - /** - * gets the object of a Smarty variable - * - * @param $obj - * @param string $variable the name of the Smarty variable - * @param object $_ptr optional pointer to data object - * @param boolean $search_parents search also in parent data - * @param bool $error_enable - * - * @return object the object of the variable - */ - public static function getVariable($obj, $variable, $_ptr, $search_parents, $error_enable) - { - if ($_ptr === null) { - $_ptr = $obj; - } - while ($_ptr !== null) { - if (isset($_ptr->tpl_vars[$variable])) { - // found it, return it - return $_ptr->tpl_vars[$variable]; - } - // not found, try at parent - if ($search_parents) { - $_ptr = $_ptr->parent; - } else { - $_ptr = null; - } - } - if (isset(Smarty::$global_tpl_vars[$variable])) { - // found it, return it - return Smarty::$global_tpl_vars[$variable]; - } - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; - if ($smarty->error_unassigned && $error_enable) { - // force a notice - $x = $$variable; - } - - return new Smarty_Undefined_Variable; - } -} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_extension_object.php b/libs/sysplugins/smarty_internal_extension_object.php deleted file mode 100644 index 05fc35a6..00000000 --- a/libs/sysplugins/smarty_internal_extension_object.php +++ /dev/null @@ -1,110 +0,0 @@ -smarty) ? $obj->smarty : $obj; - $smarty->registered_objects[$object_name] = array($object_impl, (array) $allowed, (boolean) $smarty_args, - (array) $block_methods); - } - - /** - * return a reference to a registered object - * - * @param \Smarty_Internal_Template|\Smarty $obj - * @param string $name object name - * - * @return object - * @throws \SmartyException if no such object is found - */ - static function getRegisteredObject($obj, $name) - { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; - if (!isset($smarty->registered_objects[$name])) { - throw new SmartyException("'$name' is not a registered object"); - } - if (!is_object($smarty->registered_objects[$name][0])) { - throw new SmartyException("registered '$name' is not an object"); - } - return $smarty->registered_objects[$name][0]; - } - - /** - * unregister an object - * - * @param \Smarty_Internal_Template|\Smarty $obj - * @param string $name object name - * - * @return \Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or - * Smarty_Internal_Template) instance for chaining - */ - static function unregisterObject($obj, $name) - { - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; - if (isset($smarty->registered_objects[$name])) { - unset($smarty->registered_objects[$name]); - } - } - - /** - * Registers static classes to be used in templates - * - * @param \Smarty_Internal_Template|\Smarty $obj - * @param string $class_name - * @param string $class_impl the referenced PHP class to register - * - * @return \Smarty_Internal_Templatebase - * @throws \SmartyException - */ - static function registerClass($obj, $class_name, $class_impl) - { - // test if exists - if (!class_exists($class_impl)) { - throw new SmartyException("Undefined class '$class_impl' in register template class"); - } - // register the class - $smarty = isset($obj->smarty) ? $obj->smarty : $obj; - $smarty->registered_classes[$class_name] = $class_impl; - } - -} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_addautoloadfilters.php b/libs/sysplugins/smarty_internal_method_addautoloadfilters.php new file mode 100644 index 00000000..b739f0e3 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_addautoloadfilters.php @@ -0,0 +1,51 @@ +smarty) ? $obj->smarty : $obj; + if ($type !== null) { + $this->_checkFilterType($type); + if (!empty($smarty->autoload_filters[$type])) { + $smarty->autoload_filters[$type] = array_merge($smarty->autoload_filters[$type], (array) $filters); + } else { + $smarty->autoload_filters[$type] = (array) $filters; + } + } else { + foreach ((array) $filters as $type => $value) { + $this->_checkFilterType($type); + if (!empty($smarty->autoload_filters[$type])) { + $smarty->autoload_filters[$type] = array_merge($smarty->autoload_filters[$type], (array) $value); + } else { + $smarty->autoload_filters[$type] = (array) $value; + } + } + } + return $obj; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_adddefaultmodifiers.php b/libs/sysplugins/smarty_internal_method_adddefaultmodifiers.php new file mode 100644 index 00000000..55d2c9e7 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_adddefaultmodifiers.php @@ -0,0 +1,42 @@ +smarty) ? $obj->smarty : $obj; + if (is_array($modifiers)) { + $this->default_modifiers = array_merge($smarty->default_modifiers, $modifiers); + } else { + $smarty->default_modifiers[] = $modifiers; + } + return $obj; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_append.php b/libs/sysplugins/smarty_internal_method_append.php new file mode 100644 index 00000000..82b741cc --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_append.php @@ -0,0 +1,72 @@ + $_val) { + if ($_key != '') { + self::append($data, $_key, $_val, $merge, $nocache); + } + } + } else { + if ($tpl_var != '' && isset($value)) { + if (!isset($data->tpl_vars[$tpl_var])) { + $tpl_var_inst = $data->_getVariable($tpl_var, null, true, false); + if ($tpl_var_inst instanceof Smarty_Undefined_Variable) { + $data->tpl_vars[$tpl_var] = new Smarty_Variable(null, $nocache); + } else { + $data->tpl_vars[$tpl_var] = clone $tpl_var_inst; + } + } + if (!(is_array($data->tpl_vars[$tpl_var]->value) || + $data->tpl_vars[$tpl_var]->value instanceof ArrayAccess) + ) { + settype($data->tpl_vars[$tpl_var]->value, 'array'); + } + if ($merge && is_array($value)) { + foreach ($value as $_mkey => $_mval) { + $data->tpl_vars[$tpl_var]->value[$_mkey] = $_mval; + } + } else { + $data->tpl_vars[$tpl_var]->value[] = $value; + } + } + } + + return $data; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_appendbyref.php b/libs/sysplugins/smarty_internal_method_appendbyref.php new file mode 100644 index 00000000..5a55e972 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_appendbyref.php @@ -0,0 +1,48 @@ +tpl_vars[$tpl_var])) { + $data->tpl_vars[$tpl_var] = new Smarty_Variable(); + } + if (!is_array($data->tpl_vars[$tpl_var]->value)) { + settype($data->tpl_vars[$tpl_var]->value, 'array'); + } + if ($merge && is_array($value)) { + foreach ($value as $_key => $_val) { + $data->tpl_vars[$tpl_var]->value[$_key] = &$value[$_key]; + } + } else { + $data->tpl_vars[$tpl_var]->value[] = &$value; + } + } + + return $data; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_clearallassign.php b/libs/sysplugins/smarty_internal_method_clearallassign.php new file mode 100644 index 00000000..1e5fec4b --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_clearallassign.php @@ -0,0 +1,37 @@ +tpl_vars = array(); + + return $data; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_clearallcache.php b/libs/sysplugins/smarty_internal_method_clearallcache.php new file mode 100644 index 00000000..24ceb0ed --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_clearallcache.php @@ -0,0 +1,41 @@ +clearAll($smarty, $exp_time); + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_clearassign.php b/libs/sysplugins/smarty_internal_method_clearassign.php new file mode 100644 index 00000000..3a7bd1e4 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_clearassign.php @@ -0,0 +1,44 @@ +tpl_vars[$curr_var]); + } + } else { + unset($data->tpl_vars[$tpl_var]); + } + + return $data; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_clearcache.php b/libs/sysplugins/smarty_internal_method_clearcache.php new file mode 100644 index 00000000..7db0a145 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_clearcache.php @@ -0,0 +1,44 @@ +clear($smarty, $template_name, $cache_id, $compile_id, $exp_time); + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_extension_clearcompiled.php b/libs/sysplugins/smarty_internal_method_clearcompiledtemplate.php similarity index 88% rename from libs/sysplugins/smarty_internal_extension_clearcompiled.php rename to libs/sysplugins/smarty_internal_method_clearcompiledtemplate.php index e6761262..6f18bf36 100644 --- a/libs/sysplugins/smarty_internal_extension_clearcompiled.php +++ b/libs/sysplugins/smarty_internal_method_clearcompiledtemplate.php @@ -1,28 +1,39 @@ clearCompiledTemplate() method + * Smarty::clearCompiledTemplate() method * * @package Smarty * @subpackage PluginsInternal * @author Uwe Tews */ -class Smarty_Internal_Extension_ClearCompiled +class Smarty_Internal_Method_ClearCompiledTemplate { + /** + * Valid for Smarty object + * + * @var int + */ + public $objMap = 1; + /** * Delete compiled template file * - * @param Smarty $smarty Smarty instance + * @api Smarty::clearCompiledTemplate() + * @link http://www.smarty.net/docs/en/api.clear.compiled.template.tpl + * + * @param \Smarty $smarty * @param string $resource_name template name * @param string $compile_id compile id * @param integer $exp_time expiration time * * @return integer number of template files deleted */ - public static function clearCompiledTemplate(Smarty $smarty, $resource_name, $compile_id, $exp_time) + public function clearCompiledTemplate(Smarty $smarty, $resource_name = null, $compile_id = null, $exp_time = null) { + $_compile_dir = $smarty->getCompileDir(); if ($_compile_dir == '/') { //We should never want to delete this! return 0; @@ -32,6 +43,7 @@ class Smarty_Internal_Extension_ClearCompiled if (isset($resource_name)) { $_save_stat = $smarty->caching; $smarty->caching = false; + /* @var Smarty_Internal_Template $tpl */ $tpl = new $smarty->template_class($resource_name, $smarty); $smarty->caching = $_save_stat; if ($tpl->source->exists) { @@ -47,7 +59,6 @@ class Smarty_Internal_Extension_ClearCompiled } else { return 0; } - $_resource_part_2 = str_replace('.php', '.cache.php', $_resource_part_1); $_resource_part_2_length = strlen($_resource_part_2); } diff --git a/libs/sysplugins/smarty_internal_method_clearconfig.php b/libs/sysplugins/smarty_internal_method_clearconfig.php new file mode 100644 index 00000000..9c6167f4 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_clearconfig.php @@ -0,0 +1,41 @@ +config_vars[$name]); + } else { + $data->config_vars = array(); + } + return $data; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_compileallconfig.php b/libs/sysplugins/smarty_internal_method_compileallconfig.php new file mode 100644 index 00000000..4d6be65c --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_compileallconfig.php @@ -0,0 +1,32 @@ +compileAll($smarty, $extension, $force_compile, $time_limit, $max_errors, true); + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_extension_compileall.php b/libs/sysplugins/smarty_internal_method_compilealltemplates.php similarity index 74% rename from libs/sysplugins/smarty_internal_extension_compileall.php rename to libs/sysplugins/smarty_internal_method_compilealltemplates.php index 40f2a7f5..6e29fc34 100644 --- a/libs/sysplugins/smarty_internal_extension_compileall.php +++ b/libs/sysplugins/smarty_internal_method_compilealltemplates.php @@ -1,29 +1,54 @@ clearCompiledTemplate() method + * Smarty::compileAllTemplates() method * * @package Smarty * @subpackage PluginsInternal * @author Uwe Tews */ -class Smarty_Internal_Extension_CompileAll +class Smarty_Internal_Method_CompileAllTemplates { + /** + * Valid for Smarty object + * + * @var int + */ + public $objMap = 1; + + /** + * Compile all template files + * + * @api Smarty::compileAllTemplates() + * + * @param \Smarty $smarty + * @param string $extension file extension + * @param bool $force_compile force all to recompile + * @param int $time_limit + * @param int $max_errors + * + * @return integer number of template files recompiled + */ + public function compileAllTemplates(Smarty $smarty, $extension = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null) + { + return $this->compileAll($smarty, $extension, $force_compile, $time_limit, $max_errors); + } + /** * Compile all template or config files * + * @param \Smarty $smarty * @param string $extension template file name extension * @param bool $force_compile force all to recompile * @param int $time_limit set maximum execution time * @param int $max_errors set maximum allowed errors - * @param Smarty $smarty Smarty instance * @param bool $isConfig flag true if called for config files * * @return int number of template files compiled */ - public static function compileAll($extension, $force_compile, $time_limit, $max_errors, Smarty $smarty, $isConfig = false) + protected function compileAll(Smarty $smarty, $extension, $force_compile, $time_limit, $max_errors, $isConfig = false) { // switch off time limit if (function_exists('set_time_limit')) { @@ -53,6 +78,7 @@ class Smarty_Internal_Extension_CompileAll $_smarty = clone $smarty; $_smarty->force_compile = $force_compile; try { + /* @var Smarty_Internal_Template $_tpl */ $_tpl = new $smarty->template_class($_file, $_smarty); $_tpl->caching = Smarty::CACHING_OFF; $_tpl->source = $isConfig ? Smarty_Template_Config::load($_tpl) : Smarty_Template_Source::load($_tpl); @@ -82,4 +108,4 @@ class Smarty_Internal_Extension_CompileAll echo "\n
"; return $_count; } -} +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_configload.php b/libs/sysplugins/smarty_internal_method_configload.php new file mode 100644 index 00000000..5fa17efa --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_configload.php @@ -0,0 +1,107 @@ +smarty) ? $data->smarty : $data; + /* @var \Smarty_Internal_Template $confObj */ + $confObj = new $smarty->template_class($config_file, $smarty, $data); + $confObj->caching = Smarty::CACHING_OFF; + $confObj->source = Smarty_Template_Config::load($confObj); + $confObj->source->config_sections = $sections; + $confObj->source->scope = $scope; + $confObj->compiled = Smarty_Template_Compiled::load($confObj); + if ($confObj->smarty->debugging) { + Smarty_Internal_Debug::start_render($confObj); + } + $confObj->compiled->render($confObj); + if ($confObj->smarty->debugging) { + Smarty_Internal_Debug::end_render($confObj); + } + if ($data instanceof Smarty_Internal_Template) { + $data->compiled->file_dependency[$confObj->source->uid] = array($confObj->source->filepath, + $confObj->source->getTimeStamp(), + $confObj->source->type); + } + return $data; + } + + /** + * load config variables into template object + * + * @param \Smarty_Internal_Template $_template + * @param array $_config_vars + */ + static function _loadConfigVars(Smarty_Internal_Template $_template, $_config_vars) + { + $scope = $_template->source->scope; + // pointer to scope (local scope is parent of template object + $scope_ptr = $_template->parent; + if ($scope == 'parent') { + if (isset($_template->parent->parent)) { + $scope_ptr = $_template->parent->parent; + } + } elseif ($scope == 'root' || $scope == 'global') { + while (isset($scope_ptr->parent)) { + $scope_ptr = $scope_ptr->parent; + } + } + // copy global config vars + foreach ($_config_vars['vars'] as $variable => $value) { + if ($_template->smarty->config_overwrite || !isset($scope_ptr->config_vars[$variable])) { + $scope_ptr->config_vars[$variable] = $value; + } else { + $scope_ptr->config_vars[$variable] = array_merge((array) $scope_ptr->config_vars[$variable], (array) $value); + } + } + // scan sections + $sections = $_template->source->config_sections; + if (!empty($sections)) { + foreach ((array) $sections as $_template_section) { + if (isset($_config_vars['sections'][$_template_section])) { + foreach ($_config_vars['sections'][$_template_section]['vars'] as $variable => $value) { + if ($_template->smarty->config_overwrite || !isset($scope_ptr->config_vars[$variable])) { + $scope_ptr->config_vars[$variable] = $value; + } else { + $scope_ptr->config_vars[$variable] = array_merge((array) $scope_ptr->config_vars[$variable], (array) $value); + } + } + } + } + } + } +} diff --git a/libs/sysplugins/smarty_internal_method_createdata.php b/libs/sysplugins/smarty_internal_method_createdata.php new file mode 100644 index 00000000..600bc777 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_createdata.php @@ -0,0 +1,44 @@ +smarty) ? $this->smarty : $obj; + $dataObj = new Smarty_Data($parent, $smarty, $name); + if ($smarty->debugging) { + Smarty_Internal_Debug::register_data($dataObj); + } + return $dataObj; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_getautoloadfilters.php b/libs/sysplugins/smarty_internal_method_getautoloadfilters.php new file mode 100644 index 00000000..e1a7801f --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_getautoloadfilters.php @@ -0,0 +1,37 @@ + array( 'filter1', 'filter2', … ) ) or array( 'filter1', 'filter2', …) if $type + * was specified + */ + public function getAutoloadFilters(Smarty_Internal_TemplateBase $obj, $type = null) + { + $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + if ($type !== null) { + $this->_checkFilterType($type); + return isset($smarty->autoload_filters[$type]) ? $smarty->autoload_filters[$type] : array(); + } + return $smarty->autoload_filters; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_getconfigvars.php b/libs/sysplugins/smarty_internal_method_getconfigvars.php new file mode 100644 index 00000000..b1567216 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_getconfigvars.php @@ -0,0 +1,58 @@ +config_vars[$varname])) { + return $_ptr->config_vars[$varname]; + } + } else { + $var_array = array_merge($_ptr->config_vars, $var_array); + } + // not found, try at parent + if ($search_parents) { + $_ptr = $_ptr->parent; + } else { + $_ptr = null; + } + } + if (isset($varname)) { + return ''; + } else { + return $var_array; + } + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_getdebugtemplate.php b/libs/sysplugins/smarty_internal_method_getdebugtemplate.php new file mode 100644 index 00000000..3c3432ce --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_getdebugtemplate.php @@ -0,0 +1,35 @@ +smarty) ? $obj->smarty : $obj; + 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 new file mode 100644 index 00000000..32e0cc41 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_getdefaultmodifiers.php @@ -0,0 +1,35 @@ +smarty) ? $obj->smarty : $obj; + 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 new file mode 100644 index 00000000..be0c0dba --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_getregisteredobject.php @@ -0,0 +1,44 @@ +smarty) ? $obj->smarty : $obj; + if (!isset($smarty->registered_objects[$object_name])) { + throw new SmartyException("'$object_name' is not a registered object"); + } + if (!is_object($smarty->registered_objects[$object_name][0])) { + throw new SmartyException("registered '$object_name' is not an object"); + } + return $smarty->registered_objects[$object_name][0]; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_extension_getstreamvar.php b/libs/sysplugins/smarty_internal_method_getstreamvariable.php similarity index 53% rename from libs/sysplugins/smarty_internal_extension_getstreamvar.php rename to libs/sysplugins/smarty_internal_method_getstreamvariable.php index 5f09e908..b922fd08 100644 --- a/libs/sysplugins/smarty_internal_extension_getstreamvar.php +++ b/libs/sysplugins/smarty_internal_method_getstreamvariable.php @@ -1,26 +1,35 @@ smarty) ? $obj->smarty : $obj; + $smarty = isset($data->smarty) ? $data->smarty : $data; if ($smarty->error_unassigned) { throw new SmartyException('Undefined stream variable "' . $variable . '"'); } else { diff --git a/libs/sysplugins/smarty_internal_method_gettags.php b/libs/sysplugins/smarty_internal_method_gettags.php new file mode 100644 index 00000000..347983d2 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_gettags.php @@ -0,0 +1,61 @@ +smarty) ? $this->smarty : $obj; + if ($obj instanceof Smarty_Internal_Template && !isset($template)) { + $tpl = clone $obj; + } elseif (isset($template) && $template instanceof Smarty_Internal_Template) { + $tpl = clone $template; + } elseif (isset($template) && is_string($template)) { + /* @var Smarty_Internal_Template $tpl */ + $tpl = new $smarty->template_class($template, $smarty); + // checks if template exists + if (!$tpl->source->exists) { + throw new SmartyException("Unable to load template {$tpl->source->type} '{$tpl->source->name}'"); + } + } + if (isset($tpl)) { + $tpl->smarty = clone $tpl->smarty; + $tpl->smarty->get_used_tags = true; + $tpl->smarty->merge_compiled_includes = false; + $tpl->smarty->disableSecurity(); + $tpl->caching = false; + $tpl->loadCompiler(); + $tpl->compiler->compileTemplate($tpl); + return $tpl->used_tags; + } + throw new SmartyException("Missing template specification"); + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_gettemplatevars.php b/libs/sysplugins/smarty_internal_method_gettemplatevars.php new file mode 100644 index 00000000..9c963074 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_gettemplatevars.php @@ -0,0 +1,71 @@ +_getVariable($varname, $_ptr, $search_parents, false); + if (is_object($_var)) { + return $_var->value; + } else { + return null; + } + } else { + $_result = array(); + if ($_ptr === null) { + $_ptr = $data; + } + while ($_ptr !== null) { + foreach ($_ptr->tpl_vars AS $key => $var) { + if (!array_key_exists($key, $_result)) { + $_result[$key] = $var->value; + } + } + // not found, try at parent + if ($search_parents) { + $_ptr = $_ptr->parent; + } else { + $_ptr = null; + } + } + if ($search_parents && isset(Smarty::$global_tpl_vars)) { + foreach (Smarty::$global_tpl_vars AS $key => $var) { + if (!array_key_exists($key, $_result)) { + $_result[$key] = $var->value; + } + } + } + return $_result; + } + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_loadfilter.php b/libs/sysplugins/smarty_internal_method_loadfilter.php new file mode 100644 index 00000000..7fb11179 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_loadfilter.php @@ -0,0 +1,77 @@ + true, 'post' => true, 'output' => true, 'variable' => true); + + /** + * load a filter of specified type and name + * + * @api Smarty::loadFilter() + * + * @link http://www.smarty.net/docs/en/api.load.filter.tpl + * + * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj + * @param string $type filter type + * @param string $name filter name + * + * @return bool + * @throws SmartyException if filter could not be loaded + */ + public function loadFilter(Smarty_Internal_TemplateBase $obj, $type, $name) + { + $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $this->_checkFilterType($type); + $_plugin = "smarty_{$type}filter_{$name}"; + $_filter_name = $_plugin; + if (is_callable($_plugin)) { + $smarty->registered_filters[$type][$_filter_name] = $_plugin; + return true; + } + if ($smarty->loadPlugin($_plugin)) { + if (class_exists($_plugin, false)) { + $_plugin = array($_plugin, 'execute'); + } + if (is_callable($_plugin)) { + $smarty->registered_filters[$type][$_filter_name] = $_plugin; + return true; + } + } + throw new SmartyException("{$type}filter \"{$name}\" not found or callable"); + } + + /** + * Check if filter type is valid + * + * @param string $type + * + * @throws \SmartyException + */ + public function _checkFilterType($type) + { + if (!isset($this->filterTypes[$type])) { + throw new SmartyException("Illegal filter type \"{$type}\""); + } + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_mustcompile.php b/libs/sysplugins/smarty_internal_method_mustcompile.php new file mode 100644 index 00000000..c0922e4e --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_mustcompile.php @@ -0,0 +1,49 @@ +source->exists) { + if ($_template->parent instanceof Smarty_Internal_Template) { + $parent_resource = " in '$_template->parent->template_resource}'"; + } else { + $parent_resource = ''; + } + throw new SmartyException("Unable to load template {$_template->source->type} '{$_template->source->name}'{$parent_resource}"); + } + if ($_template->mustCompile === null) { + $_template->mustCompile = (!$_template->source->uncompiled && + ($_template->smarty->force_compile || $_template->source->recompiled || !$_template->compiled->exists || + ($_template->smarty->compile_check && $_template->compiled->getTimeStamp() < $_template->source->getTimeStamp()))); + } + + return $_template->mustCompile; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_registercacheresource.php b/libs/sysplugins/smarty_internal_method_registercacheresource.php new file mode 100644 index 00000000..55c5090a --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_registercacheresource.php @@ -0,0 +1,39 @@ +smarty) ? $obj->smarty : $obj; + $smarty->registered_cache_resources[$name] = $resource_handler; + return $obj; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_registerclass.php b/libs/sysplugins/smarty_internal_method_registerclass.php new file mode 100644 index 00000000..d2e5e20b --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_registerclass.php @@ -0,0 +1,46 @@ +smarty) ? $obj->smarty : $obj; + // test if exists + if (!class_exists($class_impl)) { + throw new SmartyException("Undefined class '$class_impl' in register template class"); + } + // register the class + $smarty->registered_classes[$class_name] = $class_impl; + return $obj; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_registerdefaultconfighandler.php b/libs/sysplugins/smarty_internal_method_registerdefaultconfighandler.php new file mode 100644 index 00000000..370aa38d --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_registerdefaultconfighandler.php @@ -0,0 +1,42 @@ +smarty) ? $obj->smarty : $obj; + if (is_callable($callback)) { + $smarty->default_config_handler_func = $callback; + } else { + throw new SmartyException("Default config handler not callable"); + } + return $obj; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_registerdefaultpluginhandler.php b/libs/sysplugins/smarty_internal_method_registerdefaultpluginhandler.php new file mode 100644 index 00000000..80b801ce --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_registerdefaultpluginhandler.php @@ -0,0 +1,43 @@ +smarty) ? $obj->smarty : $obj; + if (is_callable($callback)) { + $smarty->default_plugin_handler_func = $callback; + } else { + throw new SmartyException("Default plugin handler '$callback' not callable"); + } + return $obj; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_registerdefaulttemplatehandler.php b/libs/sysplugins/smarty_internal_method_registerdefaulttemplatehandler.php new file mode 100644 index 00000000..cbb6b1f7 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_registerdefaulttemplatehandler.php @@ -0,0 +1,72 @@ +smarty) ? $obj->smarty : $obj; + if (is_callable($callback)) { + $smarty->default_template_handler_func = $callback; + } else { + throw new SmartyException("Default template handler not callable"); + } + return $obj; + } + + /** + * get default content from template or config resource handler + * + * @param Smarty_Template_Source $source + */ + public static function _getDefaultTemplate(Smarty_Template_Source $source) + { + if ($source->isConfig) { + $default_handler = $source->smarty->default_config_handler_func; + } else { + $default_handler = $source->smarty->default_template_handler_func; + } + $_content = $_timestamp = null; + $_return = call_user_func_array($default_handler, array($source->type, $source->name, &$_content, &$_timestamp, + $source->smarty)); + if (is_string($_return)) { + $source->exists = is_file($_return); + if ($source->exists) { + $source->timestamp = filemtime($_return); + } + $source->filepath = $_return; + } elseif ($_return === true) { + $source->content = $_content; + $source->timestamp = $_timestamp; + $source->exists = true; + $source->recompiled = true; + $source->filepath = false; + } + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_registerfilter.php b/libs/sysplugins/smarty_internal_method_registerfilter.php new file mode 100644 index 00000000..84b2c263 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_registerfilter.php @@ -0,0 +1,88 @@ + true, 'post' => true, 'output' => true, 'variable' => true); + + /** + * Registers a filter function + * + * @api Smarty::registerFilter() + * + * @link http://www.smarty.net/docs/en/api.register.filter.tpl + * + * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj + * @param string $type filter type + * @param callback $callback + * @param string|null $name optional filter name + * + * @return \Smarty|\Smarty_Internal_Template + * @throws \SmartyException + */ + public function registerFilter(Smarty_Internal_TemplateBase $obj, $type, $callback, $name = null) + { + $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + $this->_checkFilterType($type); + $name = isset($name) ? $name : $this->_getFilterName($callback); + if (!is_callable($callback)) { + throw new SmartyException("{$type}filter \"{$name}\" not callable"); + } + $smarty->registered_filters[$type][$name] = $callback; + return $obj; + } + + /** + * Return internal filter name + * + * @param callback $function_name + * + * @return string internal filter name + */ + public function _getFilterName($function_name) + { + if (is_array($function_name)) { + $_class_name = (is_object($function_name[0]) ? get_class($function_name[0]) : $function_name[0]); + + return $_class_name . '_' . $function_name[1]; + } elseif (is_string($function_name)) { + return $function_name; + } else { + return 'closure'; + } + } + + /** + * Check if filter type is valid + * + * @param string $type + * + * @throws \SmartyException + */ + public function _checkFilterType($type) + { + if (!isset($this->filterTypes[$type])) { + throw new SmartyException("Illegal filter type \"{$type}\""); + } + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_registerobject.php b/libs/sysplugins/smarty_internal_method_registerobject.php new file mode 100644 index 00000000..f27f1720 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_registerobject.php @@ -0,0 +1,71 @@ +smarty) ? $obj->smarty : $obj; + // test if allowed methods callable + if (!empty($allowed_methods_properties)) { + foreach ((array) $allowed_methods_properties as $method) { + if (!is_callable(array($object, $method)) && !property_exists($object, $method)) { + throw new SmartyException("Undefined method or property '$method' in registered object"); + } + } + } + // test if block methods callable + if (!empty($block_methods)) { + foreach ((array) $block_methods as $method) { + if (!is_callable(array($object, $method))) { + throw new SmartyException("Undefined method '$method' in registered object"); + } + } + } + // register the object + $smarty->registered_objects[$object_name] = array($object, (array) $allowed_methods_properties, + (boolean) $format, (array) $block_methods); + return $obj; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_registerplugin.php b/libs/sysplugins/smarty_internal_method_registerplugin.php new file mode 100644 index 00000000..95814581 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_registerplugin.php @@ -0,0 +1,50 @@ +smarty) ? $obj->smarty : $obj; + if (isset($smarty->registered_plugins[$type][$name])) { + throw new SmartyException("Plugin tag \"{$name}\" already registered"); + } elseif (!is_callable($callback)) { + throw new SmartyException("Plugin \"{$name}\" not callable"); + } else { + $smarty->registered_plugins[$type][$name] = array($callback, (bool) $cacheable, (array) $cache_attr); + } + return $obj; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_registerresource.php b/libs/sysplugins/smarty_internal_method_registerresource.php new file mode 100644 index 00000000..43246ee9 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_registerresource.php @@ -0,0 +1,44 @@ +smarty) ? $obj->smarty : $obj; + $smarty->registered_resources[$name] = $resource_handler instanceof + Smarty_Resource ? $resource_handler : array($resource_handler, false); + return $obj; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_setautoloadfilters.php b/libs/sysplugins/smarty_internal_method_setautoloadfilters.php new file mode 100644 index 00000000..b1f965cd --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_setautoloadfilters.php @@ -0,0 +1,70 @@ + true, 'post' => true, 'output' => true, 'variable' => true); + + /** + * Set autoload filters + * + * @api Smarty::setAutoloadFilters() + * + * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj + * @param array $filters filters to load automatically + * @param string $type "pre", "output", … specify the + * filter type to set. Defaults to + * none treating $filters' keys as + * the appropriate types + * + * @return \Smarty|\Smarty_Internal_Template + */ + public function setAutoloadFilters(Smarty_Internal_TemplateBase $obj, $filters, $type = null) + { + $smarty = isset($obj->smarty) ? $obj->smarty : $obj; + if ($type !== null) { + $this->_checkFilterType($type); + $smarty->autoload_filters[$type] = (array) $filters; + } else { + foreach ((array) $filters as $type => $value) { + $this->_checkFilterType($type); + } + $smarty->autoload_filters = (array) $filters; + } + return $obj; + } + + /** + * Check if filter type is valid + * + * @param string $type + * + * @throws \SmartyException + */ + public function _checkFilterType($type) + { + if (!isset($this->filterTypes[$type])) { + throw new SmartyException("Illegal filter type \"{$type}\""); + } + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_setdebugtemplate.php b/libs/sysplugins/smarty_internal_method_setdebugtemplate.php new file mode 100644 index 00000000..4ff5d7f8 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_setdebugtemplate.php @@ -0,0 +1,41 @@ +smarty) ? $obj->smarty : $obj; + if (!is_readable($tpl_name)) { + throw new SmartyException("Unknown file '{$tpl_name}'"); + } + $smarty->debug_tpl = $tpl_name; + return $obj; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_setdefaultmodifiers.php b/libs/sysplugins/smarty_internal_method_setdefaultmodifiers.php new file mode 100644 index 00000000..5a707287 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_setdefaultmodifiers.php @@ -0,0 +1,38 @@ +smarty) ? $obj->smarty : $obj; + $smarty->default_modifiers = (array) $modifiers; + return $obj; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_unloadfilter.php b/libs/sysplugins/smarty_internal_method_unloadfilter.php new file mode 100644 index 00000000..e3d966e1 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_unloadfilter.php @@ -0,0 +1,42 @@ +smarty) ? $obj->smarty : $obj; + $this->_checkFilterType($type); + if (isset($smarty->registered_filters[$type])) { + $_filter_name = "smarty_{$type}filter_{$name}"; + if (isset($smarty->registered_filters[$type][$_filter_name])) { + unset ($smarty->registered_filters[$type][$_filter_name]); + if (empty($smarty->registered_filters[$type])) { + unset($smarty->registered_filters[$type]); + } + } + } + return $obj; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_unregistercacheresource.php b/libs/sysplugins/smarty_internal_method_unregistercacheresource.php new file mode 100644 index 00000000..80381015 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_unregistercacheresource.php @@ -0,0 +1,40 @@ +smarty) ? $obj->smarty : $obj; + if (isset($smarty->registered_cache_resources[$name])) { + unset($smarty->registered_cache_resources[$name]); + } + return $obj; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_unregisterfilter.php b/libs/sysplugins/smarty_internal_method_unregisterfilter.php new file mode 100644 index 00000000..c80ae9a6 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_unregisterfilter.php @@ -0,0 +1,42 @@ +smarty) ? $obj->smarty : $obj; + $this->_checkFilterType($type); + if (isset($smarty->registered_filters[$type])) { + $name = is_string($callback) ? $callback : $this->_getFilterName($callback); + if (isset($smarty->registered_filters[$type][$name])) { + unset($smarty->registered_filters[$type][$name]); + if (empty($smarty->registered_filters[$type])) { + unset($smarty->registered_filters[$type]); + } + } + } + return $obj; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_unregisterobject.php b/libs/sysplugins/smarty_internal_method_unregisterobject.php new file mode 100644 index 00000000..a9433168 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_unregisterobject.php @@ -0,0 +1,40 @@ +smarty) ? $obj->smarty : $obj; + if (isset($smarty->registered_objects[$object_name])) { + unset($smarty->registered_objects[$object_name]); + } + return $obj; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_unregisterplugin.php b/libs/sysplugins/smarty_internal_method_unregisterplugin.php new file mode 100644 index 00000000..06cb2d35 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_unregisterplugin.php @@ -0,0 +1,41 @@ +smarty) ? $obj->smarty : $obj; + if (isset($smarty->registered_plugins[$type][$name])) { + unset($smarty->registered_plugins[$type][$name]); + } + return $obj; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_unregisterresource.php b/libs/sysplugins/smarty_internal_method_unregisterresource.php new file mode 100644 index 00000000..767bd74a --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_unregisterresource.php @@ -0,0 +1,40 @@ +smarty) ? $obj->smarty : $obj; + if (isset($smarty->registered_resources[$type])) { + unset($smarty->registered_resources[$type]); + } + return $obj; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index 1c3250a8..fd1ffd40 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -17,9 +17,17 @@ * @property Smarty_Template_Source|Smarty_Template_Config $source * @property Smarty_Template_Compiled $compiled * @property Smarty_Template_Cached $cached + * @method bool mustCompile() */ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase { + /** + * This object type (Smarty = 1, template = 2, data = 4) + * + * @var int + */ + public $_objType = 2; + /** * Global smarty instance * @@ -399,33 +407,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase } } - /** - * Returns if the current template must be compiled by the Smarty compiler - * It does compare the timestamps of template source and the compiled templates and checks the force compile - * configuration - * - * @throws SmartyException - * @return boolean true if the template must be compiled - */ - public function mustCompile() - { - if (!$this->source->exists) { - if ($this->parent instanceof Smarty_Internal_Template) { - $parent_resource = " in '$this->parent->template_resource}'"; - } else { - $parent_resource = ''; - } - throw new SmartyException("Unable to load template {$this->source->type} '{$this->source->name}'{$parent_resource}"); - } - if ($this->mustCompile === null) { - $this->mustCompile = (!$this->source->uncompiled && - ($this->smarty->force_compile || $this->source->recompiled || !$this->compiled->exists || - ($this->smarty->compile_check && $this->compiled->getTimeStamp() < $this->source->getTimeStamp()))); - } - - return $this->mustCompile; - } - /** * Compiles the template * If the template is not evaluated the compiled template is saved on disk @@ -806,20 +787,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase throw new SmartyException("Not matching {capture} open/close in \"{$this->template_resource}\""); } - /** - * Empty cache for this template - * - * @param integer $exp_time expiration time - * - * @return integer number of cache files deleted - */ - public function clearCache($exp_time = null) - { - Smarty_CacheResource::invalidLoadedCache($this->smarty); - - return $this->cached->handler->clear($this->smarty, $this->template_resource, $this->cache_id, $this->compile_id, $exp_time); - } - /** * Load compiled object * diff --git a/libs/sysplugins/smarty_internal_templatebase.php b/libs/sysplugins/smarty_internal_templatebase.php index 6c2f5ad5..9752b3ed 100644 --- a/libs/sysplugins/smarty_internal_templatebase.php +++ b/libs/sysplugins/smarty_internal_templatebase.php @@ -11,8 +11,36 @@ /** * Class with shared template methods * - * @package Smarty - * @subpackage Template + * @package Smarty + * @subpackage Template + * + * @method Smarty_Internal_TemplateBase setAutoloadFilters(mixed $filters, string $type = null) + * @method Smarty_Internal_TemplateBase addAutoloadFilters(mixed $filters, string $type = null) + * @method array getAutoloadFilters(string $type = null) + * @local_method Smarty_Internal_TemplateBase registerFilter(string $type, callback $callback, string $name = null) + * @method Smarty_Internal_TemplateBase unregisterFilter(string $type, mixed $callback) + * @local_method bool loadFilter(string $type, string $name) + * @method Smarty_Internal_TemplateBase unloadFilter(string $type, string $name) + * @method string getDebugTemplate() + * @method Smarty_Internal_TemplateBase setDebugTemplate(string $tpl_name) + * @method Smarty_Internal_TemplateBase setDefaultModifier(mixed $modifiers) + * @method Smarty_Internal_TemplateBase addDefaultModifier(mixed $modifiers) + * @method array getDefaultModifier() + * @method Smarty_Internal_TemplateBase registerDefaultPluginHandler(callback $callback) + * @method Smarty_Internal_TemplateBase registerResource(string $name, Smarty_Resource $resource_handler) + * @method Smarty_Internal_TemplateBase unregisterResource(string $name) + * @method Smarty_Internal_TemplateBase registerCacheResource(string $name, Smarty_CacheResource $resource_handler) + * @method Smarty_Internal_TemplateBase unregisterCacheResource(string $name) + * @local_method Smarty_Internal_TemplateBase registerPlugin(string $type, string $name, callback $callback, bool + * $cacheable = true, mixed $cache_attr = null) + * @method Smarty_Internal_TemplateBase unregisterPlugin(string $type, string $name) + * @local_method Smarty_Internal_TemplateBase registerObject(string $object_name, object $object, array + * $allowed_methods_properties = array(), bool $format = true, array $block_methods = array()) + * @method Smarty_Internal_TemplateBase unregisterObject(string $object_name) + * @method object getRegisteredObject(string $object_name) + * @method Smarty_Internal_TemplateBase registerClass(string $class_name, string $class_impl) + * @method Smarty_Internal_TemplateBase createData(Smarty_Internal_Data $parent = null, string $name = null) + * @method array getTags(mixed $template = null) */ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data { @@ -46,9 +74,171 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data */ public $cache_lifetime = 3600; + /** + * Registers plugin to be used in templates + * NOTE: this method can be safely removed for dynamic loading + * + * @api Smarty::registerPlugin() + * @link http://www.smarty.net/docs/en/api.register.plugin.tpl + * + * @param string $type plugin type + * @param string $name name of template tag + * @param callback $callback PHP callback to register + * @param bool $cacheable if true (default) this function is cache able + * @param mixed $cache_attr caching attributes if any + * + * @return \Smarty|\Smarty_Internal_Template + * @throws SmartyException when the plugin tag is invalid + */ + public function registerPlugin($type, $name, $callback, $cacheable = true, $cache_attr = null) + { + /* @var Smarty $smarty */ + $smarty = isset($this->smarty) ? $this->smarty : $this; + if (isset($smarty->registered_plugins[$type][$name])) { + throw new SmartyException("Plugin tag \"{$name}\" already registered"); + } elseif (!is_callable($callback)) { + throw new SmartyException("Plugin \"{$name}\" not callable"); + } else { + $smarty->registered_plugins[$type][$name] = array($callback, (bool) $cacheable, (array) $cache_attr); + } + return $this; + } + + /** + * load a filter of specified type and name + * NOTE: this method can be safely removed for dynamic loading + * + * @api Smarty::loadFilter() + * @link http://www.smarty.net/docs/en/api.load.filter.tpl + * + * @param string $type filter type + * @param string $name filter name + * + * @return bool + * @throws SmartyException if filter could not be loaded + */ + public function loadFilter($type, $name) + { + /* @var Smarty $smarty */ + $smarty = isset($this->smarty) ? $this->smarty : $this; + if (!in_array($type, array('pre', 'post', 'output', 'variable'))) { + throw new SmartyException("Illegal filter type \"{$type}\""); + } + $_plugin = "smarty_{$type}filter_{$name}"; + $_filter_name = $_plugin; + if (is_callable($_plugin)) { + $smarty->registered_filters[$type][$_filter_name] = $_plugin; + return true; + } + if ($smarty->loadPlugin($_plugin)) { + if (class_exists($_plugin, false)) { + $_plugin = array($_plugin, 'execute'); + } + if (is_callable($_plugin)) { + $smarty->registered_filters[$type][$_filter_name] = $_plugin; + return true; + } + } + throw new SmartyException("{$type}filter \"{$name}\" not found or callable"); + } + + /** + * Registers a filter function + * NOTE: this method can be safely removed for dynamic loading + * + * @api Smarty::registerFilter() + * @link http://www.smarty.net/docs/en/api.register.filter.tpl + * + * @param string $type filter type + * @param callback $callback + * @param string|null $name optional filter name + * + * @return \Smarty|\Smarty_Internal_Template + * @throws \SmartyException + */ + public function registerFilter($type, $callback, $name = null) + { + /* @var Smarty $smarty */ + $smarty = isset($this->smarty) ? $this->smarty : $this; + if (!in_array($type, array('pre', 'post', 'output', 'variable'))) { + throw new SmartyException("Illegal filter type \"{$type}\""); + } + $name = isset($name) ? $name : $this->_getFilterName($callback); + if (!is_callable($callback)) { + throw new SmartyException("{$type}filter \"{$name}\" not callable"); + } + $smarty->registered_filters[$type][$name] = $callback; + return $this; + } + + /** + * Return internal filter name + * + * @param callback $function_name + * + * @return string internal filter name + */ + public function _getFilterName($function_name) + { + if (is_array($function_name)) { + $_class_name = (is_object($function_name[0]) ? get_class($function_name[0]) : $function_name[0]); + + return $_class_name . '_' . $function_name[1]; + } elseif (is_string($function_name)) { + return $function_name; + } else { + return 'closure'; + } + } + + /** + * Registers object to be used in templates + * NOTE: this method can be safely removed for dynamic loading + * + * @api Smarty::registerObject() + * @link http://www.smarty.net/docs/en/api.register.object.tpl + * + * @param string $object_name + * @param object $object the referenced PHP object to register + * @param array $allowed_methods_properties list of allowed methods (empty = all) + * @param bool $format smarty argument format, else traditional + * @param array $block_methods list of block-methods + * + * @return \Smarty|\Smarty_Internal_Template + * @throws \SmartyException + */ + public function registerObject($object_name, $object, $allowed_methods_properties = array(), $format = true, $block_methods = array()) + { + /* @var Smarty $smarty */ + $smarty = isset($this->smarty) ? $this->smarty : $this; + // test if allowed methods callable + if (!empty($allowed_methods_properties)) { + foreach ((array) $allowed_methods_properties as $method) { + if (!is_callable(array($object, $method)) && !property_exists($object, $method)) { + throw new SmartyException("Undefined method or property '$method' in registered object"); + } + } + } + // test if block methods callable + if (!empty($block_methods)) { + foreach ((array) $block_methods as $method) { + if (!is_callable(array($object, $method))) { + throw new SmartyException("Undefined method '$method' in registered object"); + } + } + } + // register the object + $smarty->registered_objects[$object_name] = array($object, (array) $allowed_methods_properties, + (boolean) $format, (array) $block_methods); + return $this; + } + /** * test if cache is valid * + * @api Smarty::isCached() + * @link http://www.smarty.net/docs/en/api.is.cached.tpl + * * @param string|\Smarty_Internal_Template $template the resource handle of the template file or template object * @param mixed $cache_id cache id to be used with this template * @param mixed $compile_id compile id to be used with this template @@ -65,6 +255,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data if ($parent === null) { $parent = $this; } + /* @var Smarty $smarty */ $smarty = isset($this->smarty) ? $this->smarty : $this; $template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent, false); } @@ -77,408 +268,36 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data } /** - * creates a data object - * - * @param object $parent next higher level of Smarty variables - * @param string $name optional data block name - * - * @returns Smarty_Data data object + * @param boolean $caching */ - public function createData($parent = null, $name = null) + public function setCaching($caching) { - $dataObj = new Smarty_Data($parent, $this, $name); - if ($this->debugging) { - Smarty_Internal_Debug::register_data($dataObj); - } - return $dataObj; + $this->caching = $caching; } /** - * Get unique template id - * - * @param string $template_name - * @param null|mixed $cache_id - * @param null|mixed $compile_id - * - * @return string + * @param int $cache_lifetime */ - public function getTemplateId($template_name, $cache_id = null, $compile_id = null) + public function setCacheLifetime($cache_lifetime) { - $cache_id = isset($cache_id) ? $cache_id : $this->cache_id; - $compile_id = isset($compile_id) ? $compile_id : $this->compile_id; - $smarty = isset($this->smarty) ? $this->smarty : $this; - if ($smarty->allow_ambiguous_resources) { - $_templateId = Smarty_Resource::getUniqueTemplateName($this, $template_name) . "#{$cache_id}#{$compile_id}"; - } else { - $_templateId = $smarty->joined_template_dir . "#{$template_name}#{$cache_id}#{$compile_id}"; - } - if (isset($_templateId[150])) { - $_templateId = sha1($_templateId); - } - return $_templateId; + $this->cache_lifetime = $cache_lifetime; } /** - * Registers plugin to be used in templates - * - * @param string $type plugin type - * @param string $tag name of template tag - * @param callback $callback PHP callback to register - * @param boolean $cacheable if true (default) this function is cache able - * @param array $cache_attr caching attributes if any - * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or - * Smarty_Internal_Template) instance for chaining - * @throws SmartyException when the plugin tag is invalid + * @param string $compile_id */ - public function registerPlugin($type, $tag, $callback, $cacheable = true, $cache_attr = null) + public function setCompileId($compile_id) { - $smarty = isset($this->smarty) ? $this->smarty : $this; - if (isset($smarty->registered_plugins[$type][$tag])) { - throw new SmartyException("Plugin tag \"{$tag}\" already registered"); - } elseif (!is_callable($callback)) { - throw new SmartyException("Plugin \"{$tag}\" not callable"); - } else { - $smarty->registered_plugins[$type][$tag] = array($callback, (bool) $cacheable, (array) $cache_attr); - } - - return $this; + $this->compile_id = $compile_id; } /** - * Unregister Plugin - * - * @param string $type of plugin - * @param string $tag name of plugin - * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or - * Smarty_Internal_Template) instance for chaining + * @param string $cache_id */ - public function unregisterPlugin($type, $tag) + public function setCacheId($cache_id) { - $smarty = isset($this->smarty) ? $this->smarty : $this; - if (isset($smarty->registered_plugins[$type][$tag])) { - unset($smarty->registered_plugins[$type][$tag]); - } - - return $this; + $this->cache_id = $cache_id; } - /** - * Registers a resource to fetch a template - * - * @param string $type name of resource type - * @param Smarty_Resource|array $callback or instance of Smarty_Resource, or array of callbacks to handle resource - * (deprecated) - * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or - * Smarty_Internal_Template) instance for chaining - */ - public function registerResource($type, $callback) - { - $smarty = isset($this->smarty) ? $this->smarty : $this; - $smarty->registered_resources[$type] = $callback instanceof Smarty_Resource ? $callback : array($callback, - false); - - return $this; - } - - /** - * Unregisters a resource - * - * @param string $type name of resource type - * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or - * Smarty_Internal_Template) instance for chaining - */ - public function unregisterResource($type) - { - $smarty = isset($this->smarty) ? $this->smarty : $this; - if (isset($smarty->registered_resources[$type])) { - unset($smarty->registered_resources[$type]); - } - - return $this; - } - - /** - * Registers a cache resource to cache a template's output - * - * @param string $type name of cache resource type - * @param Smarty_CacheResource $callback instance of Smarty_CacheResource to handle output caching - * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or - * Smarty_Internal_Template) instance for chaining - */ - public function registerCacheResource($type, Smarty_CacheResource $callback) - { - $smarty = isset($this->smarty) ? $this->smarty : $this; - $smarty->registered_cache_resources[$type] = $callback; - - return $this; - } - - /** - * Unregisters a cache resource - * - * @param string $type name of cache resource type - * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or - * Smarty_Internal_Template) instance for chaining - */ - public function unregisterCacheResource($type) - { - $smarty = isset($this->smarty) ? $this->smarty : $this; - if (isset($smarty->registered_cache_resources[$type])) { - unset($smarty->registered_cache_resources[$type]); - } - - return $this; - } - - /** - * Registers object to be used in templates - * - * @param $object_name - * @param object $object_impl the referenced PHP object to register - * @param array $allowed list of allowed methods (empty = all) - * @param boolean $smarty_args smarty argument format, else traditional - * @param array $block_methods list of block-methods - * - * @throws SmartyException - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or - * Smarty_Internal_Template) instance for chaining - */ - public function registerObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) - { - Smarty_Internal_Extension_Object::registerObject($this, $object_name, $object_impl, $allowed, $smarty_args, $block_methods); - return $this; - } - - /** - * return a reference to a registered object - * - * @param string $name object name - * - * @return object - * @throws SmartyException if no such object is found - */ - public function getRegisteredObject($name) - { - return Smarty_Internal_Extension_Object::getRegisteredObject($this, $name); - } - - /** - * unregister an object - * - * @param string $name object name - * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or - * Smarty_Internal_Template) instance for chaining - */ - public function unregisterObject($name) - { - Smarty_Internal_Extension_Object::unregisterObject($this, $name); - return $this; - } - - /** - * Registers static classes to be used in templates - * - * @param $class_name - * @param string $class_impl the referenced PHP class to register - * - * @throws SmartyException - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or - * Smarty_Internal_Template) instance for chaining - */ - public function registerClass($class_name, $class_impl) - { - Smarty_Internal_Extension_Object::registerClass($this, $class_name, $class_impl); - return $this; - } - - /** - * Registers a default plugin handler - * - * @param callable $callback class/method name - * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or - * Smarty_Internal_Template) instance for chaining - * @throws SmartyException if $callback is not callable - */ - public function registerDefaultPluginHandler($callback) - { - $smarty = isset($this->smarty) ? $this->smarty : $this; - if (is_callable($callback)) { - $smarty->default_plugin_handler_func = $callback; - } else { - throw new SmartyException("Default plugin handler '$callback' not callable"); - } - - return $this; - } - - /** - * Registers a default template handler - * - * @param callable $callback class/method name - * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or - * Smarty_Internal_Template) instance for chaining - * @throws SmartyException if $callback is not callable - */ - public function registerDefaultTemplateHandler($callback) - { - Smarty_Internal_Extension_DefaultTemplateHandler::registerDefaultTemplateHandler($this, $callback); - return $this; - } - - /** - * Registers a default template handler - * - * @param callable $callback class/method name - * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or - * Smarty_Internal_Template) instance for chaining - * @throws SmartyException if $callback is not callable - */ - public function registerDefaultConfigHandler($callback) - { - Smarty_Internal_Extension_DefaultTemplateHandler::registerDefaultConfigHandler($this, $callback); - return $this; - } - - /** - * Registers a filter function - * - * @param string $type filter type - * @param callback $callback - * @param null|string $name option filter name - * - * @return \Smarty_Internal_TemplateBase current Smarty_Internal_Templatebase (or Smarty or - * Smarty_Internal_Template) instance for chaining - * @throws \SmartyException - */ - public function registerFilter($type, $callback, $name = null) - { - Smarty_Internal_Extension_Filter::registerFilter($this, $type, $callback, $name); - return $this; - } - - /** - * Unregisters a filter function - * - * @param string $type filter type - * @param callback|string $callback - * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or - * Smarty_Internal_Template) instance for chaining - */ - public function unregisterFilter($type, $callback) - { - Smarty_Internal_Extension_Filter::unregisterFilter($this, $type, $callback); - return $this; - } - - /** - * load a filter of specified type and name - * - * @param string $type filter type - * @param string $name filter name - * - * @return bool - * @throws SmartyException if filter could not be loaded - */ - public function loadFilter($type, $name) - { - return Smarty_Internal_Extension_Filter::loadFilter($this, $type, $name); - } - - /** - * unload a filter of specified type and name - * - * @param string $type filter type - * @param string $name filter name - * - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or - * Smarty_Internal_Template) instance for chaining - */ - public function unloadFilter($type, $name) - { - Smarty_Internal_Extension_Filter::unloadFilter($this, $type, $name); - return $this; - } - - /** - * preg_replace callback to convert camelcase getter/setter to underscore property names - * - * @param string $match match string - * - * @return string replacement - */ - private function replaceCamelcase($match) - { - return "_" . strtolower($match[1]); - } - - /** - * Handle unknown class methods - * - * @param string $name unknown method-name - * @param array $args argument array - * - * @throws SmartyException - */ - public function __call($name, $args) - { - static $_prefixes = array('set' => true, 'get' => true); - static $_resolved_property_name = array(); - static $_resolved_property_source = array(); - - // see if this is a set/get for a property - $first3 = strtolower(substr($name, 0, 3)); - if (isset($_prefixes[$first3]) && isset($name[3]) && $name[3] !== '_') { - if (isset($_resolved_property_name[$name])) { - $property_name = $_resolved_property_name[$name]; - } else { - // try to keep case correct for future PHP 6.0 case-sensitive class methods - // lcfirst() not available < PHP 5.3.0, so improvise - $property_name = strtolower(substr($name, 3, 1)) . substr($name, 4); - // convert camel case to underscored name - $property_name = preg_replace_callback('/([A-Z])/', array($this, 'replaceCamelcase'), $property_name); - $_resolved_property_name[$name] = $property_name; - } - if (isset($_resolved_property_source[$property_name])) { - $status = $_resolved_property_source[$property_name]; - } else { - $status = null; - if (property_exists($this, $property_name)) { - $status = true; - } elseif (property_exists($this->smarty, $property_name)) { - $status = false; - } elseif (in_array($name, $this->smarty->obsoleteProperties)) { - return null; - } else { - } - $_resolved_property_source[$property_name] = $status; - } - $smarty = null; - if ($status === true) { - $smarty = $this; - } elseif ($status === false) { - $smarty = $this->smarty; - } - if ($smarty) { - if ($first3 == 'get') { - return $smarty->$property_name; - } else { - return $smarty->$property_name = $args[0]; - } - } - throw new SmartyException("property '$property_name' does not exist."); - } - throw new SmartyException("Call of unknown method '$name'."); - } } diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index 1569b4ba..e32ca6a3 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -785,7 +785,7 @@ abstract class Smarty_Internal_TemplateCompilerBase if (strpos($variable, '(') == 0) { // not a variable variable $var = trim($variable, '\''); - $this->tag_nocache = $this->tag_nocache | $this->template->getVariable($var, null, true, false)->nocache; + $this->tag_nocache = $this->tag_nocache | $this->template->_getVariable($var, null, true, false)->nocache; // todo $this->template->compiled->properties['variables'][$var] = $this->tag_nocache | $this->nocache; } return '$_smarty_tpl->tpl_vars[' . $variable . ']->value'; diff --git a/libs/sysplugins/smarty_internal_templateparser.php b/libs/sysplugins/smarty_internal_templateparser.php index 88b03401..c4de7801 100644 --- a/libs/sysplugins/smarty_internal_templateparser.php +++ b/libs/sysplugins/smarty_internal_templateparser.php @@ -2093,13 +2093,13 @@ class Smarty_Internal_Templateparser #line 879 "../smarty/lexer/smarty_internal_templateparser.y" function yy_r116() { - $this->_retvalue = '$_smarty_tpl->getConfigVariable( \'' . $this->yystack[$this->yyidx + - 1]->minor . '\')'; + $this->_retvalue = '$_smarty_tpl->_getConfigVariable( \'' . $this->yystack[$this->yyidx + - 1]->minor . '\')'; } #line 883 "../smarty/lexer/smarty_internal_templateparser.y" function yy_r117() { - $this->_retvalue = '(is_array($tmp = $_smarty_tpl->getConfigVariable( \'' . + $this->_retvalue = '(is_array($tmp = $_smarty_tpl->_getConfigVariable( \'' . $this->yystack[$this->yyidx + - 2]->minor . '\')) ? $tmp' . $this->yystack[$this->yyidx + 0]->minor . ' :null)'; } @@ -2107,13 +2107,13 @@ class Smarty_Internal_Templateparser #line 887 "../smarty/lexer/smarty_internal_templateparser.y" function yy_r118() { - $this->_retvalue = '$_smarty_tpl->getConfigVariable( ' . $this->yystack[$this->yyidx + - 1]->minor . ')'; + $this->_retvalue = '$_smarty_tpl->_getConfigVariable( ' . $this->yystack[$this->yyidx + - 1]->minor . ')'; } #line 891 "../smarty/lexer/smarty_internal_templateparser.y" function yy_r119() { - $this->_retvalue = '(is_array($tmp = $_smarty_tpl->getConfigVariable( ' . + $this->_retvalue = '(is_array($tmp = $_smarty_tpl->_getConfigVariable( ' . $this->yystack[$this->yyidx + - 2]->minor . ')) ? $tmp' . $this->yystack[$this->yyidx + 0]->minor . ' : null)'; } @@ -2332,7 +2332,7 @@ class Smarty_Internal_Templateparser $this->compiler->trigger_template_error('Illegal number of paramer in "isset()"'); } $par = implode(',', $this->yystack[$this->yyidx + - 1]->minor); - if (strncasecmp($par, '$_smarty_tpl->getConfigVariable', strlen('$_smarty_tpl->getConfigVariable')) === + if (strncasecmp($par, '$_smarty_tpl->_getConfigVariable', strlen('$_smarty_tpl->_getConfigVariable')) === 0 ) { self::$prefix_number ++; diff --git a/libs/sysplugins/smarty_internal_testinstall.php b/libs/sysplugins/smarty_internal_testinstall.php index 1ba31638..a89f62c6 100644 --- a/libs/sysplugins/smarty_internal_testinstall.php +++ b/libs/sysplugins/smarty_internal_testinstall.php @@ -19,7 +19,6 @@ class Smarty_Internal_TestInstall * diagnose Smarty setup * If $errors is secified, the diagnostic report will be appended to the array, rather than being output. * - * @param Smarty $smarty Smarty instance to test * @param array $errors array to push results into rather than outputting them * * @return bool status, true if everything is fine, false else @@ -47,7 +46,7 @@ class Smarty_Internal_TestInstall if ($_stream_resolve_include_path) { $template_dir = stream_resolve_include_path($_template_dir); } else { - $template_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_template_dir); + $template_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_template_dir, null, $smarty); } if ($template_dir !== false) { @@ -166,7 +165,7 @@ class Smarty_Internal_TestInstall if ($_stream_resolve_include_path) { $plugin_dir = stream_resolve_include_path($_plugin_dir); } else { - $plugin_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_plugin_dir); + $plugin_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_plugin_dir, null, $smarty); } if ($plugin_dir !== false) { @@ -288,7 +287,6 @@ class Smarty_Internal_TestInstall // test if all registered config_dir are accessible foreach ($smarty->getConfigDir() as $config_dir) { $_config_dir = $config_dir; - $config_dir = realpath($config_dir); // resolve include_path or fail existence if (!$config_dir) { if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_config_dir)) { @@ -296,7 +294,7 @@ class Smarty_Internal_TestInstall if ($_stream_resolve_include_path) { $config_dir = stream_resolve_include_path($_config_dir); } else { - $config_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_config_dir); + $config_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_config_dir, null, $smarty); } if ($config_dir !== false) { @@ -404,8 +402,6 @@ class Smarty_Internal_TestInstall "smarty_internal_data.php" => true, "smarty_internal_debug.php" => true, "smarty_internal_extension_codeframe.php" => true, - "smarty_internal_extension_config.php" => true, - "smarty_internal_extension_defaulttemplatehandler.php" => true, "smarty_internal_filter_handler.php" => true, "smarty_internal_function_call_handler.php" => true, "smarty_internal_get_include_path.php" => true, @@ -430,7 +426,6 @@ class Smarty_Internal_TestInstall "smarty_internal_templatecompilerbase.php" => true, "smarty_internal_templatelexer.php" => true, "smarty_internal_templateparser.php" => true, - "smarty_internal_utility.php" => true, "smarty_internal_write_file.php" => true, "smarty_resource.php" => true, "smarty_resource_custom.php" => true, diff --git a/libs/sysplugins/smarty_internal_utility.php b/libs/sysplugins/smarty_internal_utility.php deleted file mode 100644 index 1ddd0f37..00000000 --- a/libs/sysplugins/smarty_internal_utility.php +++ /dev/null @@ -1,62 +0,0 @@ - - * @author Uwe Tews - * @package Smarty - * @subpackage PluginsInternal - * @version 3-SVN$Rev: 3286 $ - */ - -/** - * Utility class - * - * @package Smarty - * @subpackage Security - */ -class Smarty_Internal_Utility -{ - /** - * private constructor to prevent calls creation of new instances - */ - final private function __construct() - { - // intentionally left blank - } - - /** - * Return array of tag/attributes of all tags used by an template - * - * @param Smarty_Internal_Template $template - * - * @throws Exception - * @throws SmartyException - * @return array of tag/attributes - */ - public static function getTags(Smarty_Internal_Template $template) - { - $template->smarty->get_used_tags = true; - $template->compileTemplateSource(); - - return $template->used_tags; - } -} diff --git a/libs/sysplugins/smarty_template_config.php b/libs/sysplugins/smarty_template_config.php index 01f04306..57739de8 100644 --- a/libs/sysplugins/smarty_template_config.php +++ b/libs/sysplugins/smarty_template_config.php @@ -14,10 +14,7 @@ * @package Smarty * @subpackage TemplateResources * @author Uwe Tews - * @property integer $timestamp Source Timestamp - * @property boolean $exists Source Existence - * @property boolean $template Extended Template reference - * @property string $content Source Content + * */ class Smarty_Template_Config extends Smarty_Template_Source { @@ -89,7 +86,7 @@ class Smarty_Template_Config extends Smarty_Template_Source * @param Smarty $smarty smarty object * @param string $template_resource resource identifier * - * @return Smarty_Template_Source Source Object + * @return Smarty_Template_Config Source Object * @throws SmartyException */ public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null, $template_resource = null) @@ -110,7 +107,7 @@ class Smarty_Template_Config extends Smarty_Template_Source $source = new Smarty_Template_Config($resource, $smarty, $template_resource, $type, $name); $resource->populate($source, $_template); if (!$source->exists && isset($_template->smarty->default_config_handler_func)) { - Smarty_Internal_Extension_DefaultTemplateHandler::_getDefault($_template, $source); + Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source); } $source->unique_resource = $resource->buildUniqueResourceName($smarty, $name, true); return $source; diff --git a/libs/sysplugins/smarty_template_source.php b/libs/sysplugins/smarty_template_source.php index 70bb6a48..e4ea0794 100644 --- a/libs/sysplugins/smarty_template_source.php +++ b/libs/sysplugins/smarty_template_source.php @@ -7,10 +7,7 @@ * @package Smarty * @subpackage TemplateResources * @author Rodney Rehm - * @property integer $timestamp Source Timestamp - * @property boolean $exists Source Existence - * @property boolean $template Extended Template reference - * @property string $content Source Content + * */ class Smarty_Template_Source { @@ -217,7 +214,7 @@ class Smarty_Template_Source $source = new Smarty_Template_Source($resource, $smarty, $template_resource, $type, $name); $resource->populate($source, $_template); if (!$source->exists && isset($_template->smarty->default_template_handler_func)) { - Smarty_Internal_Extension_DefaultTemplateHandler::_getDefault($_template, $source); + Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source); } // on recompiling resources we are done if (($smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON) && !$resource->recompiled) {