source: trunk/www.guidonia.net/wp/wp-content/plugins/contact-form-7/includes/formatting.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 3.5 KB
Line 
1<?php
2
3function wpcf7_autop( $pee, $br = 1 ) {
4 if ( trim($pee) === '' )
5 return '';
6 $pee = $pee . "\n"; // just to make things a little easier, pad the end
7 $pee = preg_replace( '|<br />\s*<br />|', "\n\n", $pee );
8 // Space things out a little
9 /* wpcf7: removed select and input */
10 $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)';
11 $pee = preg_replace( '!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee );
12 $pee = preg_replace( '!(</' . $allblocks . '>)!', "$1\n\n", $pee );
13 $pee = str_replace( array( "\r\n", "\r" ), "\n", $pee ); // cross-platform newlines
14 if ( strpos( $pee, '<object' ) !== false ) {
15 $pee = preg_replace( '|\s*<param([^>]*)>\s*|', "<param$1>", $pee ); // no pee inside object/embed
16 $pee = preg_replace( '|\s*</embed>\s*|', '</embed>', $pee );
17 }
18 $pee = preg_replace( "/\n\n+/", "\n\n", $pee ); // take care of duplicates
19 // make paragraphs, including one at the end
20 $pees = preg_split( '/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY );
21 $pee = '';
22 foreach ( $pees as $tinkle )
23 $pee .= '<p>' . trim( $tinkle, "\n" ) . "</p>\n";
24 $pee = preg_replace( '|<p>\s*</p>|', '', $pee ); // under certain strange conditions it could create a P of entirely whitespace
25 $pee = preg_replace( '!<p>([^<]+)</(div|address|form)>!', "<p>$1</p></$2>", $pee );
26 $pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee ); // don't pee all over a tag
27 $pee = preg_replace( "|<p>(<li.+?)</p>|", "$1", $pee ); // problem with nested lists
28 $pee = preg_replace( '|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee );
29 $pee = str_replace( '</blockquote></p>', '</p></blockquote>', $pee );
30 $pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee );
31 $pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee );
32 if ( $br ) {
33 /* wpcf7: add textarea */
34 $pee = preg_replace_callback( '/<(script|style|textarea).*?<\/\\1>/s', create_function( '$matches', 'return str_replace("\n", "<WPPreserveNewline />", $matches[0]);' ), $pee );
35 $pee = preg_replace( '|(?<!<br />)\s*\n|', "<br />\n", $pee ); // optionally make line breaks
36 $pee = str_replace( '<WPPreserveNewline />', "\n", $pee );
37 }
38 $pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee );
39 $pee = preg_replace( '!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee );
40 if ( strpos( $pee, '<pre' ) !== false )
41 $pee = preg_replace_callback( '!(<pre[^>]*>)(.*?)</pre>!is', 'clean_pre', $pee );
42 $pee = preg_replace( "|\n</p>$|", '</p>', $pee );
43 /* wpcf7: replaced to wpcf7_get_shortcode_regex ( -> comment out) */
44 // don't auto-p wrap shortcodes that stand alone
45 // $pee = preg_replace( '/<p>\s*?(' . wpcf7_get_shortcode_regex() . ')\s*<\/p>/s', '$1', $pee );
46
47 return $pee;
48}
49
50function wpcf7_strip_quote( $text ) {
51 $text = trim( $text );
52 if ( preg_match( '/^"(.*)"$/', $text, $matches ) )
53 $text = $matches[1];
54 elseif ( preg_match( "/^'(.*)'$/", $text, $matches ) )
55 $text = $matches[1];
56 return $text;
57}
58
59function wpcf7_strip_quote_deep( $arr ) {
60 if ( is_string( $arr ) )
61 return wpcf7_strip_quote( $arr );
62
63 if ( is_array( $arr ) ) {
64 $result = array();
65 foreach ( $arr as $key => $text ) {
66 $result[$key] = wpcf7_strip_quote( $text );
67 }
68 return $result;
69 }
70}
71
72function wpcf7_canonicalize( $text ) {
73 if ( function_exists( 'mb_convert_kana' ) && 'UTF-8' == get_option( 'blog_charset' ) )
74 $text = mb_convert_kana( $text, 'asKV', 'UTF-8' );
75
76 $text = strtolower( $text );
77 $text = trim( $text );
78 return $text;
79}
80
81?>
Note: See TracBrowser for help on using the repository browser.