- Classes migradas de inc/*.class.php (PluginButterfly*) para src/ com namespace GlpiPlugin\Butterfly (PSR-4 registrado pelo core; KB-033). Referências de core qualificadas (\Config, \Html, \Session, ...). - Editor de CSS custom agora usa o Monaco do core (GLPI.Monaco.createEditor + sync via formdata, mesmo padrão de custom_ui do core) com fallback para textarea se a lib não carregar. - pics/ movido para public/pics: no GLPI 11 só recursos em public/ são servidos estaticamente em /plugins/<key>/... (RequestRouterTrait). URLs do select2 de temas agora usam root_doc + encodeURIComponent. - MIN_GLPI_VERSION 11.0.0; removido bloco morto de GLPI <9.5 e css/login.base.css órfão. - config_page com glpi_tab urlencoded para a classe namespaced. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
81 lines
2.9 KiB
PHP
81 lines
2.9 KiB
PHP
<?php
|
|
|
|
// GLPI 11: o core já foi bootado pelo LegacyFileLoadController antes deste
|
|
// arquivo executar — não incluir inc/includes.php (KB-PLUGIN-028)
|
|
|
|
// FIX: Prevent this script from being stored as the "Return URL" after login
|
|
if (isset($_SESSION['glpi_currentpage']) && strpos($_SESSION['glpi_currentpage'], basename(__FILE__)) !== false) {
|
|
unset($_SESSION['glpi_currentpage']);
|
|
}
|
|
|
|
// Redirect if is a not cached URL
|
|
if (!isset($_GET['_'])) {
|
|
$timestamp = \GlpiPlugin\Butterfly\Toolbox::getTimestamp();
|
|
|
|
// Disable cache and redirect to cached URL
|
|
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
|
|
header("Cache-Control: post-check=0, pre-check=0", false);
|
|
header("Pragma: no-cache");
|
|
|
|
$file = basename(__FILE__);
|
|
$url = "$file?_=$timestamp";
|
|
if (isset($_GET['v'])) {
|
|
$url .= '&v=' . $_GET['v'];
|
|
}
|
|
header("Location: " . $url);
|
|
die;
|
|
}
|
|
|
|
$name = 'internal';
|
|
$css = "";
|
|
|
|
$picture = \GlpiPlugin\Butterfly\Config::getConfig("{$name}_picture", '');
|
|
if ($picture) {
|
|
$css .= ".page .glpi-logo {";
|
|
$css .= " width: " . \GlpiPlugin\Butterfly\Config::getConfig("{$name}_picture_width", '100px') . " !important;";
|
|
$css .= " height: " . \GlpiPlugin\Butterfly\Config::getConfig("{$name}_picture_height", '55px') . " !important;";
|
|
$css .= " background-size: contain !important;";
|
|
$css .= " background-repeat: no-repeat !important;";
|
|
$css .= " background-position: center !important;";
|
|
$css .= " background-image: url(\"" . \GlpiPlugin\Butterfly\Toolbox::getPictureUrl($picture) . "\") !important;";
|
|
$css .= "}";
|
|
}
|
|
|
|
$css_type = \GlpiPlugin\Butterfly\Config::getConfig("{$name}_css_type", 'scss');
|
|
$css_custom = \GlpiPlugin\Butterfly\Config::getConfig("{$name}_css_custom", '');
|
|
|
|
$css_custom = html_entity_decode($css_custom);
|
|
|
|
if ($css_type === 'scss' && $css_custom && \GlpiPlugin\Butterfly\Scss::hasScssSuport()) {
|
|
try {
|
|
$variables = [];
|
|
$variables['butterfly_timestamp'] = \GlpiPlugin\Butterfly\Toolbox::getTimestamp();
|
|
|
|
$css .= \GlpiPlugin\Butterfly\Scss::compileScss($css_custom, $variables);
|
|
} catch (\Throwable $th) {
|
|
// Log error safely - check if ErrorHandler class exists
|
|
$errorHandlerClass = '\Glpi\Application\ErrorHandler';
|
|
if (class_exists($errorHandlerClass)) {
|
|
$errorHandlerClass::getInstance()->handleException($th);
|
|
} else {
|
|
// Fallback error logging
|
|
error_log('Butterfly Plugin SCSS Error: ' . $th->getMessage());
|
|
}
|
|
}
|
|
} else if ($css_type === 'css') {
|
|
$css .= $css_custom;
|
|
}
|
|
|
|
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;
|