Completed
Push — master ( d36751...81d373 )
by Lukas
26:06 queued 14:56
created

EMailTemplate::addHeader()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 9
rs 9.6666
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
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 the footer is added */
58
	protected $footerAdded = false;
59
60
	protected $head = <<<EOF
61
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
62
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#f3f3f3!important">
63
<head>
64
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
65
	<meta name="viewport" content="width=device-width">
66
	<title></title>
67
	<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>
68
</head>
69
<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">
70
	<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">
71
	</span>
72
	<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%">
73
		<tr style="padding:0;text-align:left;vertical-align:top">
74
			<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">
75
				<center data-parsed="" style="min-width:580px;width:100%">
76
EOF;
77
78
	protected $tail = <<<EOF
79
					</center>
80
				</td>
81
			</tr>
82
		</table>
83
		<!-- prevent Gmail on iOS font size manipulation -->
84
		<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>
85
	</body>
86
</html>
87
EOF;
88
89
	protected $header = <<<EOF
90
<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%%">
91
	<tr style="padding:0;text-align:left;vertical-align:top">
92
		<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">
93
			<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">
94
				<tbody>
95
				<tr style="padding:0;text-align:left;vertical-align:top">
96
					<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">
97
						<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%%">
98
							<tbody>
99
							<tr style="padding:0;text-align:left;vertical-align:top">
100
								<center data-parsed="" style="min-width:580px;width:100%%">
101
									<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;max-height:100%%;max-width:100px;outline:0;text-align:center;text-decoration:none;width:auto">
102
								</center>
103
							</tr>
104
							</tbody>
105
						</table>
106
					</td>
107
				</tr>
108
				</tbody>
109
			</table>
110
		</td>
111
	</tr>
112
</table>
113
<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%%">
114
	<tbody>
115
	<tr style="padding:0;text-align:left;vertical-align:top">
116
		<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>
117
	</tr>
118
	</tbody>
119
</table>
120
EOF;
121
122
	protected $heading = <<<EOF
123
<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">
124
	<tbody>
125
	<tr style="padding:0;text-align:left;vertical-align:top">
126
		<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">
127
			<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>
128
		</td>
129
	</tr>
130
	</tbody>
131
</table>
132
<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%%">
133
	<tbody>
134
	<tr style="padding:0;text-align:left;vertical-align:top">
135
		<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>
136
	</tr>
137
	</tbody>
138
</table>
139
EOF;
140
141
	protected $bodyBegin = <<<EOF
142
<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%">
143
	<tr style="padding:0;text-align:left;vertical-align:top">
144
		<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">
145
			<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">
146
				<tbody>
147
				<tr style="padding:0;text-align:left;vertical-align:top">
148
					<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">
149
						<table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
150
							<tbody>
151
							<tr style="padding:0;text-align:left;vertical-align:top">
152
								<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>
153
							</tr>
154
							</tbody>
155
						</table>
156
EOF;
157
158
	protected $bodyText = <<<EOF
159
<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%%">
160
	<tbody>
161
	<tr style="padding:0;text-align:left;vertical-align:top">
162
		<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">
163
			<table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
164
				<tr style="padding:0;text-align:left;vertical-align:top">
165
					<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">
166
						<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>
167
					</th>
168
					<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>
169
				</tr>
170
			</table>
171
		</th>
172
	</tr>
173
	</tbody>
174
</table>
175
EOF;
176
177
	protected $buttonGroup = <<<EOF
178
<table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
179
	<tbody>
180
	<tr style="padding:0;text-align:left;vertical-align:top">
181
		<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>
182
	</tr>
183
	</tbody>
184
</table>
185
<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%%">
186
	<tbody>
187
	<tr style="padding:0;text-align:left;vertical-align:top">
188
		<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">
189
			<table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
190
				<tr style="padding:0;text-align:left;vertical-align:top">
191
					<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">
192
						<center data-parsed="" style="min-width:490px;width:100%%">
193
							<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">
194
								<tr style="padding:0;text-align:left;vertical-align:top">
195
									<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">
196
										<table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
197
											<tr style="padding:0;text-align:left;vertical-align:top">
198
												<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">
199
													<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>
200
												</td>
201
											</tr>
202
										</table>
203
									</td>
204
								</tr>
205
							</table>
206
							<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">
207
								<tr style="padding:0;text-align:left;vertical-align:top">
208
									<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">
209
										<table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
