]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix email buttons for white theme 7558/head
authorMorris Jobke <hey@morrisjobke.de>
Fri, 8 Dec 2017 11:16:05 +0000 (12:16 +0100)
committerMorris Jobke <hey@morrisjobke.de>
Mon, 18 Dec 2017 16:03:01 +0000 (17:03 +0100)
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
apps/theming/lib/Capabilities.php
apps/theming/lib/ThemingDefaults.php
apps/theming/tests/CapabilitiesTest.php
lib/private/Mail/EMailTemplate.php
lib/private/legacy/defaults.php
lib/public/Defaults.php
tests/Settings/Mailer/NewUserMailHelperTest.php
tests/data/emails/new-account-email-custom.html
tests/data/emails/new-account-email-single-button.html
tests/data/emails/new-account-email.html
tests/lib/Mail/EMailTemplateTest.php

index 58fc5feeec906a905e7fec9d3f98f5bd93aa18d1..cc938db1af2891c694dc43403572c3944b74fd6f 100644 (file)
@@ -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() :
index 6b166d897b001864db5435b73400723f1e0773e9..f1a914995d61ba72c07aaf93352078c965f465ac 100644 (file)
@@ -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';
+       }
 }
index 8ab7f6e2c7f1dd47d354a6f7e74ef3b006e91329..77582064a3e816e04164b40b808d60bd5d3c08ea 100644 (file)
@@ -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())
index 245e19cee8104d3ee2ae1d310aa87362408c07ad..6686e45ab7c87177b0d145ee0ccbd66257b0d0e2 100644 (file)
@@ -230,7 +230,7 @@ EOF;
                                                                                <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
                                                                                        <tr style="padding:0;text-align:left;vertical-align:top">
                                                                                                <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:%s;border:0 solid %s;border-collapse:collapse!important;color:#fefefe;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
-                                                                                                       <a href="%s" style="Margin:0;border:0 solid %s;border-radius:2px;color:#fefefe;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">%s</a>
+                                                                                                       <a href="%s" style="Margin:0;border:0 solid %s;border-radius:2px;color:%s;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;outline:1px solid %s;text-decoration:none">%s</a>
                                                                                                </td>
                                                                                        </tr>
                                                                                </table>
@@ -283,7 +283,7 @@ EOF;
                                                                                <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
                                                                                        <tr style="padding:0;text-align:left;vertical-align:top">
                                                                                                <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:%s;border:0 solid %s;border-collapse:collapse!important;color:#fefefe;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
-                                                                                                       <a href="%s" style="Margin:0;border:0 solid %s;border-radius:2px;color:#fefefe;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">%s</a>
+                                                                                                       <a href="%s" style="Margin:0;border:0 solid %s;border-radius:2px;color:%s;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;outline:1px solid %s;text-decoration:none">%s</a>
                                                                                                </td>
                                                                                        </tr>
                                                                                </table>
@@ -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 . ': ';
index f6d72d9776d7088eee99584210d7d3171c484c11..f4c1b38a5b34a729f845f898b46691596acef760 100644 (file)
@@ -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;
+       }
 }
index 543657694c57d22aef335be715b26bbcce25d209..e220208aa07a8031e16ac440eb74ca813ed07845 100644 (file)
@@ -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();
+       }
 }
