diff options
Diffstat (limited to 'lib/exe/css.php')
-rw-r--r-- | lib/exe/css.php | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/lib/exe/css.php b/lib/exe/css.php index cab7384b2..6c1d60751 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -56,7 +56,7 @@ function css_out(){ } // cache influencers - $tplinc = tpl_basedir($tpl); + $tplinc = tpl_incdir($tpl); $cache_files = getConfigFiles('main'); $cache_files[] = $tplinc.'style.ini'; $cache_files[] = $tplinc.'style.local.ini'; // @deprecated @@ -133,6 +133,9 @@ function css_out(){ $css = ob_get_contents(); ob_end_clean(); + // strip any source maps + stripsourcemaps($css); + // apply style replacements $css = css_applystyle($css, $styleini['replacements']); @@ -552,7 +555,7 @@ function css_compress($css){ $css = preg_replace_callback('#(/\*)(.*?)(\*/)#s','css_comment_cb',$css); //strip (incorrect but common) one line comments - $css = preg_replace('/(?<!:)\/\/.*$/m','',$css); + $css = preg_replace_callback('/^.*\/\/.*$/m','css_onelinecomment_cb',$css); // strip whitespaces $css = preg_replace('![\r\n\t ]+!',' ',$css); @@ -588,4 +591,58 @@ function css_comment_cb($matches){ return $matches[0]; } +/** + * Callback for css_compress() + * + * Strips one line comments but makes sure it will not destroy url() constructs with slashes + * + * @param $matches + * @return string + */ +function css_onelinecomment_cb($matches) { + $line = $matches[0]; + + $i = 0; + $len = strlen($line); + + while ($i< $len){ + $nextcom = strpos($line, '//', $i); + $nexturl = stripos($line, 'url(', $i); + + if($nextcom === false) { + // no more comments, we're done + $i = $len; + break; + } + + // keep any quoted string that starts before a comment + $nextsqt = strpos($line, "'", $i); + $nextdqt = strpos($line, '"', $i); + if(min($nextsqt, $nextdqt) < $nextcom) { + $skipto = false; + if($nextsqt !== false && ($nextdqt === false || $nextsqt < $nextdqt)) { + $skipto = strpos($line, "'", $nextsqt+1) +1; + } else if ($nextdqt !== false) { + $skipto = strpos($line, '"', $nextdqt+1) +1; + } + + if($skipto !== false) { + $i = $skipto; + continue; + } + } + + if($nexturl === false || $nextcom < $nexturl) { + // no url anymore, strip comment and be done + $i = $nextcom; + break; + } + + // we have an upcoming url + $i = strpos($line, ')', $nexturl); + } + + return substr($line, 0, $i); +} + //Setup VIM: ex: et ts=4 : |