diff options
author | Christopher Smith <chris@jalakai.co.uk> | 2013-11-05 20:15:39 +0000 |
---|---|---|
committer | Christopher Smith <chris@jalakai.co.uk> | 2013-11-05 20:15:39 +0000 |
commit | de737055c55e54246de5000d601a089328c1af1c (patch) | |
tree | b550180179878affe7bf3d688777ad473e82db82 /lib/exe/css.php | |
parent | 30f686eb67205a1da8765c992e2f9ee1a158c712 (diff) | |
download | rpg-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.php | 30 |
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 * |