aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormathiasm <mathiasm@piwigo.org>2009-09-27 20:47:24 +0000
committermathiasm <mathiasm@piwigo.org>2009-09-27 20:47:24 +0000
commite6363de6fd7cd1791991a6dbaeae43849e907423 (patch)
treeeb21a5dcec90d016f509f175e04fa35fa5af3d1b
parent1c8a47a61f6185975827320669487573b693d9a2 (diff)
Add Smarty's prefilter capability. see topic:16219 (FR).
git-svn-id: http://piwigo.org/svn/trunk@3927 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--include/template.class.php38
1 files changed, 38 insertions, 0 deletions
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 </head>
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')