From baeca33789aa1b9a38a5377d678a7c22f35866b3 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 9 Feb 2022 21:32:50 +0100 Subject: [PATCH] Don't support dark/light mode for IE --- library/Icinga/Application/webrouter.php | 6 ++++-- library/Icinga/Util/LessParser.php | 12 +++++++++--- library/Icinga/Web/LessCompiler.php | 7 +++++-- library/Icinga/Web/StyleSheet.php | 15 ++++++++++----- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/library/Icinga/Application/webrouter.php b/library/Icinga/Application/webrouter.php index 47210808e..9eb5bf6f8 100644 --- a/library/Icinga/Application/webrouter.php +++ b/library/Icinga/Application/webrouter.php @@ -56,10 +56,12 @@ if (in_array($path, $special)) { switch ($path) { case 'css/icinga.css': - Stylesheet::send(); + $forIe11 = (bool) preg_match('/Trident\/7.0;.*rv:11/', $_SERVER['HTTP_USER_AGENT']); + Stylesheet::send(false, $forIe11); exit; case 'css/icinga.min.css': - Stylesheet::send(true); + $forIe11 = (bool) preg_match('/Trident\/7.0;.*rv:11/', $_SERVER['HTTP_USER_AGENT']); + Stylesheet::send(true, $forIe11); exit; case 'js/icinga.dev.js': diff --git a/library/Icinga/Util/LessParser.php b/library/Icinga/Util/LessParser.php index 40bcd69c9..595332a30 100644 --- a/library/Icinga/Util/LessParser.php +++ b/library/Icinga/Util/LessParser.php @@ -14,10 +14,16 @@ require_once 'lessphp/lessc.inc.php'; class LessParser extends lessc { - public function __construct() + /** + * @param bool $disableModes Disable replacing compiled Less colors with CSS var() function calls and don't inject + * light mode calls + */ + public function __construct($disableModes = false) { $this->registerFunction('extract-variable-default', [$this, 'extractVariableDefault']); - $this->setOption('plugins', [new Visitor()]); + if (! $disableModes) { + $this->setOption('plugins', [new Visitor()]); + } } /** @@ -35,7 +41,7 @@ class LessParser extends lessc * background: drop-shadow(5px 0 3px @mixin-parameter); * * @param mixed $value - * @param bool $valAsDefault + * @param bool $valAsDefault * * @return mixed */ diff --git a/library/Icinga/Web/LessCompiler.php b/library/Icinga/Web/LessCompiler.php index 5ed5d5bae..aebff28b1 100644 --- a/library/Icinga/Web/LessCompiler.php +++ b/library/Icinga/Web/LessCompiler.php @@ -58,10 +58,13 @@ class LessCompiler /** * Create a new LESS compiler + * + * @param bool $disableModes Disable replacing compiled Less colors with CSS var() function calls and don't inject + * light mode calls */ - public function __construct() + public function __construct($disableModes = false) { - $this->lessc = new LessParser(); + $this->lessc = new LessParser($disableModes); // Discourage usage of import because we're caching based on an explicit list of LESS files to compile $this->lessc->importDisabled = true; } diff --git a/library/Icinga/Web/StyleSheet.php b/library/Icinga/Web/StyleSheet.php index f7134723a..ab4e9d94c 100644 --- a/library/Icinga/Web/StyleSheet.php +++ b/library/Icinga/Web/StyleSheet.php @@ -113,12 +113,15 @@ class StyleSheet /** * Create the StyleSheet + * + * @param bool $disableModes Disable replacing compiled Less colors with CSS var() function calls and don't inject + * light mode calls */ - public function __construct() + public function __construct($disableModes = false) { $app = Icinga::app(); $this->app = $app; - $this->lessCompiler = new LessCompiler(); + $this->lessCompiler = new LessCompiler($disableModes); $this->pubPath = $app->getBaseDir('public'); $this->collect(); } @@ -221,11 +224,13 @@ class StyleSheet * * Does not cache the stylesheet if the HTTP header Cache-Control or Pragma is set to no-cache. * - * @param bool $minified Whether to compress the stylesheet + * @param bool $minified Whether to compress the stylesheet + * @param bool $disableModes Disable replacing compiled Less colors with CSS var() function calls and don't inject + * light mode calls */ - public static function send($minified = false) + public static function send($minified = false, $disableModes = false) { - $styleSheet = new self(); + $styleSheet = new self($disableModes); $request = $styleSheet->app->getRequest(); $response = $styleSheet->app->getResponse();