From 253d4b48ec708eb42033862dc15c8576f44a48ed Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 1 Oct 2014 15:32:05 +0200 Subject: more PHPDocs, unused var, small bit code reformatting --- lib/exe/js.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/exe/js.php') diff --git a/lib/exe/js.php b/lib/exe/js.php index bec12ef7a..97f2b52c3 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -154,6 +154,8 @@ function js_out(){ * Load the given file, handle include calls and print it * * @author Andreas Gohr + * + * @param string $file filename path to file */ function js_load($file){ if(!@file_exists($file)) return; @@ -189,6 +191,8 @@ function js_load($file){ * Returns a list of possible Plugin Scripts (no existance check here) * * @author Andreas Gohr + * + * @return array */ function js_pluginscripts(){ $list = array(); @@ -206,6 +210,8 @@ function js_pluginscripts(){ * - Nothing is returned for plugins without an entry for $lang['js'] * * @author Gabriel Birke + * + * @return array */ function js_pluginstrings() { global $conf; @@ -231,6 +237,8 @@ function js_pluginstrings() { * * - $lang['js'] must be an array. * - Nothing is returned for template without an entry for $lang['js'] + * + * @return array */ function js_templatestrings() { global $conf; @@ -252,6 +260,9 @@ function js_templatestrings() { * as newline * * @author Andreas Gohr + * + * @param string $string + * @return string */ function js_escape($string){ return str_replace('\\\\n','\\n',addslashes($string)); @@ -261,6 +272,8 @@ function js_escape($string){ * Adds the given JavaScript code to the window.onload() event * * @author Andreas Gohr + * + * @param string $func */ function js_runonstart($func){ echo "jQuery(function(){ $func; });".NL; @@ -275,6 +288,9 @@ function js_runonstart($func){ * @author Nick Galbreath * @author Andreas Gohr * @link http://code.google.com/p/jsstrip/ + * + * @param string $s + * @return string */ function js_compress($s){ $s = ltrim($s); // strip all initial whitespace -- cgit v1.2.3 From 70daee86e69783928d3da887a3a3e26b8ab74734 Mon Sep 17 00:00:00 2001 From: LarsDW223 Date: Tue, 14 Oct 2014 16:12:08 +0200 Subject: Corrected compression for ++ and -- operator. Partially fixes #897. --- lib/exe/js.php | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'lib/exe/js.php') diff --git a/lib/exe/js.php b/lib/exe/js.php index bec12ef7a..2ab78dfc3 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -289,6 +289,10 @@ function js_compress($s){ // items that don't need spaces next to them $chars = "^&|!+\-*\/%=\?:;,{}()<>% \t\n\r'\"[]"; + // items which need a space if the sign before and after whitespace is equal. + // E.g. '+ ++' may not be compressed to '+++' --> syntax error. + $ops = "+-"; + $regex_starters = array("(", "=", "[", "," , ":", "!"); $whitespaces_chars = array(" ", "\t", "\n", "\r", "\0", "\x0B"); @@ -389,19 +393,27 @@ function js_compress($s){ // whitespaces if( $ch == ' ' || $ch == "\r" || $ch == "\n" || $ch == "\t" ){ - // leading spaces - if($i+1 < $slen && (strpos($chars,$s[$i+1]) !== false)){ - $i = $i + 1; - continue; - } - // trailing spaces - // if this ch is space AND the last char processed - // is special, then skip the space $lch = substr($result,-1); - if($lch && (strpos($chars,$lch) !== false)){ - $i = $i + 1; - continue; + + // Only consider deleting whitespace if the signs before and after + // are not equal and are not an operator which may not follow itself. + if ((!$lch || $s[$i+1] == ' ') + || $lch != $s[$i+1] + || strpos($ops,$s[$i+1]) === false) { + // leading spaces + if($i+1 < $slen && (strpos($chars,$s[$i+1]) !== false)){ + $i = $i + 1; + continue; + } + // trailing spaces + // if this ch is space AND the last char processed + // is special, then skip the space + if($lch && (strpos($chars,$lch) !== false)){ + $i = $i + 1; + continue; + } } + // else after all of this convert the "whitespace" to // a single space. It will get appended below $ch = ' '; -- cgit v1.2.3 From 5c5b52fd17bf855ab64656790b39ff43450902c9 Mon Sep 17 00:00:00 2001 From: LarsDW223 Date: Wed, 15 Oct 2014 10:48:15 +0200 Subject: Fixed JavaScript compression. The compressor did not recognize a regular expression after a '&&' ot '||' operator. So it could happen that code had been cut off if the regular expression included '\//' (which was treated as a single line comment because of the regular expression not being recognized). Finally fixes #897. --- lib/exe/js.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/exe/js.php') diff --git a/lib/exe/js.php b/lib/exe/js.php index 2ab78dfc3..545ba7b23 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -293,7 +293,7 @@ function js_compress($s){ // E.g. '+ ++' may not be compressed to '+++' --> syntax error. $ops = "+-"; - $regex_starters = array("(", "=", "[", "," , ":", "!"); + $regex_starters = array("(", "=", "[", "," , ":", "!", "&", "|"); $whitespaces_chars = array(" ", "\t", "\n", "\r", "\0", "\x0B"); -- cgit v1.2.3 From 7b909d5e68cfee08dd85a3f28a2bdc9d6f41aaff Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 10 Dec 2014 21:24:29 +0100 Subject: Extendable config cascade for userstyles and userscript Added user*.less files to config --- lib/exe/js.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/exe/js.php') diff --git a/lib/exe/js.php b/lib/exe/js.php index ec236e98f..793104e81 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -72,8 +72,10 @@ function js_out(){ // add possible plugin scripts and userscript $files = array_merge($files,js_pluginscripts()); - if(isset($config_cascade['userscript']['default'])){ - $files[] = $config_cascade['userscript']['default']; + if(!empty($config_cascade['userscript']['default'])) { + foreach($config_cascade['userscript']['default'] as $userscript) { + $files[] = $userscript; + } } $cache_files = array_merge($files, getConfigFiles('main')); -- cgit v1.2.3 From 79e79377626799a77c11aa7849cb9c64305590c8 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 7 Jan 2015 10:47:45 +0100 Subject: Remove error supression for file_exists() In an older version of PHP a file_exists() call would issue a warning when the file did not exist. This was fixed in later PHP releases. Since we require PHP 5.3 now, there's no need to supress any error here anymore. This might even give a minor performance boost. --- lib/exe/js.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/exe/js.php') diff --git a/lib/exe/js.php b/lib/exe/js.php index 793104e81..3f9781e34 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -160,7 +160,7 @@ function js_out(){ * @param string $file filename path to file */ function js_load($file){ - if(!@file_exists($file)) return; + if(!file_exists($file)) return; static $loaded = array(); $data = io_readFile($file); @@ -179,7 +179,7 @@ function js_load($file){ if($ifile{0} != '/') $ifile = dirname($file).'/'.$ifile; - if(@file_exists($ifile)){ + if(file_exists($ifile)){ $idata = io_readFile($ifile); }else{ $idata = ''; @@ -221,10 +221,10 @@ function js_pluginstrings() { $plugins = plugin_list(); foreach ($plugins as $p){ if (isset($lang)) unset($lang); - if (@file_exists(DOKU_PLUGIN."$p/lang/en/lang.php")) { + if (file_exists(DOKU_PLUGIN."$p/lang/en/lang.php")) { include DOKU_PLUGIN."$p/lang/en/lang.php"; } - if (isset($conf['lang']) && $conf['lang']!='en' && @file_exists(DOKU_PLUGIN."$p/lang/".$conf['lang']."/lang.php")) { + if (isset($conf['lang']) && $conf['lang']!='en' && file_exists(DOKU_PLUGIN."$p/lang/".$conf['lang']."/lang.php")) { include DOKU_PLUGIN."$p/lang/".$conf['lang']."/lang.php"; } if (isset($lang['js'])) { @@ -245,10 +245,10 @@ function js_pluginstrings() { function js_templatestrings() { global $conf; $templatestrings = array(); - if (@file_exists(tpl_incdir()."lang/en/lang.php")) { + if (file_exists(tpl_incdir()."lang/en/lang.php")) { include tpl_incdir()."lang/en/lang.php"; } - if (isset($conf['lang']) && $conf['lang']!='en' && @file_exists(tpl_incdir()."lang/".$conf['lang']."/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($lang['js'])) { -- cgit v1.2.3 From 138a9500555ab0f27ce3fd67d3ea3ab17f8e9e3b Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 3 Mar 2015 17:19:43 +0100 Subject: send JavaScript with correct mimetype While Browsers (IE of course) still fail to accept the correct application/javascript mimetype in the type attribute of the script element, we should serve the scripts with the correct Content-Type header at least. This is especially important as the default configuration of mod_deflate expects application/javascript and will not compress text/javascript. --- lib/exe/js.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/exe/js.php') diff --git a/lib/exe/js.php b/lib/exe/js.php index 3f9781e34..06d0dda55 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -14,7 +14,7 @@ require_once(DOKU_INC.'inc/init.php'); // Main (don't run when UNIT test) if(!defined('SIMPLE_TEST')){ - header('Content-Type: text/javascript; charset=utf-8'); + header('Content-Type: application/javascript; charset=utf-8'); js_out(); } -- cgit v1.2.3 From 5fc6f52e0a12f737afab24869c01076585fdcc69 Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Mon, 4 May 2015 19:30:30 +0100 Subject: cache JavaScript per template --- lib/exe/js.php | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'lib/exe/js.php') 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; } -- cgit v1.2.3 From 767d16693c9df38a2f496d4ca2ba8559db5eba5d Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 31 Jul 2015 10:00:09 +0200 Subject: removed deprecated JavaScript --- lib/exe/js.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lib/exe/js.php') diff --git a/lib/exe/js.php b/lib/exe/js.php index 2df2d0ba6..16d22daf2 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -56,11 +56,9 @@ function js_out(){ DOKU_INC.'lib/scripts/delay.js', DOKU_INC.'lib/scripts/cookie.js', DOKU_INC.'lib/scripts/script.js', - DOKU_INC.'lib/scripts/tw-sack.js', DOKU_INC.'lib/scripts/qsearch.js', DOKU_INC.'lib/scripts/tree.js', DOKU_INC.'lib/scripts/index.js', - DOKU_INC.'lib/scripts/drag.js', DOKU_INC.'lib/scripts/textselection.js', DOKU_INC.'lib/scripts/toolbar.js', DOKU_INC.'lib/scripts/edit.js', @@ -68,7 +66,7 @@ function js_out(){ DOKU_INC.'lib/scripts/locktimer.js', DOKU_INC.'lib/scripts/linkwiz.js', DOKU_INC.'lib/scripts/media.js', -# deprecated DOKU_INC.'lib/scripts/compatibility.js', + DOKU_INC.'lib/scripts/compatibility.js', # disabled for FS#1958 DOKU_INC.'lib/scripts/hotkeys.js', DOKU_INC.'lib/scripts/behaviour.js', DOKU_INC.'lib/scripts/page.js', -- cgit v1.2.3