|
1
|
|
|
<?php namespace EmailLog\Util; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Email Log Helper functions. |
|
5
|
|
|
* Some of these functions would be used the addons. |
|
6
|
|
|
*/ |
|
7
|
|
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Perform additional sanitation of emails. |
|
11
|
|
|
* |
|
12
|
|
|
* @since 1.9 |
|
13
|
|
|
* |
|
14
|
|
|
* @param string $email Email string to be sanitized. |
|
15
|
|
|
* @param bool $multiple (Optional) Should multiple emails be allowed. True by default. |
|
16
|
|
|
* |
|
17
|
|
|
* @return string Sanitized email. |
|
18
|
|
|
*/ |
|
19
|
|
|
function sanitize_email( $email, $multiple = true ) { |
|
20
|
9 |
|
$emails = explode( ',', $email ); |
|
21
|
9 |
|
if ( ! $multiple ) { |
|
22
|
2 |
|
$emails = array_slice( $emails, 0, 1 ); |
|
23
|
2 |
|
} |
|
24
|
|
|
|
|
25
|
9 |
|
$cleaned_emails = array_map( __NAMESPACE__ . '\\sanitize_email_with_name', $emails ); |
|
26
|
|
|
|
|
27
|
9 |
|
return implode( ', ', $cleaned_emails ); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Sanitize email with name. |
|
32
|
|
|
* |
|
33
|
|
|
* @since 1.9 |
|
34
|
|
|
* |
|
35
|
|
|
* @param string $string Email string to be sanitized. |
|
36
|
|
|
* |
|
37
|
|
|
* @return string Sanitized email. |
|
38
|
|
|
*/ |
|
39
|
|
|
function sanitize_email_with_name( $string ) { |
|
40
|
9 |
|
$string = trim( $string ); |
|
41
|
|
|
|
|
42
|
9 |
|
$bracket_pos = strpos( $string, '<' ); |
|
43
|
9 |
|
if ( false !== $bracket_pos ) { |
|
44
|
5 |
|
if ( $bracket_pos > 0 ) { |
|
45
|
5 |
|
$name = substr( $string, 0, $bracket_pos ); |
|
46
|
5 |
|
$name = trim( $name ); |
|
47
|
|
|
|
|
48
|
5 |
|
$email = substr( $string, $bracket_pos + 1 ); |
|
49
|
5 |
|
$email = str_replace( '>', '', $email ); |
|
50
|
|
|
|
|
51
|
5 |
|
return sanitize_text_field( $name ) . ' <' . \sanitize_email( $email ) . '>'; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
4 |
|
return \sanitize_email( $string ); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Gets the columns to export logs. |
|
60
|
|
|
* |
|
61
|
|
|
* If the More Fields add-on is active, additional columns are returned. |
|
62
|
|
|
* |
|
63
|
|
|
* @since 2.0.0 |
|
64
|
|
|
* |
|
65
|
|
|
* @return string[] List of Columns to export. |
|
66
|
|
|
*/ |
|
67
|
|
|
function get_log_columns_to_export() { |
|
68
|
|
|
|
|
69
|
|
|
if ( is_plugin_active( 'email-log-more-fields/email-log-more-fields.php' ) ) { |
|
70
|
|
|
return array( 'id', 'sent_date', 'to_email', 'subject', 'from', 'cc', 'bcc', 'reply-to', 'attachment' ); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return array( 'id', 'sent_date', 'to_email', 'subject' ); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Is it an admin request and not an ajax request. |
|
78
|
|
|
* |
|
79
|
|
|
* @since 2.1 |
|
80
|
|
|
* |
|
81
|
|
|
* @return bool True if admin non ajax request, False otherwise. |
|
82
|
|
|
*/ |
|
83
|
|
|
function is_admin_non_ajax_request() { |
|
84
|
|
|
if ( function_exists( 'wp_doing_ajax' ) && wp_doing_ajax() ) { |
|
85
|
|
|
return false; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
89
|
|
|
return false; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return is_admin(); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Checks the Checkbox when values are present in a given array. |
|
97
|
|
|
* |
|
98
|
|
|
* Use this function in Checkbox fields. |
|
99
|
|
|
* |
|
100
|
|
|
* @since 2.1.0 |
|
101
|
|
|
* |
|
102
|
|
|
* @param array $values List of all possible values. |
|
103
|
|
|
* @param string $current The current value to be checked. |
|
104
|
|
|
*/ |
|
105
|
|
|
function checked_array( $values, $current ) { |
|
106
|
|
|
if ( ! is_array( $values ) ) { |
|
|
|
|
|
|
107
|
|
|
return; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
if ( in_array( $current, $values ) ) { |
|
111
|
|
|
echo "checked='checked'"; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Returns the Email failure SVG. |
|
117
|
|
|
* |
|
118
|
|
|
* @see https://www.flaticon.com/free-icon/do-not-disturb-rounded-sign_61072 |
|
119
|
|
|
* |
|
120
|
|
|
* @since 2.4.0 |
|
121
|
|
|
* |
|
122
|
|
|
* @return string |
|
123
|
|
|
*/ |
|
124
|
|
|
function get_email_failed_svg() { |
|
125
|
|
|
return <<<EOT |
|
126
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?> |
|
127
|
|
|
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> |
|
128
|
|
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> |
|
129
|
|
|
<svg class="el_sent_status--failed" version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" |
|
130
|
|
|
width="15px" height="15px" viewBox="0 0 510 510" style="enable-background:new 0 0 510 510;" xml:space="preserve"> |
|
131
|
|
|
<g> |
|
132
|
|
|
<g id="do-not-disturb"> |
|
133
|
|
|
<path d="M255,0C114.75,0,0,114.75,0,255s114.75,255,255,255s255-114.75,255-255S395.25,0,255,0z M51,255c0-112.2,91.8-204,204-204 |
|
134
|
|
|
c45.9,0,89.25,15.3,124.95,43.35l-285.6,285.6C66.3,344.25,51,300.9,51,255z M255,459c-45.9,0-89.25-15.3-124.95-43.35 |
|
135
|
|
|
L415.65,130.05C443.7,165.75,459,209.1,459,255C459,367.2,367.2,459,255,459z"/> |
|
136
|
|
|
</g> |
|
137
|
|
|
</g> |
|
138
|
|
|
<g> |
|
139
|
|
|
</g> |
|
140
|
|
|
<g> |
|
141
|
|
|
</g> |
|
142
|
|
|
<g> |
|
143
|
|
|
</g> |
|
144
|
|
|
<g> |
|
145
|
|
|
</g> |
|
146
|
|
|
<g> |
|
147
|
|
|
</g> |
|
148
|
|
|
<g> |
|
149
|
|
|
</g> |
|
150
|
|
|
<g> |
|
151
|
|
|
</g> |
|
152
|
|
|
<g> |
|
153
|
|
|
</g> |
|
154
|
|
|
<g> |
|
155
|
|
|
</g> |
|
156
|
|
|
<g> |
|
157
|
|
|
</g> |
|
158
|
|
|
<g> |
|
159
|
|
|
</g> |
|
160
|
|
|
<g> |
|
161
|
|
|
</g> |
|
162
|
|
|
<g> |
|
163
|
|
|
</g> |
|
164
|
|
|
<g> |
|
165
|
|
|
</g> |
|
166
|
|
|
<g> |
|
167
|
|
|
</g> |
|
168
|
|
|
</svg> |
|
169
|
|
|
EOT; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Returns the Email sent SVG. |
|
174
|
|
|
* |
|
175
|
|
|
* @see https://www.flaticon.com/free-icon/tick-inside-circle_61222 |
|
176
|
|
|
* |
|
177
|
|
|
* @since 2.4.0 |
|
178
|
|
|
* |
|
179
|
|
|
* @return string |
|
180
|
|
|
*/ |
|
181
|
|
|
function get_email_sent_svg() { |
|
182
|
|
|
return <<<EOT |
|
183
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?> |
|
184
|
|
|
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> |
|
185
|
|
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> |
|
186
|
|
|
<svg class="el_sent_status--sent" version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" |
|
187
|
|
|
width="15px" height="15px" viewBox="0 0 510 510" style="enable-background:new 0 0 510 510;" xml:space="preserve"> |
|
188
|
|
|
<g> |
|
189
|
|
|
<g id="check-circle-outline"> |
|
190
|
|
|
<path d="M150.45,206.55l-35.7,35.7L229.5,357l255-255l-35.7-35.7L229.5,285.6L150.45,206.55z M459,255c0,112.2-91.8,204-204,204 |
|
191
|
|
|
S51,367.2,51,255S142.8,51,255,51c20.4,0,38.25,2.55,56.1,7.65l40.801-40.8C321.3,7.65,288.15,0,255,0C114.75,0,0,114.75,0,255 |
|
192
|
|
|
s114.75,255,255,255s255-114.75,255-255H459z"/> |
|
193
|
|
|
</g> |
|
194
|
|
|
</g> |
|
195
|
|
|
<g> |
|
196
|
|
|
</g> |
|
197
|
|
|
<g> |
|
198
|
|
|
</g> |
|
199
|
|
|
<g> |
|
200
|
|
|
</g> |
|
201
|
|
|
<g> |
|
202
|
|
|
</g> |
|
203
|
|
|
<g> |
|
204
|
|
|
</g> |
|
205
|
|
|
<g> |
|
206
|
|
|
</g> |
|
207
|
|
|
<g> |
|
208
|
|
|
</g> |
|
209
|
|
|
<g> |
|
210
|
|
|
</g> |
|
211
|
|
|
<g> |
|
212
|
|
|
</g> |
|
213
|
|
|
<g> |
|
214
|
|
|
</g> |
|
215
|
|
|
<g> |
|
216
|
|
|
</g> |
|
217
|
|
|
<g> |
|
218
|
|
|
</g> |
|
219
|
|
|
<g> |
|
220
|
|
|
</g> |
|
221
|
|
|
<g> |
|
222
|
|
|
</g> |
|
223
|
|
|
<g> |
|
224
|
|
|
</g> |
|
225
|
|
|
</svg> |
|
226
|
|
|
|
|
227
|
|
|
EOT; |
|
228
|
|
|
|
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* @param int $result |
|
233
|
|
|
* |
|
234
|
|
|
* @return string |
|
235
|
|
|
*/ |
|
236
|
|
|
function get_log_row_class_by_result_code( $result ) { |
|
237
|
|
|
$log_row_classes = array( |
|
238
|
|
|
0 => 'el_email_sent_status--failed', |
|
239
|
|
|
1 => 'el_email_sent_status--sent', |
|
240
|
|
|
); |
|
241
|
|
|
if ( empty ( $result ) ) { |
|
242
|
|
|
return $log_row_classes[0]; |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
$result = absint( $result ); |
|
246
|
|
|
if ( array_key_exists( $result, $log_row_classes ) ) { |
|
247
|
|
|
return $log_row_classes[ $result ]; |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
return $log_row_classes[0]; |
|
251
|
|
|
} |