aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2008-09-09 09:53:31 +0000
committerrvelices <rv-github@modusoptimus.com>2008-09-09 09:53:31 +0000
commit9aec2fb5e728a37026adc0d5246e1cfe7d226cb9 (patch)
tree61cd3a69456a91747317de8db797db56e01157f7 /include
parent26474d349f6f03b3f74beb91ef680f0c634e05d5 (diff)
- 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
Diffstat (limited to 'include')
-rw-r--r--include/template.class.php32
1 files changed, 32 insertions, 0 deletions
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 = '<script type="text/javascript" src="'.$params['src'].'"></script>';
+ 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;