N°2259 - iTop Compilation of branding images ignore real format of source image

This commit is contained in:
acognet
2021-09-17 16:36:40 +02:00
parent a1d6a705ca
commit 61f6c1fe33
8 changed files with 45 additions and 45 deletions

View File

@@ -7,6 +7,7 @@
*/
use Combodo\iTop\Application\Branding;
use Combodo\iTop\TwigExtension;
/**
@@ -238,16 +239,9 @@ class LoginTwigRenderer
public function GetDefaultVars()
{
$sLogo = 'itop-logo-external.png';
$sBrandingLogo = 'login-logo.png';
$sVersionShort = Dict::Format('UI:iTopVersion:Short', ITOP_APPLICATION, ITOP_VERSION);
$sIconUrl = Utils::GetConfig()->Get('app_icon_url');
$sDisplayIcon = utils::GetAbsoluteUrlAppRoot().'images/'.$sLogo.'?t='.utils::GetCacheBusterTimestamp();
if (file_exists(MODULESROOT.'branding/'.$sBrandingLogo))
{
$sDisplayIcon = utils::GetAbsoluteUrlModulesRoot().'branding/'.$sBrandingLogo.'?t='.utils::GetCacheBusterTimestamp();
}
$sDisplayIcon = Branding::GetLoginLogoAbsoluteUrl();
$aVars = array(
'sAppRootUrl' => utils::GetAbsoluteUrlAppRoot(),

View File

@@ -24,6 +24,7 @@
* @license http://opensource.org/licenses/AGPL-3.0
*/
use Combodo\iTop\Application\Branding;
use Combodo\iTop\Application\Helper\Session;
/**
@@ -141,16 +142,9 @@ class LoginWebPage extends NiceWebPage
public function DisplayLoginHeader($bMainAppLogo = false)
{
$sLogo = 'itop-logo-external.png';
$sBrandingLogo = 'login-logo.png';
$sVersionShort = Dict::Format('UI:iTopVersion:Short', ITOP_APPLICATION, ITOP_VERSION);
$sIconUrl = Utils::GetConfig()->Get('app_icon_url');
$sDisplayIcon = utils::GetAbsoluteUrlAppRoot().'images/'.$sLogo.'?t='.utils::GetCacheBusterTimestamp();
if (file_exists(MODULESROOT.'branding/'.$sBrandingLogo))
{
$sDisplayIcon = utils::GetAbsoluteUrlModulesRoot().'branding/'.$sBrandingLogo.'?t='.utils::GetCacheBusterTimestamp();
}
$sDisplayIcon = Branding::GetLoginLogoAbsoluteUrl();
$this->add("<div id=\"login-logo\"><a href=\"".htmlentities($sIconUrl, ENT_QUOTES,
self::PAGES_CHARSET)."\"><img title=\"$sVersionShort\" src=\"$sDisplayIcon\"></a></div>\n");
}

View File

@@ -86,6 +86,7 @@ a:hover {
#login-logo img {
border: 0;
max-height: 54px;
}
#login-form {

View File

@@ -2851,15 +2851,19 @@ EOF;
if (($sIcon = $oBrandingNode->GetChildText($sNodeName)) && (strlen($sIcon) > 0))
{
$sSourceFile = $sTempTargetDir.'/'.$sIcon;
$sTargetFile = $sTempTargetDir.'/branding/'.$sTargetFile.'.png';
$aIconName=explode(".", $sIcon);
$sIconExtension=$aIconName[count($aIconName)-1];
$sTargetFile = '/branding/'.$sTargetFile.'.'.$sIconExtension;
if (!file_exists($sSourceFile))
{
throw new Exception("Branding $sNodeName: could not find the file $sIcon ($sSourceFile)");
}
copy($sSourceFile, $sTargetFile);
copy($sSourceFile, $sTempTargetDir.$sTargetFile);
return $sTargetFile;
}
return null;
}
/**
@@ -3098,11 +3102,25 @@ EOF;
{
// Transform file refs into files in the images folder
$this->CompileFiles($oBrandingNode, $sTempTargetDir.'/branding', $sFinalTargetDir.'/branding', 'branding');
$aDataBranding = [];
$this->CompileLogo($oBrandingNode, $sTempTargetDir, $sFinalTargetDir, 'login_logo', 'login-logo');
$this->CompileLogo($oBrandingNode, $sTempTargetDir, $sFinalTargetDir, 'main_logo', 'main-logo-full');
$this->CompileLogo($oBrandingNode, $sTempTargetDir, $sFinalTargetDir, 'main_logo_compact', 'main-logo-compact');
$this->CompileLogo($oBrandingNode, $sTempTargetDir, $sFinalTargetDir, 'portal_logo', 'portal-logo');
$aLogosToCompile=[['sNodeName'=>'login_logo', 'sTargetFile'=> 'login-logo', 'sType'=>'login_logo'],
['sNodeName'=>'main_logo', 'sTargetFile'=> 'main-logo-full', 'sType'=>'main-logo-full'],
['sNodeName'=>'main_logo_compact', 'sTargetFile'=> 'main_logo_compact', 'sType'=>'main_logo_compact'],
['sNodeName'=>'login_logo', 'sTargetFile'=>'portal_logo', 'sType'=>'portal_logo']];
foreach ($aLogosToCompile as $aLogo) {
$sLogo = $this->CompileLogo($oBrandingNode, $sTempTargetDir, $sFinalTargetDir, $aLogo['sNodeName'], $aLogo['sTargetFile']);
if ($sLogo != null) {
$aDataBranding['sType'] = $sLogo;
}
}
if ($sTempTargetDir == null) {
$sWorkingPath = APPROOT.'env-'.utils::GetCurrentEnvironment().'/';
} else {
$sWorkingPath = $sTempTargetDir;
}
file_put_contents($sWorkingPath.'/branding/logos.json', json_encode($aDataBranding));
// Cleanup the images directory (eventually made by CompileFiles)
if (file_exists($sTempTargetDir.'/branding/images'))

View File

@@ -73,25 +73,22 @@ class Branding
public static function GetLogoAbsoluteUrl($sType = self::DEFAULT_LOGO_TYPE)
{
$sDefaultLogoPath = static::$aLogoPaths[$sType]['default'];
$sCustomLogoPath = static::$aLogoPaths[$sType]['custom'];
if (file_exists(MODULESROOT.$sCustomLogoPath))
{
$sUrl = utils::GetAbsoluteUrlModulesRoot().$sCustomLogoPath;
$sWorkingPath = APPROOT.'env-'.utils::GetCurrentEnvironment();
$aThemeParameters = json_decode(@file_get_contents($sWorkingPath.'/branding/logos.json'), true);
if ( isset( $aThemeParameters[$sType])) {
$sCustomLogoPath = $aThemeParameters[$sType];
if (file_exists(MODULESROOT.$sCustomLogoPath)) {
return utils::GetAbsoluteUrlModulesRoot().$sCustomLogoPath.'?t='.utils::GetCacheBusterTimestamp();
}
}
else
{
$sUrl = utils::GetAbsoluteUrlAppRoot().$sDefaultLogoPath;
}
return $sUrl.'?t='.utils::GetCacheBusterTimestamp();
return utils::GetAbsoluteUrlAppRoot().$sDefaultLogoPath.'?t='.utils::GetCacheBusterTimestamp();
}
/**
* Return the absolute URL for the full main logo
*
* @return string
* @throws \Exception
* @throws \Exception<
*/
public static function GetFullMainLogoAbsoluteUrl()
{

View File

@@ -1,5 +1,6 @@
<?php
use Combodo\iTop\Application\Branding;
use Combodo\iTop\Application\UI\Base\Component\Title\Title;
use Combodo\iTop\Application\UI\Base\Component\Title\TitleUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlockUIBlockFactory;
@@ -59,7 +60,7 @@ class ErrorPage extends NiceWebPage
public function output()
{
$sLogo = utils::GetAbsoluteUrlAppRoot(true).'/images/itop-logo.png?t='.utils::GetCacheBusterTimestamp();
$sLogo = Branding::GetFullMainLogoAbsoluteUrl();
$oSetupPage = UIContentBlockUIBlockFactory::MakeStandard('ibo_setup_container', ['ibo-setup']);
$oHeader = UIContentBlockUIBlockFactory::MakeStandard('header', ['ibo-setup--header']);
$oSetupPage->AddSubBlock($oHeader);

View File

@@ -18,6 +18,7 @@
*/
use Combodo\iTop\Application\Branding;
use Combodo\iTop\Application\TwigBase\Twig\TwigHelper;
use Combodo\iTop\Renderer\BlockRenderer;
use Combodo\iTop\Renderer\Console\ConsoleBlockRenderer;
@@ -72,12 +73,7 @@ class UnauthenticatedWebPage extends NiceWebPage
$this->sContent = '';
$this->sPanelTitle = '';
$this->sPanelIcon = utils::GetAbsoluteUrlAppRoot().'images/itop-logo.png';
if (file_exists(MODULESROOT.'branding/main-logo.png'))
{
$this->sPanelIcon = utils::GetAbsoluteUrlModulesRoot().'branding/main-logo.png';
}
$this->sPanelIcon = Branding::GetFullMainLogoAbsoluteUrl();
$this->SetContentType('text/html');

View File

@@ -4,6 +4,8 @@
* @license http://opensource.org/licenses/AGPL-3.0
*/
use Combodo\iTop\Application\Branding;
/**
* Custom class derived from TCPDF for providing custom headers and footers
@@ -91,10 +93,7 @@ class iTopPDF extends TCPDF
'', true, 0, false, true, 15, 'M' /* $valign */);
// Branding logo
$sBrandingIcon = APPROOT.'images/itop-logo.png';
if (file_exists(MODULESROOT.'branding/main-logo.png')) {
$sBrandingIcon = MODULESROOT.'branding/main-logo.png';
}
$sBrandingIcon = Branding::GetFullMainLogoAbsoluteUrl();
$this->Image($sBrandingIcon, $aMargins['left'], 5, 0, 10);
}