Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 01b06623 authored by AVINASH GUSAIN's avatar AVINASH GUSAIN
Browse files

Merge branch 'dev/email-template-design-fix' into 'main'

email template design fixes

See merge request e/infra/ecloud/nextcloud-apps/ecloud-theme-helper!29
parents 615a15f8 59e64bd1
Loading
Loading
Loading
Loading
Loading
+301 −234
Original line number Diff line number Diff line
@@ -4,22 +4,22 @@ namespace OCA\ECloudThemeHelper\Mail;

use OC\Mail\EMailTemplate as ParentTemplate;

class EMailTemplate extends ParentTemplate {

class EMailTemplate extends ParentTemplate
{
  protected $header = <<<EOF
<table align="center" class="container main-heading float-center" style="Margin:0 auto;background:0 0!important;border-collapse:collapse;border-spacing:0;float:none;margin-top:20px;padding:0;text-align:center;vertical-align:top;width:580px;">
<tbody>
<tr style="border: 1px solid #EAEDF2;box-sizing: border-box;height:50px;">
<tr style="border: 1px solid #EAEDF2;box-sizing: border-box;height:70px;">
<td>
<table align="center" class="container main-heading float-center" style="Margin:0 auto;background:0 0!important;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:580px">
<tbody>
<tr style="padding:0;text-align:left;vertical-align:top">
    <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
        <img class="logo float-center" src="%s" alt="%s" align="center" style="-ms-interpolation-mode:bicubic;clear:both;display:block;float:left;margin:0 auto;outline:0;text-align:center;text-decoration:none;max-height:105px;max-width:105px;width:auto;padding-top:4px;margin-left:10px;">
        <img class="logo float-center" src="%s" alt="%s" align="center" style="-ms-interpolation-mode:bicubic;clear:both;display:block;float:right;margin:0 auto;outline:0;text-align:center;text-decoration:none;max-height:105px;max-width:105px;width:auto;padding-top:4px;margin-left:10px;padding-right:30px">
EOF;

  protected $heading = <<<EOF
<h1 class="text-center" style="Margin:0;Margin-bottom:10px;color:inherit;font-family:arial;font-size:24px;font-weight:400;color:#000000;line-height:1.3;margin:0;padding:0;text-align:center;word-wrap:normal;padding-right:105px;">%s</h1>
<h1 class="text-center" style="Margin:0;Margin-bottom:10px;color:inherit;font-family:arial;font-size:24px;font-weight:400;color:#000000;line-height:1.3;margin:0;padding:0;text-align:left;word-wrap:normal;padding-right:135px;padding-left:40px;">%s</h1>
    </td>
</tr>
</tbody>
@@ -33,8 +33,8 @@ protected $bodyBegin = <<<EOF
<td>
<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">
		<td height="36px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-size:40px;font-weight:400;hyphens:auto;line-height:36px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
	<tr style="padding:0;text-align:left;vertical-align:top;height: 84px;">
		<td height="36px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-size:40px;font-weight:400;hyphens:auto;line-height:36px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:middle;word-wrap:break-word">&#xA0;</td>
	</tr>
	</tbody>
</table>
@@ -43,7 +43,7 @@ protected $bodyBegin = <<<EOF
    <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
        <table align="center" class="container" style="Margin:0 auto;background:#fff;border-collapse:collapse;border-spacing:0;margin:0 auto;padding:0;text-align:inherit;vertical-align:top;width:580px">
            <tbody>
            <tr style="padding:0;text-align:left;vertical-align:top">
            <tr style="padding:0;text-align:left;vertical-align:top;">
                <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
EOF;

@@ -53,17 +53,11 @@ protected $bannerHeading = <<<EOF
<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">
		<td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-size:40px;font-weight:400;hyphens:auto;line-height:36px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word;background:%s;font-size:18px;text-align:center;font-weight:500;color:%s">%s</td>
	</tr>
	</tbody>
</table>
<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">
		<td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-size:40px;font-weight:400;hyphens:auto;line-height:36px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
		<td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-size:40px;font-weight:400;hyphens:auto;line-height:23px;margin:0;mso-line-height-rule:exactly;padding:30px 30px 30px 40px;text-align:left;vertical-align:top;word-wrap:break-word;background:%s;font-size:18px;font-weight:500;color:%s">%s</td>
	</tr>
	</tbody>
</table>
</td></tr>
EOF;

