Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Implement extracted getEmailLogo method
  • Loading branch information
brueckner committed May 31, 2021
commit 317dd23a35c6b8b4f5aaeba5eccc48179907b5a8
2 changes: 1 addition & 1 deletion apps/theming/lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function getCapabilities() {
'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()),
Expand Down
34 changes: 34 additions & 0 deletions apps/theming/lib/ThemingDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,40 @@ public function getLogo($useSvg = true): string {
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
*
Expand Down
2 changes: 1 addition & 1 deletion apps/theming/tests/ThemingDefaultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ public function testGetEmailLogoCustom() {
->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() {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Mail/EMailTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ public function addHeader() {
}
$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()]);
}

Expand Down
14 changes: 14 additions & 0 deletions lib/private/legacy/OC_Defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,20 @@ public function getLogo($useSvg = true) {
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();
Expand Down
14 changes: 12 additions & 2 deletions lib/public/Defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,18 @@ public function getiTunesAppId(): string {
* @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();
}

/**
Expand Down