Completed
Push — master ( b5d31e...39468f )
by Lukas
13:10
created

EMailTemplate   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 386
Duplicated Lines 5.18 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 20
loc 386
rs 10
c 0
b 0
f 0
wmc 25
lcom 1
cbo 3

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A addHeader() 0 9 2
A addHeading() 0 11 3
A addBodyText() 0 16 4
B addBodyButtonGroup() 0 23 5
A addFooter() 0 20 4
A renderHTML() 10 10 3
A renderText() 10 10 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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="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">
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 $bodyEnd = <<<EOF
231
232
					</td>
233
				</tr>
234
				</tbody>
235
			</table>
236
		</td>
237
	</tr>
238
</table>
239
EOF;
240
241
	protected $footer = <<<EOF
242
<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%%">
243
	<tbody>
244
	<tr style="padding:0;text-align:left;vertical-align:top">
245
		<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>
246
	</tr>
247
	</tbody>
248
</table>
249
<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%%">
250
	<tr style="padding:0;text-align:left;vertical-align:top">
251
		<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">
252
			<center data-parsed="" style="min-width:580px;width:100%%">
253
				<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%%">
254
					<tbody>
255
					<tr style="padding:0;text-align:left;vertical-align:top">
256
						<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>
257
					</tr>
258
					</tbody>
259
				</table>
260
				<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>
261
			</center>
262
		</td>
263
	</tr>
264
</table>
265
EOF;
266
267
	/**
268
	 * @param Defaults $themingDefaults
269
	 * @param IURLGenerator $urlGenerator
270
	 * @param IL10N $l10n
271
	 */
272
	public function __construct(Defaults $themingDefaults,
273
								IURLGenerator $urlGenerator,
274
								IL10N $l10n) {
275
		$this->themingDefaults = $themingDefaults;
276
		$this->urlGenerator = $urlGenerator;
277
		$this->l10n = $l10n;
278
		$this->htmlBody .= $this->head;
279
	}
280
281
	/**
282
	 * Adds a header to the email
283
	 */
284
	public function addHeader() {
285
		if ($this->headerAdded) {
286
			return;
287
		}
288
		$this->headerAdded = true;
289
290
		$logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo());
291
		$this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl]);
292
	}
293
294
	/**
295
	 * Adds a heading to the email
296
	 *
297
	 * @param string $title
298
	 * @param string $plainTitle Title that is used in the plain text email - if empty the $title is used
299
	 */
300
	public function addHeading($title, $plainTitle = '') {
301
		if ($this->footerAdded) {
302
			return;
303
		}
304
		if ($plainTitle === '') {
305
			$plainTitle = $title;
306
		}
307
308
		$this->htmlBody .= vsprintf($this->heading, [$title]);
309
		$this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL;
310
	}
311
312
	/**
313
	 * Adds a paragraph to the body of the email
314
	 *
315
	 * @param string $text
316
	 * @param string $plainText Text that is used in the plain text email - if empty the $text is used
317
	 */
318
	public function addBodyText($text, $plainText = '') {
319
		if ($this->footerAdded) {
320
			return;
321
		}
322
		if ($plainText === '') {
323
			$plainText = $text;
324
		}
325
326
		if (!$this->bodyOpened) {
327
			$this->htmlBody .= $this->bodyBegin;
328
			$this->bodyOpened = true;
329
		}
330
331
		$this->htmlBody .= vsprintf($this->bodyText, [$text]);
332
		$this->plainBody .= $plainText . PHP_EOL . PHP_EOL;
333
	}
334
335
	/**
336
	 * Adds a button group of two buttons to the body of the email
337
	 *
338
	 * @param string $textLeft Text of left button
339
	 * @param string $urlLeft URL of left button
340
	 * @param string $textRight Text of right button
341
	 * @param string $urlRight URL of right button
342
	 * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used
343
	 * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used
344
	 */
345
	public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight, $plainTextLeft = '', $plainTextRight = '') {
346
		if ($this->footerAdded) {
347
			return;
348
		}
349
		if ($plainTextLeft === '') {
350
			$plainTextLeft = $textLeft;
351
		}
352
353
		if ($plainTextRight === '') {
354
			$plainTextRight = $textRight;
355
		}
356
357
		if (!$this->bodyOpened) {
358
			$this->htmlBody .= $this->bodyBegin;
359
			$this->bodyOpened = true;
360
		}
361
362
		$color = $this->themingDefaults->getColorPrimary();
363
		$this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textLeft, $urlRight, $textRight]);
364
		$this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL;
365
		$this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL;
366
367
	}
368
369
	/**
370
	 * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
371
	 *
372
	 * @param string $text
373
	 */
374
	public function addFooter($text = '') {
375
		if($text === '') {
376
			$text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically generated email, please do not reply.');
377
		}
378
379
		if ($this->footerAdded) {
380
			return;
381
		}
382
		$this->footerAdded = true;
383
384
		if ($this->bodyOpened) {
385
			$this->htmlBody .= $this->bodyEnd;
386
			$this->bodyOpened = false;
387
		}
388
389
		$this->htmlBody .= vsprintf($this->footer, [$text]);
390
		$this->htmlBody .= $this->tail;
391
		$this->plainBody .= '--' . PHP_EOL;
392
		$this->plainBody .= str_replace('<br>', PHP_EOL, $text);
393
	}
394
395
	/**
396
	 * Returns the rendered HTML email as string
397
	 *
398
	 * @return string
399
	 */
400 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...
401
		if (!$this->footerAdded) {
402
			$this->footerAdded = true;
403
			if ($this->bodyOpened) {
404
				$this->htmlBody .= $this->bodyEnd;
405
			}
406
			$this->htmlBody .= $this->tail;
407
		}
408
		return $this->htmlBody;
409
	}
410
411
	/**
412
	 * Returns the rendered plain text email as string
413
	 *
414
	 * @return string
415
	 */
416 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...
417
		if (!$this->footerAdded) {
418
			$this->footerAdded = true;
419
			if ($this->bodyOpened) {
420
				$this->htmlBody .= $this->bodyEnd;
421
			}
422
			$this->htmlBody .= $this->tail;
423
		}
424
		return $this->plainBody;
425
	}
426
}
427