Completed
Push — master ( cebbb1...15cd21 )
by Morris
28:14 queued 27:39
created

EMailTemplate::setMetaData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 4
rs 10
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 OCP\Defaults;
29
use OCP\IL10N;
30
use OCP\IURLGenerator;
31
use OCP\Mail\IEMailTemplate;
32
33
/**
34
 * Class EMailTemplate
35
 *
36
 * addBodyText and addBodyButtonGroup automatically opens the body
37
 * addFooter, renderHtml, renderText automatically closes the body and the HTML if opened
38
 *
39
 * @package OC\Mail
40
 */
41
class EMailTemplate implements IEMailTemplate {
42
	/** @var Defaults */
43
	protected $themingDefaults;
44
	/** @var IURLGenerator */
45
	protected $urlGenerator;
46
	/** @var IL10N */
47
	protected $l10n;
48
	/** @var string */
49
	protected $emailId;
50
	/** @var array */
51
	protected $data;
52
53
	/** @var string */
54
	protected $htmlBody = '';
55
	/** @var string */
56
	protected $plainBody = '';
57
	/** @var bool indicated if the footer is added */
58
	protected $headerAdded = false;
59
	/** @var bool indicated if the body is already opened */
60
	protected $bodyOpened = false;
61
	/** @var bool indicated if there is a list open in the body */
62
	protected $bodyListOpened = false;
63
	/** @var bool indicated if the footer is added */
64
	protected $footerAdded = false;
65
66
	protected $head = <<<EOF
67
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
68
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#f3f3f3!important">
69
<head>
70
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
71
	<meta name="viewport" content="width=device-width">
72
	<title></title>
73
	<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>
74
</head>
75
<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">
76
	<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">
77
	</span>
78
	<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%">
79
		<tr style="padding:0;text-align:left;vertical-align:top">
80
			<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">
81
				<center data-parsed="" style="min-width:580px;width:100%">
82
EOF;
83
84
	protected $tail = <<<EOF
85
					</center>
86
				</td>
87
			</tr>
88
		</table>
89
		<!-- prevent Gmail on iOS font size manipulation -->
90
		<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>
91
	</body>
92
</html>
93
EOF;
94
95
	protected $header = <<<EOF
96
<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%%">
97
	<tr style="padding:0;text-align:left;vertical-align:top">
98
		<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">
99
			<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">
100
				<tbody>
101
				<tr style="padding:0;text-align:left;vertical-align:top">
102
					<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">
103
						<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%%">
104
							<tbody>
105
							<tr style="padding:0;text-align:left;vertical-align:top">
106
								<center data-parsed="" style="min-width:580px;width:100%%">
107
									<img class="logo float-center" src="%s" alt="%s" align="center" style="-ms-interpolation-mode:bicubic;Margin:0 auto;clear:both;display:block;float:none;margin:0 auto;outline:0;text-align:center;text-decoration:none" height="50">
108
								</center>
109
							</tr>
110
							</tbody>
111
						</table>
112
					</td>
113
				</tr>
114
				</tbody>
115
			</table>
116
		</td>
117
	</tr>
118
</table>
119
<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%%">
120
	<tbody>
121
	<tr style="padding:0;text-align:left;vertical-align:top">
122
		<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>
123
	</tr>
124
	</tbody>
125
</table>
126
EOF;
127
128
	protected $heading = <<<EOF
129
<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">
130
	<tbody>
131
	<tr style="padding:0;text-align:left;vertical-align:top">
132
		<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">
133
			<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>
134
		</td>
135
	</tr>
136
	</tbody>
137
</table>
138
<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%%">
139
	<tbody>
140
	<tr style="padding:0;text-align:left;vertical-align:top">
141
		<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>
142
	</tr>
143
	</tbody>
144
</table>
145
EOF;
146
147
	protected $bodyBegin = <<<EOF
148
<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%">
149
	<tr style="padding:0;text-align:left;vertical-align:top">
150
		<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">
151
			<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">
152
				<tbody>
153
				<tr style="padding:0;text-align:left;vertical-align:top">
154
					<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">
155
						<table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
156
							<tbody>
157
							<tr style="padding:0;text-align:left;vertical-align:top">
158
								<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>
159
							</tr>
160
							</tbody>
161
						</table>
162
EOF;
163
164
	protected $bodyText = <<<EOF
165
<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%%">
166
	<tbody>
167
	<tr style="padding:0;text-align:left;vertical-align:top">
168
		<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">
169
			<table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
170
				<tr style="padding:0;text-align:left;vertical-align:top">
171
					<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">
172
						<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>
173
					</th>
174
					<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>
175
				</tr>
176
			</table>
177
		</th>
178
	</tr>
179
	</tbody>
180
</table>
181
EOF;
182
183
	protected $listBegin = <<<EOF
184
<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%%">
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
EOF;
190
191
	protected $listItem = <<<EOF
192
				<tr style="padding:0;text-align:left;vertical-align:top">
193
					<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;">
194
						<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>
195
					</td>
196
					<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">
197
						<p class="text-left" style="Margin:0;Margin-bottom:10px;color:#555;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>
198
					</td>
199
					<td 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"></td>
200
				</tr>
201
EOF;
202
203
	protected $listEnd = <<<EOF
204
			</table>
205
		</th>
206
	</tr>
207
	</tbody>
208
</table>
209
EOF;
210
211
	protected $buttonGroup = <<<EOF
212
<table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
213
	<tbody>
214
	<tr style="padding:0;text-align:left;vertical-align:top">
215
		<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>
216
	</tr>
217
	</tbody>
218
</table>
219
<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%%">
220
	<tbody>
221
	<tr style="padding:0;text-align:left;vertical-align:top">
222
		<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">
223
			<table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
224
				<tr style="padding:0;text-align:left;vertical-align:top">
225
					<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">
226
						<center data-parsed="" style="min-width:490px;width:100%%">
227
							<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">
228
								<tr style="padding:0;text-align:left;vertical-align:top">
229
									<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">
230
										<table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
231
											<tr style="padding:0;text-align:left;vertical-align:top">
232
												<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">
233
													<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>
234
												</td>
235
											</tr>
236
										</table>
237
									</td>
238
								</tr>
239
							</table>
240
							<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">
241
								<tr style="padding:0;text-align:left;vertical-align:top">
242
									<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">
243
										<table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
244
											<tr style="padding:0;text-align:left;vertical-align:top">
245
												<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">
246
													<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>
247
												</td>
248
											</tr>
249
										</table>
250
									</td>
251
								</tr>
252
							</table>
253
						</center>
254
					</th>
255
					<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>
256
				</tr>
257
			</table>
258
		</th>
259
	</tr>
260
	</tbody>
261
</table>
262
EOF;
263
264
	protected $button = <<<EOF
265
<table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
266
	<tbody>
267
	<tr style="padding:0;text-align:left;vertical-align:top">
268
		<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>
269
	</tr>
270
	</tbody>
271
</table>
272
<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%%">
273
	<tbody>
274
	<tr style="padding:0;text-align:left;vertical-align:top">
275
		<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">
276
			<table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
277
				<tr style="padding:0;text-align:left;vertical-align:top">
278
					<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">
279
						<center data-parsed="" style="min-width:490px;width:100%%">
280
							<table class="button btn default primary float-center" style="Margin:0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0;max-height:40px;padding:0;text-align:center;vertical-align:top;width:auto">
281
								<tr style="padding:0;text-align:left;vertical-align:top">
282
									<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">
283
										<table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
284
											<tr style="padding:0;text-align:left;vertical-align:top">
285
												<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">
286
													<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>
287
												</td>
288
											</tr>
289
										</table>
290
									</td>
291
								</tr>
292
							</table>
293
						</center>
294
					</th>
295
					<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>
296
				</tr>
297
			</table>
298
		</th>
299
	</tr>
300
	</tbody>
301
</table>
302
EOF;
303
304
	protected $bodyEnd = <<<EOF
305
306
					</td>
307
				</tr>
308
				</tbody>
309
			</table>
310
		</td>
311
	</tr>
312
</table>
313
EOF;
314
315
	protected $footer = <<<EOF
316
<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%%">
317
	<tbody>
318
	<tr style="padding:0;text-align:left;vertical-align:top">
319
		<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>
320
	</tr>
321
	</tbody>
322
</table>
323
<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%%">
324
	<tr style="padding:0;text-align:left;vertical-align:top">
325
		<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">
326
			<center data-parsed="" style="min-width:580px;width:100%%">
327
				<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%%">
328
					<tbody>
329
					<tr style="padding:0;text-align:left;vertical-align:top">
330
						<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>
331
					</tr>
332
					</tbody>
333
				</table>
334
				<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>
335
			</center>
336
		</td>
337
	</tr>
338
</table>
339
EOF;
340
341
	/**
342
	 * @param Defaults $themingDefaults
343
	 * @param IURLGenerator $urlGenerator
344
	 * @param IL10N $l10n
345
	 * @param string $emailId
346
	 * @param array $data
347
	 */
348
	public function __construct(Defaults $themingDefaults,
349
								IURLGenerator $urlGenerator,
350
								IL10N $l10n,
351
								$emailId,
352
								array $data) {
353
		$this->themingDefaults = $themingDefaults;
354
		$this->urlGenerator = $urlGenerator;
355
		$this->l10n = $l10n;
356
		$this->htmlBody .= $this->head;
357
		$this->emailId = $emailId;
358
		$this->data = $data;
359
	}
360
361
	/**
362
	 * Adds a header to the email
363
	 */
364
	public function addHeader() {
365
		if ($this->headerAdded) {
366
			return;
367
		}
368
		$this->headerAdded = true;
369
370
		$logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false));
