From 61f6c1fe33a970fed85bca8f06b1371398cb29e3 Mon Sep 17 00:00:00 2001 From: acognet Date: Fri, 17 Sep 2021 16:36:40 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B02259=20-=20iTop=20Compilation=20of=20bra?= =?UTF-8?q?nding=20images=20ignore=20real=20format=20of=20source=20image?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/logintwig.class.inc.php | 10 ++----- application/loginwebpage.class.inc.php | 10 ++----- css/login.css | 1 + setup/compiler.class.inc.php | 30 +++++++++++++++---- sources/application/Branding.php | 21 ++++++------- sources/application/WebPage/ErrorPage.php | 3 +- .../WebPage/UnauthenticatedWebPage.php | 8 ++--- sources/application/WebPage/iTopPDF.php | 7 ++--- 8 files changed, 45 insertions(+), 45 deletions(-) diff --git a/application/logintwig.class.inc.php b/application/logintwig.class.inc.php index 878d51cc3..ed0c88787 100644 --- a/application/logintwig.class.inc.php +++ b/application/logintwig.class.inc.php @@ -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(), diff --git a/application/loginwebpage.class.inc.php b/application/loginwebpage.class.inc.php index 6dec4e565..8c7aa5105 100644 --- a/application/loginwebpage.class.inc.php +++ b/application/loginwebpage.class.inc.php @@ -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("
\n"); } diff --git a/css/login.css b/css/login.css index d755d1650..bd7a5e7d9 100644 --- a/css/login.css +++ b/css/login.css @@ -86,6 +86,7 @@ a:hover { #login-logo img { border: 0; + max-height: 54px; } #login-form { diff --git a/setup/compiler.class.inc.php b/setup/compiler.class.inc.php index d19897b1e..6c9ff70b8 100644 --- a/setup/compiler.class.inc.php +++ b/setup/compiler.class.inc.php @@ -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')) diff --git a/sources/application/Branding.php b/sources/application/Branding.php index 86309c21d..caa14a274 100644 --- a/sources/application/Branding.php +++ b/sources/application/Branding.php @@ -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() { diff --git a/sources/application/WebPage/ErrorPage.php b/sources/application/WebPage/ErrorPage.php index 3abdfcf5f..815ddc0c9 100644 --- a/sources/application/WebPage/ErrorPage.php +++ b/sources/application/WebPage/ErrorPage.php @@ -1,5 +1,6 @@ AddSubBlock($oHeader); diff --git a/sources/application/WebPage/UnauthenticatedWebPage.php b/sources/application/WebPage/UnauthenticatedWebPage.php index a7af03cfb..26c44f97d 100644 --- a/sources/application/WebPage/UnauthenticatedWebPage.php +++ b/sources/application/WebPage/UnauthenticatedWebPage.php @@ -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'); diff --git a/sources/application/WebPage/iTopPDF.php b/sources/application/WebPage/iTopPDF.php index 6fe2ffc07..2d8779f95 100644 --- a/sources/application/WebPage/iTopPDF.php +++ b/sources/application/WebPage/iTopPDF.php @@ -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); }