From 9aec2fb5e728a37026adc0d5246e1cfe7d226cb9 Mon Sep 17 00:00:00 2001 From: rvelices Date: Tue, 9 Sep 2008 09:53:31 +0000 Subject: - fix typing error in index.tpl - added template smarty function known_script (e.g.{known_script id="x" src"y.js"}) - useful to avoid double inclusion of a script such as prototype,jquery,... when a template and plugin need it independently (see the use in admin.tpl for example) - removed unused themeconf.template_dir git-svn-id: http://piwigo.org/svn/trunk@2513 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/template.class.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'include/template.class.php') diff --git a/include/template.class.php b/include/template.class.php index 7b4e4caf1..25389b8fa 100644 --- a/include/template.class.php +++ b/include/template.class.php @@ -62,6 +62,7 @@ class Template { $this->smarty->register_modifier( 'translate', array('Template', 'mod_translate') ); $this->smarty->register_modifier( 'explode', array('Template', 'mod_explode') ); $this->smarty->register_block('html_head', array(&$this, 'block_html_head') ); + $this->smarty->register_function('known_script', array(&$this, 'func_known_script'), false ); $this->smarty->register_prefilter( array('Template', 'prefilter_white_space') ); if ( $conf['compiled_template_cache_language'] ) { @@ -339,6 +340,37 @@ class Template { } } + /** + * This smarty "known_script" functions allows to insert well known java scripts + * such as prototype, jquery, etc... only once. Examples: + * {known_script id="jquery" src="{$ROOT_URL}template-common/lib/jquery.packed.js"} + */ + function func_known_script($params, &$smarty ) + { + if (!isset($params['id'])) + { + $smarty->trigger_error("known_script: missing 'id' parameter"); + return; + } + $id = $params['id']; + if (! isset( $this->known_scripts[$id] ) ) + { + if (!isset($params['src'])) + { + $smarty->trigger_error("known_script: missing 'src' parameter"); + return; + } + $this->known_scripts[$id] = $params['src']; + $content = ''; + if (isset($params['now']) and $params['now'] and empty($this->output) ) + { + return $content; + } + $repeat = false; + $this->block_html_head(null, $content, $smarty, $repeat); + } + } + /*static */ function prefilter_white_space($source, &$smarty) { $ld = $smarty->left_delimiter; -- cgit v1.2.3