210
											<tr style="padding:0;text-align:left;vertical-align:top">
211
												<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">
212
													<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>
213
												</td>
214
											</tr>
215
										</table>
216
									</td>
217
								</tr>
218
							</table>
219
						</center>
220
					</th>
221
					<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>
222
				</tr>
223
			</table>
224
		</th>
225
	</tr>
226
	</tbody>
227
</table>
228
EOF;
229
230
	protected $button = <<<EOF
231
<table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
232
	<tbody>
233
	<tr style="padding:0;text-align:left;vertical-align:top">
234
		<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>
235
	</tr>
236
	</tbody>
237
</table>
238
<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%%">
239
	<tbody>
240
	<tr style="padding:0;text-align:left;vertical-align:top">
241
		<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">
242
			<table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
243
				<tr style="padding:0;text-align:left;vertical-align:top">
244
					<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">
245
						<center data-parsed="" style="min-width:490px;width:100%%">
246
							<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">
247
								<tr style="padding:0;text-align:left;vertical-align:top">
248
									<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">
249
										<table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
250
											<tr style="padding:0;text-align:left;vertical-align:top">
251
												<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">
252
													<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>
253
												</td>
254
											</tr>
255
										</table>
256
									</td>
257
								</tr>
258
							</table>
259
						</center>
260
					</th>
261
					<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>
262
				</tr>
263
			</table>
264
		</th>
265
	</tr>
266
	</tbody>
267
</table>
268
EOF;
269
270
	protected $bodyEnd = <<<EOF
271
272
					</td>
273
				</tr>
274
				</tbody>
275
			</table>
276
		</td>
277
	</tr>
278
</table>
279
EOF;
280
281
	protected $footer = <<<EOF
282
<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%%">
283
	<tbody>
284
	<tr style="padding:0;text-align:left;vertical-align:top">
285
		<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>
286
	</tr>
287
	</tbody>
288
</table>
289
<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%%">
290
	<tr style="padding:0;text-align:left;vertical-align:top">
291
		<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">
292
			<center data-parsed="" style="min-width:580px;width:100%%">
293
				<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%%">
294
					<tbody>
295
					<tr style="padding:0;text-align:left;vertical-align:top">
296
						<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>
297
					</tr>
298
					</tbody>
299
				</table>
300
				<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>
301
			</center>
302
		</td>
303
	</tr>
304
</table>
305
EOF;
306
307
	/**
308
	 * @param Defaults $themingDefaults
309
	 * @param IURLGenerator $urlGenerator
310
	 * @param IL10N $l10n
311
	 */
312
	public function __construct(Defaults $themingDefaults,
313
								IURLGenerator $urlGenerator,
314
								IL10N $l10n) {
315
		$this->themingDefaults = $themingDefaults;
316
		$this->urlGenerator = $urlGenerator;
317
		$this->l10n = $l10n;
318
		$this->htmlBody .= $this->head;
319
	}
320
321
	/**
322
	 * Adds a header to the email
323
	 */
324
	public function addHeader() {
325
		if ($this->headerAdded) {
326
			return;
327
		}
328
		$this->headerAdded = true;
329
330
		$logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo());
331
		$this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl, $this->themingDefaults->getName()]);
332
	}
333
334
	/**
335
	 * Adds a heading to the email
336
	 *
337
	 * @param string $title
338
	 * @param string $plainTitle|bool Title that is used in the plain text email
0 ignored issues
show
Documentation introduced by
There is no parameter named $plainTitle|bool. Did you maybe mean $plainTitle?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
339
	 *   if empty the $title is used, if false none will be used
340
	 */
341
	public function addHeading($title, $plainTitle = '') {
342
		if ($this->footerAdded) {
343
			return;
344
		}
345
		if ($plainTitle === '') {
346
			$plainTitle = $title;
347
		}
348
349
		$this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]);
350
		if ($plainTitle !== false) {
351
			$this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL;
352
		}
353
	}
354
355
	/**
356
	 * Adds a paragraph to the body of the email
357
	 *
358
	 * @param string $text
359
	 * @param string|bool $plainText Text that is used in the plain text email
360
	 *   if empty the $text is used, if false none will be used
361
	 */
