diff --git a/change_log.txt b/change_log.txt index f88b3762..7c548b47 100644 --- a/change_log.txt +++ b/change_log.txt @@ -2,6 +2,7 @@ 28.06.2015 - move $smarty->enableSecurity() into Smarty_Security class - optimize security isTrustedResourceDir() + - move auto load filter methods into extension 27.06.2015 - bugfix resolve naming conflict between custom Smarty delimiter '<%' and PHP ASP tags https://github.com/smarty-php/smarty/issues/64 diff --git a/libs/Autoloader.php b/libs/Autoloader.php index a7356b2b..aa89cc97 100644 --- a/libs/Autoloader.php +++ b/libs/Autoloader.php @@ -47,43 +47,44 @@ class Smarty_Autoloader */ public static $rootClasses = array('Smarty' => 'Smarty.class.php', 'SmartyBC' => 'SmartyBC.class.php',); - private static $syspluginsClasses = array('smarty_config_source' => true, - 'smarty_security' => true, - 'smarty_cacheresource' => true, - 'smarty_compiledresource' => true, - 'smarty_cacheresource_custom' => true, - 'smarty_cacheresource_keyvaluestore' => true, - 'smarty_resource' => true, - 'smarty_resource_custom' => true, - 'smarty_resource_uncompiled' => true, - 'smarty_resource_recompiled' => true, - 'smarty_template_source' => true, - 'smarty_template_compiled' => true, - 'smarty_template_cached' => true, - 'smarty_template_config' => true, - 'smarty_data' => true, - 'smarty_variable' => true, - 'smarty_undefined_variable' => true, - 'smartyexception' => true, - 'smartycompilerexception' => true, - 'smarty_internal_data' => true, - 'smarty_internal_template' => true, - 'smarty_internal_templatebase' => true, - 'smarty_internal_resource_file' => true, - 'smarty_internal_resource_extends' => true, - 'smarty_internal_resource_eval' => true, - 'smarty_internal_resource_string' => true, - 'smarty_internal_resource_registered' => true, - 'smarty_internal_extension_codeframe' => true, - 'smarty_internal_extension_config' => true, - 'smarty_internal_extension_filter' => true, - 'smarty_internal_extension_object' => true, - 'smarty_internal_extension_loadplugin' => true, - 'smarty_internal_extension_clearcompiled' => true, - 'smarty_internal_filter_handler' => true, - 'smarty_internal_function_call_handler' => true, - 'smarty_internal_cacheresource_file' => true, - 'smarty_internal_write_file' => true,); + private static $syspluginsClasses = array('smarty_config_source' => true, + 'smarty_security' => true, + 'smarty_cacheresource' => true, + 'smarty_compiledresource' => true, + 'smarty_cacheresource_custom' => true, + 'smarty_cacheresource_keyvaluestore' => true, + 'smarty_resource' => true, + 'smarty_resource_custom' => true, + 'smarty_resource_uncompiled' => true, + 'smarty_resource_recompiled' => true, + 'smarty_template_source' => true, + 'smarty_template_compiled' => true, + 'smarty_template_cached' => true, + 'smarty_template_config' => true, + 'smarty_data' => true, + 'smarty_variable' => true, + 'smarty_undefined_variable' => true, + 'smartyexception' => true, + 'smartycompilerexception' => true, + 'smarty_internal_data' => true, + 'smarty_internal_template' => true, + 'smarty_internal_templatebase' => true, + 'smarty_internal_resource_file' => true, + 'smarty_internal_resource_extends' => true, + 'smarty_internal_resource_eval' => true, + 'smarty_internal_resource_string' => true, + 'smarty_internal_resource_registered' => true, + 'smarty_internal_extension_codeframe' => true, + 'smarty_internal_extension_config' => true, + 'smarty_internal_extension_filter' => true, + 'smarty_internal_extension_autoloadfilter' => true, + 'smarty_internal_extension_object' => true, + 'smarty_internal_extension_loadplugin' => true, + 'smarty_internal_extension_clearcompiled' => true, + 'smarty_internal_filter_handler' => true, + 'smarty_internal_function_call_handler' => true, + 'smarty_internal_cacheresource_file' => true, + 'smarty_internal_write_file' => true,); /** * Registers Smarty_Autoloader backward compatible to older installations. diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 74f0d9a5..95316a0e 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.28-dev/13'; + const SMARTY_VERSION = '3.1.28-dev/14'; /** * define variable scopes @@ -1249,12 +1249,7 @@ class Smarty extends Smarty_Internal_TemplateBase */ public function setAutoloadFilters($filters, $type = null) { - if ($type !== null) { - $this->autoload_filters[$type] = (array) $filters; - } else { - $this->autoload_filters = (array) $filters; - } - + Smarty_Internal_Extension_AutoLoadFilter::setAutoloadFilters($this, $filters, $type); return $this; } @@ -1269,22 +1264,7 @@ class Smarty extends Smarty_Internal_TemplateBase */ public function addAutoloadFilters($filters, $type = null) { - if ($type !== null) { - if (!empty($this->autoload_filters[$type])) { - $this->autoload_filters[$type] = array_merge($this->autoload_filters[$type], (array) $filters); - } else { - $this->autoload_filters[$type] = (array) $filters; - } - } else { - foreach ((array) $filters as $key => $value) { - if (!empty($this->autoload_filters[$key])) { - $this->autoload_filters[$key] = array_merge($this->autoload_filters[$key], (array) $value); - } else { - $this->autoload_filters[$key] = (array) $value; - } - } - } - + Smarty_Internal_Extension_AutoLoadFilter::addAutoloadFilters($this, $filters, $type); return $this; } @@ -1298,10 +1278,7 @@ class Smarty extends Smarty_Internal_TemplateBase */ public function getAutoloadFilters($type = null) { - if ($type !== null) { - return isset($this->autoload_filters[$type]) ? $this->autoload_filters[$type] : array(); - } - return $this->autoload_filters; + return Smarty_Internal_Extension_AutoLoadFilter::getAutoloadFilters($this, $type); } /** diff --git a/libs/sysplugins/smarty_internal_extension_autoloadfilter.php b/libs/sysplugins/smarty_internal_extension_autoloadfilter.php new file mode 100644 index 00000000..216bb5d4 --- /dev/null +++ b/libs/sysplugins/smarty_internal_extension_autoloadfilter.php @@ -0,0 +1,102 @@ + true, 'post' => true, 'output' => true, 'variable' => true); + + /** + * Set autoload filters + * + * @param \Smarty $smarty + * @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 + */ + public static function setAutoloadFilters(Smarty $smarty, $filters, $type) + { + if ($type !== null) { + self::_checkFilterType($type); + $smarty->autoload_filters[$type] = (array) $filters; + } else { + foreach ((array) $filters as $type => $value) { + self::_checkFilterType($type); + } + $smarty->autoload_filters = (array) $filters; + } + } + + /** + * Add autoload filters + * + * @param \Smarty $smarty + * @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 + */ + public static function addAutoloadFilters(Smarty $smarty, $filters, $type) + { + if ($type !== null) { + self::_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) { + self::_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; + } + } + } + } + + /** + * Get autoload filters + * + * @param \Smarty $smarty + * @param string $type type of filter to get auto loads for. Defaults to all autoload filters + * + * @return array array( 'type1' => array( 'filter1', 'filter2', … ) ) or array( 'filter1', 'filter2', …) if $type + * was specified + */ + public static function getAutoloadFilters(Smarty $smarty, $type) + { + if ($type !== null) { + self::_checkFilterType($type); + return isset($smarty->autoload_filters[$type]) ? $smarty->autoload_filters[$type] : array(); + } + return $smarty->autoload_filters; + } + + /** + * 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