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'); 37de4634ecSGerry Weißbach $type = 'feed'; 38de4634ecSGerry Weißbach } else { 395d48a5eaSGerry Weißbach $mediatypes = array('screen', 'all', 'print', 'speech'); 40de4634ecSGerry 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 47*14cd40ecSChang Zhao // load style.ini 480bfc8d5aSAnika Henke $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"; 55afb2c082SAndreas Gohr $cache_files[] = __FILE__; 564d6524b8SAndreas Gohr if($INPUT->bool('preview')) $cache_files[] = $conf['cachedir'].'/preview.ini'; 57afb2c082SAndreas Gohr 5878a6aeb1SAndreas Gohr // Array of needed files and their web locations, the latter ones 5978a6aeb1SAndreas Gohr // are needed to fix relative paths in the stylesheets 60ef36714bSGerry Weißbach $media_files = array(); 6114977bd2SMichael Hamann foreach($mediatypes as $mediatype) { 62ef36714bSGerry Weißbach $files = array(); 633e32b194SGerry Weißbach 64318cd03eSAnika Henke // load core styles 65ef36714bSGerry Weißbach $files[DOKU_INC.'lib/styles/'.$mediatype.'.css'] = DOKU_BASE.'lib/styles/'; 66af4684acSAndreas Gohr 6743576758SAndreas Gohr // load jQuery-UI theme 686c47a78cSAnika Henke if ($mediatype == 'screen') { 69ef36714bSGerry Weißbach $files[DOKU_INC.'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE.'lib/scripts/jquery/jquery-ui-theme/'; 706c47a78cSAnika Henke } 71318cd03eSAnika Henke // load plugin styles 72ef36714bSGerry Weißbach $files = array_merge($files, css_pluginstyles($mediatype)); 73318cd03eSAnika Henke // load template styles 74afb2c082SAndreas Gohr if (isset($styleini['stylesheets'][$mediatype])) { 75ef36714bSGerry Weißbach $files = array_merge($files, $styleini['stylesheets'][$mediatype]); 7609edb711SAndreas Gohr } 77318cd03eSAnika Henke // load user styles 787b909d5eSGerrit Uitslag if(!empty($config_cascade['userstyle'][$mediatype])) { 797b909d5eSGerrit Uitslag foreach($config_cascade['userstyle'][$mediatype] as $userstyle) { 80ef36714bSGerry Weißbach $files[$userstyle] = DOKU_BASE; 817b909d5eSGerrit Uitslag } 82318cd03eSAnika Henke } 8378a6aeb1SAndreas Gohr 84ef36714bSGerry Weißbach // Let plugins decide to either put more styles here or to remove some 853e32b194SGerry Weißbach $media_files[$mediatype] = css_filewrapper($mediatype, $files); 86ef36714bSGerry Weißbach $CSSEvt = new Doku_Event('CSS_STYLES_INCLUDED', $media_files[$mediatype]); 87ef36714bSGerry Weißbach 88ef36714bSGerry Weißbach // Make it preventable. 89ef36714bSGerry Weißbach if ( $CSSEvt->advise_before() ) { 90ef36714bSGerry Weißbach $cache_files = array_merge($cache_files, array_keys($media_files[$mediatype]['files'])); 91ef36714bSGerry Weißbach } else { 92ef36714bSGerry Weißbach // unset if prevented. Nothing will be printed for this mediatype. 93ef36714bSGerry Weißbach unset($media_files[$mediatype]); 9414977bd2SMichael Hamann } 956619f42eSAdrian Lang 96ef36714bSGerry Weißbach // finish event. 97ef36714bSGerry Weißbach $CSSEvt->advise_after(); 98ef36714bSGerry Weißbach } 99ef36714bSGerry Weißbach 100ef36714bSGerry Weißbach // The generated script depends on some dynamic options 10185319150SGerry Weißbach $cache = new cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].$INPUT->bool('preview').DOKU_BASE.$tpl.$type,'.css'); 102ef36714bSGerry Weißbach $cache->_event = 'CSS_CACHE_USE'; 103ef36714bSGerry Weißbach 10438f56bffSBen Coburn // check cache age & handle conditional request 1056619f42eSAdrian Lang // This may exit if a cache can be used 106e7c68c4dSGerry Weißbach $cache_ok = $cache->useCache(array('files' => $cache_files)); 107e7c68c4dSGerry Weißbach http_cached($cache->cache, $cache_ok); 10878a6aeb1SAndreas Gohr 1093899c2ecSMichael Hamann // start output buffering 1103899c2ecSMichael Hamann ob_start(); 1113899c2ecSMichael Hamann 112ef36714bSGerry Weißbach // Fire CSS_STYLES_INCLUDED for one last time to let the 113ef36714bSGerry Weißbach // plugins decide whether to include the DW default styles. 114ef36714bSGerry Weißbach // This can be done by preventing the Default. 115ef36714bSGerry Weißbach $media_files['DW_DEFAULT'] = css_filewrapper('DW_DEFAULT'); 116ef36714bSGerry Weißbach trigger_event('CSS_STYLES_INCLUDED', $media_files['DW_DEFAULT'], 'css_defaultstyles'); 117ef36714bSGerry Weißbach 1186c47a78cSAnika Henke // build the stylesheet 11914977bd2SMichael Hamann foreach ($mediatypes as $mediatype) { 12078a6aeb1SAndreas Gohr 121ef36714bSGerry Weißbach // Check if there is a wrapper set for this type. 122ef36714bSGerry Weißbach if ( !isset($media_files[$mediatype]) ) { 123ef36714bSGerry Weißbach continue; 12478a6aeb1SAndreas Gohr } 12578a6aeb1SAndreas Gohr 126ef36714bSGerry Weißbach $cssData = $media_files[$mediatype]; 127ef36714bSGerry Weißbach 128ef36714bSGerry Weißbach // Print the styles. 129ef36714bSGerry Weißbach print NL; 130ef36714bSGerry Weißbach if ( $cssData['encapsulate'] === true ) print $cssData['encapsulationPrefix'] . ' {'; 131ef36714bSGerry Weißbach print '/* START '.$cssData['mediatype'].' styles */'.NL; 132ef36714bSGerry Weißbach 1336c47a78cSAnika Henke // load files 134ef36714bSGerry Weißbach foreach($cssData['files'] as $file => $location){ 13572a66eb7SAndreas Gohr $display = str_replace(fullpath(DOKU_INC), '', fullpath($file)); 136ef36714bSGerry Weißbach print "\n/* XXXXXXXXX $display XXXXXXXXX */\n"; 137ef36714bSGerry Weißbach print css_loadfile($file, $location); 1386c47a78cSAnika Henke } 139ef36714bSGerry Weißbach 140ef36714bSGerry Weißbach print NL; 141ef36714bSGerry Weißbach if ( $cssData['encapsulate'] === true ) print '} /* /@media '; 142ef36714bSGerry Weißbach else print '/*'; 143ef36714bSGerry Weißbach print ' END '.$cssData['mediatype'].' styles */'.NL; 1446c47a78cSAnika Henke } 145ef36714bSGerry Weißbach 14678a6aeb1SAndreas Gohr // end output buffering and get contents 14778a6aeb1SAndreas Gohr $css = ob_get_contents(); 14878a6aeb1SAndreas Gohr ob_end_clean(); 14978a6aeb1SAndreas Gohr 150f8fb2d18SAndreas Gohr // strip any source maps 151f8fb2d18SAndreas Gohr stripsourcemaps($css); 152f8fb2d18SAndreas Gohr 1536e69c1baSAndreas Gohr // apply style replacements 154afb2c082SAndreas Gohr $css = css_applystyle($css, $styleini['replacements']); 1556e69c1baSAndreas Gohr 15672a66eb7SAndreas Gohr // parse less 15772a66eb7SAndreas Gohr $css = css_parseless($css); 158d4a1ece8SAndreas Gohr 15978a6aeb1SAndreas Gohr // compress whitespace and comments 16078a6aeb1SAndreas Gohr if($conf['compress']){ 16178a6aeb1SAndreas Gohr $css = css_compress($css); 16278a6aeb1SAndreas Gohr } 16378a6aeb1SAndreas Gohr 164809d3ba5SAndreas Gohr // embed small images right into the stylesheet 165809d3ba5SAndreas Gohr if($conf['cssdatauri']){ 166809d3ba5SAndreas Gohr $base = preg_quote(DOKU_BASE,'#'); 167809d3ba5SAndreas Gohr $css = preg_replace_callback('#(url\([ \'"]*)('.$base.')(.*?(?:\.(png|gif)))#i','css_datauri',$css); 168809d3ba5SAndreas Gohr } 169809d3ba5SAndreas Gohr 1706619f42eSAdrian Lang http_cached_finish($cache->cache, $css); 17178a6aeb1SAndreas Gohr} 17278a6aeb1SAndreas Gohr 17378a6aeb1SAndreas Gohr/** 17472a66eb7SAndreas Gohr * Uses phpless to parse LESS in our CSS 17572a66eb7SAndreas Gohr * 17672a66eb7SAndreas Gohr * most of this function is error handling to show a nice useful error when 17772a66eb7SAndreas Gohr * LESS compilation fails 17872a66eb7SAndreas Gohr * 179253d4b48SGerrit Uitslag * @param string $css 18072a66eb7SAndreas Gohr * @return string 18172a66eb7SAndreas Gohr */ 18272a66eb7SAndreas Gohrfunction css_parseless($css) { 1837d247a3cSGerrit Uitslag global $conf; 1847d247a3cSGerrit Uitslag 18572a66eb7SAndreas Gohr $less = new lessc(); 186343a31d8SAndreas Gohr $less->importDir = array(DOKU_INC); 1877d247a3cSGerrit Uitslag $less->setPreserveComments(!$conf['compress']); 18830f686ebSChristopher Smith 18930f686ebSChristopher Smith if (defined('DOKU_UNITTEST')){ 19030f686ebSChristopher Smith $less->importDir[] = TMP_DIR; 19130f686ebSChristopher Smith } 19230f686ebSChristopher Smith 19372a66eb7SAndreas Gohr try { 19472a66eb7SAndreas Gohr return $less->compile($css); 19572a66eb7SAndreas Gohr } catch(Exception $e) { 19672a66eb7SAndreas Gohr // get exception message 19772a66eb7SAndreas Gohr $msg = str_replace(array("\n", "\r", "'"), array(), $e->getMessage()); 19872a66eb7SAndreas Gohr 19972a66eb7SAndreas Gohr // try to use line number to find affected file 20072a66eb7SAndreas Gohr if(preg_match('/line: (\d+)$/', $msg, $m)){ 20172a66eb7SAndreas Gohr $msg = substr($msg, 0, -1* strlen($m[0])); //remove useless linenumber 20272a66eb7SAndreas Gohr $lno = $m[1]; 20372a66eb7SAndreas Gohr 20472a66eb7SAndreas Gohr // walk upwards to last include 20572a66eb7SAndreas Gohr $lines = explode("\n", $css); 20672a66eb7SAndreas Gohr for($i=$lno-1; $i>=0; $i--){ 20772a66eb7SAndreas Gohr if(preg_match('/\/(\* XXXXXXXXX )(.*?)( XXXXXXXXX \*)\//', $lines[$i], $m)){ 20872a66eb7SAndreas Gohr // we found it, add info to message 20972a66eb7SAndreas Gohr $msg .= ' in '.$m[2].' at line '.($lno-$i); 21072a66eb7SAndreas Gohr break; 21172a66eb7SAndreas Gohr } 21272a66eb7SAndreas Gohr } 21372a66eb7SAndreas Gohr } 21472a66eb7SAndreas Gohr 21572a66eb7SAndreas Gohr // something went wrong 21672a66eb7SAndreas Gohr $error = 'A fatal error occured during compilation of the CSS files. '. 21772a66eb7SAndreas Gohr 'If you recently installed a new plugin or template it '. 21872a66eb7SAndreas Gohr 'might be broken and you should try disabling it again. ['.$msg.']'; 21972a66eb7SAndreas Gohr 22072a66eb7SAndreas Gohr echo ".dokuwiki:before { 22172a66eb7SAndreas Gohr content: '$error'; 22272a66eb7SAndreas Gohr background-color: red; 22372a66eb7SAndreas Gohr display: block; 22472a66eb7SAndreas Gohr background-color: #fcc; 22572a66eb7SAndreas Gohr border-color: #ebb; 22672a66eb7SAndreas Gohr color: #000; 22772a66eb7SAndreas Gohr padding: 0.5em; 22872a66eb7SAndreas Gohr }"; 22972a66eb7SAndreas Gohr 23072a66eb7SAndreas Gohr exit; 23172a66eb7SAndreas Gohr } 23272a66eb7SAndreas Gohr} 23372a66eb7SAndreas Gohr 23472a66eb7SAndreas Gohr/** 2356e69c1baSAndreas Gohr * Does placeholder replacements in the style according to 2366e69c1baSAndreas Gohr * the ones defined in a templates style.ini file 2376e69c1baSAndreas Gohr * 238d4a1ece8SAndreas Gohr * This also adds the ini defined placeholders as less variables 239d4a1ece8SAndreas Gohr * (sans the surrounding __ and with a ini_ prefix) 240d4a1ece8SAndreas Gohr * 2416e69c1baSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 242253d4b48SGerrit Uitslag * 243253d4b48SGerrit Uitslag * @param string $css 244253d4b48SGerrit Uitslag * @param array $replacements array(placeholder => value) 245253d4b48SGerrit Uitslag * @return string 2466e69c1baSAndreas Gohr */ 247afb2c082SAndreas Gohrfunction css_applystyle($css, $replacements) { 248cbe37079SAndreas Gohr // we convert ini replacements to LESS variable names 249cbe37079SAndreas Gohr // and build a list of variable: value; pairs 250d4a1ece8SAndreas Gohr $less = ''; 251afb2c082SAndreas Gohr foreach((array) $replacements as $key => $value) { 252cbe37079SAndreas Gohr $lkey = trim($key, '_'); 253cbe37079SAndreas Gohr $lkey = '@ini_'.$lkey; 254cbe37079SAndreas Gohr $less .= "$lkey: $value;\n"; 255cbe37079SAndreas Gohr 256afb2c082SAndreas Gohr $replacements[$key] = $lkey; 257d4a1ece8SAndreas Gohr } 258c51b334eSAndreas Gohr 259cbe37079SAndreas Gohr // we now replace all old ini replacements with LESS variables 260afb2c082SAndreas Gohr $css = strtr($css, $replacements); 261cbe37079SAndreas Gohr 262cbe37079SAndreas Gohr // now prepend the list of LESS variables as the very first thing 263c51b334eSAndreas Gohr $css = $less.$css; 2646e69c1baSAndreas Gohr return $css; 2656e69c1baSAndreas Gohr} 2666e69c1baSAndreas Gohr 2676e69c1baSAndreas Gohr/** 268afb2c082SAndreas Gohr * Load style ini contents 2690ac69508SAnika Henke * 270afb2c082SAndreas Gohr * Loads and merges style.ini files from template and config and prepares 271afb2c082SAndreas Gohr * the stylesheet modes 272afb2c082SAndreas Gohr * 273afb2c082SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 274253d4b48SGerrit Uitslag * 275afb2c082SAndreas Gohr * @param string $tpl the used template 2764d6524b8SAndreas Gohr * @param bool $preview load preview replacements 277afb2c082SAndreas Gohr * @return array with keys 'stylesheets' and 'replacements' 2780e6f9f08SAnika Henke */ 2794d6524b8SAndreas Gohrfunction css_styleini($tpl, $preview=false) { 2804d6524b8SAndreas Gohr global $conf; 2814d6524b8SAndreas Gohr 282afb2c082SAndreas Gohr $stylesheets = array(); // mode, file => base 2839f184f79SAndreas Gohr // guaranteed placeholder => value 2849f184f79SAndreas Gohr $replacements = array( 2859f184f79SAndreas Gohr '__text__' => "#000", 2869f184f79SAndreas Gohr '__background__' => "#fff", 2879f184f79SAndreas Gohr '__text_alt__' => "#999", 2889f184f79SAndreas Gohr '__background_alt__' => "#eee", 2899f184f79SAndreas Gohr '__text_neu__' => "#666", 2909f184f79SAndreas Gohr '__background_neu__' => "#ddd", 2919f184f79SAndreas Gohr '__border__' => "#ccc", 2929f184f79SAndreas Gohr '__highlight__' => "#ff9", 2939f184f79SAndreas Gohr '__link__' => "#00f", 2949f184f79SAndreas Gohr ); 2950ac69508SAnika Henke 296afb2c082SAndreas Gohr // load template's style.ini 297afb2c082SAndreas Gohr $incbase = tpl_incdir($tpl); 298afb2c082SAndreas Gohr $webbase = tpl_basedir($tpl); 299afb2c082SAndreas Gohr $ini = $incbase.'style.ini'; 300afb2c082SAndreas Gohr if(file_exists($ini)){ 301afb2c082SAndreas Gohr $data = parse_ini_file($ini, true); 3020ac69508SAnika Henke 303afb2c082SAndreas Gohr // stylesheets 304afb2c082SAndreas Gohr if(is_array($data['stylesheets'])) foreach($data['stylesheets'] as $file => $mode){ 305afb2c082SAndreas Gohr $stylesheets[$mode][$incbase.$file] = $webbase; 306afb2c082SAndreas Gohr } 307afb2c082SAndreas Gohr 308afb2c082SAndreas Gohr // replacements 309afb2c082SAndreas Gohr if(is_array($data['replacements'])){ 31047f862d1SChristopher Smith $replacements = array_merge($replacements, css_fixreplacementurls($data['replacements'],$webbase)); 3110ac69508SAnika Henke } 3120ac69508SAnika Henke } 313afb2c082SAndreas Gohr 314afb2c082SAndreas Gohr // load configs's style.ini 315afb2c082SAndreas Gohr $webbase = DOKU_BASE; 3168c5aad7bSAnika Henke $ini = DOKU_CONF."tpl/$tpl/style.ini"; 3178c5aad7bSAnika Henke $incbase = dirname($ini).'/'; 318afb2c082SAndreas Gohr if(file_exists($ini)){ 319afb2c082SAndreas Gohr $data = parse_ini_file($ini, true); 320afb2c082SAndreas Gohr 321afb2c082SAndreas Gohr // stylesheets 32206c9ee33SMarius van Witzenburg if(isset($data['stylesheets']) && is_array($data['stylesheets'])) foreach($data['stylesheets'] as $file => $mode){ 323afb2c082SAndreas Gohr $stylesheets[$mode][$incbase.$file] = $webbase; 3240ac69508SAnika Henke } 325afb2c082SAndreas Gohr 326afb2c082SAndreas Gohr // replacements 32706c9ee33SMarius van Witzenburg if(isset($data['replacements']) && is_array($data['replacements'])){ 32847f862d1SChristopher Smith $replacements = array_merge($replacements, css_fixreplacementurls($data['replacements'],$webbase)); 329afb2c082SAndreas Gohr } 330afb2c082SAndreas Gohr } 331afb2c082SAndreas Gohr 3324d6524b8SAndreas Gohr // allow replacement overwrites in preview mode 3334d6524b8SAndreas Gohr if($preview) { 3344d6524b8SAndreas Gohr $webbase = DOKU_BASE; 3354d6524b8SAndreas Gohr $ini = $conf['cachedir'].'/preview.ini'; 3364d6524b8SAndreas Gohr if(file_exists($ini)) { 3374d6524b8SAndreas Gohr $data = parse_ini_file($ini, true); 3384d6524b8SAndreas Gohr // replacements 3394d6524b8SAndreas Gohr if(is_array($data['replacements'])) { 3404d6524b8SAndreas Gohr $replacements = array_merge($replacements, css_fixreplacementurls($data['replacements'], $webbase)); 3414d6524b8SAndreas Gohr } 3424d6524b8SAndreas Gohr } 3434d6524b8SAndreas Gohr } 3444d6524b8SAndreas Gohr 345afb2c082SAndreas Gohr return array( 346afb2c082SAndreas Gohr 'stylesheets' => $stylesheets, 347afb2c082SAndreas Gohr 'replacements' => $replacements 348afb2c082SAndreas Gohr ); 3490e6f9f08SAnika Henke} 3500e6f9f08SAnika Henke 3511e2c5948SChristopher Smith/** 3521e2c5948SChristopher Smith * Amend paths used in replacement relative urls, refer FS#2879 3531e2c5948SChristopher Smith * 3541e2c5948SChristopher Smith * @author Chris Smith <chris@jalakai.co.uk> 355253d4b48SGerrit Uitslag * 356253d4b48SGerrit Uitslag * @param array $replacements with key-value pairs 357253d4b48SGerrit Uitslag * @param string $location 358253d4b48SGerrit Uitslag * @return array 3591e2c5948SChristopher Smith */ 36047f862d1SChristopher Smithfunction css_fixreplacementurls($replacements, $location) { 36147f862d1SChristopher Smith foreach($replacements as $key => $value) { 36247f862d1SChristopher Smith $replacements[$key] = preg_replace('#(url\([ \'"]*)(?!/|data:|http://|https://| |\'|")#','\\1'.$location,$value); 36347f862d1SChristopher Smith } 36447f862d1SChristopher Smith return $replacements; 36547f862d1SChristopher Smith} 36647f862d1SChristopher Smith 3670e6f9f08SAnika Henke/** 368ef36714bSGerry Weißbach * Wrapper for the files, content and mediatype for the event CSS_STYLES_INCLUDED 369ef36714bSGerry Weißbach * 370ef36714bSGerry Weißbach * @author Gerry Weißbach <gerry.w@gammaproduction.de> 371ef36714bSGerry Weißbach * 372ef36714bSGerry Weißbach * @param string $mediatype type ofthe current media files/content set 373ef36714bSGerry Weißbach * @param array $files set of files that define the current mediatype 374ef36714bSGerry Weißbach * @return array 375ef36714bSGerry Weißbach */ 3763e32b194SGerry Weißbachfunction css_filewrapper($mediatype, $files=array()){ 377ef36714bSGerry Weißbach return array( 378ef36714bSGerry Weißbach 'files' => $files, 379ef36714bSGerry Weißbach 'mediatype' => $mediatype, 380cf35519cSGerry Weißbach 'encapsulate' => $mediatype != 'all', 381ef36714bSGerry Weißbach 'encapsulationPrefix' => '@media '.$mediatype 382ef36714bSGerry Weißbach ); 383ef36714bSGerry Weißbach} 384ef36714bSGerry Weißbach 385ef36714bSGerry Weißbach/** 386ef36714bSGerry Weißbach * Prints the @media encapsulated default styles of DokuWiki 387ef36714bSGerry Weißbach * 388ef36714bSGerry Weißbach * @author Gerry Weißbach <gerry.w@gammaproduction.de> 389ef36714bSGerry Weißbach * 390ef36714bSGerry Weißbach * This function is being called by a CSS_STYLES_INCLUDED event 391ef36714bSGerry Weißbach * The event can be distinguished by the mediatype which is: 392ef36714bSGerry Weißbach * DW_DEFAULT 393ef36714bSGerry Weißbach */ 394ef36714bSGerry Weißbachfunction css_defaultstyles(){ 395ef36714bSGerry Weißbach // print the default classes for interwiki links and file downloads 396ef36714bSGerry Weißbach print '@media screen {'; 397ef36714bSGerry Weißbach css_interwiki(); 398ef36714bSGerry Weißbach css_filetypes(); 399ef36714bSGerry Weißbach print '}'; 400ef36714bSGerry Weißbach} 401ef36714bSGerry Weißbach 402ef36714bSGerry Weißbach/** 4031c2d1019SAndreas Gohr * Prints classes for interwikilinks 4041c2d1019SAndreas Gohr * 4051c2d1019SAndreas Gohr * Interwiki links have two classes: 'interwiki' and 'iw_$name>' where 4061c2d1019SAndreas Gohr * $name is the identifier given in the config. All Interwiki links get 4071c2d1019SAndreas Gohr * an default style with a default icon. If a special icon is available 4081c2d1019SAndreas Gohr * for an interwiki URL it is set in it's own class. Both classes can be 4091c2d1019SAndreas Gohr * overwritten in the template or userstyles. 4101c2d1019SAndreas Gohr * 4111c2d1019SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 4121c2d1019SAndreas Gohr */ 4131c2d1019SAndreas Gohrfunction css_interwiki(){ 4141c2d1019SAndreas Gohr 4151c2d1019SAndreas Gohr // default style 4161c2d1019SAndreas Gohr echo 'a.interwiki {'; 4171c2d1019SAndreas Gohr echo ' background: transparent url('.DOKU_BASE.'lib/images/interwiki.png) 0px 1px no-repeat;'; 4187b4ea081Smarklundeberg echo ' padding: 1px 0px 1px 16px;'; 4191c2d1019SAndreas Gohr echo '}'; 4201c2d1019SAndreas Gohr 4211c2d1019SAndreas Gohr // additional styles when icon available 4221c2d1019SAndreas Gohr $iwlinks = getInterwiki(); 4231c2d1019SAndreas Gohr foreach(array_keys($iwlinks) as $iw){ 4249d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$iw); 42579e79377SAndreas Gohr if(file_exists(DOKU_INC.'lib/images/interwiki/'.$iw.'.png')){ 4269d2ddea4SAndreas Gohr echo "a.iw_$class {"; 4271c2d1019SAndreas Gohr echo ' background-image: url('.DOKU_BASE.'lib/images/interwiki/'.$iw.'.png)'; 4281c2d1019SAndreas Gohr echo '}'; 42979e79377SAndreas Gohr }elseif(file_exists(DOKU_INC.'lib/images/interwiki/'.$iw.'.gif')){ 4309d2ddea4SAndreas Gohr echo "a.iw_$class {"; 4311c2d1019SAndreas Gohr echo ' background-image: url('.DOKU_BASE.'lib/images/interwiki/'.$iw.'.gif)'; 4321c2d1019SAndreas Gohr echo '}'; 4331c2d1019SAndreas Gohr } 4341c2d1019SAndreas Gohr } 435d15166e5SAndreas Gohr} 4361c2d1019SAndreas Gohr 437d15166e5SAndreas Gohr/** 438d15166e5SAndreas Gohr * Prints classes for file download links 439d15166e5SAndreas Gohr * 440d15166e5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 441d15166e5SAndreas Gohr */ 442d15166e5SAndreas Gohrfunction css_filetypes(){ 443d15166e5SAndreas Gohr 444d15166e5SAndreas Gohr // default style 445035e07f1SKate Arzamastseva echo '.mediafile {'; 446d15166e5SAndreas Gohr echo ' background: transparent url('.DOKU_BASE.'lib/images/fileicons/file.png) 0px 1px no-repeat;'; 4475b77caf4SAndreas Gohr echo ' padding-left: 18px;'; 4485b77caf4SAndreas Gohr echo ' padding-bottom: 1px;'; 449d15166e5SAndreas Gohr echo '}'; 450d15166e5SAndreas Gohr 451d15166e5SAndreas Gohr // additional styles when icon available 45227bf7924STom N Harris // scan directory for all icons 45327bf7924STom N Harris $exts = array(); 45427bf7924STom N Harris if($dh = opendir(DOKU_INC.'lib/images/fileicons')){ 45527bf7924STom N Harris while(false !== ($file = readdir($dh))){ 45627bf7924STom N Harris if(preg_match('/([_\-a-z0-9]+(?:\.[_\-a-z0-9]+)*?)\.(png|gif)/i',$file,$match)){ 45727bf7924STom N Harris $ext = strtolower($match[1]); 45827bf7924STom N Harris $type = '.'.strtolower($match[2]); 45927bf7924STom N Harris if($ext!='file' && (!isset($exts[$ext]) || $type=='.png')){ 46027bf7924STom N Harris $exts[$ext] = $type; 461d15166e5SAndreas Gohr } 462d15166e5SAndreas Gohr } 4631c2d1019SAndreas Gohr } 46427bf7924STom N Harris closedir($dh); 46527bf7924STom N Harris } 46627bf7924STom N Harris foreach($exts as $ext=>$type){ 46727bf7924STom N Harris $class = preg_replace('/[^_\-a-z0-9]+/','_',$ext); 468035e07f1SKate Arzamastseva echo ".mf_$class {"; 46927bf7924STom N Harris echo ' background-image: url('.DOKU_BASE.'lib/images/fileicons/'.$ext.$type.')'; 47027bf7924STom N Harris echo '}'; 47127bf7924STom N Harris } 47227bf7924STom N Harris} 4731c2d1019SAndreas Gohr 4741c2d1019SAndreas Gohr/** 47578a6aeb1SAndreas Gohr * Loads a given file and fixes relative URLs with the 47678a6aeb1SAndreas Gohr * given location prefix 477253d4b48SGerrit Uitslag * 478253d4b48SGerrit Uitslag * @param string $file file system path 479253d4b48SGerrit Uitslag * @param string $location 480253d4b48SGerrit Uitslag * @return string 48178a6aeb1SAndreas Gohr */ 48278a6aeb1SAndreas Gohrfunction css_loadfile($file,$location=''){ 48312ffbbc3SChristopher Smith $css_file = new DokuCssFile($file); 48412ffbbc3SChristopher Smith return $css_file->load($location); 48512ffbbc3SChristopher Smith} 48612ffbbc3SChristopher Smith 4871e2c5948SChristopher Smith/** 4881e2c5948SChristopher Smith * Helper class to abstract loading of css/less files 4891e2c5948SChristopher Smith * 4901e2c5948SChristopher Smith * @author Chris Smith <chris@jalakai.co.uk> 4911e2c5948SChristopher Smith */ 49212ffbbc3SChristopher Smithclass DokuCssFile { 49312ffbbc3SChristopher Smith 4941e2c5948SChristopher Smith protected $filepath; // file system path to the CSS/Less file 4951e2c5948SChristopher Smith protected $location; // base url location of the CSS/Less file 496fd18b5f4SGerrit Uitslag protected $relative_path = null; 49712ffbbc3SChristopher Smith 49812ffbbc3SChristopher Smith public function __construct($file) { 49912ffbbc3SChristopher Smith $this->filepath = $file; 50012ffbbc3SChristopher Smith } 50112ffbbc3SChristopher Smith 5021e2c5948SChristopher Smith /** 5031e2c5948SChristopher Smith * Load the contents of the css/less file and adjust any relative paths/urls (relative to this file) to be 5041e2c5948SChristopher Smith * relative to the dokuwiki root: the web root (DOKU_BASE) for most files; the file system root (DOKU_INC) 5051e2c5948SChristopher Smith * for less files. 5061e2c5948SChristopher Smith * 5071e2c5948SChristopher Smith * @param string $location base url for this file 5081e2c5948SChristopher Smith * @return string the CSS/Less contents of the file 5091e2c5948SChristopher Smith */ 51012ffbbc3SChristopher Smith public function load($location='') { 51179e79377SAndreas Gohr if (!file_exists($this->filepath)) return ''; 51212ffbbc3SChristopher Smith 51312ffbbc3SChristopher Smith $css = io_readFile($this->filepath); 51478a6aeb1SAndreas Gohr if (!$location) return $css; 51578a6aeb1SAndreas Gohr 51612ffbbc3SChristopher Smith $this->location = $location; 517de737055SChristopher Smith 51812ffbbc3SChristopher Smith $css = preg_replace_callback('#(url\( *)([\'"]?)(.*?)(\2)( *\))#',array($this,'replacements'),$css); 51912ffbbc3SChristopher Smith $css = preg_replace_callback('#(@import\s+)([\'"])(.*?)(\2)#',array($this,'replacements'),$css); 520809d3ba5SAndreas Gohr 52178a6aeb1SAndreas Gohr return $css; 52278a6aeb1SAndreas Gohr } 52378a6aeb1SAndreas Gohr 5241e2c5948SChristopher Smith /** 5251e2c5948SChristopher Smith * Get the relative file system path of this file, relative to dokuwiki's root folder, DOKU_INC 5261e2c5948SChristopher Smith * 5271e2c5948SChristopher Smith * @return string relative file system path 5281e2c5948SChristopher Smith */ 529fd18b5f4SGerrit Uitslag protected function getRelativePath(){ 53012ffbbc3SChristopher Smith 53112ffbbc3SChristopher Smith if (is_null($this->relative_path)) { 53212ffbbc3SChristopher Smith $basedir = array(DOKU_INC); 5331e2c5948SChristopher Smith 5341e2c5948SChristopher Smith // during testing, files may be found relative to a second base dir, TMP_DIR 53512ffbbc3SChristopher Smith if (defined('DOKU_UNITTEST')) { 53612ffbbc3SChristopher Smith $basedir[] = realpath(TMP_DIR); 53712ffbbc3SChristopher Smith } 53812ffbbc3SChristopher Smith 53973f25ac0SAndreas Gohr $basedir = array_map('preg_quote_cb', $basedir); 54073f25ac0SAndreas Gohr $regex = '/^('.join('|',$basedir).')/'; 54112ffbbc3SChristopher Smith $this->relative_path = preg_replace($regex, '', dirname($this->filepath)); 54212ffbbc3SChristopher Smith } 54312ffbbc3SChristopher Smith 54412ffbbc3SChristopher Smith return $this->relative_path; 54512ffbbc3SChristopher Smith } 54612ffbbc3SChristopher Smith 5471e2c5948SChristopher Smith /** 5481e2c5948SChristopher Smith * preg_replace callback to adjust relative urls from relative to this file to relative 5491e2c5948SChristopher Smith * to the appropriate dokuwiki root location as described in the code 5501e2c5948SChristopher Smith * 5511e2c5948SChristopher Smith * @param array see http://php.net/preg_replace_callback 5521e2c5948SChristopher Smith * @return string see http://php.net/preg_replace_callback 5531e2c5948SChristopher Smith */ 55412ffbbc3SChristopher Smith public function replacements($match) { 555de737055SChristopher Smith 5561e2c5948SChristopher Smith // not a relative url? - no adjustment required 557de737055SChristopher Smith if (preg_match('#^(/|data:|https?://)#',$match[3])) { 558de737055SChristopher Smith return $match[0]; 559de737055SChristopher Smith } 5601e2c5948SChristopher Smith // a less file import? - requires a file system location 561de737055SChristopher Smith else if (substr($match[3],-5) == '.less') { 562de737055SChristopher Smith if ($match[3]{0} != '/') { 56312ffbbc3SChristopher Smith $match[3] = $this->getRelativePath() . '/' . $match[3]; 564de737055SChristopher Smith } 565de737055SChristopher Smith } 5661e2c5948SChristopher Smith // everything else requires a url adjustment 567de737055SChristopher Smith else { 56812ffbbc3SChristopher Smith $match[3] = $this->location . $match[3]; 569de737055SChristopher Smith } 570de737055SChristopher Smith 571de737055SChristopher Smith return join('',array_slice($match,1)); 572de737055SChristopher Smith } 57312ffbbc3SChristopher Smith} 574de737055SChristopher Smith 575809d3ba5SAndreas Gohr/** 5764eb5f931SChristopher Smith * Convert local image URLs to data URLs if the filesize is small 577809d3ba5SAndreas Gohr * 578809d3ba5SAndreas Gohr * Callback for preg_replace_callback 579253d4b48SGerrit Uitslag * 580253d4b48SGerrit Uitslag * @param array $match 581253d4b48SGerrit Uitslag * @return string 582809d3ba5SAndreas Gohr */ 583809d3ba5SAndreas Gohrfunction css_datauri($match){ 58428f4004cSAndreas Gohr global $conf; 58528f4004cSAndreas Gohr 586809d3ba5SAndreas Gohr $pre = unslash($match[1]); 587809d3ba5SAndreas Gohr $base = unslash($match[2]); 588809d3ba5SAndreas Gohr $url = unslash($match[3]); 589809d3ba5SAndreas Gohr $ext = unslash($match[4]); 590809d3ba5SAndreas Gohr 591809d3ba5SAndreas Gohr $local = DOKU_INC.$url; 592809d3ba5SAndreas Gohr $size = @filesize($local); 59328f4004cSAndreas Gohr if($size && $size < $conf['cssdatauri']){ 594809d3ba5SAndreas Gohr $data = base64_encode(file_get_contents($local)); 595809d3ba5SAndreas Gohr } 5968f34cf3dSMichael Große if (!empty($data)){ 5976a5d6817SAnika Henke $url = 'data:image/'.$ext.';base64,'.$data; 598809d3ba5SAndreas Gohr }else{ 599809d3ba5SAndreas Gohr $url = $base.$url; 600809d3ba5SAndreas Gohr } 601809d3ba5SAndreas Gohr return $pre.$url; 602809d3ba5SAndreas Gohr} 603809d3ba5SAndreas Gohr 60415c394afSAndreas Gohr 60578a6aeb1SAndreas Gohr/** 60678a6aeb1SAndreas Gohr * Returns a list of possible Plugin Styles (no existance check here) 60778a6aeb1SAndreas Gohr * 60878a6aeb1SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 609253d4b48SGerrit Uitslag * 610253d4b48SGerrit Uitslag * @param string $mediatype 611253d4b48SGerrit Uitslag * @return array 61278a6aeb1SAndreas Gohr */ 613318cd03eSAnika Henkefunction css_pluginstyles($mediatype='screen'){ 61478a6aeb1SAndreas Gohr $list = array(); 61578a6aeb1SAndreas Gohr $plugins = plugin_list(); 61678a6aeb1SAndreas Gohr foreach ($plugins as $p){ 617318cd03eSAnika Henke $list[DOKU_PLUGIN."$p/$mediatype.css"] = DOKU_BASE."lib/plugins/$p/"; 618d4a1ece8SAndreas Gohr $list[DOKU_PLUGIN."$p/$mediatype.less"] = DOKU_BASE."lib/plugins/$p/"; 619318cd03eSAnika Henke // alternative for screen.css 620318cd03eSAnika Henke if ($mediatype=='screen') { 62178a6aeb1SAndreas Gohr $list[DOKU_PLUGIN."$p/style.css"] = DOKU_BASE."lib/plugins/$p/"; 622d4a1ece8SAndreas Gohr $list[DOKU_PLUGIN."$p/style.less"] = DOKU_BASE."lib/plugins/$p/"; 62378a6aeb1SAndreas Gohr } 62478a6aeb1SAndreas Gohr } 62578a6aeb1SAndreas Gohr return $list; 62678a6aeb1SAndreas Gohr} 62778a6aeb1SAndreas Gohr 62878a6aeb1SAndreas Gohr/** 62978a6aeb1SAndreas Gohr * Very simple CSS optimizer 63078a6aeb1SAndreas Gohr * 63178a6aeb1SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 632253d4b48SGerrit Uitslag * 633253d4b48SGerrit Uitslag * @param string $css 634253d4b48SGerrit Uitslag * @return string 63578a6aeb1SAndreas Gohr */ 63678a6aeb1SAndreas Gohrfunction css_compress($css){ 637fd7c2db0SAndreas Gohr //strip comments through a callback 638fd7c2db0SAndreas Gohr $css = preg_replace_callback('#(/\*)(.*?)(\*/)#s','css_comment_cb',$css); 639fd7c2db0SAndreas Gohr 640247c1c5dSAndreas Gohr //strip (incorrect but common) one line comments 641fe5a50c3SAndreas Gohr $css = preg_replace_callback('/^.*\/\/.*$/m','css_onelinecomment_cb',$css); 642247c1c5dSAndreas Gohr 64378a6aeb1SAndreas Gohr // strip whitespaces 64478a6aeb1SAndreas Gohr $css = preg_replace('![\r\n\t ]+!',' ',$css); 645f5379589SChristopher Smith $css = preg_replace('/ ?([;,{}\/]) ?/','\\1',$css); 646f5379589SChristopher Smith $css = preg_replace('/ ?: /',':',$css); 64778a6aeb1SAndreas Gohr 648205907a7Sfurun // number compression 649205907a7Sfurun $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" 650205907a7Sfurun $css = preg_replace('/([: ])\.(0)+((?:pt|pc|in|mm|cm|em|ex|px)\b|%)(?=[^\{]*[;\}])/', '$1$2', $css); // ".0em" to "0" 651205907a7Sfurun $css = preg_replace('/([: ]0)0*(\.0*)?((?:pt|pc|in|mm|cm|em|ex|px)(?=[^\{]*[;\}])\b|%)/', '$1', $css); // "0.0em" to "0" 652205907a7Sfurun $css = preg_replace('/([: ]\d+)(\.0*)((?:pt|pc|in|mm|cm|em|ex|px)(?=[^\{]*[;\}])\b|%)/', '$1$3', $css); // "1.0em" to "1em" 653205907a7Sfurun $css = preg_replace('/([: ])0+(\d+|\d*\.\d+)((?:pt|pc|in|mm|cm|em|ex|px)(?=[^\{]*[;\}])\b|%)/', '$1$2$3', $css); // "001em" to "1em" 654205907a7Sfurun 655205907a7Sfurun // shorten attributes (1em 1em 1em 1em -> 1em) 656205907a7Sfurun $css = preg_replace('/(?<![\w\-])((?:margin|padding|border|border-(?:width|radius)):)([\w\.]+)( \2)+(?=[;\}]| !)/', '$1$2', $css); // "1em 1em 1em 1em" to "1em" 657205907a7Sfurun $css = preg_replace('/(?<![\w\-])((?:margin|padding|border|border-(?:width)):)([\w\.]+) ([\w\.]+) \2 \3(?=[;\}]| !)/', '$1$2 $3', $css); // "1em 2em 1em 2em" to "1em 2em" 658205907a7Sfurun 65978a6aeb1SAndreas Gohr // shorten colors 660205907a7Sfurun $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); 66178a6aeb1SAndreas Gohr 66278a6aeb1SAndreas Gohr return $css; 66378a6aeb1SAndreas Gohr} 66478a6aeb1SAndreas Gohr 665c00aef76SAndreas Gohr/** 666c00aef76SAndreas Gohr * Callback for css_compress() 667c00aef76SAndreas Gohr * 668c00aef76SAndreas Gohr * Keeps short comments (< 5 chars) to maintain typical browser hacks 669c00aef76SAndreas Gohr * 670c00aef76SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 671253d4b48SGerrit Uitslag * 672253d4b48SGerrit Uitslag * @param array $matches 673253d4b48SGerrit Uitslag * @return string 674c00aef76SAndreas Gohr */ 675c00aef76SAndreas Gohrfunction css_comment_cb($matches){ 676c00aef76SAndreas Gohr if(strlen($matches[2]) > 4) return ''; 677c00aef76SAndreas Gohr return $matches[0]; 678c00aef76SAndreas Gohr} 67978a6aeb1SAndreas Gohr 680fe5a50c3SAndreas Gohr/** 681fe5a50c3SAndreas Gohr * Callback for css_compress() 682fe5a50c3SAndreas Gohr * 683fe5a50c3SAndreas Gohr * Strips one line comments but makes sure it will not destroy url() constructs with slashes 684fe5a50c3SAndreas Gohr * 685253d4b48SGerrit Uitslag * @param array $matches 686fe5a50c3SAndreas Gohr * @return string 687fe5a50c3SAndreas Gohr */ 688fe5a50c3SAndreas Gohrfunction css_onelinecomment_cb($matches) { 689fe5a50c3SAndreas Gohr $line = $matches[0]; 690fe5a50c3SAndreas Gohr 691fe5a50c3SAndreas Gohr $i = 0; 692fe5a50c3SAndreas Gohr $len = strlen($line); 693918a4468SAndreas Gohr 694fe5a50c3SAndreas Gohr while ($i< $len){ 695fe5a50c3SAndreas Gohr $nextcom = strpos($line, '//', $i); 696fe5a50c3SAndreas Gohr $nexturl = stripos($line, 'url(', $i); 697fe5a50c3SAndreas Gohr 698fe5a50c3SAndreas Gohr if($nextcom === false) { 699fe5a50c3SAndreas Gohr // no more comments, we're done 700918a4468SAndreas Gohr $i = $len; 701fe5a50c3SAndreas Gohr break; 702fe5a50c3SAndreas Gohr } 703fe5a50c3SAndreas Gohr 704918a4468SAndreas Gohr // keep any quoted string that starts before a comment 705918a4468SAndreas Gohr $nextsqt = strpos($line, "'", $i); 706918a4468SAndreas Gohr $nextdqt = strpos($line, '"', $i); 707918a4468SAndreas Gohr if(min($nextsqt, $nextdqt) < $nextcom) { 708918a4468SAndreas Gohr $skipto = false; 709918a4468SAndreas Gohr if($nextsqt !== false && ($nextdqt === false || $nextsqt < $nextdqt)) { 710918a4468SAndreas Gohr $skipto = strpos($line, "'", $nextsqt+1) +1; 711918a4468SAndreas Gohr } else if ($nextdqt !== false) { 712918a4468SAndreas Gohr $skipto = strpos($line, '"', $nextdqt+1) +1; 713918a4468SAndreas Gohr } 714918a4468SAndreas Gohr 715918a4468SAndreas Gohr if($skipto !== false) { 716918a4468SAndreas Gohr $i = $skipto; 717918a4468SAndreas Gohr continue; 718918a4468SAndreas Gohr } 719918a4468SAndreas Gohr } 720918a4468SAndreas Gohr 721918a4468SAndreas Gohr if($nexturl === false || $nextcom < $nexturl) { 722918a4468SAndreas Gohr // no url anymore, strip comment and be done 723918a4468SAndreas Gohr $i = $nextcom; 724918a4468SAndreas Gohr break; 725918a4468SAndreas Gohr } 726918a4468SAndreas Gohr 727918a4468SAndreas Gohr // we have an upcoming url 728918a4468SAndreas Gohr $i = strpos($line, ')', $nexturl); 729918a4468SAndreas Gohr } 730918a4468SAndreas Gohr 731918a4468SAndreas Gohr return substr($line, 0, $i); 732fe5a50c3SAndreas Gohr} 733fe5a50c3SAndreas Gohr 734e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 735