xref: /dokuwiki/lib/exe/css.php (revision 123bc813fd93ab5d8dab3cc4a66a09e613a10aa2)
1<?php
2/**
3 * DokuWiki StyleSheet creator
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Andreas Gohr <andi@splitbrain.org>
7 */
8
9if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../');
10if(!defined('NOSESSION')) define('NOSESSION',true); // we do not use a session or authentication here (better caching)
11if(!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT',1); // we gzip ourself here
12if(!defined('NL')) define('NL',"\n");
13require_once(DOKU_INC.'inc/init.php');
14
15// Main (don't run when UNIT test)
16if(!defined('SIMPLE_TEST')){
17    header('Content-Type: text/css; charset=utf-8');
18    css_out();
19}
20
21
22// ---------------------- functions ------------------------------
23
24/**
25 * Output all needed Styles
26 *
27 * @author Andreas Gohr <andi@splitbrain.org>
28 */
29function css_out(){
30    global $conf;
31    global $lang;
32    global $config_cascade;
33    global $INPUT;
34
35    // decide from where to get the template
36    $tpl = trim(preg_replace('/[^\w-]+/','',$INPUT->str('t')));
37    if(!$tpl) $tpl = $conf['template'];
38
39    // load style.ini
40    $styleini = css_styleini($tpl, $INPUT->bool('preview'));
41
42    // find mediatypes
43    if ($INPUT->str('s') == 'feed') {
44        $mediatypes = array('feed');
45        $type = 'feed';
46    } else {
47        $mediatypes = array_unique(array_merge(array('screen', 'all', 'print'), array_keys($styleini['stylesheets'])));
48        $type = '';
49    }
50
51    // The generated script depends on some dynamic options
52    $cache = new cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].$INPUT->int('preview').DOKU_BASE.$tpl.$type,'.css');
53
54    // if old 'default' userstyle setting exists, make it 'screen' userstyle for backwards compatibility
55    if (isset($config_cascade['userstyle']['default'])) {
56        $config_cascade['userstyle']['screen'] = array($config_cascade['userstyle']['default']);
57    }
58
59    // cache influencers
60    $tplinc = tpl_incdir($tpl);
61    $cache_files = getConfigFiles('main');
62    $cache_files[] = $tplinc.'style.ini';
63    $cache_files[] = $tplinc.'style.local.ini'; // @deprecated
64    $cache_files[] = DOKU_CONF."tpl/$tpl/style.ini";
65    $cache_files[] = __FILE__;
66    if($INPUT->bool('preview')) $cache_files[] = $conf['cachedir'].'/preview.ini';
67
68    // Array of needed files and their web locations, the latter ones
69    // are needed to fix relative paths in the stylesheets
70    $files = array();
71    foreach($mediatypes as $mediatype) {
72        $files[$mediatype] = array();
73        // load core styles
74        $files[$mediatype][DOKU_INC.'lib/styles/'.$mediatype.'.css'] = DOKU_BASE.'lib/styles/';
75
76        // load jQuery-UI theme
77        if ($mediatype == 'screen') {
78            $files[$mediatype][DOKU_INC.'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE.'lib/scripts/jquery/jquery-ui-theme/';
79        }
80        // load plugin styles
81        $files[$mediatype] = array_merge($files[$mediatype], css_pluginstyles($mediatype));
82        // load template styles
83        if (isset($styleini['stylesheets'][$mediatype])) {
84            $files[$mediatype] = array_merge($files[$mediatype], $styleini['stylesheets'][$mediatype]);
85        }
86        // load user styles
87        if(!empty($config_cascade['userstyle'][$mediatype])) {
88            foreach($config_cascade['userstyle'][$mediatype] as $userstyle) {
89                $files[$mediatype][$userstyle] = DOKU_BASE;
90            }
91        }
92
93        $cache_files = array_merge($cache_files, array_keys($files[$mediatype]));
94    }
95
96    // check cache age & handle conditional request
97    // This may exit if a cache can be used
98    http_cached($cache->cache,
99                $cache->useCache(array('files' => $cache_files)));
100
101    // start output buffering
102    ob_start();
103
104    // build the stylesheet
105    foreach ($mediatypes as $mediatype) {
106
107        // print the default classes for interwiki links and file downloads
108        if ($mediatype == 'screen') {
109            print '@media screen {';
110            css_interwiki();
111            css_filetypes();
112            print '}';
113        }
114
115        // load files
116        $css_content = '';
117        foreach($files[$mediatype] as $file => $location){
118            $display = str_replace(fullpath(DOKU_INC), '', fullpath($file));
119            $css_content .= "\n/* XXXXXXXXX $display XXXXXXXXX */\n";
120            $css_content .= css_loadfile($file, $location);
121        }
122        switch ($mediatype) {
123            case 'screen':
124                print NL.'@media screen { /* START screen styles */'.NL.$css_content.NL.'} /* /@media END screen styles */'.NL;
125                break;
126            case 'print':
127                print NL.'@media print { /* START print styles */'.NL.$css_content.NL.'} /* /@media END print styles */'.NL;
128                break;
129            case 'all':
130            case 'feed':
131            default:
132                print NL.'/* START rest styles */ '.NL.$css_content.NL.'/* END rest styles */'.NL;
133                break;
134        }
135    }
136    // end output buffering and get contents
137    $css = ob_get_contents();
138    ob_end_clean();
139
140    // strip any source maps
141    stripsourcemaps($css);
142
143    // apply style replacements
144    $css = css_applystyle($css, $styleini['replacements']);
145
146    // parse less
147    $css = css_parseless($css);
148
149    // compress whitespace and comments
150    if($conf['compress']){
151        $css = css_compress($css);
152    }
153
154    // embed small images right into the stylesheet
155    if($conf['cssdatauri']){
156        $base = preg_quote(DOKU_BASE,'#');
157        $css = preg_replace_callback('#(url\([ \'"]*)('.$base.')(.*?(?:\.(png|gif)))#i','css_datauri',$css);
158    }
159
160    http_cached_finish($cache->cache, $css);
161}
162
163/**
164 * Uses phpless to parse LESS in our CSS
165 *
166 * most of this function is error handling to show a nice useful error when
167 * LESS compilation fails
168 *
169 * @param string $css
170 * @return string
171 */
172function css_parseless($css) {
173    global $conf;
174
175    $less = new lessc();
176    $less->importDir[] = DOKU_INC;
177    $less->setPreserveComments(!$conf['compress']);
178
179    if (defined('DOKU_UNITTEST')){
180        $less->importDir[] = TMP_DIR;
181    }
182
183    try {
184        return $less->compile($css);
185    } catch(Exception $e) {
186        // get exception message
187        $msg = str_replace(array("\n", "\r", "'"), array(), $e->getMessage());
188
189        // try to use line number to find affected file
190        if(preg_match('/line: (\d+)$/', $msg, $m)){
191            $msg = substr($msg, 0, -1* strlen($m[0])); //remove useless linenumber
192            $lno = $m[1];
193
194            // walk upwards to last include
195            $lines = explode("\n", $css);
196            for($i=$lno-1; $i>=0; $i--){
197                if(preg_match('/\/(\* XXXXXXXXX )(.*?)( XXXXXXXXX \*)\//', $lines[$i], $m)){
198                    // we found it, add info to message
199                    $msg .= ' in '.$m[2].' at line '.($lno-$i);
200                    break;
201                }
202            }
203        }
204
205        // something went wrong
206        $error = 'A fatal error occured during compilation of the CSS files. '.
207            'If you recently installed a new plugin or template it '.
208            'might be broken and you should try disabling it again. ['.$msg.']';
209
210        echo ".dokuwiki:before {
211            content: '$error';
212            background-color: red;
213            display: block;
214            background-color: #fcc;
215            border-color: #ebb;
216            color: #000;
217            padding: 0.5em;
218        }";
219
220        exit;
221    }
222}
223
224/**
225 * Does placeholder replacements in the style according to
226 * the ones defined in a templates style.ini file
227 *
228 * This also adds the ini defined placeholders as less variables
229 * (sans the surrounding __ and with a ini_ prefix)
230 *
231 * @author Andreas Gohr <andi@splitbrain.org>
232 *
233 * @param string $css
234 * @param array $replacements  array(placeholder => value)
235 * @return string
236 */
237function css_applystyle($css, $replacements) {
238    // we convert ini replacements to LESS variable names
239    // and build a list of variable: value; pairs
240    $less = '';
241    foreach((array) $replacements as $key => $value) {
242        $lkey = trim($key, '_');
243        $lkey = '@ini_'.$lkey;
244        $less .= "$lkey: $value;\n";
245
246        $replacements[$key] = $lkey;
247    }
248
249    // we now replace all old ini replacements with LESS variables
250    $css = strtr($css, $replacements);
251
252    // now prepend the list of LESS variables as the very first thing
253    $css = $less.$css;
254    return $css;
255}
256
257/**
258 * Load style ini contents
259 *
260 * Loads and merges style.ini files from template and config and prepares
261 * the stylesheet modes
262 *
263 * @author Andreas Gohr <andi@splitbrain.org>
264 *
265 * @param string $tpl the used template
266 * @param bool   $preview load preview replacements
267 * @return array with keys 'stylesheets' and 'replacements'
268 */
269function css_styleini($tpl, $preview=false) {
270    global $conf;
271
272    $stylesheets = array(); // mode, file => base
273    $replacements = array(); // placeholder => value
274
275    // load template's style.ini
276    $incbase = tpl_incdir($tpl);
277    $webbase = tpl_basedir($tpl);
278    $ini = $incbase.'style.ini';
279    if(file_exists($ini)){
280        $data = parse_ini_file($ini, true);
281
282        // stylesheets
283        if(is_array($data['stylesheets'])) foreach($data['stylesheets'] as $file => $mode){
284            $stylesheets[$mode][$incbase.$file] = $webbase;
285        }
286
287        // replacements
288        if(is_array($data['replacements'])){
289            $replacements = array_merge($replacements, css_fixreplacementurls($data['replacements'],$webbase));
290        }
291    }
292
293    // load template's style.local.ini
294    // @deprecated 2013-08-03
295    $ini = $incbase.'style.local.ini';
296    if(file_exists($ini)){
297        $data = parse_ini_file($ini, true);
298
299        // stylesheets
300        if(is_array($data['stylesheets'])) foreach($data['stylesheets'] as $file => $mode){
301            $stylesheets[$mode][$incbase.$file] = $webbase;
302        }
303
304        // replacements
305        if(is_array($data['replacements'])){
306            $replacements = array_merge($replacements, css_fixreplacementurls($data['replacements'],$webbase));
307        }
308    }
309
310    // load configs's style.ini
311    $webbase = DOKU_BASE;
312    $ini = DOKU_CONF."tpl/$tpl/style.ini";
313    $incbase = dirname($ini).'/';
314    if(file_exists($ini)){
315        $data = parse_ini_file($ini, true);
316
317        // stylesheets
318        if(is_array($data['stylesheets'])) foreach($data['stylesheets'] as $file => $mode){
319            $stylesheets[$mode][$incbase.$file] = $webbase;
320        }
321
322        // replacements
323        if(is_array($data['replacements'])){
324            $replacements = array_merge($replacements, css_fixreplacementurls($data['replacements'],$webbase));
325        }
326    }
327
328    // allow replacement overwrites in preview mode
329    if($preview) {
330        $webbase = DOKU_BASE;
331        $ini     = $conf['cachedir'].'/preview.ini';
332        if(file_exists($ini)) {
333            $data = parse_ini_file($ini, true);
334            // replacements
335            if(is_array($data['replacements'])) {
336                $replacements = array_merge($replacements, css_fixreplacementurls($data['replacements'], $webbase));
337            }
338        }
339    }
340
341    return array(
342        'stylesheets' => $stylesheets,
343        'replacements' => $replacements
344    );
345}
346
347/**
348 * Amend paths used in replacement relative urls, refer FS#2879
349 *
350 * @author Chris Smith <chris@jalakai.co.uk>
351 *
352 * @param array $replacements with key-value pairs
353 * @param string $location
354 * @return array
355 */
356function css_fixreplacementurls($replacements, $location) {
357    foreach($replacements as $key => $value) {
358        $replacements[$key] = preg_replace('#(url\([ \'"]*)(?!/|data:|http://|https://| |\'|")#','\\1'.$location,$value);
359    }
360    return $replacements;
361}
362
363/**
364 * Prints classes for interwikilinks
365 *
366 * Interwiki links have two classes: 'interwiki' and 'iw_$name>' where
367 * $name is the identifier given in the config. All Interwiki links get
368 * an default style with a default icon. If a special icon is available
369 * for an interwiki URL it is set in it's own class. Both classes can be
370 * overwritten in the template or userstyles.
371 *
372 * @author Andreas Gohr <andi@splitbrain.org>
373 */
374function css_interwiki(){
375
376    // default style
377    echo 'a.interwiki {';
378    echo ' background: transparent url('.DOKU_BASE.'lib/images/interwiki.png) 0px 1px no-repeat;';
379    echo ' padding: 1px 0px 1px 16px;';
380    echo '}';
381
382    // additional styles when icon available
383    $iwlinks = getInterwiki();
384    foreach(array_keys($iwlinks) as $iw){
385        $class = preg_replace('/[^_\-a-z0-9]+/i','_',$iw);
386        if(file_exists(DOKU_INC.'lib/images/interwiki/'.$iw.'.png')){
387            echo "a.iw_$class {";
388            echo '  background-image: url('.DOKU_BASE.'lib/images/interwiki/'.$iw.'.png)';
389            echo '}';
390        }elseif(file_exists(DOKU_INC.'lib/images/interwiki/'.$iw.'.gif')){
391            echo "a.iw_$class {";
392            echo '  background-image: url('.DOKU_BASE.'lib/images/interwiki/'.$iw.'.gif)';
393            echo '}';
394        }
395    }
396}
397
398/**
399 * Prints classes for file download links
400 *
401 * @author Andreas Gohr <andi@splitbrain.org>
402 */
403function css_filetypes(){
404
405    // default style
406    echo '.mediafile {';
407    echo ' background: transparent url('.DOKU_BASE.'lib/images/fileicons/file.png) 0px 1px no-repeat;';
408    echo ' padding-left: 18px;';
409    echo ' padding-bottom: 1px;';
410    echo '}';
411
412    // additional styles when icon available
413    // scan directory for all icons
414    $exts = array();
415    if($dh = opendir(DOKU_INC.'lib/images/fileicons')){
416        while(false !== ($file = readdir($dh))){
417            if(preg_match('/([_\-a-z0-9]+(?:\.[_\-a-z0-9]+)*?)\.(png|gif)/i',$file,$match)){
418                $ext = strtolower($match[1]);
419                $type = '.'.strtolower($match[2]);
420                if($ext!='file' && (!isset($exts[$ext]) || $type=='.png')){
421                    $exts[$ext] = $type;
422                }
423            }
424        }
425        closedir($dh);
426    }
427    foreach($exts as $ext=>$type){
428        $class = preg_replace('/[^_\-a-z0-9]+/','_',$ext);
429        echo ".mf_$class {";
430        echo '  background-image: url('.DOKU_BASE.'lib/images/fileicons/'.$ext.$type.')';
431        echo '}';
432    }
433}
434
435/**
436 * Loads a given file and fixes relative URLs with the
437 * given location prefix
438 *
439 * @param string $file file system path
440 * @param string $location
441 * @return string
442 */
443function css_loadfile($file,$location=''){
444    $css_file = new DokuCssFile($file);
445    return $css_file->load($location);
446}
447
448/**
449 *  Helper class to abstract loading of css/less files
450 *
451 *  @author Chris Smith <chris@jalakai.co.uk>
452 */
453class DokuCssFile {
454
455    protected $filepath;             // file system path to the CSS/Less file
456    protected $location;             // base url location of the CSS/Less file
457    protected $relative_path = null;
458
459    public function __construct($file) {
460        $this->filepath = $file;
461    }
462
463    /**
464     * Load the contents of the css/less file and adjust any relative paths/urls (relative to this file) to be
465     * relative to the dokuwiki root: the web root (DOKU_BASE) for most files; the file system root (DOKU_INC)
466     * for less files.
467     *
468     * @param   string   $location   base url for this file
469     * @return  string               the CSS/Less contents of the file
470     */
471    public function load($location='') {
472        if (!file_exists($this->filepath)) return '';
473
474        $css = io_readFile($this->filepath);
475        if (!$location) return $css;
476
477        $this->location = $location;
478
479        $css = preg_replace_callback('#(url\( *)([\'"]?)(.*?)(\2)( *\))#',array($this,'replacements'),$css);
480        $css = preg_replace_callback('#(@import\s+)([\'"])(.*?)(\2)#',array($this,'replacements'),$css);
481
482        return $css;
483    }
484
485    /**
486     * Get the relative file system path of this file, relative to dokuwiki's root folder, DOKU_INC
487     *
488     * @return string   relative file system path
489     */
490    protected function getRelativePath(){
491
492        if (is_null($this->relative_path)) {
493            $basedir = array(DOKU_INC);
494
495            // during testing, files may be found relative to a second base dir, TMP_DIR
496            if (defined('DOKU_UNITTEST')) {
497                $basedir[] = realpath(TMP_DIR);
498            }
499
500            $basedir = array_map('preg_quote_cb', $basedir);
501            $regex = '/^('.join('|',$basedir).')/';
502            $this->relative_path = preg_replace($regex, '', dirname($this->filepath));
503        }
504
505        return $this->relative_path;
506    }
507
508    /**
509     * preg_replace callback to adjust relative urls from relative to this file to relative
510     * to the appropriate dokuwiki root location as described in the code
511     *
512     * @param  array    see http://php.net/preg_replace_callback
513     * @return string   see http://php.net/preg_replace_callback
514     */
515    public function replacements($match) {
516
517        // not a relative url? - no adjustment required
518        if (preg_match('#^(/|data:|https?://)#',$match[3])) {
519            return $match[0];
520        }
521        // a less file import? - requires a file system location
522        else if (substr($match[3],-5) == '.less') {
523            if ($match[3]{0} != '/') {
524                $match[3] = $this->getRelativePath() . '/' . $match[3];
525            }
526        }
527        // everything else requires a url adjustment
528        else {
529            $match[3] = $this->location . $match[3];
530        }
531
532        return join('',array_slice($match,1));
533    }
534}
535
536/**
537 * Convert local image URLs to data URLs if the filesize is small
538 *
539 * Callback for preg_replace_callback
540 *
541 * @param array $match
542 * @return string
543 */
544function css_datauri($match){
545    global $conf;
546
547    $pre   = unslash($match[1]);
548    $base  = unslash($match[2]);
549    $url   = unslash($match[3]);
550    $ext   = unslash($match[4]);
551
552    $local = DOKU_INC.$url;
553    $size  = @filesize($local);
554    if($size && $size < $conf['cssdatauri']){
555        $data = base64_encode(file_get_contents($local));
556    }
557    if($data){
558        $url = 'data:image/'.$ext.';base64,'.$data;
559    }else{
560        $url = $base.$url;
561    }
562    return $pre.$url;
563}
564
565
566/**
567 * Returns a list of possible Plugin Styles (no existance check here)
568 *
569 * @author Andreas Gohr <andi@splitbrain.org>
570 *
571 * @param string $mediatype
572 * @return array
573 */
574function css_pluginstyles($mediatype='screen'){
575    $list = array();
576    $plugins = plugin_list();
577    foreach ($plugins as $p){
578        $list[DOKU_PLUGIN."$p/$mediatype.css"]  = DOKU_BASE."lib/plugins/$p/";
579        $list[DOKU_PLUGIN."$p/$mediatype.less"]  = DOKU_BASE."lib/plugins/$p/";
580        // alternative for screen.css
581        if ($mediatype=='screen') {
582            $list[DOKU_PLUGIN."$p/style.css"]  = DOKU_BASE."lib/plugins/$p/";
583            $list[DOKU_PLUGIN."$p/style.less"]  = DOKU_BASE."lib/plugins/$p/";
584        }
585    }
586    return $list;
587}
588
589/**
590 * Very simple CSS optimizer
591 *
592 * @author Andreas Gohr <andi@splitbrain.org>
593 *
594 * @param string $css
595 * @return string
596 */
597function css_compress($css){
598    //strip comments through a callback
599    $css = preg_replace_callback('#(/\*)(.*?)(\*/)#s','css_comment_cb',$css);
600
601    //strip (incorrect but common) one line comments
602    $css = preg_replace_callback('/^.*\/\/.*$/m','css_onelinecomment_cb',$css);
603
604    // strip whitespaces
605    $css = preg_replace('![\r\n\t ]+!',' ',$css);
606    $css = preg_replace('/ ?([;,{}\/]) ?/','\\1',$css);
607    $css = preg_replace('/ ?: /',':',$css);
608
609    // number compression
610    $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"
611    $css = preg_replace('/([: ])\.(0)+((?:pt|pc|in|mm|cm|em|ex|px)\b|%)(?=[^\{]*[;\}])/', '$1$2', $css); // ".0em" to "0"
612    $css = preg_replace('/([: ]0)0*(\.0*)?((?:pt|pc|in|mm|cm|em|ex|px)(?=[^\{]*[;\}])\b|%)/', '$1', $css); // "0.0em" to "0"
613    $css = preg_replace('/([: ]\d+)(\.0*)((?:pt|pc|in|mm|cm|em|ex|px)(?=[^\{]*[;\}])\b|%)/', '$1$3', $css); // "1.0em" to "1em"
614    $css = preg_replace('/([: ])0+(\d+|\d*\.\d+)((?:pt|pc|in|mm|cm|em|ex|px)(?=[^\{]*[;\}])\b|%)/', '$1$2$3', $css); // "001em" to "1em"
615
616    // shorten attributes (1em 1em 1em 1em -> 1em)
617    $css = preg_replace('/(?<![\w\-])((?:margin|padding|border|border-(?:width|radius)):)([\w\.]+)( \2)+(?=[;\}]| !)/', '$1$2', $css); // "1em 1em 1em 1em" to "1em"
618    $css = preg_replace('/(?<![\w\-])((?:margin|padding|border|border-(?:width)):)([\w\.]+) ([\w\.]+) \2 \3(?=[;\}]| !)/', '$1$2 $3', $css); // "1em 2em 1em 2em" to "1em 2em"
619
620    // shorten colors
621    $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);
622
623    return $css;
624}
625
626/**
627 * Callback for css_compress()
628 *
629 * Keeps short comments (< 5 chars) to maintain typical browser hacks
630 *
631 * @author Andreas Gohr <andi@splitbrain.org>
632 *
633 * @param array $matches
634 * @return string
635 */
636function css_comment_cb($matches){
637    if(strlen($matches[2]) > 4) return '';
638    return $matches[0];
639}
640
641/**
642 * Callback for css_compress()
643 *
644 * Strips one line comments but makes sure it will not destroy url() constructs with slashes
645 *
646 * @param array $matches
647 * @return string
648 */
649function css_onelinecomment_cb($matches) {
650    $line = $matches[0];
651
652    $i = 0;
653    $len = strlen($line);
654
655    while ($i< $len){
656        $nextcom = strpos($line, '//', $i);
657        $nexturl = stripos($line, 'url(', $i);
658
659        if($nextcom === false) {
660            // no more comments, we're done
661            $i = $len;
662            break;
663        }
664
665        // keep any quoted string that starts before a comment
666        $nextsqt = strpos($line, "'", $i);
667        $nextdqt = strpos($line, '"', $i);
668        if(min($nextsqt, $nextdqt) < $nextcom) {
669            $skipto = false;
670            if($nextsqt !== false && ($nextdqt === false || $nextsqt < $nextdqt)) {
671                $skipto = strpos($line, "'", $nextsqt+1) +1;
672            } else if ($nextdqt !== false) {
673                $skipto = strpos($line, '"', $nextdqt+1) +1;
674            }
675
676            if($skipto !== false) {
677                $i = $skipto;
678                continue;
679            }
680        }
681
682        if($nexturl === false || $nextcom < $nexturl) {
683            // no url anymore, strip comment and be done
684            $i = $nextcom;
685            break;
686        }
687
688        // we have an upcoming url
689        $i = strpos($line, ')', $nexturl);
690    }
691
692    return substr($line, 0, $i);
693}
694
695//Setup VIM: ex: et ts=4 :
696