1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
<?php
class EchoHtmlEmailFormatter extends EchoEventFormatter {
// phpcs:disable Generic.Files.LineLength
const PRIMARY_LINK_STYLE = 'cursor:pointer; text-align:center; text-decoration:none; padding:.45em 0.6em .45em; color:#FFF; background:#36C; font-family: Arial, Helvetica, sans-serif;font-size: 13px;';
const SECONDARY_LINK_STYLE = 'text-decoration: none;font-size: 10px;font-family: Arial, Helvetica, sans-serif; color: #72777D;';
// phpcs:enable Generic.Files.LineLength
protected function formatModel( EchoEventPresentationModel $model ) {
$subject = $model->getSubjectMessage()->parse();
$intro = $model->getHeaderMessage()->parse();
$bodyMsg = $model->getBodyMessage();
$summary = $bodyMsg ? $bodyMsg->parse() : '';
$actions = [];
$primaryLink = $model->getPrimaryLinkWithMarkAsRead();
if ( $primaryLink ) {
$actions[] = $this->renderLink( $primaryLink, self::PRIMARY_LINK_STYLE );
}
foreach ( array_filter( $model->getSecondaryLinks() ) as $secondaryLink ) {
$actions[] = $this->renderLink( $secondaryLink, self::SECONDARY_LINK_STYLE );
}
$iconUrl = wfExpandUrl(
EchoIcon::getRasterizedUrl( $model->getIconType(), $this->language->getCode() ),
PROTO_CANONICAL
);
$body = $this->renderBody(
$this->language,
$iconUrl,
$summary,
implode( " ", $actions ),
$intro,
$this->getFooter()
);
return [
'body' => $body,
'subject' => $subject,
];
}
private function renderBody( Language $lang, $emailIcon, $summary, $action, $intro, $footer ) {
$alignStart = $lang->alignStart();
$langCode = $lang->getHtmlCode();
$langDir = $lang->getDir();
$iconImgSrc = Sanitizer::encodeAttribute( $emailIcon );
global $wgCanonicalServer;
// phpcs:disable Generic.Files.LineLength
return <<< EOF
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
@media only screen and (max-width: 480px){
table[id="email-container"]{max-width:600px !important; width:100% !important;}
}
</style>
<base href="{$wgCanonicalServer}">
</head><body>
<table cellspacing="0" cellpadding="0" border="0" width="100%" align="center" lang="{$langCode}" dir="{$langDir}">
<tr>
<td bgcolor="#EAECF0"><center>
<br /><br />
<table cellspacing="0" cellpadding="0" border="0" width="600" id="email-container">
<tr>
<td bgcolor="#FFFFFF" width="5%"> </td>
<td bgcolor="#FFFFFF" width="10%"> </td>
<td bgcolor="#FFFFFF" width="80%" style="line-height:40px;"> </td>
<td bgcolor="#FFFFFF" width="5%"> </td>
</tr><tr>
<td bgcolor="#FFFFFF" rowspan="2"> </td>
<td bgcolor="#FFFFFF" align="center" valign="top" rowspan="2"><img src="{$iconImgSrc}" alt="" height="30" width="30"></td>
<td bgcolor="#FFFFFF" align="{$alignStart}" style="font-family: Arial, Helvetica, sans-serif; font-size:13px; line-height:20px; color:#72777D;">{$intro}</td>
<td bgcolor="#FFFFFF" rowspan="2"> </td>
</tr><tr>
<td bgcolor="#FFFFFF" align="{$alignStart}" style="font-family: Arial, Helvetica, sans-serif; line-height: 20px; font-weight: 600;">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td bgcolor="#FFFFFF" align="{$alignStart}" style="font-family: Arial, Helvetica, sans-serif; padding-top: 8px; font-size:13px; font-weight: bold; color: #54595D;">
{$summary}
</td>
</tr>
</table>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td bgcolor="#FFFFFF" align="{$alignStart}" style="font-family: Arial, Helvetica, sans-serif; font-size:14px; padding-top: 25px;">
{$action}
</td>
</tr>
</table>
</td>
</tr><tr>
<td bgcolor="#FFFFFF"> </td>
<td bgcolor="#FFFFFF"> </td>
<td bgcolor="#FFFFFF" style="line-height:40px;"> </td>
<td bgcolor="#FFFFFF"> </td>
</tr><tr>
<td> </td>
<td> </td>
<td align="{$alignStart}" style="font-family: Arial, Helvetica, sans-serif; font-size:10px; line-height:13px; color:#72777D; padding:10px 20px;"><br />
{$footer}
<br /><br />
</td>
<td> </td>
</tr><tr>
<td colspan="4"> </td>
</tr>
</table>
<br><br></center>
</td>
</tr>
</table>
</body></html>
EOF;
// phpcs:enable Generic.Files.LineLength
}
/**
* @return string
*/
public function getFooter() {
global $wgEchoEmailFooterAddress;
$preferenceLink = $this->renderLink(
[
'label' => $this->msg( 'echo-email-html-footer-preference-link-text', $this->user )
->text(),
'url' => SpecialPage::getTitleFor( 'Preferences', false, 'mw-prefsection-echo' )
->getFullURL( '', false, PROTO_CANONICAL ),
],
'text-decoration: none; color: #36C;'
);
$footer = $this->msg( 'echo-email-html-footer-with-link' )
->rawParams( $preferenceLink )
->params( $this->user )
->parse();
if ( $wgEchoEmailFooterAddress ) {
$footer .= '<br />' . $wgEchoEmailFooterAddress;
}
return $footer;
}
private function renderLink( $link, $style ) {
return Html::element(
'a',
[
'href' => wfExpandUrl( $link['url'], PROTO_CANONICAL ),
'style' => $style,
],
$link['label']
);
}
}
|