Completed
Pull Request — master (#4467)
by Joas
42:45 queued 27:55
created
lib/public/Mail/IEMailTemplate.php 2 patches
Doc Comments   +8 added lines, -1 removed lines patch added patch discarded remove patch
@@ -55,6 +55,7 @@  discard block
 block discarded – undo
55 55
 	 * Adds a header to the email
56 56
 	 *
57 57
 	 * @since 12.0.0
58
+	 * @return void
58 59
 	 */
59 60
 	public function addHeader();
60 61
 
@@ -62,10 +63,11 @@  discard block
 block discarded – undo
62 63
 	 * Adds a heading to the email
63 64
 	 *
64 65
 	 * @param string $title
65
-	 * @param string $plainTitle|bool Title that is used in the plain text email
66
+	 * @param string $plainTitle Title that is used in the plain text email
66 67
 	 *   if empty the $title is used, if false none will be used
67 68
 	 *
68 69
 	 * @since 12.0.0
70
+	 * @return void
69 71
 	 */
70 72
 	public function addHeading($title, $plainTitle = '');
71 73
 
@@ -77,6 +79,7 @@  discard block
 block discarded – undo
77 79
 	 *   if empty the $text is used, if false none will be used
78 80
 	 *
79 81
 	 * @since 12.0.0
82
+	 * @return void
80 83
 	 */
81 84
 	public function addBodyText($text, $plainText = '');
82 85
 
@@ -87,6 +90,7 @@  discard block
 block discarded – undo
87 90
 	 * @param string $plainText Text that is used in the plain text email
88 91
 	 *   if empty the $text is used
89 92
 	 * @since 12.0.0
93
+	 * @return void
90 94
 	 */
91 95
 	public function addBodyListItem($text, $plainText = '');
92 96
 
@@ -101,6 +105,7 @@  discard block
 block discarded – undo
101 105
 	 * @param string $plainTextRight Text of right button that is used in the plain text version - if empty the $textRight is used
102 106
 	 *
103 107
 	 * @since 12.0.0
108
+	 * @return void
104 109
 	 */
105 110
 	public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight, $plainTextLeft = '', $plainTextRight = '');
106 111
 
@@ -113,6 +118,7 @@  discard block
 block discarded – undo
113 118
 	 * 		if empty the $text is used, if false none will be used
114 119
 	 *
115 120
 	 * @since 12.0.0
121
+	 * @return void
116 122
 	 */
117 123
 	public function addBodyButton($text, $url, $plainText = '');
118 124
 
@@ -122,6 +128,7 @@  discard block
 block discarded – undo
122 128
 	 * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
123 129
 	 *
124 130
 	 * @since 12.0.0
131
+	 * @return void
125 132
 	 */
126 133
 	public function addFooter($text = '');
127 134
 
Please login to merge, or discard this patch.
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -51,95 +51,95 @@
 block discarded – undo
51 51
  * @since 12.0.0
52 52
  */
