From e6363de6fd7cd1791991a6dbaeae43849e907423 Mon Sep 17 00:00:00 2001 From: mathiasm Date: Sun, 27 Sep 2009 20:47:24 +0000 Subject: Add Smarty's prefilter capability. see topic:16219 (FR). git-svn-id: http://piwigo.org/svn/trunk@3927 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/template.class.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/include/template.class.php b/include/template.class.php index be9aeda97..1d908c405 100644 --- a/include/template.class.php +++ b/include/template.class.php @@ -46,6 +46,9 @@ class Template { // Template extents filenames for each template handle. var $extents = array(); + // Templates prefilter from external sources (plugins) + var $external_filters = array(); + // used by html_head smarty block to add content before var $html_head_elements = array(); @@ -290,6 +293,8 @@ class Template { $this->smarty->assign( 'TAG_INPUT_ENABLED', ((is_adviser()) ? 'disabled="disabled" onclick="return false;"' : '')); + $this->load_external_filters(); + global $conf, $lang_info; if ( $conf['compiled_template_cache_language'] and isset($lang_info['code']) ) { @@ -333,6 +338,7 @@ class Template { } //else maybe error or warning ? $this->html_head_elements = array(); } + echo $this->output; $this->output=''; } @@ -419,6 +425,37 @@ class Template { } } + /** + * This function allows to declare a Smarty prefilter from a plugin, thus allowing + * it to modify template source before compilation and without changing core files + * They will be processed by weight ascending. + * http://www.smarty.net/manual/en/advanced.features.prefilters.php + */ + function set_external_filter($weight, $callback) + { + + if (! is_integer($weight)) return false; + $this->external_filters[$weight] = $callback; + return ksort($this->external_filters); + } + + /** + * This function actually triggers the filters on the tpl files. + * Called in the parse method. + * http://www.smarty.net/manual/en/advanced.features.prefilters.php + */ + function load_external_filters() + { + if (! isset($this->external_filters) || ! count($this->external_filters)) return; + print_r($this->external_filters ); + $test= array(1,2,3); + print_r($test); + foreach ($this->external_filters as $filter) + { + $this->smarty->register_prefilter( $filter ); + } + } + static function prefilter_white_space($source, &$smarty) { $ld = $smarty->left_delimiter; @@ -465,6 +502,7 @@ class Template { } } + /** * This class contains basic functions that can be called directly from the * templates in the form $pwg->l10n('edit') -- cgit v1.2.3