Completed
Push — master ( 4c6036...8838ed )
by Morris
11:46
created

EMailTemplate::addFooter()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 6
nop 1
dl 0
loc 20
rs 9.2
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright 2017, Morris Jobke <[email protected]>
4
 * @copyright 2017, Lukas Reschke <[email protected]>
5
 *
6
 * @author Morris Jobke <[email protected]>
7
 * @author Lukas Reschke <[email protected]>
8
 *
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
namespace OC\Mail;
27
28
use OCA\Theming\ThemingDefaults;
29
use OCP\IL10N;
30
use OCP\IURLGenerator;
31
32
/**
33
 * Class EMailTemplate
34
 *
35
 * addBodyText and addBodyButtonGroup automatically opens the body
36
 * addFooter, renderHTML, renderText automatically closes the body and the HTML if opened
37
 *
38
 * @package OC\Mail
39
 */
40
class EMailTemplate implements IEMailTemplate {
41
	/** @var ThemingDefaults */
42
	protected $themingDefaults;
43
	/** @var IURLGenerator */
44
	protected $urlGenerator;
45
	/** @var IL10N */
46
	protected $l10n;
47
48
	/** @var string */
49
	protected $htmlBody = '';
50
	/** @var string */
51
	protected $plainBody = '';
52
	/** @var bool indicated if the footer is added */
53
	protected $headerAdded = false;
54
	/** @var bool indicated if the body is already opened */
55
	protected $bodyOpened = false;
56
	/** @var bool indicated if the footer is added */
57
	protected $footerAdded = false;
58
59
	protected $head = <<<EOF
60
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
61
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#f3f3f3!important">
62
<head>
63
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
64
	<meta name="viewport" content="width=device-width">
65
	<title></title>
66
	<style type="text/css">@media only screen{html{min-height:100%;background:#F5F5F5}}@media only screen and (max-width:610px){table.body img{width:auto;height:auto}table.body center{min-width:0!important}table.body .container{width:95%!important}table.body .columns{height:auto!important;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;padding-left:30px!important;padding-right:30px!important}th.small-12{display:inline-block!important;width:100%!important}table.menu{width:100%!important}table.menu td,table.menu th{width:auto!important;display:inline-block!important}table.menu.vertical td,table.menu.vertical th{display:block!important}table.menu[align=center]{width:auto!important}}</style>
67
</head>
68
<body style="-moz-box-sizing:border-box;-ms-text-size-adjust:100%;-webkit-box-sizing:border-box;-webkit-font-smoothing:antialiased;-webkit-text-size-adjust:100%;Margin:0;background:#f3f3f3!important;box-sizing:border-box;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;min-width:100%;padding:0;text-align:left;width:100%!important">
69
	<span class="preheader" style="color:#F5F5F5;display:none!important;font-size:1px;line-height:1px;max-height:0;max-width:0;mso-hide:all!important;opacity:0;overflow:hidden;visibility:hidden">
70
	</span>
71
	<table class="body" style="-webkit-font-smoothing:antialiased;Margin:0;background:#f3f3f3!important;border-collapse:collapse;border-spacing:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;height:100%;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;width:100%">
72
		<tr style="padding:0;text-align:left;vertical-align:top">
73
			<td class="center" align="center" valign="top" 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">
74
				<center data-parsed="" style="min-width:580px;width:100%">
75
EOF;
76
77
	protected $tail = <<<EOF
78
					</center>
79
				</td>
80
			</tr>
81
		</table>
82
		<!-- prevent Gmail on iOS font size manipulation -->
83
		<div style="display:none;white-space:nowrap;font:15px courier;line-height:0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
84
	</body>
85
</html>
86
EOF;
87
88
	protected $header = <<<EOF
89
<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%%">
90
	<tr style="padding:0;text-align:left;vertical-align:top">
91
		<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">
92
			<table align="center" class="container" style="Margin:0 auto;background:0 0;border-collapse:collapse;border-spacing:0;margin:0 auto;padding:0;text-align:inherit;vertical-align:top;width:580px">
93
				<tbody>
94
				<tr style="padding:0;text-align:left;vertical-align:top">
95
					<td 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">
96
						<table class="row collapse" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%%">
97
							<tbody>
98
							<tr style="padding:0;text-align:left;vertical-align:top">
99
								<center data-parsed="" style="min-width:580px;width:100%%">
100
									<img class="logo float-center" src="%s" alt="logo" align="center" style="-ms-interpolation-mode:bicubic;Margin:0 auto;clear:both;display:block;float:none;margin:0 auto;max-height:100%%;max-width:100px;outline:0;text-align:center;text-decoration:none;width:auto">
101
								</center>
102
							</tr>
103
							</tbody>
104
						</table>
105
					</td>
106
				</tr>
107
				</tbody>
108
			</table>
109
		</td>
110
	</tr>
111
</table>
112
<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%%">
113
	<tbody>
114
	<tr style="padding:0;text-align:left;vertical-align:top">
115
		<td height="80px" 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:80px;font-weight:400;hyphens:auto;line-height:80px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
116
	</tr>
117
	</tbody>
118
</table>
119
EOF;
120
121
	protected $heading = <<<EOF
122
<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">
123
	<tbody>
124
	<tr style="padding:0;text-align:left;vertical-align:top">
125
		<td 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">
126
			<h1 class="text-center" style="Margin:0;Margin-bottom:10px;color:inherit;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:24px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;text-align:center;word-wrap:normal">%s</h1>
127
		</td>
128
	</tr>
129
	</tbody>
130
</table>
131
<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%%">
132
	<tbody>
133
	<tr style="padding:0;text-align:left;vertical-align:top">
134
		<td height="40px" 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:40px;font-weight:400;hyphens:auto;line-height:40px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
135
	</tr>
136
	</tbody>
137
</table>
138
EOF;
139
140
	protected $bodyBegin = <<<EOF
141
<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%">
142
	<tr style="padding:0;text-align:left;vertical-align:top">
143
		<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">
144
			<table align="center" class="container has-shadow" style="Margin:0 auto;background:#fefefe;border-collapse:collapse;border-spacing:0;box-shadow:0 1px 2px 0 rgba(0,0,0,.2),0 1px 3px 0 rgba(0,0,0,.1);margin:0 auto;padding:0;text-align:inherit;vertical-align:top;width:580px">
145
				<tbody>
146
				<tr style="padding:0;text-align:left;vertical-align:top">
147
					<td 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">
148
						<table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
149
							<tbody>
150
							<tr style="padding:0;text-align:left;vertical-align:top">
151
								<td height="60px" 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:60px;font-weight:400;hyphens:auto;line-height:60px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
152
							</tr>
153
							</tbody>
154
						</table>
155
EOF;
156
157
	protected $bodyText = <<<EOF
158
<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%%">
159
	<tbody>
160
	<tr style="padding:0;text-align:left;vertical-align:top">
161
		<th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
162
			<table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
163
				<tr style="padding:0;text-align:left;vertical-align:top">
164
					<th 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">
165
						<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;text-align:left">%s</p>
166
					</th>
167
					<th class="expander" 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!important;text-align:left;visibility:hidden;width:0"></th>
168
				</tr>
169
			</table>
170
		</th>
171
	</tr>
172
	</tbody>
173
</table>
174
EOF;
175
176
	protected $buttonGroup = <<<EOF
177
<table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
178
	<tbody>
179
	<tr style="padding:0;text-align:left;vertical-align:top">
180
		<td height="50px" 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:50px;font-weight:400;hyphens:auto;line-height:50px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
181
	</tr>
182
	</tbody>
183
</table>
184
<table align="center" class="row btn-group" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%%">
185
	<tbody>
186
	<tr style="padding:0;text-align:left;vertical-align:top">
187
		<th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
188
			<table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
189
				<tr style="padding:0;text-align:left;vertical-align:top">
190
					<th 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">
191
						<center data-parsed="" style="min-width:490px;width:100%%">
192
							<table class="button btn default primary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;margin-right:15px;max-height:40px;max-width:200px;padding:0;text-align:center;vertical-align:top;width:auto">
193
								<tr style="padding:0;text-align:left;vertical-align:top">
194
									<td 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">
195
										<table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
196
											<tr style="padding:0;text-align:left;vertical-align:top">
197
												<td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:%s;border:0 solid %s;border-collapse:collapse!important;color:#fefefe;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">
198
													<a href="%s" style="Margin:0;border:0 solid %s;border-radius:2px;color:#fefefe;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">%s</a>
199
												</td>
200
											</tr>
201
										</table>
202
									</td>
203
								</tr>
204
							</table>
205
							<table class="button btn default secondary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;max-height:40px;max-width:200px;padding:0;text-align:center;vertical-align:top;width:auto">
206
								<tr style="padding:0;text-align:left;vertical-align:top">
207
									<td 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">
208
										<table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
209
											<tr style="padding:0;text-align:left;vertical-align:top">
210
												<td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:#777;border:0 solid #777;border-collapse:collapse!important;color:#fefefe;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">
211
													<a href="%s" style="Margin:0;background-color:#fff;border:0 solid #777;border-radius:2px;color:#6C6C6C!important;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;outline:1px solid #CBCBCB;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">%s</a>
212
												</td>
213
											</tr>
214
										</table>
215
									</td>
216
								</tr>
217
							</table>
218
						</center>
219
					</th>
220
					<th class="expander" 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!important;text-align:left;visibility:hidden;width:0"></th>
221
				</tr>
222
			</table>
223
		</th>
224
	</tr>
225
	</tbody>
226
</table>
227
EOF;
228
229
	protected $bodyEnd = <<<EOF
230
231
					</td>
232
				</tr>
233
				</tbody>
234
			</table>
235
		</td>
236
	</tr>
237
</table>
238
EOF;
239
240
	protected $footer = <<<EOF
241
<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%%">
242
	<tbody>
243
	<tr style="padding:0;text-align:left;vertical-align:top">
244
		<td height="60px" 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:60px;font-weight:400;hyphens:auto;line-height:60px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
245
	</tr>
246
	</tbody>
247
</table>
248
<table align="center" class="wrapper footer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%">
249
	<tr style="padding:0;text-align:left;vertical-align:top">
250
		<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">
251
			<center data-parsed="" style="min-width:580px;width:100%%">
252
				<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%%">
253
					<tbody>
254
					<tr style="padding:0;text-align:left;vertical-align:top">
255
						<td height="15px" 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:15px;font-weight:400;hyphens:auto;line-height:15px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
256
					</tr>
257
					</tbody>
258
				</table>
259
				<p class="text-center float-center" align="center" style="Margin:0;Margin-bottom:10px;color:#C8C8C8;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:12px;font-weight:400;line-height:16px;margin:0;margin-bottom:10px;padding:0;text-align:center">%s</p>
260
			</center>
261
		</td>
262
	</tr>
263
</table>
264
EOF;
265
266
	/**
267
	 * @param ThemingDefaults $themingDefaults
268
	 * @param IURLGenerator $urlGenerator
269
	 * @param IL10N $l10n
270
	 */
271
	public function __construct(ThemingDefaults $themingDefaults,
272
								IURLGenerator $urlGenerator,
273
								IL10N $l10n) {
274
		$this->themingDefaults = $themingDefaults;
275
		$this->urlGenerator = $urlGenerator;
276
		$this->l10n = $l10n;
277
		$this->htmlBody .= $this->head;
278
	}
279
280
	/**
281
	 * Adds a header to the email
282
	 */
283
	public function addHeader() {
284
		if ($this->headerAdded) {
285
			return;
286
		}
287
		$this->headerAdded = true;
288
289
		$logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo()) . '?v='. $this->themingDefaults->getCacheBusterCounter();
290
		$this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl]);
291
	}
