2014-03-04 16:15:08 +01:00
|
|
|
<?php
|
2015-02-04 10:46:36 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2014-03-04 16:15:08 +01:00
|
|
|
|
|
|
|
namespace Icinga\Web;
|
|
|
|
|
|
|
|
use Icinga\Application\Icinga;
|
2014-09-02 16:24:55 +02:00
|
|
|
use Icinga\Web\FileCache;
|
2014-03-04 16:15:08 +01:00
|
|
|
use Icinga\Web\LessCompiler;
|
|
|
|
|
|
|
|
class StyleSheet
|
|
|
|
{
|
|
|
|
protected static $lessFiles = array(
|
2015-01-29 11:25:37 +01:00
|
|
|
'../application/fonts/fontello-ifont/css/ifont-embedded.css',
|
2014-11-19 10:31:51 +01:00
|
|
|
'css/vendor/tipsy.css',
|
2014-03-04 16:15:08 +01:00
|
|
|
'css/icinga/defaults.less',
|
2015-02-25 13:51:26 +01:00
|
|
|
'css/icinga/animation.less',
|
2014-03-04 16:15:08 +01:00
|
|
|
'css/icinga/layout-colors.less',
|
|
|
|
'css/icinga/layout-structure.less',
|
|
|
|
'css/icinga/menu.less',
|
|
|
|
'css/icinga/header-elements.less',
|
2015-05-29 14:17:12 +02:00
|
|
|
'css/icinga/footer-elements.less',
|
2014-03-04 16:15:08 +01:00
|
|
|
'css/icinga/main-content.less',
|
|
|
|
'css/icinga/tabs.less',
|
|
|
|
'css/icinga/forms.less',
|
2014-10-06 16:04:58 +02:00
|
|
|
'css/icinga/setup.less',
|
2014-03-05 20:12:45 +01:00
|
|
|
'css/icinga/widgets.less',
|
2014-03-04 16:15:08 +01:00
|
|
|
'css/icinga/pagination.less',
|
2014-04-09 19:13:46 +02:00
|
|
|
'css/icinga/selection-toolbar.less',
|
2015-04-15 14:20:36 +02:00
|
|
|
'css/icinga/login.less',
|
|
|
|
'css/icinga/controls.less'
|
2014-03-04 16:15:08 +01:00
|
|
|
);
|
|
|
|
|
2014-03-06 10:21:32 +01:00
|
|
|
public static function compileForPdf()
|
|
|
|
{
|
2014-11-13 16:35:26 +01:00
|
|
|
self::checkPhp();
|
2014-03-06 10:21:32 +01:00
|
|
|
$less = new LessCompiler();
|
2014-11-12 17:14:09 +01:00
|
|
|
$basedir = Icinga::app()->getBootstrapDirectory();
|
2014-03-06 10:21:32 +01:00
|
|
|
foreach (self::$lessFiles as $file) {
|
2014-03-31 18:30:27 +02:00
|
|
|
$less->addFile($basedir . '/' . $file);
|
2014-03-06 10:21:32 +01:00
|
|
|
}
|
|
|
|
$less->addLoadedModules();
|
|
|
|
$less->addFile($basedir . '/css/pdf/pdfprint.less');
|
|
|
|
return $less->compile();
|
|
|
|
}
|
|
|
|
|
2014-03-27 08:32:02 +01:00
|
|
|
public static function sendMinified()
|
|
|
|
{
|
|
|
|
self::send(true);
|
|
|
|
}
|
|
|
|
|
2014-09-05 10:55:25 +02:00
|
|
|
protected static function fixModuleLayoutCss($css)
|
|
|
|
{
|
|
|
|
return preg_replace(
|
|
|
|
'/(\.icinga-module\.module-[^\s]+) (#layout\.[^\s]+)/m',
|
|
|
|
'\2 \1',
|
|
|
|
$css
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-11-13 16:35:26 +01:00
|
|
|
protected static function checkPhp()
|
|
|
|
{
|
|
|
|
// PHP had a rather conservative PCRE backtrack limit unless 5.3.7
|
|
|
|
if (version_compare(PHP_VERSION, '5.3.7') <= 0) {
|
|
|
|
ini_set('pcre.backtrack_limit', 1000000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-27 08:32:02 +01:00
|
|
|
public static function send($minified = false)
|
2014-03-04 16:15:08 +01:00
|
|
|
{
|
2014-11-13 16:35:26 +01:00
|
|
|
self::checkPhp();
|
2014-09-02 16:24:55 +02:00
|
|
|
$app = Icinga::app();
|
2014-11-12 17:14:09 +01:00
|
|
|
$basedir = $app->getBootstrapDirectory();
|
2014-09-02 16:24:55 +02:00
|
|
|
foreach (self::$lessFiles as $file) {
|
|
|
|
$lessFiles[] = $basedir . '/' . $file;
|
|
|
|
}
|
|
|
|
$files = $lessFiles;
|
|
|
|
foreach ($app->getModuleManager()->getLoadedModules() as $name => $module) {
|
|
|
|
if ($module->hasCss()) {
|
|
|
|
$files[] = $module->getCssFilename();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($etag = FileCache::etagMatchesFiles($files)) {
|
|
|
|
header("HTTP/1.1 304 Not Modified");
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
$etag = FileCache::etagForFiles($files);
|
|
|
|
}
|
|
|
|
header('Cache-Control: public');
|
|
|
|
header('ETag: "' . $etag . '"');
|
2014-03-04 16:15:08 +01:00
|
|
|
header('Content-Type: text/css');
|
2014-03-27 08:32:02 +01:00
|
|
|
|
|
|
|
$min = $minified ? '.min' : '';
|
2014-09-02 16:24:55 +02:00
|
|
|
$cacheFile = 'icinga-' . $etag . $min . '.css';
|
|
|
|
$cache = FileCache::instance();
|
|
|
|
if ($cache->has($cacheFile)) {
|
|
|
|
$cache->send($cacheFile);
|
|
|
|
return;
|
2014-03-27 08:32:02 +01:00
|
|
|
}
|
2015-01-28 17:03:23 +01:00
|
|
|
|
2015-01-29 11:25:37 +01:00
|
|
|
$less = new LessCompiler();
|
2015-07-22 12:45:10 +02:00
|
|
|
$less->disableExtendedImport();
|
2014-09-02 16:24:55 +02:00
|
|
|
foreach ($lessFiles as $file) {
|
|
|
|
$less->addFile($file);
|
2014-03-04 16:15:08 +01:00
|
|
|
}
|
2014-03-27 08:32:02 +01:00
|
|
|
$less->addLoadedModules();
|
|
|
|
if ($minified) {
|
|
|
|
$less->compress();
|
|
|
|
}
|
2014-09-05 10:55:25 +02:00
|
|
|
$out = self::fixModuleLayoutCss($less->compile());
|
2014-09-02 16:24:55 +02:00
|
|
|
$cache->store($cacheFile, $out);
|
2014-03-27 08:32:02 +01:00
|
|
|
echo $out;
|
2014-03-04 16:15:08 +01:00
|
|
|
}
|
|
|
|
}
|