index bc98549202d87182454123177e827275c91cf384..09d53f0574b1cf62e37000528d7954c357811050 100644 (file)
@@ -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 = <<<EOF
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@@ -281,7 +285,7 @@ class NewUserMailHelperTest extends TestCase {
                                                                                <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
                                                                                        <tr style="padding:0;text-align:left;vertical-align:top">
                                                                                                <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:;border:0 solid ;border-collapse:collapse!important;color:#fefefe;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
-                                                                                                       <a href="https://example.com/resetPassword/MySuperLongSecureRandomToken" style="Margin:0;border:0 solid ;border-radius:2px;color:#fefefe;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">Set your password</a>
+                                                                                                       <a href="https://example.com/resetPassword/MySuperLongSecureRandomToken" style="Margin:0;border:0 solid ;border-radius:2px;color:#ffffff;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;outline:1px solid #ffffff;text-decoration:none">Set your password</a>
                                                                                                </td>
                                                                                        </tr>
                                                                                </table>
@@ -390,6 +394,10 @@ EOF;
                        ->expects($this->any())
                        ->method('getName')
                        ->willReturn('TestCloud');
+               $this->defaults
+                       ->expects($this->any())
+                       ->method('getTextColorPrimary')
+                       ->willReturn('#ffffff');
 
                $expectedHtmlBody = <<<EOF
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@@ -514,7 +522,7 @@ EOF;
                                                                                <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
                                                                                        <tr style="padding:0;text-align:left;vertical-align:top">
                                                                                                <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:;border:0 solid ;border-collapse:collapse!important;color:#fefefe;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
-                                                                                                       <a href="https://example.com/" style="Margin:0;border:0 solid ;border-radius:2px;color:#fefefe;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">Go to TestCloud</a>
+                                                                                                       <a href="https://example.com/" style="Margin:0;border:0 solid ;border-radius:2px;color:#ffffff;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;outline:1px solid #ffffff;text-decoration:none">Go to TestCloud</a>
                                                                                                </td>
                                                                                        </tr>
                                                                                </table>
index 9d35a7f3515e3cdff6110e44a2915e5c8d0fe693..601aa0b63d4a11de245d0d5691fb8e319e85533c 100644 (file)
                                                                                <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
                                                                                        <tr style="padding:0;text-align:left;vertical-align:top">
                                                                                                <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:#0082c9;border:0 solid #0082c9;border-collapse:collapse!important;color:#fefefe;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
-                                                                                                       <a href="https://example.org/resetPassword/123" style="Margin:0;border:0 solid #0082c9;border-radius:2px;color:#fefefe;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">Set your password</a>
+                                                                                                       <a href="https://example.org/resetPassword/123" style="Margin:0;border:0 solid #0082c9;border-radius:2px;color:#ffffff;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;outline:1px solid #ffffff;text-decoration:none">Set your password</a>
                                                                                                </td>
                                                                                        </tr>
                                                                                </table>
index 3746d5d2cbb3941cfa7cfd5fc8e19b009dfc823c..db8ab868682c1e521f147491c79815f442ea88ba 100644 (file)
                                                                                <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
                                                                                        <tr style="padding:0;text-align:left;vertical-align:top">
                                                                                                <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:#0082c9;border:0 solid #0082c9;border-collapse:collapse!important;color:#fefefe;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
-                                                                                                       <a href="https://example.org/resetPassword/123" style="Margin:0;border:0 solid #0082c9;border-radius:2px;color:#fefefe;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">Set your password</a>
+                                                                                                       <a href="https://example.org/resetPassword/123" style="Margin:0;border:0 solid #0082c9;border-radius:2px;color:#ffffff;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;outline:1px solid #ffffff;text-decoration:none">Set your password</a>
                                                                                                </td>
                                                                                        </tr>
                                                                                </table>
index d33cb540c38cf0f615af9c09d5eb9536704fc37b..f7ffbb8abf6599b0386d6c1dbf80bf033ca1ec0e 100644 (file)
                                                                                <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
                                                                                        <tr style="padding:0;text-align:left;vertical-align:top">
                                                                                                <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:#0082c9;border:0 solid #0082c9;border-collapse:collapse!important;color:#fefefe;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
-                                                                                                       <a href="https://example.org/resetPassword/123" style="Margin:0;border:0 solid #0082c9;border-radius:2px;color:#fefefe;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">Set your password</a>
+                                                                                                       <a href="https://example.org/resetPassword/123" style="Margin:0;border:0 solid #0082c9;border-radius:2px;color:#ffffff;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;outline:1px solid #ffffff;text-decoration:none">Set your password</a>
                                                                                                </td>
                                                                                        </tr>
                                                                                </table>
index 339cd95defc7df3b28231c919cc47be9fa9be386..d4687c44b069d4d61844e144843fe3fe283fea94 100644 (file)
@@ -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')