diff options
author | Andreas Gohr <andi@splitbrain.org> | 2011-07-07 21:25:21 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2011-07-07 21:25:21 +0200 |
commit | 0a9349a634619dddcb0aa563e287026dcbd7a60c (patch) | |
tree | 451949dff4663d18c590b9c472639f2536bec9ba /lib | |
parent | bf1ec6525db0b131d051d4e0023afb87e36f584b (diff) | |
parent | 28f4004c937cfc11f16e6cc7c0eb7da1a61dfcbe (diff) | |
download | rpg-0a9349a634619dddcb0aa563e287026dcbd7a60c.tar.gz rpg-0a9349a634619dddcb0aa563e287026dcbd7a60c.tar.bz2 |
Merge branch 'datauris'
Conflicts:
lib/exe/css.php
Diffstat (limited to 'lib')
-rw-r--r-- | lib/exe/css.php | 37 | ||||
-rw-r--r-- | lib/plugins/config/lang/en/lang.php | 1 | ||||
-rw-r--r-- | lib/plugins/config/settings/config.metadata.php | 1 |
3 files changed, 37 insertions, 2 deletions
diff --git a/lib/exe/css.php b/lib/exe/css.php index 03fe6ad90..8f86f2433 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -123,6 +123,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); + } + http_cached_finish($cache->cache, $css); } @@ -221,11 +227,38 @@ 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){ + global $conf; + + $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 < $conf['cssdatauri']){ + $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) diff --git a/lib/plugins/config/lang/en/lang.php b/lib/plugins/config/lang/en/lang.php index 9b7c643bf..e5dd4707a 100644 --- a/lib/plugins/config/lang/en/lang.php +++ b/lib/plugins/config/lang/en/lang.php @@ -133,6 +133,7 @@ $lang['jpg_quality'] = 'JPG compression quality (0-100)'; $lang['subscribers'] = 'Enable page subscription support'; $lang['subscribe_time'] = 'Time after which subscription lists and digests are sent (sec); This should be smaller than the time specified in recent_days.'; $lang['compress'] = 'Compact CSS and javascript output'; +$lang['cssdatauri'] = 'Size in bytes up to which images referenced in CSS files should be embedded right into the stylesheet to reduce HTTP request header overhead. This technique won\'t work in IE < 8! <code>400</code> to <code>600</code> bytes is a good value. Set <code>0</code> to disable.'; $lang['hidepages'] = 'Hide matching pages (regular expressions)'; $lang['send404'] = 'Send "HTTP 404/Page Not Found" for non existing pages'; $lang['sitemap'] = 'Generate Google sitemap (days)'; diff --git a/lib/plugins/config/settings/config.metadata.php b/lib/plugins/config/settings/config.metadata.php index af7e63a61..abea1be1c 100644 --- a/lib/plugins/config/settings/config.metadata.php +++ b/lib/plugins/config/settings/config.metadata.php @@ -179,6 +179,7 @@ $meta['autoplural'] = array('onoff'); $meta['mailfrom'] = array('richemail'); $meta['mailprefix'] = array('string'); $meta['compress'] = array('onoff'); +$meta['cssdatauri'] = array('numeric','_pattern' => '/^\d+$/'); $meta['gzip_output'] = array('onoff'); $meta['hidepages'] = array('string'); $meta['send404'] = array('onoff'); |