292
293
	/**
294
	 * Adds a heading to the email
295
	 *
296
	 * @param string $title
297
	 */
298
	public function addHeading($title) {
299
		if ($this->footerAdded) {
300
			return;
301
		}
302
303
		$this->htmlBody .= vsprintf($this->heading, [$title]);
304
		$this->plainBody .= $title . PHP_EOL . PHP_EOL;
305
	}
306
307
	/**
308
	 * Adds a paragraph to the body of the email
309
	 *
310
	 * @param string $text
311
	 */
312
	public function addBodyText($text) {
313
		if ($this->footerAdded) {
314
			return;
315
		}
316
317
		if (!$this->bodyOpened) {
318
			$this->htmlBody .= $this->bodyBegin;
319
			$this->bodyOpened = true;
320
		}
321
322
		$this->htmlBody .= vsprintf($this->bodyText, [$text]);
323
		$this->plainBody .= $text . PHP_EOL . PHP_EOL;
324
	}
325
326
	/**
327
	 * Adds a button group of two buttons to the body of the email
328
	 *
329
	 * @param string $textLeft Text of left button
330
	 * @param string $urlLeft URL of left button
331
	 * @param string $textRight Text of right button
332
	 * @param string $urlRight URL of right button
333
	 */
334
	public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight) {
335
		if ($this->footerAdded) {
336
			return;
337
		}
338
339
		if (!$this->bodyOpened) {
340
			$this->htmlBody .= $this->bodyBegin;
341
			$this->bodyOpened = true;
342
		}
343
344
		$color = $this->themingDefaults->getColorPrimary();
345
		$this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textLeft, $urlRight, $textRight]);
