diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/exe/css.php | 165 | ||||
-rw-r--r-- | lib/exe/js.php (renamed from lib/exe/jscss.php) | 80 | ||||
-rw-r--r-- | lib/scripts/script.js | 50 | ||||
-rw-r--r-- | lib/tpl/default/detail.php | 10 | ||||
-rw-r--r-- | lib/tpl/default/main.php | 16 | ||||
-rw-r--r-- | lib/tpl/default/media.php | 11 | ||||
-rw-r--r-- | lib/tpl/default/mediaedit.php | 2 | ||||
-rw-r--r-- | lib/tpl/default/mediaref.php | 11 |
8 files changed, 254 insertions, 91 deletions
diff --git a/lib/exe/css.php b/lib/exe/css.php new file mode 100644 index 000000000..7b6523b41 --- /dev/null +++ b/lib/exe/css.php @@ -0,0 +1,165 @@ +<?php +/** + * DokuWiki StyleSheet creator + * + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author Andreas Gohr <andi@splitbrain.org> + */ + +if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); +define('NOSESSION',true); // we do not use a session or authentication here (better caching) +require_once(DOKU_INC.'inc/init.php'); +require_once(DOKU_INC.'inc/pageutils.php'); +require_once(DOKU_INC.'inc/io.php'); + +// Main (don't run when UNIT test) +if(!defined('SIMPLE_TEST')){ + header('Content-Type: text/css; charset=utf-8'); + css_out(); +} + + +// ---------------------- functions ------------------------------ + +/** + * Output all needed Styles + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function css_out(){ + global $conf; + global $lang; + $print = (bool) $_REQUEST['print']; //print mode? + + // The generated script depends on some dynamic options + $cache = getCacheName('styles'.$print,'.css'); + + // Array of needed files and their web locations, the latter ones + // are needed to fix relative paths in the stylesheets + $files = array(); + if($print){ + $files[DOKU_TPLINC.'print.css'] = DOKU_TPL; + // load plugin styles + $files = array_merge($files, css_pluginstyles('print')); + $files[DOKU_CONF.'userprint.css'] = ''; + }else{ + $files[DOKU_INC.'lib/styles/style.css'] = DOKU_BASE.'lib/styles/'; + //fixme spellchecker style + $files[DOKU_TPLINC.'layout.css'] = DOKU_TPL; + $files[DOKU_TPLINC.'design.css'] = DOKU_TPL; + if($lang['direction'] == 'rtl'){ + $files[DOKU_TPLINC.'rtl.css'] = DOKU_TPL; + } + // load plugin styles + $files = array_merge($files, css_pluginstyles('screen')); + $files[DOKU_CONF.'userstyle.css'] = ''; + } + + // check cache age + if(css_cacheok($cache,array_keys($files))){ + readfile($cache); + return; + } + + // start output buffering and build the stylesheet + ob_start(); + + // load files + foreach($files as $file => $location){ + print css_loadfile($file, $location); + } + + // end output buffering and get contents + $css = ob_get_contents(); + ob_end_clean(); + + // compress whitespace and comments + if($conf['compress']){ + $css = css_compress($css); + } + + // save cache file + io_saveFile($cache,$css); + + // finally send output + print $css; +} + +/** + * Checks if a CSS Cache file still is valid + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function css_cacheok($cache,$files){ + $ctime = @filemtime($cache); + if(!$ctime) return false; //There is no cache + + // some additional files to check + $files[] = DOKU_CONF.'dokuwiki.conf'; + $files[] = DOKU_CONF.'local.conf'; + $files[] = __FILE__; + + // now walk the files + foreach($files as $file){ + if(@filemtime($file) > $ctime){ + return false; + } + } + return true; +} + +/** + * Loads a given file and fixes relative URLs with the + * given location prefix + */ +function css_loadfile($file,$location=''){ + if(!@file_exists($file)) return ''; + $css = io_readFile($file); + if(!$location) return $css; + + $css = preg_replace('!(url\( *)([^/])!','\\1'.$location.'\\2',$css); + return $css; +} + +/** + * Returns a list of possible Plugin Styles (no existance check here) + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function css_pluginstyles($mode='screen'){ + $list = array(); + $plugins = plugin_list(); + foreach ($plugins as $p){ + if($mode == 'print'){ + $list[DOKU_PLUGIN."$p/print.css"] = DOKU_BASE."lib/plugins/$p/"; + }else{ + $list[DOKU_PLUGIN."$p/style.css"] = DOKU_BASE."lib/plugins/$p/"; + $list[DOKU_PLUGIN."$p/screen.css"] = DOKU_BASE."lib/plugins/$p/"; + } + } + return $list; +} + +/** + * Very simple CSS optimizer + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function css_compress($css){ + // strip whitespaces + $css = preg_replace('![\r\n\t ]+!',' ',$css); + $css = preg_replace('/ ?([:;,{}]) ?/','\\1',$css); + + // strip comments (ungreedy) + // We keep very small comments to maintain typical browser hacks + $css = preg_replace('!(/\*)(.{4,})(\*/)!U','',$css); + + // shorten colors + $css = preg_replace("/#([0-9a-fA-F]{1})\\1([0-9a-fA-F]{1})\\2([0-9a-fA-F]{1})\\3/", "#\\1\\2\\3",$css); + + return $css; +} + + +//Setup VIM: ex: et ts=4 enc=utf-8 : +?> diff --git a/lib/exe/jscss.php b/lib/exe/js.php index 33d67eece..9708dbc0d 100644 --- a/lib/exe/jscss.php +++ b/lib/exe/js.php @@ -1,6 +1,6 @@ <?php /** - * DokuWiki JavaScript and CSS creator + * DokuWiki JavaScript creator * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Andreas Gohr <andi@splitbrain.org> @@ -14,12 +14,9 @@ require_once(DOKU_INC.'inc/io.php'); // Main (don't run when UNIT test) if(!defined('SIMPLE_TEST')){ - if($_REQUEST['type'] == 'css'){ - css_out(); - }else{ - header('Content-Type: text/javascript; charset=utf-8'); - js_out(); - } + header('Content-Type: text/javascript; charset=utf-8'); + js_out(); + js_dynamicout(); } @@ -28,7 +25,6 @@ if(!defined('SIMPLE_TEST')){ /** * Output all needed JavaScript * - * @todo Add Whitespace and Comment Compression * @author Andreas Gohr <andi@splitbrain.org> */ function js_out(){ @@ -38,7 +34,7 @@ function js_out(){ $write = (bool) $_REQUEST['write']; // writable? // The generated script depends on some dynamic options - $cache = getCacheName($conf['lang'].$edit.$write,$ext='.js'); + $cache = getCacheName('scripts'.$edit.$write,'.js'); // Array of needed files $files = array( @@ -56,10 +52,11 @@ function js_out(){ } } - // FIXME load plugin scripts + // get possible plugin scripts + $plugins = js_pluginscripts(); // check cache age here - if(js_cacheok($cache,$files)){ + if(js_cacheok($cache,array_merge($files,$plugins))){ readfile($cache); return; } @@ -109,18 +106,22 @@ function js_out(){ } } + // load plugin scripts (suppress warnings for missing ones) + foreach($plugins as $plugin){ + @readfile($plugin); + } // load user script - if(@file_exists(DOKU_INC.'conf/userscript.js')){ - readfile(DOKU_INC.'conf/userscript.js'); - } + @readfile(DOKU_CONF.'userscript.js'); // end output buffering and get contents $js = ob_get_contents(); ob_end_clean(); // compress whitespace and comments - $js = js_compress($js); + if($conf['compress']){ + $js = js_compress($js); + } // save cache file io_saveFile($cache,$js); @@ -130,6 +131,21 @@ function js_out(){ } /** + * Adds some dynamic JavaScript using the readonly Session + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function js_dynamicout(){ + $edit = (bool) $_REQUEST['edit']; // edit or preview mode? + $write = (bool) $_REQUEST['write']; // writable? + $sig = (bool) $_REQUEST['sig']; // show sig button? + if($edit && $write && $sig){ + require_once(DOKU_INC.'inc/toolbar.php'); + toolbar_addsigbutton('toolbar'); + } +} + +/** * Checks if a JavaScript Cache file still is valid * * @author Andreas Gohr <andi@splitbrain.org> @@ -139,9 +155,10 @@ function js_cacheok($cache,$files){ if(!$ctime) return false; //There is no cache // some additional files to check - $files[] = DOKU_INC.'conf/dokuwiki.conf'; - $files[] = DOKU_INC.'conf/local.conf'; - $files[] = DOKU_INC.'conf/userscript.js'; + $files[] = DOKU_CONF.'dokuwiki.conf'; + $files[] = DOKU_CONF.'local.conf'; + $files[] = DOKU_CONF.'userscript.js'; + $files[] = __FILE__; // now walk the files foreach($files as $file){ @@ -153,6 +170,20 @@ function js_cacheok($cache,$files){ } /** + * Returns a list of possible Plugin Scripts (no existance check here) + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function js_pluginscripts(){ + $list = array(); + $plugins = plugin_list(); + foreach ($plugins as $p){ + $list[] = DOKU_PLUGIN."$p/script.js"; + } + return $list; +} + +/** * Escapes a String to be embedded in a JavaScript call, keeps \n * as newline * @@ -171,7 +202,16 @@ function js_runonstart($func){ print "addEvent(window,'load',function(){ $func; });"; } -//http://modp.com/release/jsstrip/jsstrip.py +/** + * Strip comments and whitespaces from given JavaScript Code + * + * This is a rewrite of Nick Galbreaths python tool jsstrip.py which is + * released under BSD license. See link for original code. + * + * @author Nick Galbreath <nickg@modp.com> + * @author Andreas Gohr <andi@splitbrain.org> + * @link http://modp.com/release/jsstrip/ + */ function js_compress($s){ $i = 0; $line = 0; @@ -287,7 +327,5 @@ function js_compress($s){ return $out; } -//http://csstidy.sourceforge.net/download.php - //Setup VIM: ex: et ts=4 enc=utf-8 : ?> diff --git a/lib/scripts/script.js b/lib/scripts/script.js index 180f2dcd5..b91859265 100644 --- a/lib/scripts/script.js +++ b/lib/scripts/script.js @@ -6,8 +6,8 @@ * Some browser detection */ var clientPC = navigator.userAgent.toLowerCase(); // Get client info -var is_gecko = ((clientPC.indexOf('gecko')!=-1) && (clientPC.indexOf('spoofer')==-1) - && (clientPC.indexOf('khtml') == -1) && (clientPC.indexOf('netscape/7.0')==-1)); +var is_gecko = ((clientPC.indexOf('gecko')!=-1) && (clientPC.indexOf('spoofer')==-1) && + (clientPC.indexOf('khtml') == -1) && (clientPC.indexOf('netscape/7.0')==-1)); var is_safari = ((clientPC.indexOf('AppleWebKit')!=-1) && (clientPC.indexOf('spoofer')==-1)); var is_khtml = (navigator.vendor == 'KDE' || ( document.childNodes && !document.all && !navigator.taintEnabled )); if (clientPC.indexOf('opera')!=-1) { @@ -23,10 +23,11 @@ if (clientPC.indexOf('opera')!=-1) { */ function findPosX(object){ var curleft = 0; + var obj; if(typeof(object) == 'object'){ - var obj = object; + obj = object; }else{ - var obj = document.getElementById(object); + obj = document.getElementById(object); } if (obj.offsetParent){ while (obj.offsetParent){ @@ -47,10 +48,11 @@ function findPosX(object){ */ function findPosY(object){ var curtop = 0; + var obj; if(typeof(object) == 'object'){ - var obj = object; + obj = object; }else{ - var obj = document.getElementById(object); + obj = document.getElementById(object); } if (obj.offsetParent){ while (obj.offsetParent){ @@ -72,7 +74,7 @@ function findPosY(object){ function jsEscape(text){ var re=new RegExp("\\\\","g"); text=text.replace(re,"\\\\"); - var re=new RegExp("'","g"); + re=new RegExp("'","g"); text=text.replace(re,"\\'"); re=new RegExp('"',"g"); text=text.replace(re,'"'); @@ -150,8 +152,8 @@ function showTocToggle(showtxt,hidetxt) { document.writeln('<div class=\'toctoggle\'><a href="javascript:toggleToc()" class="toc">' + '<span id="showlink" style="display:none;">' + show + '</span>' + - '<span id="hidelink">' + hide + '</span>' - + '</a></div>'); + '<span id="hidelink">' + hide + '</span>' + + '</a></div>'); } } @@ -200,12 +202,14 @@ function getCookie(name) { var begin = dc.indexOf("; " + prefix); if (begin == -1) { begin = dc.indexOf(prefix); - if (begin != 0) return null; - } else + if (begin !== 0){ return null; } + } else { begin += 2; + } var end = document.cookie.indexOf(";", begin); - if (end == -1) + if (end == -1){ end = dc.length; + } return unescape(dc.substring(begin + prefix.length, end)); } @@ -217,8 +221,9 @@ function getCookie(name) { function fixDate(date) { var base = new Date(0); var skew = base.getTime(); - if (skew > 0) + if (skew > 0){ date.setTime(date.getTime() - skew); + } } /* @@ -258,16 +263,17 @@ function fnt(id, e, evt) { } // does the footnote tooltip already exist? - var fnt = document.getElementById('insitu-fn'+id); - if (!fnt) { + var fnote = document.getElementById('insitu-fn'+id); + var footnote; + if (!fnote) { // if not create it... // locate the footnote anchor element var a = document.getElementById( "fn"+id ); - if (!a) return; + if (!a){ return; } // anchor parent is the footnote container, get its innerHTML - var footnote = new String (a.parentNode.innerHTML); + footnote = new String (a.parentNode.innerHTML); // strip the leading footnote anchors and their comma separators footnote = footnote.replace(/<a\s.*?href=\".*\#fnt\d+\".*?<\/a>/gi, ''); @@ -276,7 +282,7 @@ function fnt(id, e, evt) { // prefix ids on any elements with "insitu-" to ensure they remain unique footnote = footnote.replace(/\bid=\"(.*?)\"/gi,'id="insitu-$1'); } else { - var footnote = new String(fnt.innerHTML); + footnote = new String(fnt.innerHTML); } // activate the tooltip @@ -289,13 +295,13 @@ function fnt(id, e, evt) { * Add the edit window size controls */ function initSizeCtl(ctlid,edid){ - if(!document.getElementById) return; + if(!document.getElementById){ return; } var ctl = document.getElementById(ctlid); var textarea = document.getElementById(edid); var hgt = getCookie('DokuWikisizeCtl'); - if(hgt == null){ + if(hgt === null || hgt === ''){ textarea.style.height = '300px'; }else{ textarea.style.height = hgt; @@ -319,7 +325,7 @@ function sizeCtl(edid,val){ var height = parseInt(textarea.style.height.substr(0,textarea.style.height.length-2)); height += val; textarea.style.height = height+'px'; - + var now = new Date(); fixDate(now); now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); //expire in a year @@ -330,7 +336,7 @@ function sizeCtl(edid,val){ * Handler to close all open Popups */ function closePopups(){ - if(!document.getElementById) return; + if(!document.getElementById){ return; } var divs = document.getElementsByTagName('div'); for(var i=0; i < divs.length; i++){ diff --git a/lib/tpl/default/detail.php b/lib/tpl/default/detail.php index 70865c933..5a59e0305 100644 --- a/lib/tpl/default/detail.php +++ b/lib/tpl/default/detail.php @@ -24,16 +24,6 @@ <?php tpl_metaheaders()?> <link rel="shortcut icon" href="<?php echo DOKU_BASE?>lib/images/favicon.ico" /> - <link rel="stylesheet" media="screen" type="text/css" href="<?php echo DOKU_TPL?>layout.css" /> - <link rel="stylesheet" media="screen" type="text/css" href="<?php echo DOKU_TPL?>design.css" /> - - <!--[if gte IE 5]> - <style type="text/css"> - /* that IE 5+ conditional comment makes this only visible in IE 5+ */ - /* IE bugfix for transparent PNGs */ - //DISABLED img { behavior: url("<?php echo DOKU_BASE?>lib/scripts/pngbehavior.htc"); } - </style> - <![endif]--> </head> <body> diff --git a/lib/tpl/default/main.php b/lib/tpl/default/main.php index afa0b5534..bb32def6b 100644 --- a/lib/tpl/default/main.php +++ b/lib/tpl/default/main.php @@ -23,22 +23,6 @@ <?php tpl_metaheaders()?> <link rel="shortcut icon" href="<?php echo DOKU_BASE?>lib/images/favicon.ico" /> - <link rel="stylesheet" media="screen" type="text/css" href="<?php echo DOKU_TPL?>layout.css" /> - <link rel="stylesheet" media="screen" type="text/css" href="<?php echo DOKU_TPL?>design.css" /> - - <?php if($lang['direction'] == 'rtl') {?> - <link rel="stylesheet" media="screen" type="text/css" href="<?php echo DOKU_TPL?>rtl.css" /> - <?php } ?> - - <link rel="stylesheet" media="print" type="text/css" href="<?php echo DOKU_TPL?>print.css" /> - - <!--[if gte IE 5]> - <style type="text/css"> - /* that IE 5+ conditional comment makes this only visible in IE 5+ */ - /* IE bugfix for transparent PNGs */ - //DISABLED img { behavior: url("<?php echo DOKU_BASE?>lib/scripts/pngbehavior.htc"); } - </style> - <![endif]--> <?php /*old includehook*/ @include(dirname(__FILE__).'/meta.html')?> </head> diff --git a/lib/tpl/default/media.php b/lib/tpl/default/media.php index f6fb66750..b3738e39a 100644 --- a/lib/tpl/default/media.php +++ b/lib/tpl/default/media.php @@ -21,16 +21,7 @@ <?php tpl_metaheaders()?> <link rel="shortcut icon" href="<?php echo DOKU_BASE?>lib/images/favicon.ico" /> - <link rel="stylesheet" media="screen" type="text/css" href="<?php echo DOKU_TPL?>layout.css" /> - <link rel="stylesheet" media="screen" type="text/css" href="<?php echo DOKU_TPL?>design.css" /> - - <!--[if gte IE 5]> - <style type="text/css"> - /* that IE 5+ conditional comment makes this only visible in IE 5+ */ - /* IE bugfix for transparent PNGs */ - //DISABLED img { behavior: url("<?php echo DOKU_BASE?>lib/scripts/pngbehavior.htc"); } - </style> - <![endif]--> + </head> <body> diff --git a/lib/tpl/default/mediaedit.php b/lib/tpl/default/mediaedit.php index c7b7e2e53..92d1db8db 100644 --- a/lib/tpl/default/mediaedit.php +++ b/lib/tpl/default/mediaedit.php @@ -22,8 +22,6 @@ <?php tpl_metaheaders()?> <link rel="shortcut icon" href="<?php echo DOKU_BASE?>images/favicon.ico" /> - <link rel="stylesheet" media="screen" type="text/css" href="<?php echo DOKU_TPL?>layout.css" /> - <link rel="stylesheet" media="screen" type="text/css" href="<?php echo DOKU_TPL?>design.css" /> </head> <body> diff --git a/lib/tpl/default/mediaref.php b/lib/tpl/default/mediaref.php index 61254c9ce..47752a571 100644 --- a/lib/tpl/default/mediaref.php +++ b/lib/tpl/default/mediaref.php @@ -22,16 +22,7 @@ <?php tpl_metaheaders()?> <link rel="shortcut icon" href="<?php echo DOKU_BASE?>images/favicon.ico" /> - <link rel="stylesheet" media="screen" type="text/css" href="<?php echo DOKU_TPL?>layout.css" /> - <link rel="stylesheet" media="screen" type="text/css" href="<?php echo DOKU_TPL?>design.css" /> - - <!--[if gte IE 5]> - <style type="text/css"> - /* that IE 5+ conditional comment makes this only visible in IE 5+ */ - /* IE bugfix for transparent PNGs */ - //img { behavior: url("<?php echo DOKU_BASE?>/pngbehavior.htc"); } - </style> - <![endif]--> + </head> <body> |