css
13 years ago
js
12 years ago
capabilities.php
13 years ago
classes.php
13 years ago
controller.php
12 years ago
deprecated.php
14 years ago
formatting.php
13 years ago
functions.php
13 years ago
pipe.php
14 years ago
shortcodes.php
13 years ago
formatting.php
150 lines
| 1 | <?php |
| 2 | |
| 3 | function wpcf7_autop( $pee, $br = 1 ) { |
| 4 | |
| 5 | if ( trim( $pee ) === '' ) |
| 6 | return ''; |
| 7 | $pee = $pee . "\n"; // just to make things a little easier, pad the end |
| 8 | $pee = preg_replace( '|<br />\s*<br />|', "\n\n", $pee ); |
| 9 | // Space things out a little |
| 10 | /* wpcf7: remove select and input */ |
| 11 | $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)'; |
| 12 | $pee = preg_replace( '!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee ); |
| 13 | $pee = preg_replace( '!(</' . $allblocks . '>)!', "$1\n\n", $pee ); |
| 14 | $pee = str_replace( array( "\r\n", "\r" ), "\n", $pee ); // cross-platform newlines |
| 15 | if ( strpos( $pee, '<object' ) !== false ) { |
| 16 | $pee = preg_replace( '|\s*<param([^>]*)>\s*|', "<param$1>", $pee ); // no pee inside object/embed |
| 17 | $pee = preg_replace( '|\s*</embed>\s*|', '</embed>', $pee ); |
| 18 | } |
| 19 | $pee = preg_replace( "/\n\n+/", "\n\n", $pee ); // take care of duplicates |
| 20 | // make paragraphs, including one at the end |
| 21 | $pees = preg_split( '/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY ); |
| 22 | $pee = ''; |
| 23 | foreach ( $pees as $tinkle ) |
| 24 | $pee .= '<p>' . trim( $tinkle, "\n" ) . "</p>\n"; |
| 25 | $pee = preg_replace( '|<p>\s*</p>|', '', $pee ); // under certain strange conditions it could create a P of entirely whitespace |
| 26 | $pee = preg_replace( '!<p>([^<]+)</(div|address|form|fieldset)>!', "<p>$1</p></$2>", $pee ); |
| 27 | $pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee ); // don't pee all over a tag |
| 28 | $pee = preg_replace( "|<p>(<li.+?)</p>|", "$1", $pee ); // problem with nested lists |
| 29 | $pee = preg_replace( '|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee ); |
| 30 | $pee = str_replace( '</blockquote></p>', '</p></blockquote>', $pee ); |
| 31 | $pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee ); |
| 32 | $pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee ); |
| 33 | if ( $br ) { |
| 34 | /* wpcf7: add textarea */ |
| 35 | $pee = preg_replace_callback( '/<(script|style|textarea).*?<\/\\1>/s', create_function( '$matches', 'return str_replace("\n", "<WPPreserveNewline />", $matches[0]);' ), $pee ); |
| 36 | $pee = preg_replace( '|(?<!<br />)\s*\n|', "<br />\n", $pee ); // optionally make line breaks |
| 37 | $pee = str_replace( '<WPPreserveNewline />', "\n", $pee ); |
| 38 | } |
| 39 | $pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee ); |
| 40 | $pee = preg_replace( '!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee ); |
| 41 | if ( strpos( $pee, '<pre' ) !== false ) |
| 42 | $pee = preg_replace_callback( '!(<pre[^>]*>)(.*?)</pre>!is', 'clean_pre', $pee ); |
| 43 | $pee = preg_replace( "|\n</p>$|", '</p>', $pee ); |
| 44 | |
| 45 | return $pee; |
| 46 | } |
| 47 | |
| 48 | function wpcf7_strip_quote( $text ) { |
| 49 | $text = trim( $text ); |
| 50 | |
| 51 | if ( preg_match( '/^"(.*)"$/', $text, $matches ) ) |
| 52 | $text = $matches[1]; |
| 53 | elseif ( preg_match( "/^'(.*)'$/", $text, $matches ) ) |
| 54 | $text = $matches[1]; |
| 55 | |
| 56 | return $text; |
| 57 | } |
| 58 | |
| 59 | function 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 | |
| 66 | foreach ( $arr as $key => $text ) |
| 67 | $result[$key] = wpcf7_strip_quote_deep( $text ); |
| 68 | |
| 69 | return $result; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | function wpcf7_normalize_newline( $text, $to = "\n" ) { |
| 74 | if ( ! is_string( $text ) ) |
| 75 | return $text; |
| 76 | |
| 77 | $nls = array( "\r\n", "\r", "\n" ); |
| 78 | |
| 79 | if ( ! in_array( $to, $nls ) ) |
| 80 | return $text; |
| 81 | |
| 82 | return str_replace( $nls, $to, $text ); |
| 83 | } |
| 84 | |
| 85 | function wpcf7_normalize_newline_deep( $arr, $to = "\n" ) { |
| 86 | if ( is_array( $arr ) ) { |
| 87 | $result = array(); |
| 88 | |
| 89 | foreach ( $arr as $key => $text ) |
| 90 | $result[$key] = wpcf7_normalize_newline_deep( $text, $to ); |
| 91 | |
| 92 | return $result; |
| 93 | } |
| 94 | |
| 95 | return wpcf7_normalize_newline( $arr, $to ); |
| 96 | } |
| 97 | |
| 98 | function wpcf7_canonicalize( $text ) { |
| 99 | if ( function_exists( 'mb_convert_kana' ) && 'UTF-8' == get_option( 'blog_charset' ) ) |
| 100 | $text = mb_convert_kana( $text, 'asKV', 'UTF-8' ); |
| 101 | |
| 102 | $text = strtolower( $text ); |
| 103 | $text = trim( $text ); |
| 104 | return $text; |
| 105 | } |
| 106 | |
| 107 | function wpcf7_is_name( $string ) { |
| 108 | // See http://www.w3.org/TR/html401/types.html#h-6.2 |
| 109 | // ID and NAME tokens must begin with a letter ([A-Za-z]) |
| 110 | // and may be followed by any number of letters, digits ([0-9]), |
| 111 | // hyphens ("-"), underscores ("_"), colons (":"), and periods ("."). |
| 112 | |
| 113 | return preg_match( '/^[A-Za-z][-A-Za-z0-9_:.]*$/', $string ); |
| 114 | } |
| 115 | |
| 116 | function wpcf7_sanitize_unit_tag( $tag ) { |
| 117 | $tag = preg_replace( '/[^A-Za-z0-9_-]/', '', $tag ); |
| 118 | return $tag; |
| 119 | } |
| 120 | |
| 121 | function wpcf7_is_email( $email ) { |
| 122 | $result = is_email( $email ); |
| 123 | return apply_filters( 'wpcf7_is_email', $result, $email ); |
| 124 | } |
| 125 | |
| 126 | function wpcf7_is_url( $url ) { |
| 127 | $result = ( false !== filter_var( $url, FILTER_VALIDATE_URL ) ); |
| 128 | return apply_filters( 'wpcf7_is_url', $result, $url ); |
| 129 | } |
| 130 | |
| 131 | function wpcf7_is_tel( $tel ) { |
| 132 | $result = preg_match( '/^[+]?[0-9() -]*$/', $tel ); |
| 133 | return apply_filters( 'wpcf7_is_tel', $result, $tel ); |
| 134 | } |
| 135 | |
| 136 | function wpcf7_is_number( $number ) { |
| 137 | $result = is_numeric( $number ); |
| 138 | return apply_filters( 'wpcf7_is_number', $result, $number ); |
| 139 | } |
| 140 | |
| 141 | function wpcf7_is_date( $date ) { |
| 142 | $result = preg_match( '/^([0-9]{4,})-([0-9]{2})-([0-9]{2})$/', $date, $matches ); |
| 143 | |
| 144 | if ( $result ) |
| 145 | $result = checkdate( $matches[2], $matches[3], $matches[1] ); |
| 146 | |
| 147 | return apply_filters( 'wpcf7_is_date', $result, $date ); |
| 148 | } |
| 149 | |
| 150 | ?> |