Ticket #9723: clean.up.in.formatting.php.file.patch
| File clean.up.in.formatting.php.file.patch, 38.5 KB (added by , 17 years ago) |
|---|
-
formatting.php
26 26 * @param string $text The text to be formatted 27 27 * @return string The string replaced with html entities 28 28 */ 29 function wptexturize( $text) {29 function wptexturize( $text ) { 30 30 global $wp_cockneyreplace; 31 31 $next = true; 32 32 $has_pre_parent = false; … … 58 58 $curl = str_replace($static_characters, $static_replacements, $curl); 59 59 // regular expressions 60 60 $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl); 61 } elseif ( strpos($curl, '<code') !== false || strpos($curl, '<kbd') !== false || strpos($curl, '<style') !== false || strpos($curl, '<script') !== false) {61 } elseif ( strpos($curl, '<code') !== false || strpos($curl, '<kbd') !== false || strpos($curl, '<style') !== false || strpos($curl, '<script') !== false ) { 62 62 $next = false; 63 } elseif ( strpos($curl, '<pre') !== false) {63 } elseif ( strpos($curl, '<pre') !== false ) { 64 64 $has_pre_parent = true; 65 } elseif ( strpos($curl, '</pre>') !== false) {65 } elseif ( strpos($curl, '</pre>') !== false ) { 66 66 $has_pre_parent = false; 67 67 } else { 68 68 $next = true; … … 86 86 * @param array|string $matches The array or string 87 87 * @return string The pre block without paragraph/line-break conversion. 88 88 */ 89 function clean_pre( $matches) {89 function clean_pre( $matches ) { 90 90 if ( is_array($matches) ) 91 91 $text = $matches[1] . $matches[2] . "</pre>"; 92 92 else … … 113 113 * @param int|bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true. 114 114 * @return string Text which has been converted into correct paragraph tags. 115 115 */ 116 function wpautop( $pee, $br = 1) {116 function wpautop( $pee, $br = 1 ) { 117 117 if ( trim($pee) === '' ) 118 118 return ''; 119 119 120 $pee = $pee . "\n"; // just to make things a little easier, pad the end 120 121 $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee); 122 121 123 // Space things out a little 122 124 $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr)'; 123 125 $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee); … … 141 143 $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee); 142 144 $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee); 143 145 $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); 144 if ( $br) {146 if ( $br ) { 145 147 $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', create_function('$matches', 'return str_replace("\n", "<WPPreserveNewline />", $matches[0]);'), $pee); 146 148 $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks 147 149 $pee = str_replace('<WPPreserveNewline />', "\n", $pee); 148 150 } 149 151 $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee); 150 152 $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee); 151 if ( strpos($pee, '<pre') !== false)153 if ( strpos($pee, '<pre') !== false ) 152 154 $pee = preg_replace_callback('!(<pre[^>]*>)(.*?)</pre>!is', 'clean_pre', $pee ); 153 155 $pee = preg_replace( "|\n</p>$|", '</p>', $pee ); 154 156 $pee = preg_replace('/<p>\s*?(' . get_shortcode_regex() . ')\s*<\/p>/s', '$1', $pee); // don't auto-p wrap shortcodes that stand alone … … 166 168 * @param string $Str The string to be checked 167 169 * @return bool True if $Str fits a UTF-8 model, false otherwise. 168 170 */ 169 function seems_utf8( $Str) { # by bmorel at ssi dot fr171 function seems_utf8( $Str ) { 170 172 $length = strlen($Str); 171 for ( $i=0; $i < $length; $i++) {172 if ( ord($Str[$i]) < 0x80) continue; #0bbbbbbb173 elseif ( (ord($Str[$i]) & 0xE0) == 0xC0) $n=1; #110bbbbb174 elseif ( (ord($Str[$i]) & 0xF0) == 0xE0) $n=2; #1110bbbb175 elseif ( (ord($Str[$i]) & 0xF8) == 0xF0) $n=3; #11110bbb176 elseif ( (ord($Str[$i]) & 0xFC) == 0xF8) $n=4; #111110bb177 elseif ( (ord($Str[$i]) & 0xFE) == 0xFC) $n=5; #1111110b178 else return false; #Does not match any model179 for ( $j=0; $j<$n; $j++) { #n bytes matching 10bbbbbb follow ?180 if ( (++$i == $length) || ((ord($Str[$i]) & 0xC0) != 0x80))173 for ( $i = 0; $i < $length; $i++ ) { 174 if ( ord($Str[$i] ) < 0x80) continue; // 0bbbbbbb 175 elseif ( (ord($Str[$i]) & 0xE0) == 0xC0 ) $n = 1; // 110bbbbb 176 elseif ( (ord($Str[$i]) & 0xF0) == 0xE0 ) $n = 2; // 1110bbbb 177 elseif ( (ord($Str[$i]) & 0xF8) == 0xF0 ) $n = 3; // 11110bbb 178 elseif ( (ord($Str[$i]) & 0xFC) == 0xF8 ) $n = 4; // 111110bb 179 elseif ( (ord($Str[$i]) & 0xFE) == 0xFC ) $n = 5; // 1111110b 180 else return false; // Does not match any model 181 for ( $j = 0; $j < $n; $j++ ) { // n bytes matching 10bbbbbb follow ? 182 if ( (++$i == $length) || ((ord($Str[$i]) & 0xC0) != 0x80) ) 181 183 return false; 182 184 } 183 185 } … … 200 202 * @param boolean $double_encode Optional. Whether or not to encode existing html entities. Default is false. 201 203 * @return string The encoded text with HTML entities. 202 204 */ 203 function wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) 204 { 205 function wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) { 205 206 $string = (string) $string; 206 207 207 if ( 0 === strlen( $string ) ) {208 if ( 0 === strlen( $string ) ) 208 209 return ''; 209 }210 210 211 211 // Don't bother if there are no specialchars - saves some processing 212 if ( !preg_match( '/[&<>"\']/', $string ) ) {212 if ( !preg_match( '/[&<>"\']/', $string ) ) 213 213 return $string; 214 }215 214 216 215 // Account for the previous behaviour of the function when the $quote_style is not an accepted value 217 if ( empty( $quote_style ) ) {216 if ( empty( $quote_style ) ) 218 217 $quote_style = ENT_NOQUOTES; 219 } elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {218 elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) 220 219 $quote_style = ENT_QUOTES; 221 }222 220 223 221 // Store the site charset as a static to avoid multiple calls to wp_load_alloptions() 224 222 if ( !$charset ) { … … 229 227 } 230 228 $charset = $_charset; 231 229 } 232 if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ) ) ) {230 if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ) ) ) 233 231 $charset = 'UTF-8'; 234 }235 232 236 233 $_quote_style = $quote_style; 237 234 … … 251 248 $string = @htmlspecialchars( $string, $quote_style, $charset ); 252 249 253 250 // Handle double encoding ourselves 254 if ( !$double_encode ) {251 if ( !$double_encode ) 255 252 $string = str_replace( array( '|wp_entity|', '|/wp_entity|' ), array( '&', ';' ), $string ); 256 }257 253 258 254 // Backwards compatibility 259 if ( 'single' === $_quote_style ) {255 if ( 'single' === $_quote_style ) 260 256 $string = str_replace( "'", ''', $string ); 261 }262 257 263 258 return $string; 264 259 } … … 277 272 * @param mixed $quote_style Optional. Converts double quotes if set to ENT_COMPAT, both single and double if set to ENT_QUOTES or none if set to ENT_NOQUOTES. Also compatible with old wp_specialchars() values; converting single quotes if set to 'single', double if set to 'double' or both if otherwise set. Default is ENT_NOQUOTES. 278 273 * @return string The decoded text without HTML entities. 279 274 */ 280 function wp_specialchars_decode( $string, $quote_style = ENT_NOQUOTES ) 281 { 275 function wp_specialchars_decode( $string, $quote_style = ENT_NOQUOTES ) { 282 276 $string = (string) $string; 283 277 284 if ( 0 === strlen( $string ) ) {278 if ( 0 === strlen( $string ) ) 285 279 return ''; 286 }287 280 288 281 // Don't bother if there are no entities - saves a lot of processing 289 if ( strpos( $string, '&' ) === false ) {282 if ( strpos( $string, '&' ) === false ) 290 283 return $string; 291 }292 284 293 285 // Match the previous behaviour of wp_specialchars() when the $quote_style is not an accepted value 294 if ( empty( $quote_style ) ) {286 if ( empty( $quote_style ) ) 295 287 $quote_style = ENT_NOQUOTES; 296 } elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {288 elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) 297 289 $quote_style = ENT_QUOTES; 298 }299 290 300 291 // More complete than get_html_translation_table( HTML_SPECIALCHARS ) 301 292 $single = array( ''' => '\'', ''' => '\'' ); … … 339 330 { 340 331 $string = (string) $string; 341 332 342 if ( 0 === strlen( $string ) ) {333 if ( 0 === strlen( $string ) ) 343 334 return ''; 344 }345 335 346 336 // Store the site charset as a static to avoid multiple calls to get_option() 347 337 static $is_utf8; 348 if ( !isset( $is_utf8 ) ) {338 if ( !isset( $is_utf8 ) ) 349 339 $is_utf8 = in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ); 350 } 351 if ( !$is_utf8 ) { 340 if ( !$is_utf8 ) 352 341 return $string; 353 }354 342 355 343 // Check for support for utf8 in the installed PCRE library once and store the result in a static 356 344 static $utf8_pcre; 357 if ( !isset( $utf8_pcre ) ) {345 if ( !isset( $utf8_pcre ) ) 358 346 $utf8_pcre = @preg_match( '/^./u', 'a' ); 359 } 347 360 348 // We can't demand utf8 in the PCRE installation, so just return the string in those cases 361 if ( !$utf8_pcre ) {349 if ( !$utf8_pcre ) 362 350 return $string; 363 }364 351 365 352 // preg_match fails when it encounters invalid UTF8 in $string 366 if ( 1 === @preg_match( '/^./us', $string ) ) {353 if ( 1 === @preg_match( '/^./us', $string ) ) 367 354 return $string; 368 }369 355 370 356 // Attempt to strip the bad chars if requested (not recommended) 371 if ( $strip && function_exists( 'iconv' ) ) {357 if ( $strip && function_exists( 'iconv' ) ) 372 358 return iconv( 'utf-8', 'utf-8', $string ); 373 }374 359 375 360 return ''; 376 361 } … … 401 386 $unicode .= chr($value); 402 387 $unicode_length++; 403 388 } else { 404 if ( count( $values ) == 0 ) $num_octets = ( $value < 224 ) ? 2 : 3; 389 if ( count( $values ) == 0 ) 390 $num_octets = ( $value < 224 ) ? 2 : 3; 405 391 406 392 $values[] = $value; 407 393 408 394 if ( $length && ( $unicode_length + ($num_octets * 3) ) > $length ) 409 395 break; 410 396 if ( count( $values ) == $num_octets ) { 411 if ( $num_octets == 3) {397 if ( $num_octets == 3 ) { 412 398 $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]); 413 399 $unicode_length += 9; 414 400 } else { … … 439 425 if ( !preg_match('/[\x80-\xff]/', $string) ) 440 426 return $string; 441 427 442 if ( seems_utf8($string)) {428 if ( seems_utf8($string) ) { 443 429 $chars = array( 444 430 // Decompositions for Latin-1 Supplement 445 431 chr(195).chr(128) => 'A', chr(195).chr(129) => 'A', … … 637 623 * @param string $fallback_title Optional. A title to use if $title is empty. 638 624 * @return string The sanitized string. 639 625 */ 640 function sanitize_title( $title, $fallback_title = '') {626 function sanitize_title( $title, $fallback_title = '' ) { 641 627 $raw_title = $title; 642 628 $title = strip_tags($title); 643 629 $title = apply_filters('sanitize_title', $title, $raw_title); … … 659 645 * @param string $title The title to be sanitized. 660 646 * @return string The sanitized title. 661 647 */ 662 function sanitize_title_with_dashes( $title) {648 function sanitize_title_with_dashes( $title ) { 663 649 $title = strip_tags($title); 664 650 // Preserve escaped octets. 665 651 $title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title); … … 669 655 $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title); 670 656 671 657 $title = remove_accents($title); 672 if ( seems_utf8($title)) {673 if ( function_exists('mb_strtolower')) {658 if ( seems_utf8($title) ) { 659 if ( function_exists('mb_strtolower') ) 674 660 $title = mb_strtolower($title, 'UTF-8'); 675 }676 661 $title = utf8_uri_encode($title, 200); 677 662 } 678 663 … … 718 703 * @param string $deprecated Not used. 719 704 * @return string Converted string. 720 705 */ 721 function convert_chars( $content, $deprecated = '') {706 function convert_chars( $content, $deprecated = '' ) { 722 707 // Translation of invalid Unicode references range to valid range 723 708 $wp_htmltranswinuni = array( 724 709 '€' => '€', // the Euro sign … … 780 765 * @param array $matches Single Match 781 766 * @return string An HTML entity 782 767 */ 783 function funky_javascript_callback( $matches) {768 function funky_javascript_callback( $matches ) { 784 769 return "&#".base_convert($matches[1],16,10).";"; 785 770 } 786 771 … … 796 781 * @param string $text Text to be made safe. 797 782 * @return string Fixed text. 798 783 */ 799 function funky_javascript_fix( $text) {784 function funky_javascript_fix( $text ) { 800 785 // Fixes for browsers' javascript bugs 801 786 global $is_macIE, $is_winIE; 802 787 803 788 if ( $is_winIE || $is_macIE ) 804 $text = preg_replace_callback("/\%u([0-9A-F]{4,4})/", 805 "funky_javascript_callback", 806 $text); 789 $text = preg_replace_callback("/\%u([0-9A-F]{4,4})/", "funky_javascript_callback", $text); 807 790 808 791 return $text; 809 792 } … … 847 830 */ 848 831 function force_balance_tags( $text ) { 849 832 $tagstack = array(); $stacksize = 0; $tagqueue = ''; $newtext = ''; 850 $single_tags = array('br', 'hr', 'img', 'input'); // Known single-entity/self-closing tags851 $nestable_tags = array('blockquote', 'div', 'span'); // Tags that can be immediately nested within themselves833 $single_tags = array('br', 'hr', 'img', 'input'); // Known single-entity/self-closing tags 834 $nestable_tags = array('blockquote', 'div', 'span'); // Tags that can be immediately nested within themselves 852 835 853 #WP bug fix for comments - in case you REALLY meant to type '< !--'836 // WP bug fix for comments - in case you REALLY meant to type '< !--' 854 837 $text = str_replace('< !--', '< !--', $text); 855 #WP bug fix for LOVE <3 (and other situations with '<' before a number)838 // WP bug fix for LOVE <3 (and other situations with '<' before a number) 856 839 $text = preg_replace('#<([0-9]{1})#', '<$1', $text); 857 840 858 while ( preg_match("/<(\/?\w*)\s*([^>]*)>/",$text,$regex)) {841 while ( preg_match("/<(\/?\w*)\s*([^>]*)>/",$text,$regex) ) { 859 842 $newtext .= $tagqueue; 860 843 861 844 $i = strpos($text,$regex[0]); … … 867 850 if ( isset($regex[1][0]) && '/' == $regex[1][0] ) { // End Tag 868 851 $tag = strtolower(substr($regex[1],1)); 869 852 // if too many closing tags 870 if( $stacksize <= 0) {853 if( $stacksize <= 0 ) { 871 854 $tag = ''; 872 855 //or close to be safe $tag = '/' . $tag; 873 856 } 874 857 // if stacktop value = tag close value then pop 875 else if ( $tagstack[$stacksize - 1] == $tag) { // found closing tag858 else if ( $tagstack[$stacksize - 1] == $tag ) { // found closing tag 876 859 $tag = '</' . $tag . '>'; // Close Tag 877 860 // Pop 878 861 array_pop ($tagstack); 879 862 $stacksize--; 880 863 } else { // closing tag not at top, search for it 881 for ( $j=$stacksize-1;$j>=0;$j--) {864 for ( $j = $stacksize-1; $j >= 0; $j-- ) { 882 865 if ($tagstack[$j] == $tag) { 883 866 // add tag to tagqueue 884 for ( $k=$stacksize-1;$k>=$j;$k--){867 for ( $k = $stacksize-1; $k >= $j; $k-- ){ 885 868 $tagqueue .= '</' . array_pop ($tagstack) . '>'; 886 869 $stacksize--; 887 870 } … … 896 879 // Tag Cleaning 897 880 898 881 // If self-closing or '', don't do anything. 899 if( (substr($regex[2],-1) == '/') || ($tag == '')) {882 if( (substr($regex[2],-1) == '/') || ($tag == '') ) { 900 883 } 901 884 // ElseIf it's a known single-entity tag but it doesn't close itself, do so 902 885 elseif ( in_array($tag, $single_tags) ) { 903 886 $regex[2] .= '/'; 904 887 } else { // Push the tag onto the stack 905 888 // If the top of the stack is the same as the tag we want to push, close previous tag 906 if ( ($stacksize > 0) && !in_array($tag, $nestable_tags) && ($tagstack[$stacksize - 1] == $tag)) {889 if ( ($stacksize > 0) && !in_array($tag, $nestable_tags) && ($tagstack[$stacksize - 1] == $tag) ) { 907 890 $tagqueue = '</' . array_pop ($tagstack) . '>'; 908 891 $stacksize--; 909 892 } … … 912 895 913 896 // Attributes 914 897 $attributes = $regex[2]; 915 if( $attributes) {898 if( $attributes ) 916 899 $attributes = ' '.$attributes; 917 } 900 918 901 $tag = '<'.$tag.$attributes.'>'; 919 902 //If already queuing a close tag, then put this tag on, too 920 if ( $tagqueue) {903 if ( $tagqueue ) { 921 904 $tagqueue .= $tag; 922 905 $tag = ''; 923 906 } … … 933 916 $newtext .= $text; 934 917 935 918 // Empty Stack 936 while( $x = array_pop($tagstack)) {919 while( $x = array_pop($tagstack) ) 937 920 $newtext .= '</' . $x . '>'; // Add remaining tags to close 938 }939 921 940 922 // WP fix for the bug with HTML comments 941 923 $newtext = str_replace("< !--","<!--",$newtext); … … 957 939 * @param bool $richedit Whether or not the $content should pass through htmlspecialchars(). Default false. 958 940 * @return string The text after the filter (and possibly htmlspecialchars()) has been run. 959 941 */ 960 function format_to_edit( $content, $richedit = false) {942 function format_to_edit( $content, $richedit = false ) { 961 943 $content = apply_filters('format_to_edit', $content); 962 944 if (! $richedit ) 963 945 $content = htmlspecialchars($content); … … 972 954 * @param string $content The text to pass through the filter. 973 955 * @return string Text returned from the 'format_to_post' filter. 974 956 */ 975 function format_to_post( $content) {957 function format_to_post( $content ) { 976 958 $content = apply_filters('format_to_post', $content); 977 959 return $content; 978 960 } … … 994 976 * @param int $threshold Digit places number needs to be to not have zeros added. 995 977 * @return string Adds leading zeros to number if needed. 996 978 */ 997 function zeroise( $number, $threshold) {998 return sprintf( '%0'.$threshold.'s', $number);979 function zeroise( $number, $threshold ) { 980 return sprintf( '%0'.$threshold.'s', $number ); 999 981 } 1000 982 1001 983 /** … … 1006 988 * @param string $string Value to which backslashes will be added. 1007 989 * @return string String with backslashes inserted. 1008 990 */ 1009 function backslashit( $string) {991 function backslashit( $string ) { 1010 992 $string = preg_replace('/^([0-9])/', '\\\\\\\\\1', $string); 1011 993 $string = preg_replace('/([a-z])/i', '\\\\\1', $string); 1012 994 return $string; … … 1027 1009 * @param string $string What to add the trailing slash to. 1028 1010 * @return string String with trailing slash added. 1029 1011 */ 1030 function trailingslashit( $string) {1031 return untrailingslashit( $string) . '/';1012 function trailingslashit( $string ) { 1013 return untrailingslashit( $string ) . '/'; 1032 1014 } 1033 1015 1034 1016 /** … … 1042 1024 * @param string $string What to remove the trailing slash from. 1043 1025 * @return string String without the trailing slash. 1044 1026 */ 1045 function untrailingslashit( $string) {1046 return rtrim( $string, '/');1027 function untrailingslashit( $string ) { 1028 return rtrim( $string, '/' ); 1047 1029 } 1048 1030 1049 1031 /** … … 1057 1039 * @param string $gpc The string returned from HTTP request data. 1058 1040 * @return string Returns a string escaped with slashes. 1059 1041 */ 1060 function addslashes_gpc( $gpc) {1042 function addslashes_gpc( $gpc ) { 1061 1043 global $wpdb; 1062 1044 1063 if (get_magic_quotes_gpc()) {1045 if (get_magic_quotes_gpc()) 1064 1046 $gpc = stripslashes($gpc); 1065 }1066 1047 1067 1048 return $wpdb->escape($gpc); 1068 1049 } … … 1078 1059 * @param array|string $value The array or string to be striped. 1079 1060 * @return array|string Stripped array (or string in the callback). 1080 1061 */ 1081 function stripslashes_deep( $value) {1062 function stripslashes_deep( $value ) { 1082 1063 $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); 1083 1064 return $value; 1084 1065 } … … 1094 1075 * @param array|string $value The array or string to be encoded. 1095 1076 * @return array|string $value The encoded array (or string from the callback). 1096 1077 */ 1097 function urlencode_deep( $value) {1078 function urlencode_deep( $value ) { 1098 1079 $value = is_array($value) ? array_map('urlencode_deep', $value) : urlencode($value); 1099 1080 return $value; 1100 1081 } … … 1108 1089 * @param int $mailto Optional. Range from 0 to 1. Used for encoding. 1109 1090 * @return string Converted email address. 1110 1091 */ 1111 function antispambot( $emailaddy, $mailto=0) {1092 function antispambot( $emailaddy, $mailto = 0 ) { 1112 1093 $emailNOSPAMaddy = ''; 1113 srand ((float) microtime() * 1000000);1114 for ( $i = 0; $i < strlen($emailaddy); $i = $i + 1) {1094 srand((float) microtime() * 1000000); 1095 for ( $i = 0; $i < strlen($emailaddy); $i++ ) { 1115 1096 $j = floor(rand(0, 1+$mailto)); 1116 if ( $j==0) {1097 if ( $j == 0 ) 1117 1098 $emailNOSPAMaddy .= '&#'.ord(substr($emailaddy,$i,1)).';'; 1118 } elseif ($j==1) {1099 elseif ( $j == 1 ) 1119 1100 $emailNOSPAMaddy .= substr($emailaddy,$i,1); 1120 } elseif ($j==2) {1101 elseif ( $j == 2 ) 1121 1102 $emailNOSPAMaddy .= '%'.zeroise(dechex(ord(substr($emailaddy, $i, 1))), 2); 1122 }1123 1103 } 1124 1104 $emailNOSPAMaddy = str_replace('@','@',$emailNOSPAMaddy); 1125 1105 return $emailNOSPAMaddy; … … 1137 1117 * @param array $matches Single Regex Match. 1138 1118 * @return string HTML A element with URI address. 1139 1119 */ 1140 function _make_url_clickable_cb( $matches) {1120 function _make_url_clickable_cb( $matches ) { 1141 1121 $url = $matches[2]; 1142 1122 $url = clean_url($url); 1143 1123 if ( empty($url) ) 1144 1124 return $matches[0]; 1145 return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>";1125 return $matches[1] . '<a href="$url" rel="nofollow">$url</a>'; 1146 1126 } 1147 1127 1148 1128 /** … … 1157 1137 * @param array $matches Single Regex Match. 1158 1138 * @return string HTML A element with URL address. 1159 1139 */ 1160 function _make_web_ftp_clickable_cb( $matches) {1140 function _make_web_ftp_clickable_cb( $matches ) { 1161 1141 $ret = ''; 1162 1142 $dest = $matches[2]; 1163 1143 $dest = 'http://' . $dest; … … 1169 1149 $ret = substr($dest, -1); 1170 1150 $dest = substr($dest, 0, strlen($dest)-1); 1171 1151 } 1172 return $matches[1] . "<a href=\"$dest\" rel=\"nofollow\">$dest</a>". $ret;1152 return $matches[1] . '<a href="$dest" rel="nofollow">$dest</a>' . $ret; 1173 1153 } 1174 1154 1175 1155 /** … … 1184 1164 * @param array $matches Single Regex Match. 1185 1165 * @return string HTML A element with email address. 1186 1166 */ 1187 function _make_email_clickable_cb( $matches) {1167 function _make_email_clickable_cb( $matches ) { 1188 1168 $email = $matches[2] . '@' . $matches[3]; 1189 return $matches[1] . "<a href=\"mailto:$email\">$email</a>";1169 return $matches[1] . '<a href="mailto:$email">$email</a>'; 1190 1170 } 1191 1171 1192 1172 /** … … 1200 1180 * @param string $ret Content to convert URIs. 1201 1181 * @return string Content with converted URIs. 1202 1182 */ 1203 function make_clickable( $ret) {1183 function make_clickable( $ret ) { 1204 1184 $ret = ' ' . $ret; 1205 1185 // in testing, using arrays here was found to be faster 1206 1186 $ret = preg_replace_callback('#(?<=[\s>])(\()?([\w]+?://(?:[\w\\x80-\\xff\#$%&~/\-=?@\[\](+]|[.,;:](?![\s<])|(?(1)\)(?![\s<])|\)))+)#is', '_make_url_clickable_cb', $ret); … … 1243 1223 function wp_rel_nofollow_callback( $matches ) { 1244 1224 $text = $matches[1]; 1245 1225 $text = str_replace(array(' rel="nofollow"', " rel='nofollow'"), '', $text); 1246 return "<a $text rel=\"nofollow\">";1226 return '<a $text rel="nofollow">'; 1247 1227 } 1248 1228 1249 1229 … … 1259 1239 * @param string $smiley Smiley code to convert to image. 1260 1240 * @return string Image string for smiley. 1261 1241 */ 1262 function translate_smiley( $smiley) {1242 function translate_smiley( $smiley ) { 1263 1243 global $wpsmiliestrans; 1264 1244 1265 if ( count($smiley) == 0) {1245 if ( count($smiley) == 0 ) 1266 1246 return ''; 1267 }1268 1247 1269 1248 $siteurl = get_option( 'siteurl' ); 1270 1249 … … 1272 1251 $img = $wpsmiliestrans[$smiley]; 1273 1252 $smiley_masked = attr($smiley); 1274 1253 1275 return " <img src='$siteurl/wp-includes/images/smilies/$img' alt='$smiley_masked' class='wp-smiley' /> ";1254 return '<img src="$siteurl/wp-includes/images/smilies/$img" alt="$smiley_masked" class="wp-smiley" /> '; 1276 1255 } 1277 1256 1278 1257 … … 1288 1267 * @param string $text Content to convert smilies from text. 1289 1268 * @return string Converted content with text smilies replaced with images. 1290 1269 */ 1291 function convert_smilies( $text) {1270 function convert_smilies( $text ) { 1292 1271 global $wp_smiliessearch; 1293 1272 $output = ''; 1294 1273 if ( get_option('use_smilies') && !empty($wp_smiliessearch) ) { 1295 1274 // HTML loop taken from texturize function, could possible be consolidated 1296 1275 $textarr = preg_split("/(<.*>)/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between 1297 1276 $stop = count($textarr);// loop stuff 1298 for ( $i = 0; $i < $stop; $i++) {1277 for ( $i = 0; $i < $stop; $i++ ) { 1299 1278 $content = $textarr[$i]; 1300 if ( (strlen($content) > 0) && ('<' != $content{0})) {// If it's not a tag1279 if ( (strlen($content) > 0) && ('<' != $content{0}) ) // If it's not a tag 1301 1280 $content = preg_replace_callback($wp_smiliessearch, 'translate_smiley', $content); 1302 }1303 1281 $output .= $content; 1304 1282 } 1305 1283 } else { … … 1322 1300 */ 1323 1301 function is_email( $email, $check_dns = false ) { 1324 1302 // Test for the minimum length the email can be 1325 if ( strlen( $email ) < 3 ) {1303 if ( strlen( $email ) < 3 ) 1326 1304 return apply_filters( 'is_email', false, $email, 'email_too_short' ); 1327 }1328 1305 1329 1306 // Test for an @ character after the first position 1330 if ( strpos( $email, '@', 1 ) === false ) {1307 if ( strpos( $email, '@', 1 ) === false ) 1331 1308 return apply_filters( 'is_email', false, $email, 'email_no_at' ); 1332 }1333 1309 1334 1310 // Split out the local and domain parts 1335 1311 list( $local, $domain ) = explode( '@', $email, 2 ); 1336 1312 1337 1313 // LOCAL PART 1338 1314 // Test for invalid characters 1339 if ( !preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) {1315 if ( !preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) 1340 1316 return apply_filters( 'is_email', false, $email, 'local_invalid_chars' ); 1341 }1342 1317 1343 1318 // DOMAIN PART 1344 1319 // Test for sequences of periods 1345 if ( preg_match( '/\.{2,}/', $domain ) ) {1320 if ( preg_match( '/\.{2,}/', $domain ) ) 1346 1321 return apply_filters( 'is_email', false, $email, 'domain_period_sequence' ); 1347 }1348 1322 1349 1323 // Test for leading and trailing periods and whitespace 1350 if ( trim( $domain, " \t\n\r\0\x0B." ) !== $domain ) {1324 if ( trim( $domain, " \t\n\r\0\x0B." ) !== $domain ) 1351 1325 return apply_filters( 'is_email', false, $email, 'domain_period_limits' ); 1352 }1353 1326 1354 1327 // Split the domain into subs 1355 1328 $subs = explode( '.', $domain ); 1356 1329 1357 1330 // Assume the domain will have at least two subs 1358 if ( 2 > count( $subs ) ) {1331 if ( 2 > count( $subs ) ) 1359 1332 return apply_filters( 'is_email', false, $email, 'domain_no_periods' ); 1360 }1361 1333 1362 1334 // Loop through each sub 1363 1335 foreach ( $subs as $sub ) { 1364 1336 // Test for leading and trailing hyphens and whitespace 1365 if ( trim( $sub, " \t\n\r\0\x0B-" ) !== $sub ) {1337 if ( trim( $sub, " \t\n\r\0\x0B-" ) !== $sub ) 1366 1338 return apply_filters( 'is_email', false, $email, 'sub_hyphen_limits' ); 1367 }1368 1339 1369 1340 // Test for invalid characters 1370 if ( !preg_match('/^[a-z0-9-]+$/i', $sub ) ) {1341 if ( !preg_match('/^[a-z0-9-]+$/i', $sub ) ) 1371 1342 return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' ); 1372 }1373 1343 } 1374 1344 1375 1345 // DNS 1376 1346 // Check the domain has a valid MX and A resource record 1377 if ( $check_dns && function_exists( 'checkdnsrr' ) && !( checkdnsrr( $domain . '.', 'MX' ) || checkdnsrr( $domain . '.', 'A' ) ) ) {1347 if ( $check_dns && function_exists( 'checkdnsrr' ) && !( checkdnsrr( $domain . '.', 'MX' ) || checkdnsrr( $domain . '.', 'A' ) ) ) 1378 1348 return apply_filters( 'is_email', false, $email, 'dns_no_rr' ); 1379 }1380 1349 1381 1350 // Congratulations your email made it! 1382 1351 return apply_filters( 'is_email', $email, $email, null ); … … 1391 1360 * @param string $string Subject line 1392 1361 * @return string Converted string to ASCII 1393 1362 */ 1394 function wp_iso_descrambler( $string) {1363 function wp_iso_descrambler( $string ) { 1395 1364 /* this may only work with iso-8859-1, I'm afraid */ 1396 if ( !preg_match('#\=\?(.+)\?Q\?(.+)\?\=#i', $string, $matches)) {1365 if ( !preg_match('#\=\?(.+)\?Q\?(.+)\?\=#i', $string, $matches) ) { 1397 1366 return $string; 1398 1367 } else { 1399 1368 $subject = str_replace('_', ' ', $matches[2]); … … 1414 1383 * @param string $string The date to be converted. 1415 1384 * @return string GMT version of the date provided. 1416 1385 */ 1417 function get_gmt_from_date( $string) {1386 function get_gmt_from_date( $string ) { 1418 1387 preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches); 1419 1388 $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); 1420 1389 $string_gmt = gmdate('Y-m-d H:i:s', $string_time - get_option('gmt_offset') * 3600); … … 1432 1401 * @param string $string The date to be converted. 1433 1402 * @return string Formatted date relative to the GMT offset. 1434 1403 */ 1435 function get_date_from_gmt( $string) {1404 function get_date_from_gmt( $string ) { 1436 1405 preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches); 1437 1406 $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); 1438 1407 $string_localtime = gmdate('Y-m-d H:i:s', $string_time + get_option('gmt_offset')*3600); … … 1447 1416 * @param string $timezone Either 'Z' for 0 offset or '±hhmm'. 1448 1417 * @return int|float The offset in seconds. 1449 1418 */ 1450 function iso8601_timezone_to_offset( $timezone) {1419 function iso8601_timezone_to_offset( $timezone ) { 1451 1420 // $timezone is either 'Z' or '[+|-]hhmm' 1452 if ( $timezone == 'Z') {1421 if ( $timezone == 'Z' ) { 1453 1422 $offset = 0; 1454 1423 } else { 1455 1424 $sign = (substr($timezone, 0, 1) == '+') ? 1 : -1; … … 1469 1438 * @param string $timezone Optional. If set to GMT returns the time minus gmt_offset. Default is 'user'. 1470 1439 * @return string The date and time in MySQL DateTime format - Y-m-d H:i:s. 1471 1440 */ 1472 function iso8601_to_datetime( $date_string, $timezone = 'user') {1441 function iso8601_to_datetime( $date_string, $timezone = 'user' ) { 1473 1442 $timezone = strtolower($timezone); 1474 1443 1475 if ( $timezone == 'gmt') {1444 if ( $timezone == 'gmt' ) { 1476 1445 1477 1446 preg_match('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', $date_string, $date_bits); 1478 1447 1479 if ( !empty($date_bits[7])) {// we have a timezone, so let's compute an offset1448 if ( !empty($date_bits[7]) ) // we have a timezone, so let's compute an offset 1480 1449 $offset = iso8601_timezone_to_offset($date_bits[7]); 1481 } else {// we don't have a timezone, so we assume user local timezone (not server's!)1450 else // we don't have a timezone, so we assume user local timezone (not server's!) 1482 1451 $offset = 3600 * get_option('gmt_offset'); 1483 }1484 1452 1485 1453 $timestamp = gmmktime($date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1]); 1486 1454 $timestamp -= $offset; 1487 1455 1488 1456 return gmdate('Y-m-d H:i:s', $timestamp); 1489 1457 1490 } else if ( $timezone == 'user') {1458 } else if ( $timezone == 'user' ) { 1491 1459 return preg_replace('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', '$1-$2-$3 $4:$5:$6', $date_string); 1492 1460 } 1493 1461 } … … 1504 1472 * @param string $text Content to replace links to open in a new window. 1505 1473 * @return string Content that has filtered links. 1506 1474 */ 1507 function popuplinks( $text) {1508 $text = preg_replace('/<a (.+?)>/i', "<a $1 target='_blank' rel='external'>", $text);1475 function popuplinks( $text ) { 1476 $text = preg_replace('/<a (.+?)>/i', '<a $1 target="_blank" rel="external">', $text); 1509 1477 return $text; 1510 1478 } 1511 1479 … … 1519 1487 */ 1520 1488 function sanitize_email( $email ) { 1521 1489 // Test for the minimum length the email can be 1522 if ( strlen( $email ) < 3 ) {1490 if ( strlen( $email ) < 3 ) 1523 1491 return apply_filters( 'sanitize_email', '', $email, 'email_too_short' ); 1524 }1525 1492 1526 1493 // Test for an @ character after the first position 1527 if ( strpos( $email, '@', 1 ) === false ) {1494 if ( strpos( $email, '@', 1 ) === false ) 1528 1495 return apply_filters( 'sanitize_email', '', $email, 'email_no_at' ); 1529 }1530 1496 1531 1497 // Split out the local and domain parts 1532 1498 list( $local, $domain ) = explode( '@', $email, 2 ); … … 1534 1500 // LOCAL PART 1535 1501 // Test for invalid characters 1536 1502 $local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local ); 1537 if ( '' === $local ) {1503 if ( '' === $local ) 1538 1504 return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' ); 1539 }1540 1505 1541 1506 // DOMAIN PART 1542 1507 // Test for sequences of periods 1543 1508 $domain = preg_replace( '/\.{2,}/', '', $domain ); 1544 if ( '' === $domain ) {1509 if ( '' === $domain ) 1545 1510 return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' ); 1546 }1547 1511 1548 1512 // Test for leading and trailing periods and whitespace 1549 1513 $domain = trim( $domain, " \t\n\r\0\x0B." ); 1550 if ( '' === $domain ) {1514 if ( '' === $domain ) 1551 1515 return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' ); 1552 }1553 1516 1554 1517 // Split the domain into subs 1555 1518 $subs = explode( '.', $domain ); 1556 1519 1557 1520 // Assume the domain will have at least two subs 1558 if ( 2 > count( $subs ) ) {1521 if ( 2 > count( $subs ) ) 1559 1522 return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' ); 1560 }1561 1523 1562 1524 // Create an array that will contain valid subs 1563 1525 $new_subs = array(); … … 1571 1533 $sub = preg_replace( '/^[^a-z0-9-]+$/i', '', $sub ); 1572 1534 1573 1535 // If there's anything left, add it to the valid subs 1574 if ( '' !== $sub ) {1536 if ( '' !== $sub ) 1575 1537 $new_subs[] = $sub; 1576 }1577 1538 } 1578 1539 1579 1540 // If there aren't 2 or more valid subs 1580 if ( 2 > count( $new_subs ) ) {1541 if ( 2 > count( $new_subs ) ) 1581 1542 return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' ); 1582 }1583 1543 1584 1544 // Join valid subs into the new domain 1585 1545 $domain = join( '.', $new_subs ); … … 1607 1567 if ( empty($to) ) 1608 1568 $to = time(); 1609 1569 $diff = (int) abs($to - $from); 1610 if ( $diff <= 3600) {1570 if ( $diff <= 3600 ) { 1611 1571 $mins = round($diff / 60); 1612 if ( $mins <= 1) {1572 if ( $mins <= 1 ) 1613 1573 $mins = 1; 1614 }1615 1574 $since = sprintf(_n('%s min', '%s mins', $mins), $mins); 1616 } else if ( ($diff <= 86400) && ($diff > 3600)) {1575 } else if ( ($diff <= 86400) && ($diff > 3600) ) { 1617 1576 $hours = round($diff / 3600); 1618 if ( $hours <= 1) {1577 if ( $hours <= 1 ) 1619 1578 $hours = 1; 1620 }1621 1579 $since = sprintf(_n('%s hour', '%s hours', $hours), $hours); 1622 } elseif ( $diff >= 86400) {1580 } elseif ( $diff >= 86400 ) { 1623 1581 $days = round($diff / 86400); 1624 if ( $days <= 1) {1582 if ( $days <= 1 ) 1625 1583 $days = 1; 1626 }1627 1584 $since = sprintf(_n('%s day', '%s days', $days), $days); 1628 1585 } 1629 1586 return $since; … … 1641 1598 * @param string $text The exerpt. If set to empty an excerpt is generated. 1642 1599 * @return string The excerpt. 1643 1600 */ 1644 function wp_trim_excerpt( $text) {1601 function wp_trim_excerpt( $text ) { 1645 1602 $raw_excerpt = $text; 1646 1603 if ( '' == $text ) { 1647 1604 $text = get_the_content(''); … … 1653 1610 $text = strip_tags($text); 1654 1611 $excerpt_length = apply_filters('excerpt_length', 55); 1655 1612 $words = explode(' ', $text, $excerpt_length + 1); 1656 if ( count($words) > $excerpt_length) {1613 if ( count($words) > $excerpt_length ) { 1657 1614 array_pop($words); 1658 1615 array_push($words, '[...]'); 1659 1616 $text = implode(' ', $words); … … 1670 1627 * @param string $text The text within which entities will be converted. 1671 1628 * @return string Text with converted entities. 1672 1629 */ 1673 function ent2ncr( $text) {1630 function ent2ncr( $text ) { 1674 1631 $to_ncr = array( 1675 1632 '"' => '"', 1676 1633 '&' => '&', … … 1945 1902 * @param string $text The text to be formatted. 1946 1903 * @return string The formatted text after filter is applied. 1947 1904 */ 1948 function wp_richedit_pre( $text) {1905 function wp_richedit_pre( $text ) { 1949 1906 // Filtering a blank results in an annoying <br />\n 1950 if ( empty($text) ) return apply_filters('richedit_pre', ''); 1907 if ( empty($text) ) 1908 return apply_filters('richedit_pre', ''); 1951 1909 1952 1910 $output = convert_chars($text); 1953 1911 $output = wpautop($output); … … 1967 1925 * @param string $output The text to be formatted. 1968 1926 * @return string Formatted text after filter applied. 1969 1927 */ 1970 function wp_htmledit_pre( $output) {1928 function wp_htmledit_pre( $output ) { 1971 1929 if ( !empty($output) ) 1972 1930 $output = htmlspecialchars($output, ENT_NOQUOTES); // convert only < > & 1973 1931 … … 1994 1952 function clean_url( $url, $protocols = null, $context = 'display' ) { 1995 1953 $original_url = $url; 1996 1954 1997 if ('' == $url) return $url; 1955 if ( '' == $url ) 1956 return $url; 1957 1998 1958 $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]|i', '', $url); 1999 1959 $strip = array('%0d', '%0a'); 2000 1960 $url = str_replace($strip, '', $url); … … 2003 1963 * presume it needs http:// appended (unless a relative 2004 1964 * link starting with / or a php file). 2005 1965 */ 2006 if ( strpos($url, ':') === false && 2007 substr( $url, 0, 1 ) != '/' && substr( $url, 0, 1 ) != '#' && !preg_match('/^[a-z0-9-]+?\.php/i', $url) ) 1966 if ( strpos($url, ':') === false && substr( $url, 0, 1 ) != '/' && substr( $url, 0, 1 ) != '#' && !preg_match('/^[a-z0-9-]+?\.php/i', $url) ) 2008 1967 $url = 'http://' . $url; 2009 1968 2010 1969 // Replace ampersands and single quotes only when displaying. … … 2046 2005 * @param string $myHTML The text to be converted. 2047 2006 * @return string Converted text. 2048 2007 */ 2049 function htmlentities2( $myHTML) {2008 function htmlentities2( $myHTML ) { 2050 2009 $translation_table = get_html_translation_table( HTML_ENTITIES, ENT_QUOTES ); 2051 2010 $translation_table[chr(38)] = '&'; 2052 2011 return preg_replace( "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/", "&", strtr($myHTML, $translation_table) ); … … 2062 2021 * @param string $text The text to be escaped. 2063 2022 * @return string Escaped text. 2064 2023 */ 2065 function js_escape( $text) {2024 function js_escape( $text ) { 2066 2025 $safe_text = wp_check_invalid_utf8( $text ); 2067 2026 $safe_text = wp_specialchars( $safe_text, ENT_COMPAT ); 2068 2027 $safe_text = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes( $safe_text ) ); … … 2107 2066 * @param string $tag_name 2108 2067 * @return string 2109 2068 */ 2110 function tag_escape( $tag_name) {2069 function tag_escape( $tag_name ) { 2111 2070 $safe_tag = strtolower( preg_replace('/[^a-zA-Z_:]/', '', $tag_name) ); 2112 2071 return apply_filters('tag_escape', $safe_tag, $tag_name); 2113 2072 } … … 2120 2079 * @param string $text The text to be escaped. 2121 2080 * @return string text, safe for inclusion in LIKE query. 2122 2081 */ 2123 function like_escape( $text) {2082 function like_escape( $text ) { 2124 2083 return str_replace(array("%", "_"), array("\\%", "\\_"), $text); 2125 2084 } 2126 2085 … … 2151 2110 * @param string $value The unsanitised value. 2152 2111 * @return string Sanitized value. 2153 2112 */ 2154 function sanitize_option( $option, $value) {2113 function sanitize_option( $option, $value ) { 2155 2114 2156 switch ( $option) {2115 switch ( $option ) { 2157 2116 case 'admin_email': 2158 2117 $value = sanitize_email($value); 2159 2118 break; … … 2181 2140 case 'posts_per_page': 2182 2141 case 'posts_per_rss': 2183 2142 $value = (int) $value; 2184 if ( empty($value) ) $value = 1; 2185 if ( $value < -1 ) $value = abs($value); 2143 if ( empty($value) ) 2144 $value = 1; 2145 if ( $value < -1 ) 2146 $value = abs($value); 2186 2147 break; 2187 2148 2188 2149 case 'default_ping_status': 2189 2150 case 'default_comment_status': 2190 2151 // Options that if not there have 0 value but need to be something like "closed" 2191 if ( $value == '0' || $value == '' )2152 if ( $value == '0' || $value == '' ) 2192 2153 $value = 'closed'; 2193 2154 break; 2194 2155 … … 2358 2319 * @param array $args List items to prepend to the content and replace '%l'. 2359 2320 * @return string Localized list items and rest of the content. 2360 2321 */ 2361 function wp_sprintf_l( $pattern, $args) {2322 function wp_sprintf_l( $pattern, $args ) { 2362 2323 // Not a match 2363 2324 if ( substr($pattern, 0, 2) != '%l' ) 2364 2325 return $pattern; … … 2445 2406 * @param string $base The base URL to prefix to links. 2446 2407 * @return string The processed link. 2447 2408 */ 2448 function _links_add_base( $m, $base) {2409 function _links_add_base( $m, $base ) { 2449 2410 //1 = attribute name 2 = quotation mark 3 = URL 2450 return $m[1] . '=' . $m[2] . 2451 (strpos($m[3], 'http://') === false ? 2452 path_join($base, $m[3]) : 2453 $m[3]) 2454 . $m[2]; 2411 return $m[1] . '=' . $m[2] . (strpos($m[3], 'http://') === false ? path_join($base, $m[3]) : $m[3]) . $m[2]; 2455 2412 } 2456 2413 2457 2414 /** … … 2471 2428 */ 2472 2429 function links_add_target( $content, $target = '_blank', $tags = array('a') ) { 2473 2430 $tags = implode('|', (array)$tags); 2474 return preg_replace_callback("!<($tags)(.+?)>!i", 2431 return preg_replace_callback("!<($tags)(.+?)>!i", 2475 2432 create_function('$m', 'return _links_add_target($m, "' . $target . '");'), 2476 2433 $content); 2477 2434 }