346
		$this->plainBody .= $textLeft . ': ' . $urlLeft . PHP_EOL;
347
		$this->plainBody .= $textRight . ': ' . $urlRight . PHP_EOL . PHP_EOL;
348
349
	}
350
351
	/**
352
	 * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
353
	 *
354
	 * @param string $text
355
	 */
356
	public function addFooter($text = '') {
357
		if($text === '') {
358
			$text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically generated email, please do not reply.');
359
		}
360
361
		if ($this->footerAdded) {
362
			return;
363
		}
364
		$this->footerAdded = true;
365
366
		if ($this->bodyOpened) {
367
			$this->htmlBody .= $this->bodyEnd;
368
			$this->bodyOpened = false;
369
		}
370
371
		$this->htmlBody .= vsprintf($this->footer, [$text]);
372
		$this->htmlBody .= $this->tail;
373
		$this->plainBody .= '--' . PHP_EOL;
374
		$this->plainBody .= str_replace('<br>', PHP_EOL, $text);
375
	}
376
377
	/**
378
	 * Returns the rendered HTML email as string
379
	 *
380
	 * @return string
381
	 */
382 View Code Duplication
	public function renderHTML() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
383
		if (!$this->footerAdded) {
384
			$this->footerAdded = true;
385
			if ($this->bodyOpened) {
386
				$this->htmlBody .= $this->bodyEnd;
387
			}
388
			$this->htmlBody .= $this->tail;
389
		}
390
		return $this->htmlBody;
391
	}
392
393
	/**
394
	 * Returns the rendered plain text email as string
395
	 *
396
	 * @return string
397
	 */
398 View Code Duplication
	public function renderText() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
399
		if (!$this->footerAdded) {
400
			$this->footerAdded = true;
401
			if ($this->bodyOpened) {
402
				$this->htmlBody .= $this->bodyEnd;
403
			}
404
			$this->htmlBody .= $this->tail;
405
		}
406
		return $this->plainBody;
407
	}
408
}
409