From 88833bac87e7fb295c0479a8260d1d63051bca8d Mon Sep 17 00:00:00 2001 From: flammy Date: Mon, 24 Jun 2013 15:05:59 +0300 Subject: Fixes validation problems with base64 encoded images in CSS. --- lib/exe/css.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index 1e662c64a..768c8eda4 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -314,7 +314,7 @@ function css_datauri($match){ $data = base64_encode(file_get_contents($local)); } if($data){ - $url = 'data:image/'.$ext.';base64,'.$data; + $url = '\'data:image/'.$ext.';base64,'.$data.'\''; }else{ $url = $base.$url; } -- cgit v1.2.3 From d4a1ece8f011dd69db05b83d2f98e3207f1a7e48 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 29 Jul 2013 20:06:01 +0200 Subject: add LESS support still needs testing --- lib/exe/css.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index 1e662c64a..4a9c825c1 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -154,7 +154,11 @@ function css_out(){ // apply style replacements $css = css_applystyle($css,$tplinc); - // place all @import statements at the top of the file + // parse LESS + $less = new lessc(); + $css = $less->compile($css); + + // place all remaining @import statements at the top of the file $css = css_moveimports($css); // compress whitespace and comments @@ -175,6 +179,9 @@ function css_out(){ * Does placeholder replacements in the style according to * the ones defined in a templates style.ini file * + * This also adds the ini defined placeholders as less variables + * (sans the surrounding __ and with a ini_ prefix) + * * @author Andreas Gohr */ function css_applystyle($css,$tplinc){ @@ -182,6 +189,13 @@ function css_applystyle($css,$tplinc){ if($styleini){ $css = strtr($css,$styleini['replacements']); + + $less = ''; + foreach($styleini as $key => $value){ + $key = trim($key, '_'); + $key = '@ini_'.$key; + $less .= "$key: $value\n"; + } } return $css; } @@ -333,14 +347,17 @@ function css_pluginstyles($mediatype='screen'){ $plugins = plugin_list(); foreach ($plugins as $p){ $list[DOKU_PLUGIN."$p/$mediatype.css"] = DOKU_BASE."lib/plugins/$p/"; + $list[DOKU_PLUGIN."$p/$mediatype.less"] = DOKU_BASE."lib/plugins/$p/"; // alternative for screen.css if ($mediatype=='screen') { $list[DOKU_PLUGIN."$p/style.css"] = DOKU_BASE."lib/plugins/$p/"; + $list[DOKU_PLUGIN."$p/style.less"] = DOKU_BASE."lib/plugins/$p/"; } // @deprecated 2012-04-09: rtl will cease to be a mode of its own, // please use "[dir=rtl]" in any css file in all, screen or print mode instead if($lang['direction'] == 'rtl'){ $list[DOKU_PLUGIN."$p/rtl.css"] = DOKU_BASE."lib/plugins/$p/"; + $list[DOKU_PLUGIN."$p/rtl.less"] = DOKU_BASE."lib/plugins/$p/"; } } return $list; -- cgit v1.2.3 From c51b334ee77310dc0055311092f224be0342cd65 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 30 Jul 2013 12:07:15 +0200 Subject: fixed ini replacement to less variables stuff --- lib/exe/css.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index 4a9c825c1..04516e8ba 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -191,11 +191,13 @@ function css_applystyle($css,$tplinc){ $css = strtr($css,$styleini['replacements']); $less = ''; - foreach($styleini as $key => $value){ + foreach($styleini['replacements'] as $key => $value){ $key = trim($key, '_'); $key = '@ini_'.$key; - $less .= "$key: $value\n"; + $less .= "$key: $value;\n"; } + + $css = $less.$css; } return $css; } -- cgit v1.2.3 From cbe37079b2519e6a79696ab6525a61498ab3c3a6 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 30 Jul 2013 15:56:29 +0200 Subject: convert ini replacements to less vars first This makes it possible to safely overwrite ini replacements from within any less file --- lib/exe/css.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index 04516e8ba..0157e6a40 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -154,6 +154,9 @@ function css_out(){ // apply style replacements $css = css_applystyle($css,$tplinc); + print $css; + + // parse LESS $less = new lessc(); $css = $less->compile($css); @@ -188,15 +191,21 @@ function css_applystyle($css,$tplinc){ $styleini = css_styleini($tplinc); if($styleini){ - $css = strtr($css,$styleini['replacements']); - + // we convert ini replacements to LESS variable names + // and build a list of variable: value; pairs $less = ''; foreach($styleini['replacements'] as $key => $value){ - $key = trim($key, '_'); - $key = '@ini_'.$key; - $less .= "$key: $value;\n"; + $lkey = trim($key, '_'); + $lkey = '@ini_'.$lkey; + $less .= "$lkey: $value;\n"; + + $styleini['replacements'][$key] = $lkey; } + // we now replace all old ini replacements with LESS variables + $css = strtr($css, $styleini['replacements']); + + // now prepend the list of LESS variables as the very first thing $css = $less.$css; } return $css; -- cgit v1.2.3 From fbaa87779929e23ede8a79fd3890ef493fdb1d81 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 30 Jul 2013 16:00:28 +0200 Subject: removed debug statement. sorry --- lib/exe/css.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index 0157e6a40..cd531ef35 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -154,9 +154,6 @@ function css_out(){ // apply style replacements $css = css_applystyle($css,$tplinc); - print $css; - - // parse LESS $less = new lessc(); $css = $less->compile($css); -- cgit v1.2.3 From fd975da73e627193ca68a681ea6b2556c8327f63 Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Wed, 31 Jul 2013 11:58:47 +0100 Subject: removed possibility to have rtl.less files in plugins --- lib/exe/css.php | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index cd531ef35..5c966db82 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -365,7 +365,6 @@ function css_pluginstyles($mediatype='screen'){ // please use "[dir=rtl]" in any css file in all, screen or print mode instead if($lang['direction'] == 'rtl'){ $list[DOKU_PLUGIN."$p/rtl.css"] = DOKU_BASE."lib/plugins/$p/"; - $list[DOKU_PLUGIN."$p/rtl.less"] = DOKU_BASE."lib/plugins/$p/"; } } return $list; -- cgit v1.2.3 From 72a66eb76026e69cd4554035a010693d6ae017ad Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 2 Aug 2013 18:12:46 +0200 Subject: check less compilation for errors This now gives proper files and line numbers for errors --- lib/exe/css.php | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index 5c966db82..91fc11d66 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -131,6 +131,8 @@ function css_out(){ // load files $css_content = ''; foreach($files[$mediatype] as $file => $location){ + $display = str_replace(fullpath(DOKU_INC), '', fullpath($file)); + $css_content .= "\n/* XXXXXXXXX $display XXXXXXXXX */\n"; $css_content .= css_loadfile($file, $location); } switch ($mediatype) { @@ -154,9 +156,8 @@ function css_out(){ // apply style replacements $css = css_applystyle($css,$tplinc); - // parse LESS - $less = new lessc(); - $css = $less->compile($css); + // parse less + $css = css_parseless($css); // place all remaining @import statements at the top of the file $css = css_moveimports($css); @@ -175,6 +176,59 @@ function css_out(){ http_cached_finish($cache->cache, $css); } +/** + * Uses phpless to parse LESS in our CSS + * + * most of this function is error handling to show a nice useful error when + * LESS compilation fails + * + * @param $css + * @return string + */ +function css_parseless($css) { + $less = new lessc(); + try { + return $less->compile($css); + } catch(Exception $e) { + // get exception message + $msg = str_replace(array("\n", "\r", "'"), array(), $e->getMessage()); + + // try to use line number to find affected file + if(preg_match('/line: (\d+)$/', $msg, $m)){ + $msg = substr($msg, 0, -1* strlen($m[0])); //remove useless linenumber + $lno = $m[1]; + + // walk upwards to last include + $lines = explode("\n", $css); + $count = count($lines); + for($i=$lno-1; $i>=0; $i--){ + if(preg_match('/\/(\* XXXXXXXXX )(.*?)( XXXXXXXXX \*)\//', $lines[$i], $m)){ + // we found it, add info to message + $msg .= ' in '.$m[2].' at line '.($lno-$i); + break; + } + } + } + + // something went wrong + $error = 'A fatal error occured during compilation of the CSS files. '. + 'If you recently installed a new plugin or template it '. + 'might be broken and you should try disabling it again. ['.$msg.']'; + + echo ".dokuwiki:before { + content: '$error'; + background-color: red; + display: block; + background-color: #fcc; + border-color: #ebb; + color: #000; + padding: 0.5em; + }"; + + exit; + } +} + /** * Does placeholder replacements in the style according to * the ones defined in a templates style.ini file -- cgit v1.2.3