From ba8a7a6115d36c01c114ca4e47dbf2908e3ddba2 Mon Sep 17 00:00:00 2001 From: andrei Date: Fri, 5 Apr 2002 17:16:52 +0000 Subject: [PATCH] Make it possible to unregister pre/postfilter plugins. --- NEWS | 4 +++- Smarty.class.php | 10 ++++++++-- Smarty_Compiler.class.php | 5 ++++- libs/Smarty.class.php | 10 ++++++++-- libs/Smarty_Compiler.class.php | 5 ++++- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index a8190df1..74f62e5e 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,6 @@ - - added htmlall attribute to escape (Monte) + - added ability to unregister pre/postfilters plugins at + runtime. (Andrei) + - added 'htmlall' attribute to escape modifier. (Monte) - added template_exists() API function. (Andrei) - fixed a problem with using dynamic values for 'file' attribute of {include_php} tag. (Andrei) diff --git a/Smarty.class.php b/Smarty.class.php index 2a5bbe0c..7406e253 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -370,7 +370,10 @@ class Smarty \*======================================================================*/ function unregister_prefilter($function) { - unset($this->_plugins['prefilter'][$function]); + if (isset($this->_plugins['prefilter'][$function])) + unset($this->_plugins['prefilter'][$function]); + else + $this->_plugins['prefilter'][$function] = false; } /*======================================================================*\ @@ -390,7 +393,10 @@ class Smarty \*======================================================================*/ function unregister_postfilter($function) { - unset($this->_plugins['postfilter'][$function]); + if (isset($this->_plugins['postfilter'][$function])) + unset($this->_plugins['postfilter'][$function]); + else + $this->_plugins['postfilter'][$function] = false; } /*======================================================================*\ diff --git a/Smarty_Compiler.class.php b/Smarty_Compiler.class.php index ff3ef881..3043736a 100644 --- a/Smarty_Compiler.class.php +++ b/Smarty_Compiler.class.php @@ -80,6 +80,7 @@ class Smarty_Compiler extends Smarty { // run template source through prefilter functions if (count($this->_plugins['prefilter']) > 0) { foreach ($this->_plugins['prefilter'] as $filter_name => $prefilter) { + if ($prefilter === false) continue; if ($prefilter[3] || function_exists($prefilter[0])) { $template_source = $prefilter[0]($template_source, $this); $this->_plugins['prefilter'][$filter_name][3] = true; @@ -176,6 +177,7 @@ class Smarty_Compiler extends Smarty { // run compiled template through postfilter functions if (count($this->_plugins['postfilter']) > 0) { foreach ($this->_plugins['postfilter'] as $filter_name => $postfilter) { + if ($postfilter === false) continue; if ($postfilter[3] || function_exists($postfilter[0])) { $template_compiled = $postfilter[0]($template_compiled, $this); $this->_plugins['postfilter'][$filter_name][3] = true; @@ -1366,7 +1368,8 @@ class Smarty_Compiler extends Smarty { $parts[2] != 'php' || ($parts[0] != 'prefilter' && $parts[0] != 'postfilter') || - isset($this->_plugins[$parts[0]][$parts[1]])) + (isset($this->_plugins[$parts[0]][$parts[1]]) && + $this->_plugins[$parts[0]][$parts[1]] === false)) continue; $plugin_file = $plugins_dir . '/' . $entry; diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 2a5bbe0c..7406e253 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -370,7 +370,10 @@ class Smarty \*======================================================================*/ function unregister_prefilter($function) { - unset($this->_plugins['prefilter'][$function]); + if (isset($this->_plugins['prefilter'][$function])) + unset($this->_plugins['prefilter'][$function]); + else + $this->_plugins['prefilter'][$function] = false; } /*======================================================================*\ @@ -390,7 +393,10 @@ class Smarty \*======================================================================*/ function unregister_postfilter($function) { - unset($this->_plugins['postfilter'][$function]); + if (isset($this->_plugins['postfilter'][$function])) + unset($this->_plugins['postfilter'][$function]); + else + $this->_plugins['postfilter'][$function] = false; } /*======================================================================*\ diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index ff3ef881..3043736a 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -80,6 +80,7 @@ class Smarty_Compiler extends Smarty { // run template source through prefilter functions if (count($this->_plugins['prefilter']) > 0) { foreach ($this->_plugins['prefilter'] as $filter_name => $prefilter) { + if ($prefilter === false) continue; if ($prefilter[3] || function_exists($prefilter[0])) { $template_source = $prefilter[0]($template_source, $this); $this->_plugins['prefilter'][$filter_name][3] = true; @@ -176,6 +177,7 @@ class Smarty_Compiler extends Smarty { // run compiled template through postfilter functions if (count($this->_plugins['postfilter']) > 0) { foreach ($this->_plugins['postfilter'] as $filter_name => $postfilter) { + if ($postfilter === false) continue; if ($postfilter[3] || function_exists($postfilter[0])) { $template_compiled = $postfilter[0]($template_compiled, $this); $this->_plugins['postfilter'][$filter_name][3] = true; @@ -1366,7 +1368,8 @@ class Smarty_Compiler extends Smarty { $parts[2] != 'php' || ($parts[0] != 'prefilter' && $parts[0] != 'postfilter') || - isset($this->_plugins[$parts[0]][$parts[1]])) + (isset($this->_plugins[$parts[0]][$parts[1]]) && + $this->_plugins[$parts[0]][$parts[1]] === false)) continue; $plugin_file = $plugins_dir . '/' . $entry;