371
		$this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl, $this->themingDefaults->getName()]);
372
	}
373
374
	/**
375
	 * Adds a heading to the email
376
	 *
377
	 * @param string $title
378
	 * @param string|bool $plainTitle Title that is used in the plain text email
379
	 *   if empty the $title is used, if false none will be used
380
	 */
381 View Code Duplication
	public function addHeading($title, $plainTitle = '') {
382
		if ($this->footerAdded) {
383
			return;
384
		}
385
		if ($plainTitle === '') {
386
			$plainTitle = $title;
387
		}
388
389
		$this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]);
390
		if ($plainTitle !== false) {
391
			$this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL;
392
		}
393
	}
394
395
	/**
396
	 * Open the HTML body when it is not already
397
	 */
398
	protected function ensureBodyIsOpened() {
399
		if ($this->bodyOpened) {
400
			return;
401
		}
402
403
		$this->htmlBody .= $this->bodyBegin;
404
		$this->bodyOpened = true;
405
	}
406
407
	/**
408
	 * Adds a paragraph to the body of the email
409
	 *
410
	 * @param string $text
411
	 * @param string|bool $plainText Text that is used in the plain text email
412
	 *   if empty the $text is used, if false none will be used
413
	 */
414 View Code Duplication
	public function addBodyText($text, $plainText = '') {
415
		if ($this->footerAdded) {
416
			return;
417
		}
418
		if ($plainText === '') {
419
			$plainText = $text;
420
		}
421
422
		$this->ensureBodyIsOpened();
423
424
		$this->htmlBody .= vsprintf($this->bodyText, [htmlspecialchars($text)]);
425
		if ($plainText !== false) {
426
			$this->plainBody .= $plainText . PHP_EOL . PHP_EOL;
427
		}
428
	}
