Commit c05228d2 authored by Johan Cwiklinski's avatar Johan Cwiklinski

Merge branch '9.5/bugfixes'

parents b787d1b5 9a8e9672
......@@ -45,4 +45,15 @@ include_once GLPI_ROOT . '/inc/config.php';
$css = Html::compileScss($_GET);
header('Content-Type: text/css');
$is_cacheable = !isset($_GET['debug']) && !isset($_GET['nocache']);
if ($is_cacheable) {
// Makes CSS cacheable by browsers and proxies
$max_age = WEEK_TIMESTAMP;
header_remove('Pragma');
header('Cache-Control: public');
header('Cache-Control: max-age=' . $max_age);
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + $max_age));
}
echo $css;
......@@ -47,6 +47,11 @@ echo "<html lang=\"{$CFG_GLPI["languages"][$_SESSION['glpilanguage']][3]}\">";
<?php
echo Html::scss('glpi-legacy');
if (isset($_SESSION['glpihighcontrast_css']) && $_SESSION['glpihighcontrast_css']) {
echo Html::scss('css/highcontrast');
}
$theme = isset($_SESSION['glpipalette']) ? $_SESSION['glpipalette'] : 'auror';
echo Html::scss('css/palettes/' . $theme);
echo Html::script($CFG_GLPI["root_doc"].'/script.js');
?>
......
......@@ -1280,6 +1280,11 @@ class Html {
// CSS link
echo Html::scss('glpi-legacy');
if (isset($_SESSION['glpihighcontrast_css']) && $_SESSION['glpihighcontrast_css']) {
echo Html::scss('css/highcontrast');
}
$theme = isset($_SESSION['glpipalette']) ? $_SESSION['glpipalette'] : 'auror';
echo Html::scss('css/palettes/' . $theme);
echo "<link rel='shortcut icon' type='images/x-icon' href='".
$CFG_GLPI["root_doc"]."/pics/favicon.ico' >\n";
......@@ -4936,6 +4941,9 @@ class Html {
$file = $url;
$url = self::getPrefixedUrl('/front/css.php');
$url .= '?file=' . $file;
if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) {
$url .= '&debug';
}
}
return self::csslink($url, $options);
......@@ -6678,12 +6686,10 @@ class Html {
$appCache = Toolbox::getAppCache();
$ckey = isset($args['v']) ? $args['v'] : GLPI_SCHEMA_VERSION;
$is_debug = $_SESSION['glpi_use_mode'] == Session::DEBUG_MODE;
$files = [];
$scss = new Compiler();
$scss->setFormatter('Leafo\ScssPhp\Formatter\Crunched');
if ($is_debug || isset($args['debug'])) {
if (isset($args['debug'])) {
$ckey .= '_sourcemap';
$scss->setSourceMap(Compiler::SOURCE_MAP_INLINE);
$scss->setSourceMapOptions(
......@@ -6694,77 +6700,65 @@ class Html {
);
}
if (!isset($args['file']) || $args['file'] == 'main_styles') {
$file = isset($args['file']) ? $args['file'] : 'css/styles';
$files[] = 'css/glpi';
} else if ($args['file'] == 'glpi-legacy') {
$ckey .= '_legacy';
$files[] = 'css/legacy';
if (isset($_SESSION['glpihighcontrast_css'])
&& $_SESSION['glpihighcontrast_css']) {
$ckey .= '_highcontrast';
$files[] = 'css/highcontrast';
}
// CSS theme
$theme = 'auror';
if (isset($_SESSION["glpipalette"])) {
$theme = $_SESSION['glpipalette'];
}
$ckey .= '_' . $theme;
$files[] = 'css/palettes/' . $theme;
} else {
if (!Toolbox::startsWith($args['file'], 'css/')) {
$args['file'] = '/css/' . $args['file'];
}
$ckey .= '_' . md5($args['file']);
$filename = realpath(GLPI_ROOT . $args['file'] . '.scss');
if (!Toolbox::startsWith($filename, realpath(GLPI_ROOT))) {
// Prevent import of a file from ouside GLPI dir
$ckey .= '_' . $file;
$ckey = 'css_' . md5($ckey);
// or not ending with .scss
return '';
}
$files[] = $args['file'];
if (!Toolbox::endsWith($file, '.scss')) {
// Prevent include of file if ext is not .scss
$file .= '.scss';
}
$ckey = md5($ckey);
$import = '';
// Requested file path
$path = GLPI_ROOT . '/' . $file;
foreach ($files as $file) {
$path = GLPI_ROOT . "/$file";
if (!Toolbox::endsWith($file, '.scss')) {
$path .= ".scss";
}
$pathargs = explode('/', $file);
$pathargs[] = '_' . array_pop($pathargs);
$pathalt = GLPI_ROOT . '/' . implode('/', $pathargs) . '.scss';
if (file_exists($path) || file_exists($pathalt)) {
if (!file_exists($path)) {
$path = $pathalt;
}
$import .= '@import "' . $file . '";';
$fckey = md5($file);
$hashfile = self::getScssFileHash($path);
// Alternate file path (prefixed by a "_", i.e. "_highcontrast.scss").
$pathargs = explode('/', $file);
$pathargs[] = '_' . array_pop($pathargs);
$pathalt = GLPI_ROOT . '/' . implode('/', $pathargs);
if (!file_exists($path) && !file_exists($pathalt)) {
Toolbox::logWarning('Requested file ' . $path . ' does not exists.');
return '';
}
if (!file_exists($path)) {
$path = $pathalt;
}
// Prevent import of a file from ouside GLPI dir
$path = realpath($path);
if (!Toolbox::startsWith($path, realpath(GLPI_ROOT))) {
Toolbox::logWarning('Requested file ' . $path . ' is outside GLPI file tree.');
return '';
}
$import = '@import "' . $file . '";';
$fckey = md5($file);
$md5file = md5(file_get_contents($path));
//check if files has changed
//check if files has changed
if ($appCache->has($fckey)) {
$hash = $appCache->get($fckey);
if ($hashfile != $hash) {
//file has changed
Toolbox::logDebug("$file has changed, reloading");
$args['reload'] = true;
if ($md5file != $md5) {
//file has changed
Toolbox::logDebug("$file has changed, reloading");
$args['reload'] = true;
$appCache->set($fckey, $hashfile);
}
} else {
Toolbox::logDebug("$file is new, loading");
$appCache->set($fckey, $hashfile);
}
} else {
Toolbox::logWarning('Requested file ' . $path . ' does not exists.');
}
} else {
Toolbox::logDebug("$file is new, loading");
$appCache->set($fckey, $md5file);
}
$scss->addImportPath(GLPI_ROOT);
......
......@@ -87,6 +87,11 @@ if (!file_exists(GLPI_CONFIG_DIR . "/db.yaml")) {
// Appel CSS
echo Html::scss('glpi-legacy');
if (isset($_SESSION['glpihighcontrast_css']) && $_SESSION['glpihighcontrast_css']) {
echo Html::scss('css/highcontrast');
}
$theme = isset($_SESSION['glpipalette']) ? $_SESSION['glpipalette'] : 'auror';
echo Html::scss('css/palettes/' . $theme);
// font awesome icons
echo Html::css('public/lib/fontawesome-free/css/all.css');
......
......@@ -82,7 +82,7 @@ class CompileScssCommand extends Command {
$files = $input->getOption('file');
if (empty($files)) {
$files[] = 'main_styles'; // Compile main styles if no file option is set.
$files[] = 'css/styles'; // Compile main styles if no file option is set.
$files[] = 'glpi-legacy'; // Compile legacy styles if no file option is set.
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment