mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-09 21:04:28 +02:00
- implementation of a 'variable' filter as replacement for default modifier
- update of unregister_....filter methods
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
04/10/2009
|
||||||
|
- implementation of a 'variable' filter as replacement for default modifier
|
||||||
|
|
||||||
04/09/2009
|
04/09/2009
|
||||||
- fixed execution of filters defined by classes
|
- fixed execution of filters defined by classes
|
||||||
- compile the always the content of {block} tags to make shure that the filters are running over it
|
- compile the always the content of {block} tags to make shure that the filters are running over it
|
||||||
|
@@ -42,9 +42,9 @@ if (!defined('SMARTY_DIR')) {
|
|||||||
/**
|
/**
|
||||||
* define variable scopes
|
* define variable scopes
|
||||||
*/
|
*/
|
||||||
define('SMARTY_LOCAL_SCOPE',0);
|
define('SMARTY_LOCAL_SCOPE', 0);
|
||||||
define('SMARTY_PARENT_SCOPE',1);
|
define('SMARTY_PARENT_SCOPE', 1);
|
||||||
define('SMARTY_ROOT_SCOPE',2);
|
define('SMARTY_ROOT_SCOPE', 2);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* load required base class for creation of the smarty object
|
* load required base class for creation of the smarty object
|
||||||
@@ -137,8 +137,6 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
public $exception_handler = array('SmartyException', 'getStaticException');
|
public $exception_handler = array('SmartyException', 'getStaticException');
|
||||||
// cached template objects
|
// cached template objects
|
||||||
static $template_objects = null;
|
static $template_objects = null;
|
||||||
// autoload filter
|
|
||||||
public $autoload_filters = array();
|
|
||||||
// check If-Modified-Since headers
|
// check If-Modified-Since headers
|
||||||
public $cache_modified_check = false;
|
public $cache_modified_check = false;
|
||||||
// registered plugins
|
// registered plugins
|
||||||
@@ -155,6 +153,10 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
public $registered_filters = array();
|
public $registered_filters = array();
|
||||||
// filter handler
|
// filter handler
|
||||||
public $filter_handler = null;
|
public $filter_handler = null;
|
||||||
|
// autoload filter
|
||||||
|
public $autoload_filters = array();
|
||||||
|
// status of filter on variable output
|
||||||
|
public $variable_filter = false;
|
||||||
// cache resorce objects
|
// cache resorce objects
|
||||||
public $cache_resource_objects = array();
|
public $cache_resource_objects = array();
|
||||||
// write file object
|
// write file object
|
||||||
@@ -194,6 +196,9 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
$this->loadPlugin($this->template_class);
|
$this->loadPlugin($this->template_class);
|
||||||
$this->loadPlugin('Smarty_Internal_Plugin_Handler');
|
$this->loadPlugin('Smarty_Internal_Plugin_Handler');
|
||||||
$this->plugin_handler = new Smarty_Internal_Plugin_Handler;
|
$this->plugin_handler = new Smarty_Internal_Plugin_Handler;
|
||||||
|
$this->loadPlugin('Smarty_Internal_Run_Filter');
|
||||||
|
$this->filter_handler = new Smarty_Internal_Run_Filter;
|
||||||
|
|
||||||
if (!$this->debugging && $this->debugging_ctrl == 'URL') {
|
if (!$this->debugging && $this->debugging_ctrl == 'URL') {
|
||||||
$_query_string = $this->request_use_auto_globals ? isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING']:'' : isset($GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING']) ? $GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING']:'';
|
$_query_string = $this->request_use_auto_globals ? isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING']:'' : isset($GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING']) ? $GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING']:'';
|
||||||
if (false !== strpos($_query_string, $this->smarty_debug_id)) {
|
if (false !== strpos($_query_string, $this->smarty_debug_id)) {
|
||||||
|
21
libs/plugins/variablefilter.htmlspecialchars.php
Normal file
21
libs/plugins/variablefilter.htmlspecialchars.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Smarty plugin
|
||||||
|
*
|
||||||
|
* @package Smarty
|
||||||
|
* @subpackage PluginsFilter
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty htmlspecialchars variablefilter plugin
|
||||||
|
*
|
||||||
|
* @param string $source input string
|
||||||
|
* @param object $ &$smarty Smarty object
|
||||||
|
* @return string filtered output
|
||||||
|
*/
|
||||||
|
function smarty_variablefilter_htmlspecialchars($source, &$smarty)
|
||||||
|
{
|
||||||
|
return htmlspecialchars($source, ENT_QUOTES);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@@ -23,7 +23,7 @@ class Smarty_Internal_Compile_Print_Expression extends Smarty_Internal_CompileBa
|
|||||||
{
|
{
|
||||||
$this->compiler = $compiler;
|
$this->compiler = $compiler;
|
||||||
$this->required_attributes = array('value');
|
$this->required_attributes = array('value');
|
||||||
$this->optional_attributes = array('assign','nocache');
|
$this->optional_attributes = array('assign', 'nocache', 'filter');
|
||||||
// check and get attributes
|
// check and get attributes
|
||||||
$_attr = $this->_get_attributes($args);
|
$_attr = $this->_get_attributes($args);
|
||||||
|
|
||||||
@@ -33,13 +33,17 @@ class Smarty_Internal_Compile_Print_Expression extends Smarty_Internal_CompileBa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isset($_attr['filter'])) {
|
||||||
|
$_attr['filter'] = 'null';
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($_attr['assign'])) {
|
if (isset($_attr['assign'])) {
|
||||||
// assign output to variable
|
// assign output to variable
|
||||||
$output = '<?php $_smarty_tpl->assign(' . $_attr['assign'] . ',' . $_attr['value'] . ');?>';
|
$output = '<?php $_smarty_tpl->assign(' . $_attr['assign'] . ',' . $_attr['value'] . ');?>';
|
||||||
} else {
|
} else {
|
||||||
// display value
|
// display value
|
||||||
$this->compiler->has_output = true;
|
$this->compiler->has_output = true;
|
||||||
$output = '<?php echo ' . $_attr['value'] . ';?>';
|
$output = '<?php echo $this->smarty->filter_handler->execute(\'variable\', ' . $_attr['value'] . ',' . $_attr['filter'] . ');?>';
|
||||||
}
|
}
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
@@ -32,10 +32,6 @@ class Smarty_Internal_Compiler extends Smarty_Internal_Base {
|
|||||||
$this->smarty->loadPlugin($parser_class);
|
$this->smarty->loadPlugin($parser_class);
|
||||||
$this->lexer_class = $lexer_class;
|
$this->lexer_class = $lexer_class;
|
||||||
$this->parser_class = $parser_class;
|
$this->parser_class = $parser_class;
|
||||||
if (!is_object($this->smarty->filter_handler) && (isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre']) || isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post']))) {
|
|
||||||
$this->smarty->loadPlugin('Smarty_Internal_Run_Filter');
|
|
||||||
$this->smarty->filter_handler = new Smarty_Internal_Run_Filter;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -22,36 +22,38 @@ class Smarty_Internal_Run_Filter extends Smarty_Internal_Base {
|
|||||||
* plugin filename format: filtertype.filtername.php
|
* plugin filename format: filtertype.filtername.php
|
||||||
* Smarty2 filter plugins could be used
|
* Smarty2 filter plugins could be used
|
||||||
*
|
*
|
||||||
* @param string $type the type of filter ('pre','post' or 'output') which shall run
|
* @param string $type the type of filter ('pre','post','output' or 'variable') which shall run
|
||||||
* @param string $content the content which shall be processed by the filters
|
* @param string $content the content which shall be processed by the filters
|
||||||
* @return string the filtered content
|
* @return string the filtered content
|
||||||
*/
|
*/
|
||||||
public function execute($type, $content)
|
public function execute($type, $content, $flag = null)
|
||||||
{
|
{
|
||||||
$output = $content;
|
$output = $content;
|
||||||
// loop over autoload filters of specified type
|
if ($type != 'variable' || ($this->smarty->variable_filter && $flag !== false) || $flag === true) {
|
||||||
if (!empty($this->smarty->autoload_filters[$type])) {
|
// loop over autoload filters of specified type
|
||||||
foreach ((array)$this->smarty->autoload_filters[$type] as $name) {
|
if (!empty($this->smarty->autoload_filters[$type])) {
|
||||||
$plugin_name = "Smarty_{$type}filter_{$name}";
|
foreach ((array)$this->smarty->autoload_filters[$type] as $name) {
|
||||||
if ($this->smarty->loadPlugin($plugin_name)) {
|
$plugin_name = "Smarty_{$type}filter_{$name}";
|
||||||
// use class plugin if found
|
if ($this->smarty->loadPlugin($plugin_name)) {
|
||||||
if (class_exists($plugin_name, false)) {
|
// use class plugin if found
|
||||||
// loaded class of filter plugin
|
if (class_exists($plugin_name, false)) {
|
||||||
$output = call_user_func_array(array($plugin_name, 'execute'), array($output, $this->smarty));
|
// loaded class of filter plugin
|
||||||
} elseif (function_exists($plugin_name)) {
|
$output = call_user_func_array(array($plugin_name, 'execute'), array($output, $this->smarty));
|
||||||
// use loaded Smarty2 style plugin
|
} elseif (function_exists($plugin_name)) {
|
||||||
$output = call_user_func_array($plugin_name, array($output, $this->smarty));
|
// use loaded Smarty2 style plugin
|
||||||
|
$output = call_user_func_array($plugin_name, array($output, $this->smarty));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// nothing found, throw exception
|
||||||
|
throw new Exception("Unable to load filter {$plugin_name}");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// nothing found, throw exception
|
|
||||||
throw new Exception("Unable to load filter {$plugin_name}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
// loop over registerd filters of specified type
|
||||||
// loop over registerd filters of specified type
|
if (!empty($this->smarty->registered_filters[$type])) {
|
||||||
if (!empty($this->smarty->registered_filters[$type])) {
|
foreach ($this->smarty->registered_filters[$type] as $key => $name) {
|
||||||
foreach ($this->smarty->registered_filters[$type] as $key => $name) {
|
$output = call_user_func_array($this->smarty->registered_filters[$type][$key], array($output, $this->smarty));
|
||||||
$output = call_user_func_array($this->smarty->registered_filters[$type][$key], array($output, $this->smarty));
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// return filtered output
|
// return filtered output
|
||||||
|
@@ -91,11 +91,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
|||||||
$this->cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($this->caching_type);
|
$this->cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($this->caching_type);
|
||||||
$this->parent = $_parent;
|
$this->parent = $_parent;
|
||||||
$this->tpl_vars['smarty'] = new Smarty_Variable;
|
$this->tpl_vars['smarty'] = new Smarty_Variable;
|
||||||
// load filter handler if required
|
|
||||||
if (!is_object($this->smarty->filter_handler) && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) {
|
|
||||||
$this->smarty->loadPlugin('Smarty_Internal_Run_Filter');
|
|
||||||
$this->smarty->filter_handler = new Smarty_Internal_Run_Filter;
|
|
||||||
}
|
|
||||||
// Template resource
|
// Template resource
|
||||||
$this->template_resource = $template_resource;
|
$this->template_resource = $template_resource;
|
||||||
// parse resource name
|
// parse resource name
|
||||||
|
26
libs/sysplugins/method.disablevariablefilter.php
Normal file
26
libs/sysplugins/method.disablevariablefilter.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty method disableVariableFilter
|
||||||
|
*
|
||||||
|
* Disable filter on variable output
|
||||||
|
*
|
||||||
|
* @package Smarty
|
||||||
|
* @subpackage SmartyMethod
|
||||||
|
* @author Uwe Tews
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty class disableVariableFilter
|
||||||
|
*
|
||||||
|
* Disable filter on variable output
|
||||||
|
*/
|
||||||
|
class Smarty_Method_disableVariableFilter extends Smarty_Internal_Base {
|
||||||
|
public function execute()
|
||||||
|
{
|
||||||
|
$this->smarty->variable_filter = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
26
libs/sysplugins/method.enablevariablefilter.php
Normal file
26
libs/sysplugins/method.enablevariablefilter.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty method enableVariableFilter
|
||||||
|
*
|
||||||
|
* Enable filter on variable output
|
||||||
|
*
|
||||||
|
* @package Smarty
|
||||||
|
* @subpackage SmartyMethod
|
||||||
|
* @author Uwe Tews
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty class enableVariableFilter
|
||||||
|
*
|
||||||
|
* Enable filter on variable output
|
||||||
|
*/
|
||||||
|
class Smarty_Method_enableVariableFilter extends Smarty_Internal_Base {
|
||||||
|
public function execute()
|
||||||
|
{
|
||||||
|
$this->smarty->variable_filter = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
25
libs/sysplugins/method.getvariablefilter.php
Normal file
25
libs/sysplugins/method.getvariablefilter.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty method getVariableFilter
|
||||||
|
*
|
||||||
|
* get status of filter on variable output
|
||||||
|
*
|
||||||
|
* @package Smarty
|
||||||
|
* @subpackage SmartyMethod
|
||||||
|
* @author Uwe Tews
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty class getVariableFilter
|
||||||
|
*
|
||||||
|
* get status of filter on variable output
|
||||||
|
*/
|
||||||
|
class Smarty_Method_getVariableFilter extends Smarty_Internal_Base {
|
||||||
|
public function execute()
|
||||||
|
{
|
||||||
|
return $this->smarty->variable_filter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@@ -25,7 +25,7 @@ class Smarty_Method_Load_Filter extends Smarty_Internal_Base {
|
|||||||
*/
|
*/
|
||||||
function execute($type, $name)
|
function execute($type, $name)
|
||||||
{
|
{
|
||||||
$_plugin = "Smarty_{$type}filter_{$name}";
|
$_plugin = "smarty_{$type}filter_{$name}";
|
||||||
$_filter_name = $_plugin;
|
$_filter_name = $_plugin;
|
||||||
if ($this->smarty->loadPlugin($_plugin)) {
|
if ($this->smarty->loadPlugin($_plugin)) {
|
||||||
if (class_exists($_plugin, false)) {
|
if (class_exists($_plugin, false)) {
|
||||||
|
33
libs/sysplugins/method.register_variablefilter.php
Normal file
33
libs/sysplugins/method.register_variablefilter.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty method Register_Variablefilter
|
||||||
|
*
|
||||||
|
* Registers a PHP function as an output filter for variables
|
||||||
|
*
|
||||||
|
* @package Smarty
|
||||||
|
* @subpackage SmartyMethod
|
||||||
|
* @author Uwe Tews
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty class Register_Variablefilter
|
||||||
|
*
|
||||||
|
* Register a PHP function as variablefilter
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Smarty_Method_Register_Variablefilter extends Smarty_Internal_Base {
|
||||||
|
/**
|
||||||
|
* Registers an output filter function which
|
||||||
|
* runs over any variable output
|
||||||
|
*
|
||||||
|
* @param callback $function
|
||||||
|
*/
|
||||||
|
public function execute($function)
|
||||||
|
{
|
||||||
|
$_name = (is_array($function)) ? $function[0] : $function;
|
||||||
|
$this->smarty->registered_filters['variable'][$_name] = $function;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@@ -25,7 +25,8 @@ class Smarty_Method_Unregister_Outputfilter extends Smarty_Internal_Base {
|
|||||||
*/
|
*/
|
||||||
public function execute($function)
|
public function execute($function)
|
||||||
{
|
{
|
||||||
unset($this->smarty->registered_filters['output'][$function]);
|
$_name = (is_array($function)) ? $function[0] : $function;
|
||||||
|
unset($this->smarty->registered_filters['output'][$_name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,7 +24,8 @@ class Smarty_Method_Unregister_Postfilter extends Smarty_Internal_Base {
|
|||||||
*/
|
*/
|
||||||
public function execute($function)
|
public function execute($function)
|
||||||
{
|
{
|
||||||
unset($this->smarty->registered_filters['post'][$function]);
|
$_name = (is_array($function)) ? $function[0] : $function;
|
||||||
|
unset($this->smarty->registered_filters['post'][$_name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,7 +24,8 @@ class Smarty_Method_Unregister_Prefilter extends Smarty_Internal_Base {
|
|||||||
*/
|
*/
|
||||||
public function execute($function)
|
public function execute($function)
|
||||||
{
|
{
|
||||||
unset($this->smarty->registered_filters['pre'][$function]);
|
$_name = (is_array($function)) ? $function[0] : $function;
|
||||||
|
unset($this->smarty->registered_filters['pre'][$_name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
32
libs/sysplugins/method.unregister_variablefilter.php
Normal file
32
libs/sysplugins/method.unregister_variablefilter.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty method Unregister_Variablefilter
|
||||||
|
*
|
||||||
|
* Unregister a variablefilter
|
||||||
|
*
|
||||||
|
* @package Smarty
|
||||||
|
* @subpackage SmartyMethod
|
||||||
|
* @author Uwe Tews
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty class Unregister_Variablefilter
|
||||||
|
*
|
||||||
|
* Unregister a variablefilter
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Smarty_Method_Unregister_Variablefilter extends Smarty_Internal_Base {
|
||||||
|
/**
|
||||||
|
* Unregisters a variablefilter function
|
||||||
|
*
|
||||||
|
* @param callback $function
|
||||||
|
*/
|
||||||
|
public function execute($function)
|
||||||
|
{
|
||||||
|
$_name = (is_array($function)) ? $function[0] : $function;
|
||||||
|
unset($this->smarty->registered_filters['variable'][$_name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
Reference in New Issue
Block a user