53 53
 interface IEMailTemplate {
54
-	/**
55
-	 * Adds a header to the email
56
-	 *
57
-	 * @since 12.0.0
58
-	 */
59
-	public function addHeader();
54
+    /**
55
+     * Adds a header to the email
56
+     *
57
+     * @since 12.0.0
58
+     */
59
+    public function addHeader();
60 60
 
61
-	/**
62
-	 * Adds a heading to the email
63
-	 *
64
-	 * @param string $title
65
-	 * @param string $plainTitle|bool Title that is used in the plain text email
66
-	 *   if empty the $title is used, if false none will be used
67
-	 *
68
-	 * @since 12.0.0
69
-	 */
70
-	public function addHeading($title, $plainTitle = '');
61
+    /**
62
+     * Adds a heading to the email
63
+     *
64
+     * @param string $title
65
+     * @param string $plainTitle|bool Title that is used in the plain text email
66
+     *   if empty the $title is used, if false none will be used
67
+     *
68
+     * @since 12.0.0
69
+     */
70
+    public function addHeading($title, $plainTitle = '');
71 71
 
72
-	/**
73
-	 * Adds a paragraph to the body of the email
74
-	 *
75
-	 * @param string $text
76
-	 * @param string|bool $plainText Text that is used in the plain text email
77
-	 *   if empty the $text is used, if false none will be used
78
-	 *
79
-	 * @since 12.0.0
80
-	 */
81
-	public function addBodyText($text, $plainText = '');
72
+    /**
73
+     * Adds a paragraph to the body of the email
74
+     *
75
+     * @param string $text
76
+     * @param string|bool $plainText Text that is used in the plain text email
77
+     *   if empty the $text is used, if false none will be used
78
+     *
79
+     * @since 12.0.0
80
+     */
81
+    public function addBodyText($text, $plainText = '');
82 82
 
83
-	/**
84
-	 * Adds a list item to the body of the email
85
-	 *
86
-	 * @param string $text
87
-	 * @param string $plainText Text that is used in the plain text email
88
-	 *   if empty the $text is used
89
-	 * @since 12.0.0
90
-	 */
91
-	public function addBodyListItem($text, $plainText = '');
83
+    /**
84
+     * Adds a list item to the body of the email
85
+     *
86
+     * @param string $text
87
+     * @param string $plainText Text that is used in the plain text email
88
+     *   if empty the $text is used
89
+     * @since 12.0.0
90
+     */
91
+    public function addBodyListItem($text, $plainText = '');
92 92
 
93
-	/**
94
-	 * Adds a button group of two buttons to the body of the email
95
-	 *
96
-	 * @param string $textLeft Text of left button
97
-	 * @param string $urlLeft URL of left button
98
-	 * @param string $textRight Text of right button
99
-	 * @param string $urlRight URL of right button
100
-	 * @param string $plainTextLeft Text of left button that is used in the plain text version - if empty the $textLeft is used
101
-	 * @param string $plainTextRight Text of right button that is used in the plain text version - if empty the $textRight is used
102
-	 *
103
-	 * @since 12.0.0
104
-	 */
105
-	public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight, $plainTextLeft = '', $plainTextRight = '');
93
+    /**
94
+     * Adds a button group of two buttons to the body of the email
95
+     *
96
+     * @param string $textLeft Text of left button
97
+     * @param string $urlLeft URL of left button
98
+     * @param string $textRight Text of right button
99
+     * @param string $urlRight URL of right button
100
+     * @param string $plainTextLeft Text of left button that is used in the plain text version - if empty the $textLeft is used
101
+     * @param string $plainTextRight Text of right button that is used in the plain text version - if empty the $textRight is used
102
+     *
103
+     * @since 12.0.0
104
+     */
105
+    public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight, $plainTextLeft = '', $plainTextRight = '');
106 106
 
107
-	/**
108
-	 * Adds a button to the body of the email
109
-	 *
110
-	 * @param string $text Text of button
111
-	 * @param string $url URL of button
112
-	 * @param string $plainText Text of button in plain text version
113
-	 * 		if empty the $text is used, if false none will be used
114
-	 *
115
-	 * @since 12.0.0
116
-	 */
117
-	public function addBodyButton($text, $url, $plainText = '');
107
+    /**
108
+     * Adds a button to the body of the email
109
+     *
110
+     * @param string $text Text of button
111
+     * @param string $url URL of button
112
+     * @param string $plainText Text of button in plain text version
113
+     * 		if empty the $text is used, if false none will be used
114
+     *
115
+     * @since 12.0.0
116
+     */
117
+    public function addBodyButton($text, $url, $plainText = '');
118 118
 
119
-	/**
120
-	 * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
121
-	 *
122
-	 * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
123
-	 *
124
-	 * @since 12.0.0
125
-	 */
126
-	public function addFooter($text = '');
119
+    /**
120
+     * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
121
+     *
122
+     * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
123
+     *
124
+     * @since 12.0.0
125
+     */
126
+    public function addFooter($text = '');
127 127
 
128
-	/**
129
-	 * Returns the rendered HTML email as string
130
-	 *
131
-	 * @return string
132
-	 *
133
-	 * @since 12.0.0
134
-	 */
135
-	public function renderHtml();
128
+    /**
129
+     * Returns the rendered HTML email as string
130
+     *
131
+     * @return string
132
+     *
133
+     * @since 12.0.0
134
+     */
135
+    public function renderHtml();
136 136
 
