aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorpatdenice <patdenice@piwigo.org>2009-10-01 10:46:48 +0000
committerpatdenice <patdenice@piwigo.org>2009-10-01 10:46:48 +0000
commit162a4d1b78544a33cb04919b7214c26245c470bc (patch)
tree53339d1de58c5d794c7107b6ecf37cfd75fdb65d /include
parent243a0693e948eccc22f85174d42515d20368bc1e (diff)
Allow to add prefilters, postfilters and output filters to templates.
git-svn-id: http://piwigo.org/svn/trunk@3951 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include')
-rw-r--r--include/template.class.php69
1 files changed, 47 insertions, 22 deletions
diff --git a/include/template.class.php b/include/template.class.php
index 0a1b5b7fb..15d7bc3fa 100644
--- a/include/template.class.php
+++ b/include/template.class.php
@@ -429,21 +429,22 @@ class Template {
* They will be processed by weight ascending.
* http://www.smarty.net/manual/en/advanced.features.prefilters.php
*/
- function set_external_filter($handle, $callback, $weight=50)
+ function set_prefilter($handle, $callback, $weight=50)
{
- if (isset($this->external_filters[$handle][$weight]))
- {
- foreach($this->external_filters[$handle][$weight] as $func)
- {
- if ($func == $callback)
- {
- return false;
- }
- }
- }
- $this->external_filters[$handle][$weight][] = $callback;
+ $this->external_filters[$handle][$weight][] = array('pre', $callback);
+ ksort($this->external_filters[$handle]);
+ }
+
+ function set_postfilter($handle, $callback, $weight=50)
+ {
+ $this->external_filters[$handle][$weight][] = array('post', $callback);
+ ksort($this->external_filters[$handle]);
+ }
+
+ function set_outputfilter($handle, $callback, $weight=50)
+ {
+ $this->external_filters[$handle][$weight][] = array('output', $callback);
ksort($this->external_filters[$handle]);
- return true;
}
/**
@@ -455,16 +456,28 @@ class Template {
{
if (isset($this->external_filters[$handle]))
{
- $compile_id = $this->smarty->compile_id;
- foreach ($this->external_filters[$handle] as $callbacks)
+ $compile_id = '';
+ foreach ($this->external_filters[$handle] as $filters)
{
- foreach ($callbacks as $callback)
+ foreach ($filters as $filter)
{
- $compile_id .= $callback;
- $this->smarty->register_prefilter($callback);
+ list($type, $callback) = $filter;
+ $compile_id .= $type.( is_array($callback) ? implode('', $callback) : $callback );
+ switch ($type)
+ {
+ case 'pre':
+ $this->smarty->register_prefilter($callback);
+ break;
+ case 'post':
+ $this->smarty->register_postfilter($callback);
+ break;
+ case 'output':
+ $this->smarty->register_outputfilter($callback);
+ break;
+ }
}
}
- $this->smarty->compile_id = base_convert(crc32($compile_id), 10, 36);
+ $this->smarty->compile_id .= '.'.base_convert(crc32($compile_id), 10, 36);
}
}
@@ -472,11 +485,23 @@ class Template {
{
if (isset($this->external_filters[$handle]))
{
- foreach ($this->external_filters[$handle] as $callbacks)
+ foreach ($this->external_filters[$handle] as $filters)
{
- foreach ($callbacks as $callback)
+ foreach ($filters as $filter)
{
- $this->smarty->unregister_prefilter($callback);
+ list($type, $callback) = $filter;
+ switch ($type)
+ {
+ case 'pre':
+ $this->smarty->unregister_prefilter($callback);
+ break;
+ case 'post':
+ $this->smarty->unregister_postfilter($callback);
+ break;
+ case 'output':
+ $this->smarty->unregister_outputfilter($callback);
+ break;
+ }
}
}
}