From: Morris Jobke Date: Fri, 8 Dec 2017 11:16:05 +0000 (+0100) Subject: Fix email buttons for white theme X-Git-Tag: v12.0.5RC1~25^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e726d191f13fc0e6f79436625d734faa8f284a58;p=nextcloud-server.git Fix email buttons for white theme Signed-off-by: Morris Jobke --- diff --git a/apps/theming/lib/Capabilities.php b/apps/theming/lib/Capabilities.php index 58fc5feeec9..cc938db1af2 100644 --- a/apps/theming/lib/Capabilities.php +++ b/apps/theming/lib/Capabilities.php @@ -73,7 +73,7 @@ class Capabilities implements ICapability { 'url' => $this->theming->getBaseUrl(), 'slogan' => $this->theming->getSlogan(), 'color' => $this->theming->getColorPrimary(), - 'color-text' => $this->util->invertTextColor($this->theming->getColorPrimary()) ? '#000000' : '#FFFFFF', + 'color-text' => $this->theming->getTextColorPrimary(), 'logo' => $this->url->getAbsoluteURL($this->theming->getLogo()), 'background' => $backgroundLogo === 'backgroundColor' ? $this->theming->getColorPrimary() : diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index 6b166d897b0..f1a914995d6 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -231,13 +231,8 @@ class ThemingDefaults extends \OC_Defaults { $variables['image-login-plain'] = 'false'; if ($this->config->getAppValue('theming', 'color', null) !== null) { - if ($this->util->invertTextColor($this->getColorPrimary())) { - $colorPrimaryText = '#000000'; - } else { - $colorPrimaryText = '#ffffff'; - } $variables['color-primary'] = $this->getColorPrimary(); - $variables['color-primary-text'] = $colorPrimaryText; + $variables['color-primary-text'] = $this->getTextColorPrimary(); $variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary()); } @@ -321,4 +316,13 @@ class ThemingDefaults extends \OC_Defaults { return $returnValue; } + + /** + * Color of text in the header and primary buttons + * + * @return string + */ + public function getTextColorPrimary() { + return $this->util->invertTextColor($this->getColorPrimary()) ? '#000000' : '#ffffff'; + } } diff --git a/apps/theming/tests/CapabilitiesTest.php b/apps/theming/tests/CapabilitiesTest.php index 8ab7f6e2c7f..77582064a3e 100644 --- a/apps/theming/tests/CapabilitiesTest.php +++ b/apps/theming/tests/CapabilitiesTest.php @@ -61,7 +61,7 @@ class CapabilitiesTest extends TestCase { public function dataGetCapabilities() { return [ - ['name', 'url', 'slogan', '#FFFFFF', 'logo', 'background', 'http://absolute/', [ + ['name', 'url', 'slogan', '#FFFFFF', '#000000', 'logo', 'background', 'http://absolute/', [ 'name' => 'name', 'url' => 'url', 'slogan' => 'slogan', @@ -70,21 +70,21 @@ class CapabilitiesTest extends TestCase { 'logo' => 'http://absolute/logo', 'background' => 'http://absolute/background', ]], - ['name1', 'url2', 'slogan3', '#01e4a0', 'logo5', 'background6', 'http://localhost/', [ + ['name1', 'url2', 'slogan3', '#01e4a0', '#ffffff', 'logo5', 'background6', 'http://localhost/', [ 'name' => 'name1', 'url' => 'url2', 'slogan' => 'slogan3', 'color' => '#01e4a0', - 'color-text' => '#FFFFFF', + 'color-text' => '#ffffff', 'logo' => 'http://localhost/logo5', 'background' => 'http://localhost/background6', ]], - ['name1', 'url2', 'slogan3', '#000000', 'logo5', 'backgroundColor', 'http://localhost/', [ + ['name1', 'url2', 'slogan3', '#000000', '#ffffff', 'logo5', 'backgroundColor', 'http://localhost/', [ 'name' => 'name1', 'url' => 'url2', 'slogan' => 'slogan3', 'color' => '#000000', - 'color-text' => '#FFFFFF', + 'color-text' => '#ffffff', 'logo' => 'http://localhost/logo5', 'background' => '#000000', ]], @@ -98,11 +98,12 @@ class CapabilitiesTest extends TestCase { * @param string $slogan * @param string $color * @param string $logo + * @param string $textColor * @param string $background * @param string $baseUrl * @param string[] $expected */ - public function testGetCapabilities($name, $url, $slogan, $color, $logo, $background, $baseUrl, array $expected) { + public function testGetCapabilities($name, $url, $slogan, $color, $textColor, $logo, $background, $baseUrl, array $expected) { $this->config->expects($this->once()) ->method('getAppValue') ->willReturn($background); @@ -121,6 +122,9 @@ class CapabilitiesTest extends TestCase { $this->theming->expects($this->once()) ->method('getLogo') ->willReturn($logo); + $this->theming->expects($this->once()) + ->method('getTextColorPrimary') + ->willReturn($textColor); if($background !== 'backgroundColor') { $this->theming->expects($this->once()) diff --git a/lib/private/Mail/EMailTemplate.php b/lib/private/Mail/EMailTemplate.php index 245e19cee81..6686e45ab7c 100644 --- a/lib/private/Mail/EMailTemplate.php +++ b/lib/private/Mail/EMailTemplate.php @@ -230,7 +230,7 @@ EOF;
- %s + %s
@@ -283,7 +283,7 @@ EOF;
- %s + %s
@@ -518,8 +518,9 @@ EOF; $this->ensureBodyListClosed(); $color = $this->themingDefaults->getColorPrimary(); + $textColor = $this->themingDefaults->getTextColorPrimary(); - $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, htmlspecialchars($textLeft), $urlRight, htmlspecialchars($textRight)]); + $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textColor, $textColor, htmlspecialchars($textLeft), $urlRight, htmlspecialchars($textRight)]); $this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL; $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; @@ -548,7 +549,8 @@ EOF; } $color = $this->themingDefaults->getColorPrimary(); - $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, htmlspecialchars($text)]); + $textColor = $this->themingDefaults->getTextColorPrimary(); + $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, $textColor, $textColor, htmlspecialchars($text)]); if ($plainText !== false) { $this->plainBody .= $plainText . ': '; diff --git a/lib/private/legacy/defaults.php b/lib/private/legacy/defaults.php index f6d72d9776d..f4c1b38a5b3 100644 --- a/lib/private/legacy/defaults.php +++ b/lib/private/legacy/defaults.php @@ -47,6 +47,7 @@ class OC_Defaults { private $defaultSlogan; private $defaultLogoClaim; private $defaultColorPrimary; + private $defaultTextColorPrimary; public function __construct() { $this->l = \OC::$server->getL10N('lib'); @@ -64,6 +65,7 @@ class OC_Defaults { $this->defaultSlogan = $this->l->t('a safe home for all your data'); $this->defaultLogoClaim = ''; $this->defaultColorPrimary = '#0082c9'; + $this->defaultTextColorPrimary = '#ffffff'; $themePath = OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults.php'; if (file_exists($themePath)) { @@ -319,4 +321,11 @@ class OC_Defaults { } return $logo . '?v=' . hash('sha1', implode('.', \OCP\Util::getVersion())); } + + public function getTextColorPrimary() { + if ($this->themeExist('getTextColorPrimary')) { + return $this->theme->getTextColorPrimary(); + } + return $this->defaultTextColorPrimary; + } } diff --git a/lib/public/Defaults.php b/lib/public/Defaults.php index 543657694c5..e220208aa07 100644 --- a/lib/public/Defaults.php +++ b/lib/public/Defaults.php @@ -212,4 +212,13 @@ class Defaults { public function getTitle() { return $this->defaults->getTitle(); } + + /** + * Returns primary color + * @return string + * @since 13.0.0 + */ + public function getTextColorPrimary() { + return $this->defaults->getTextColorPrimary(); + } } diff --git a/tests/Settings/Mailer/NewUserMailHelperTest.php b/tests/Settings/Mailer/NewUserMailHelperTest.php index bc98549202d..09d53f0574b 100644 --- a/tests/Settings/Mailer/NewUserMailHelperTest.php +++ b/tests/Settings/Mailer/NewUserMailHelperTest.php @@ -157,6 +157,10 @@ class NewUserMailHelperTest extends TestCase { ->expects($this->any()) ->method('getName') ->willReturn('TestCloud'); + $this->defaults + ->expects($this->any()) + ->method('getTextColorPrimary') + ->willReturn('#ffffff'); $expectedHtmlBody = << @@ -281,7 +285,7 @@ class NewUserMailHelperTest extends TestCase {
- Set your password + Set your password
@@ -390,6 +394,10 @@ EOF; ->expects($this->any()) ->method('getName') ->willReturn('TestCloud'); + $this->defaults + ->expects($this->any()) + ->method('getTextColorPrimary') + ->willReturn('#ffffff'); $expectedHtmlBody = << @@ -514,7 +522,7 @@ EOF;
- Go to TestCloud + Go to TestCloud
diff --git a/tests/data/emails/new-account-email-custom.html b/tests/data/emails/new-account-email-custom.html index 9d35a7f3515..601aa0b63d4 100644 --- a/tests/data/emails/new-account-email-custom.html +++ b/tests/data/emails/new-account-email-custom.html @@ -120,7 +120,7 @@
- Set your password + Set your password
diff --git a/tests/data/emails/new-account-email-single-button.html b/tests/data/emails/new-account-email-single-button.html index 3746d5d2cbb..db8ab868682 100644 --- a/tests/data/emails/new-account-email-single-button.html +++ b/tests/data/emails/new-account-email-single-button.html @@ -120,7 +120,7 @@
- Set your password + Set your password
diff --git a/tests/data/emails/new-account-email.html b/tests/data/emails/new-account-email.html index d33cb540c38..f7ffbb8abf6 100644 --- a/tests/data/emails/new-account-email.html +++ b/tests/data/emails/new-account-email.html @@ -120,7 +120,7 @@
- Set your password + Set your password
diff --git a/tests/lib/Mail/EMailTemplateTest.php b/tests/lib/Mail/EMailTemplateTest.php index 339cd95defc..d4687c44b06 100644 --- a/tests/lib/Mail/EMailTemplateTest.php +++ b/tests/lib/Mail/EMailTemplateTest.php @@ -68,6 +68,10 @@ class EMailTemplateTest extends TestCase { ->expects($this->any()) ->method('getName') ->willReturn('TestCloud'); + $this->defaults + ->expects($this->any()) + ->method('getTextColorPrimary') + ->willReturn('#ffffff'); $this->urlGenerator ->expects($this->once()) ->method('getAbsoluteURL') @@ -109,6 +113,10 @@ class EMailTemplateTest extends TestCase { ->expects($this->any()) ->method('getLogo') ->willReturn('/img/logo-mail-header.png'); + $this->defaults + ->expects($this->any()) + ->method('getTextColorPrimary') + ->willReturn('#ffffff'); $this->urlGenerator ->expects($this->once()) ->method('getAbsoluteURL') @@ -148,6 +156,10 @@ class EMailTemplateTest extends TestCase { ->expects($this->any()) ->method('getLogo') ->willReturn('/img/logo-mail-header.png'); + $this->defaults + ->expects($this->any()) + ->method('getTextColorPrimary') + ->willReturn('#ffffff'); $this->urlGenerator ->expects($this->once()) ->method('getAbsoluteURL') @@ -189,6 +201,10 @@ class EMailTemplateTest extends TestCase { ->expects($this->any()) ->method('getLogo') ->willReturn('/img/logo-mail-header.png'); + $this->defaults + ->expects($this->any()) + ->method('getTextColorPrimary') + ->willReturn('#ffffff'); $this->urlGenerator ->expects($this->once()) ->method('getAbsoluteURL')