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 3.9 3.9-beta 3.9.1 3.9.2 3.9.3 4.0 4.0.1 4.0.2 4.0.3 4.1 4.1-beta 4.1.1 4.1.2 4.2 4.2-beta 4.2.1 4.2.2 4.3 4.3.1 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6 4.6.1 4.7 4.8 4.8.1 4.9 4.9.1 4.9.2 5.0 5.0.1
contact-form-7 / includes / formatting.php
contact-form-7 / includes Last commit date
css 9 years ago js 8 years ago capabilities.php 8 years ago config-validator.php 8 years ago contact-form-functions.php 9 years ago contact-form-template.php 8 years ago contact-form.php 8 years ago controller.php 8 years ago form-tag.php 9 years ago form-tags-manager.php 8 years ago formatting.php 8 years ago functions.php 8 years ago integration.php 9 years ago l10n.php 9 years ago mail.php 8 years ago pipe.php 9 years ago rest-api.php 8 years ago shortcodes.php 9 years ago submission.php 8 years ago upgrade.php 9 years ago validation.php 9 years ago
formatting.php
381 lines
1 <?php
2
3 function wpcf7_autop( $pee, $br = 1 ) {
4 if ( trim( $pee ) === '' ) {
5 return '';
6 }
7
8 $pee = $pee . "\n"; // just to make things a little easier, pad the end
9 $pee = preg_replace( '|<br />\s*<br />|', "\n\n", $pee );
10 // Space things out a little
11 /* wpcf7: remove select and input */
12 $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
13 $pee = preg_replace( '!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee );
14 $pee = preg_replace( '!(</' . $allblocks . '>)!', "$1\n\n", $pee );
15
16 /* wpcf7: take care of [response], [recaptcha], and [hidden] tags */
17 $form_tags_manager = WPCF7_FormTagsManager::get_instance();
18 $block_hidden_form_tags = $form_tags_manager->collect_tag_types(
19 array( 'display-block', 'display-hidden' ) );
20 $block_hidden_form_tags = sprintf( '(?:%s)',
21 implode( '|', $block_hidden_form_tags ) );
22
23 $pee = preg_replace( '!(\[' . $block_hidden_form_tags . '[^]]*\])!',
24 "\n$1\n\n", $pee );
25
26 $pee = str_replace( array( "\r\n", "\r" ), "\n", $pee ); // cross-platform newlines
27
28 if ( strpos( $pee, '<object' ) !== false ) {
29 $pee = preg_replace( '|\s*<param([^>]*)>\s*|', "<param$1>", $pee ); // no pee inside object/embed
30 $pee = preg_replace( '|\s*</embed>\s*|', '</embed>', $pee );
31 }
32
33 $pee = preg_replace( "/\n\n+/", "\n\n", $pee ); // take care of duplicates
34 // make paragraphs, including one at the end
35 $pees = preg_split( '/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY );
36 $pee = '';
37
38 foreach ( $pees as $tinkle ) {
39 $pee .= '<p>' . trim( $tinkle, "\n" ) . "</p>\n";
40 }
41
42 $pee = preg_replace( '|<p>\s*</p>|', '', $pee ); // under certain strange conditions it could create a P of entirely whitespace
43 $pee = preg_replace( '!<p>([^<]+)</(div|address|form|fieldset)>!', "<p>$1</p></$2>", $pee );
44 $pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee ); // don't pee all over a tag
45 $pee = preg_replace( "|<p>(<li.+?)</p>|", "$1", $pee ); // problem with nested lists
46 $pee = preg_replace( '|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee );
47 $pee = str_replace( '</blockquote></p>', '</p></blockquote>', $pee );
48 $pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee );
49 $pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee );
50
51 /* wpcf7: take care of [response], [recaptcha], and [hidden] tag */
52 $pee = preg_replace( '!<p>\s*(\[' . $block_hidden_form_tags . '[^]]*\])!',
53 "$1", $pee );
54 $pee = preg_replace( '!(\[' . $block_hidden_form_tags . '[^]]*\])\s*</p>!',
55 "$1", $pee );
56
57 if ( $br ) {
58 /* wpcf7: add textarea */
59 $pee = preg_replace_callback(
60 '/<(script|style|textarea).*?<\/\\1>/s',
61 'wpcf7_autop_preserve_newline_callback', $pee );
62 $pee = preg_replace( '|(?<!<br />)\s*\n|', "<br />\n", $pee ); // optionally make line breaks
63 $pee = str_replace( '<WPPreserveNewline />', "\n", $pee );
64
65 /* wpcf7: remove extra <br /> just added before [response], [recaptcha], and [hidden] tags */
66 $pee = preg_replace( '!<br />\n(\[' . $block_hidden_form_tags . '[^]]*\])!',
67 "\n$1", $pee );
68 }
69
70 $pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee );
71 $pee = preg_replace( '!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee );
72
73 if ( strpos( $pee, '<pre' ) !== false ) {
74 $pee = preg_replace_callback( '!(<pre[^>]*>)(.*?)</pre>!is',
75 'clean_pre', $pee );
76 }
77
78 $pee = preg_replace( "|\n</p>$|", '</p>', $pee );
79
80 return $pee;
81 }
82
83 function wpcf7_autop_preserve_newline_callback( $matches ) {
84 return str_replace( "\n", '<WPPreserveNewline />', $matches[0] );
85 }
86
87 function wpcf7_sanitize_query_var( $text ) {
88 $text = wp_unslash( $text );
89 $text = wp_check_invalid_utf8( $text );
90
91 if ( false !== strpos( $text, '<' ) ) {
92 $text = wp_pre_kses_less_than( $text );
93 $text = wp_strip_all_tags( $text );
94 }
95
96 $text = preg_replace( '/%[a-f0-9]{2}/i', '', $text );
97 $text = preg_replace( '/ +/', ' ', $text );
98 $text = trim( $text, ' ' );
99
100 return $text;
101 }
102
103 function wpcf7_strip_quote( $text ) {
104 $text = trim( $text );
105
106 if ( preg_match( '/^"(.*)"$/s', $text, $matches ) ) {
107 $text = $matches[1];
108 } elseif ( preg_match( "/^'(.*)'$/s", $text, $matches ) ) {
109 $text = $matches[1];
110 }
111
112 return $text;
113 }
114
115 function wpcf7_strip_quote_deep( $arr ) {
116 if ( is_string( $arr ) ) {
117 return wpcf7_strip_quote( $arr );
118 }
119
120 if ( is_array( $arr ) ) {
121 $result = array();
122
123 foreach ( $arr as $key => $text ) {
124 $result[$key] = wpcf7_strip_quote_deep( $text );
125 }
126
127 return $result;
128 }
129 }
130
131 function wpcf7_normalize_newline( $text, $to = "\n" ) {
132 if ( ! is_string( $text ) ) {
133 return $text;
134 }
135
136 $nls = array( "\r\n", "\r", "\n" );
137
138 if ( ! in_array( $to, $nls ) ) {
139 return $text;
140 }
141
142 return str_replace( $nls, $to, $text );
143 }
144
145 function wpcf7_normalize_newline_deep( $arr, $to = "\n" ) {
146 if ( is_array( $arr ) ) {
147 $result = array();
148
149 foreach ( $arr as $key => $text ) {
150 $result[$key] = wpcf7_normalize_newline_deep( $text, $to );
151 }
152
153 return $result;
154 }
155
156 return wpcf7_normalize_newline( $arr, $to );
157 }
158
159 function wpcf7_strip_newline( $str ) {
160 $str = (string) $str;
161 $str = str_replace( array( "\r", "\n" ), '', $str );
162 return trim( $str );
163 }
164
165 function wpcf7_canonicalize( $text, $strto = 'lower' ) {
166 if ( function_exists( 'mb_convert_kana' )
167 && 'UTF-8' == get_option( 'blog_charset' ) ) {
168 $text = mb_convert_kana( $text, 'asKV', 'UTF-8' );
169 }
170
171 if ( 'lower' == $strto ) {
172 $text = strtolower( $text );
173 } elseif ( 'upper' == $strto ) {
174 $text = strtoupper( $text );
175 }
176
177 $text = trim( $text );
178 return $text;
179 }
180
181 /**
182 * Check whether a string is a valid NAME token.
183 *
184 * ID and NAME tokens must begin with a letter ([A-Za-z])
185 * and may be followed by any number of letters, digits ([0-9]),
186 * hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
187 *
188 * @see http://www.w3.org/TR/html401/types.html#h-6.2
189 *
190 * @return bool True if it is a valid name, false if not.
191 */
192 function wpcf7_is_name( $string ) {
193 return preg_match( '/^[A-Za-z][-A-Za-z0-9_:.]*$/', $string );
194 }
195
196 function wpcf7_sanitize_unit_tag( $tag ) {
197 $tag = preg_replace( '/[^A-Za-z0-9_-]/', '', $tag );
198 return $tag;
199 }
200
201 function wpcf7_is_email( $email ) {
202 $result = is_email( $email );
203 return apply_filters( 'wpcf7_is_email', $result, $email );
204 }
205
206 function wpcf7_is_url( $url ) {
207 $result = ( false !== filter_var( $url, FILTER_VALIDATE_URL ) );
208 return apply_filters( 'wpcf7_is_url', $result, $url );
209 }
210
211 function wpcf7_is_tel( $tel ) {
212 $result = preg_match( '%^[+]?[0-9()/ -]*$%', $tel );
213 return apply_filters( 'wpcf7_is_tel', $result, $tel );
214 }
215
216 function wpcf7_is_number( $number ) {
217 $result = is_numeric( $number );
218 return apply_filters( 'wpcf7_is_number', $result, $number );
219 }
220
221 function wpcf7_is_date( $date ) {
222 $result = preg_match( '/^([0-9]{4,})-([0-9]{2})-([0-9]{2})$/', $date, $matches );
223
224 if ( $result ) {
225 $result = checkdate( $matches[2], $matches[3], $matches[1] );
226 }
227
228 return apply_filters( 'wpcf7_is_date', $result, $date );
229 }
230
231 function wpcf7_is_mailbox_list( $mailbox_list ) {
232 if ( ! is_array( $mailbox_list ) ) {
233 $mailbox_text = (string) $mailbox_list;
234 $mailbox_text = wp_unslash( $mailbox_text );
235
236 $mailbox_text = preg_replace( '/\\\\(?:\"|\')/', 'esc-quote',
237 $mailbox_text );
238
239 $mailbox_text = preg_replace( '/(?:\".*?\"|\'.*?\')/', 'quoted-string',
240 $mailbox_text );
241
242 $mailbox_list = explode( ',', $mailbox_text );
243 }
244
245 $addresses = array();
246
247 foreach ( $mailbox_list as $mailbox ) {
248 if ( ! is_string( $mailbox ) ) {
249 return false;
250 }
251
252 $mailbox = trim( $mailbox );
253
254 if ( preg_match( '/<(.+)>$/', $mailbox, $matches ) ) {
255 $addr_spec = $matches[1];
256 } else {
257 $addr_spec = $mailbox;
258 }
259
260 if ( ! wpcf7_is_email( $addr_spec ) ) {
261 return false;
262 }
263
264 $addresses[] = $addr_spec;
265 }
266
267 return $addresses;
268 }
269
270 function wpcf7_is_email_in_domain( $email, $domain ) {
271 $email_list = wpcf7_is_mailbox_list( $email );
272 $domain = strtolower( $domain );
273
274 foreach ( $email_list as $email ) {
275 $email_domain = substr( $email, strrpos( $email, '@' ) + 1 );
276 $email_domain = strtolower( $email_domain );
277 $domain_parts = explode( '.', $domain );
278
279 do {
280 $site_domain = implode( '.', $domain_parts );
281
282 if ( $site_domain == $email_domain ) {
283 continue 2;
284 }
285
286 array_shift( $domain_parts );
287 } while ( $domain_parts );
288
289 return false;
290 }
291
292 return true;
293 }
294
295 function wpcf7_is_email_in_site_domain( $email ) {
296 if ( wpcf7_is_localhost() ) {
297 return true;
298 }
299
300 $site_domain = strtolower( $_SERVER['SERVER_NAME'] );
301
302 if ( preg_match( '/^[0-9.]+$/', $site_domain ) ) { // 123.456.789.012
303 return true;
304 }
305
306 if ( wpcf7_is_email_in_domain( $email, $site_domain ) ) {
307 return true;
308 }
309
310 $home_url = home_url();
311
312 // for interoperability with WordPress MU Domain Mapping plugin
313 if ( is_multisite() && function_exists( 'domain_mapping_siteurl' ) ) {
314 $domain_mapping_siteurl = domain_mapping_siteurl( false );
315
316 if ( $domain_mapping_siteurl ) {
317 $home_url = $domain_mapping_siteurl;
318 }
319 }
320
321 if ( preg_match( '%^https?://([^/]+)%', $home_url, $matches ) ) {
322 $site_domain = strtolower( $matches[1] );
323
324 if ( $site_domain != strtolower( $_SERVER['SERVER_NAME'] )
325 && wpcf7_is_email_in_domain( $email, $site_domain ) ) {
326 return true;
327 }
328 }
329
330 return false;
331 }
332
333 function wpcf7_antiscript_file_name( $filename ) {
334 $filename = basename( $filename );
335 $parts = explode( '.', $filename );
336
337 if ( count( $parts ) < 2 ) {
338 return $filename;
339 }
340
341 $script_pattern = '/^(php|phtml|pl|py|rb|cgi|asp|aspx)\d?$/i';
342
343 $filename = array_shift( $parts );
344 $extension = array_pop( $parts );
345
346 foreach ( (array) $parts as $part ) {
347 if ( preg_match( $script_pattern, $part ) ) {
348 $filename .= '.' . $part . '_';
349 } else {
350 $filename .= '.' . $part;
351 }
352 }
353
354 if ( preg_match( $script_pattern, $extension ) ) {
355 $filename .= '.' . $extension . '_.txt';
356 } else {
357 $filename .= '.' . $extension;
358 }
359
360 return $filename;
361 }
362
363 function wpcf7_mask_password( $text, $length_unmasked = 0 ) {
364 $length = strlen( $text );
365 $length_unmasked = absint( $length_unmasked );
366
367 if ( 0 == $length_unmasked ) {
368 if ( 9 < $length ) {
369 $length_unmasked = 4;
370 } elseif ( 3 < $length ) {
371 $length_unmasked = 2;
372 } else {
373 $length_unmasked = $length;
374 }
375 }
376
377 $text = substr( $text, 0 - $length_unmasked );
378 $text = str_pad( $text, $length, '*', STR_PAD_LEFT );
379 return $text;
380 }
381