429
430
	/**
431
	 * Adds a list item to the body of the email
432
	 *
433
	 * @param string $text
434
	 * @param string $metaInfo
435
	 * @param string $icon Absolute path, must be 16*16 pixels
436
	 * @param string $plainText Text that is used in the plain text email
437
	 *   if empty the $text is used, if false none will be used
438
	 * @param string $plainMetaInfo Meta info that is used in the plain text email
439
	 *   if empty the $metaInfo is used, if false none will be used
440
	 * @since 12.0.0
441
	 */
442
	public function addBodyListItem($text, $metaInfo = '', $icon = '', $plainText = '', $plainMetaInfo = '') {
443
		$this->ensureBodyListOpened();
444
445
		if ($plainText === '') {
446
			$plainText = $text;
447
		}
448
		if ($plainMetaInfo === '') {
449
			$plainMetaInfo = $metaInfo;
450
		}
451
452
		$htmlText = htmlspecialchars($text);
453
		if ($metaInfo) {
454
			$htmlText = '<em style="color:#777;">' . htmlspecialchars($metaInfo) . '</em><br>' . $htmlText;
455
		}
456
		if ($icon !== '') {
457
			$icon = '<img src="' . htmlspecialchars($icon) . '" alt="&bull;">';
458
		} else {
459
			$icon = '&bull;';
460
		}
461
		$this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]);
462
		if ($plainText !== false) {
463
			$this->plainBody .= '  * ' . $plainText;
464
			if ($plainMetaInfo !== false) {
465
				$this->plainBody .= ' (' . $plainMetaInfo . ')';
466
			}
467
			$this->plainBody .= PHP_EOL;
468
		}
469
	}
