diff options
author | Gerry Weißbach <gerry.w@gammaproduction.de> | 2014-07-16 08:02:34 +0200 |
---|---|---|
committer | Gerry Weißbach <gerry.w@gammaproduction.de> | 2014-07-16 08:02:34 +0200 |
commit | 0bd5b90b4c1294b3c9abc1977060f971dc2e2744 (patch) | |
tree | ac79a7402ffef718685f16dbba6692a0c9b5f458 /lib/exe/css.php | |
parent | 1858e4d7685782550789fd8c228e55ae319bc37a (diff) | |
parent | 80679bafa1a5ed611bafc603afd0ae7b2b5954a7 (diff) | |
download | rpg-0bd5b90b4c1294b3c9abc1977060f971dc2e2744.tar.gz rpg-0bd5b90b4c1294b3c9abc1977060f971dc2e2744.tar.bz2 |
Merge remote-tracking branch 'splitbrain/master'
Diffstat (limited to 'lib/exe/css.php')
-rw-r--r-- | lib/exe/css.php | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/lib/exe/css.php b/lib/exe/css.php index f273b7ee4..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 @@ -70,6 +70,7 @@ function css_out(){ $files[$mediatype] = array(); // load core styles $files[$mediatype][DOKU_INC.'lib/styles/'.$mediatype.'.css'] = DOKU_BASE.'lib/styles/'; + // load jQuery-UI theme if ($mediatype == 'screen') { $files[$mediatype][DOKU_INC.'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE.'lib/scripts/jquery/jquery-ui-theme/'; @@ -132,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']); @@ -551,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); @@ -587,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 : |