diff --git a/apps/theming/lib/Capabilities.php b/apps/theming/lib/Capabilities.php index 96b314081a..7dd30f7d2c 100644 --- a/apps/theming/lib/Capabilities.php +++ b/apps/theming/lib/Capabilities.php @@ -82,7 +82,7 @@ class Capabilities implements IPublicCapability { 'color-element-bright' => $this->util->elementColor($color), 'color-element-dark' => $this->util->elementColor($color, false), 'logo' => $this->url->getAbsoluteURL($this->theming->getLogo()), - 'emailLogo' => $this->url->getAbsoluteURL($this->theming->getLogo(false, true)), + 'emailLogo' => $this->url->getAbsoluteURL($this->theming->getEmailLogo()), 'background' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $this->theming->getColorPrimary() !== '#0082c9') ? $this->theming->getColorPrimary() : $this->url->getAbsoluteURL($this->theming->getBackground()), diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index cd8fc8546b..fba62b8b70 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -256,6 +256,40 @@ class ThemingDefaults extends \OC_Defaults { return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo', 'useSvg' => $useSvg, 'v' => $cacheBusterCounter ]); } + /** + * Themed email logo url + * + * @return string + */ + public function getEmailLogo(): string { + $logoKey = 'emailLogo'; + $emailLogo = $this->config->getAppValue('theming', $logoKey . 'Mime', ''); + $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); + + // short cut to avoid setting up the filesystem just to check if the logo is there + // + // explanation: if an SVG is requested and the app config value for logoMime is set then the logo is there. + // otherwise we need to check it and maybe also generate a PNG from the SVG (that's done in getImage() which + // needs to be called then) + if ($emailLogo !== false) { + $logoExists = true; + } else { + try { + $this->imageManager->getImage($logoKey, false); + $logoExists = true; + } catch (\Exception $e) { + $logoExists = false; + } + } + + if (!$emailLogo || !$logoExists) { + $emailLogo = $this->urlGenerator->imagePath('core', 'logo/logo.png'); + return $emailLogo . '?v=' . $cacheBusterCounter; + } + + return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => $logoKey, 'useSvg' => false, 'v' => $cacheBusterCounter ]); + } + /** * Themed background image url * diff --git a/apps/theming/tests/ThemingDefaultsTest.php b/apps/theming/tests/ThemingDefaultsTest.php index 8d1b4aefa1..0fc0bc62c3 100644 --- a/apps/theming/tests/ThemingDefaultsTest.php +++ b/apps/theming/tests/ThemingDefaultsTest.php @@ -649,7 +649,7 @@ class ThemingDefaultsTest extends TestCase { ->method('linkToRoute') ->with('theming.Theming.getImage') ->willReturn('custom-email-logo?v=0'); - $this->assertEquals('custom-email-logo' . '?v=0', $this->template->getLogo(false, true)); + $this->assertEquals('custom-email-logo' . '?v=0', $this->template->getEmailLogo()); } public function testGetScssVariablesCached() { diff --git a/lib/private/Mail/EMailTemplate.php b/lib/private/Mail/EMailTemplate.php index 9c4cdac168..6cedf39c50 100644 --- a/lib/private/Mail/EMailTemplate.php +++ b/lib/private/Mail/EMailTemplate.php @@ -380,7 +380,7 @@ EOF; } $this->headerAdded = true; - $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false, true)); + $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getEmailLogo()); $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl, $this->themingDefaults->getName()]); } diff --git a/lib/private/legacy/OC_Defaults.php b/lib/private/legacy/OC_Defaults.php index a9f588eb6e..2a20fddb87 100644 --- a/lib/private/legacy/OC_Defaults.php +++ b/lib/private/legacy/OC_Defaults.php @@ -324,6 +324,20 @@ class OC_Defaults { return $logo . '?v=' . hash('sha1', implode('.', \OCP\Util::getVersion())); } + /** + * Themed email logo url + * + * @return string + */ + public function getEmailLogo() { + if ($this->themeExist('getEmailLogo')) { + return $this->theme->getEmailLogo(); + } + + $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.png'); + return $logo . '?v=' . hash('sha1', implode('.', \OCP\Util::getVersion())); + } + public function getTextColorPrimary() { if ($this->themeExist('getTextColorPrimary')) { return $this->theme->getTextColorPrimary(); diff --git a/lib/public/Defaults.php b/lib/public/Defaults.php index fbcafe63e1..422af46904 100644 --- a/lib/public/Defaults.php +++ b/lib/public/Defaults.php @@ -180,8 +180,18 @@ class Defaults { * @return string * @since 12.0.0 */ - public function getLogo(bool $useSvg = true, $emailLogo = false): string { - return $this->defaults->getLogo($useSvg, $emailLogo); + public function getLogo(bool $useSvg = true): string { + return $this->defaults->getLogo($useSvg); + } + + /** + * Themed email logo url + * + * @return string + * @since 12.0.0 + */ + public function getEmailLogo(): string { + return $this->defaults->getEmailLogo(); } /**