summaryrefslogtreecommitdiff
path: root/lib/exe/css.php
diff options
context:
space:
mode:
authorChristopher Smith <chris@jalakai.co.uk>2013-11-05 20:15:39 +0000
committerChristopher Smith <chris@jalakai.co.uk>2013-11-05 20:15:39 +0000
commitde737055c55e54246de5000d601a089328c1af1c (patch)
treeb550180179878affe7bf3d688777ad473e82db82 /lib/exe/css.php
parent30f686eb67205a1da8765c992e2f9ee1a158c712 (diff)
downloadrpg-de737055c55e54246de5000d601a089328c1af1c.tar.gz
rpg-de737055c55e54246de5000d601a089328c1af1c.tar.bz2
update url/file rewriting in css_loadfile() to support @import of less files
Diffstat (limited to 'lib/exe/css.php')
-rw-r--r--lib/exe/css.php30
1 files changed, 28 insertions, 2 deletions
diff --git a/lib/exe/css.php b/lib/exe/css.php
index bc0645400..3929b2d4b 100644
--- a/lib/exe/css.php
+++ b/lib/exe/css.php
@@ -403,12 +403,38 @@ function css_loadfile($file,$location=''){
$css = io_readFile($file);
if(!$location) return $css;
- $css = preg_replace('#(url\([ \'"]*)(?!/|data:|http://|https://| |\'|")#','\\1'.$location,$css);
- $css = preg_replace('#(@import\s+[\'"])(?!/|data:|http://|https://)#', '\\1'.$location, $css);
+ global $css_location;
+ global $css_current_dir;
+ $css_current_dir = preg_replace('#^('.DOKU_INC.(defined('DOKU_UNITTEST')?'|'.realpath(TMP_DIR) : '').')#','',dirname($file)).'/';
+ $css_location = $location;
+
+ $css = preg_replace_callback('#(url\( *)([\'"]?)(.*?)(\2)( *\))#','css_loadfile_callback',$css);
+ $css = preg_replace_callback('#(@import\s+)([\'"])(.*?)(\2)#','css_loadfile_callback',$css);
+# $css = preg_replace_callback('#(url\([ \'"]*)(?!/|data:|http://|https://| |\'|")#','\\1'.$location,$css);
+# $css = preg_replace_callback('#(@import\s+[\'"])(?!/|data:|http://|https://)#', '\\1'.$location, $css);
return $css;
}
+function css_loadfile_callback($match){
+ global $css_location;
+ global $css_current_dir;
+
+ if (preg_match('#^(/|data:|https?://)#',$match[3])) {
+ return $match[0];
+ }
+ else if (substr($match[3],-5) == '.less') {
+ if ($match[3]{0} != '/') {
+ $match[3] = $css_current_dir . $match[3];
+ }
+ }
+ else {
+ $match[3] = $css_location . $match[3];
+ }
+
+ return join('',array_slice($match,1));
+}
+
/**
* Converte local image URLs to data URLs if the filesize is small
*