  protected $buttonGrouptentative = <<<EOF
@@ -100,8 +94,8 @@ protected $buttonGrouptentative = <<<EOF
									<td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
										<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:#ffffff;border:0 solid #0086FF;border-collapse:collapse!important;color:#fefefe;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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="%10\$s" style="Margin:0;background-color:#ffffff;border:0 solid #0086FF;border-radius:2px;color:#0086FF!important;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;outline:1px solid #0086FF;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">%11\$s</a>
												<td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:#ffffff;border:0 solid #666666;border-collapse:collapse!important;color:#fefefe;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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="%10\$s" style="Margin:0;background-color:#ffffff;border:0 solid #666666;border-radius:2px;color:#666666!important;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;outline:1px solid #666666;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">%11\$s</a>
												</td>
											</tr>
										</table>
@@ -113,8 +107,8 @@ protected $buttonGrouptentative = <<<EOF
									<td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
										<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:#ffffff;border:0 solid #0086FF;border-collapse:collapse!important;color:#fefefe;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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="%8\$s" style="Margin:0;background-color:#ffffff;border:0 solid #6C757D;border-radius:2px;color:#0086FF!important;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;outline:1px solid #0086FF;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">%9\$s</a>
												<td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:#ffffff;border:0 solid #666666;border-collapse:collapse!important;color:#fefefe;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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="%8\$s" style="Margin:0;background-color:#ffffff;border:0 solid #666666;border-radius:2px;color:#666666!important;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;outline:1px solid #666666;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">%9\$s</a>
												</td>
											</tr>
										</table>
@@ -134,26 +128,42 @@ EOF;
  /**
   * Adds a header to the email
   */
	public function addHeader() {
  public function addHeader()
  {
    if ($this->headerAdded) {
      return;
    }
    $this->headerAdded = true;

		$logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false));
		$logoMailUrl = str_replace('logo.png','logomail.png',$logoUrl);
		$this->htmlBody .= vsprintf($this->header, [$logoMailUrl, $this->themingDefaults->getName()]);
    $logoUrl = $this->urlGenerator->getAbsoluteURL(
      $this->themingDefaults->getLogo(false)
    );
    $logoMailUrl = str_replace("logo.png", "logomail.png", $logoUrl);
    $this->htmlBody .= vsprintf($this->header, [
      $logoMailUrl,
      $this->themingDefaults->getName(),
    ]);
  }

