summaryrefslogtreecommitdiff
path: root/lib/exe/css.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/exe/css.php')
-rw-r--r--lib/exe/css.php41
1 files changed, 39 insertions, 2 deletions
diff --git a/lib/exe/css.php b/lib/exe/css.php
index 9ac70905b..30d0d18c5 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
@@ -555,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);
@@ -591,4 +591,41 @@ 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];
+
+ $out = '';
+ $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
+ $out .= substr($line, $i, $len-$i);
+ break;
+ }
+ if($nexturl === false || $nextcom < $nexturl) {
+ // no url anymore, strip comment and be done
+ $out .= substr($line, $i, $nextcom-$i);
+ break;
+ }
+ // we have an upcoming url
+ $urlclose = strpos($line, ')', $nexturl);
+ $out .= substr($line, $i, $urlclose-$i);
+ $i = $urlclose;
+ }
+
+ return $out;
+}
+
//Setup VIM: ex: et ts=4 :