From 809d3ba53bea8b34155cb8d009d7fa4b8a7bbdaf Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 17 Jun 2011 00:20:48 +0200 Subject: Use data uris for small image files in CSS This patch adds a new config option 'cssdatauri'. When enabled, the CSS patcher will automatically convert all occurances of small (<600 byte) PNG and GIF images in the CSS to embedded, base64 encoded data uris. This reduces the number of needed HTTP requests and avoids the HTTP header overhead. --- lib/exe/css.php | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'lib/exe') diff --git a/lib/exe/css.php b/lib/exe/css.php index e4105b427..02ed169c4 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -135,6 +135,12 @@ function css_out(){ $css = css_compress($css); } + // embed small images right into the stylesheet + if($conf['cssdatauri']){ + $base = preg_quote(DOKU_BASE,'#'); + $css = preg_replace_callback('#(url\([ \'"]*)('.$base.')(.*?(?:\.(png|gif)))#i','css_datauri',$css); + } + // save cache file io_saveFile($cache,$css); if(function_exists('gzopen')) io_saveFile("$cache.gz",$css); @@ -271,11 +277,36 @@ function css_loadfile($file,$location=''){ $css = io_readFile($file); if(!$location) return $css; - $css = preg_replace('#(url\([ \'"]*)(?!/|http://|https://| |\'|")#','\\1'.$location,$css); - $css = preg_replace('#(@import\s+[\'"])(?!/|http://|https://)#', '\\1'.$location, $css); + $css = preg_replace('#(url\([ \'"]*)(?!/|data:|http://|https://| |\'|")#','\\1'.$location,$css); + $css = preg_replace('#(@import\s+[\'"])(?!/|data:|http://|https://)#', '\\1'.$location, $css); + return $css; } +/** + * Converte local image URLs to data URLs if the filesize is small + * + * Callback for preg_replace_callback + */ +function css_datauri($match){ + $pre = unslash($match[1]); + $base = unslash($match[2]); + $url = unslash($match[3]); + $ext = unslash($match[4]); + + $local = DOKU_INC.$url; + $size = @filesize($local); + if($size && $size < 600){ + $data = base64_encode(file_get_contents($local)); + } + if($data){ + $url = 'data:image/'.$ext.';base64,'.$data; + }else{ + $url = $base.$url; + } + return $pre.$url; +} + /** * Returns a list of possible Plugin Styles (no existance check here) -- cgit v1.2.3 From 28f4004c937cfc11f16e6cc7c0eb7da1a61dfcbe Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 18 Jun 2011 10:16:47 +0200 Subject: Made the maximum embed size for datauris configurable The feature is now disabled by default. Metadata for config manager was added. --- lib/exe/css.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/exe') diff --git a/lib/exe/css.php b/lib/exe/css.php index 02ed169c4..92d198e19 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -289,6 +289,8 @@ function css_loadfile($file,$location=''){ * Callback for preg_replace_callback */ function css_datauri($match){ + global $conf; + $pre = unslash($match[1]); $base = unslash($match[2]); $url = unslash($match[3]); @@ -296,7 +298,7 @@ function css_datauri($match){ $local = DOKU_INC.$url; $size = @filesize($local); - if($size && $size < 600){ + if($size && $size < $conf['cssdatauri']){ $data = base64_encode(file_get_contents($local)); } if($data){ -- cgit v1.2.3 From 6619f42eb475ad91a0b73d1aa6268ff41c6129a2 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Fri, 1 Jul 2011 16:49:28 +0200 Subject: Refactor CSS and JS caching * Increase HTTP cache time since the resources are timestamped on request anyway * Check userscript.js only once for JS cache validation * Use cache class --- lib/exe/css.php | 68 ++++++++------------------------------------------------- lib/exe/js.php | 67 ++++++++------------------------------------------------ 2 files changed, 18 insertions(+), 117 deletions(-) (limited to 'lib/exe') diff --git a/lib/exe/css.php b/lib/exe/css.php index e4105b427..9751b5be4 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -46,7 +46,7 @@ function css_out(){ } // The generated script depends on some dynamic options - $cache = getCacheName('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tplinc.$mediatype,'.css'); + $cache = new cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tplinc.$mediatype,'.css'); // load template styles $tplstyles = array(); @@ -87,26 +87,14 @@ function css_out(){ } } - // check cache age & handle conditional request - header('Cache-Control: public, max-age=3600'); - header('Pragma: public'); - if(css_cacheok($cache,array_keys($files),$tplinc)){ - http_conditionalRequest(filemtime($cache)); - if($conf['allowdebug']) header("X-CacheUsed: $cache"); - - // finally send output - if ($conf['gzip_output'] && http_gzip_valid($cache)) { - header('Vary: Accept-Encoding'); - header('Content-Encoding: gzip'); - readfile($cache.".gz"); - } else { - if (!http_sendfile($cache)) readfile($cache); - } + $cache_files = array_merge(array_keys($files), getConfigFiles('main')); + $cache_files[] = $tplinc.'style.ini'; + $cache_files[] = __FILE__; - return; - } else { - http_conditionalRequest(time()); - } + // check cache age & handle conditional request + // This may exit if a cache can be used + http_cached($cache->cache, + $cache->useCache(array('files' => $cache_files))); // start output buffering and build the stylesheet ob_start(); @@ -135,45 +123,7 @@ function css_out(){ $css = css_compress($css); } - // save cache file - io_saveFile($cache,$css); - if(function_exists('gzopen')) io_saveFile("$cache.gz",$css); - - // finally send output - if ($conf['gzip_output']) { - header('Vary: Accept-Encoding'); - header('Content-Encoding: gzip'); - print gzencode($css,9,FORCE_GZIP); - } else { - print $css; - } -} - -/** - * Checks if a CSS Cache file still is valid - * - * @author Andreas Gohr - */ -function css_cacheok($cache,$files,$tplinc){ - global $config_cascade; - - if(isset($_REQUEST['purge'])) return false; //support purge request - - $ctime = @filemtime($cache); - if(!$ctime) return false; //There is no cache - - // some additional files to check - $files = array_merge($files, getConfigFiles('main')); - $files[] = $tplinc.'style.ini'; - $files[] = __FILE__; - - // now walk the files - foreach($files as $file){ - if(@filemtime($file) > $ctime){ - return false; - } - } - return true; + http_cached_finish($cache->cache, $css); } /** diff --git a/lib/exe/js.php b/lib/exe/js.php index 28894ffc6..0688825c6 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -32,7 +32,8 @@ function js_out(){ global $config_cascade; // The generated script depends on some dynamic options - $cache = getCacheName('scripts'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'],'.js'); + $cache = new cache('scripts'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'], + '.js'); // load minified version for some files $min = $conf['compress'] ? '.min' : ''; @@ -70,25 +71,13 @@ function js_out(){ $files[] = $config_cascade['userscript']['default']; } + $cache_files = array_merge($files, getConfigFiles('main')); + $cache_files[] = __FILE__; + // check cache age & handle conditional request - header('Cache-Control: public, max-age=3600'); - header('Pragma: public'); - if(js_cacheok($cache,$files)){ - http_conditionalRequest(filemtime($cache)); - if($conf['allowdebug']) header("X-CacheUsed: $cache"); - - // finally send output - if ($conf['gzip_output'] && http_gzip_valid($cache)) { - header('Vary: Accept-Encoding'); - header('Content-Encoding: gzip'); - readfile($cache.".gz"); - } else { - if (!http_sendfile($cache)) readfile($cache); - } - return; - } else { - http_conditionalRequest(time()); - } + // This may exit if a cache can be used + http_cached($cache->cache, + $cache->useCache(array('files' => $cache_files))); // start output buffering and build the script ob_start(); @@ -137,18 +126,7 @@ function js_out(){ $js .= "\n"; // https://bugzilla.mozilla.org/show_bug.cgi?id=316033 - // save cache file - io_saveFile($cache,$js); - if(function_exists('gzopen')) io_saveFile("$cache.gz",$js); - - // finally send output - if ($conf['gzip_output']) { - header('Vary: Accept-Encoding'); - header('Content-Encoding: gzip'); - print gzencode($js,9,FORCE_GZIP); - } else { - print $js; - } + http_cached_finish($cache->cache, $js); } /** @@ -183,33 +161,6 @@ function js_load($file){ echo "$data\n"; } -/** - * Checks if a JavaScript Cache file still is valid - * - * @author Andreas Gohr - */ -function js_cacheok($cache,$files){ - if(isset($_REQUEST['purge'])) return false; //support purge request - - $ctime = @filemtime($cache); - if(!$ctime) return false; //There is no cache - - global $config_cascade; - - // some additional files to check - $files = array_merge($files, getConfigFiles('main')); - $files[] = $config_cascade['userscript']['default']; - $files[] = __FILE__; - - // now walk the files - foreach($files as $file){ - if(@filemtime($file) > $ctime){ - return false; - } - } - return true; -} - /** * Returns a list of possible Plugin Scripts (no existance check here) * -- cgit v1.2.3 From f46c377bfc514cbaac6dda38078587088ab3f200 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 5 Jul 2011 21:38:31 +0200 Subject: fixed loading of the jQuery-UI style sheet --- lib/exe/css.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/exe') diff --git a/lib/exe/css.php b/lib/exe/css.php index 9751b5be4..ece8affb7 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -63,7 +63,7 @@ function css_out(){ // load core styles $files[DOKU_INC.'lib/styles/'.$mediatype.'.css'] = DOKU_BASE.'lib/styles/'; // load jQuery-UI theme - $files[DOKU_INC.'lib/js/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE.'lib/js/jquery/jquery-ui-theme/'; + $files[DOKU_INC.'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE.'lib/js/jquery/jquery-ui-theme/'; // load plugin styles $files = array_merge($files, css_pluginstyles($mediatype)); // load template styles -- cgit v1.2.3 From bf1ec6525db0b131d051d4e0023afb87e36f584b Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 5 Jul 2011 21:48:37 +0200 Subject: another fix for the jQuery-UI theme --- lib/exe/css.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/exe') diff --git a/lib/exe/css.php b/lib/exe/css.php index ece8affb7..03fe6ad90 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -63,7 +63,7 @@ function css_out(){ // load core styles $files[DOKU_INC.'lib/styles/'.$mediatype.'.css'] = DOKU_BASE.'lib/styles/'; // load jQuery-UI theme - $files[DOKU_INC.'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE.'lib/js/jquery/jquery-ui-theme/'; + $files[DOKU_INC.'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE.'lib/scripts/jquery/jquery-ui-theme/'; // load plugin styles $files = array_merge($files, css_pluginstyles($mediatype)); // load template styles -- cgit v1.2.3 From ddf8a04fe3281e871c5311235b08185a5ceab797 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 8 Jul 2011 12:20:02 +0200 Subject: moved some editor functions to a new dw_editor object There are probably more functions that should go in here --- lib/exe/js.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/exe') diff --git a/lib/exe/js.php b/lib/exe/js.php index 0688825c6..720e34577 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -55,6 +55,7 @@ function js_out(){ DOKU_INC.'lib/scripts/textselection.js', DOKU_INC.'lib/scripts/toolbar.js', DOKU_INC.'lib/scripts/edit.js', + DOKU_INC.'lib/scripts/editor.js', DOKU_INC.'lib/scripts/locktimer.js', DOKU_INC.'lib/scripts/linkwiz.js', DOKU_INC.'lib/scripts/media.js', @@ -107,7 +108,6 @@ function js_out(){ // init stuff js_runonstart("addEvent(document,'click',closePopups)"); js_runonstart('addTocToggle()'); - js_runonstart("initSizeCtl('size__ctl','wiki__text')"); js_runonstart("initToolbar('tool__bar','wiki__text',toolbar)"); if($conf['locktime'] != 0){ js_runonstart("locktimer.init(".($conf['locktime'] - 60).",'".js_escape($lang['willexpire'])."',".$conf['usedraft'].", 'wiki__text')"); -- cgit v1.2.3 From 32cb905a0339607a7acfef6488bec0015bae6b8b Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 8 Jul 2011 13:04:59 +0200 Subject: moved the TOC toggling to dw_behaviour --- lib/exe/js.php | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/exe') diff --git a/lib/exe/js.php b/lib/exe/js.php index 720e34577..308c1b534 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -107,7 +107,6 @@ function js_out(){ // init stuff js_runonstart("addEvent(document,'click',closePopups)"); - js_runonstart('addTocToggle()'); js_runonstart("initToolbar('tool__bar','wiki__text',toolbar)"); if($conf['locktime'] != 0){ js_runonstart("locktimer.init(".($conf['locktime'] - 60).",'".js_escape($lang['willexpire'])."',".$conf['usedraft'].", 'wiki__text')"); -- cgit v1.2.3 From d10c9a7424d1ef0aace2fd34e1008196d111a88c Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Thu, 7 Jul 2011 16:08:05 +0200 Subject: Rewrite mediamanager JavaScript Make it faster, prettier, less wrong, add UI effects, use jQuery UI Dialog, Abstract tree view stuff away into jQuery.dw_tree --- lib/exe/js.php | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/exe') diff --git a/lib/exe/js.php b/lib/exe/js.php index 308c1b534..44ab2d5ca 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -50,6 +50,7 @@ function js_out(){ 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', -- cgit v1.2.3 From 992ded5a7e2cbd2c8092ded03d035d0cbeade327 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 10 Jul 2011 13:14:07 +0200 Subject: make use of auth_isMember() in XMLRPC authentication check FS#2287 --- lib/exe/xmlrpc.php | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'lib/exe') diff --git a/lib/exe/xmlrpc.php b/lib/exe/xmlrpc.php index 108dd8fd1..8b572d213 100644 --- a/lib/exe/xmlrpc.php +++ b/lib/exe/xmlrpc.php @@ -30,26 +30,9 @@ class dokuwiki_xmlrpc_server extends IXR_IntrospectionServer { global $USERINFO; if(!$conf['useacl']) return true; //no ACL - then no checks + if(trim($conf['xmlrpcuser']) == '') return true; //no restrictions - $allowed = explode(',',$conf['xmlrpcuser']); - $allowed = array_map('trim', $allowed); - $allowed = array_unique($allowed); - $allowed = array_filter($allowed); - - if(!count($allowed)) return true; //no restrictions - - $user = $_SERVER['REMOTE_USER']; - $groups = (array) $USERINFO['grps']; - - if(in_array($user,$allowed)) return true; //user explicitly mentioned - - //check group memberships - foreach($groups as $group){ - if(in_array('@'.$group,$allowed)) return true; - } - - //still here? no access! - return false; + return auth_isMember($conf['xmlrpcuser'],$_SERVER['REMOTE_USER'],(array) $USERINFO['grps']); } /** -- cgit v1.2.3 From a1dee2b998bc3dc8436bb076435d405ec412e054 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Mon, 11 Jul 2011 22:17:27 +0200 Subject: Fix some bugs and glitches in (mediamanager) tree * Fix selector in subtree loading callback * Remove HTML inconsistencies between AJAX and plain PHP lists * Unify icon and CSS class switching in dw_tree and dw_mediamanager --- lib/exe/ajax.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'lib/exe') diff --git a/lib/exe/ajax.php b/lib/exe/ajax.php index 1056a05f8..2bfa3680c 100644 --- a/lib/exe/ajax.php +++ b/lib/exe/ajax.php @@ -192,12 +192,10 @@ function ajax_medians(){ $data = array(); search($data,$conf['mediadir'],'search_index',array('nofiles' => true),$dir); - foreach($data as $item){ - $item['level'] = $lvl+1; - echo media_nstree_li($item); - echo media_nstree_item($item); - echo ''; + foreach(array_keys($data) as $item){ + $data[$item]['level'] = $lvl+1; } + echo html_buildlist($data, 'idx', 'media_nstree_item', 'media_nstree_li'); } /** @@ -229,14 +227,10 @@ function ajax_index(){ $data = array(); search($data,$conf['datadir'],'search_index',array('ns' => $ns),$dir); - foreach($data as $item){ - $item['level'] = $lvl+1; - echo html_li_index($item); - echo '
'; - echo html_list_index($item); - echo '
'; - echo ''; + foreach(array_keys($data) as $item){ + $data[$item]['level'] = $lvl+1; } + echo html_buildlist($data, 'idx', 'html_list_index', 'html_li_index'); } /** -- cgit v1.2.3