xref: /dokuwiki/lib/exe/css.php (revision f7d780b9b82a664525120a90a8b1cb25be57d0e0)
178a6aeb1SAndreas Gohr<?php
278a6aeb1SAndreas Gohr/**
378a6aeb1SAndreas Gohr * DokuWiki StyleSheet creator
478a6aeb1SAndreas Gohr *
578a6aeb1SAndreas Gohr * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
678a6aeb1SAndreas Gohr * @author     Andreas Gohr <andi@splitbrain.org>
778a6aeb1SAndreas Gohr */
878a6aeb1SAndreas Gohr
9d0a27cb0SAndreas Gohrif(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../');
101c2d1019SAndreas Gohrif(!defined('NOSESSION')) define('NOSESSION',true); // we do not use a session or authentication here (better caching)
1198bda4fdSAndreas Gohrif(!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT',1); // we gzip ourself here
1278a6aeb1SAndreas Gohrrequire_once(DOKU_INC.'inc/init.php');
1378a6aeb1SAndreas Gohr
1478a6aeb1SAndreas Gohr// Main (don't run when UNIT test)
1578a6aeb1SAndreas Gohrif(!defined('SIMPLE_TEST')){
1678a6aeb1SAndreas Gohr    header('Content-Type: text/css; charset=utf-8');
1778a6aeb1SAndreas Gohr    css_out();
1878a6aeb1SAndreas Gohr}
1978a6aeb1SAndreas Gohr
2078a6aeb1SAndreas Gohr
2178a6aeb1SAndreas Gohr// ---------------------- functions ------------------------------
2278a6aeb1SAndreas Gohr
2378a6aeb1SAndreas Gohr/**
2478a6aeb1SAndreas Gohr * Output all needed Styles
2578a6aeb1SAndreas Gohr *
2678a6aeb1SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
2778a6aeb1SAndreas Gohr */
2878a6aeb1SAndreas Gohrfunction css_out(){
2978a6aeb1SAndreas Gohr    global $conf;
3078a6aeb1SAndreas Gohr    global $lang;
3109edb711SAndreas Gohr    global $config_cascade;
3209edb711SAndreas Gohr
33615960feSTom N Harris    $style = '';
34c66972f2SAdrian Lang    if (isset($_REQUEST['s']) &&
35c66972f2SAdrian Lang        in_array($_REQUEST['s'], array('all', 'print', 'feed'))) {
36c66972f2SAdrian Lang        $style = $_REQUEST['s'];
37615960feSTom N Harris    }
3878a6aeb1SAndreas Gohr
39f7589b08SChris Smith    $tpl = trim(preg_replace('/[^\w-]+/','',$_REQUEST['t']));
40124af657SAndreas Gohr    if($tpl){
41124af657SAndreas Gohr        $tplinc = DOKU_INC.'lib/tpl/'.$tpl.'/';
42124af657SAndreas Gohr        $tpldir = DOKU_BASE.'lib/tpl/'.$tpl.'/';
43124af657SAndreas Gohr    }else{
44124af657SAndreas Gohr        $tplinc = DOKU_TPLINC;
45124af657SAndreas Gohr        $tpldir = DOKU_TPL;
46124af657SAndreas Gohr    }
47124af657SAndreas Gohr
4878a6aeb1SAndreas Gohr    // The generated script depends on some dynamic options
49e3e6ab3cSGina Haeussge    $cache = getCacheName('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tplinc.$style,'.css');
5078a6aeb1SAndreas Gohr
51519b3173SAndreas Gohr    // load template styles
52519b3173SAndreas Gohr    $tplstyles = array();
53124af657SAndreas Gohr    if(@file_exists($tplinc.'style.ini')){
54124af657SAndreas Gohr        $ini = parse_ini_file($tplinc.'style.ini',true);
55519b3173SAndreas Gohr        foreach($ini['stylesheets'] as $file => $mode){
56124af657SAndreas Gohr            $tplstyles[$mode][$tplinc.$file] = $tpldir;
57519b3173SAndreas Gohr        }
58519b3173SAndreas Gohr    }
59519b3173SAndreas Gohr
6078a6aeb1SAndreas Gohr    // Array of needed files and their web locations, the latter ones
6178a6aeb1SAndreas Gohr    // are needed to fix relative paths in the stylesheets
6278a6aeb1SAndreas Gohr    $files   = array();
637aaa4c46Smartin.tschofen    //if (isset($tplstyles['all'])) $files = array_merge($files, $tplstyles['all']);
64615960feSTom N Harris    if(!empty($style)){
65615960feSTom N Harris        $files[DOKU_INC.'lib/styles/'.$style.'.css'] = DOKU_BASE.'lib/styles/';
665b77caf4SAndreas Gohr        // load plugin, template, user styles
67615960feSTom N Harris        $files = array_merge($files, css_pluginstyles($style));
68615960feSTom N Harris        if (isset($tplstyles[$style])) $files = array_merge($files, $tplstyles[$style]);
6909edb711SAndreas Gohr
7009edb711SAndreas Gohr        if(isset($config_cascade['userstyle'][$style])){
7109edb711SAndreas Gohr            $files[$config_cascade['userstyle'][$style]] = DOKU_BASE;
7209edb711SAndreas Gohr        }
7378a6aeb1SAndreas Gohr    }else{
7478a6aeb1SAndreas Gohr        $files[DOKU_INC.'lib/styles/style.css'] = DOKU_BASE.'lib/styles/';
755b77caf4SAndreas Gohr        // load plugin, template, user styles
765b77caf4SAndreas Gohr        $files = array_merge($files, css_pluginstyles('screen'));
771f5663fdSchris        if (isset($tplstyles['screen'])) $files = array_merge($files, $tplstyles['screen']);
7878a6aeb1SAndreas Gohr        if($lang['direction'] == 'rtl'){
791f5663fdSchris            if (isset($tplstyles['rtl'])) $files = array_merge($files, $tplstyles['rtl']);
8078a6aeb1SAndreas Gohr        }
8109edb711SAndreas Gohr        if(isset($config_cascade['userstyle']['default'])){
8209edb711SAndreas Gohr            $files[$config_cascade['userstyle']['default']] = DOKU_BASE;
8309edb711SAndreas Gohr        }
8478a6aeb1SAndreas Gohr    }
8578a6aeb1SAndreas Gohr
8638f56bffSBen Coburn    // check cache age & handle conditional request
8707525e80SBen Coburn    header('Cache-Control: public, max-age=3600');
8838f56bffSBen Coburn    header('Pragma: public');
89124af657SAndreas Gohr    if(css_cacheok($cache,array_keys($files),$tplinc)){
9038f56bffSBen Coburn        http_conditionalRequest(filemtime($cache));
91cf6894dfSAndreas Gohr        if($conf['allowdebug']) header("X-CacheUsed: $cache");
92ca2b464bSChris Smith
93ca2b464bSChris Smith        // finally send output
9498bda4fdSAndreas Gohr        if ($conf['gzip_output'] && http_gzip_valid($cache)) {
95ca2b464bSChris Smith          header('Vary: Accept-Encoding');
96ca2b464bSChris Smith          header('Content-Encoding: gzip');
9798bda4fdSAndreas Gohr          readfile($cache.".gz");
98ca2b464bSChris Smith        } else {
99ca2b464bSChris Smith          if (!http_sendfile($cache)) readfile($cache);
100ca2b464bSChris Smith        }
101ca2b464bSChris Smith
10278a6aeb1SAndreas Gohr        return;
10338f56bffSBen Coburn    } else {
10438f56bffSBen Coburn        http_conditionalRequest(time());
10578a6aeb1SAndreas Gohr    }
10678a6aeb1SAndreas Gohr
10778a6aeb1SAndreas Gohr    // start output buffering and build the stylesheet
10878a6aeb1SAndreas Gohr    ob_start();
10978a6aeb1SAndreas Gohr
110d15166e5SAndreas Gohr    // print the default classes for interwiki links and file downloads
1111c2d1019SAndreas Gohr    css_interwiki();
112d15166e5SAndreas Gohr    css_filetypes();
1131c2d1019SAndreas Gohr
11478a6aeb1SAndreas Gohr    // load files
11578a6aeb1SAndreas Gohr    foreach($files as $file => $location){
11678a6aeb1SAndreas Gohr        print css_loadfile($file, $location);
11778a6aeb1SAndreas Gohr    }
11878a6aeb1SAndreas Gohr
11978a6aeb1SAndreas Gohr    // end output buffering and get contents
12078a6aeb1SAndreas Gohr    $css = ob_get_contents();
12178a6aeb1SAndreas Gohr    ob_end_clean();
12278a6aeb1SAndreas Gohr
1236e69c1baSAndreas Gohr    // apply style replacements
124124af657SAndreas Gohr    $css = css_applystyle($css,$tplinc);
1256e69c1baSAndreas Gohr
126*f7d780b9SGabriel Birke    // place all @import statements at the top of the file
127*f7d780b9SGabriel Birke    $css = css_moveimports($css);
128*f7d780b9SGabriel Birke
12978a6aeb1SAndreas Gohr    // compress whitespace and comments
13078a6aeb1SAndreas Gohr    if($conf['compress']){
13178a6aeb1SAndreas Gohr        $css = css_compress($css);
13278a6aeb1SAndreas Gohr    }
13378a6aeb1SAndreas Gohr
13478a6aeb1SAndreas Gohr    // save cache file
13578a6aeb1SAndreas Gohr    io_saveFile($cache,$css);
136c8317406SAndreas Gohr    if(function_exists('gzopen')) io_saveFile("$cache.gz",$css);
13778a6aeb1SAndreas Gohr
13878a6aeb1SAndreas Gohr    // finally send output
13998bda4fdSAndreas Gohr    if ($conf['gzip_output']) {
140ca2b464bSChris Smith      header('Vary: Accept-Encoding');
141ca2b464bSChris Smith      header('Content-Encoding: gzip');
142ca2b464bSChris Smith      print gzencode($css,9,FORCE_GZIP);
143ca2b464bSChris Smith    } else {
14478a6aeb1SAndreas Gohr      print $css;
14578a6aeb1SAndreas Gohr    }
146ca2b464bSChris Smith}
14778a6aeb1SAndreas Gohr
14878a6aeb1SAndreas Gohr/**
14978a6aeb1SAndreas Gohr * Checks if a CSS Cache file still is valid
15078a6aeb1SAndreas Gohr *
15178a6aeb1SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
15278a6aeb1SAndreas Gohr */
153124af657SAndreas Gohrfunction css_cacheok($cache,$files,$tplinc){
154f8121585SChris Smith    global $config_cascade;
155f8121585SChris Smith
156c66972f2SAdrian Lang    if(isset($_REQUEST['purge'])) return false; //support purge request
1570df6f150SAndreas Gohr
15878a6aeb1SAndreas Gohr    $ctime = @filemtime($cache);
15978a6aeb1SAndreas Gohr    if(!$ctime) return false; //There is no cache
16078a6aeb1SAndreas Gohr
16178a6aeb1SAndreas Gohr    // some additional files to check
162f8121585SChris Smith    $files = array_merge($files, getConfigFiles('main'));
163124af657SAndreas Gohr    $files[] = $tplinc.'style.ini';
16478a6aeb1SAndreas Gohr    $files[] = __FILE__;
16578a6aeb1SAndreas Gohr
16678a6aeb1SAndreas Gohr    // now walk the files
16778a6aeb1SAndreas Gohr    foreach($files as $file){
16878a6aeb1SAndreas Gohr        if(@filemtime($file) > $ctime){
16978a6aeb1SAndreas Gohr            return false;
17078a6aeb1SAndreas Gohr        }
17178a6aeb1SAndreas Gohr    }
17278a6aeb1SAndreas Gohr    return true;
17378a6aeb1SAndreas Gohr}
17478a6aeb1SAndreas Gohr
17578a6aeb1SAndreas Gohr/**
1766e69c1baSAndreas Gohr * Does placeholder replacements in the style according to
1776e69c1baSAndreas Gohr * the ones defined in a templates style.ini file
1786e69c1baSAndreas Gohr *
1796e69c1baSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1806e69c1baSAndreas Gohr */
181124af657SAndreas Gohrfunction css_applystyle($css,$tplinc){
182124af657SAndreas Gohr    if(@file_exists($tplinc.'style.ini')){
183124af657SAndreas Gohr        $ini = parse_ini_file($tplinc.'style.ini',true);
184519b3173SAndreas Gohr        $css = strtr($css,$ini['replacements']);
1856e69c1baSAndreas Gohr    }
1866e69c1baSAndreas Gohr    return $css;
1876e69c1baSAndreas Gohr}
1886e69c1baSAndreas Gohr
1896e69c1baSAndreas Gohr/**
1901c2d1019SAndreas Gohr * Prints classes for interwikilinks
1911c2d1019SAndreas Gohr *
1921c2d1019SAndreas Gohr * Interwiki links have two classes: 'interwiki' and 'iw_$name>' where
1931c2d1019SAndreas Gohr * $name is the identifier given in the config. All Interwiki links get
1941c2d1019SAndreas Gohr * an default style with a default icon. If a special icon is available
1951c2d1019SAndreas Gohr * for an interwiki URL it is set in it's own class. Both classes can be
1961c2d1019SAndreas Gohr * overwritten in the template or userstyles.
1971c2d1019SAndreas Gohr *
1981c2d1019SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1991c2d1019SAndreas Gohr */
2001c2d1019SAndreas Gohrfunction css_interwiki(){
2011c2d1019SAndreas Gohr
2021c2d1019SAndreas Gohr    // default style
2031c2d1019SAndreas Gohr    echo 'a.interwiki {';
2041c2d1019SAndreas Gohr    echo ' background: transparent url('.DOKU_BASE.'lib/images/interwiki.png) 0px 1px no-repeat;';
2051c2d1019SAndreas Gohr    echo ' padding-left: 16px;';
2061c2d1019SAndreas Gohr    echo '}';
2071c2d1019SAndreas Gohr
2081c2d1019SAndreas Gohr    // additional styles when icon available
2091c2d1019SAndreas Gohr    $iwlinks = getInterwiki();
2101c2d1019SAndreas Gohr    foreach(array_keys($iwlinks) as $iw){
2119d2ddea4SAndreas Gohr        $class = preg_replace('/[^_\-a-z0-9]+/i','_',$iw);
2121c2d1019SAndreas Gohr        if(@file_exists(DOKU_INC.'lib/images/interwiki/'.$iw.'.png')){
2139d2ddea4SAndreas Gohr            echo "a.iw_$class {";
2141c2d1019SAndreas Gohr            echo '  background-image: url('.DOKU_BASE.'lib/images/interwiki/'.$iw.'.png)';
2151c2d1019SAndreas Gohr            echo '}';
2161c2d1019SAndreas Gohr        }elseif(@file_exists(DOKU_INC.'lib/images/interwiki/'.$iw.'.gif')){
2179d2ddea4SAndreas Gohr            echo "a.iw_$class {";
2181c2d1019SAndreas Gohr            echo '  background-image: url('.DOKU_BASE.'lib/images/interwiki/'.$iw.'.gif)';
2191c2d1019SAndreas Gohr            echo '}';
2201c2d1019SAndreas Gohr        }
2211c2d1019SAndreas Gohr    }
222d15166e5SAndreas Gohr}
2231c2d1019SAndreas Gohr
224d15166e5SAndreas Gohr/**
225d15166e5SAndreas Gohr * Prints classes for file download links
226d15166e5SAndreas Gohr *
227d15166e5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
228d15166e5SAndreas Gohr */
229d15166e5SAndreas Gohrfunction css_filetypes(){
230d15166e5SAndreas Gohr
231d15166e5SAndreas Gohr    // default style
232d15166e5SAndreas Gohr    echo 'a.mediafile {';
233d15166e5SAndreas Gohr    echo ' background: transparent url('.DOKU_BASE.'lib/images/fileicons/file.png) 0px 1px no-repeat;';
2345b77caf4SAndreas Gohr    echo ' padding-left: 18px;';
2355b77caf4SAndreas Gohr    echo ' padding-bottom: 1px;';
236d15166e5SAndreas Gohr    echo '}';
237d15166e5SAndreas Gohr
238d15166e5SAndreas Gohr    // additional styles when icon available
23927bf7924STom N Harris    // scan directory for all icons
24027bf7924STom N Harris    $exts = array();
24127bf7924STom N Harris    if($dh = opendir(DOKU_INC.'lib/images/fileicons')){
24227bf7924STom N Harris        while(false !== ($file = readdir($dh))){
24327bf7924STom N Harris            if(preg_match('/([_\-a-z0-9]+(?:\.[_\-a-z0-9]+)*?)\.(png|gif)/i',$file,$match)){
24427bf7924STom N Harris                $ext = strtolower($match[1]);
24527bf7924STom N Harris                $type = '.'.strtolower($match[2]);
24627bf7924STom N Harris                if($ext!='file' && (!isset($exts[$ext]) || $type=='.png')){
24727bf7924STom N Harris                    $exts[$ext] = $type;
248d15166e5SAndreas Gohr                }
249d15166e5SAndreas Gohr            }
2501c2d1019SAndreas Gohr        }
25127bf7924STom N Harris        closedir($dh);
25227bf7924STom N Harris    }
25327bf7924STom N Harris    foreach($exts as $ext=>$type){
25427bf7924STom N Harris        $class = preg_replace('/[^_\-a-z0-9]+/','_',$ext);
25527bf7924STom N Harris        echo "a.mf_$class {";
25627bf7924STom N Harris        echo '  background-image: url('.DOKU_BASE.'lib/images/fileicons/'.$ext.$type.')';
25727bf7924STom N Harris        echo '}';
25827bf7924STom N Harris    }
25927bf7924STom N Harris}
2601c2d1019SAndreas Gohr
2611c2d1019SAndreas Gohr/**
26278a6aeb1SAndreas Gohr * Loads a given file and fixes relative URLs with the
26378a6aeb1SAndreas Gohr * given location prefix
26478a6aeb1SAndreas Gohr */
26578a6aeb1SAndreas Gohrfunction css_loadfile($file,$location=''){
26678a6aeb1SAndreas Gohr    if(!@file_exists($file)) return '';
26778a6aeb1SAndreas Gohr    $css = io_readFile($file);
26878a6aeb1SAndreas Gohr    if(!$location) return $css;
26978a6aeb1SAndreas Gohr
27015c394afSAndreas Gohr    $css = preg_replace('#(url\([ \'"]*)((?!/|http://|https://| |\'|"))#','\\1'.$location.'\\3',$css);
271*f7d780b9SGabriel Birke    $css = preg_replace('#(@import\s+[\'"])((?!/|http://|https://))#', '\\1'.$location.'\\2"', $css);
27278a6aeb1SAndreas Gohr    return $css;
27378a6aeb1SAndreas Gohr}
27478a6aeb1SAndreas Gohr
27515c394afSAndreas Gohr
27678a6aeb1SAndreas Gohr/**
27778a6aeb1SAndreas Gohr * Returns a list of possible Plugin Styles (no existance check here)
27878a6aeb1SAndreas Gohr *
27978a6aeb1SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
28078a6aeb1SAndreas Gohr */
28178a6aeb1SAndreas Gohrfunction css_pluginstyles($mode='screen'){
282208c0215SAndreas Gohr    global $lang;
28378a6aeb1SAndreas Gohr    $list = array();
28478a6aeb1SAndreas Gohr    $plugins = plugin_list();
28578a6aeb1SAndreas Gohr    foreach ($plugins as $p){
2867aaa4c46Smartin.tschofen        if($mode == 'all'){
287ea40e5efSmtbrains            $list[DOKU_PLUGIN."$p/all.css"]  = DOKU_BASE."lib/plugins/$p/";
2887aaa4c46Smartin.tschofen        }elseif($mode == 'print'){
2897aaa4c46Smartin.tschofen            $list[DOKU_PLUGIN."$p/print.css"]  = DOKU_BASE."lib/plugins/$p/";
290615960feSTom N Harris        }elseif($mode == 'feed'){
291615960feSTom N Harris            $list[DOKU_PLUGIN."$p/feed.css"]  = DOKU_BASE."lib/plugins/$p/";
29278a6aeb1SAndreas Gohr        }else{
29378a6aeb1SAndreas Gohr            $list[DOKU_PLUGIN."$p/style.css"]  = DOKU_BASE."lib/plugins/$p/";
29478a6aeb1SAndreas Gohr            $list[DOKU_PLUGIN."$p/screen.css"] = DOKU_BASE."lib/plugins/$p/";
29578a6aeb1SAndreas Gohr        }
296208c0215SAndreas Gohr        if($lang['direction'] == 'rtl'){
297208c0215SAndreas Gohr            $list[DOKU_PLUGIN."$p/rtl.css"] = DOKU_BASE."lib/plugins/$p/";
298208c0215SAndreas Gohr        }
29978a6aeb1SAndreas Gohr    }
30078a6aeb1SAndreas Gohr    return $list;
30178a6aeb1SAndreas Gohr}
30278a6aeb1SAndreas Gohr
30378a6aeb1SAndreas Gohr/**
304*f7d780b9SGabriel Birke * Move all @import statements in a combined stylesheet to the top so they
305*f7d780b9SGabriel Birke * aren't ignored by the browser.
306*f7d780b9SGabriel Birke *
307*f7d780b9SGabriel Birke * @author Gabriel Birke <birke@d-scribe.de>
308*f7d780b9SGabriel Birke */
309*f7d780b9SGabriel Birkefunction css_moveimports($css)
310*f7d780b9SGabriel Birke{
311*f7d780b9SGabriel Birke    if(!preg_match_all('/@import\s+(?:url\([^)]+\)|"[^"]+")\s*[^;]*;\s*/', $css, $matches, PREG_OFFSET_CAPTURE)) {
312*f7d780b9SGabriel Birke        return $css;
313*f7d780b9SGabriel Birke    }
314*f7d780b9SGabriel Birke    $newCss  = "";
315*f7d780b9SGabriel Birke    $imports = "";
316*f7d780b9SGabriel Birke    $offset  = 0;
317*f7d780b9SGabriel Birke    foreach($matches[0] as $match) {
318*f7d780b9SGabriel Birke        $newCss  .= substr($css, $offset, $match[1] - $offset);
319*f7d780b9SGabriel Birke        $imports .= $match[0];
320*f7d780b9SGabriel Birke        $offset   = $match[1] + strlen($match[0]);
321*f7d780b9SGabriel Birke    }
322*f7d780b9SGabriel Birke    $newCss .= substr($css, $offset);
323*f7d780b9SGabriel Birke    return $imports.$newCss;
324*f7d780b9SGabriel Birke}
325*f7d780b9SGabriel Birke
326*f7d780b9SGabriel Birke/**
32778a6aeb1SAndreas Gohr * Very simple CSS optimizer
32878a6aeb1SAndreas Gohr *
32978a6aeb1SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
33078a6aeb1SAndreas Gohr */
33178a6aeb1SAndreas Gohrfunction css_compress($css){
332fd7c2db0SAndreas Gohr    //strip comments through a callback
333fd7c2db0SAndreas Gohr    $css = preg_replace_callback('#(/\*)(.*?)(\*/)#s','css_comment_cb',$css);
334fd7c2db0SAndreas Gohr
335247c1c5dSAndreas Gohr    //strip (incorrect but common) one line comments
336fd7c2db0SAndreas Gohr    $css = preg_replace('/(?<!:)\/\/.*$/m','',$css);
337247c1c5dSAndreas Gohr
33878a6aeb1SAndreas Gohr    // strip whitespaces
33978a6aeb1SAndreas Gohr    $css = preg_replace('![\r\n\t ]+!',' ',$css);
3405646f690SAndreas Gohr    $css = preg_replace('/ ?([:;,{}\/]) ?/','\\1',$css);
34178a6aeb1SAndreas Gohr
34278a6aeb1SAndreas Gohr    // shorten colors
34378a6aeb1SAndreas Gohr    $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);
34478a6aeb1SAndreas Gohr
34578a6aeb1SAndreas Gohr    return $css;
34678a6aeb1SAndreas Gohr}
34778a6aeb1SAndreas Gohr
348c00aef76SAndreas Gohr/**
349c00aef76SAndreas Gohr * Callback for css_compress()
350c00aef76SAndreas Gohr *
351c00aef76SAndreas Gohr * Keeps short comments (< 5 chars) to maintain typical browser hacks
352c00aef76SAndreas Gohr *
353c00aef76SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
354c00aef76SAndreas Gohr */
355c00aef76SAndreas Gohrfunction css_comment_cb($matches){
356c00aef76SAndreas Gohr    if(strlen($matches[2]) > 4) return '';
357c00aef76SAndreas Gohr    return $matches[0];
358c00aef76SAndreas Gohr}
35978a6aeb1SAndreas Gohr
360e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
361