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 From 4d6524b8916955bf5fa9086042917244751dc03d Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 16 May 2015 16:29:20 +0200 Subject: allow preview style replacements --- lib/exe/css.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index 701cebaed..dc4d7d75c 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -37,7 +37,7 @@ function css_out(){ if(!$tpl) $tpl = $conf['template']; // load style.ini - $styleini = css_styleini($tpl); + $styleini = css_styleini($tpl, $INPUT->bool('preview')); // find mediatypes if ($INPUT->str('s') == 'feed') { @@ -49,7 +49,7 @@ function css_out(){ } // The generated script depends on some dynamic options - $cache = new cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tpl.$type,'.css'); + $cache = new cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].$INPUT->int('preview').DOKU_BASE.$tpl.$type,'.css'); // if old 'default' userstyle setting exists, make it 'screen' userstyle for backwards compatibility if (isset($config_cascade['userstyle']['default'])) { @@ -63,6 +63,7 @@ function css_out(){ $cache_files[] = $tplinc.'style.local.ini'; // @deprecated $cache_files[] = DOKU_CONF."tpl/$tpl/style.ini"; $cache_files[] = __FILE__; + if($INPUT->bool('preview')) $cache_files[] = $conf['cachedir'].'/preview.ini'; // Array of needed files and their web locations, the latter ones // are needed to fix relative paths in the stylesheets @@ -262,9 +263,12 @@ function css_applystyle($css, $replacements) { * @author Andreas Gohr * * @param string $tpl the used template + * @param bool $preview load preview replacements * @return array with keys 'stylesheets' and 'replacements' */ -function css_styleini($tpl) { +function css_styleini($tpl, $preview=false) { + global $conf; + $stylesheets = array(); // mode, file => base $replacements = array(); // placeholder => value @@ -321,6 +325,19 @@ function css_styleini($tpl) { } } + // allow replacement overwrites in preview mode + if($preview) { + $webbase = DOKU_BASE; + $ini = $conf['cachedir'].'/preview.ini'; + if(file_exists($ini)) { + $data = parse_ini_file($ini, true); + // replacements + if(is_array($data['replacements'])) { + $replacements = array_merge($replacements, css_fixreplacementurls($data['replacements'], $webbase)); + } + } + } + return array( 'stylesheets' => $stylesheets, 'replacements' => $replacements -- cgit v1.2.3 From 20a2375a6cfe911180fca2c58673b4554528a372 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 24 Jul 2015 12:23:37 +0200 Subject: Revert "Additionally allow more media types" #982 This reverts commit de4634ec87b1a277c1686990d993dafc43db05ed. --- lib/exe/css.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index 701cebaed..e0bc68312 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -32,25 +32,24 @@ 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 style.ini - $styleini = css_styleini($tpl); - - // find mediatypes if ($INPUT->str('s') == 'feed') { $mediatypes = array('feed'); $type = 'feed'; } else { - $mediatypes = array_unique(array_merge(array('screen', 'all', 'print'), array_keys($styleini['stylesheets']))); + $mediatypes = array('screen', 'all', 'print'); $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'] = array($config_cascade['userstyle']['default']); -- cgit v1.2.3 From 656e58456ff0e79ba9cdcbffc1e23c89d43c123c Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Fri, 31 Jul 2015 10:35:23 +0100 Subject: removed deprecated support for style.local.ini use conf/tpl//style.ini instead --- lib/exe/css.php | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index 3b8a524bc..925b78a76 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -59,7 +59,6 @@ function css_out(){ $tplinc = tpl_incdir($tpl); $cache_files = getConfigFiles('main'); $cache_files[] = $tplinc.'style.ini'; - $cache_files[] = $tplinc.'style.local.ini'; // @deprecated $cache_files[] = DOKU_CONF."tpl/$tpl/style.ini"; $cache_files[] = __FILE__; if($INPUT->bool('preview')) $cache_files[] = $conf['cachedir'].'/preview.ini'; @@ -289,23 +288,6 @@ function css_styleini($tpl, $preview=false) { } } - // load template's style.local.ini - // @deprecated 2013-08-03 - $ini = $incbase.'style.local.ini'; - if(file_exists($ini)){ - $data = parse_ini_file($ini, true); - - // stylesheets - if(is_array($data['stylesheets'])) foreach($data['stylesheets'] as $file => $mode){ - $stylesheets[$mode][$incbase.$file] = $webbase; - } - - // replacements - if(is_array($data['replacements'])){ - $replacements = array_merge($replacements, css_fixreplacementurls($data['replacements'],$webbase)); - } - } - // load configs's style.ini $webbase = DOKU_BASE; $ini = DOKU_CONF."tpl/$tpl/style.ini"; -- cgit v1.2.3