summaryrefslogtreecommitdiff
path: root/lib/exe/css.php
diff options
context:
space:
mode:
authorAdrian Lang <mail@adrianlang.de>2011-11-10 15:43:15 +0100
committerAdrian Lang <mail@adrianlang.de>2011-11-10 15:43:15 +0100
commit16a774a8a61756df2d8fb813bfbaed98b42e3e65 (patch)
tree3a48d311e74ccbf4017330cef8af00003b0ddb34 /lib/exe/css.php
parent662a7b3fcc22d8327026bc1ef161a096683f1580 (diff)
parenta5a71ecfcc1ed6bfca1995b39cd0abe4b8dd9eeb (diff)
downloadrpg-16a774a8a61756df2d8fb813bfbaed98b42e3e65.tar.gz
rpg-16a774a8a61756df2d8fb813bfbaed98b42e3e65.tar.bz2
Merge branch 'master' into stable
Conflicts: doku.php
Diffstat (limited to 'lib/exe/css.php')
-rw-r--r--lib/exe/css.php110
1 files changed, 48 insertions, 62 deletions
diff --git a/lib/exe/css.php b/lib/exe/css.php
index 03f900034..d54e2e46c 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();
@@ -62,6 +62,8 @@ function css_out(){
$files = array();
// 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/scripts/jquery/jquery-ui-theme/';
// load plugin styles
$files = array_merge($files, css_pluginstyles($mediatype));
// load template styles
@@ -85,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();
@@ -133,45 +123,13 @@ 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;
+ // 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);
}
-}
-
-/**
- * Checks if a CSS Cache file still is valid
- *
- * @author Andreas Gohr <andi@splitbrain.org>
- */
-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);
}
/**
@@ -231,7 +189,7 @@ function css_interwiki(){
function css_filetypes(){
// default style
- echo 'a.mediafile {';
+ echo '.mediafile {';
echo ' background: transparent url('.DOKU_BASE.'lib/images/fileicons/file.png) 0px 1px no-repeat;';
echo ' padding-left: 18px;';
echo ' padding-bottom: 1px;';
@@ -254,7 +212,7 @@ function css_filetypes(){
}
foreach($exts as $ext=>$type){
$class = preg_replace('/[^_\-a-z0-9]+/','_',$ext);
- echo "a.mf_$class {";
+ echo ".mf_$class {";
echo ' background-image: url('.DOKU_BASE.'lib/images/fileicons/'.$ext.$type.')';
echo '}';
}
@@ -269,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)
@@ -334,7 +319,8 @@ function css_compress($css){
// strip whitespaces
$css = preg_replace('![\r\n\t ]+!',' ',$css);
- $css = preg_replace('/ ?([:;,{}\/]) ?/','\\1',$css);
+ $css = preg_replace('/ ?([;,{}\/]) ?/','\\1',$css);
+ $css = preg_replace('/ ?: /',':',$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);