470
471
	protected function ensureBodyListOpened() {
472
		if ($this->bodyListOpened) {
473
			return;
474
		}
475
476
		$this->ensureBodyIsOpened();
477
		$this->bodyListOpened = true;
478
		$this->htmlBody .= $this->listBegin;
479
	}
480
481
	protected function ensureBodyListClosed() {
482
		if (!$this->bodyListOpened) {
483
			return;
484
		}
485
486
		$this->bodyListOpened = false;
487
		$this->htmlBody .= $this->listEnd;
488
	}
489
490
	/**
491
	 * Adds a button group of two buttons to the body of the email
492
	 *
493
	 * @param string $textLeft Text of left button
494
	 * @param string $urlLeft URL of left button
495
	 * @param string $textRight Text of right button
496
	 * @param string $urlRight URL of right button
497
	 * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used
498
	 * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used
499
	 */
500
	public function addBodyButtonGroup($textLeft,
501
									   $urlLeft,
502
									   $textRight,
503
									   $urlRight,
504
									   $plainTextLeft = '',
505
									   $plainTextRight = '') {
506
		if ($this->footerAdded) {
507
			return;
508
		}
509
		if ($plainTextLeft === '') {
510
			$plainTextLeft = $textLeft;
511
		}
512
513
		if ($plainTextRight === '') {
514
			$plainTextRight = $textRight;
515
		}
516
517
		$this->ensureBodyIsOpened();
518
		$this->ensureBodyListClosed();
519
520
		$color = $this->themingDefaults->getColorPrimary();
521
522
		$this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, htmlspecialchars($textLeft), $urlRight, htmlspecialchars($textRight)]);
523
		$this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL;
524
		$this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL;
525
526
	}
527
528
	/**
529
	 * Adds a button to the body of the email
530
	 *
531
	 * @param string $text Text of button
532
	 * @param string $url URL of button
533
	 * @param string $plainText Text of button in plain text version
534
	 * 		if empty the $text is used, if false none will be used
535
	 *
536
	 * @since 12.0.0
537
	 */
538
	public function addBodyButton($text, $url, $plainText = '') {
539
		if ($this->footerAdded) {
540
			return;
541
		}
542
543
		$this->ensureBodyIsOpened();
544
		$this->ensureBodyListClosed();
545
546
		if ($plainText === '') {
547
			$plainText = $text;
548
		}
549
550
		$color = $this->themingDefaults->getColorPrimary();
551
		$this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, htmlspecialchars($text)]);
552
553
		if ($plainText !== false) {
554
			$this->plainBody .= $plainText . ': ';
555
		}
556
557
		$this->plainBody .=  $url . PHP_EOL;
558
559
	}
560
561
	/**
562
	 * Close the HTML body when it is open
563
	 */
564
	protected function ensureBodyIsClosed() {
565
		if (!$this->bodyOpened) {
566
			return;
567
		}
568
569
		$this->ensureBodyListClosed();
570
571
		$this->htmlBody .= $this->bodyEnd;
572
		$this->bodyOpened = false;
573
	}
574
575
	/**
576
	 * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
577
	 *
578
	 * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
579
	 */
580
	public function addFooter($text = '') {
581
		if($text === '') {
582
			$text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically sent email, please do not reply.');
583
		}
584
585
		if ($this->footerAdded) {
586
			return;
587
		}
588
		$this->footerAdded = true;
589
590
		$this->ensureBodyIsClosed();
591
592
		$this->htmlBody .= vsprintf($this->footer, [$text]);
593
		$this->htmlBody .= $this->tail;
594
		$this->plainBody .= PHP_EOL . '-- ' . PHP_EOL;
595
		$this->plainBody .= str_replace('<br>', PHP_EOL, $text);
596
	}
597
598
	/**
599
	 * Returns the rendered HTML email as string
600
	 *
601
	 * @return string
602
	 */
603 View Code Duplication
	public function renderHtml() {
604
		if (!$this->footerAdded) {
605
			$this->footerAdded = true;
606
			$this->ensureBodyIsClosed();
607
			$this->htmlBody .= $this->tail;
608
		}
609
		return $this->htmlBody;
610
	}
611
612
	/**
613
	 * Returns the rendered plain text email as string
614
	 *
615
	 * @return string
616
	 */
617 View Code Duplication
	public function renderText() {
618
		if (!$this->footerAdded) {
619
			$this->footerAdded = true;
620
			$this->ensureBodyIsClosed();
621
			$this->htmlBody .= $this->tail;
622
		}
623
		return $this->plainBody;
624
	}
625
}
626