mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
Added postfilter functions.
This commit is contained in:
2
NEWS
2
NEWS
@@ -1,3 +1,5 @@
|
|||||||
|
- added support for postfilter functions that are applied to compiled
|
||||||
|
template right after compilation. (Andrei)
|
||||||
- fixed the name of clear_compile_tpl() API function to clear_compiled_tpl.
|
- fixed the name of clear_compile_tpl() API function to clear_compiled_tpl.
|
||||||
(Andrei)
|
(Andrei)
|
||||||
- added fix for removing comments so that the line numbers are reported
|
- added fix for removing comments so that the line numbers are reported
|
||||||
|
@@ -170,9 +170,11 @@ class Smarty
|
|||||||
|
|
||||||
var $compiler_class = 'Smarty_Compiler'; // the compiler class used by
|
var $compiler_class = 'Smarty_Compiler'; // the compiler class used by
|
||||||
// Smarty to compile templates
|
// Smarty to compile templates
|
||||||
var $resource_funcs = array(); // what functions resource handlers are mapped to
|
var $resource_funcs = array(); // functions that resource handlers are mapped to
|
||||||
var $prefilter_funcs = array(); // what functions templates are prefiltered through
|
var $prefilter_funcs = array(); // functions that templates are filtered through
|
||||||
// before being compiled
|
// before being compiled
|
||||||
|
var $postfilter_funcs = array(); // functions that compiled templates are filtered
|
||||||
|
// through after compilation
|
||||||
|
|
||||||
var $request_vars_order = "EGPCS"; // the order in which request variables are
|
var $request_vars_order = "EGPCS"; // the order in which request variables are
|
||||||
// registered, similar to variables_order
|
// registered, similar to variables_order
|
||||||
@@ -366,7 +368,7 @@ class Smarty
|
|||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: unregister_prefilter
|
Function: unregister_prefilter
|
||||||
Purpose: Unregisters a prefilter
|
Purpose: Unregisters a prefilter function
|
||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
function unregister_prefilter($function_name)
|
function unregister_prefilter($function_name)
|
||||||
{
|
{
|
||||||
@@ -379,6 +381,31 @@ class Smarty
|
|||||||
$this->prefilter_funcs = $tmp_array;
|
$this->prefilter_funcs = $tmp_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*======================================================================*\
|
||||||
|
Function: register_postfilter
|
||||||
|
Purpose: Registers a postfilter function to apply
|
||||||
|
to a compiled template after compilation
|
||||||
|
\*======================================================================*/
|
||||||
|
function register_postfilter($function_name)
|
||||||
|
{
|
||||||
|
$this->postfilter_funcs[] = $function_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*======================================================================*\
|
||||||
|
Function: unregister_postfilter
|
||||||
|
Purpose: Unregisters a postfilter function
|
||||||
|
\*======================================================================*/
|
||||||
|
function unregister_postfilter($function_name)
|
||||||
|
{
|
||||||
|
$tmp_array = array();
|
||||||
|
foreach($this->postfilter_funcs as $curr_func) {
|
||||||
|
if ($curr_func != $function_name) {
|
||||||
|
$tmp_array[] = $curr_func;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->postfilter_funcs = $tmp_array;
|
||||||
|
}
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: clear_cache()
|
Function: clear_cache()
|
||||||
Purpose: clear cached content for the given template and cache id
|
Purpose: clear cached content for the given template and cache id
|
||||||
@@ -786,6 +813,7 @@ function _generate_debug_output() {
|
|||||||
$smarty_compiler->custom_mods = $this->custom_mods;
|
$smarty_compiler->custom_mods = $this->custom_mods;
|
||||||
$smarty_compiler->_version = $this->_version;
|
$smarty_compiler->_version = $this->_version;
|
||||||
$smarty_compiler->prefilter_funcs = $this->prefilter_funcs;
|
$smarty_compiler->prefilter_funcs = $this->prefilter_funcs;
|
||||||
|
$smarty_compiler->postfilter_funcs = $this->postfilter_funcs;
|
||||||
$smarty_compiler->compiler_funcs = $this->compiler_funcs;
|
$smarty_compiler->compiler_funcs = $this->compiler_funcs;
|
||||||
$smarty_compiler->security = $this->security;
|
$smarty_compiler->security = $this->security;
|
||||||
$smarty_compiler->secure_dir = $this->secure_dir;
|
$smarty_compiler->secure_dir = $this->secure_dir;
|
||||||
|
@@ -63,7 +63,7 @@ class Smarty_Compiler extends Smarty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// run template source through functions registered in prefilter_funcs
|
// run template source through prefilter functions
|
||||||
if (is_array($this->prefilter_funcs) && count($this->prefilter_funcs) > 0) {
|
if (is_array($this->prefilter_funcs) && count($this->prefilter_funcs) > 0) {
|
||||||
foreach ($this->prefilter_funcs as $prefilter) {
|
foreach ($this->prefilter_funcs as $prefilter) {
|
||||||
if (function_exists($prefilter)) {
|
if (function_exists($prefilter)) {
|
||||||
@@ -162,6 +162,18 @@ class Smarty_Compiler extends Smarty {
|
|||||||
$template_header = "<?php /* Smarty version ".$this->_version.", created on ".strftime("%Y-%m-%d %H:%M:%S")."\n";
|
$template_header = "<?php /* Smarty version ".$this->_version.", created on ".strftime("%Y-%m-%d %H:%M:%S")."\n";
|
||||||
$template_header .= " compiled from ".$tpl_file." */ ?>\n";
|
$template_header .= " compiled from ".$tpl_file." */ ?>\n";
|
||||||
$template_compiled = $template_header.$template_compiled;
|
$template_compiled = $template_header.$template_compiled;
|
||||||
|
|
||||||
|
|
||||||
|
// run compiled template through postfilter functions
|
||||||
|
if (is_array($this->postfilter_funcs) && count($this->postfilter_funcs) > 0) {
|
||||||
|
foreach ($this->postfilter_funcs as $postfilter) {
|
||||||
|
if (function_exists($postfilter)) {
|
||||||
|
$template_compiled = $postfilter($template_compiled, $this);
|
||||||
|
} else {
|
||||||
|
$this->_trigger_error_msg("postfilter function $postfilter does not exist.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -170,9 +170,11 @@ class Smarty
|
|||||||
|
|
||||||
var $compiler_class = 'Smarty_Compiler'; // the compiler class used by
|
var $compiler_class = 'Smarty_Compiler'; // the compiler class used by
|
||||||
// Smarty to compile templates
|
// Smarty to compile templates
|
||||||
var $resource_funcs = array(); // what functions resource handlers are mapped to
|
var $resource_funcs = array(); // functions that resource handlers are mapped to
|
||||||
var $prefilter_funcs = array(); // what functions templates are prefiltered through
|
var $prefilter_funcs = array(); // functions that templates are filtered through
|
||||||
// before being compiled
|
// before being compiled
|
||||||
|
var $postfilter_funcs = array(); // functions that compiled templates are filtered
|
||||||
|
// through after compilation
|
||||||
|
|
||||||
var $request_vars_order = "EGPCS"; // the order in which request variables are
|
var $request_vars_order = "EGPCS"; // the order in which request variables are
|
||||||
// registered, similar to variables_order
|
// registered, similar to variables_order
|
||||||
@@ -366,7 +368,7 @@ class Smarty
|
|||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: unregister_prefilter
|
Function: unregister_prefilter
|
||||||
Purpose: Unregisters a prefilter
|
Purpose: Unregisters a prefilter function
|
||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
function unregister_prefilter($function_name)
|
function unregister_prefilter($function_name)
|
||||||
{
|
{
|
||||||
@@ -379,6 +381,31 @@ class Smarty
|
|||||||
$this->prefilter_funcs = $tmp_array;
|
$this->prefilter_funcs = $tmp_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*======================================================================*\
|
||||||
|
Function: register_postfilter
|
||||||
|
Purpose: Registers a postfilter function to apply
|
||||||
|
to a compiled template after compilation
|
||||||
|
\*======================================================================*/
|
||||||
|
function register_postfilter($function_name)
|
||||||
|
{
|
||||||
|
$this->postfilter_funcs[] = $function_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*======================================================================*\
|
||||||
|
Function: unregister_postfilter
|
||||||
|
Purpose: Unregisters a postfilter function
|
||||||
|
\*======================================================================*/
|
||||||
|
function unregister_postfilter($function_name)
|
||||||
|
{
|
||||||
|
$tmp_array = array();
|
||||||
|
foreach($this->postfilter_funcs as $curr_func) {
|
||||||
|
if ($curr_func != $function_name) {
|
||||||
|
$tmp_array[] = $curr_func;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->postfilter_funcs = $tmp_array;
|
||||||
|
}
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: clear_cache()
|
Function: clear_cache()
|
||||||
Purpose: clear cached content for the given template and cache id
|
Purpose: clear cached content for the given template and cache id
|
||||||
@@ -786,6 +813,7 @@ function _generate_debug_output() {
|
|||||||
$smarty_compiler->custom_mods = $this->custom_mods;
|
$smarty_compiler->custom_mods = $this->custom_mods;
|
||||||
$smarty_compiler->_version = $this->_version;
|
$smarty_compiler->_version = $this->_version;
|
||||||
$smarty_compiler->prefilter_funcs = $this->prefilter_funcs;
|
$smarty_compiler->prefilter_funcs = $this->prefilter_funcs;
|
||||||
|
$smarty_compiler->postfilter_funcs = $this->postfilter_funcs;
|
||||||
$smarty_compiler->compiler_funcs = $this->compiler_funcs;
|
$smarty_compiler->compiler_funcs = $this->compiler_funcs;
|
||||||
$smarty_compiler->security = $this->security;
|
$smarty_compiler->security = $this->security;
|
||||||
$smarty_compiler->secure_dir = $this->secure_dir;
|
$smarty_compiler->secure_dir = $this->secure_dir;
|
||||||
|
@@ -63,7 +63,7 @@ class Smarty_Compiler extends Smarty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// run template source through functions registered in prefilter_funcs
|
// run template source through prefilter functions
|
||||||
if (is_array($this->prefilter_funcs) && count($this->prefilter_funcs) > 0) {
|
if (is_array($this->prefilter_funcs) && count($this->prefilter_funcs) > 0) {
|
||||||
foreach ($this->prefilter_funcs as $prefilter) {
|
foreach ($this->prefilter_funcs as $prefilter) {
|
||||||
if (function_exists($prefilter)) {
|
if (function_exists($prefilter)) {
|
||||||
@@ -162,6 +162,18 @@ class Smarty_Compiler extends Smarty {
|
|||||||
$template_header = "<?php /* Smarty version ".$this->_version.", created on ".strftime("%Y-%m-%d %H:%M:%S")."\n";
|
$template_header = "<?php /* Smarty version ".$this->_version.", created on ".strftime("%Y-%m-%d %H:%M:%S")."\n";
|
||||||
$template_header .= " compiled from ".$tpl_file." */ ?>\n";
|
$template_header .= " compiled from ".$tpl_file." */ ?>\n";
|
||||||
$template_compiled = $template_header.$template_compiled;
|
$template_compiled = $template_header.$template_compiled;
|
||||||
|
|
||||||
|
|
||||||
|
// run compiled template through postfilter functions
|
||||||
|
if (is_array($this->postfilter_funcs) && count($this->postfilter_funcs) > 0) {
|
||||||
|
foreach ($this->postfilter_funcs as $postfilter) {
|
||||||
|
if (function_exists($postfilter)) {
|
||||||
|
$template_compiled = $postfilter($template_compiled, $this);
|
||||||
|
} else {
|
||||||
|
$this->_trigger_error_msg("postfilter function $postfilter does not exist.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user