Implement extracted getEmailLogo method

This commit is contained in:
Johannes Brückner 2021-05-31 10:08:39 +02:00
parent 5d98dacc8d
commit 317dd23a35
6 changed files with 63 additions and 5 deletions

View File

@ -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()),

View File

@ -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
*

View File

@ -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() {

View File

@ -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()]);
}

View File

@ -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();

View File

@ -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();
}
/**