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 126c47a78cSAnika Henkeif(!defined('NL')) define('NL',"\n"); 1378a6aeb1SAndreas Gohrrequire_once(DOKU_INC.'inc/init.php'); 1478a6aeb1SAndreas Gohr 1578a6aeb1SAndreas Gohr// Main (don't run when UNIT test) 1678a6aeb1SAndreas Gohrif(!defined('SIMPLE_TEST')){ 1778a6aeb1SAndreas Gohr header('Content-Type: text/css; charset=utf-8'); 1878a6aeb1SAndreas Gohr css_out(); 1978a6aeb1SAndreas Gohr} 2078a6aeb1SAndreas Gohr 2178a6aeb1SAndreas Gohr 2278a6aeb1SAndreas Gohr// ---------------------- functions ------------------------------ 2378a6aeb1SAndreas Gohr 2478a6aeb1SAndreas Gohr/** 2578a6aeb1SAndreas Gohr * Output all needed Styles 2678a6aeb1SAndreas Gohr * 2778a6aeb1SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 2878a6aeb1SAndreas Gohr */ 2978a6aeb1SAndreas Gohrfunction css_out(){ 3078a6aeb1SAndreas Gohr global $conf; 3178a6aeb1SAndreas Gohr global $lang; 3209edb711SAndreas Gohr global $config_cascade; 33bfd0f597STom N Harris global $INPUT; 3409edb711SAndreas Gohr 3529f2dfdcSAndreas Gohr if ($INPUT->str('s') == 'feed') { 366c47a78cSAnika Henke $mediatypes = array('feed'); 376c47a78cSAnika Henke $type = 'feed'; 386c47a78cSAnika Henke } else { 396c47a78cSAnika Henke $mediatypes = array('screen', 'all', 'print'); 406c47a78cSAnika Henke $type = ''; 41615960feSTom N Harris } 4278a6aeb1SAndreas Gohr 43bfd0f597STom N Harris $tpl = trim(preg_replace('/[^\w-]+/','',$INPUT->str('t'))); 44124af657SAndreas Gohr if($tpl){ 45124af657SAndreas Gohr $tplinc = DOKU_INC.'lib/tpl/'.$tpl.'/'; 46124af657SAndreas Gohr $tpldir = DOKU_BASE.'lib/tpl/'.$tpl.'/'; 47124af657SAndreas Gohr }else{ 4881aca18eSAndreas Gohr $tplinc = tpl_incdir(); 4981aca18eSAndreas Gohr $tpldir = tpl_basedir(); 50124af657SAndreas Gohr } 51124af657SAndreas Gohr 520e6f9f08SAnika Henke // used style.ini file 530e6f9f08SAnika Henke $styleini = css_styleini($tplinc); 540e6f9f08SAnika Henke 5578a6aeb1SAndreas Gohr // The generated script depends on some dynamic options 566c47a78cSAnika Henke $cache = new cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tplinc.$type,'.css'); 5778a6aeb1SAndreas Gohr 58519b3173SAndreas Gohr // load template styles 59519b3173SAndreas Gohr $tplstyles = array(); 600e6f9f08SAnika Henke if ($styleini) { 610ac69508SAnika Henke foreach($styleini['stylesheets'] as $file => $mode) { 62124af657SAndreas Gohr $tplstyles[$mode][$tplinc.$file] = $tpldir; 63519b3173SAndreas Gohr } 64519b3173SAndreas Gohr } 65519b3173SAndreas Gohr 66dbf794bfSMichael Hamann // if old 'default' userstyle setting exists, make it 'screen' userstyle for backwards compatibility 67dbf794bfSMichael Hamann if (isset($config_cascade['userstyle']['default'])) { 68dbf794bfSMichael Hamann $config_cascade['userstyle']['screen'] = $config_cascade['userstyle']['default']; 69dbf794bfSMichael Hamann } 70dbf794bfSMichael Hamann 7178a6aeb1SAndreas Gohr // Array of needed files and their web locations, the latter ones 7278a6aeb1SAndreas Gohr // are needed to fix relative paths in the stylesheets 7378a6aeb1SAndreas Gohr $files = array(); 7414977bd2SMichael Hamann 7514977bd2SMichael Hamann $cache_files = getConfigFiles('main'); 760ac69508SAnika Henke $cache_files[] = $tplinc.'style.ini'; 770ac69508SAnika Henke $cache_files[] = $tplinc.'style.local.ini'; 7814977bd2SMichael Hamann $cache_files[] = __FILE__; 7914977bd2SMichael Hamann 8014977bd2SMichael Hamann foreach($mediatypes as $mediatype) { 8114977bd2SMichael Hamann $files[$mediatype] = array(); 82318cd03eSAnika Henke // load core styles 8314977bd2SMichael Hamann $files[$mediatype][DOKU_INC.'lib/styles/'.$mediatype.'.css'] = DOKU_BASE.'lib/styles/'; 8443576758SAndreas Gohr // load jQuery-UI theme 856c47a78cSAnika Henke if ($mediatype == 'screen') { 8614977bd2SMichael Hamann $files[$mediatype][DOKU_INC.'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE.'lib/scripts/jquery/jquery-ui-theme/'; 876c47a78cSAnika Henke } 88318cd03eSAnika Henke // load plugin styles 8914977bd2SMichael Hamann $files[$mediatype] = array_merge($files[$mediatype], css_pluginstyles($mediatype)); 90318cd03eSAnika Henke // load template styles 91318cd03eSAnika Henke if (isset($tplstyles[$mediatype])) { 9214977bd2SMichael Hamann $files[$mediatype] = array_merge($files[$mediatype], $tplstyles[$mediatype]); 9309edb711SAndreas Gohr } 94318cd03eSAnika Henke // load user styles 95318cd03eSAnika Henke if(isset($config_cascade['userstyle'][$mediatype])){ 9614977bd2SMichael Hamann $files[$mediatype][$config_cascade['userstyle'][$mediatype]] = DOKU_BASE; 97318cd03eSAnika Henke } 98318cd03eSAnika Henke // load rtl styles 996c47a78cSAnika Henke // note: this adds the rtl styles only to the 'screen' media type 1006c47a78cSAnika Henke // @deprecated 2012-04-09: rtl will cease to be a mode of its own, 1016c47a78cSAnika Henke // please use "[dir=rtl]" in any css file in all, screen or print mode instead 102318cd03eSAnika Henke if ($mediatype=='screen') { 10378a6aeb1SAndreas Gohr if($lang['direction'] == 'rtl'){ 10414977bd2SMichael Hamann if (isset($tplstyles['rtl'])) $files[$mediatype] = array_merge($files[$mediatype], $tplstyles['rtl']); 105c5c68de9SMichael Hamann if (isset($config_cascade['userstyle']['rtl'])) $files[$mediatype][$config_cascade['userstyle']['rtl']] = DOKU_BASE; 10678a6aeb1SAndreas Gohr } 10778a6aeb1SAndreas Gohr } 10878a6aeb1SAndreas Gohr 10914977bd2SMichael Hamann $cache_files = array_merge($cache_files, array_keys($files[$mediatype])); 11014977bd2SMichael Hamann } 1116619f42eSAdrian Lang 11238f56bffSBen Coburn // check cache age & handle conditional request 1136619f42eSAdrian Lang // This may exit if a cache can be used 1146619f42eSAdrian Lang http_cached($cache->cache, 1156619f42eSAdrian Lang $cache->useCache(array('files' => $cache_files))); 11678a6aeb1SAndreas Gohr 1173899c2ecSMichael Hamann // start output buffering 1183899c2ecSMichael Hamann ob_start(); 1193899c2ecSMichael Hamann 1206c47a78cSAnika Henke // build the stylesheet 12114977bd2SMichael Hamann foreach ($mediatypes as $mediatype) { 12278a6aeb1SAndreas Gohr 123d15166e5SAndreas Gohr // print the default classes for interwiki links and file downloads 1246c47a78cSAnika Henke if ($mediatype == 'screen') { 125cacfb606SAnika Henke print '@media screen {'; 1261c2d1019SAndreas Gohr css_interwiki(); 127d15166e5SAndreas Gohr css_filetypes(); 128cacfb606SAnika Henke print '}'; 12978a6aeb1SAndreas Gohr } 13078a6aeb1SAndreas Gohr 1316c47a78cSAnika Henke // load files 1326c47a78cSAnika Henke $css_content = ''; 13314977bd2SMichael Hamann foreach($files[$mediatype] as $file => $location){ 1346c47a78cSAnika Henke $css_content .= css_loadfile($file, $location); 1356c47a78cSAnika Henke } 1366c47a78cSAnika Henke switch ($mediatype) { 1376c47a78cSAnika Henke case 'screen': 1386c47a78cSAnika Henke print NL.'@media screen { /* START screen styles */'.NL.$css_content.NL.'} /* /@media END screen styles */'.NL; 1396c47a78cSAnika Henke break; 1406c47a78cSAnika Henke case 'print': 1416c47a78cSAnika Henke print NL.'@media print { /* START print styles */'.NL.$css_content.NL.'} /* /@media END print styles */'.NL; 1426c47a78cSAnika Henke break; 1436c47a78cSAnika Henke case 'all': 1446c47a78cSAnika Henke case 'feed': 1456c47a78cSAnika Henke default: 1466c47a78cSAnika Henke print NL.'/* START rest styles */ '.NL.$css_content.NL.'/* END rest styles */'.NL; 1476c47a78cSAnika Henke break; 1486c47a78cSAnika Henke } 1496c47a78cSAnika Henke } 15078a6aeb1SAndreas Gohr // end output buffering and get contents 15178a6aeb1SAndreas Gohr $css = ob_get_contents(); 15278a6aeb1SAndreas Gohr ob_end_clean(); 15378a6aeb1SAndreas Gohr 1546e69c1baSAndreas Gohr // apply style replacements 155124af657SAndreas Gohr $css = css_applystyle($css,$tplinc); 1566e69c1baSAndreas Gohr 157*cbe37079SAndreas Gohr print $css; 158*cbe37079SAndreas Gohr 159*cbe37079SAndreas Gohr 160d4a1ece8SAndreas Gohr // parse LESS 161d4a1ece8SAndreas Gohr $less = new lessc(); 162d4a1ece8SAndreas Gohr $css = $less->compile($css); 163d4a1ece8SAndreas Gohr 164d4a1ece8SAndreas Gohr // place all remaining @import statements at the top of the file 165f7d780b9SGabriel Birke $css = css_moveimports($css); 166f7d780b9SGabriel Birke 16778a6aeb1SAndreas Gohr // compress whitespace and comments 16878a6aeb1SAndreas Gohr if($conf['compress']){ 16978a6aeb1SAndreas Gohr $css = css_compress($css); 17078a6aeb1SAndreas Gohr } 17178a6aeb1SAndreas Gohr 172809d3ba5SAndreas Gohr // embed small images right into the stylesheet 173809d3ba5SAndreas Gohr if($conf['cssdatauri']){ 174809d3ba5SAndreas Gohr $base = preg_quote(DOKU_BASE,'#'); 175809d3ba5SAndreas Gohr $css = preg_replace_callback('#(url\([ \'"]*)('.$base.')(.*?(?:\.(png|gif)))#i','css_datauri',$css); 176809d3ba5SAndreas Gohr } 177809d3ba5SAndreas Gohr 1786619f42eSAdrian Lang http_cached_finish($cache->cache, $css); 17978a6aeb1SAndreas Gohr} 18078a6aeb1SAndreas Gohr 18178a6aeb1SAndreas Gohr/** 1826e69c1baSAndreas Gohr * Does placeholder replacements in the style according to 1836e69c1baSAndreas Gohr * the ones defined in a templates style.ini file 1846e69c1baSAndreas Gohr * 185d4a1ece8SAndreas Gohr * This also adds the ini defined placeholders as less variables 186d4a1ece8SAndreas Gohr * (sans the surrounding __ and with a ini_ prefix) 187d4a1ece8SAndreas Gohr * 1886e69c1baSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1896e69c1baSAndreas Gohr */ 190124af657SAndreas Gohrfunction css_applystyle($css,$tplinc){ 1910e6f9f08SAnika Henke $styleini = css_styleini($tplinc); 1920e6f9f08SAnika Henke 1930e6f9f08SAnika Henke if($styleini){ 194*cbe37079SAndreas Gohr // we convert ini replacements to LESS variable names 195*cbe37079SAndreas Gohr // and build a list of variable: value; pairs 196d4a1ece8SAndreas Gohr $less = ''; 197c51b334eSAndreas Gohr foreach($styleini['replacements'] as $key => $value){ 198*cbe37079SAndreas Gohr $lkey = trim($key, '_'); 199*cbe37079SAndreas Gohr $lkey = '@ini_'.$lkey; 200*cbe37079SAndreas Gohr $less .= "$lkey: $value;\n"; 201*cbe37079SAndreas Gohr 202*cbe37079SAndreas Gohr $styleini['replacements'][$key] = $lkey; 203d4a1ece8SAndreas Gohr } 204c51b334eSAndreas Gohr 205*cbe37079SAndreas Gohr // we now replace all old ini replacements with LESS variables 206*cbe37079SAndreas Gohr $css = strtr($css, $styleini['replacements']); 207*cbe37079SAndreas Gohr 208*cbe37079SAndreas Gohr // now prepend the list of LESS variables as the very first thing 209c51b334eSAndreas Gohr $css = $less.$css; 2106e69c1baSAndreas Gohr } 2116e69c1baSAndreas Gohr return $css; 2126e69c1baSAndreas Gohr} 2136e69c1baSAndreas Gohr 2146e69c1baSAndreas Gohr/** 2150ac69508SAnika Henke * Get contents of merged style.ini and style.local.ini as an array. 2160ac69508SAnika Henke * 2170ac69508SAnika Henke * @author Anika Henke <anika@selfthinker.org> 2180e6f9f08SAnika Henke */ 2190e6f9f08SAnika Henkefunction css_styleini($tplinc) { 2200ac69508SAnika Henke $styleini = array(); 2210ac69508SAnika Henke 2220ac69508SAnika Henke foreach (array($tplinc.'style.ini', $tplinc.'style.local.ini') as $ini) { 2230ac69508SAnika Henke $tmp = (@file_exists($ini)) ? parse_ini_file($ini, true) : array(); 2240ac69508SAnika Henke 2250ac69508SAnika Henke foreach($tmp as $key => $value) { 2260ac69508SAnika Henke if(array_key_exists($key, $styleini) && is_array($value)) { 2270ac69508SAnika Henke $styleini[$key] = array_merge($styleini[$key], $tmp[$key]); 2280ac69508SAnika Henke } else { 2290ac69508SAnika Henke $styleini[$key] = $value; 2300ac69508SAnika Henke } 2310ac69508SAnika Henke } 2320ac69508SAnika Henke } 2330ac69508SAnika Henke return $styleini; 2340e6f9f08SAnika Henke} 2350e6f9f08SAnika Henke 2360e6f9f08SAnika Henke/** 2371c2d1019SAndreas Gohr * Prints classes for interwikilinks 2381c2d1019SAndreas Gohr * 2391c2d1019SAndreas Gohr * Interwiki links have two classes: 'interwiki' and 'iw_$name>' where 2401c2d1019SAndreas Gohr * $name is the identifier given in the config. All Interwiki links get 2411c2d1019SAndreas Gohr * an default style with a default icon. If a special icon is available 2421c2d1019SAndreas Gohr * for an interwiki URL it is set in it's own class. Both classes can be 2431c2d1019SAndreas Gohr * overwritten in the template or userstyles. 2441c2d1019SAndreas Gohr * 2451c2d1019SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 2461c2d1019SAndreas Gohr */ 2471c2d1019SAndreas Gohrfunction css_interwiki(){ 2481c2d1019SAndreas Gohr 2491c2d1019SAndreas Gohr // default style 2501c2d1019SAndreas Gohr echo 'a.interwiki {'; 2511c2d1019SAndreas Gohr echo ' background: transparent url('.DOKU_BASE.'lib/images/interwiki.png) 0px 1px no-repeat;'; 2527b4ea081Smarklundeberg echo ' padding: 1px 0px 1px 16px;'; 2531c2d1019SAndreas Gohr echo '}'; 2541c2d1019SAndreas Gohr 2551c2d1019SAndreas Gohr // additional styles when icon available 2561c2d1019SAndreas Gohr $iwlinks = getInterwiki(); 2571c2d1019SAndreas Gohr foreach(array_keys($iwlinks) as $iw){ 2589d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$iw); 2591c2d1019SAndreas Gohr if(@file_exists(DOKU_INC.'lib/images/interwiki/'.$iw.'.png')){ 2609d2ddea4SAndreas Gohr echo "a.iw_$class {"; 2611c2d1019SAndreas Gohr echo ' background-image: url('.DOKU_BASE.'lib/images/interwiki/'.$iw.'.png)'; 2621c2d1019SAndreas Gohr echo '}'; 2631c2d1019SAndreas Gohr }elseif(@file_exists(DOKU_INC.'lib/images/interwiki/'.$iw.'.gif')){ 2649d2ddea4SAndreas Gohr echo "a.iw_$class {"; 2651c2d1019SAndreas Gohr echo ' background-image: url('.DOKU_BASE.'lib/images/interwiki/'.$iw.'.gif)'; 2661c2d1019SAndreas Gohr echo '}'; 2671c2d1019SAndreas Gohr } 2681c2d1019SAndreas Gohr } 269d15166e5SAndreas Gohr} 2701c2d1019SAndreas Gohr 271d15166e5SAndreas Gohr/** 272d15166e5SAndreas Gohr * Prints classes for file download links 273d15166e5SAndreas Gohr * 274d15166e5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 275d15166e5SAndreas Gohr */ 276d15166e5SAndreas Gohrfunction css_filetypes(){ 277d15166e5SAndreas Gohr 278d15166e5SAndreas Gohr // default style 279035e07f1SKate Arzamastseva echo '.mediafile {'; 280d15166e5SAndreas Gohr echo ' background: transparent url('.DOKU_BASE.'lib/images/fileicons/file.png) 0px 1px no-repeat;'; 2815b77caf4SAndreas Gohr echo ' padding-left: 18px;'; 2825b77caf4SAndreas Gohr echo ' padding-bottom: 1px;'; 283d15166e5SAndreas Gohr echo '}'; 284d15166e5SAndreas Gohr 285d15166e5SAndreas Gohr // additional styles when icon available 28627bf7924STom N Harris // scan directory for all icons 28727bf7924STom N Harris $exts = array(); 28827bf7924STom N Harris if($dh = opendir(DOKU_INC.'lib/images/fileicons')){ 28927bf7924STom N Harris while(false !== ($file = readdir($dh))){ 29027bf7924STom N Harris if(preg_match('/([_\-a-z0-9]+(?:\.[_\-a-z0-9]+)*?)\.(png|gif)/i',$file,$match)){ 29127bf7924STom N Harris $ext = strtolower($match[1]); 29227bf7924STom N Harris $type = '.'.strtolower($match[2]); 29327bf7924STom N Harris if($ext!='file' && (!isset($exts[$ext]) || $type=='.png')){ 29427bf7924STom N Harris $exts[$ext] = $type; 295d15166e5SAndreas Gohr } 296d15166e5SAndreas Gohr } 2971c2d1019SAndreas Gohr } 29827bf7924STom N Harris closedir($dh); 29927bf7924STom N Harris } 30027bf7924STom N Harris foreach($exts as $ext=>$type){ 30127bf7924STom N Harris $class = preg_replace('/[^_\-a-z0-9]+/','_',$ext); 302035e07f1SKate Arzamastseva echo ".mf_$class {"; 30327bf7924STom N Harris echo ' background-image: url('.DOKU_BASE.'lib/images/fileicons/'.$ext.$type.')'; 30427bf7924STom N Harris echo '}'; 30527bf7924STom N Harris } 30627bf7924STom N Harris} 3071c2d1019SAndreas Gohr 3081c2d1019SAndreas Gohr/** 30978a6aeb1SAndreas Gohr * Loads a given file and fixes relative URLs with the 31078a6aeb1SAndreas Gohr * given location prefix 31178a6aeb1SAndreas Gohr */ 31278a6aeb1SAndreas Gohrfunction css_loadfile($file,$location=''){ 31378a6aeb1SAndreas Gohr if(!@file_exists($file)) return ''; 31478a6aeb1SAndreas Gohr $css = io_readFile($file); 31578a6aeb1SAndreas Gohr if(!$location) return $css; 31678a6aeb1SAndreas Gohr 317809d3ba5SAndreas Gohr $css = preg_replace('#(url\([ \'"]*)(?!/|data:|http://|https://| |\'|")#','\\1'.$location,$css); 318809d3ba5SAndreas Gohr $css = preg_replace('#(@import\s+[\'"])(?!/|data:|http://|https://)#', '\\1'.$location, $css); 319809d3ba5SAndreas Gohr 32078a6aeb1SAndreas Gohr return $css; 32178a6aeb1SAndreas Gohr} 32278a6aeb1SAndreas Gohr 323809d3ba5SAndreas Gohr/** 324809d3ba5SAndreas Gohr * Converte local image URLs to data URLs if the filesize is small 325809d3ba5SAndreas Gohr * 326809d3ba5SAndreas Gohr * Callback for preg_replace_callback 327809d3ba5SAndreas Gohr */ 328809d3ba5SAndreas Gohrfunction css_datauri($match){ 32928f4004cSAndreas Gohr global $conf; 33028f4004cSAndreas Gohr 331809d3ba5SAndreas Gohr $pre = unslash($match[1]); 332809d3ba5SAndreas Gohr $base = unslash($match[2]); 333809d3ba5SAndreas Gohr $url = unslash($match[3]); 334809d3ba5SAndreas Gohr $ext = unslash($match[4]); 335809d3ba5SAndreas Gohr 336809d3ba5SAndreas Gohr $local = DOKU_INC.$url; 337809d3ba5SAndreas Gohr $size = @filesize($local); 33828f4004cSAndreas Gohr if($size && $size < $conf['cssdatauri']){ 339809d3ba5SAndreas Gohr $data = base64_encode(file_get_contents($local)); 340809d3ba5SAndreas Gohr } 341809d3ba5SAndreas Gohr if($data){ 342809d3ba5SAndreas Gohr $url = 'data:image/'.$ext.';base64,'.$data; 343809d3ba5SAndreas Gohr }else{ 344809d3ba5SAndreas Gohr $url = $base.$url; 345809d3ba5SAndreas Gohr } 346809d3ba5SAndreas Gohr return $pre.$url; 347809d3ba5SAndreas Gohr} 348809d3ba5SAndreas Gohr 34915c394afSAndreas Gohr 35078a6aeb1SAndreas Gohr/** 35178a6aeb1SAndreas Gohr * Returns a list of possible Plugin Styles (no existance check here) 35278a6aeb1SAndreas Gohr * 35378a6aeb1SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 35478a6aeb1SAndreas Gohr */ 355318cd03eSAnika Henkefunction css_pluginstyles($mediatype='screen'){ 356208c0215SAndreas Gohr global $lang; 35778a6aeb1SAndreas Gohr $list = array(); 35878a6aeb1SAndreas Gohr $plugins = plugin_list(); 35978a6aeb1SAndreas Gohr foreach ($plugins as $p){ 360318cd03eSAnika Henke $list[DOKU_PLUGIN."$p/$mediatype.css"] = DOKU_BASE."lib/plugins/$p/"; 361d4a1ece8SAndreas Gohr $list[DOKU_PLUGIN."$p/$mediatype.less"] = DOKU_BASE."lib/plugins/$p/"; 362318cd03eSAnika Henke // alternative for screen.css 363318cd03eSAnika Henke if ($mediatype=='screen') { 36478a6aeb1SAndreas Gohr $list[DOKU_PLUGIN."$p/style.css"] = DOKU_BASE."lib/plugins/$p/"; 365d4a1ece8SAndreas Gohr $list[DOKU_PLUGIN."$p/style.less"] = DOKU_BASE."lib/plugins/$p/"; 36678a6aeb1SAndreas Gohr } 3676c47a78cSAnika Henke // @deprecated 2012-04-09: rtl will cease to be a mode of its own, 3686c47a78cSAnika Henke // please use "[dir=rtl]" in any css file in all, screen or print mode instead 369208c0215SAndreas Gohr if($lang['direction'] == 'rtl'){ 370208c0215SAndreas Gohr $list[DOKU_PLUGIN."$p/rtl.css"] = DOKU_BASE."lib/plugins/$p/"; 371d4a1ece8SAndreas Gohr $list[DOKU_PLUGIN."$p/rtl.less"] = DOKU_BASE."lib/plugins/$p/"; 372208c0215SAndreas Gohr } 37378a6aeb1SAndreas Gohr } 37478a6aeb1SAndreas Gohr return $list; 37578a6aeb1SAndreas Gohr} 37678a6aeb1SAndreas Gohr 37778a6aeb1SAndreas Gohr/** 378f7d780b9SGabriel Birke * Move all @import statements in a combined stylesheet to the top so they 379f7d780b9SGabriel Birke * aren't ignored by the browser. 380f7d780b9SGabriel Birke * 381f7d780b9SGabriel Birke * @author Gabriel Birke <birke@d-scribe.de> 382f7d780b9SGabriel Birke */ 383f7d780b9SGabriel Birkefunction css_moveimports($css) 384f7d780b9SGabriel Birke{ 385f7d780b9SGabriel Birke if(!preg_match_all('/@import\s+(?:url\([^)]+\)|"[^"]+")\s*[^;]*;\s*/', $css, $matches, PREG_OFFSET_CAPTURE)) { 386f7d780b9SGabriel Birke return $css; 387f7d780b9SGabriel Birke } 388f7d780b9SGabriel Birke $newCss = ""; 389f7d780b9SGabriel Birke $imports = ""; 390f7d780b9SGabriel Birke $offset = 0; 391f7d780b9SGabriel Birke foreach($matches[0] as $match) { 392f7d780b9SGabriel Birke $newCss .= substr($css, $offset, $match[1] - $offset); 393f7d780b9SGabriel Birke $imports .= $match[0]; 394f7d780b9SGabriel Birke $offset = $match[1] + strlen($match[0]); 395f7d780b9SGabriel Birke } 396f7d780b9SGabriel Birke $newCss .= substr($css, $offset); 397f7d780b9SGabriel Birke return $imports.$newCss; 398f7d780b9SGabriel Birke} 399f7d780b9SGabriel Birke 400f7d780b9SGabriel Birke/** 40178a6aeb1SAndreas Gohr * Very simple CSS optimizer 40278a6aeb1SAndreas Gohr * 40378a6aeb1SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 40478a6aeb1SAndreas Gohr */ 40578a6aeb1SAndreas Gohrfunction css_compress($css){ 406fd7c2db0SAndreas Gohr //strip comments through a callback 407fd7c2db0SAndreas Gohr $css = preg_replace_callback('#(/\*)(.*?)(\*/)#s','css_comment_cb',$css); 408fd7c2db0SAndreas Gohr 409247c1c5dSAndreas Gohr //strip (incorrect but common) one line comments 410fd7c2db0SAndreas Gohr $css = preg_replace('/(?<!:)\/\/.*$/m','',$css); 411247c1c5dSAndreas Gohr 41278a6aeb1SAndreas Gohr // strip whitespaces 41378a6aeb1SAndreas Gohr $css = preg_replace('![\r\n\t ]+!',' ',$css); 414f5379589SChristopher Smith $css = preg_replace('/ ?([;,{}\/]) ?/','\\1',$css); 415f5379589SChristopher Smith $css = preg_replace('/ ?: /',':',$css); 41678a6aeb1SAndreas Gohr 41778a6aeb1SAndreas Gohr // shorten colors 41878a6aeb1SAndreas 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); 41978a6aeb1SAndreas Gohr 42078a6aeb1SAndreas Gohr return $css; 42178a6aeb1SAndreas Gohr} 42278a6aeb1SAndreas Gohr 423c00aef76SAndreas Gohr/** 424c00aef76SAndreas Gohr * Callback for css_compress() 425c00aef76SAndreas Gohr * 426c00aef76SAndreas Gohr * Keeps short comments (< 5 chars) to maintain typical browser hacks 427c00aef76SAndreas Gohr * 428c00aef76SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 429c00aef76SAndreas Gohr */ 430c00aef76SAndreas Gohrfunction css_comment_cb($matches){ 431c00aef76SAndreas Gohr if(strlen($matches[2]) > 4) return ''; 432c00aef76SAndreas Gohr return $matches[0]; 433c00aef76SAndreas Gohr} 43478a6aeb1SAndreas Gohr 435e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 436