137
-	/**
138
-	 * Returns the rendered plain text email as string
139
-	 *
140
-	 * @return string
141
-	 *
142
-	 * @since 12.0.0
143
-	 */
144
-	public function renderText();
137
+    /**
138
+     * Returns the rendered plain text email as string
139
+     *
140
+     * @return string
141
+     *
142
+     * @since 12.0.0
143
+     */
144
+    public function renderText();
145 145
 }
Please login to merge, or discard this patch.
lib/private/Mail/EMailTemplate.php 2 patches
Indentation   +291 added lines, -291 removed lines patch added patch discarded remove patch
@@ -39,27 +39,27 @@  discard block
 block discarded – undo
39 39
  * @package OC\Mail
40 40
  */
41 41
 class EMailTemplate implements IEMailTemplate {
42
-	/** @var Defaults */
43
-	protected $themingDefaults;
44
-	/** @var IURLGenerator */
45
-	protected $urlGenerator;
46
-	/** @var IL10N */
47
-	protected $l10n;
48
-
49
-	/** @var string */
50
-	protected $htmlBody = '';
51
-	/** @var string */
52
-	protected $plainBody = '';
53
-	/** @var bool indicated if the footer is added */
54
-	protected $headerAdded = false;
55
-	/** @var bool indicated if the body is already opened */
56
-	protected $bodyOpened = false;
57
-	/** @var bool indicated if there is a list open in the body */
58
-	protected $bodyListOpened = false;
59
-	/** @var bool indicated if the footer is added */
60
-	protected $footerAdded = false;
61
-
62
-	protected $head = <<<EOF
42
+    /** @var Defaults */
43
+    protected $themingDefaults;
44
+    /** @var IURLGenerator */
45
+    protected $urlGenerator;
46
+    /** @var IL10N */
47
+    protected $l10n;
48
+
49
+    /** @var string */
50
+    protected $htmlBody = '';
51
+    /** @var string */
52
+    protected $plainBody = '';
53
+    /** @var bool indicated if the footer is added */
54
+    protected $headerAdded = false;
55
+    /** @var bool indicated if the body is already opened */
56
+    protected $bodyOpened = false;
57
+    /** @var bool indicated if there is a list open in the body */
58
+    protected $bodyListOpened = false;
59
+    /** @var bool indicated if the footer is added */
60
+    protected $footerAdded = false;
61
+
62
+    protected $head = <<<EOF
63 63
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
64 64
 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#f3f3f3!important">
65 65
 <head>
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 				<center data-parsed="" style="min-width:580px;width:100%">
78 78
 EOF;
79 79
 
80
-	protected $tail = <<<EOF
80
+    protected $tail = <<<EOF
81 81
 					</center>
82 82
 				</td>
83 83
 			</tr>
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 </html>
89 89
 EOF;
90 90
 
91
-	protected $header = <<<EOF
91
+    protected $header = <<<EOF
92 92
 <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%%">
93 93
 	<tr style="padding:0;text-align:left;vertical-align:top">
94 94
 		<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">
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 </table>
122 122
 EOF;
123 123
 
124
-	protected $heading = <<<EOF
124
+    protected $heading = <<<EOF
125 125
 <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">
126 126
 	<tbody>
127 127
 	<tr style="padding:0;text-align:left;vertical-align:top">
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 </table>
141 141
 EOF;
142 142
 
143
-	protected $bodyBegin = <<<EOF
143
+    protected $bodyBegin = <<<EOF
144 144
 <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%">
145 145
 	<tr style="padding:0;text-align:left;vertical-align:top">
146 146
 		<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">
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 						</table>
158 158
 EOF;
159 159
 
160
-	protected $bodyText = <<<EOF
160
+    protected $bodyText = <<<EOF
161 161
 <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%%">
162 162
 	<tbody>
163 163
 	<tr style="padding:0;text-align:left;vertical-align:top">
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 </table>
177 177
 EOF;
178 178
 
179
-	protected $listBegin = <<<EOF
179
+    protected $listBegin = <<<EOF
180 180
 <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%%">
181 181
 	<tbody>
182 182
 	<tr style="padding:0;text-align:left;vertical-align:top">
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 			<table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
185 185
 EOF;
186 186
 
187
-	protected $listItem = <<<EOF
187
+    protected $listItem = <<<EOF
188 188
 				<tr style="padding:0;text-align:left;vertical-align:top">
189 189
 					<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;">
190 190
 						<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">&bull;</p>
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 				</tr>
197 197
 EOF;
198 198
 
199
-	protected $listEnd = <<<EOF
199
+    protected $listEnd = <<<EOF
200 200
 			</table>
201 201
 		</th>
202 202
 	</tr>
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 </table>
205 205
 EOF;
206 206
 
207
-	protected $buttonGroup = <<<EOF
207
+    protected $buttonGroup = <<<EOF
208 208
 <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
209 209
 	<tbody>
210 210
 	<tr style="padding:0;text-align:left;vertical-align:top">
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
 </table>
258 258
 EOF;
259 259
 
260
-	protected $button = <<<EOF
260
+    protected $button = <<<EOF
261 261
 <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
262 262
 	<tbody>
263 263
 	<tr style="padding:0;text-align:left;vertical-align:top">
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
 </table>
298 298
 EOF;
299 299
 
300
-	protected $bodyEnd = <<<EOF
300
+    protected $bodyEnd = <<<EOF
301 301
 
302 302
 					</td>
303 303
 				</tr>
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
 </table>
309 309
 EOF;
310 310
 
311
-	protected $footer = <<<EOF
311
+    protected $footer = <<<EOF
312 312
 <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%%">
313 313
 	<tbody>
314 314
 	<tr style="padding:0;text-align:left;vertical-align:top">
@@ -334,262 +334,262 @@  discard block
 block discarded – undo
334 334
 </table>
335 335
 EOF;
336 336
 
337
-	/**
338
-	 * @param Defaults $themingDefaults
339
-	 * @param IURLGenerator $urlGenerator
340
-	 * @param IL10N $l10n
341
-	 */
342
-	public function __construct(Defaults $themingDefaults,
343
-								IURLGenerator $urlGenerator,
344
-								IL10N $l10n) {
345
-		$this->themingDefaults = $themingDefaults;
346
-		$this->urlGenerator = $urlGenerator;
347
-		$this->l10n = $l10n;
348
-		$this->htmlBody .= $this->head;
349
-	}
350
-
351
-	/**
352
-	 * Adds a header to the email
353
-	 */
354
-	public function addHeader() {
355
-		if ($this->headerAdded) {
356
-			return;
357
-		}
358
-		$this->headerAdded = true;
359
-
360
-		$logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo());
361
-		$this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl, $this->themingDefaults->getName()]);
362
-	}
363
-
364
-	/**
365
-	 * Adds a heading to the email
366
-	 *
367
-	 * @param string $title
368
-	 * @param string $plainTitle|bool Title that is used in the plain text email
369
-	 *   if empty the $title is used, if false none will be used
370
-	 */
371
-	public function addHeading($title, $plainTitle = '') {
372
-		if ($this->footerAdded) {
373
-			return;
374
-		}
375
-		if ($plainTitle === '') {
376
-			$plainTitle = $title;
377
-		}
378
-
379
-		$this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]);
380
-		if ($plainTitle !== false) {
381
-			$this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL;
382
-		}
383
-	}
384
-
385
-	/**
386
-	 * Open the HTML body when it is not already
387
-	 */
388
-	protected function ensureBodyIsOpened() {
389
-		if ($this->bodyOpened) {
390
-			return;
391
-		}
392
-
393
-		$this->htmlBody .= $this->bodyBegin;
394
-		$this->bodyOpened = true;
395
-	}
396
-
397
-	/**
398
-	 * Adds a paragraph to the body of the email
399
-	 *
400
-	 * @param string $text
401
-	 * @param string|bool $plainText Text that is used in the plain text email
402
-	 *   if empty the $text is used, if false none will be used
403
-	 */
404
-	public function addBodyText($text, $plainText = '') {
405
-		if ($this->footerAdded) {
406
-			return;
407
-		}
408
-		if ($plainText === '') {
409
-			$plainText = $text;
410
-		}
411
-
412
-		$this->ensureBodyIsOpened();
413
-
414
-		$this->htmlBody .= vsprintf($this->bodyText, [htmlspecialchars($text)]);
415
-		if ($plainText !== false) {
416
-			$this->plainBody .= $plainText . PHP_EOL . PHP_EOL;
417
-		}
418
-	}
419
-
420
-	/**
421
-	 * Adds a list item to the body of the email
422
-	 *
423
-	 * @param string $text
424
-	 * @param string $plainText Text that is used in the plain text email
425
-	 *   if empty the $text is used
426
-	 * @since 12.0.0
427
-	 */
428
-	public function addBodyListItem($text, $plainText = '') {
429
-		$this->ensureBodyListOpened();
430
-
431
-		if ($plainText === '') {
432
-			$plainText = $text;
433
-		}
434
-
435
-		$this->htmlBody .= vsprintf($this->listItem, [htmlspecialchars($text)]);
436
-		if ($plainText !== false) {
437
-			$this->plainBody .= '  * ' . $plainText . PHP_EOL;
438
-		}
439
-	}
440
-
441
-	protected function ensureBodyListOpened() {
442
-		if ($this->bodyListOpened) {
443
-			return;
444
-		}
445
-
446
-		$this->ensureBodyIsOpened();
447
-		$this->bodyListOpened = true;
448
-		$this->htmlBody .= $this->listBegin;
449
-	}
450
-
451
-	protected function ensureBodyListClosed() {
452
-		if (!$this->bodyListOpened) {
453
-			return;
454
-		}
455
-
456
-		$this->bodyListOpened = false;
457
-		$this->htmlBody .= $this->listEnd;
458
-	}
459
-
460
-	/**
461
-	 * Adds a button group of two buttons to the body of the email
462
-	 *
463
-	 * @param string $textLeft Text of left button
464
-	 * @param string $urlLeft URL of left button
465
-	 * @param string $textRight Text of right button
466
-	 * @param string $urlRight URL of right button
467
-	 * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used
468
-	 * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used
469
-	 */
470
-	public function addBodyButtonGroup($textLeft,
471
-									   $urlLeft,
472
-									   $textRight,
473
-									   $urlRight,
474
-									   $plainTextLeft = '',
475
-									   $plainTextRight = '') {
476
-		if ($this->footerAdded) {
477
-			return;
478
-		}
479
-		if ($plainTextLeft === '') {
480
-			$plainTextLeft = $textLeft;
481
-		}
482
-
483
-		if ($plainTextRight === '') {
484
-			$plainTextRight = $textRight;
485
-		}
486
-
487
-		$this->ensureBodyIsOpened();
488
-		$this->ensureBodyListClosed();
489
-
490
-		$color = $this->themingDefaults->getColorPrimary();
491
-
492
-		$this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, htmlspecialchars($textLeft), $urlRight, htmlspecialchars($textRight)]);
493
-		$this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL;
494
-		$this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL;
495
-
496
-	}
497
-
498
-	/**
499
-	 * Adds a button to the body of the email
500
-	 *
501
-	 * @param string $text Text of button
502
-	 * @param string $url URL of button
503
-	 * @param string $plainText Text of button in plain text version
504
-	 * 		if empty the $text is used, if false none will be used
505
-	 *
506
-	 * @since 12.0.0
507
-	 */
508
-	public function addBodyButton($text, $url, $plainText = '') {
509
-		if ($this->footerAdded) {
510
-			return;
511
-		}
512
-
513
-		$this->ensureBodyIsOpened();
514
-		$this->ensureBodyListClosed();
515
-
516
-		if ($plainText === '') {
517
-			$plainText = $text;
518
-		}
519
-
520
-		$color = $this->themingDefaults->getColorPrimary();
521
-		$this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, htmlspecialchars($text)]);
522
-
523
-		if ($plainText !== false) {
524
-			$this->plainBody .= $plainText . ': ';
525
-		}
526
-
527
-		$this->plainBody .=  $url . PHP_EOL;
528
-
529
-	}
530
-
531
-	/**
532
-	 * Close the HTML body when it is open
533
-	 */
534
-	protected function ensureBodyIsClosed() {
535
-		if (!$this->bodyOpened) {
536
-			return;
537
-		}
538
-
539
-		$this->ensureBodyListClosed();
540
-
541
-		$this->htmlBody .= $this->bodyEnd;
542
-		$this->bodyOpened = false;
543
-	}
544
-
545
-	/**
546
-	 * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
547
-	 *
548
-	 * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
549
-	 */
550
-	public function addFooter($text = '') {
551
-		if($text === '') {
552
-			$text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically sent email, please do not reply.');
553
-		}
554
-
555
-		if ($this->footerAdded) {
556
-			return;
557
-		}
558
-		$this->footerAdded = true;
559
-
560
-		$this->ensureBodyIsClosed();
561
-
562
-		$this->htmlBody .= vsprintf($this->footer, [$text]);
563
-		$this->htmlBody .= $this->tail;
564
-		$this->plainBody .= PHP_EOL . '-- ' . PHP_EOL;
565
-		$this->plainBody .= str_replace('<br>', PHP_EOL, $text);
566
-	}
567
-
568
-	/**
569
-	 * Returns the rendered HTML email as string
570
-	 *
571
-	 * @return string
572
-	 */
573
-	public function renderHtml() {
574
-		if (!$this->footerAdded) {
575
-			$this->footerAdded = true;
576
-			$this->ensureBodyIsClosed();
577
-			$this->htmlBody .= $this->tail;
578
-		}
579
-		return $this->htmlBody;
580
-	}
581
-
582
-	/**
583
-	 * Returns the rendered plain text email as string
584
-	 *
585
-	 * @return string
586
-	 */
587
-	public function renderText() {
588
-		if (!$this->footerAdded) {
589
-			$this->footerAdded = true;
590
-			$this->ensureBodyIsClosed();
591
-			$this->htmlBody .= $this->tail;
592
-		}
593
-		return $this->plainBody;
594
-	}
337
+    /**
338
+     * @param Defaults $themingDefaults
339
+     * @param IURLGenerator $urlGenerator
340
+     * @param IL10N $l10n
341
+     */
342
+    public function __construct(Defaults $themingDefaults,
343
+                                IURLGenerator $urlGenerator,
344
+                                IL10N $l10n) {
345
+        $this->themingDefaults = $themingDefaults;
346
+        $this->urlGenerator = $urlGenerator;
347
+        $this->l10n = $l10n;
348
+        $this->htmlBody .= $this->head;
349
+    }
350
+
351
+    /**
352
+     * Adds a header to the email
353
+     */
354
+    public function addHeader() {
355
+        if ($this->headerAdded) {
356
+            return;
357
+        }
358
+        $this->headerAdded = true;
359
+
360
+        $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo());
361
+        $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl, $this->themingDefaults->getName()]);
362
+    }
363
+
364
+    /**
365
+     * Adds a heading to the email
366
+     *
367
+     * @param string $title
368
+     * @param string $plainTitle|bool Title that is used in the plain text email
369
+     *   if empty the $title is used, if false none will be used
370
+     */
371
+    public function addHeading($title, $plainTitle = '') {
372
+        if ($this->footerAdded) {
373
+            return;
374
+        }
375
+        if ($plainTitle === '') {
376
+            $plainTitle = $title;
377
+        }
378
+
379
+        $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]);
380
+        if ($plainTitle !== false) {
381
+            $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL;
382
+        }
383
+    }
384
+
385
+    /**
386
+     * Open the HTML body when it is not already
387
+     */
388
+    protected function ensureBodyIsOpened() {
389
+        if ($this->bodyOpened) {
390
+            return;
391
+        }
392
+
393
+        $this->htmlBody .= $this->bodyBegin;
394
+        $this->bodyOpened = true;
395
+    }
396
+
397
+    /**
398
+     * Adds a paragraph to the body of the email
399
+     *
400
+     * @param string $text
401
+     * @param string|bool $plainText Text that is used in the plain text email
402
+     *   if empty the $text is used, if false none will be used
403
+     */
404
+    public function addBodyText($text, $plainText = '') {
405
+        if ($this->footerAdded) {
406
+            return;
407
+        }
408
+        if ($plainText === '') {
409
+            $plainText = $text;
410
+        }
411
+
412
+        $this->ensureBodyIsOpened();
413
+
414
+        $this->htmlBody .= vsprintf($this->bodyText, [htmlspecialchars($text)]);
415
+        if ($plainText !== false) {
416
+            $this->plainBody .= $plainText . PHP_EOL . PHP_EOL;
417
+        }
418
+    }
419
+
420
+    /**
421
+     * Adds a list item to the body of the email
422
+     *
423
+     * @param string $text
424
+     * @param string $plainText Text that is used in the plain text email
425
+     *   if empty the $text is used
426
+     * @since 12.0.0
427
+     */
428
+    public function addBodyListItem($text, $plainText = '') {
429
+        $this->ensureBodyListOpened();
430
+
431
+        if ($plainText === '') {
432
+            $plainText = $text;
433
+        }
434
+
435
+        $this->htmlBody .= vsprintf($this->listItem, [htmlspecialchars($text)]);
436
+        if ($plainText !== false) {
437
+            $this->plainBody .= '  * ' . $plainText . PHP_EOL;
438
+        }
439
+    }
440
+
441
+    protected function ensureBodyListOpened() {
442
+        if ($this->bodyListOpened) {
443
+            return;
444
+        }
445
+
446
+        $this->ensureBodyIsOpened();
447
+        $this->bodyListOpened = true;
448
+        $this->htmlBody .= $this->listBegin;
449
+    }
450
+
451
+    protected function ensureBodyListClosed() {
452
+        if (!$this->bodyListOpened) {
453
+            return;
454
+        }
455
+
456
+        $this->bodyListOpened = false;
457
+        $this->htmlBody .= $this->listEnd;
458
+    }
459
+
460
+    /**
461
+     * Adds a button group of two buttons to the body of the email
462
+     *
463
+     * @param string $textLeft Text of left button
464
+     * @param string $urlLeft URL of left button
465
+     * @param string $textRight Text of right button
466
+     * @param string $urlRight URL of right button
467
+     * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used
468
+     * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used
469
+     */
470
+    public function addBodyButtonGroup($textLeft,
471
+                                        $urlLeft,
472
+                                        $textRight,
473
+                                        $urlRight,
474
+                                        $plainTextLeft = '',
475
+                                        $plainTextRight = '') {
476
+        if ($this->footerAdded) {
477
+            return;
478
+        }
479
+        if ($plainTextLeft === '') {
480
+            $plainTextLeft = $textLeft;
481
+        }
482
+
483
+        if ($plainTextRight === '') {
484
+            $plainTextRight = $textRight;
485
+        }
486
+
487
+        $this->ensureBodyIsOpened();
488
+        $this->ensureBodyListClosed();
489
+
490
+        $color = $this->themingDefaults->getColorPrimary();
491
+
492
+        $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, htmlspecialchars($textLeft), $urlRight, htmlspecialchars($textRight)]);
493
+        $this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL;
494
+        $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL;
495
+
496
+    }
497
+
498
+    /**
499
+     * Adds a button to the body of the email
500
+     *
501
+     * @param string $text Text of button
502
+     * @param string $url URL of button
503
+     * @param string $plainText Text of button in plain text version
504
+     * 		if empty the $text is used, if false none will be used
505
+     *
506
+     * @since 12.0.0
507
+     */
508
+    public function addBodyButton($text, $url, $plainText = '') {
509
+        if ($this->footerAdded) {
510
+            return;
511
+        }
512
+
513
+        $this->ensureBodyIsOpened();
514
+        $this->ensureBodyListClosed();
515
+
516
+        if ($plainText === '') {
517
+            $plainText = $text;
518
+        }
519
+
520
+        $color = $this->themingDefaults->getColorPrimary();
521
+        $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, htmlspecialchars($text)]);
522
+
523
+        if ($plainText !== false) {
524
+            $this->plainBody .= $plainText . ': ';
525
+        }
526
+
527
+        $this->plainBody .=  $url . PHP_EOL;
528
+
529
+    }
530
+
531
+    /**
532
+     * Close the HTML body when it is open
533
+     */
534
+    protected function ensureBodyIsClosed() {
535
+        if (!$this->bodyOpened) {
536
+            return;
537
+        }
538
+
539
+        $this->ensureBodyListClosed();
540
+
541
+        $this->htmlBody .= $this->bodyEnd;
542
+        $this->bodyOpened = false;
543
+    }
544
+
545
+    /**
546
+     * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
547
+     *
548
+     * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
549
+     */
550
+    public function addFooter($text = '') {
551
+        if($text === '') {
552
+            $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically sent email, please do not reply.');
553
+        }
554
+
555
+        if ($this->footerAdded) {
556
+            return;
557
+        }
558
+        $this->footerAdded = true;
559
+
560
+        $this->ensureBodyIsClosed();
561
+
562
+        $this->htmlBody .= vsprintf($this->footer, [$text]);
563
+        $this->htmlBody .= $this->tail;
564
+        $this->plainBody .= PHP_EOL . '-- ' . PHP_EOL;
565
+        $this->plainBody .= str_replace('<br>', PHP_EOL, $text);
566
+    }
567
+
568
+    /**
569
+     * Returns the rendered HTML email as string
570
+     *
571
+     * @return string
572
+     */
573
+    public function renderHtml() {
574
+        if (!$this->footerAdded) {
575
+            $this->footerAdded = true;
576
+            $this->ensureBodyIsClosed();
577
+            $this->htmlBody .= $this->tail;
578
+        }
579
+        return $this->htmlBody;
580
+    }
581
+
582
+    /**
583
+     * Returns the rendered plain text email as string
584
+     *
585
+     * @return string
586
+     */
587
+    public function renderText() {
588
+        if (!$this->footerAdded) {
589
+            $this->footerAdded = true;
590
+            $this->ensureBodyIsClosed();
591
+            $this->htmlBody .= $this->tail;
592
+        }
593
+        return $this->plainBody;
594
+    }
595 595
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
 
