summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2017-04-07 14:51:05 +0200
committerMorris Jobke <hey@morrisjobke.de>2017-04-07 12:03:47 -0500
commit281ad406e88d36c1492c7aefd8ef28762379f9e3 (patch)
tree91b81364f1a9244455657b86848025c628fd4089 /lib/private
parent1be75e8db8f583476f1cd03498afd608fce6408d (diff)
downloadnextcloud-server-281ad406e88d36c1492c7aefd8ef28762379f9e3.tar.gz
nextcloud-server-281ad406e88d36c1492c7aefd8ef28762379f9e3.zip
Add support for theming
Add support for theming in generated emails and simplify API Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Mail/EMailTemplate.php56
-rw-r--r--lib/private/Mail/IEMailTemplate.php25
-rw-r--r--lib/private/Server.php4
3 files changed, 52 insertions, 33 deletions
diff --git a/lib/private/Mail/EMailTemplate.php b/lib/private/Mail/EMailTemplate.php
index 7a884dd928c..7d3ca51c50e 100644
--- a/lib/private/Mail/EMailTemplate.php
+++ b/lib/private/Mail/EMailTemplate.php
@@ -1,8 +1,10 @@
<?php
/**
* @copyright 2017, Morris Jobke <hey@morrisjobke.de>
+ * @copyright 2017, Lukas Reschke <lukas@statuscode.ch>
*
* @author Morris Jobke <hey@morrisjobke.de>
+ * @author Lukas Reschke <lukas@statuscode.ch>
*
* @license GNU AGPL version 3 or any later version
*
@@ -23,6 +25,9 @@
namespace OC\Mail;
+use OCA\Theming\ThemingDefaults;
+use OCP\IL10N;
+use OCP\IURLGenerator;
/**
* Class EMailTemplate
@@ -33,9 +38,12 @@ namespace OC\Mail;
* @package OC\Mail
*/
class EMailTemplate implements IEMailTemplate {
-
- /** @var \OC_Defaults */
- protected $defaults;
+ /** @var ThemingDefaults */
+ protected $themingDefaults;
+ /** @var IURLGenerator */
+ protected $urlGenerator;
+ /** @var IL10N */
+ protected $l10n;
/** @var string */
protected $htmlBody = '';
@@ -88,7 +96,7 @@ EOF;
<table class="row collapse" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%%">
<tbody>
<tr style="padding:0;text-align:left;vertical-align:top">
- <center data-parsed="" style="min-width:580px;width:100%%"><!-- TODO -->
+ <center data-parsed="" style="min-width:580px;width:100%%">
<img class="logo float-center" src="%s" alt="logo" align="center" style="-ms-interpolation-mode:bicubic;Margin:0 auto;clear:both;display:block;float:none;margin:0 auto;max-height:100%%;max-width:100px;outline:0;text-align:center;text-decoration:none;width:auto">
</center>
</tr>
@@ -240,8 +248,7 @@ EOF;
<table align="center" class="wrapper footer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%">
<tr style="padding:0;text-align:left;vertical-align:top">
<td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;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">
- <center data-parsed="" style="min-width:580px;width:100%%"><!-- TODO -->
- <img class="logo float-center" src="%s" alt="logo" align="center" style="-ms-interpolation-mode:bicubic;Margin:0 auto;clear:both;display:block;float:none;margin:0 auto;max-height:100%%;max-width:75px;outline:0;text-align:center;text-decoration:none;width:auto">
+ <center data-parsed="" style="min-width:580px;width:100%%">
<table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%">
<tbody>
<tr style="padding:0;text-align:left;vertical-align:top">
@@ -249,32 +256,38 @@ EOF;
</tr>
</tbody>
</table>
- <p class="text-center float-center" align="center" style="Margin:0;Margin-bottom:10px;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:12px;font-weight:400;line-height:16px;margin:0;margin-bottom:10px;padding:0;text-align:center">%s</p>
+ <p class="text-center float-center" align="center" style="Margin:0;Margin-bottom:10px;color:#C8C8C8;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:12px;font-weight:400;line-height:16px;margin:0;margin-bottom:10px;padding:0;text-align:center">%s</p>
</center>
</td>
</tr>
</table>
EOF;
-
- public function __construct(\OC_Defaults $defaults) {
- $this->defaults = $defaults;
-
+ /**
+ * @param ThemingDefaults $themingDefaults
+ * @param IURLGenerator $urlGenerator
+ * @param IL10N $l10n
+ */
+ public function __construct(ThemingDefaults $themingDefaults,
+ IURLGenerator $urlGenerator,
+ IL10N $l10n) {
+ $this->themingDefaults = $themingDefaults;
+ $this->urlGenerator = $urlGenerator;
+ $this->l10n = $l10n;
$this->htmlBody .= $this->head;
}
/**
* Adds a header to the email
- *
- * @param string $logoUrl
*/
- public function addHeader($logoUrl) {
+ public function addHeader() {
if ($this->headerAdded) {
return;
}
$this->headerAdded = true;
- $this->htmlBody .= vsprintf($this->header, [$this->defaults->getColorPrimary(), $logoUrl]);
+ $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo()) . '?v='. $this->themingDefaults->getCacheBusterCounter();
+ $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl]);
}
/**
@@ -328,7 +341,7 @@ EOF;
$this->bodyOpened = true;
}
- $color = $this->defaults->getColorPrimary();
+ $color = $this->themingDefaults->getColorPrimary();
$this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textLeft, $urlRight, $textRight]);
$this->plainBody .= $textLeft . ': ' . $urlLeft . PHP_EOL;
$this->plainBody .= $textRight . ': ' . $urlRight . PHP_EOL . PHP_EOL;
@@ -338,10 +351,13 @@ EOF;
/**
* Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
*
- * @param string $logoUrl
* @param string $text
*/
- public function addFooter($logoUrl, $text) {
+ public function addFooter($text = '') {
+ if($text === '') {
+ $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically generated email, please do not reply.');
+ }
+
if ($this->footerAdded) {
return;
}
@@ -351,7 +367,8 @@ EOF;
$this->htmlBody .= $this->bodyEnd;
$this->bodyOpened = false;
}
- $this->htmlBody .= vsprintf($this->footer, [$logoUrl, $text]);
+
+ $this->htmlBody .= vsprintf($this->footer, [$text]);
$this->htmlBody .= $this->tail;
$this->plainBody .= '--' . PHP_EOL;
$this->plainBody .= str_replace('<br>', PHP_EOL, $text);
@@ -389,4 +406,3 @@ EOF;
return $this->plainBody;
}
}
-
diff --git a/lib/private/Mail/IEMailTemplate.php b/lib/private/Mail/IEMailTemplate.php
index 5bf2b8e4394..0d660a35516 100644
--- a/lib/private/Mail/IEMailTemplate.php
+++ b/lib/private/Mail/IEMailTemplate.php
@@ -34,7 +34,7 @@ namespace OC\Mail;
*
* $emailTemplate = new EMailTemplate($this->defaults);
*
- * $emailTemplate->addHeader('https://example.org/img/logo-mail-header.png');
+ * $emailTemplate->addHeader();
* $emailTemplate->addHeading('Welcome aboard');
* $emailTemplate->addBodyText('You have now an Nextcloud account, you can add, protect, and share your data.');
*
@@ -43,21 +43,25 @@ namespace OC\Mail;
* 'Install Client', 'https://nextcloud.com/install/#install-clients'
* );
*
- * $emailTemplate->addFooter(
- * 'https://example.org/img/logo-mail-footer.png',
- * 'Nextcloud - a safe home for your data <br>This is an automatically generated email, please do not reply.'
- * );
+ * $emailTemplate->addFooter('Optional footer text');
*
* $htmlContent = $emailTemplate->renderHTML();
* $plainContent = $emailTemplate->renderText();
*/
interface IEMailTemplate {
/**
+ * @param \OCA\Theming\ThemingDefaults $themingDefaults
+ * @param \OCP\IURLGenerator $urlGenerator
+ * @param \OCP\IL10N $l10n
+ */
+ public function __construct(\OCA\Theming\ThemingDefaults $themingDefaults,
+ \OCP\IURLGenerator $urlGenerator,
+ \OCP\IL10N $l10n);
+
+ /**
* Adds a header to the email
- *
- * @param string $logoUrl
*/
- public function addHeader($logoUrl);
+ public function addHeader();
/**
* Adds a heading to the email
@@ -86,10 +90,9 @@ interface IEMailTemplate {
/**
* Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
*
- * @param string $logoUrl
* @param string $text
*/
- public function addFooter($logoUrl, $text);
+ public function addFooter($text = '');
/**
* Returns the rendered HTML email as string
@@ -104,4 +107,4 @@ interface IEMailTemplate {
* @return string
*/
public function renderText();
-} \ No newline at end of file
+}
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 98910b097b7..0d05bfe0dc8 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -823,7 +823,7 @@ class Server extends ServerContainer implements IServerContainer {
$c->getL10N('theming'),
$c->getURLGenerator(),
new \OC_Defaults(),
- $c->getLazyRootFolder(),
+ $c->getAppDataDir('theming'),
$c->getMemCacheFactory()
);
}
@@ -1572,7 +1572,7 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
- * @return \OC_Defaults
+ * @return \OCA\Theming\ThemingDefaults
*/
public function getThemingDefaults() {
return $this->query('ThemingDefaults');