- 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>
138 lines
5.2 KiB
PHP
138 lines
5.2 KiB
PHP
<?php
|
|
|
|
function plugin_butterfly_display_login() {
|
|
|
|
// Mesma sanitização do picture.send.php — tema é sempre um nome simples de diretório
|
|
$requestedTheme = null;
|
|
if (isset($_GET['theme'])) {
|
|
$requestedTheme = preg_replace('/[^a-zA-Z0-9_\-]/', '', (string)$_GET['theme']);
|
|
}
|
|
|
|
$themeInfo = null;
|
|
if ($requestedTheme) {
|
|
$themeInfo = \GlpiPlugin\Butterfly\Theme::getThemeInfo($requestedTheme);
|
|
}
|
|
if (!$themeInfo) {
|
|
$theme = \GlpiPlugin\Butterfly\Config::getConfig("login_theme", '');
|
|
$themeInfo = \GlpiPlugin\Butterfly\Theme::getThemeInfo($theme);
|
|
}
|
|
|
|
$loginPicture = \GlpiPlugin\Butterfly\Config::getConfig('login_picture');
|
|
|
|
if (!$loginPicture && $themeInfo && !empty($themeInfo['login-logo'])) {
|
|
$loginPicture = $themeInfo['login-logo'] . '&theme=' . $themeInfo['id'];
|
|
}
|
|
|
|
$loginCss = \GlpiPlugin\Butterfly\Scss::getLoginCSS($requestedTheme);
|
|
if (!empty($loginCss)) {
|
|
echo "<style id='plugin-butterfly-login-css'>\n" . $loginCss . "\n</style>";
|
|
}
|
|
|
|
?>
|
|
<?php if ($loginPicture) : ?>
|
|
<?php
|
|
$pictureUrl = \GlpiPlugin\Butterfly\Toolbox::getPictureUrl($loginPicture);
|
|
$maxWidth = Html::cleanInputText(\GlpiPlugin\Butterfly\Config::getConfig('login_picture_max_width', '145px'));
|
|
$maxHeight = Html::cleanInputText(\GlpiPlugin\Butterfly\Config::getConfig('login_picture_max_height', '80px'));
|
|
?>
|
|
<style>
|
|
.page-anonymous .glpi-logo {
|
|
--logo: url(<?php echo $pictureUrl ?>);
|
|
content: url(<?php echo $pictureUrl ?>);
|
|
width: auto;
|
|
height: auto;
|
|
max-width: <?php echo $maxWidth ?>;
|
|
max-height: <?php echo $maxHeight ?>;
|
|
}
|
|
</style>
|
|
<?php endif; ?>
|
|
<script type="text/javascript">
|
|
$(function() {
|
|
var $loginInputs = $('#login_name, #inputUsername');
|
|
if ($loginInputs.length) {
|
|
$loginInputs.attr('placeholder', <?php echo json_encode(__('Login'), JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP) ?>);
|
|
}
|
|
|
|
var $passwordInputs = $('input[type=password], input[name=password]');
|
|
if ($passwordInputs.length) {
|
|
$passwordInputs.attr('placeholder', <?php echo json_encode(__('Password'), JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP) ?>);
|
|
$passwordInputs.each(function() {
|
|
var $input = $(this);
|
|
var $description = $input.siblings('.form-label-description').first();
|
|
if ($description.length) {
|
|
$input.after($description);
|
|
}
|
|
});
|
|
}
|
|
<?php
|
|
$favicon = \GlpiPlugin\Butterfly\Config::getConfig('favicon_picture');
|
|
if ($favicon) :
|
|
$faviconUrl = \GlpiPlugin\Butterfly\Toolbox::getPictureUrl($favicon);
|
|
?>
|
|
var $icon = $('link[rel*=icon]');
|
|
$icon.attr('type', null);
|
|
$icon.attr('href', <?php echo json_encode($faviconUrl, JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP) ?>);
|
|
<?php
|
|
endif;
|
|
$pageTitle = \GlpiPlugin\Butterfly\Config::getConfig('page_title');
|
|
if ($pageTitle) :
|
|
?>
|
|
var $title = $('title');
|
|
var newTitle = $title.text().replace('GLPI', <?php echo json_encode($pageTitle, JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP) ?>);
|
|
$title.text(newTitle);
|
|
<?php
|
|
endif;
|
|
$footerDisplay = \GlpiPlugin\Butterfly\Config::getConfig('page_footer_display', 'original');
|
|
$footerText = \GlpiPlugin\Butterfly\Config::getConfig('page_footer_text', '');
|
|
if ($footerDisplay === 'hide') :
|
|
?>
|
|
$('#footer-login, .login-footer').hide();
|
|
<?php
|
|
endif;
|
|
if ($footerDisplay === 'custom') :
|
|
$footerText = \Glpi\RichText\RichText::getEnhancedHtml($footerText);
|
|
?>
|
|
var $footerTarget = $('#footer-login, .login-footer').first();
|
|
if ($footerTarget.length) {
|
|
$footerTarget.html(<?php echo json_encode($footerText, JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP) ?>);
|
|
} else {
|
|
$('a.copyright').parent().html(<?php echo json_encode($footerText, JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP) ?>);
|
|
}
|
|
<?php
|
|
endif;
|
|
if ($loginPicture) :
|
|
?>
|
|
var pictureUrl = <?php echo json_encode($pictureUrl, JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP); ?>;
|
|
var maxWidth = <?php echo json_encode($maxWidth, JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP); ?>;
|
|
var maxHeight = <?php echo json_encode($maxHeight, JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP); ?>;
|
|
|
|
$('.page-anonymous .glpi-logo').css({
|
|
'background-image': 'url(' + pictureUrl + ')',
|
|
'background-position': 'center',
|
|
'background-repeat': 'no-repeat',
|
|
'background-size': 'contain'
|
|
});
|
|
|
|
$('.login-header img, .glpi-login__logo img, .login-logo img')
|
|
.attr('src', pictureUrl)
|
|
.css({
|
|
'width': 'auto',
|
|
'height': 'auto',
|
|
'max-width': maxWidth,
|
|
'max-height': maxHeight
|
|
});
|
|
<?php
|
|
endif;
|
|
?>
|
|
});
|
|
</script>
|
|
<?php
|
|
}
|
|
|
|
function plugin_butterfly_install() {
|
|
return true;
|
|
}
|
|
|
|
function plugin_butterfly_uninstall() {
|
|
return true;
|
|
}
|