summaryrefslogtreecommitdiff
path: root/lib/exe/css.php
diff options
context:
space:
mode:
authorMichael Hamann <michael@content-space.de>2011-01-23 20:33:32 +0100
committerMichael Hamann <michael@content-space.de>2011-01-23 20:33:32 +0100
commitfc756e0d4d88b37c01a9155e675a549430b00593 (patch)
tree7adc185d2c349788961ff7cb8f9bcb25afbce485 /lib/exe/css.php
parent8605afb1b4e2a6a9e11e21a7bf0775bbb0d5af03 (diff)
parent820923f1328bcfe6002831570eb65238411c5b70 (diff)
downloadrpg-fc756e0d4d88b37c01a9155e675a549430b00593.tar.gz
rpg-fc756e0d4d88b37c01a9155e675a549430b00593.tar.bz2
Merge branch 'master' into indexer_improvements
Conflicts: inc/fulltext.php inc/indexer.php lib/exe/indexer.php
Diffstat (limited to 'lib/exe/css.php')
-rw-r--r--lib/exe/css.php31
1 files changed, 29 insertions, 2 deletions
diff --git a/lib/exe/css.php b/lib/exe/css.php
index 76f40c7bb..4db81de0b 100644
--- a/lib/exe/css.php
+++ b/lib/exe/css.php
@@ -122,6 +122,9 @@ function css_out(){
// apply style replacements
$css = css_applystyle($css,$tplinc);
+
+ // place all @import statements at the top of the file
+ $css = css_moveimports($css);
// compress whitespace and comments
if($conf['compress']){
@@ -264,7 +267,8 @@ function css_loadfile($file,$location=''){
$css = io_readFile($file);
if(!$location) return $css;
- $css = preg_replace('#(url\([ \'"]*)((?!/|http://|https://| |\'|"))#','\\1'.$location.'\\3',$css);
+ $css = preg_replace('#(url\([ \'"]*)(?!/|http://|https://| |\'|")#','\\1'.$location,$css);
+ $css = preg_replace('#(@import\s+[\'"])(?!/|http://|https://)#', '\\1'.$location, $css);
return $css;
}
@@ -297,6 +301,29 @@ function css_pluginstyles($mode='screen'){
}
/**
+ * Move all @import statements in a combined stylesheet to the top so they
+ * aren't ignored by the browser.
+ *
+ * @author Gabriel Birke <birke@d-scribe.de>
+ */
+function css_moveimports($css)
+{
+ if(!preg_match_all('/@import\s+(?:url\([^)]+\)|"[^"]+")\s*[^;]*;\s*/', $css, $matches, PREG_OFFSET_CAPTURE)) {
+ return $css;
+ }
+ $newCss = "";
+ $imports = "";
+ $offset = 0;
+ foreach($matches[0] as $match) {
+ $newCss .= substr($css, $offset, $match[1] - $offset);
+ $imports .= $match[0];
+ $offset = $match[1] + strlen($match[0]);
+ }
+ $newCss .= substr($css, $offset);
+ return $imports.$newCss;
+}
+
+/**
* Very simple CSS optimizer
*
* @author Andreas Gohr <andi@splitbrain.org>
@@ -330,4 +357,4 @@ function css_comment_cb($matches){
return $matches[0];
}
-//Setup VIM: ex: et ts=4 enc=utf-8 :
+//Setup VIM: ex: et ts=4 :