379 379
 		$this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]);
380 380
 		if ($plainTitle !== false) {
381
-			$this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL;
381
+			$this->plainBody .= $plainTitle.PHP_EOL.PHP_EOL;
382 382
 		}
383 383
 	}
384 384
 
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
 
414 414
 		$this->htmlBody .= vsprintf($this->bodyText, [htmlspecialchars($text)]);
415 415
 		if ($plainText !== false) {
416
-			$this->plainBody .= $plainText . PHP_EOL . PHP_EOL;
416
+			$this->plainBody .= $plainText.PHP_EOL.PHP_EOL;
417 417
 		}
418 418
 	}
419 419
 
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
 
435 435
 		$this->htmlBody .= vsprintf($this->listItem, [htmlspecialchars($text)]);
436 436
 		if ($plainText !== false) {
437
-			$this->plainBody .= '  * ' . $plainText . PHP_EOL;
437
+			$this->plainBody .= '  * '.$plainText.PHP_EOL;
438 438
 		}
439 439
 	}
440 440
 
@@ -490,8 +490,8 @@  discard block
 block discarded – undo
490 490
 		$color = $this->themingDefaults->getColorPrimary();
491 491
 
492 492
 		$this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, htmlspecialchars($textLeft), $urlRight, htmlspecialchars($textRight)]);
