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 35de4634ecSGerry Weißbach if ($INPUT->str('s') == 'feed') { 36de4634ecSGerry Weißbach $mediatypes = array('feed'); 378930b69dSGerry Weißbach $type = 'feed'; 38de4634ecSGerry Weißbach } else { 395d48a5eaSGerry Weißbach $mediatypes = array('screen', 'all', 'print', 'speech'); 408930b69dSGerry Weißbach $type = ''; 41de4634ecSGerry Weißbach } 42de4634ecSGerry Weißbach 4320a2375aSAndreas Gohr // decide from where to get the template 4420a2375aSAndreas Gohr $tpl = trim(preg_replace('/[^\w-]+/','',$INPUT->str('t'))); 4520a2375aSAndreas Gohr if(!$tpl) $tpl = $conf['template']; 4620a2375aSAndreas Gohr 4720a2375aSAndreas Gohr // load styl.ini 48*3e32b194SGerry Weißbach $styleini = css_styleini($tpl $INPUT->bool('preview')); 4920a2375aSAndreas Gohr 50afb2c082SAndreas Gohr // cache influencers 51259571aaSMichal Koutný $tplinc = tpl_incdir($tpl); 52afb2c082SAndreas Gohr $cache_files = getConfigFiles('main'); 53afb2c082SAndreas Gohr $cache_files[] = $tplinc.'style.ini'; 54afb2c082SAndreas Gohr $cache_files[] = DOKU_CONF."tpl/$tpl/style.ini"; 5582edff4dSGerry Weißbach $cache_files[] = DOKU_CONF."tpl/$tpl/ini/".$flavour.".ini"; 56afb2c082SAndreas Gohr $cache_files[] = __FILE__; 574d6524b8SAndreas Gohr if($INPUT->bool('preview')) $cache_files[] = $conf['cachedir'].'/preview.ini'; 58afb2c082SAndreas Gohr 5978a6aeb1SAndreas Gohr // Array of needed files and their web locations, the latter ones 6078a6aeb1SAndreas Gohr // are needed to fix relative paths in the stylesheets 61ef36714bSGerry Weißbach $media_files = array(); 6214977bd2SMichael Hamann foreach($mediatypes as $mediatype) { 63ef36714bSGerry Weißbach $files = array(); 64*3e32b194SGerry Weißbach 65318cd03eSAnika Henke // load core styles 66ef36714bSGerry Weißbach $files[DOKU_INC.'lib/styles/'.$mediatype.'.css'] = DOKU_BASE.'lib/styles/'; 67af4684acSAndreas Gohr 6843576758SAndreas Gohr // load jQuery-UI theme 696c47a78cSAnika Henke if ($mediatype == 'screen') { 70ef36714bSGerry Weißbach $files[DOKU_INC.'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE.'lib/scripts/jquery/jquery-ui-theme/'; 716c47a78cSAnika Henke } 72318cd03eSAnika Henke // load plugin styles 73ef36714bSGerry Weißbach $files = array_merge($files, css_pluginstyles($mediatype)); 74318cd03eSAnika Henke // load template styles 75afb2c082SAndreas Gohr if (isset($styleini['stylesheets'][$mediatype])) { 76ef36714bSGerry Weißbach $files = array_merge($files, $styleini['stylesheets'][$mediatype]); 7709edb711SAndreas Gohr } 78318cd03eSAnika Henke // load user styles 797b909d5eSGerrit Uitslag if(!empty($config_cascade['userstyle'][$mediatype])) { 807b909d5eSGerrit Uitslag foreach($config_cascade['userstyle'][$mediatype] as $userstyle) { 81ef36714bSGerry Weißbach $files[$userstyle] = DOKU_BASE; 827b909d5eSGerrit Uitslag } 83318cd03eSAnika Henke } 8478a6aeb1SAndreas Gohr 85ef36714bSGerry Weißbach // Let plugins decide to either put more styles here or to remove some 86*3e32b194SGerry Weißbach $media_files[$mediatype] = css_filewrapper($mediatype, $files); 87ef36714bSGerry Weißbach $CSSEvt = new Doku_Event('CSS_STYLES_INCLUDED', $media_files[$mediatype]); 88ef36714bSGerry Weißbach 89ef36714bSGerry Weißbach // Make it preventable. 90ef36714bSGerry Weißbach if ( $CSSEvt->advise_before() ) { 91ef36714bSGerry Weißbach $cache_files = array_merge($cache_files, array_keys($media_files[$mediatype]['files'])); 92ef36714bSGerry Weißbach } else { 93ef36714bSGerry Weißbach // unset if prevented. Nothing will be printed for this mediatype. 94ef36714bSGerry Weißbach unset($media_files[$mediatype]); 9514977bd2SMichael Hamann } 966619f42eSAdrian Lang 97ef36714bSGerry Weißbach // finish event. 98ef36714bSGerry Weißbach $CSSEvt->advise_after(); 99ef36714bSGerry Weißbach } 100ef36714bSGerry Weißbach 101ef36714bSGerry Weißbach // The generated script depends on some dynamic options 102*3e32b194SGerry Weißbach $cache = new cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tpl.$type,'.css'); 103ef36714bSGerry Weißbach $cache->_event = 'CSS_CACHE_USE'; 104ef36714bSGerry Weißbach 10538f56bffSBen Coburn // check cache age & handle conditional request 1066619f42eSAdrian Lang // This may exit if a cache can be used 1078d721324SGerry Weißbach http_cached($cache->cache, 1088d721324SGerry Weißbach $cache->useCache(array('files' => $cache_files))); 10978a6aeb1SAndreas Gohr 1103899c2ecSMichael Hamann // start output buffering 1113899c2ecSMichael Hamann ob_start(); 1123899c2ecSMichael Hamann 113ef36714bSGerry Weißbach // Fire CSS_STYLES_INCLUDED for one last time to let the 114ef36714bSGerry Weißbach // plugins decide whether to include the DW default styles. 115ef36714bSGerry Weißbach // This can be done by preventing the Default. 116ef36714bSGerry Weißbach $media_files['DW_DEFAULT'] = css_filewrapper('DW_DEFAULT'); 117ef36714bSGerry Weißbach trigger_event('CSS_STYLES_INCLUDED', $media_files['DW_DEFAULT'], 'css_defaultstyles'); 118ef36714bSGerry Weißbach 1196c47a78cSAnika Henke // build the stylesheet 12014977bd2SMichael Hamann foreach ($mediatypes as $mediatype) { 12178a6aeb1SAndreas Gohr 122ef36714bSGerry Weißbach // Check if there is a wrapper set for this type. 123ef36714bSGerry Weißbach if ( !isset($media_files[$mediatype]) ) { 124ef36714bSGerry Weißbach continue; 12578a6aeb1SAndreas Gohr } 12678a6aeb1SAndreas Gohr 127ef36714bSGerry Weißbach $cssData = $media_files[$mediatype]; 128ef36714bSGerry Weißbach 129ef36714bSGerry Weißbach // Print the styles. 130ef36714bSGerry Weißbach print NL; 131ef36714bSGerry Weißbach if ( $cssData['encapsulate'] === true ) print $cssData['encapsulationPrefix'] . ' {'; 132ef36714bSGerry Weißbach print '/* START '.$cssData['mediatype'].' styles */'.NL; 133ef36714bSGerry Weißbach 1346c47a78cSAnika Henke // load files 135ef36714bSGerry Weißbach foreach($cssData['files'] as $file => $location){ 13672a66eb7SAndreas Gohr $display = str_replace(fullpath(DOKU_INC), '', fullpath($file)); 137ef36714bSGerry Weißbach print "\n/* XXXXXXXXX $display XXXXXXXXX */\n"; 138ef36714bSGerry Weißbach print css_loadfile($file, $location); 1396c47a78cSAnika Henke } 140ef36714bSGerry Weißbach 141ef36714bSGerry Weißbach print NL; 142ef36714bSGerry Weißbach if ( $cssData['encapsulate'] === true ) print '} /* /@media '; 143ef36714bSGerry Weißbach else print '/*'; 144ef36714bSGerry Weißbach print ' END '.$cssData['mediatype'].' styles */'.NL; 1456c47a78cSAnika Henke } 146ef36714bSGerry Weißbach 14778a6aeb1SAndreas Gohr // end output buffering and get contents 14878a6aeb1SAndreas Gohr $css = ob_get_contents(); 14978a6aeb1SAndreas Gohr ob_end_clean(); 15078a6aeb1SAndreas Gohr 151f8fb2d18SAndreas Gohr // strip any source maps 152f8fb2d18SAndreas Gohr stripsourcemaps($css); 153f8fb2d18SAndreas Gohr 1546e69c1baSAndreas Gohr // apply style replacements 155afb2c082SAndreas Gohr $css = css_applystyle($css, $styleini['replacements']); 1566e69c1baSAndreas Gohr 15772a66eb7SAndreas Gohr // parse less 15872a66eb7SAndreas Gohr $css = css_parseless($css); 159d4a1ece8SAndreas Gohr 16078a6aeb1SAndreas Gohr // compress whitespace and comments 16178a6aeb1SAndreas Gohr if($conf['compress']){ 16278a6aeb1SAndreas Gohr $css = css_compress($css); 16378a6aeb1SAndreas Gohr } 16478a6aeb1SAndreas Gohr 165809d3ba5SAndreas Gohr // embed small images right into the stylesheet 166809d3ba5SAndreas Gohr if($conf['cssdatauri']){ 167809d3ba5SAndreas Gohr $base = preg_quote(DOKU_BASE,'#'); 168809d3ba5SAndreas Gohr $css = preg_replace_callback('#(url\([ \'"]*)('.$base.')(.*?(?:\.(png|gif)))#i','css_datauri',$css); 169809d3ba5SAndreas Gohr } 170809d3ba5SAndreas Gohr 1716619f42eSAdrian Lang http_cached_finish($cache->cache, $css); 17278a6aeb1SAndreas Gohr} 17378a6aeb1SAndreas Gohr 17478a6aeb1SAndreas Gohr/** 17572a66eb7SAndreas Gohr * Uses phpless to parse LESS in our CSS 17672a66eb7SAndreas Gohr * 17772a66eb7SAndreas Gohr * most of this function is error handling to show a nice useful error when 17872a66eb7SAndreas Gohr * LESS compilation fails 17972a66eb7SAndreas Gohr * 180253d4b48SGerrit Uitslag * @param string $css 18172a66eb7SAndreas Gohr * @return string 18272a66eb7SAndreas Gohr */ 18372a66eb7SAndreas Gohrfunction css_parseless($css) { 1847d247a3cSGerrit Uitslag global $conf; 1857d247a3cSGerrit Uitslag 18672a66eb7SAndreas Gohr $less = new lessc(); 187343a31d8SAndreas Gohr $less->importDir = array(DOKU_INC); 1887d247a3cSGerrit Uitslag $less->setPreserveComments(!$conf['compress']); 18930f686ebSChristopher Smith 19030f686ebSChristopher Smith if (defined('DOKU_UNITTEST')){ 19130f686ebSChristopher Smith $less->importDir[] = TMP_DIR; 19230f686ebSChristopher Smith } 19330f686ebSChristopher Smith 19472a66eb7SAndreas Gohr try { 19572a66eb7SAndreas Gohr return $less->compile($css); 19672a66eb7SAndreas Gohr } catch(Exception $e) { 19772a66eb7SAndreas Gohr // get exception message 19872a66eb7SAndreas Gohr $msg = str_replace(array("\n", "\r", "'"), array(), $e->getMessage()); 19972a66eb7SAndreas Gohr 20072a66eb7SAndreas Gohr // try to use line number to find affected file 20172a66eb7SAndreas Gohr if(preg_match('/line: (\d+)$/', $msg, $m)){ 20272a66eb7SAndreas Gohr $msg = substr($msg, 0, -1* strlen($m[0])); //remove useless linenumber 20372a66eb7SAndreas Gohr $lno = $m[1]; 20472a66eb7SAndreas Gohr 20572a66eb7SAndreas Gohr // walk upwards to last include 20672a66eb7SAndreas Gohr $lines = explode("\n", $css); 20772a66eb7SAndreas Gohr for($i=$lno-1; $i>=0; $i--){ 20872a66eb7SAndreas Gohr if(preg_match('/\/(\* XXXXXXXXX )(.*?)( XXXXXXXXX \*)\//', $lines[$i], $m)){ 20972a66eb7SAndreas Gohr // we found it, add info to message 21072a66eb7SAndreas Gohr $msg .= ' in '.$m[2].' at line '.($lno-$i); 21172a66eb7SAndreas Gohr break; 21272a66eb7SAndreas Gohr } 21372a66eb7SAndreas Gohr } 21472a66eb7SAndreas Gohr } 21572a66eb7SAndreas Gohr 21672a66eb7SAndreas Gohr // something went wrong 21772a66eb7SAndreas Gohr $error = 'A fatal error occured during compilation of the CSS files. '. 21872a66eb7SAndreas Gohr 'If you recently installed a new plugin or template it '. 21972a66eb7SAndreas Gohr 'might be broken and you should try disabling it again. ['.$msg.']'; 22072a66eb7SAndreas Gohr 22172a66eb7SAndreas Gohr echo ".dokuwiki:before { 22272a66eb7SAndreas Gohr content: '$error'; 22372a66eb7SAndreas Gohr background-color: red; 22472a66eb7SAndreas Gohr display: block; 22572a66eb7SAndreas Gohr background-color: #fcc; 22672a66eb7SAndreas Gohr border-color: #ebb; 22772a66eb7SAndreas Gohr color: #000; 22872a66eb7SAndreas Gohr padding: 0.5em; 22972a66eb7SAndreas Gohr }"; 23072a66eb7SAndreas Gohr 23172a66eb7SAndreas Gohr exit; 23272a66eb7SAndreas Gohr } 23372a66eb7SAndreas Gohr} 23472a66eb7SAndreas Gohr 23572a66eb7SAndreas Gohr/** 2366e69c1baSAndreas Gohr * Does placeholder replacements in the style according to 2376e69c1baSAndreas Gohr * the ones defined in a templates style.ini file 2386e69c1baSAndreas Gohr * 239d4a1ece8SAndreas Gohr * This also adds the ini defined placeholders as less variables 240d4a1ece8SAndreas Gohr * (sans the surrounding __ and with a ini_ prefix) 241d4a1ece8SAndreas Gohr * 2426e69c1baSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 243253d4b48SGerrit Uitslag * 244253d4b48SGerrit Uitslag * @param string $css 245253d4b48SGerrit Uitslag * @param array $replacements array(placeholder => value) 246253d4b48SGerrit Uitslag * @return string 2476e69c1baSAndreas Gohr */ 248afb2c082SAndreas Gohrfunction css_applystyle($css, $replacements) { 249cbe37079SAndreas Gohr // we convert ini replacements to LESS variable names 250cbe37079SAndreas Gohr // and build a list of variable: value; pairs 251d4a1ece8SAndreas Gohr $less = ''; 252afb2c082SAndreas Gohr foreach((array) $replacements as $key => $value) { 253cbe37079SAndreas Gohr $lkey = trim($key, '_'); 254cbe37079SAndreas Gohr $lkey = '@ini_'.$lkey; 255cbe37079SAndreas Gohr $less .= "$lkey: $value;\n"; 256cbe37079SAndreas Gohr 257afb2c082SAndreas Gohr $replacements[$key] = $lkey; 258d4a1ece8SAndreas Gohr } 259c51b334eSAndreas Gohr 260cbe37079SAndreas Gohr // we now replace all old ini replacements with LESS variables 261afb2c082SAndreas Gohr $css = strtr($css, $replacements); 262cbe37079SAndreas Gohr 263cbe37079SAndreas Gohr // now prepend the list of LESS variables as the very first thing 264c51b334eSAndreas Gohr $css = $less.$css; 2656e69c1baSAndreas Gohr return $css; 2666e69c1baSAndreas Gohr} 2676e69c1baSAndreas Gohr 2686e69c1baSAndreas Gohr/** 269afb2c082SAndreas Gohr * Load style ini contents 2700ac69508SAnika Henke * 271afb2c082SAndreas Gohr * Loads and merges style.ini files from template and config and prepares 272afb2c082SAndreas Gohr * the stylesheet modes 273afb2c082SAndreas Gohr * 274afb2c082SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 275253d4b48SGerrit Uitslag * 276afb2c082SAndreas Gohr * @param string $tpl the used template 2774d6524b8SAndreas Gohr * @param bool $preview load preview replacements 278afb2c082SAndreas Gohr * @return array with keys 'stylesheets' and 'replacements' 2790e6f9f08SAnika Henke */ 280*3e32b194SGerry Weißbachfunction css_styleini($tpl, $preview=false) { 2814d6524b8SAndreas Gohr global $conf; 2824d6524b8SAndreas Gohr 283afb2c082SAndreas Gohr $stylesheets = array(); // mode, file => base 284afb2c082SAndreas Gohr $replacements = array(); // placeholder => value 2850ac69508SAnika Henke 286*3e32b194SGerry Weißbach // load template's style.ini 287afb2c082SAndreas Gohr $incbase = tpl_incdir($tpl); 288afb2c082SAndreas Gohr $webbase = tpl_basedir($tpl); 289*3e32b194SGerry Weißbach $ini = $incbase.'style.ini'; 290afb2c082SAndreas Gohr if(file_exists($ini)){ 291afb2c082SAndreas Gohr $data = parse_ini_file($ini, true); 2920ac69508SAnika Henke 293afb2c082SAndreas Gohr // stylesheets 294afb2c082SAndreas Gohr if(is_array($data['stylesheets'])) foreach($data['stylesheets'] as $file => $mode){ 295afb2c082SAndreas Gohr $stylesheets[$mode][$incbase.$file] = $webbase; 296afb2c082SAndreas Gohr } 297*3e32b194SGerry Weißbach 298afb2c082SAndreas Gohr // replacements 299*3e32b194SGerry Weißbach if(is_array($data['replacements'])){ 30047f862d1SChristopher Smith $replacements = array_merge($replacements, css_fixreplacementurls($data['replacements'],$webbase)); 3010ac69508SAnika Henke } 3020ac69508SAnika Henke } 303afb2c082SAndreas Gohr 304afb2c082SAndreas Gohr // load configs's style.ini 305afb2c082SAndreas Gohr $webbase = DOKU_BASE; 3068c5aad7bSAnika Henke $ini = DOKU_CONF."tpl/$tpl/style.ini"; 3078c5aad7bSAnika Henke $incbase = dirname($ini).'/'; 308afb2c082SAndreas Gohr if(file_exists($ini)){ 309afb2c082SAndreas Gohr $data = parse_ini_file($ini, true); 310afb2c082SAndreas Gohr 311*3e32b194SGerry Weißbach // stylesheets 312*3e32b194SGerry Weißbach if(isset($data['stylesheets']) && is_array($data['stylesheets'])) foreach($data['stylesheets'] as $file => $mode){ 313afb2c082SAndreas Gohr $stylesheets[$mode][$incbase.$file] = $webbase; 3140ac69508SAnika Henke } 315*3e32b194SGerry Weißbach 316afb2c082SAndreas Gohr // replacements 31706c9ee33SMarius van Witzenburg if(isset($data['replacements']) && is_array($data['replacements'])){ 31847f862d1SChristopher Smith $replacements = array_merge($replacements, css_fixreplacementurls($data['replacements'],$webbase)); 319afb2c082SAndreas Gohr } 320afb2c082SAndreas Gohr } 321afb2c082SAndreas Gohr 3224d6524b8SAndreas Gohr // allow replacement overwrites in preview mode 3234d6524b8SAndreas Gohr if($preview) { 3244d6524b8SAndreas Gohr $webbase = DOKU_BASE; 3254d6524b8SAndreas Gohr $ini = $conf['cachedir'].'/preview.ini'; 3264d6524b8SAndreas Gohr if(file_exists($ini)) { 3274d6524b8SAndreas Gohr $data = parse_ini_file($ini, true); 3284d6524b8SAndreas Gohr // replacements 3294d6524b8SAndreas Gohr if(is_array($data['replacements'])) { 3304d6524b8SAndreas Gohr $replacements = array_merge($replacements, css_fixreplacementurls($data['replacements'], $webbase)); 3314d6524b8SAndreas Gohr } 3324d6524b8SAndreas Gohr } 3334d6524b8SAndreas Gohr } 3344d6524b8SAndreas Gohr 335afb2c082SAndreas Gohr return array( 336afb2c082SAndreas Gohr 'stylesheets' => $stylesheets, 337afb2c082SAndreas Gohr 'replacements' => $replacements 338afb2c082SAndreas Gohr ); 3390e6f9f08SAnika Henke} 3400e6f9f08SAnika Henke 3411e2c5948SChristopher Smith/** 3421e2c5948SChristopher Smith * Amend paths used in replacement relative urls, refer FS#2879 3431e2c5948SChristopher Smith * 3441e2c5948SChristopher Smith * @author Chris Smith <chris@jalakai.co.uk> 345253d4b48SGerrit Uitslag * 346253d4b48SGerrit Uitslag * @param array $replacements with key-value pairs 347253d4b48SGerrit Uitslag * @param string $location 348253d4b48SGerrit Uitslag * @return array 3491e2c5948SChristopher Smith */ 35047f862d1SChristopher Smithfunction css_fixreplacementurls($replacements, $location) { 35147f862d1SChristopher Smith foreach($replacements as $key => $value) { 35247f862d1SChristopher Smith $replacements[$key] = preg_replace('#(url\([ \'"]*)(?!/|data:|http://|https://| |\'|")#','\\1'.$location,$value); 35347f862d1SChristopher Smith } 35447f862d1SChristopher Smith return $replacements; 35547f862d1SChristopher Smith} 35647f862d1SChristopher Smith 3570e6f9f08SAnika Henke/** 358ef36714bSGerry Weißbach * Wrapper for the files, content and mediatype for the event CSS_STYLES_INCLUDED 359ef36714bSGerry Weißbach * 360ef36714bSGerry Weißbach * @author Gerry Weißbach <gerry.w@gammaproduction.de> 361ef36714bSGerry Weißbach * 362ef36714bSGerry Weißbach * @param string $mediatype type ofthe current media files/content set 363ef36714bSGerry Weißbach * @param array $files set of files that define the current mediatype 364ef36714bSGerry Weißbach * @return array 365ef36714bSGerry Weißbach */ 366*3e32b194SGerry Weißbachfunction css_filewrapper($mediatype, $files=array()){ 367ef36714bSGerry Weißbach return array( 368ef36714bSGerry Weißbach 'files' => $files, 369ef36714bSGerry Weißbach 'mediatype' => $mediatype, 370*3e32b194SGerry Weißbach 'encapsulate' => in_array($mediatype, array('screen', 'print', 'speech')), 371ef36714bSGerry Weißbach 'encapsulationPrefix' => '@media '.$mediatype 372ef36714bSGerry Weißbach ); 373ef36714bSGerry Weißbach} 374ef36714bSGerry Weißbach 375ef36714bSGerry Weißbach/** 376ef36714bSGerry Weißbach * Prints the @media encapsulated default styles of DokuWiki 377ef36714bSGerry Weißbach * 378ef36714bSGerry Weißbach * @author Gerry Weißbach <gerry.w@gammaproduction.de> 379ef36714bSGerry Weißbach * 380ef36714bSGerry Weißbach * This function is being called by a CSS_STYLES_INCLUDED event 381ef36714bSGerry Weißbach * The event can be distinguished by the mediatype which is: 382ef36714bSGerry Weißbach * DW_DEFAULT 383ef36714bSGerry Weißbach */ 384ef36714bSGerry Weißbachfunction css_defaultstyles(){ 385ef36714bSGerry Weißbach // print the default classes for interwiki links and file downloads 386ef36714bSGerry Weißbach print '@media screen {'; 387ef36714bSGerry Weißbach css_interwiki(); 388ef36714bSGerry Weißbach css_filetypes(); 389ef36714bSGerry Weißbach print '}'; 390ef36714bSGerry Weißbach} 391ef36714bSGerry Weißbach 392ef36714bSGerry Weißbach/** 3931c2d1019SAndreas Gohr * Prints classes for interwikilinks 3941c2d1019SAndreas Gohr * 3951c2d1019SAndreas Gohr * Interwiki links have two classes: 'interwiki' and 'iw_$name>' where 3961c2d1019SAndreas Gohr * $name is the identifier given in the config. All Interwiki links get 3971c2d1019SAndreas Gohr * an default style with a default icon. If a special icon is available 3981c2d1019SAndreas Gohr * for an interwiki URL it is set in it's own class. Both classes can be 3991c2d1019SAndreas Gohr * overwritten in the template or userstyles. 4001c2d1019SAndreas Gohr * 4011c2d1019SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 4021c2d1019SAndreas Gohr */ 4031c2d1019SAndreas Gohrfunction css_interwiki(){ 4041c2d1019SAndreas Gohr 4051c2d1019SAndreas Gohr // default style 4061c2d1019SAndreas Gohr echo 'a.interwiki {'; 4071c2d1019SAndreas Gohr echo ' background: transparent url('.DOKU_BASE.'lib/images/interwiki.png) 0px 1px no-repeat;'; 4087b4ea081Smarklundeberg echo ' padding: 1px 0px 1px 16px;'; 4091c2d1019SAndreas Gohr echo '}'; 4101c2d1019SAndreas Gohr 4111c2d1019SAndreas Gohr // additional styles when icon available 4121c2d1019SAndreas Gohr $iwlinks = getInterwiki(); 4131c2d1019SAndreas Gohr foreach(array_keys($iwlinks) as $iw){ 4149d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$iw); 41579e79377SAndreas Gohr if(file_exists(DOKU_INC.'lib/images/interwiki/'.$iw.'.png')){ 4169d2ddea4SAndreas Gohr echo "a.iw_$class {"; 4171c2d1019SAndreas Gohr echo ' background-image: url('.DOKU_BASE.'lib/images/interwiki/'.$iw.'.png)'; 4181c2d1019SAndreas Gohr echo '}'; 41979e79377SAndreas Gohr }elseif(file_exists(DOKU_INC.'lib/images/interwiki/'.$iw.'.gif')){ 4209d2ddea4SAndreas Gohr echo "a.iw_$class {"; 4211c2d1019SAndreas Gohr echo ' background-image: url('.DOKU_BASE.'lib/images/interwiki/'.$iw.'.gif)'; 4221c2d1019SAndreas Gohr echo '}'; 4231c2d1019SAndreas Gohr } 4241c2d1019SAndreas Gohr } 425d15166e5SAndreas Gohr} 4261c2d1019SAndreas Gohr 427d15166e5SAndreas Gohr/** 428d15166e5SAndreas Gohr * Prints classes for file download links 429d15166e5SAndreas Gohr * 430d15166e5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 431d15166e5SAndreas Gohr */ 432d15166e5SAndreas Gohrfunction css_filetypes(){ 433d15166e5SAndreas Gohr 434d15166e5SAndreas Gohr // default style 435035e07f1SKate Arzamastseva echo '.mediafile {'; 436d15166e5SAndreas Gohr echo ' background: transparent url('.DOKU_BASE.'lib/images/fileicons/file.png) 0px 1px no-repeat;'; 4375b77caf4SAndreas Gohr echo ' padding-left: 18px;'; 4385b77caf4SAndreas Gohr echo ' padding-bottom: 1px;'; 439d15166e5SAndreas Gohr echo '}'; 440d15166e5SAndreas Gohr 441d15166e5SAndreas Gohr // additional styles when icon available 44227bf7924STom N Harris // scan directory for all icons 44327bf7924STom N Harris $exts = array(); 44427bf7924STom N Harris if($dh = opendir(DOKU_INC.'lib/images/fileicons')){ 44527bf7924STom N Harris while(false !== ($file = readdir($dh))){ 44627bf7924STom N Harris if(preg_match('/([_\-a-z0-9]+(?:\.[_\-a-z0-9]+)*?)\.(png|gif)/i',$file,$match)){ 44727bf7924STom N Harris $ext = strtolower($match[1]); 44827bf7924STom N Harris $type = '.'.strtolower($match[2]); 44927bf7924STom N Harris if($ext!='file' && (!isset($exts[$ext]) || $type=='.png')){ 45027bf7924STom N Harris $exts[$ext] = $type; 451d15166e5SAndreas Gohr } 452d15166e5SAndreas Gohr } 4531c2d1019SAndreas Gohr } 45427bf7924STom N Harris closedir($dh); 45527bf7924STom N Harris } 45627bf7924STom N Harris foreach($exts as $ext=>$type){ 45727bf7924STom N Harris $class = preg_replace('/[^_\-a-z0-9]+/','_',$ext); 458035e07f1SKate Arzamastseva echo ".mf_$class {"; 45927bf7924STom N Harris echo ' background-image: url('.DOKU_BASE.'lib/images/fileicons/'.$ext.$type.')'; 46027bf7924STom N Harris echo '}'; 46127bf7924STom N Harris } 46227bf7924STom N Harris} 4631c2d1019SAndreas Gohr 4641c2d1019SAndreas Gohr/** 46578a6aeb1SAndreas Gohr * Loads a given file and fixes relative URLs with the 46678a6aeb1SAndreas Gohr * given location prefix 467253d4b48SGerrit Uitslag * 468253d4b48SGerrit Uitslag * @param string $file file system path 469253d4b48SGerrit Uitslag * @param string $location 470253d4b48SGerrit Uitslag * @return string 47178a6aeb1SAndreas Gohr */ 47278a6aeb1SAndreas Gohrfunction css_loadfile($file,$location=''){ 47312ffbbc3SChristopher Smith $css_file = new DokuCssFile($file); 47412ffbbc3SChristopher Smith return $css_file->load($location); 47512ffbbc3SChristopher Smith} 47612ffbbc3SChristopher Smith 4771e2c5948SChristopher Smith/** 4781e2c5948SChristopher Smith * Helper class to abstract loading of css/less files 4791e2c5948SChristopher Smith * 4801e2c5948SChristopher Smith * @author Chris Smith <chris@jalakai.co.uk> 4811e2c5948SChristopher Smith */ 48212ffbbc3SChristopher Smithclass DokuCssFile { 48312ffbbc3SChristopher Smith 4841e2c5948SChristopher Smith protected $filepath; // file system path to the CSS/Less file 4851e2c5948SChristopher Smith protected $location; // base url location of the CSS/Less file 486fd18b5f4SGerrit Uitslag protected $relative_path = null; 48712ffbbc3SChristopher Smith 48812ffbbc3SChristopher Smith public function __construct($file) { 48912ffbbc3SChristopher Smith $this->filepath = $file; 49012ffbbc3SChristopher Smith } 49112ffbbc3SChristopher Smith 4921e2c5948SChristopher Smith /** 4931e2c5948SChristopher Smith * Load the contents of the css/less file and adjust any relative paths/urls (relative to this file) to be 4941e2c5948SChristopher Smith * relative to the dokuwiki root: the web root (DOKU_BASE) for most files; the file system root (DOKU_INC) 4951e2c5948SChristopher Smith * for less files. 4961e2c5948SChristopher Smith * 4971e2c5948SChristopher Smith * @param string $location base url for this file 4981e2c5948SChristopher Smith * @return string the CSS/Less contents of the file 4991e2c5948SChristopher Smith */ 50012ffbbc3SChristopher Smith public function load($location='') { 50179e79377SAndreas Gohr if (!file_exists($this->filepath)) return ''; 50212ffbbc3SChristopher Smith 50312ffbbc3SChristopher Smith $css = io_readFile($this->filepath); 50478a6aeb1SAndreas Gohr if (!$location) return $css; 50578a6aeb1SAndreas Gohr 50612ffbbc3SChristopher Smith $this->location = $location; 507de737055SChristopher Smith 50812ffbbc3SChristopher Smith $css = preg_replace_callback('#(url\( *)([\'"]?)(.*?)(\2)( *\))#',array($this,'replacements'),$css); 50912ffbbc3SChristopher Smith $css = preg_replace_callback('#(@import\s+)([\'"])(.*?)(\2)#',array($this,'replacements'),$css); 510809d3ba5SAndreas Gohr 51178a6aeb1SAndreas Gohr return $css; 51278a6aeb1SAndreas Gohr } 51378a6aeb1SAndreas Gohr 5141e2c5948SChristopher Smith /** 5151e2c5948SChristopher Smith * Get the relative file system path of this file, relative to dokuwiki's root folder, DOKU_INC 5161e2c5948SChristopher Smith * 5171e2c5948SChristopher Smith * @return string relative file system path 5181e2c5948SChristopher Smith */ 519fd18b5f4SGerrit Uitslag protected function getRelativePath(){ 52012ffbbc3SChristopher Smith 52112ffbbc3SChristopher Smith if (is_null($this->relative_path)) { 52212ffbbc3SChristopher Smith $basedir = array(DOKU_INC); 5231e2c5948SChristopher Smith 5241e2c5948SChristopher Smith // during testing, files may be found relative to a second base dir, TMP_DIR 52512ffbbc3SChristopher Smith if (defined('DOKU_UNITTEST')) { 52612ffbbc3SChristopher Smith $basedir[] = realpath(TMP_DIR); 52712ffbbc3SChristopher Smith } 52812ffbbc3SChristopher Smith 52973f25ac0SAndreas Gohr $basedir = array_map('preg_quote_cb', $basedir); 53073f25ac0SAndreas Gohr $regex = '/^('.join('|',$basedir).')/'; 53112ffbbc3SChristopher Smith $this->relative_path = preg_replace($regex, '', dirname($this->filepath)); 53212ffbbc3SChristopher Smith } 53312ffbbc3SChristopher Smith 53412ffbbc3SChristopher Smith return $this->relative_path; 53512ffbbc3SChristopher Smith } 53612ffbbc3SChristopher Smith 5371e2c5948SChristopher Smith /** 5381e2c5948SChristopher Smith * preg_replace callback to adjust relative urls from relative to this file to relative 5391e2c5948SChristopher Smith * to the appropriate dokuwiki root location as described in the code 5401e2c5948SChristopher Smith * 5411e2c5948SChristopher Smith * @param array see http://php.net/preg_replace_callback 5421e2c5948SChristopher Smith * @return string see http://php.net/preg_replace_callback 5431e2c5948SChristopher Smith */ 54412ffbbc3SChristopher Smith public function replacements($match) { 545de737055SChristopher Smith 5461e2c5948SChristopher Smith // not a relative url? - no adjustment required 547de737055SChristopher Smith if (preg_match('#^(/|data:|https?://)#',$match[3])) { 548de737055SChristopher Smith return $match[0]; 549de737055SChristopher Smith } 5501e2c5948SChristopher Smith // a less file import? - requires a file system location 551de737055SChristopher Smith else if (substr($match[3],-5) == '.less') { 552de737055SChristopher Smith if ($match[3]{0} != '/') { 55312ffbbc3SChristopher Smith $match[3] = $this->getRelativePath() . '/' . $match[3]; 554de737055SChristopher Smith } 555de737055SChristopher Smith } 5561e2c5948SChristopher Smith // everything else requires a url adjustment 557de737055SChristopher Smith else { 55812ffbbc3SChristopher Smith $match[3] = $this->location . $match[3]; 559de737055SChristopher Smith } 560de737055SChristopher Smith 561de737055SChristopher Smith return join('',array_slice($match,1)); 562de737055SChristopher Smith } 56312ffbbc3SChristopher Smith} 564de737055SChristopher Smith 565809d3ba5SAndreas Gohr/** 5664eb5f931SChristopher Smith * Convert local image URLs to data URLs if the filesize is small 567809d3ba5SAndreas Gohr * 568809d3ba5SAndreas Gohr * Callback for preg_replace_callback 569253d4b48SGerrit Uitslag * 570253d4b48SGerrit Uitslag * @param array $match 571253d4b48SGerrit Uitslag * @return string 572809d3ba5SAndreas Gohr */ 573809d3ba5SAndreas Gohrfunction css_datauri($match){ 57428f4004cSAndreas Gohr global $conf; 57528f4004cSAndreas Gohr 576809d3ba5SAndreas Gohr $pre = unslash($match[1]); 577809d3ba5SAndreas Gohr $base = unslash($match[2]); 578809d3ba5SAndreas Gohr $url = unslash($match[3]); 579809d3ba5SAndreas Gohr $ext = unslash($match[4]); 580809d3ba5SAndreas Gohr 581809d3ba5SAndreas Gohr $local = DOKU_INC.$url; 582809d3ba5SAndreas Gohr $size = @filesize($local); 58328f4004cSAndreas Gohr if($size && $size < $conf['cssdatauri']){ 584809d3ba5SAndreas Gohr $data = base64_encode(file_get_contents($local)); 585809d3ba5SAndreas Gohr } 586809d3ba5SAndreas Gohr if($data){ 5876a5d6817SAnika Henke $url = 'data:image/'.$ext.';base64,'.$data; 588809d3ba5SAndreas Gohr }else{ 589809d3ba5SAndreas Gohr $url = $base.$url; 590809d3ba5SAndreas Gohr } 591809d3ba5SAndreas Gohr return $pre.$url; 592809d3ba5SAndreas Gohr} 593809d3ba5SAndreas Gohr 59415c394afSAndreas Gohr 59578a6aeb1SAndreas Gohr/** 59678a6aeb1SAndreas Gohr * Returns a list of possible Plugin Styles (no existance check here) 59778a6aeb1SAndreas Gohr * 59878a6aeb1SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 599253d4b48SGerrit Uitslag * 600253d4b48SGerrit Uitslag * @param string $mediatype 601253d4b48SGerrit Uitslag * @return array 60278a6aeb1SAndreas Gohr */ 603318cd03eSAnika Henkefunction css_pluginstyles($mediatype='screen'){ 60478a6aeb1SAndreas Gohr $list = array(); 60578a6aeb1SAndreas Gohr $plugins = plugin_list(); 60678a6aeb1SAndreas Gohr foreach ($plugins as $p){ 607318cd03eSAnika Henke $list[DOKU_PLUGIN."$p/$mediatype.css"] = DOKU_BASE."lib/plugins/$p/"; 608d4a1ece8SAndreas Gohr $list[DOKU_PLUGIN."$p/$mediatype.less"] = DOKU_BASE."lib/plugins/$p/"; 609318cd03eSAnika Henke // alternative for screen.css 610318cd03eSAnika Henke if ($mediatype=='screen') { 61178a6aeb1SAndreas Gohr $list[DOKU_PLUGIN."$p/style.css"] = DOKU_BASE."lib/plugins/$p/"; 612d4a1ece8SAndreas Gohr $list[DOKU_PLUGIN."$p/style.less"] = DOKU_BASE."lib/plugins/$p/"; 61378a6aeb1SAndreas Gohr } 61478a6aeb1SAndreas Gohr } 61578a6aeb1SAndreas Gohr return $list; 61678a6aeb1SAndreas Gohr} 61778a6aeb1SAndreas Gohr 61878a6aeb1SAndreas Gohr/** 61978a6aeb1SAndreas Gohr * Very simple CSS optimizer 62078a6aeb1SAndreas Gohr * 62178a6aeb1SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 622253d4b48SGerrit Uitslag * 623253d4b48SGerrit Uitslag * @param string $css 624253d4b48SGerrit Uitslag * @return string 62578a6aeb1SAndreas Gohr */ 62678a6aeb1SAndreas Gohrfunction css_compress($css){ 627fd7c2db0SAndreas Gohr //strip comments through a callback 628fd7c2db0SAndreas Gohr $css = preg_replace_callback('#(/\*)(.*?)(\*/)#s','css_comment_cb',$css); 629fd7c2db0SAndreas Gohr 630247c1c5dSAndreas Gohr //strip (incorrect but common) one line comments 631fe5a50c3SAndreas Gohr $css = preg_replace_callback('/^.*\/\/.*$/m','css_onelinecomment_cb',$css); 632247c1c5dSAndreas Gohr 63378a6aeb1SAndreas Gohr // strip whitespaces 63478a6aeb1SAndreas Gohr $css = preg_replace('![\r\n\t ]+!',' ',$css); 635f5379589SChristopher Smith $css = preg_replace('/ ?([;,{}\/]) ?/','\\1',$css); 636f5379589SChristopher Smith $css = preg_replace('/ ?: /',':',$css); 63778a6aeb1SAndreas Gohr 638205907a7Sfurun // number compression 639205907a7Sfurun $css = preg_replace('/([: ])0+(\.\d+?)0*((?:pt|pc|in|mm|cm|em|ex|px)\b|%)(?=[^\{]*[;\}])/', '$1$2$3', $css); // "0.1em" to ".1em", "1.10em" to "1.1em" 640205907a7Sfurun $css = preg_replace('/([: ])\.(0)+((?:pt|pc|in|mm|cm|em|ex|px)\b|%)(?=[^\{]*[;\}])/', '$1$2', $css); // ".0em" to "0" 641205907a7Sfurun $css = preg_replace('/([: ]0)0*(\.0*)?((?:pt|pc|in|mm|cm|em|ex|px)(?=[^\{]*[;\}])\b|%)/', '$1', $css); // "0.0em" to "0" 642205907a7Sfurun $css = preg_replace('/([: ]\d+)(\.0*)((?:pt|pc|in|mm|cm|em|ex|px)(?=[^\{]*[;\}])\b|%)/', '$1$3', $css); // "1.0em" to "1em" 643205907a7Sfurun $css = preg_replace('/([: ])0+(\d+|\d*\.\d+)((?:pt|pc|in|mm|cm|em|ex|px)(?=[^\{]*[;\}])\b|%)/', '$1$2$3', $css); // "001em" to "1em" 644205907a7Sfurun 645205907a7Sfurun // shorten attributes (1em 1em 1em 1em -> 1em) 646205907a7Sfurun $css = preg_replace('/(?<![\w\-])((?:margin|padding|border|border-(?:width|radius)):)([\w\.]+)( \2)+(?=[;\}]| !)/', '$1$2', $css); // "1em 1em 1em 1em" to "1em" 647205907a7Sfurun $css = preg_replace('/(?<![\w\-])((?:margin|padding|border|border-(?:width)):)([\w\.]+) ([\w\.]+) \2 \3(?=[;\}]| !)/', '$1$2 $3', $css); // "1em 2em 1em 2em" to "1em 2em" 648205907a7Sfurun 64978a6aeb1SAndreas Gohr // shorten colors 650205907a7Sfurun $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); 65178a6aeb1SAndreas Gohr 65278a6aeb1SAndreas Gohr return $css; 65378a6aeb1SAndreas Gohr} 65478a6aeb1SAndreas Gohr 655c00aef76SAndreas Gohr/** 656c00aef76SAndreas Gohr * Callback for css_compress() 657c00aef76SAndreas Gohr * 658c00aef76SAndreas Gohr * Keeps short comments (< 5 chars) to maintain typical browser hacks 659c00aef76SAndreas Gohr * 660c00aef76SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 661253d4b48SGerrit Uitslag * 662253d4b48SGerrit Uitslag * @param array $matches 663253d4b48SGerrit Uitslag * @return string 664c00aef76SAndreas Gohr */ 665c00aef76SAndreas Gohrfunction css_comment_cb($matches){ 666c00aef76SAndreas Gohr if(strlen($matches[2]) > 4) return ''; 667c00aef76SAndreas Gohr return $matches[0]; 668c00aef76SAndreas Gohr} 66978a6aeb1SAndreas Gohr 670fe5a50c3SAndreas Gohr/** 671fe5a50c3SAndreas Gohr * Callback for css_compress() 672fe5a50c3SAndreas Gohr * 673fe5a50c3SAndreas Gohr * Strips one line comments but makes sure it will not destroy url() constructs with slashes 674fe5a50c3SAndreas Gohr * 675253d4b48SGerrit Uitslag * @param array $matches 676fe5a50c3SAndreas Gohr * @return string 677fe5a50c3SAndreas Gohr */ 678fe5a50c3SAndreas Gohrfunction css_onelinecomment_cb($matches) { 679fe5a50c3SAndreas Gohr $line = $matches[0]; 680fe5a50c3SAndreas Gohr 681fe5a50c3SAndreas Gohr $i = 0; 682fe5a50c3SAndreas Gohr $len = strlen($line); 683918a4468SAndreas Gohr 684fe5a50c3SAndreas Gohr while ($i< $len){ 685fe5a50c3SAndreas Gohr $nextcom = strpos($line, '//', $i); 686fe5a50c3SAndreas Gohr $nexturl = stripos($line, 'url(', $i); 687fe5a50c3SAndreas Gohr 688fe5a50c3SAndreas Gohr if($nextcom === false) { 689fe5a50c3SAndreas Gohr // no more comments, we're done 690918a4468SAndreas Gohr $i = $len; 691fe5a50c3SAndreas Gohr break; 692fe5a50c3SAndreas Gohr } 693fe5a50c3SAndreas Gohr 694918a4468SAndreas Gohr // keep any quoted string that starts before a comment 695918a4468SAndreas Gohr $nextsqt = strpos($line, "'", $i); 696918a4468SAndreas Gohr $nextdqt = strpos($line, '"', $i); 697918a4468SAndreas Gohr if(min($nextsqt, $nextdqt) < $nextcom) { 698918a4468SAndreas Gohr $skipto = false; 699918a4468SAndreas Gohr if($nextsqt !== false && ($nextdqt === false || $nextsqt < $nextdqt)) { 700918a4468SAndreas Gohr $skipto = strpos($line, "'", $nextsqt+1) +1; 701918a4468SAndreas Gohr } else if ($nextdqt !== false) { 702918a4468SAndreas Gohr $skipto = strpos($line, '"', $nextdqt+1) +1; 703918a4468SAndreas Gohr } 704918a4468SAndreas Gohr 705918a4468SAndreas Gohr if($skipto !== false) { 706918a4468SAndreas Gohr $i = $skipto; 707918a4468SAndreas Gohr continue; 708918a4468SAndreas Gohr } 709918a4468SAndreas Gohr } 710918a4468SAndreas Gohr 711918a4468SAndreas Gohr if($nexturl === false || $nextcom < $nexturl) { 712918a4468SAndreas Gohr // no url anymore, strip comment and be done 713918a4468SAndreas Gohr $i = $nextcom; 714918a4468SAndreas Gohr break; 715918a4468SAndreas Gohr } 716918a4468SAndreas Gohr 717918a4468SAndreas Gohr // we have an upcoming url 718918a4468SAndreas Gohr $i = strpos($line, ')', $nexturl); 719918a4468SAndreas Gohr } 720918a4468SAndreas Gohr 721918a4468SAndreas Gohr return substr($line, 0, $i); 722fe5a50c3SAndreas Gohr} 723fe5a50c3SAndreas Gohr 724e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 725