  /**
   * Adds a header banner
   */
	public function addHeadingBanner(string $bgcolor,string $fontcolor,string $text, $plainText = '') {
		$this->htmlBody .= vsprintf($this->bannerHeading, [$bgcolor,$fontcolor,$text]);
  public function addHeadingBanner(
    string $bgcolor,
    string $fontcolor,
    string $text,
    $plainText = ""
  ) {
    $this->htmlBody .= vsprintf($this->bannerHeading, [
      $bgcolor,
      $fontcolor,
      $text,
    ]);
    if ($plainText !== false) {
      $this->plainBody .= $plainText . PHP_EOL . PHP_EOL;
    }
		$this->bodyOpened = true;
    //$this->bodyOpened = true;
	$this->ensureBodyListOpened();
  }

  /**
@@ -169,27 +179,41 @@ EOF;
   * @param integer plainIndent If > 0, Indent plainText by this amount.
   * @since 12.0.0
   */
	public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = '', $plainIndent = 0) {
  public function addBodyListItem(
    string $text,
    string $metaInfo = "",
    string $icon = "",
    $plainText = "",
    $plainMetaInfo = "",
    $plainIndent = 0
  ) {
    $this->ensureBodyListOpened();

		if ($plainText === '' || $plainText === true) {
    if ($plainText === "" || $plainText === true) {
      $plainText = $text;
      $text = htmlspecialchars($text);
      $text = str_replace("\n", "<br/>", $text); // convert newlines to HTML breaks
    }
		if ($plainMetaInfo === '' || $plainMetaInfo === true) {
    if ($plainMetaInfo === "" || $plainMetaInfo === true) {
      $plainMetaInfo = $metaInfo;
      $metaInfo = htmlspecialchars($metaInfo);
    }

    $htmlText = $text;
    if ($metaInfo) {
			$htmlText = '<span style="color:#777;font-weight:700;">' . $metaInfo . ' </span>  '. $htmlText;
      $htmlText =
        '<span style="color:#777;font-weight:700;">' .
        $metaInfo .
        " </span>  " .
        $htmlText;
    }
		if ($icon !== '') {
			$icon = '<img style="padding-top: 3px;" src="' . htmlspecialchars($icon) . '" alt="&bull;">';
    if ($icon !== "") {
      $icon =
        '<span style="display:block;width:16px;padding-bottom:25px;"><img style="padding-top: 3px;" src="' .
        htmlspecialchars($icon) .
        '" alt="&bull;"></span>';
    } else {
			$icon = '&bull;';
      $icon = "&bull;";
    }

    $this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]);
@@ -198,9 +222,9 @@ EOF;
        /*
         * If plainIndent is not set by caller, this is the old NC17 layout code.
         */
				$this->plainBody .= '  * ' . $plainText;
        $this->plainBody .= "  * " . $plainText;
        if ($plainMetaInfo !== false) {
					$this->plainBody .= ' (' . $plainMetaInfo . ')';
          $this->plainBody .= " (" . $plainMetaInfo . ")";
        }
        $this->plainBody .= PHP_EOL;
      } else {
@@ -212,10 +236,16 @@ EOF;
         * (to account for space after label).  Fixes: #12391
         */
        /** @var string $label */
				$label = ($plainMetaInfo !== false)? $plainMetaInfo : '';
				$this->plainBody .= sprintf("%${plainIndent}s %s\n",
        $label = $plainMetaInfo !== false ? $plainMetaInfo : "";
        $this->plainBody .= sprintf(
          "%${plainIndent}s %s\n",
          $label,
					str_replace("\n", "\n" . str_repeat(' ', $plainIndent + 1), $plainText));
          str_replace(
            "\n",
            "\n" . str_repeat(" ", $plainIndent + 1),
            $plainText
          )
        );
      }
    }
  }
@@ -232,27 +262,41 @@ EOF;
   * @param integer plainIndent If > 0, Indent plainText by this amount.
   * @since 12.0.0
   */
	public function addBodyListItemModified(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = '', $plainIndent = 0) {
  public function addBodyListItemModified(
    string $text,
    string $metaInfo = "",
    string $icon = "",
    $plainText = "",
    $plainMetaInfo = "",
    $plainIndent = 0
  ) {
    $this->ensureBodyListOpened();

		if ($plainText === '' || $plainText === true) {
    if ($plainText === "" || $plainText === true) {
      $plainText = $text;
      $text = htmlspecialchars($text);
      $text = str_replace("\n", "<br/>", $text); // convert newlines to HTML breaks
    }
		if ($plainMetaInfo === '' || $plainMetaInfo === true) {
    if ($plainMetaInfo === "" || $plainMetaInfo === true) {
      $plainMetaInfo = $metaInfo;
      $metaInfo = htmlspecialchars($metaInfo);
    }

    $htmlText = $text;
    if ($metaInfo) {
			$htmlText = '<span style="color:#6CA91C;font-weight:700;">' . $metaInfo . ' </span>  '. $htmlText;
      $htmlText =
        '<span style="color:#6CA91C;font-weight:700;">' .
        $metaInfo .
        " </span>  " .
        $htmlText;
    }
		if ($icon !== '') {
			$icon = '<img style="padding-top: 3px;" src="' . htmlspecialchars($icon) . '" alt="&bull;">';
    if ($icon !== "") {
      $icon =
        '<span style="display:block;width:16px;padding-bottom:25px;"><img style="padding-top: 3px;" src="' .
        htmlspecialchars($icon) .
        '" alt="&bull;"></span>';
    } else {
			$icon = '&bull;';
      $icon = "&bull;";
    }

    $this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]);
@@ -261,9 +305,9 @@ EOF;
        /*
         * If plainIndent is not set by caller, this is the old NC17 layout code.
         */
				$this->plainBody .= '  * ' . $plainText;
        $this->plainBody .= "  * " . $plainText;
        if ($plainMetaInfo !== false) {
					$this->plainBody .= ' (' . $plainMetaInfo . ')';
          $this->plainBody .= " (" . $plainMetaInfo . ")";
        }
        $this->plainBody .= PHP_EOL;
      } else {
@@ -275,10 +319,16 @@ EOF;
         * (to account for space after label).  Fixes: #12391
         */
        /** @var string $label */
				$label = ($plainMetaInfo !== false)? $plainMetaInfo : '';
				$this->plainBody .= sprintf("%${plainIndent}s %s\n",
        $label = $plainMetaInfo !== false ? $plainMetaInfo : "";
        $this->plainBody .= sprintf(
          "%${plainIndent}s %s\n",
          $label,
					str_replace("\n", "\n" . str_repeat(' ', $plainIndent + 1), $plainText));
          str_replace(
            "\n",
            "\n" . str_repeat(" ", $plainIndent + 1),
            $plainText
          )
        );
      }
    }
  }
@@ -289,19 +339,23 @@ EOF;
   * @param string|bool $plainText Text that is used in the plain text email
   *   if empty the $text is used, if false none will be used
   */
	public function addBodyText(string $text, $plainText = '') {
  public function addBodyText(string $text, $plainText = "")
  {
    if ($this->footerAdded) {
      return;
    }

		if ($plainText === '') {
    if ($plainText === "") {
      $plainText = $text;
      $text = htmlspecialchars($text);
    }
    $text = str_replace("…", "", $text);
    $text = str_replace("...", "", $text);
		$text=str_replace('<a href=','<a style="text-decoration: none;color: #007BFF;font-size: 18px;" href=',$text);

    $text = str_replace(
      "<a href=",
      '<a style="text-decoration: none;color: #007BFF;font-size: 18px;" href=',
      $text
    );

    $this->ensureBodyListClosed();
    $this->ensureBodyIsOpened();
@@ -323,23 +377,25 @@ EOF;
   * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used
   * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used
   */
	public function addBodyButtonGroupTentative(string $textLeft,
  public function addBodyButtonGroupTentative(
    string $textLeft,
    string $urlLeft,
    string $textRight,
    string $urlRight,
    string $textCenter,
    string $urlCenter,
									   string $plainTextLeft = '',
									   string $plainTextRight = '') {
    string $plainTextLeft = "",
    string $plainTextRight = ""
  ) {
    if ($this->footerAdded) {
      return;
    }
		if ($plainTextLeft === '') {
    if ($plainTextLeft === "") {
      $plainTextLeft = $textLeft;
      $textLeft = htmlspecialchars($textLeft);
    }

		if ($plainTextRight === '') {
    if ($plainTextRight === "") {
      $plainTextRight = $textRight;
      $textRight = htmlspecialchars($textRight);
    }
@@ -347,12 +403,23 @@ EOF;
    $this->ensureBodyIsOpened();
    $this->ensureBodyListClosed();

		$color = $this->themingDefaults->getColorPrimary();
    $color = '#5996F2';
    $textColor = $this->themingDefaults->getTextColorPrimary();

		$this->htmlBody .= vsprintf($this->buttonGrouptentative, [$color, $color, $urlLeft, $color, $textColor, $textColor, $textLeft, $urlRight, $textRight, $urlCenter, $textCenter]);
		$this->plainBody .= PHP_EOL . $plainTextLeft . ': ' . $urlLeft . PHP_EOL;
		$this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL;
    $this->htmlBody .= vsprintf($this->buttonGrouptentative, [
      $color,
      $color,
      $urlLeft,
      $color,
      $textColor,
      $textColor,
      $textLeft,
      $urlRight,
      $textRight,
      $urlCenter,
      $textCenter,
    ]);
    $this->plainBody .= PHP_EOL . $plainTextLeft . ": " . $urlLeft . PHP_EOL;
    $this->plainBody .= $plainTextRight . ": " . $urlRight . PHP_EOL . PHP_EOL;
  }

}
 No newline at end of file