This commit is contained in:
Johannes Brückner 2021-06-02 11:16:17 +02:00 committed by GitHub
commit 63aa206afa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 107 additions and 11 deletions

View File

@ -82,6 +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->getEmailLogo()),
'background' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $this->theming->getColorPrimary() !== '#0082c9') ?
$this->theming->getColorPrimary() :
$this->url->getAbsoluteURL($this->theming->getBackground()),

View File

@ -38,7 +38,7 @@ class UpdateConfig extends Command {
];
public const SUPPORTED_IMAGE_KEYS = [
'background', 'logo', 'favicon', 'logoheader'
'background', 'logo', 'emailLogo', 'favicon', 'logoheader'
];
private $themingDefaults;

View File

@ -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 */
@ -86,6 +86,7 @@ class ImageManager {
switch ($key) {
case 'logo':
case 'emailLogo':
case 'logoheader':
case 'favicon':
return $this->urlGenerator->imagePath('core', 'logo/logo.png') . '?v=' . $cacheBusterCounter;

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
*
@ -300,12 +334,14 @@ class ThemingDefaults extends \OC_Defaults {
$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')."')";
@ -424,6 +460,7 @@ class ThemingDefaults extends \OC_Defaults {
$returnValue = $this->getColorPrimary();
break;
case 'logo':
case 'emailLogo':
case 'logoheader':
case 'background':
case 'favicon':

View File

@ -77,6 +77,16 @@ style('theming', 'settings-admin');
<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']); ?>" />

View File

@ -634,6 +634,24 @@ class ThemingDefaultsTest extends TestCase {
$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())
@ -647,14 +665,15 @@ class ThemingDefaultsTest extends TestCase {
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');
@ -664,15 +683,18 @@ class ThemingDefaultsTest extends TestCase {
->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',

View File

@ -380,7 +380,7 @@ EOF;
}
$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()]);
}

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

@ -176,6 +176,7 @@ class Defaults {
* 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
*/
@ -183,6 +184,16 @@ class Defaults {
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