summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2015-05-08 20:36:20 +0200
committerAndreas Gohr <andi@splitbrain.org>2015-05-08 20:36:20 +0200
commite8f68fc7c6be6e98e6bcd80303e3ebb17984c3c5 (patch)
tree611470a6d087781eefa59f359b2d6bda339fdf2c /lib
parentcffb4528cea1b9e7e03dc724aaa9719dbd6e23c9 (diff)
parente283bd6c307c6538f4d5447a938266b5e414c159 (diff)
downloadrpg-e8f68fc7c6be6e98e6bcd80303e3ebb17984c3c5.tar.gz
rpg-e8f68fc7c6be6e98e6bcd80303e3ebb17984c3c5.tar.bz2
Merge pull request #1130 from splitbrain/cache-js-per-tpl
Cache JavaScript per template
Diffstat (limited to 'lib')
-rw-r--r--lib/exe/js.php26
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/exe/js.php b/lib/exe/js.php
index 06d0dda55..2df2d0ba6 100644
--- a/lib/exe/js.php
+++ b/lib/exe/js.php
@@ -30,9 +30,14 @@ function js_out(){
global $conf;
global $lang;
global $config_cascade;
+ global $INPUT;
+
+ // decide from where to get the template
+ $tpl = trim(preg_replace('/[^\w-]+/','',$INPUT->str('t')));
+ if(!$tpl) $tpl = $conf['template'];
// The generated script depends on some dynamic options
- $cache = new cache('scripts'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'],'.js');
+ $cache = new cache('scripts'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tpl,'.js');
$cache->_event = 'JS_CACHE_USE';
// load minified version for some files
@@ -67,7 +72,7 @@ function js_out(){
# disabled for FS#1958 DOKU_INC.'lib/scripts/hotkeys.js',
DOKU_INC.'lib/scripts/behaviour.js',
DOKU_INC.'lib/scripts/page.js',
- tpl_incdir().'script.js',
+ tpl_incdir($tpl).'script.js',
);
// add possible plugin scripts and userscript
@@ -92,7 +97,7 @@ function js_out(){
$json = new JSON();
// add some global variables
print "var DOKU_BASE = '".DOKU_BASE."';";
- print "var DOKU_TPL = '".tpl_basedir()."';";
+ print "var DOKU_TPL = '".tpl_basedir($tpl)."';";
print "var DOKU_COOKIE_PARAM = " . $json->encode(
array(
'path' => empty($conf['cookiedir']) ? DOKU_REL : $conf['cookiedir'],
@@ -104,7 +109,7 @@ function js_out(){
// load JS specific translations
$lang['js']['plugins'] = js_pluginstrings();
- $templatestrings = js_templatestrings();
+ $templatestrings = js_templatestrings($tpl);
if(!empty($templatestrings)) {
$lang['js']['template'] = $templatestrings;
}
@@ -240,19 +245,20 @@ function js_pluginstrings() {
* - $lang['js'] must be an array.
* - Nothing is returned for template without an entry for $lang['js']
*
+ * @param string $tpl
* @return array
*/
-function js_templatestrings() {
+function js_templatestrings($tpl) {
global $conf;
$templatestrings = array();
- if (file_exists(tpl_incdir()."lang/en/lang.php")) {
- include tpl_incdir()."lang/en/lang.php";
+ if (file_exists(tpl_incdir($tpl)."lang/en/lang.php")) {
+ include tpl_incdir($tpl)."lang/en/lang.php";
}
- if (isset($conf['lang']) && $conf['lang']!='en' && file_exists(tpl_incdir()."lang/".$conf['lang']."/lang.php")) {
- include tpl_incdir()."lang/".$conf['lang']."/lang.php";
+ if (isset($conf['lang']) && $conf['lang']!='en' && file_exists(tpl_incdir($tpl)."lang/".$conf['lang']."/lang.php")) {
+ include tpl_incdir($tpl)."lang/".$conf['lang']."/lang.php";
}
if (isset($lang['js'])) {
- $templatestrings[$conf['template']] = $lang['js'];
+ $templatestrings[$tpl] = $lang['js'];
}
return $templatestrings;
}