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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
block-editor 5 years ago css 5 years ago js 5 years ago capabilities.php 7 years ago config-validator.php 5 years ago contact-form-functions.php 5 years ago contact-form-template.php 5 years ago contact-form.php 5 years ago controller.php 7 years ago form-tag.php 5 years ago form-tags-manager.php 6 years ago formatting.php 5 years ago functions.php 5 years ago integration.php 7 years ago l10n.php 5 years ago mail.php 5 years ago pipe.php 5 years ago rest-api.php 5 years ago shortcodes.php 9 years ago special-mail-tags.php 5 years ago submission.php 5 years ago upgrade.php 7 years ago validation.php 7 years ago
formatting.php
388 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 and '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 $pattern = '%^[+]?' // + sign
213 . '(?:\([0-9]+\)|[0-9]+)' // (1234) or 1234
214 . '(?:[/ -]*' // delimiter
215 . '(?:\([0-9]+\)|[0-9]+)' // (1234) or 1234
216 . ')*$%';
217
218 $result = preg_match( $pattern, trim( $tel ) );
219 return apply_filters( 'wpcf7_is_tel', $result, $tel );
220 }
221
222 function wpcf7_is_number( $number ) {
223 $result = is_numeric( $number );
224 return apply_filters( 'wpcf7_is_number', $result, $number );
225 }
226
227 function wpcf7_is_date( $date ) {
228 $result = preg_match( '/^([0-9]{4,})-([0-9]{2})-([0-9]{2})$/', $date, $matches );
229
230 if ( $result ) {
231 $result = checkdate( $matches[2], $matches[3], $matches[1] );
232 }
233
234 return apply_filters( 'wpcf7_is_date', $result, $date );
235 }
236
237 function wpcf7_is_mailbox_list( $mailbox_list ) {
238 if ( ! is_array( $mailbox_list ) ) {
239 $mailbox_text = (string) $mailbox_list;
240 $mailbox_text = wp_unslash( $mailbox_text );
241
242 $mailbox_text = preg_replace( '/\\\\(?:\"|\')/', 'esc-quote',
243 $mailbox_text );
244
245 $mailbox_text = preg_replace( '/(?:\".*?\"|\'.*?\')/', 'quoted-string',
246 $mailbox_text );
247
248 $mailbox_list = explode( ',', $mailbox_text );
249 }
250
251 $addresses = array();
252
253 foreach ( $mailbox_list as $mailbox ) {
254 if ( ! is_string( $mailbox ) ) {
255 return false;
256 }
257
258 $mailbox = trim( $mailbox );
259
260 if ( preg_match( '/<(.+)>$/', $mailbox, $matches ) ) {
261 $addr_spec = $matches[1];
262 } else {
263 $addr_spec = $mailbox;
264 }
265
266 if ( ! wpcf7_is_email( $addr_spec ) ) {
267 return false;
268 }
269
270 $addresses[] = $addr_spec;
271 }
272
273 return $addresses;
274 }
275
276 function wpcf7_is_email_in_domain( $email, $domain ) {
277 $email_list = wpcf7_is_mailbox_list( $email );
278 $domain = strtolower( $domain );
279
280 foreach ( $email_list as $email ) {
281 $email_domain = substr( $email, strrpos( $email, '@' ) + 1 );
282 $email_domain = strtolower( $email_domain );
283 $domain_parts = explode( '.', $domain );
284
285 do {
286 $site_domain = implode( '.', $domain_parts );
287
288 if ( $site_domain == $email_domain ) {
289 continue 2;
290 }
291
292 array_shift( $domain_parts );
293 } while ( $domain_parts );
294
295 return false;
296 }
297
298 return true;
299 }
300
301 function wpcf7_is_email_in_site_domain( $email ) {
302 if ( wpcf7_is_localhost() ) {
303 return true;
304 }
305
306 $site_domain = strtolower( $_SERVER['SERVER_NAME'] );
307
308 if ( preg_match( '/^[0-9.]+$/', $site_domain ) ) { // 123.456.789.012
309 return true;
310 }
311
312 if ( wpcf7_is_email_in_domain( $email, $site_domain ) ) {
313 return true;
314 }
315
316 $home_url = home_url();
317
318 // for interoperability with WordPress MU Domain Mapping plugin
319 if ( is_multisite()
320 and function_exists( 'domain_mapping_siteurl' ) ) {
321 $domain_mapping_siteurl = domain_mapping_siteurl( false );
322
323 if ( $domain_mapping_siteurl ) {
324 $home_url = $domain_mapping_siteurl;
325 }
326 }
327
328 if ( preg_match( '%^https?://([^/]+)%', $home_url, $matches ) ) {
329 $site_domain = strtolower( $matches[1] );
330
331 if ( $site_domain != strtolower( $_SERVER['SERVER_NAME'] )
332 and wpcf7_is_email_in_domain( $email, $site_domain ) ) {
333 return true;
334 }
335 }
336
337 return false;
338 }
339
340 function wpcf7_antiscript_file_name( $filename ) {
341 $filename = wp_basename( $filename );
342 $parts = explode( '.', $filename );
343
344 if ( count( $parts ) < 2 ) {
345 return $filename;
346 }
347
348 $script_pattern = '/^(php|phtml|pl|py|rb|cgi|asp|aspx)\d?$/i';
349
350 $filename = array_shift( $parts );
351 $extension = array_pop( $parts );
352
353 foreach ( (array) $parts as $part ) {
354 if ( preg_match( $script_pattern, $part ) ) {
355 $filename .= '.' . $part . '_';
356 } else {
357 $filename .= '.' . $part;
358 }
359 }
360
361 if ( preg_match( $script_pattern, $extension ) ) {
362 $filename .= '.' . $extension . '_.txt';
363 } else {
364 $filename .= '.' . $extension;
365 }
366
367 return $filename;
368 }
369
370 function wpcf7_mask_password( $text, $length_unmasked = 0 ) {
371 $length = strlen( $text );
372 $length_unmasked = absint( $length_unmasked );
373
374 if ( 0 == $length_unmasked ) {
375 if ( 9 < $length ) {
376 $length_unmasked = 4;
377 } elseif ( 3 < $length ) {
378 $length_unmasked = 2;
379 } else {
380 $length_unmasked = $length;
381 }
382 }
383
384 $text = substr( $text, 0 - $length_unmasked );
385 $text = str_pad( $text, $length, '*', STR_PAD_LEFT );
386 return $text;
387 }
388