summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnika Henke <anika@selfthinker.org>2015-05-04 19:30:30 +0100
committerAnika Henke <anika@selfthinker.org>2015-05-04 19:30:30 +0100
commit5fc6f52e0a12f737afab24869c01076585fdcc69 (patch)
tree3c9df93f4836260d7d6263eebdeb3279e7a5e052
parentdfe7cc3f3bfbfccec6a38a94ac0f2242e8bc59e7 (diff)
downloadrpg-5fc6f52e0a12f737afab24869c01076585fdcc69.tar.gz
rpg-5fc6f52e0a12f737afab24869c01076585fdcc69.tar.bz2
cache JavaScript per template
-rw-r--r--inc/template.php2
-rw-r--r--lib/exe/js.php26
2 files changed, 17 insertions, 11 deletions
diff --git a/inc/template.php b/inc/template.php
index 88b6b14b8..d6436e416 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -417,7 +417,7 @@ function tpl_metaheaders($alt = true) {
// load external javascript
$head['script'][] = array(
'type'=> 'text/javascript', 'charset'=> 'utf-8', '_data'=> '',
- 'src' => DOKU_BASE.'lib/exe/js.php'.'?tseed='.$tseed
+ 'src' => DOKU_BASE.'lib/exe/js.php'.'?t='.$conf['template'].'&tseed='.$tseed
);
// trigger event here
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;
}