@@ -42,33 +42,33 @@ discard block |
||
| 42 | 42 | * @package OC\Mail |
| 43 | 43 | */ |
| 44 | 44 | class EMailTemplate implements IEMailTemplate { |
| 45 | - /** @var Defaults */ |
|
| 46 | - protected $themingDefaults; |
|
| 47 | - /** @var IURLGenerator */ |
|
| 48 | - protected $urlGenerator; |
|
| 49 | - /** @var IL10N */ |
|
| 50 | - protected $l10n; |
|
| 51 | - /** @var string */ |
|
| 52 | - protected $emailId; |
|
| 53 | - /** @var array */ |
|
| 54 | - protected $data; |
|
| 55 | - |
|
| 56 | - /** @var string */ |
|
| 57 | - protected $subject = ''; |
|
| 58 | - /** @var string */ |
|
| 59 | - protected $htmlBody = ''; |
|
| 60 | - /** @var string */ |
|
| 61 | - protected $plainBody = ''; |
|
| 62 | - /** @var bool indicated if the footer is added */ |
|
| 63 | - protected $headerAdded = false; |
|
| 64 | - /** @var bool indicated if the body is already opened */ |
|
| 65 | - protected $bodyOpened = false; |
|
| 66 | - /** @var bool indicated if there is a list open in the body */ |
|
| 67 | - protected $bodyListOpened = false; |
|
| 68 | - /** @var bool indicated if the footer is added */ |
|
| 69 | - protected $footerAdded = false; |
|
| 70 | - |
|
| 71 | - protected $head = <<<EOF |
|
| 45 | + /** @var Defaults */ |
|
| 46 | + protected $themingDefaults; |
|
| 47 | + /** @var IURLGenerator */ |
|
| 48 | + protected $urlGenerator; |
|
| 49 | + /** @var IL10N */ |
|
| 50 | + protected $l10n; |
|
| 51 | + /** @var string */ |
|
| 52 | + protected $emailId; |
|
| 53 | + /** @var array */ |
|
| 54 | + protected $data; |
|
| 55 | + |
|
| 56 | + /** @var string */ |
|
| 57 | + protected $subject = ''; |
|
| 58 | + /** @var string */ |
|
| 59 | + protected $htmlBody = ''; |
|
| 60 | + /** @var string */ |
|
| 61 | + protected $plainBody = ''; |
|
| 62 | + /** @var bool indicated if the footer is added */ |
|
| 63 | + protected $headerAdded = false; |
|
| 64 | + /** @var bool indicated if the body is already opened */ |
|
| 65 | + protected $bodyOpened = false; |
|
| 66 | + /** @var bool indicated if there is a list open in the body */ |
|
| 67 | + protected $bodyListOpened = false; |
|
| 68 | + /** @var bool indicated if the footer is added */ |
|
| 69 | + protected $footerAdded = false; |
|
| 70 | + |
|
| 71 | + protected $head = <<<EOF |
|
| 72 | 72 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 73 | 73 | <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#f3f3f3!important"> |
| 74 | 74 | <head> |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | <center data-parsed="" style="min-width:580px;width:100%"> |
| 87 | 87 | EOF; |
| 88 | 88 | |
| 89 | - protected $tail = <<<EOF |
|
| 89 | + protected $tail = <<<EOF |
|
| 90 | 90 | </center> |
| 91 | 91 | </td> |
| 92 | 92 | </tr> |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | </html> |
| 98 | 98 | EOF; |
| 99 | 99 | |
| 100 | - protected $header = <<<EOF |
|
| 100 | + protected $header = <<<EOF |
|
| 101 | 101 | <table align="center" class="wrapper header float-center" style="Margin:0 auto;background:#8a8a8a;background-color:%s;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%"> |
| 102 | 102 | <tr style="padding:0;text-align:left;vertical-align:top"> |
| 103 | 103 | <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:20px;text-align:left;vertical-align:top;word-wrap:break-word"> |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | </table> |
| 131 | 131 | EOF; |
| 132 | 132 | |
| 133 | - protected $heading = <<<EOF |
|
| 133 | + protected $heading = <<<EOF |
|
| 134 | 134 | <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"> |
| 135 | 135 | <tbody> |
| 136 | 136 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | </table> |
| 150 | 150 | EOF; |
| 151 | 151 | |
| 152 | - protected $bodyBegin = <<<EOF |
|
| 152 | + protected $bodyBegin = <<<EOF |
|
| 153 | 153 | <table align="center" class="wrapper content 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%"> |
| 154 | 154 | <tr style="padding:0;text-align:left;vertical-align:top"> |
| 155 | 155 | <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"> |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | </table> |
| 167 | 167 | EOF; |
| 168 | 168 | |
| 169 | - protected $bodyText = <<<EOF |
|
| 169 | + protected $bodyText = <<<EOF |
|
| 170 | 170 | <table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%%"> |
| 171 | 171 | <tbody> |
| 172 | 172 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -185,8 +185,8 @@ discard block |
||
| 185 | 185 | </table> |
| 186 | 186 | EOF; |
| 187 | 187 | |
| 188 | - // note: listBegin (like bodyBegin) is not processed through sprintf, so "%" is not escaped as "%%". (bug #12151) |
|
| 189 | - protected $listBegin = <<<EOF |
|
| 188 | + // note: listBegin (like bodyBegin) is not processed through sprintf, so "%" is not escaped as "%%". (bug #12151) |
|
| 189 | + protected $listBegin = <<<EOF |
|
| 190 | 190 | <table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%"> |
| 191 | 191 | <tbody> |
| 192 | 192 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%"> |
| 195 | 195 | EOF; |
| 196 | 196 | |
| 197 | - protected $listItem = <<<EOF |
|
| 197 | + protected $listItem = <<<EOF |
|
| 198 | 198 | <tr style="padding:0;text-align:left;vertical-align:top"> |
| 199 | 199 | <td style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left;width:15px;"> |
| 200 | 200 | <p class="text-left" style="Margin:0;Margin-bottom:10px;color:#777;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;padding-left:10px;text-align:left">%s</p> |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | </tr> |
| 207 | 207 | EOF; |
| 208 | 208 | |
| 209 | - protected $listEnd = <<<EOF |
|
| 209 | + protected $listEnd = <<<EOF |
|
| 210 | 210 | </table> |
| 211 | 211 | </th> |
| 212 | 212 | </tr> |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | </table> |
| 215 | 215 | EOF; |
| 216 | 216 | |
| 217 | - protected $buttonGroup = <<<EOF |
|
| 217 | + protected $buttonGroup = <<<EOF |
|
| 218 | 218 | <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%"> |
| 219 | 219 | <tbody> |
| 220 | 220 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | </table> |
| 268 | 268 | EOF; |
| 269 | 269 | |
| 270 | - protected $button = <<<EOF |
|
| 270 | + protected $button = <<<EOF |
|
| 271 | 271 | <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%"> |
| 272 | 272 | <tbody> |
| 273 | 273 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | </table> |
| 308 | 308 | EOF; |
| 309 | 309 | |
| 310 | - protected $bodyEnd = <<<EOF |
|
| 310 | + protected $bodyEnd = <<<EOF |
|
| 311 | 311 | |
| 312 | 312 | </td> |
| 313 | 313 | </tr> |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | </table> |
| 319 | 319 | EOF; |
| 320 | 320 | |
| 321 | - protected $footer = <<<EOF |
|
| 321 | + protected $footer = <<<EOF |
|
| 322 | 322 | <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%%"> |
| 323 | 323 | <tbody> |
| 324 | 324 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -344,314 +344,314 @@ discard block |
||
| 344 | 344 | </table> |
| 345 | 345 | EOF; |
| 346 | 346 | |
| 347 | - /** |
|
| 348 | - * @param Defaults $themingDefaults |
|
| 349 | - * @param IURLGenerator $urlGenerator |
|
| 350 | - * @param IL10N $l10n |
|
| 351 | - * @param string $emailId |
|
| 352 | - * @param array $data |
|
| 353 | - */ |
|
| 354 | - public function __construct(Defaults $themingDefaults, |
|
| 355 | - IURLGenerator $urlGenerator, |
|
| 356 | - IL10N $l10n, |
|
| 357 | - $emailId, |
|
| 358 | - array $data) { |
|
| 359 | - $this->themingDefaults = $themingDefaults; |
|
| 360 | - $this->urlGenerator = $urlGenerator; |
|
| 361 | - $this->l10n = $l10n; |
|
| 362 | - $this->htmlBody .= $this->head; |
|
| 363 | - $this->emailId = $emailId; |
|
| 364 | - $this->data = $data; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * Sets the subject of the email |
|
| 369 | - * |
|
| 370 | - * @param string $subject |
|
| 371 | - */ |
|
| 372 | - public function setSubject(string $subject) { |
|
| 373 | - $this->subject = $subject; |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Adds a header to the email |
|
| 378 | - */ |
|
| 379 | - public function addHeader() { |
|
| 380 | - if ($this->headerAdded) { |
|
| 381 | - return; |
|
| 382 | - } |
|
| 383 | - $this->headerAdded = true; |
|
| 384 | - |
|
| 385 | - $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false)); |
|
| 386 | - $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl, $this->themingDefaults->getName()]); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * Adds a heading to the email |
|
| 391 | - * |
|
| 392 | - * @param string $title |
|
| 393 | - * @param string|bool $plainTitle Title that is used in the plain text email |
|
| 394 | - * if empty the $title is used, if false none will be used |
|
| 395 | - */ |
|
| 396 | - public function addHeading(string $title, $plainTitle = '') { |
|
| 397 | - if ($this->footerAdded) { |
|
| 398 | - return; |
|
| 399 | - } |
|
| 400 | - if ($plainTitle === '') { |
|
| 401 | - $plainTitle = $title; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]); |
|
| 405 | - if ($plainTitle !== false) { |
|
| 406 | - $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL; |
|
| 407 | - } |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * Open the HTML body when it is not already |
|
| 412 | - */ |
|
| 413 | - protected function ensureBodyIsOpened() { |
|
| 414 | - if ($this->bodyOpened) { |
|
| 415 | - return; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - $this->htmlBody .= $this->bodyBegin; |
|
| 419 | - $this->bodyOpened = true; |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Adds a paragraph to the body of the email |
|
| 424 | - * |
|
| 425 | - * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 426 | - * @param string|bool $plainText Text that is used in the plain text email |
|
| 427 | - * if empty the $text is used, if false none will be used |
|
| 428 | - */ |
|
| 429 | - public function addBodyText(string $text, $plainText = '') { |
|
| 430 | - if ($this->footerAdded) { |
|
| 431 | - return; |
|
| 432 | - } |
|
| 433 | - if ($plainText === '') { |
|
| 434 | - $plainText = $text; |
|
| 435 | - $text = htmlspecialchars($text); |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - $this->ensureBodyIsOpened(); |
|
| 439 | - |
|
| 440 | - $this->htmlBody .= vsprintf($this->bodyText, [$text]); |
|
| 441 | - if ($plainText !== false) { |
|
| 442 | - $this->plainBody .= $plainText . PHP_EOL . PHP_EOL; |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - /** |
|
| 447 | - * Adds a list item to the body of the email |
|
| 448 | - * |
|
| 449 | - * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 450 | - * @param string $metaInfo Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email |
|
| 451 | - * @param string $icon Absolute path, must be 16*16 pixels |
|
| 452 | - * @param string|bool $plainText Text that is used in the plain text email |
|
| 453 | - * if empty the $text is used, if false none will be used |
|
| 454 | - * @param string|bool $plainMetaInfo Meta info that is used in the plain text email |
|
| 455 | - * if empty the $metaInfo is used, if false none will be used |
|
| 456 | - * @since 12.0.0 |
|
| 457 | - */ |
|
| 458 | - public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = '') { |
|
| 459 | - $this->ensureBodyListOpened(); |
|
| 460 | - |
|
| 461 | - if ($plainText === '') { |
|
| 462 | - $plainText = $text; |
|
| 463 | - $text = htmlspecialchars($text); |
|
| 464 | - } |
|
| 465 | - if ($plainMetaInfo === '') { |
|
| 466 | - $plainMetaInfo = $metaInfo; |
|
| 467 | - $metaInfo = htmlspecialchars($metaInfo); |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - $htmlText = $text; |
|
| 471 | - if ($metaInfo) { |
|
| 472 | - $htmlText = '<em style="color:#777;">' . $metaInfo . '</em><br>' . $htmlText; |
|
| 473 | - } |
|
| 474 | - if ($icon !== '') { |
|
| 475 | - $icon = '<img src="' . htmlspecialchars($icon) . '" alt="•">'; |
|
| 476 | - } else { |
|
| 477 | - $icon = '•'; |
|
| 478 | - } |
|
| 479 | - $this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]); |
|
| 480 | - if ($plainText !== false) { |
|
| 481 | - $this->plainBody .= ' * ' . $plainText; |
|
| 482 | - if ($plainMetaInfo !== false) { |
|
| 483 | - $this->plainBody .= ' (' . $plainMetaInfo . ')'; |
|
| 484 | - } |
|
| 485 | - $this->plainBody .= PHP_EOL; |
|
| 486 | - } |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - protected function ensureBodyListOpened() { |
|
| 490 | - if ($this->bodyListOpened) { |
|
| 491 | - return; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - $this->ensureBodyIsOpened(); |
|
| 495 | - $this->bodyListOpened = true; |
|
| 496 | - $this->htmlBody .= $this->listBegin; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - protected function ensureBodyListClosed() { |
|
| 500 | - if (!$this->bodyListOpened) { |
|
| 501 | - return; |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - $this->bodyListOpened = false; |
|
| 505 | - $this->htmlBody .= $this->listEnd; |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * Adds a button group of two buttons to the body of the email |
|
| 510 | - * |
|
| 511 | - * @param string $textLeft Text of left button; Note: When $plainTextLeft falls back to this, HTML is automatically escaped in the HTML email |
|
| 512 | - * @param string $urlLeft URL of left button |
|
| 513 | - * @param string $textRight Text of right button; Note: When $plainTextRight falls back to this, HTML is automatically escaped in the HTML email |
|
| 514 | - * @param string $urlRight URL of right button |
|
| 515 | - * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used |
|
| 516 | - * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used |
|
| 517 | - */ |
|
| 518 | - public function addBodyButtonGroup(string $textLeft, |
|
| 519 | - string $urlLeft, |
|
| 520 | - string $textRight, |
|
| 521 | - string $urlRight, |
|
| 522 | - string $plainTextLeft = '', |
|
| 523 | - string $plainTextRight = '') { |
|
| 524 | - if ($this->footerAdded) { |
|
| 525 | - return; |
|
| 526 | - } |
|
| 527 | - if ($plainTextLeft === '') { |
|
| 528 | - $plainTextLeft = $textLeft; |
|
| 529 | - $textLeft = htmlspecialchars($textLeft); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - if ($plainTextRight === '') { |
|
| 533 | - $plainTextRight = $textRight; |
|
| 534 | - $textRight = htmlspecialchars($textRight); |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - $this->ensureBodyIsOpened(); |
|
| 538 | - $this->ensureBodyListClosed(); |
|
| 539 | - |
|
| 540 | - $color = $this->themingDefaults->getColorPrimary(); |
|
| 541 | - $textColor = $this->themingDefaults->getTextColorPrimary(); |
|
| 542 | - |
|
| 543 | - $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textColor, $textColor, $textLeft, $urlRight, $textRight]); |
|
| 544 | - $this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL; |
|
| 545 | - $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; |
|
| 546 | - |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Adds a button to the body of the email |
|
| 551 | - * |
|
| 552 | - * @param string $text Text of button; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 553 | - * @param string $url URL of button |
|
| 554 | - * @param string $plainText Text of button in plain text version |
|
| 555 | - * if empty the $text is used, if false none will be used |
|
| 556 | - * |
|
| 557 | - * @since 12.0.0 |
|
| 558 | - */ |
|
| 559 | - public function addBodyButton(string $text, string $url, $plainText = '') { |
|
| 560 | - if ($this->footerAdded) { |
|
| 561 | - return; |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - $this->ensureBodyIsOpened(); |
|
| 565 | - $this->ensureBodyListClosed(); |
|
| 566 | - |
|
| 567 | - if ($plainText === '') { |
|
| 568 | - $plainText = $text; |
|
| 569 | - $text = htmlspecialchars($text); |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - $color = $this->themingDefaults->getColorPrimary(); |
|
| 573 | - $textColor = $this->themingDefaults->getTextColorPrimary(); |
|
| 574 | - $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, $textColor, $textColor, $text]); |
|
| 575 | - |
|
| 576 | - if ($plainText !== false) { |
|
| 577 | - $this->plainBody .= $plainText . ': '; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - $this->plainBody .= $url . PHP_EOL; |
|
| 581 | - |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - /** |
|
| 585 | - * Close the HTML body when it is open |
|
| 586 | - */ |
|
| 587 | - protected function ensureBodyIsClosed() { |
|
| 588 | - if (!$this->bodyOpened) { |
|
| 589 | - return; |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - $this->ensureBodyListClosed(); |
|
| 593 | - |
|
| 594 | - $this->htmlBody .= $this->bodyEnd; |
|
| 595 | - $this->bodyOpened = false; |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - /** |
|
| 599 | - * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
| 600 | - * |
|
| 601 | - * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used |
|
| 602 | - */ |
|
| 603 | - public function addFooter(string $text = '') { |
|
| 604 | - if($text === '') { |
|
| 605 | - $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically sent email, please do not reply.'); |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - if ($this->footerAdded) { |
|
| 609 | - return; |
|
| 610 | - } |
|
| 611 | - $this->footerAdded = true; |
|
| 612 | - |
|
| 613 | - $this->ensureBodyIsClosed(); |
|
| 614 | - |
|
| 615 | - $this->htmlBody .= vsprintf($this->footer, [$text]); |
|
| 616 | - $this->htmlBody .= $this->tail; |
|
| 617 | - $this->plainBody .= PHP_EOL . '-- ' . PHP_EOL; |
|
| 618 | - $this->plainBody .= str_replace('<br>', PHP_EOL, $text); |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * Returns the rendered email subject as string |
|
| 623 | - * |
|
| 624 | - * @return string |
|
| 625 | - */ |
|
| 626 | - public function renderSubject(): string { |
|
| 627 | - return $this->subject; |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - /** |
|
| 631 | - * Returns the rendered HTML email as string |
|
| 632 | - * |
|
| 633 | - * @return string |
|
| 634 | - */ |
|
| 635 | - public function renderHtml(): string { |
|
| 636 | - if (!$this->footerAdded) { |
|
| 637 | - $this->footerAdded = true; |
|
| 638 | - $this->ensureBodyIsClosed(); |
|
| 639 | - $this->htmlBody .= $this->tail; |
|
| 640 | - } |
|
| 641 | - return $this->htmlBody; |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - /** |
|
| 645 | - * Returns the rendered plain text email as string |
|
| 646 | - * |
|
| 647 | - * @return string |
|
| 648 | - */ |
|
| 649 | - public function renderText(): string { |
|
| 650 | - if (!$this->footerAdded) { |
|
| 651 | - $this->footerAdded = true; |
|
| 652 | - $this->ensureBodyIsClosed(); |
|
| 653 | - $this->htmlBody .= $this->tail; |
|
| 654 | - } |
|
| 655 | - return $this->plainBody; |
|
| 656 | - } |
|
| 347 | + /** |
|
| 348 | + * @param Defaults $themingDefaults |
|
| 349 | + * @param IURLGenerator $urlGenerator |
|
| 350 | + * @param IL10N $l10n |
|
| 351 | + * @param string $emailId |
|
| 352 | + * @param array $data |
|
| 353 | + */ |
|
| 354 | + public function __construct(Defaults $themingDefaults, |
|
| 355 | + IURLGenerator $urlGenerator, |
|
| 356 | + IL10N $l10n, |
|
| 357 | + $emailId, |
|
| 358 | + array $data) { |
|
| 359 | + $this->themingDefaults = $themingDefaults; |
|
| 360 | + $this->urlGenerator = $urlGenerator; |
|
| 361 | + $this->l10n = $l10n; |
|
| 362 | + $this->htmlBody .= $this->head; |
|
| 363 | + $this->emailId = $emailId; |
|
| 364 | + $this->data = $data; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * Sets the subject of the email |
|
| 369 | + * |
|
| 370 | + * @param string $subject |
|
| 371 | + */ |
|
| 372 | + public function setSubject(string $subject) { |
|
| 373 | + $this->subject = $subject; |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Adds a header to the email |
|
| 378 | + */ |
|
| 379 | + public function addHeader() { |
|
| 380 | + if ($this->headerAdded) { |
|
| 381 | + return; |
|
| 382 | + } |
|
| 383 | + $this->headerAdded = true; |
|
| 384 | + |
|
| 385 | + $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false)); |
|
| 386 | + $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl, $this->themingDefaults->getName()]); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * Adds a heading to the email |
|
| 391 | + * |
|
| 392 | + * @param string $title |
|
| 393 | + * @param string|bool $plainTitle Title that is used in the plain text email |
|
| 394 | + * if empty the $title is used, if false none will be used |
|
| 395 | + */ |
|
| 396 | + public function addHeading(string $title, $plainTitle = '') { |
|
| 397 | + if ($this->footerAdded) { |
|
| 398 | + return; |
|
| 399 | + } |
|
| 400 | + if ($plainTitle === '') { |
|
| 401 | + $plainTitle = $title; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]); |
|
| 405 | + if ($plainTitle !== false) { |
|
| 406 | + $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL; |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Open the HTML body when it is not already |
|
| 412 | + */ |
|
| 413 | + protected function ensureBodyIsOpened() { |
|
| 414 | + if ($this->bodyOpened) { |
|
| 415 | + return; |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + $this->htmlBody .= $this->bodyBegin; |
|
| 419 | + $this->bodyOpened = true; |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Adds a paragraph to the body of the email |
|
| 424 | + * |
|
| 425 | + * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 426 | + * @param string|bool $plainText Text that is used in the plain text email |
|
| 427 | + * if empty the $text is used, if false none will be used |
|
| 428 | + */ |
|
| 429 | + public function addBodyText(string $text, $plainText = '') { |
|
| 430 | + if ($this->footerAdded) { |
|
| 431 | + return; |
|
| 432 | + } |
|
| 433 | + if ($plainText === '') { |
|
| 434 | + $plainText = $text; |
|
| 435 | + $text = htmlspecialchars($text); |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + $this->ensureBodyIsOpened(); |
|
| 439 | + |
|
| 440 | + $this->htmlBody .= vsprintf($this->bodyText, [$text]); |
|
| 441 | + if ($plainText !== false) { |
|
| 442 | + $this->plainBody .= $plainText . PHP_EOL . PHP_EOL; |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + /** |
|
| 447 | + * Adds a list item to the body of the email |
|
| 448 | + * |
|
| 449 | + * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 450 | + * @param string $metaInfo Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email |
|
| 451 | + * @param string $icon Absolute path, must be 16*16 pixels |
|
| 452 | + * @param string|bool $plainText Text that is used in the plain text email |
|
| 453 | + * if empty the $text is used, if false none will be used |
|
| 454 | + * @param string|bool $plainMetaInfo Meta info that is used in the plain text email |
|
| 455 | + * if empty the $metaInfo is used, if false none will be used |
|
| 456 | + * @since 12.0.0 |
|
| 457 | + */ |
|
| 458 | + public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = '') { |
|
| 459 | + $this->ensureBodyListOpened(); |
|
| 460 | + |
|
| 461 | + if ($plainText === '') { |
|
| 462 | + $plainText = $text; |
|
| 463 | + $text = htmlspecialchars($text); |
|
| 464 | + } |
|
| 465 | + if ($plainMetaInfo === '') { |
|
| 466 | + $plainMetaInfo = $metaInfo; |
|
| 467 | + $metaInfo = htmlspecialchars($metaInfo); |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + $htmlText = $text; |
|
| 471 | + if ($metaInfo) { |
|
| 472 | + $htmlText = '<em style="color:#777;">' . $metaInfo . '</em><br>' . $htmlText; |
|
| 473 | + } |
|
| 474 | + if ($icon !== '') { |
|
| 475 | + $icon = '<img src="' . htmlspecialchars($icon) . '" alt="•">'; |
|
| 476 | + } else { |
|
| 477 | + $icon = '•'; |
|
| 478 | + } |
|
| 479 | + $this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]); |
|
| 480 | + if ($plainText !== false) { |
|
| 481 | + $this->plainBody .= ' * ' . $plainText; |
|
| 482 | + if ($plainMetaInfo !== false) { |
|
| 483 | + $this->plainBody .= ' (' . $plainMetaInfo . ')'; |
|
| 484 | + } |
|
| 485 | + $this->plainBody .= PHP_EOL; |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + protected function ensureBodyListOpened() { |
|
| 490 | + if ($this->bodyListOpened) { |
|
| 491 | + return; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + $this->ensureBodyIsOpened(); |
|
| 495 | + $this->bodyListOpened = true; |
|
| 496 | + $this->htmlBody .= $this->listBegin; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + protected function ensureBodyListClosed() { |
|
| 500 | + if (!$this->bodyListOpened) { |
|
| 501 | + return; |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + $this->bodyListOpened = false; |
|
| 505 | + $this->htmlBody .= $this->listEnd; |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * Adds a button group of two buttons to the body of the email |
|
| 510 | + * |
|
| 511 | + * @param string $textLeft Text of left button; Note: When $plainTextLeft falls back to this, HTML is automatically escaped in the HTML email |
|
| 512 | + * @param string $urlLeft URL of left button |
|
| 513 | + * @param string $textRight Text of right button; Note: When $plainTextRight falls back to this, HTML is automatically escaped in the HTML email |
|
| 514 | + * @param string $urlRight URL of right button |
|
| 515 | + * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used |
|
| 516 | + * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used |
|
| 517 | + */ |
|
| 518 | + public function addBodyButtonGroup(string $textLeft, |
|
| 519 | + string $urlLeft, |
|
| 520 | + string $textRight, |
|
| 521 | + string $urlRight, |
|
| 522 | + string $plainTextLeft = '', |
|
| 523 | + string $plainTextRight = '') { |
|
| 524 | + if ($this->footerAdded) { |
|
| 525 | + return; |
|
| 526 | + } |
|
| 527 | + if ($plainTextLeft === '') { |
|
| 528 | + $plainTextLeft = $textLeft; |
|
| 529 | + $textLeft = htmlspecialchars($textLeft); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + if ($plainTextRight === '') { |
|
| 533 | + $plainTextRight = $textRight; |
|
| 534 | + $textRight = htmlspecialchars($textRight); |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + $this->ensureBodyIsOpened(); |
|
| 538 | + $this->ensureBodyListClosed(); |
|
| 539 | + |
|
| 540 | + $color = $this->themingDefaults->getColorPrimary(); |
|
| 541 | + $textColor = $this->themingDefaults->getTextColorPrimary(); |
|
| 542 | + |
|
| 543 | + $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textColor, $textColor, $textLeft, $urlRight, $textRight]); |
|
| 544 | + $this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL; |
|
| 545 | + $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; |
|
| 546 | + |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Adds a button to the body of the email |
|
| 551 | + * |
|
| 552 | + * @param string $text Text of button; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 553 | + * @param string $url URL of button |
|
| 554 | + * @param string $plainText Text of button in plain text version |
|
| 555 | + * if empty the $text is used, if false none will be used |
|
| 556 | + * |
|
| 557 | + * @since 12.0.0 |
|
| 558 | + */ |
|
| 559 | + public function addBodyButton(string $text, string $url, $plainText = '') { |
|
| 560 | + if ($this->footerAdded) { |
|
| 561 | + return; |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + $this->ensureBodyIsOpened(); |
|
| 565 | + $this->ensureBodyListClosed(); |
|
| 566 | + |
|
| 567 | + if ($plainText === '') { |
|
| 568 | + $plainText = $text; |
|
| 569 | + $text = htmlspecialchars($text); |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + $color = $this->themingDefaults->getColorPrimary(); |
|
| 573 | + $textColor = $this->themingDefaults->getTextColorPrimary(); |
|
| 574 | + $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, $textColor, $textColor, $text]); |
|
| 575 | + |
|
| 576 | + if ($plainText !== false) { |
|
| 577 | + $this->plainBody .= $plainText . ': '; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + $this->plainBody .= $url . PHP_EOL; |
|
| 581 | + |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + /** |
|
| 585 | + * Close the HTML body when it is open |
|
| 586 | + */ |
|
| 587 | + protected function ensureBodyIsClosed() { |
|
| 588 | + if (!$this->bodyOpened) { |
|
| 589 | + return; |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + $this->ensureBodyListClosed(); |
|
| 593 | + |
|
| 594 | + $this->htmlBody .= $this->bodyEnd; |
|
| 595 | + $this->bodyOpened = false; |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + /** |
|
| 599 | + * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
| 600 | + * |
|
| 601 | + * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used |
|
| 602 | + */ |
|
| 603 | + public function addFooter(string $text = '') { |
|
| 604 | + if($text === '') { |
|
| 605 | + $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically sent email, please do not reply.'); |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + if ($this->footerAdded) { |
|
| 609 | + return; |
|
| 610 | + } |
|
| 611 | + $this->footerAdded = true; |
|
| 612 | + |
|
| 613 | + $this->ensureBodyIsClosed(); |
|
| 614 | + |
|
| 615 | + $this->htmlBody .= vsprintf($this->footer, [$text]); |
|
| 616 | + $this->htmlBody .= $this->tail; |
|
| 617 | + $this->plainBody .= PHP_EOL . '-- ' . PHP_EOL; |
|
| 618 | + $this->plainBody .= str_replace('<br>', PHP_EOL, $text); |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * Returns the rendered email subject as string |
|
| 623 | + * |
|
| 624 | + * @return string |
|
| 625 | + */ |
|
| 626 | + public function renderSubject(): string { |
|
| 627 | + return $this->subject; |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + /** |
|
| 631 | + * Returns the rendered HTML email as string |
|
| 632 | + * |
|
| 633 | + * @return string |
|
| 634 | + */ |
|
| 635 | + public function renderHtml(): string { |
|
| 636 | + if (!$this->footerAdded) { |
|
| 637 | + $this->footerAdded = true; |
|
| 638 | + $this->ensureBodyIsClosed(); |
|
| 639 | + $this->htmlBody .= $this->tail; |
|
| 640 | + } |
|
| 641 | + return $this->htmlBody; |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + /** |
|
| 645 | + * Returns the rendered plain text email as string |
|
| 646 | + * |
|
| 647 | + * @return string |
|
| 648 | + */ |
|
| 649 | + public function renderText(): string { |
|
| 650 | + if (!$this->footerAdded) { |
|
| 651 | + $this->footerAdded = true; |
|
| 652 | + $this->ensureBodyIsClosed(); |
|
| 653 | + $this->htmlBody .= $this->tail; |
|
| 654 | + } |
|
| 655 | + return $this->plainBody; |
|
| 656 | + } |
|
| 657 | 657 | } |