mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
- move auto load filter methods into extension
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
28.06.2015
|
28.06.2015
|
||||||
- move $smarty->enableSecurity() into Smarty_Security class
|
- move $smarty->enableSecurity() into Smarty_Security class
|
||||||
- optimize security isTrustedResourceDir()
|
- optimize security isTrustedResourceDir()
|
||||||
|
- move auto load filter methods into extension
|
||||||
|
|
||||||
27.06.2015
|
27.06.2015
|
||||||
- bugfix resolve naming conflict between custom Smarty delimiter '<%' and PHP ASP tags https://github.com/smarty-php/smarty/issues/64
|
- bugfix resolve naming conflict between custom Smarty delimiter '<%' and PHP ASP tags https://github.com/smarty-php/smarty/issues/64
|
||||||
|
@@ -77,6 +77,7 @@ class Smarty_Autoloader
|
|||||||
'smarty_internal_extension_codeframe' => true,
|
'smarty_internal_extension_codeframe' => true,
|
||||||
'smarty_internal_extension_config' => true,
|
'smarty_internal_extension_config' => true,
|
||||||
'smarty_internal_extension_filter' => true,
|
'smarty_internal_extension_filter' => true,
|
||||||
|
'smarty_internal_extension_autoloadfilter' => true,
|
||||||
'smarty_internal_extension_object' => true,
|
'smarty_internal_extension_object' => true,
|
||||||
'smarty_internal_extension_loadplugin' => true,
|
'smarty_internal_extension_loadplugin' => true,
|
||||||
'smarty_internal_extension_clearcompiled' => true,
|
'smarty_internal_extension_clearcompiled' => true,
|
||||||
|
@@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* smarty version
|
* smarty version
|
||||||
*/
|
*/
|
||||||
const SMARTY_VERSION = '3.1.28-dev/13';
|
const SMARTY_VERSION = '3.1.28-dev/14';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* define variable scopes
|
* define variable scopes
|
||||||
@@ -1249,12 +1249,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
*/
|
*/
|
||||||
public function setAutoloadFilters($filters, $type = null)
|
public function setAutoloadFilters($filters, $type = null)
|
||||||
{
|
{
|
||||||
if ($type !== null) {
|
Smarty_Internal_Extension_AutoLoadFilter::setAutoloadFilters($this, $filters, $type);
|
||||||
$this->autoload_filters[$type] = (array) $filters;
|
|
||||||
} else {
|
|
||||||
$this->autoload_filters = (array) $filters;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1269,22 +1264,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
*/
|
*/
|
||||||
public function addAutoloadFilters($filters, $type = null)
|
public function addAutoloadFilters($filters, $type = null)
|
||||||
{
|
{
|
||||||
if ($type !== null) {
|
Smarty_Internal_Extension_AutoLoadFilter::addAutoloadFilters($this, $filters, $type);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1298,10 +1278,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
*/
|
*/
|
||||||
public function getAutoloadFilters($type = null)
|
public function getAutoloadFilters($type = null)
|
||||||
{
|
{
|
||||||
if ($type !== null) {
|
return Smarty_Internal_Extension_AutoLoadFilter::getAutoloadFilters($this, $type);
|
||||||
return isset($this->autoload_filters[$type]) ? $this->autoload_filters[$type] : array();
|
|
||||||
}
|
|
||||||
return $this->autoload_filters;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
102
libs/sysplugins/smarty_internal_extension_autoloadfilter.php
Normal file
102
libs/sysplugins/smarty_internal_extension_autoloadfilter.php
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty Extension AutoLoadFilter
|
||||||
|
*
|
||||||
|
* Auto load filter methods
|
||||||
|
*
|
||||||
|
* @package Smarty
|
||||||
|
* @subpackage PluginsInternal
|
||||||
|
* @author Uwe Tews
|
||||||
|
*/
|
||||||
|
class Smarty_Internal_Extension_AutoLoadFilter
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Valid filter types
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
static $filterTypes = array('pre' => 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", <20> 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", <20> 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', <20> ) ) or array( 'filter1', 'filter2', <20>) 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}\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user