butterfly/hook.php
Claude 020558f14f Novo recurso: controle da logo do login (custom/original/ocultar) + caixa de CSS grande
- Dropdown 'Logo' na seção Login Page: custom (imagem enviada ou logo do
  tema — comportamento legado, default), original (força logo GLPI) e
  hide (oculta via CSS injetado no display_login).
- Campos de CSS custom agora são textarea de 14 linhas sempre visível
  (monospace, 100%); o Monaco só assume se window.GLPI.Monaco existir
  (melhoria progressiva — antes o fallback dependia de JS e o campo
  podia ficar escondido/curto).
- Traduções pt_BR novas + pt_BR.mo recompilado (msgfmt indisponível;
  compilado com script Python puro).

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

152 lines
5.7 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);
}
// Logo do login: custom (imagem enviada ou do tema) / original / hide
$logoDisplay = \GlpiPlugin\Butterfly\Config::getConfig('login_logo_display', 'custom');
$loginPicture = null;
if ($logoDisplay === 'custom') {
$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 ($logoDisplay === 'hide') : ?>
<style>
.page-anonymous .glpi-logo,
.login-header img, .glpi-login__logo img, .login-logo img {
display: none !important;
}
</style>
<?php endif; ?>
<?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;
}