butterfly/front/internal.css.php
Claude 18879bff6d Conformidade KB: sem inc/includes.php, logo.png, limpeza e JSON_HEX_TAG
- front/*.php não incluem mais ../../../inc/includes.php: no GLPI 11 o
  LegacyFileLoadController boota o core antes do script, e o include
  quebra quando o plugin roda do marketplace dir (KB-PLUGIN-028/010).
- logo.png (512x512) criado a partir de plugin.png: o LogoController só
  reconhece o nome fixo logo.png (KB-INFRA-002).
- Removidos front/test_simple.php e front/login.css.php (deprecated),
  incluindo a firewall strategy correspondente no setup.php (KB-018).
- json_encode com JSON_HEX_TAG|JSON_HEX_AMP em todo dado dinâmico
  embutido em <script> (KB-PLUGIN-003).
- .gitignore padrão KB-018; .DS_Store removidos.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 16:25:56 -03:00

81 lines
2.8 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 = PluginButterflyToolbox::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 = PluginButterflyConfig::getConfig("{$name}_picture", '');
if ($picture) {
$css .= ".page .glpi-logo {";
$css .= " width: " . PluginButterflyConfig::getConfig("{$name}_picture_width", '100px') . " !important;";
$css .= " height: " . PluginButterflyConfig::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(\"" . PluginButterflyToolbox::getPictureUrl($picture) . "\") !important;";
$css .= "}";
}
$css_type = PluginButterflyConfig::getConfig("{$name}_css_type", 'scss');
$css_custom = PluginButterflyConfig::getConfig("{$name}_css_custom", '');
$css_custom = html_entity_decode($css_custom);
if ($css_type === 'scss' && $css_custom && PluginButterflyScss::hasScssSuport()) {
try {
$variables = [];
$variables['butterfly_timestamp'] = PluginButterflyToolbox::getTimestamp();
$css .= PluginButterflyScss::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;