From 39f3f3f2a218e43be60818e1908390e04a01b635 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 3 Jul 2026 18:04:13 -0300 Subject: [PATCH] =?UTF-8?q?Moderniza=C3=A7=C3=A3o=20GLPI=2011:=20namespace?= =?UTF-8?q?=20GlpiPlugin\Butterfly,=20Monaco,=20assets=20em=20public/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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//... (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 --- css/login.base.css | 11 -- front/internal.css.php | 20 ++-- front/internal.js.php | 12 +-- front/picture.send.php | 4 +- hook.php | 32 +++--- {pics => public/pics}/login.preview.png | Bin setup.php | 9 +- inc/config.class.php => src/Config.php | 131 ++++++++++++++--------- inc/scss.class.php => src/Scss.php | 32 +++--- inc/theme.class.php => src/Theme.php | 4 +- inc/toolbox.class.php => src/Toolbox.php | 16 +-- 11 files changed, 146 insertions(+), 125 deletions(-) delete mode 100644 css/login.base.css rename {pics => public/pics}/login.preview.png (100%) rename inc/config.class.php => src/Config.php (78%) rename inc/scss.class.php => src/Scss.php (84%) rename inc/theme.class.php => src/Theme.php (97%) rename inc/toolbox.class.php => src/Toolbox.php (94%) diff --git a/css/login.base.css b/css/login.base.css deleted file mode 100644 index 6f86054..0000000 --- a/css/login.base.css +++ /dev/null @@ -1,11 +0,0 @@ -#logo_login { - background: none; - margin: 0; - padding: 38px 0; - text-align: center; -} - -#logo_login img { - display: block; - margin: 0 auto; -} diff --git a/front/internal.css.php b/front/internal.css.php index e7c7224..9853530 100644 --- a/front/internal.css.php +++ b/front/internal.css.php @@ -10,7 +10,7 @@ if (isset($_SESSION['glpi_currentpage']) && strpos($_SESSION['glpi_currentpage'] // Redirect if is a not cached URL if (!isset($_GET['_'])) { - $timestamp = PluginButterflyToolbox::getTimestamp(); + $timestamp = \GlpiPlugin\Butterfly\Toolbox::getTimestamp(); // Disable cache and redirect to cached URL header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); @@ -29,29 +29,29 @@ if (!isset($_GET['_'])) { $name = 'internal'; $css = ""; -$picture = PluginButterflyConfig::getConfig("{$name}_picture", ''); +$picture = \GlpiPlugin\Butterfly\Config::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 .= " 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(\"" . PluginButterflyToolbox::getPictureUrl($picture) . "\") !important;"; + $css .= " background-image: url(\"" . \GlpiPlugin\Butterfly\Toolbox::getPictureUrl($picture) . "\") !important;"; $css .= "}"; } -$css_type = PluginButterflyConfig::getConfig("{$name}_css_type", 'scss'); -$css_custom = PluginButterflyConfig::getConfig("{$name}_css_custom", ''); +$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 && PluginButterflyScss::hasScssSuport()) { +if ($css_type === 'scss' && $css_custom && \GlpiPlugin\Butterfly\Scss::hasScssSuport()) { try { $variables = []; - $variables['butterfly_timestamp'] = PluginButterflyToolbox::getTimestamp(); + $variables['butterfly_timestamp'] = \GlpiPlugin\Butterfly\Toolbox::getTimestamp(); - $css .= PluginButterflyScss::compileScss($css_custom, $variables); + $css .= \GlpiPlugin\Butterfly\Scss::compileScss($css_custom, $variables); } catch (\Throwable $th) { // Log error safely - check if ErrorHandler class exists $errorHandlerClass = '\Glpi\Application\ErrorHandler'; diff --git a/front/internal.js.php b/front/internal.js.php index 8874598..9c37b81 100644 --- a/front/internal.js.php +++ b/front/internal.js.php @@ -10,7 +10,7 @@ if (isset($_SESSION['glpi_currentpage']) && strpos($_SESSION['glpi_currentpage'] // Redirect if is a not cached URL if (!isset($_GET['_'])) { - $timestamp = PluginButterflyToolbox::getTimestamp(); + $timestamp = \GlpiPlugin\Butterfly\Toolbox::getTimestamp(); // Disable cache and redirect to cached URL header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); @@ -47,16 +47,16 @@ if (false) { $('link[href*="butterfly/front/internal.css.php"]').appendTo($('head')) var $icon = $('link[rel*=icon]'); $icon.attr('type', null); $icon.attr('href', ); var $title = $('title'); @@ -65,8 +65,8 @@ if (false) { $('a[id^=show_about_modal_]').hide(); diff --git a/front/picture.send.php b/front/picture.send.php index 51a8cdb..5615148 100644 --- a/front/picture.send.php +++ b/front/picture.send.php @@ -26,9 +26,9 @@ if ($path === '') { } if ($theme !== '') { - $baseDir = PluginButterflyTheme::getThemeFolder() . '/' . $theme; + $baseDir = \GlpiPlugin\Butterfly\Theme::getThemeFolder() . '/' . $theme; } else { - $baseDir = PluginButterflyToolbox::getStorageBasePath(); + $baseDir = \GlpiPlugin\Butterfly\Toolbox::getStorageBasePath(); } $fullPath = $baseDir . '/' . ltrim($path, '/'); diff --git a/hook.php b/hook.php index bf0351b..230d1bf 100644 --- a/hook.php +++ b/hook.php @@ -10,26 +10,20 @@ function plugin_butterfly_display_login() { $themeInfo = null; if ($requestedTheme) { - $themeInfo = PluginButterflyTheme::getThemeInfo($requestedTheme); + $themeInfo = \GlpiPlugin\Butterfly\Theme::getThemeInfo($requestedTheme); } if (!$themeInfo) { - $theme = PluginButterflyConfig::getConfig("login_theme", ''); - $themeInfo = PluginButterflyTheme::getThemeInfo($theme); + $theme = \GlpiPlugin\Butterfly\Config::getConfig("login_theme", ''); + $themeInfo = \GlpiPlugin\Butterfly\Theme::getThemeInfo($theme); } - $loginPicture = PluginButterflyConfig::getConfig('login_picture'); + $loginPicture = \GlpiPlugin\Butterfly\Config::getConfig('login_picture'); if (!$loginPicture && $themeInfo && !empty($themeInfo['login-logo'])) { $loginPicture = $themeInfo['login-logo'] . '&theme=' . $themeInfo['id']; } - if ($loginPicture && version_compare(GLPI_VERSION, '9.5.0', '<')) { - echo Html::css("/plugins/butterfly/css/login.base.css", [ - 'version' => PLUGIN_BUTTERFLY_VERSION, - ]); - } - - $loginCss = PluginButterflyScss::getLoginCSS($requestedTheme); + $loginCss = \GlpiPlugin\Butterfly\Scss::getLoginCSS($requestedTheme); if (!empty($loginCss)) { echo ""; } @@ -37,9 +31,9 @@ function plugin_butterfly_display_login() { ?>