Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions apps/theming/lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +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->getEmailLogo()),
'background' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $this->theming->getColorPrimary() !== '#0082c9') ?
$this->theming->getColorPrimary() :
$this->url->getAbsoluteURL($this->theming->getBackground()),
Expand Down
2 changes: 1 addition & 1 deletion apps/theming/lib/Command/UpdateConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class UpdateConfig extends Command {
];

public const SUPPORTED_IMAGE_KEYS = [
'background', 'logo', 'favicon', 'logoheader'
'background', 'logo', 'emailLogo', 'favicon', 'logoheader'
];

private $themingDefaults;
Expand Down
3 changes: 2 additions & 1 deletion apps/theming/lib/ImageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ImageManager {
/** @var IURLGenerator */
private $urlGenerator;
/** @var array */
private $supportedImageKeys = ['background', 'logo', 'logoheader', 'favicon'];
private $supportedImageKeys = ['background', 'logo', 'emailLogo', 'logoheader', 'favicon'];
/** @var ICacheFactory */
private $cacheFactory;
/** @var ILogger */
Expand Down Expand Up @@ -86,6 +86,7 @@ public function getImageUrl(string $key, bool $useSvg = true): string {

switch ($key) {
case 'logo':
case 'emailLogo':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since svg is causing issues with email it would make sense to not allow to upload it then for an email logo:

https://github.com/nextcloud/server/pull/26871/files#diff-b9d526f6249d406c08009d9de5802b5637194bb66ec759df798dd397f9a422beR222-R225

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, you're absolutely right! The refactored version (see my other comment below) has no support for an SVG version.

case 'logoheader':
case 'favicon':
return $this->urlGenerator->imagePath('core', 'logo/logo.png') . '?v=' . $cacheBusterCounter;
Expand Down
37 changes: 37 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 Expand Up @@ -300,12 +334,14 @@ public function getScssVariables() {
$variables = [
'theming-cachebuster' => "'" . $cacheBuster . "'",
'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'",
'theming-email-logo-mime' => "'" . $this->config->getAppValue('theming', 'emailLogoMime') . "'",
'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'",
'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'",
'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'"
];

$variables['image-logo'] = "url('".$this->imageManager->getImageUrl('logo')."')";
$variables['image-email-logo'] = "url('".$this->imageManager->getImageUrl('emailLogo')."')";
$variables['image-logoheader'] = "url('".$this->imageManager->getImageUrl('logoheader')."')";
$variables['image-favicon'] = "url('".$this->imageManager->getImageUrl('favicon')."')";
$variables['image-login-background'] = "url('".$this->imageManager->getImageUrl('background')."')";
Expand Down Expand Up @@ -424,6 +460,7 @@ public function undo($setting) {
$returnValue = $this->getColorPrimary();
break;
case 'logo':
case 'emailLogo':
case 'logoheader':
case 'background':
case 'favicon':
Expand Down
10 changes: 10 additions & 0 deletions apps/theming/templates/settings-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@
<div data-setting="logoMime" data-toggle="tooltip" data-original-title="<?php p($l->t('Reset to default')); ?>" class="theme-undo icon icon-history"></div>
</form>
</div>
<div>
<form class="uploadButton" method="post" action="<?php p($_['uploadLogoRoute']) ?>" data-image-key="emailLogo">
<input type="hidden" id="theming-emailLogoMime" value="<?php p($_['images']['emailLogo']['mime']); ?>" />
<input type="hidden" name="key" value="emailLogo" />
<label for="upload-email-logo"><span><?php p($l->t('Email Logo')) ?></span></label>
<input id="upload-email-logo" class="fileupload" name="image" type="file" />
<label for="upload-email-logo" class="button icon-upload svg" id="upload-email-log" title="<?php p($l->t('Upload new email logo')) ?>"></label>
<div data-setting="emailLogoMime" data-toggle="tooltip" data-original-title="<?php p($l->t('Reset to default')); ?>" class="theme-undo icon icon-history"></div>
</form>
</div>
<div>
<form class="uploadButton" method="post" action="<?php p($_['uploadLogoRoute']) ?>" data-image-key="background">
<input type="hidden" id="theming-backgroundMime" value="<?php p($_['images']['background']['mime']); ?>" />
Expand Down
38 changes: 30 additions & 8 deletions apps/theming/tests/ThemingDefaultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,24 @@ public function testGetLogoCustom() {
$this->assertEquals('custom-logo' . '?v=0', $this->template->getLogo());
}

public function testGetEmailLogoCustom() {
$this->config
->expects($this->at(0))
->method('getAppValue')
->with('theming', 'emailLogoMime', false)
->willReturn('image/svg+xml');
$this->config
->expects($this->at(1))
->method('getAppValue')
->with('theming', 'cachebuster', '0')
->willReturn('0');
$this->urlGenerator->expects($this->once())
->method('linkToRoute')
->with('theming.Theming.getImage')
->willReturn('custom-email-logo?v=0');
$this->assertEquals('custom-email-logo' . '?v=0', $this->template->getEmailLogo());
}

public function testGetScssVariablesCached() {
$this->config->expects($this->any())->method('getAppValue')->with('theming', 'cachebuster', '0')->willReturn('1');
$this->cacheFactory->expects($this->once())
Expand All @@ -647,14 +665,15 @@ public function testGetScssVariablesCached() {
public function testGetScssVariables() {
$this->config->expects($this->at(0))->method('getAppValue')->with('theming', 'cachebuster', '0')->willReturn('0');
$this->config->expects($this->at(1))->method('getAppValue')->with('theming', 'logoMime', false)->willReturn('jpeg');
$this->config->expects($this->at(2))->method('getAppValue')->with('theming', 'backgroundMime', false)->willReturn('jpeg');
$this->config->expects($this->at(3))->method('getAppValue')->with('theming', 'logoheaderMime', false)->willReturn('jpeg');
$this->config->expects($this->at(4))->method('getAppValue')->with('theming', 'faviconMime', false)->willReturn('jpeg');
$this->config->expects($this->at(2))->method('getAppValue')->with('theming', 'emailLogoMime', false)->willReturn('jpeg');
$this->config->expects($this->at(3))->method('getAppValue')->with('theming', 'backgroundMime', false)->willReturn('jpeg');
$this->config->expects($this->at(4))->method('getAppValue')->with('theming', 'logoheaderMime', false)->willReturn('jpeg');
$this->config->expects($this->at(5))->method('getAppValue')->with('theming', 'faviconMime', false)->willReturn('jpeg');

$this->config->expects($this->at(5))->method('getAppValue')->with('theming', 'color', null)->willReturn($this->defaults->getColorPrimary());
$this->config->expects($this->at(6))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary());
$this->config->expects($this->at(6))->method('getAppValue')->with('theming', 'color', null)->willReturn($this->defaults->getColorPrimary());
$this->config->expects($this->at(7))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary());
$this->config->expects($this->at(8))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary());
$this->config->expects($this->at(9))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary());

$this->util->expects($this->any())->method('invertTextColor')->with($this->defaults->getColorPrimary())->willReturn(false);
$this->util->expects($this->any())->method('elementColor')->with($this->defaults->getColorPrimary())->willReturn('#aaaaaa');
Expand All @@ -664,15 +683,18 @@ public function testGetScssVariables() {
->willReturn($this->cache);
$this->cache->expects($this->once())->method('get')->with('getScssVariables')->willReturn(null);
$this->imageManager->expects($this->at(0))->method('getImageUrl')->with('logo')->willReturn('custom-logo?v=0');
$this->imageManager->expects($this->at(1))->method('getImageUrl')->with('logoheader')->willReturn('custom-logoheader?v=0');
$this->imageManager->expects($this->at(2))->method('getImageUrl')->with('favicon')->willReturn('custom-favicon?v=0');
$this->imageManager->expects($this->at(3))->method('getImageUrl')->with('background')->willReturn('custom-background?v=0');
$this->imageManager->expects($this->at(1))->method('getImageUrl')->with('emailLogo')->willReturn('custom-emailLogo?v=0');
$this->imageManager->expects($this->at(2))->method('getImageUrl')->with('logoheader')->willReturn('custom-logoheader?v=0');
$this->imageManager->expects($this->at(3))->method('getImageUrl')->with('favicon')->willReturn('custom-favicon?v=0');
$this->imageManager->expects($this->at(4))->method('getImageUrl')->with('background')->willReturn('custom-background?v=0');

$expected = [
'theming-cachebuster' => '\'0\'',
'theming-logo-mime' => '\'jpeg\'',
'theming-email-logo-mime' => '\'jpeg\'',
'theming-background-mime' => '\'jpeg\'',
'image-logo' => "url('custom-logo?v=0')",
'image-email-logo' => "url('custom-emailLogo?v=0')",
'image-login-background' => "url('custom-background?v=0')",
'color-primary' => $this->defaults->getColorPrimary(),
'color-primary-text' => '#ffffff',
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));
$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
11 changes: 11 additions & 0 deletions lib/public/Defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,24 @@ public function getiTunesAppId(): string {
* Themed logo url
*
* @param bool $useSvg Whether to point to the SVG image or a fallback
* @param bool $emailLogo Whether to return the email logo (if one exists)
* @return string
* @since 12.0.0
*/
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();
}

/**
* Returns primary color
* @return string
Expand Down