1
|
|
|
<?php namespace EmailLog\Util; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Email Log Helper functions. |
5
|
|
|
* Some of these functions would be used the addons. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Perform additional sanitation of emails. |
10
|
|
|
* |
11
|
|
|
* @since 1.9 |
12
|
|
|
* |
13
|
|
|
* @param string $email Email string to be sanitized. |
14
|
|
|
* @param bool $multiple (Optional) Should multiple emails be allowed. True by default. |
15
|
|
|
* |
16
|
|
|
* @return string Sanitized email. |
17
|
|
|
*/ |
18
|
|
|
function sanitize_email( $email, $multiple = true ) { |
19
|
16 |
|
$emails = explode( ',', $email ); |
20
|
16 |
|
if ( ! $multiple ) { |
21
|
4 |
|
$emails = array_slice( $emails, 0, 1 ); |
22
|
4 |
|
} |
23
|
|
|
|
24
|
16 |
|
$cleaned_emails = array_map( __NAMESPACE__ . '\\sanitize_email_with_name', $emails ); |
25
|
|
|
|
26
|
16 |
|
return implode( ', ', $cleaned_emails ); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Sanitize email with name. |
31
|
|
|
* |
32
|
|
|
* @since 1.9 |
33
|
|
|
* |
34
|
|
|
* @param $string $email Email string to be sanitized. |
|
|
|
|
35
|
|
|
* |
36
|
|
|
* @return string Sanitized email. |
37
|
|
|
*/ |
38
|
|
|
function sanitize_email_with_name( $string ) { |
39
|
16 |
|
$string = trim( $string ); |
40
|
|
|
|
41
|
16 |
|
$bracket_pos = strpos( $string, '<' ); |
42
|
16 |
|
if ( false !== $bracket_pos ) { |
43
|
|
|
// Text before the bracketed email is the name. |
44
|
8 |
|
if ( $bracket_pos > 0 ) { |
45
|
8 |
|
$name = substr( $string, 0, $bracket_pos ); |
46
|
8 |
|
$name = str_replace( '"', '', $name ); |
47
|
8 |
|
$name = trim( $name ); |
48
|
|
|
|
49
|
8 |
|
$email = substr( $string, $bracket_pos + 1 ); |
50
|
8 |
|
$email = str_replace( '>', '', $email ); |
51
|
|
|
|
52
|
8 |
|
return sanitize_text_field( $name ) . ' <' . \sanitize_email( $email ) . '>'; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
8 |
|
return \sanitize_email( $string ); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Gets the columns to export logs. |
61
|
|
|
* |
62
|
|
|
* If the More Fields add-on is active, additional columns are returned. |
63
|
|
|
* |
64
|
|
|
* @since 2.0.0 |
65
|
|
|
* |
66
|
|
|
* @return array List of Columns to export. |
67
|
|
|
*/ |
68
|
|
|
function get_log_columns_to_export() { |
69
|
|
|
|
70
|
|
|
if ( is_plugin_active( 'email-log-more-fields/email-log-more-fields.php' ) ) { |
71
|
|
|
return array( 'id', 'sent_date', 'to_email', 'subject', 'from', 'cc', 'bcc', 'reply-to', 'attachment' ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return array( 'id', 'sent_date', 'to_email', 'subject' ); |
75
|
|
|
} |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.