493
-		$this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL;
494
-		$this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL;
493
+		$this->plainBody .= $plainTextLeft.': '.$urlLeft.PHP_EOL;
494
+		$this->plainBody .= $plainTextRight.': '.$urlRight.PHP_EOL.PHP_EOL;
495 495
 
496 496
 	}
497 497
 
@@ -521,10 +521,10 @@  discard block
 block discarded – undo
521 521
 		$this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, htmlspecialchars($text)]);
522 522
 
523 523
 		if ($plainText !== false) {
524
-			$this->plainBody .= $plainText . ': ';
524
+			$this->plainBody .= $plainText.': ';
525 525
 		}
526 526
 
527
-		$this->plainBody .=  $url . PHP_EOL;
527
+		$this->plainBody .= $url.PHP_EOL;
528 528
 
529 529
 	}
530 530
 
@@ -548,8 +548,8 @@  discard block
 block discarded – undo
548 548
 	 * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
549 549
 	 */
550 550
 	public function addFooter($text = '') {
551
-		if($text === '') {
552
-			$text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically sent email, please do not reply.');
551
+		if ($text === '') {
552
+			$text = $this->themingDefaults->getName().' - '.$this->themingDefaults->getSlogan().'<br>'.$this->l10n->t('This is an automatically sent email, please do not reply.');
553 553
 		}
554 554
 
555 555
 		if ($this->footerAdded) {
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
 
562 562
 		$this->htmlBody .= vsprintf($this->footer, [$text]);
563 563
 		$this->htmlBody .= $this->tail;
564
-		$this->plainBody .= PHP_EOL . '-- ' . PHP_EOL;
564
+		$this->plainBody .= PHP_EOL.'-- '.PHP_EOL;
565 565
 		$this->plainBody .= str_replace('<br>', PHP_EOL, $text);
566 566
 	}
567 567
 
Please login to merge, or discard this patch.