From 73f25ac04a7caaa8cdb07bfc71e807f46f227f97 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 2 Feb 2014 17:52:32 +0100 Subject: fix error on CSS includes on windows The regex wasn't properly escaped here which lead to problems when the path contains backslashes. This is the root cause of the bug reported at https://github.com/cosmocode/edittable/issues/19 --- lib/exe/css.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index c96dedd37..f273b7ee4 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -456,8 +456,9 @@ class DokuCssFile { if (defined('DOKU_UNITTEST')) { $basedir[] = realpath(TMP_DIR); } - $regex = '#^('.join('|',$basedir).')#'; + $basedir = array_map('preg_quote_cb', $basedir); + $regex = '/^('.join('|',$basedir).')/'; $this->relative_path = preg_replace($regex, '', dirname($this->filepath)); } -- cgit v1.2.3 From af4684ac7612e83f2381ef2fc4146358a5a04114 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 15 Feb 2014 11:12:55 +0100 Subject: move geshi highlighting to it's own LESS file --- lib/exe/css.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index f273b7ee4..537885c89 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -70,6 +70,10 @@ function css_out(){ $files[$mediatype] = array(); // load core styles $files[$mediatype][DOKU_INC.'lib/styles/'.$mediatype.'.css'] = DOKU_BASE.'lib/styles/'; + if($mediatype == 'screen') { + $files[$mediatype][DOKU_INC.'lib/styles/geshi.less'] = DOKU_BASE.'lib/styles/'; + } + // load jQuery-UI theme if ($mediatype == 'screen') { $files[$mediatype][DOKU_INC.'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE.'lib/scripts/jquery/jquery-ui-theme/'; -- cgit v1.2.3 From 3593102dfd174c90f99e841f66b60269bfb03be9 Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Sat, 15 Feb 2014 11:37:01 +0000 Subject: included geshi styles per @import, removed from lib/exe/css --- 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 537885c89..cab7384b2 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -70,9 +70,6 @@ function css_out(){ $files[$mediatype] = array(); // load core styles $files[$mediatype][DOKU_INC.'lib/styles/'.$mediatype.'.css'] = DOKU_BASE.'lib/styles/'; - if($mediatype == 'screen') { - $files[$mediatype][DOKU_INC.'lib/styles/geshi.less'] = DOKU_BASE.'lib/styles/'; - } // load jQuery-UI theme if ($mediatype == 'screen') { -- cgit v1.2.3 From fe5a50c39e9bd837f887ea7ad8335717a6c6ab92 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 5 Mar 2014 19:37:43 +0100 Subject: fix single line comments in CSS compression double slashes in url() always have to be ignored --- lib/exe/css.php | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index cab7384b2..0a2a5a406 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -552,7 +552,7 @@ function css_compress($css){ $css = preg_replace_callback('#(/\*)(.*?)(\*/)#s','css_comment_cb',$css); //strip (incorrect but common) one line comments - $css = preg_replace('/(? Date: Wed, 5 Mar 2014 20:06:24 +0100 Subject: fixed online comment stripping --- lib/exe/css.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index 0a2a5a406..178895e99 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -611,16 +611,11 @@ function css_onelinecomment_cb($matches) { $out .= substr($line, $i, $len-$i); break; } - if($nexturl === false) { + if($nexturl === false || $nextcom < $nexturl) { // no url anymore, strip comment and be done $out .= substr($line, $i, $nextcom-$i); break; } - if($nextcom < $nexturl) { - // that comment comments out the url - $out .= substr($line, $i, $len-$i); - break; - } // we have an upcoming url $urlclose = strpos($line, ')', $nexturl); $out .= substr($line, $i, $urlclose-$i); -- cgit v1.2.3 From f8fb2d1811251304687b805a60b489f63cb5c4fb Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 15 Mar 2014 21:29:33 +0100 Subject: strip sourcemaps in CSS and JS #601 source maps are invalid for our dispatched sources and may even cause problems. this makes sure any sourcemap declarations are stripped from the output --- lib/exe/css.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index cab7384b2..9ac70905b 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -133,6 +133,9 @@ function css_out(){ $css = ob_get_contents(); ob_end_clean(); + // strip any source maps + stripsourcemaps($css); + // apply style replacements $css = css_applystyle($css, $styleini['replacements']); -- cgit v1.2.3 From 259571aa7559630d429d0046aa56d1089a6eed17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Koutn=C3=BD?= Date: Sun, 16 Mar 2014 10:20:45 +0100 Subject: Fixed cache dependency for template's style.ini Web path was used instead of filesystem one. --- 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 cab7384b2..ab5c03f0e 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 -- cgit v1.2.3 From 918a4468877109c2ba2f82fa4e1a225a4738ed9a Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 14 May 2014 19:24:01 +0200 Subject: don't treat double slashes as comments when used in string This avoids treating double slashes as single line comments in CSS when they are used in a filter or content string. closes #638 --- lib/exe/css.php | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index 30d0d18c5..6c1d60751 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -602,30 +602,47 @@ function css_comment_cb($matches){ 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); + $i = $len; break; } + + // keep any quoted string that starts before a comment + $nextsqt = strpos($line, "'", $i); + $nextdqt = strpos($line, '"', $i); + if(min($nextsqt, $nextdqt) < $nextcom) { + $skipto = false; + if($nextsqt !== false && ($nextdqt === false || $nextsqt < $nextdqt)) { + $skipto = strpos($line, "'", $nextsqt+1) +1; + } else if ($nextdqt !== false) { + $skipto = strpos($line, '"', $nextdqt+1) +1; + } + + if($skipto !== false) { + $i = $skipto; + continue; + } + } + if($nexturl === false || $nextcom < $nexturl) { // no url anymore, strip comment and be done - $out .= substr($line, $i, $nextcom-$i); + $i = $nextcom; break; } + // we have an upcoming url - $urlclose = strpos($line, ')', $nexturl); - $out .= substr($line, $i, $urlclose-$i); - $i = $urlclose; + $i = strpos($line, ')', $nexturl); } - return $out; + return substr($line, 0, $i); } //Setup VIM: ex: et ts=4 : -- cgit v1.2.3 From de4634ec87b1a277c1686990d993dafc43db05ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerry=20Wei=C3=9Fbach?= Date: Fri, 12 Sep 2014 08:41:57 +0200 Subject: Additionally allow more media types They are generated from the default ones and any additional one given by the template. This allows to e.g. split admin styles from end user styles in a closed wiki. You can then deliver only the user styles using the metaheaders plugin. --- lib/exe/css.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index 6c1d60751..902996062 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -32,24 +32,25 @@ function css_out(){ global $config_cascade; global $INPUT; + // decide from where to get the template + $tpl = trim(preg_replace('/[^\w-]+/','',$INPUT->str('t'))); + if(!$tpl) $tpl = $conf['template']; + + // load styl.ini + $styleini = css_styleini($tpl); + + // find mediatypes if ($INPUT->str('s') == 'feed') { $mediatypes = array('feed'); $type = 'feed'; } else { - $mediatypes = array('screen', 'all', 'print'); + $mediatypes = array_unique(array_merge(array('screen', 'all', 'print'), array_keys($styleini['stylesheets']))); $type = ''; } - // decide from where to get the template - $tpl = trim(preg_replace('/[^\w-]+/','',$INPUT->str('t'))); - if(!$tpl) $tpl = $conf['template']; - // The generated script depends on some dynamic options $cache = new cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tpl.$type,'.css'); - // load styl.ini - $styleini = css_styleini($tpl); - // if old 'default' userstyle setting exists, make it 'screen' userstyle for backwards compatibility if (isset($config_cascade['userstyle']['default'])) { $config_cascade['userstyle']['screen'] = $config_cascade['userstyle']['default']; -- cgit v1.2.3 From 253d4b48ec708eb42033862dc15c8576f44a48ed Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 1 Oct 2014 15:32:05 +0200 Subject: more PHPDocs, unused var, small bit code reformatting --- lib/exe/css.php | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index 6c1d60751..2212656d2 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -162,7 +162,7 @@ function css_out(){ * most of this function is error handling to show a nice useful error when * LESS compilation fails * - * @param $css + * @param string $css * @return string */ function css_parseless($css) { @@ -222,6 +222,10 @@ function css_parseless($css) { * (sans the surrounding __ and with a ini_ prefix) * * @author Andreas Gohr + * + * @param string $css + * @param array $replacements array(placeholder => value) + * @return string */ function css_applystyle($css, $replacements) { // we convert ini replacements to LESS variable names @@ -250,6 +254,7 @@ function css_applystyle($css, $replacements) { * the stylesheet modes * * @author Andreas Gohr + * * @param string $tpl the used template * @return array with keys 'stylesheets' and 'replacements' */ @@ -320,6 +325,10 @@ function css_styleini($tpl) { * Amend paths used in replacement relative urls, refer FS#2879 * * @author Chris Smith + * + * @param array $replacements with key-value pairs + * @param string $location + * @return array */ function css_fixreplacementurls($replacements, $location) { foreach($replacements as $key => $value) { @@ -403,6 +412,10 @@ function css_filetypes(){ /** * Loads a given file and fixes relative URLs with the * given location prefix + * + * @param string $file file system path + * @param string $location + * @return string */ function css_loadfile($file,$location=''){ $css_file = new DokuCssFile($file); @@ -501,6 +514,9 @@ class DokuCssFile { * Convert local image URLs to data URLs if the filesize is small * * Callback for preg_replace_callback + * + * @param array $match + * @return string */ function css_datauri($match){ global $conf; @@ -528,9 +544,11 @@ function css_datauri($match){ * Returns a list of possible Plugin Styles (no existance check here) * * @author Andreas Gohr + * + * @param string $mediatype + * @return array */ function css_pluginstyles($mediatype='screen'){ - global $lang; $list = array(); $plugins = plugin_list(); foreach ($plugins as $p){ @@ -549,6 +567,9 @@ function css_pluginstyles($mediatype='screen'){ * Very simple CSS optimizer * * @author Andreas Gohr + * + * @param string $css + * @return string */ function css_compress($css){ //strip comments through a callback @@ -585,6 +606,9 @@ function css_compress($css){ * Keeps short comments (< 5 chars) to maintain typical browser hacks * * @author Andreas Gohr + * + * @param array $matches + * @return string */ function css_comment_cb($matches){ if(strlen($matches[2]) > 4) return ''; @@ -596,7 +620,7 @@ function css_comment_cb($matches){ * * Strips one line comments but makes sure it will not destroy url() constructs with slashes * - * @param $matches + * @param array $matches * @return string */ function css_onelinecomment_cb($matches) { -- cgit v1.2.3 From 7d247a3cecc7d9f7d6e3c84a3589c591d7ed09c0 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Sat, 11 Oct 2014 10:41:57 +0200 Subject: preserve comments in less if 'compress' config disabled Otherwise comments are never visible in css.php --- lib/exe/css.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index 6c1d60751..f7235fd4e 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -166,8 +166,11 @@ function css_out(){ * @return string */ function css_parseless($css) { + global $conf; + $less = new lessc(); $less->importDir[] = DOKU_INC; + $less->setPreserveComments(!$conf['compress']); if (defined('DOKU_UNITTEST')){ $less->importDir[] = TMP_DIR; -- cgit v1.2.3 From fd18b5f4e227c2b114d961b81feecce658597226 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 22 Oct 2014 11:07:46 +0200 Subject: visibility from private to protected for DokuCssFile --- lib/exe/css.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index f7235fd4e..9645b96bc 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -421,7 +421,7 @@ class DokuCssFile { protected $filepath; // file system path to the CSS/Less file protected $location; // base url location of the CSS/Less file - private $relative_path = null; + protected $relative_path = null; public function __construct($file) { $this->filepath = $file; @@ -454,7 +454,7 @@ class DokuCssFile { * * @return string relative file system path */ - private function getRelativePath(){ + protected function getRelativePath(){ if (is_null($this->relative_path)) { $basedir = array(DOKU_INC); -- cgit v1.2.3 From 7b909d5e68cfee08dd85a3f28a2bdc9d6f41aaff Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 10 Dec 2014 21:24:29 +0100 Subject: Extendable config cascade for userstyles and userscript Added user*.less files to config --- lib/exe/css.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index 77674d251..b1065f518 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -52,7 +52,7 @@ function css_out(){ // if old 'default' userstyle setting exists, make it 'screen' userstyle for backwards compatibility if (isset($config_cascade['userstyle']['default'])) { - $config_cascade['userstyle']['screen'] = $config_cascade['userstyle']['default']; + $config_cascade['userstyle']['screen'] = array($config_cascade['userstyle']['default']); } // cache influencers @@ -82,8 +82,10 @@ function css_out(){ $files[$mediatype] = array_merge($files[$mediatype], $styleini['stylesheets'][$mediatype]); } // load user styles - if(isset($config_cascade['userstyle'][$mediatype])){ - $files[$mediatype][$config_cascade['userstyle'][$mediatype]] = DOKU_BASE; + if(!empty($config_cascade['userstyle'][$mediatype])) { + foreach($config_cascade['userstyle'][$mediatype] as $userstyle) { + $files[$mediatype][$userstyle] = DOKU_BASE; + } } $cache_files = array_merge($cache_files, array_keys($files[$mediatype])); -- cgit v1.2.3 From 79e79377626799a77c11aa7849cb9c64305590c8 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 7 Jan 2015 10:47:45 +0100 Subject: Remove error supression for file_exists() In an older version of PHP a file_exists() call would issue a warning when the file did not exist. This was fixed in later PHP releases. Since we require PHP 5.3 now, there's no need to supress any error here anymore. This might even give a minor performance boost. --- lib/exe/css.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index b1065f518..e0bc68312 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -365,11 +365,11 @@ function css_interwiki(){ $iwlinks = getInterwiki(); foreach(array_keys($iwlinks) as $iw){ $class = preg_replace('/[^_\-a-z0-9]+/i','_',$iw); - if(@file_exists(DOKU_INC.'lib/images/interwiki/'.$iw.'.png')){ + if(file_exists(DOKU_INC.'lib/images/interwiki/'.$iw.'.png')){ echo "a.iw_$class {"; echo ' background-image: url('.DOKU_BASE.'lib/images/interwiki/'.$iw.'.png)'; echo '}'; - }elseif(@file_exists(DOKU_INC.'lib/images/interwiki/'.$iw.'.gif')){ + }elseif(file_exists(DOKU_INC.'lib/images/interwiki/'.$iw.'.gif')){ echo "a.iw_$class {"; echo ' background-image: url('.DOKU_BASE.'lib/images/interwiki/'.$iw.'.gif)'; echo '}'; @@ -451,7 +451,7 @@ class DokuCssFile { * @return string the CSS/Less contents of the file */ public function load($location='') { - if (!@file_exists($this->filepath)) return ''; + if (!file_exists($this->filepath)) return ''; $css = io_readFile($this->filepath); if (!$location) return $css; -- cgit v1.2.3 From 7f253bcd8205f51a47f75fd97a45b1c573633c4c Mon Sep 17 00:00:00 2001 From: Rainbow Spike Date: Mon, 12 Jan 2015 22:06:45 +1000 Subject: Update css.php 1 little fix --- 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 3b8bc80bc..701cebaed 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -36,7 +36,7 @@ function css_out(){ $tpl = trim(preg_replace('/[^\w-]+/','',$INPUT->str('t'))); if(!$tpl) $tpl = $conf['template']; - // load styl.ini + // load style.ini $styleini = css_styleini($tpl); // find mediatypes -- cgit v1.2.3