/var/www/html/wp-content/plugins/contact-form-7/includes/validation-functions.php


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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php

/**
 * Checks whether a string is a valid NAME token.
 *
 * ID and NAME tokens must begin with a letter ([A-Za-z])
 * and may be followed by any number of letters, digits ([0-9]),
 * hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
 *
 * @link http://www.w3.org/TR/html401/types.html#h-6.2
 *
 * @return bool True if it is a valid name, false if not.
 */
function wpcf7_is_name$text ) {
    return 
preg_match'/^[A-Za-z][-A-Za-z0-9_:.]*$/'$text );
}


/**
 * Checks whether the given text is a well-formed email address.
 */
function wpcf7_is_email$text ) {
    
$result is_email$text );
    return 
apply_filters'wpcf7_is_email'$result$text );
}


/**
 * Checks whether the given text is a well-formed URL.
 */
function wpcf7_is_url$text ) {
    
$scheme wp_parse_url$textPHP_URL_SCHEME );
    
$result $scheme && in_array$schemewp_allowed_protocols(), true );
    return 
apply_filters'wpcf7_is_url'$result$text );
}


/**
 * Checks whether the given text is a well-formed telephone number.
 */
function wpcf7_is_tel$text ) {
    
$text preg_replace'%[()/.*#\s-]+%'''$text );
    
$result preg_match'/^[+]?[0-9]+$/'$text );
    return 
apply_filters'wpcf7_is_tel'$result$text );
}


/**
 * Checks whether the given text is a well-formed number.
 *
 * @link https://html.spec.whatwg.org/multipage/input.html#number-state-(type=number)
 */
function wpcf7_is_number$text ) {
    
$result false;

    
$patterns = array(
        
'/^[-]?[0-9]+(?:[eE][+-]?[0-9]+)?$/',
        
'/^[-]?(?:[0-9]+)?[.][0-9]+(?:[eE][+-]?[0-9]+)?$/',
    );

    foreach ( 
$patterns as $pattern ) {
        if ( 
preg_match$pattern$text ) ) {
            
$result true;
            break;
        }
    }

    return 
apply_filters'wpcf7_is_number'$result$text );
}


/**
 * Checks whether the given text is a valid date.
 *
 * @link https://html.spec.whatwg.org/multipage/input.html#date-state-(type=date)
 */
function wpcf7_is_date$text ) {
    
$result preg_match'/^([0-9]{4,})-([0-9]{2})-([0-9]{2})$/'$text$matches );

    if ( 
$result ) {
        
$result checkdate$matches[2], $matches[3], $matches[1] );
    }

    return 
apply_filters'wpcf7_is_date'$result$text );
}


/**
 * Checks whether the given text is a well-formed mailbox list.
 *
 * @param string|array $mailbox_list The subject to be checked.
 *                     Comma-separated string or an array of mailboxes.
 * @return array|bool Array of email addresses if all items are well-formed
 *                    mailbox, false if not.
 */
function wpcf7_is_mailbox_list$mailbox_list ) {
    if ( ! 
is_array$mailbox_list ) ) {
        
$mailbox_text = (string) $mailbox_list;

        
$mailbox_text preg_replace(
            
'/\\\\(?:\"|\')/',
            
'esc-quote',
            
$mailbox_text
        
);

        
$mailbox_text preg_replace(
            
'/(?:\".*?\"|\'.*?\')/',
            
'quoted-string',
            
$mailbox_text
        
);

        
$mailbox_list explode','$mailbox_text );
    }

    
$addresses = array();

    foreach ( 
$mailbox_list as $mailbox ) {
        if ( ! 
is_string$mailbox ) ) {
            return 
false;
        }

        
$mailbox trim$mailbox );

        if ( 
'' === $mailbox ) {
            continue;
        }

        if ( 
preg_match'/<(.+)>$/'$mailbox$matches ) ) {
            
$addr_spec $matches[1];
        } else {
            
$addr_spec $mailbox;
        }

        if ( ! 
wpcf7_is_email$addr_spec ) ) {
            return 
false;
        }

        
$addresses[] = $addr_spec;
    }

    return 
$addresses;
}


/**
 * Checks whether an email address belongs to a domain.
 *
 * @param string $email A mailbox or a comma-separated list of mailboxes.
 * @param string $domain Internet domain name.
 * @return bool True if all of the email addresses belong to the domain,
 *              false if not.
 */
function wpcf7_is_email_in_domain$email$domain ) {
    
$email_list wpcf7_is_mailbox_list$email );

    if ( 
false === $email_list ) {
        return 
false;
    }

    
$domain strtolower$domain );

    foreach ( 
$email_list as $email ) {
        
$email_domain substr$emailstrrpos$email'@' ) + );
        
$email_domain strtolower$email_domain );
        
$domain_parts explode'.'$domain );

        do {
            
$site_domain implode'.'$domain_parts );

            if ( 
$site_domain == $email_domain ) {
                continue 
2;
            }

            
array_shift$domain_parts );
        } while ( 
$domain_parts );

        return 
false;
    }

    return 
true;
}


/**
 * Checks whether an email address belongs to the site domain.
 */
function wpcf7_is_email_in_site_domain$email ) {
    if ( 
wpcf7_is_localhost() ) {
        return 
true;
    }

    
$homes = array(
        
home_url(),
        
network_home_url(),
    );

    
$homes array_unique$homes );

    foreach ( 
$homes as $home ) {
        
$sitename wp_parse_url$homePHP_URL_HOST );

        if ( 
WP_Http::is_ip_address$sitename ) ) {
            return 
true;
        }

        if ( 
wpcf7_is_email_in_domain$email$sitename ) ) {
            return 
true;
        }
    }

    return 
false;
}


/**
 * Verifies that a given file path is under the directories that WordPress
 * manages for user contents.
 *
 * Returns false if the file at the given path does not exist yet.
 *
 * @param string $path A file path.
 * @return bool True if the path is under the content directories,
 *              false otherwise.
 */
function wpcf7_is_file_path_in_content_dir$path ) {
    if ( 
$real_path realpath$path ) ) {
        
$path $real_path;
    } else {
        return 
false;
    }

    if ( 
=== strpos$pathrealpathWP_CONTENT_DIR ) ) ) {
        return 
true;
    }

    if ( 
defined'UPLOADS' )
    and 
=== strpos$pathrealpathABSPATH UPLOADS ) ) ) {
        return 
true;
    }

    return 
false;
}