362
	public function addBodyText($text, $plainText = '') {
363
		if ($this->footerAdded) {
364
			return;
365
		}
366
		if ($plainText === '') {
367
			$plainText = $text;
368
		}
369
370
		if (!$this->bodyOpened) {
371
			$this->htmlBody .= $this->bodyBegin;
372
			$this->bodyOpened = true;
373
		}
374
375
		$this->htmlBody .= vsprintf($this->bodyText, [htmlspecialchars($text)]);
376
		if ($plainText !== false) {
377
			$this->plainBody .= $plainText . PHP_EOL . PHP_EOL;
378
		}
379
	}
380
381
	/**
382
	 * Adds a button group of two buttons to the body of the email
383
	 *
384
	 * @param string $textLeft Text of left button
385
	 * @param string $urlLeft URL of left button
386
	 * @param string $textRight Text of right button
387
	 * @param string $urlRight URL of right button
388
	 * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used
389
	 * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used
390
	 */
391
	public function addBodyButtonGroup($textLeft,
392
									   $urlLeft,
393
									   $textRight,
394
									   $urlRight,
395
									   $plainTextLeft = '',
396
									   $plainTextRight = '') {
397
		if ($this->footerAdded) {
398
			return;
399
		}
400
		if ($plainTextLeft === '') {
401
			$plainTextLeft = $textLeft;
402
		}
403
404
		if ($plainTextRight === '') {
405
			$plainTextRight = $textRight;
406
		}
407
408
		if (!$this->bodyOpened) {
409
			$this->htmlBody .= $this->bodyBegin;
410
			$this->bodyOpened = true;
411
		}
412
413
		$color = $this->themingDefaults->getColorPrimary();
414
415
		$this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, htmlspecialchars($textLeft), $urlRight, htmlspecialchars($textRight)]);
416
		$this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL;
417
		$this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL;
418
419
	}
420
421
	/**
422
	 * Adds a button to the body of the email
423
	 *
424
	 * @param string $text Text of button
425
	 * @param string $url URL of button
426
	 * @param string $plainText Text of button in plain text version
427
	 * 		if empty the $text is used, if false none will be used
428
	 *
429
	 * @since 12.0.0
430
	 */
431
	public function addBodyButton($text, $url, $plainText = '') {
432
		if ($this->footerAdded) {
433
			return;
434
		}
435
436
		if (!$this->bodyOpened) {
437
			$this->htmlBody .= $this->bodyBegin;
438
			$this->bodyOpened = true;
439
		}
440
441
		if ($plainText === '') {
442
			$plainText = $text;
443
		}
444
445
		$color = $this->themingDefaults->getColorPrimary();
446
		$this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, htmlspecialchars($text)]);
447
448
		if ($plainText !== false) {
449
			$this->plainBody .= $plainText . ': ';
450
		}
451
452
		$this->plainBody .=  $url . PHP_EOL;
453
454
	}
455
456
	/**
457
	 * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
458
	 *
459
	 * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically generated email" will be used
460
	 */
461
	public function addFooter($text = '') {
462
		if($text === '') {
463
			$text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically generated email, please do not reply.');
464
		}
465
466
		if ($this->footerAdded) {
467
			return;
468
		}
469
		$this->footerAdded = true;
470
471
		if ($this->bodyOpened) {
472
			$this->htmlBody .= $this->bodyEnd;
473
			$this->bodyOpened = false;
474
		}
475
476
		$this->htmlBody .= vsprintf($this->footer, [$text]);
477
		$this->htmlBody .= $this->tail;
478
		$this->plainBody .= PHP_EOL . '-- ' . PHP_EOL;
479
		$this->plainBody .= str_replace('<br>', PHP_EOL, $text);
480
	}
481
482
	/**
483
	 * Returns the rendered HTML email as string
484
	 *
485
	 * @return string
486
	 */
487 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...
488
		if (!$this->footerAdded) {
489
			$this->footerAdded = true;
490
			if ($this->bodyOpened) {
491
				$this->htmlBody .= $this->bodyEnd;
492
			}
493
			$this->htmlBody .= $this->tail;
494
		}
495
		return $this->htmlBody;
496
	}
497
498
	/**
499
	 * Returns the rendered plain text email as string
500
	 *
501
	 * @return string
502
	 */
503 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...
504
		if (!$this->footerAdded) {
505
			$this->footerAdded = true;
506
			if ($this->bodyOpened) {
507
				$this->htmlBody .= $this->bodyEnd;
508
			}
509
			$this->htmlBody .= $this->tail;
510
		}
511
		return $this->plainBody;
512
	}
513
}
514