Skip to content

Commit

Permalink
Merge branch 'datauris'
Browse files Browse the repository at this point in the history
Conflicts:
	lib/exe/css.php
  • Loading branch information
splitbrain committed Jul 7, 2011
2 parents bf1ec65 + 28f4004 commit 0a9349a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions conf/dokuwiki.php
Expand Up @@ -108,6 +108,7 @@
$conf['subscribe_time'] = 24*60*60; //Time after which digests / lists are sent (in sec, default 1 day)
//Should be smaller than the time specified in recent_days
$conf['compress'] = 1; //Strip whitespaces and comments from Styles and JavaScript? 1|0
$conf['cssdatauri'] = 0; //Maximum byte size of small images to embed into CSS, won't work on IE<8
$conf['hidepages'] = ''; //Regexp for pages to be skipped from RSS, Search and Recent Changes
$conf['send404'] = 0; //Send a HTTP 404 status for non existing pages?
$conf['sitemap'] = 0; //Create a google sitemap? How often? In days.
Expand Down
37 changes: 35 additions & 2 deletions lib/exe/css.php
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/plugins/config/lang/en/lang.php
Expand Up @@ -133,6 +133,7 @@
$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)';
Expand Down
1 change: 1 addition & 0 deletions lib/plugins/config/settings/config.metadata.php
Expand Up @@ -179,6 +179,7 @@
$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');
Expand Down

0 comments on commit 0a9349a

Please sign in to comment.