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