Changes from branches/3.0/wp-includes/formatting.php at r17172 to trunk/wp-includes/formatting.php at r17459
- File:
-
- 1 edited
-
trunk/wp-includes/formatting.php (modified) (34 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/formatting.php
r17172 r17459 57 57 $static_replacements = array_merge(array('—', ' — ', '–', ' – ', 'xn--', '…', $opening_quote, $closing_quote, ' ™'), $cockneyreplace); 58 58 59 $dynamic_characters = array('/\'(\d\d(?:’|\')?s)/', '/\'(\d +)/', '/(\s|\A|[([{<]|")\'/', '/(\d+)"/', '/(\d+)\'/', '/(\S)\'([^\'\s])/', '/(\s|\A|[([{<])"(?!\s)/', '/"(\s|\S|\Z)/', '/\'([\s.]|\Z)/', '/\b(\d+)x(\d+)\b/');59 $dynamic_characters = array('/\'(\d\d(?:’|\')?s)/', '/\'(\d)/', '/(\s|\A|[([{<]|")\'/', '/(\d)"/', '/(\d)\'/', '/(\S)\'([^\'\s])/', '/(\s|\A|[([{<])"(?!\s)/', '/"(\s|\S|\Z)/', '/\'([\s.]|\Z)/', '/\b(\d+)x(\d+)\b/'); 60 60 $dynamic_replacements = array('’$1','’$1', '$1‘', '$1″', '$1′', '$1’$2', '$1' . $opening_quote . '$2', $closing_quote . '$1', '’$1', '$1×$2'); 61 61 … … 74 74 $curl = $textarr[$i]; 75 75 76 if ( !empty($curl) && '<' != $curl {0} && '[' != $curl{0}76 if ( !empty($curl) && '<' != $curl[0] && '[' != $curl[0] 77 77 && empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack)) { 78 78 // This is not a tag, nor is the texturization disabled … … 86 86 * tag opening 87 87 */ 88 if ('<' == $curl {0})88 if ('<' == $curl[0]) 89 89 _wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>'); 90 elseif ('[' == $curl {0})90 elseif ('[' == $curl[0]) 91 91 _wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']'); 92 92 } … … 209 209 $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); 210 210 if ($br) { 211 $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', create_function('$matches', 'return str_replace("\n", "<WPPreserveNewline />", $matches[0]);'), $pee);211 $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee); 212 212 $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks 213 213 $pee = str_replace('<WPPreserveNewline />', "\n", $pee); … … 220 220 221 221 return $pee; 222 } 223 224 /** 225 * Newline preservation help function for wpautop 226 * 227 * @since 3.1.0 228 * @access private 229 * @param array $matches preg_replace_callback matches array 230 * @returns string 231 */ 232 function _autop_newline_preservation_helper( $matches ) { 233 return str_replace("\n", "<WPPreserveNewline />", $matches[0]); 222 234 } 223 235 … … 539 551 chr(195).chr(130) => 'A', chr(195).chr(131) => 'A', 540 552 chr(195).chr(132) => 'A', chr(195).chr(133) => 'A', 541 chr(195).chr(135) => 'C', chr(195).chr(136) => 'E', 542 chr(195).chr(137) => 'E', chr(195).chr(138) => 'E', 543 chr(195).chr(139) => 'E', chr(195).chr(140) => 'I', 544 chr(195).chr(141) => 'I', chr(195).chr(142) => 'I', 545 chr(195).chr(143) => 'I', chr(195).chr(145) => 'N', 553 chr(195).chr(134) => 'AE',chr(195).chr(135) => 'C', 554 chr(195).chr(136) => 'E', chr(195).chr(137) => 'E', 555 chr(195).chr(138) => 'E', chr(195).chr(139) => 'E', 556 chr(195).chr(140) => 'I', chr(195).chr(141) => 'I', 557 chr(195).chr(142) => 'I', chr(195).chr(143) => 'I', 558 chr(195).chr(144) => 'D', chr(195).chr(145) => 'N', 546 559 chr(195).chr(146) => 'O', chr(195).chr(147) => 'O', 547 560 chr(195).chr(148) => 'O', chr(195).chr(149) => 'O', … … 549 562 chr(195).chr(154) => 'U', chr(195).chr(155) => 'U', 550 563 chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y', 551 chr(195).chr(159) => 's', chr(195).chr(160) => 'a', 552 chr(195).chr(161) => 'a', chr(195).chr(162) => 'a', 553 chr(195).chr(163) => 'a', chr(195).chr(164) => 'a', 554 chr(195).chr(165) => 'a', chr(195).chr(167) => 'c', 564 chr(195).chr(158) => 'TH',chr(195).chr(159) => 's', 565 chr(195).chr(160) => 'a', chr(195).chr(161) => 'a', 566 chr(195).chr(162) => 'a', chr(195).chr(163) => 'a', 567 chr(195).chr(164) => 'a', chr(195).chr(165) => 'a', 568 chr(195).chr(166) => 'ae',chr(195).chr(167) => 'c', 555 569 chr(195).chr(168) => 'e', chr(195).chr(169) => 'e', 556 570 chr(195).chr(170) => 'e', chr(195).chr(171) => 'e', 557 571 chr(195).chr(172) => 'i', chr(195).chr(173) => 'i', 558 572 chr(195).chr(174) => 'i', chr(195).chr(175) => 'i', 559 chr(195).chr(177) => 'n', chr(195).chr(178) => 'o', 560 chr(195).chr(179) => 'o', chr(195).chr(180) => 'o', 561 chr(195).chr(181) => 'o', chr(195).chr(182) => 'o', 562 chr(195).chr(182) => 'o', chr(195).chr(185) => 'u', 563 chr(195).chr(186) => 'u', chr(195).chr(187) => 'u', 564 chr(195).chr(188) => 'u', chr(195).chr(189) => 'y', 573 chr(195).chr(176) => 'd', chr(195).chr(177) => 'n', 574 chr(195).chr(178) => 'o', chr(195).chr(179) => 'o', 575 chr(195).chr(180) => 'o', chr(195).chr(181) => 'o', 576 chr(195).chr(182) => 'o', chr(195).chr(182) => 'o', 577 chr(195).chr(185) => 'u', chr(195).chr(186) => 'u', 578 chr(195).chr(187) => 'u', chr(195).chr(188) => 'u', 579 chr(195).chr(189) => 'y', chr(195).chr(190) => 'th', 565 580 chr(195).chr(191) => 'y', 566 581 // Decompositions for Latin Extended-A … … 629 644 chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z', 630 645 chr(197).chr(190) => 'z', chr(197).chr(191) => 's', 646 // Decompositions for Latin Extended-B 647 chr(200).chr(152) => 'S', chr(200).chr(153) => 's', 648 chr(200).chr(154) => 'T', chr(200).chr(155) => 't', 631 649 // Euro Sign 632 650 chr(226).chr(130).chr(172) => 'E', … … 719 737 * Sanitize username stripping out unsafe characters. 720 738 * 721 * If $strict is true, only alphanumeric characters (as well as _, space, ., -, 722 * @) are returned. 723 * Removes tags, octets, entities, and if strict is enabled, will remove all 724 * non-ASCII characters. After sanitizing, it passes the username, raw username 725 * (the username in the parameter), and the strict parameter as parameters for 726 * the filter. 739 * Removes tags, octets, entities, and if strict is enabled, will only keep 740 * alphanumeric, _, space, ., -, @. After sanitizing, it passes the username, 741 * raw username (the username in the parameter), and the value of $strict as 742 * parameters for the 'sanitize_user' filter. 727 743 * 728 744 * @since 2.0.0 … … 746 762 $username = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $username ); 747 763 764 $username = trim( $username ); 748 765 // Consolidate contiguous whitespace 749 766 $username = preg_replace( '|\s+|', ' ', $username ); … … 755 772 * Sanitize a string key. 756 773 * 757 * Keys are used as internal identifiers. They should be lowercase ASCII. Dashes and underscores are allowed.774 * Keys are used as internal identifiers. Lowercase alphanumeric characters, dashes and underscores are allowed. 758 775 * 759 776 * @since 3.0.0 … … 764 781 function sanitize_key( $key ) { 765 782 $raw_key = $key; 766 $key = wp_strip_all_tags($key); 767 // Kill octets 768 $key = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '', $key); 769 $key = preg_replace('/&.+?;/', '', $key); // Kill entities 770 771 $key = preg_replace('|[^a-z0-9 _.\-@]|i', '', $key); 772 773 // Consolidate contiguous whitespace 774 $key = preg_replace('|\s+|', ' ', $key); 775 776 return apply_filters('sanitize_key', $key, $raw_key); 783 $key = strtolower( $key ); 784 $key = preg_replace( '/[^a-z0-9_\-]/', '', $key ); 785 return apply_filters( 'sanitize_key', $key, $raw_key ); 777 786 } 778 787 … … 788 797 * @param string $title The string to be sanitized. 789 798 * @param string $fallback_title Optional. A title to use if $title is empty. 799 * @param string $context Optional. The operation for which the string is sanitized 790 800 * @return string The sanitized string. 791 801 */ 792 function sanitize_title($title, $fallback_title = '' ) {802 function sanitize_title($title, $fallback_title = '', $context = 'save') { 793 803 $raw_title = $title; 794 $title = strip_tags($title); 795 $title = apply_filters('sanitize_title', $title, $raw_title); 804 805 if ( 'save' == $context ) 806 $title = remove_accents($title); 807 808 $title = apply_filters('sanitize_title', $title, $raw_title, $context); 796 809 797 810 if ( '' === $title || false === $title ) … … 799 812 800 813 return $title; 814 } 815 816 function sanitize_title_for_query($title) { 817 return sanitize_title($title, '', 'query'); 801 818 } 802 819 … … 821 838 $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title); 822 839 823 $title = remove_accents($title);824 840 if (seems_utf8($title)) { 825 841 if (function_exists('mb_strtolower')) { … … 981 997 * 982 998 * @author Leonard Lin <leonard@acm.org> 983 * @license GPL v2.0999 * @license GPL 984 1000 * @copyright November 4, 2001 985 1001 * @version 1.1 … … 1099 1115 * 1100 1116 * Unless $richedit is set, it is simply a holder for the 'format_to_edit' 1101 * filter. If $richedit is set true htmlspecialchars() will be run on the1102 * content, converting special characters to HTMlentities.1117 * filter. If $richedit is set true htmlspecialchars(), through esc_textarea(), 1118 * will be run on the content, converting special characters to HTML entities. 1103 1119 * 1104 1120 * @since 0.71 … … 1108 1124 * @return string The text after the filter (and possibly htmlspecialchars()) has been run. 1109 1125 */ 1110 function format_to_edit( $content, $richedit = false) {1111 $content = apply_filters( 'format_to_edit', $content);1112 if ( ! $richedit )1113 $content = htmlspecialchars($content);1126 function format_to_edit( $content, $richedit = false ) { 1127 $content = apply_filters( 'format_to_edit', $content ); 1128 if ( ! $richedit ) 1129 $content = esc_textarea( $content ); 1114 1130 return $content; 1115 1131 } … … 1297 1313 function _make_url_clickable_cb($matches) { 1298 1314 $url = $matches[2]; 1315 $suffix = ''; 1316 1317 /** Include parentheses in the URL only if paired **/ 1318 while ( substr_count( $url, '(' ) < substr_count( $url, ')' ) ) { 1319 $suffix = strrchr( $url, ')' ) . $suffix; 1320 $url = substr( $url, 0, strrpos( $url, ')' ) ); 1321 } 1299 1322 1300 1323 $url = esc_url($url); … … 1302 1325 return $matches[0]; 1303 1326 1304 return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>" ;1327 return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>" . $suffix; 1305 1328 } 1306 1329 … … 1364 1387 $ret = ' ' . $ret; 1365 1388 // in testing, using arrays here was found to be faster 1366 $ret = preg_replace_callback('#(?< =[\s>])(\()?([\w]+?://(?:[\w\\x80-\\xff\#$%&~/=?@\[\](+-]|[.,;:](?![\s<]|(\))?([\s]|$))|(?(1)\)(?![\s<.,;:]|$)|\)))+)#is', '_make_url_clickable_cb', $ret);1389 $ret = preg_replace_callback('#(?<!=[\'"])(?<=[*\')+.,;:!&$\s>])(\()?([\w]+?://(?:[\w\\x80-\\xff\#%~/?@\[\]-]|[\'*(+.,;:!=&$](?![\b\)]|(\))?([\s]|$))|(?(1)\)(?![\s<.,;:]|$)|\)))+)#is', '_make_url_clickable_cb', $ret); 1367 1390 $ret = preg_replace_callback('#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is', '_make_web_ftp_clickable_cb', $ret); 1368 1391 $ret = preg_replace_callback('#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret); … … 1425 1448 } 1426 1449 1427 $siteurl = get_option( 'siteurl' );1428 1429 1450 $smiley = trim(reset($smiley)); 1430 1451 $img = $wpsmiliestrans[$smiley]; 1431 1452 $smiley_masked = esc_attr($smiley); 1432 1453 1433 $srcurl = apply_filters('smilies_src', "$siteurl/wp-includes/images/smilies/$img", $img, $siteurl);1454 $srcurl = apply_filters('smilies_src', includes_url("images/smilies/$img"), $img, site_url()); 1434 1455 1435 1456 return " <img src='$srcurl' alt='$smiley_masked' class='wp-smiley' /> "; … … 1457 1478 for ($i = 0; $i < $stop; $i++) { 1458 1479 $content = $textarr[$i]; 1459 if ((strlen($content) > 0) && ('<' != $content {0})) { // If it's not a tag1480 if ((strlen($content) > 0) && ('<' != $content[0])) { // If it's not a tag 1460 1481 $content = preg_replace_callback($wp_smiliessearch, 'translate_smiley', $content); 1461 1482 } … … 1477 1498 * 1478 1499 * @param string $email Email address to verify. 1479 * @param boolean $deprecated .Deprecated.1500 * @param boolean $deprecated Deprecated. 1480 1501 * @return string|bool Either false or the valid email address. 1481 1502 */ … … 1554 1575 } else { 1555 1576 $subject = str_replace('_', ' ', $matches[2]); 1556 $subject = preg_replace_callback('#\=([0-9a-f]{2})#i', create_function('$match', 'return chr(hexdec(strtolower($match[1])));'), $subject);1577 $subject = preg_replace_callback('#\=([0-9a-f]{2})#i', '_wp_iso_convert', $subject); 1557 1578 return $subject; 1558 1579 } 1580 } 1581 1582 /** 1583 * Helper function to convert hex encoded chars to ascii 1584 * 1585 * @since 3.1.0 1586 * @access private 1587 * @param array $match the preg_replace_callback matches array 1588 */ 1589 function _wp_iso_convert( $match ) { 1590 return chr( hexdec( strtolower( $match[1] ) ) ); 1559 1591 } 1560 1592 … … 1744 1776 1745 1777 // Test for invalid characters 1746 $sub = preg_replace( '/ ^[^a-z0-9-]+$/i', '', $sub );1778 $sub = preg_replace( '/[^a-z0-9-]+/i', '', $sub ); 1747 1779 1748 1780 // If there's anything left, add it to the valid subs … … 2330 2362 2331 2363 /** 2364 * Escaping for textarea values. 2365 * 2366 * @since 3.1 2367 * 2368 * @param string $text 2369 * @return string 2370 */ 2371 function esc_textarea( $text ) { 2372 $safe_text = htmlspecialchars( $text, ENT_QUOTES ); 2373 return apply_filters( 'esc_textarea', $safe_text, $text ); 2374 } 2375 2376 /** 2332 2377 * Escape a HTML tag name. 2333 2378 * … … 2581 2626 2582 2627 // Fragment has a specifier 2583 if ( $pattern {$start}== '%' ) {2628 if ( $pattern[$start] == '%' ) { 2584 2629 // Find numbered arguments or take the next one in order 2585 2630 if ( preg_match('/^%(\d+)\$/', $fragment, $matches) ) { … … 2690 2735 */ 2691 2736 function links_add_base_url( $content, $base, $attrs = array('src', 'href') ) { 2737 global $_links_add_base; 2738 $_links_add_base = $base; 2692 2739 $attrs = implode('|', (array)$attrs); 2693 return preg_replace_callback("!($attrs)=(['\"])(.+?)\\2!i", 2694 create_function('$m', 'return _links_add_base($m, "' . $base . '");'), 2695 $content); 2740 return preg_replace_callback( "!($attrs)=(['\"])(.+?)\\2!i", '_links_add_base', $content ); 2696 2741 } 2697 2742 … … 2703 2748 * 2704 2749 * @param string $m The matched link. 2705 * @param string $base The base URL to prefix to links.2706 2750 * @return string The processed link. 2707 2751 */ 2708 function _links_add_base($m, $base) { 2752 function _links_add_base($m) { 2753 global $_links_add_base; 2709 2754 //1 = attribute name 2 = quotation mark 3 = URL 2710 2755 return $m[1] . '=' . $m[2] . 2711 2756 (strpos($m[3], 'http://') === false ? 2712 path_join($ base, $m[3]) :2757 path_join($_links_add_base, $m[3]) : 2713 2758 $m[3]) 2714 2759 . $m[2]; … … 2731 2776 */ 2732 2777 function links_add_target( $content, $target = '_blank', $tags = array('a') ) { 2778 global $_links_add_target; 2779 $_links_add_target = $target; 2733 2780 $tags = implode('|', (array)$tags); 2734 return preg_replace_callback("!<($tags)(.+?)>!i", 2735 create_function('$m', 'return _links_add_target($m, "' . $target . '");'), 2736 $content); 2781 return preg_replace_callback( "!<($tags)(.+?)>!i", '_links_add_target', $content ); 2737 2782 } 2738 2783 … … 2744 2789 * 2745 2790 * @param string $m The matched link. 2746 * @param string $target The Target to add to the links.2747 2791 * @return string The processed link. 2748 2792 */ 2749 function _links_add_target( $m, $target ) { 2793 function _links_add_target( $m ) { 2794 global $_links_add_target; 2750 2795 $tag = $m[1]; 2751 2796 $link = preg_replace('|(target=[\'"](.*?)[\'"])|i', '', $m[2]); 2752 return '<' . $tag . $link . ' target="' . $target. '">';2797 return '<' . $tag . $link . ' target="' . esc_attr( $_links_add_target ) . '">'; 2753 2798 } 2754 2799 … … 2821 2866 2822 2867 /** 2868 * i18n friendly version of basename() 2869 * 2870 * @since 3.1.0 2871 * 2872 * @param string $path A path. 2873 * @param string $suffix If the filename ends in suffix this will also be cut off. 2874 * @return string 2875 */ 2876 function wp_basename( $path, $suffix = '' ) { 2877 return urldecode( basename( str_replace( '%2F', '/', urlencode( $path ) ), $suffix ) ); 2878 } 2879 2880 /** 2823 2881 * Forever eliminate "Wordpress" from the planet (or at least the little bit we can influence). 2824 2882 * … … 2827 2885 * @since 3.0.0 2828 2886 */ 2829 2830 2887 function capital_P_dangit( $text ) { 2831 2888 // Simple replacement for titles
Note: See TracChangeset
for help on using the changeset viewer.