1 | <?php |
||
8 | class Email |
||
9 | { |
||
10 | /** |
||
11 | * @var Template |
||
12 | */ |
||
13 | public $template; |
||
14 | |||
15 | /** |
||
16 | * @var Utility |
||
17 | */ |
||
18 | public $utility; |
||
19 | |||
20 | /** |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $attachments; |
||
24 | |||
25 | /** |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $headers; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $message; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $subject; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $to; |
||
44 | |||
45 | public function __construct( Template $template, Utility $utility ) |
||
50 | |||
51 | /** |
||
52 | * @return Email |
||
53 | */ |
||
54 | public function compose( array $email ) |
||
71 | |||
72 | /** |
||
73 | * @param bool $plaintext |
||
74 | * |
||
75 | * @return string|null |
||
76 | */ |
||
77 | public function read( $plaintext = false ) |
||
83 | |||
84 | /** |
||
85 | * @return bool|null |
||
86 | */ |
||
87 | public function send() |
||
103 | |||
104 | /** |
||
105 | * @return array |
||
106 | */ |
||
107 | protected function buildHeaders( array $email ) |
||
128 | |||
129 | /** |
||
130 | * @return string |
||
131 | */ |
||
132 | protected function buildHtmlMessage( array $email ) |
||
145 | |||
146 | /** |
||
147 | * @param string $message |
||
148 | * |
||
149 | * @return string |
||
150 | */ |
||
151 | protected function buildPlainTextMessage( $message ) |
||
155 | |||
156 | /** |
||
157 | * @param string $message |
||
158 | * |
||
159 | * @return string |
||
160 | */ |
||
161 | protected function filterHtml( $message ) |
||
170 | |||
171 | /** |
||
172 | * @return string |
||
173 | */ |
||
174 | protected function getDefaultFrom() |
||
175 | { |
||
176 | return sprintf( '%s <%s>', |
||
177 | wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), |
||
178 | get_option( 'admin_email' ) |
||
179 | ); |
||
180 | } |
||
181 | |||
182 | /** |
||
183 | * @return array |
||
184 | */ |
||
185 | protected function normalize( $email ) |
||
186 | { |
||
187 | $defaults = array_flip([ |
||
188 | 'after', 'attachments', 'bcc', 'before', 'cc', 'from', 'message', 'reply-to', 'subject', |
||
189 | 'template', 'template-tags', 'to', |
||
190 | ]); |
||
191 | $defaults['from'] = $this->getDefaultFrom(); |
||
192 | |||
193 | $email = shortcode_atts( $defaults, $email ); |
||
194 | |||
195 | foreach( ['attachments', 'template-tags'] as $key ) { |
||
196 | $email[$key] = array_filter( (array) $email[$key] ); |
||
197 | } |
||
198 | if( empty( $email['reply-to'] )) { |
||
199 | $email['reply-to'] = $email['from']; |
||
200 | } |
||
201 | |||
202 | return apply_filters( 'castor/email/compose', $email, $this ); |
||
203 | } |
||
204 | |||
205 | /** |
||
206 | * @return void |
||
207 | */ |
||
208 | protected function reset() |
||
216 | |||
217 | /** |
||
218 | * @param string $templatePath |
||
219 | * |
||
220 | * @return void|string |
||
221 | */ |
||
222 | protected function renderTemplate( $templatePath, array $args = [] ) |
||
237 | |||
238 | /** |
||
239 | * @param string $template |
||
240 | * |
||
241 | * @return string |
||
242 | */ |
||
243 | protected function renderTemplateString( $template, array $args = [] ) |
||
250 | |||
251 | /** |
||
252 | * - remove invisible elements |
||
253 | * - replace certain elements with a line-break |
||
254 | * - replace certain table elements with a space |
||
255 | * - add a placeholder for plain-text bullets to list elements |
||
256 | * - strip all remaining HTML tags |
||
257 | * @return string |
||
258 | */ |
||
259 | protected function stripHtmlTags( $string ) |
||
271 | } |
||
272 |