Changeset 8783
- Timestamp:
- 08/30/2008 09:28:11 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/formatting.php
r8743 r8783 11 11 * Replaces common plain text characters into formatted entities 12 12 * 13 * As an example, 13 * As an example, 14 14 * <code> 15 15 * 'cause today's effort makes it worth tomorrow's "holiday"... … … 52 52 53 53 for ( $i = 0; $i < $stop; $i++ ) { 54 54 $curl = $textarr[$i]; 55 55 56 56 if ( !empty($curl) && '<' != $curl{0} && '[' != $curl{0} && $next && !$has_pre_parent) { // If it's not a tag … … 73 73 } 74 74 75 75 return $output; 76 76 } 77 77 … … 106 106 * replace double line-breaks with HTML paragraph tags. The remaining 107 107 * line-breaks after conversion become <<br />> tags, unless $br is set to '0' 108 * 108 * or 'false'. 109 109 * 110 110 * @since 0.71 … … 155 155 * Checks to see if a string is utf8 encoded. 156 156 * 157 * {@internal Missing Long Description}}158 *159 157 * @since 1.2.1 160 158 * … … 184 182 * 185 183 * Differs from htmlspecialchars as existing HTML entities will not be encoded. 186 * Specific ically changes: & to &, < to < and > to >.184 * Specifically changes: & to &, < to < and > to >. 187 185 * 188 186 * $quotes can be set to 'single' to encode ' to ', 'double' to encode " to … … 267 265 /** 268 266 * Replaces accents in a string. 269 *270 * {@internal Missing Long Description}}271 267 * 272 268 * @since 1.2.1 … … 424 420 $name = trim($name, '-'); 425 421 return $name; 426 427 } 428 429 /** 430 * Removes characters from the username. 422 } 423 424 /** 425 * Sanitize username stripping out unsafe characters. 431 426 * 432 427 * If $strict is true, only alphanumeric characters (as well as _, space, ., -, … … 457 452 458 453 /** 459 * Returns a string which has been sanitized.454 * Sanitizes title or use fallback title. 460 455 * 461 456 * Specifically, HTML and PHP tags are stripped. Further actions can be added … … 480 475 481 476 /** 482 * Replaces the string with safe characters. Whitespace becomes a dash.477 * Sanitizes title, replacing whitespace with dashes. 483 478 * 484 479 * Limits the output to alphanumeric characters, underscore (_) and dash (-). 480 * Whitespace becomes a dash. 485 481 * 486 482 * @since 1.2.0 … … 604 600 * Fixes javascript bugs in browsers. 605 601 * 606 * {@internal Missing Long Description}}602 * Converts unicode characters to HTML numbered entities. 607 603 * 608 604 * @since 1.5.0 … … 617 613 global $is_macIE, $is_winIE; 618 614 615 /** @todo use preg_replace_callback() instead */ 619 616 if ( $is_winIE || $is_macIE ) 620 617 $text = preg_replace("/\%u([0-9A-F]{4,4})/e", "'&#'.base_convert('\\1',16,10).';'", $text); … … 624 621 625 622 /** 626 * balanceTags() - {@internal Missing Short Description}} 627 * 628 * {@internal Missing Long Description}} 623 * Will only balance the tags if forced to and the option is set to balance tags. 624 * 625 * The option 'use_balanceTags' is used for whether the tags will be balanced. 626 * Both the $force parameter and 'use_balanceTags' option will have to be true 627 * before the tags will be balanced. 629 628 * 630 629 * @since 0.71 … … 643 642 * Balances tags of string using a modified stack. 644 643 * 645 * {@internal Missing Long Description}}646 *647 644 * @since 2.0.4 648 645 * 649 646 * @author Leonard Lin <leonard@acm.org> 650 647 * @license GPL v2.0 651 * @ dateNovember 4, 2001648 * @copyright November 4, 2001 652 649 * @version 1.1 653 650 * @todo Make better - change loop condition to $text in 1.2 … … 782 779 * Holder for the 'format_to_post' filter. 783 780 * 784 * {@internal Deprecated? Unused in 2.6}}785 *786 781 * @since 0.71 787 782 * … … 797 792 * Add leading zeros when necessary. 798 793 * 799 * {@internal Missing Long Description}} 794 * If you set the threshold to '4' and the number is '10', then you will get 795 * back '0010'. If you set the number to '4' and the number is '5000', then you 796 * will get back '5000'. 800 797 * 801 798 * @since 0.71 … … 805 802 * @return string Adds leading zeros to number if needed 806 803 */ 807 function zeroise($number, $threshold) {804 function zeroise($number, $threshold) { 808 805 return sprintf('%0'.$threshold.'s', $number); 809 806 } … … 811 808 /** 812 809 * Adds backslashes before letters and before a number at the start of a string. 813 *814 * {@internal Missing Long Description}}815 810 * 816 811 * @since 0.71 … … 862 857 * Adds slashes to escape strings. 863 858 * 864 * Slashes will first be removed if magic_quotes_gpc is set, 865 * see {@link http://www.php.net/magic_quotes} for more details.859 * Slashes will first be removed if magic_quotes_gpc is set, see {@link 860 * http://www.php.net/magic_quotes} for more details. 866 861 * 867 862 * @since 0.71 … … 883 878 * Navigates through an array and removes slashes from the values. 884 879 * 885 * If an array is passed, the array_map() function causes a callback to 886 * pass the value back to the function. The slashes from this value will 887 * removed. 880 * If an array is passed, the array_map() function causes a callback to pass the 881 * value back to the function. The slashes from this value will removed. 888 882 * 889 883 * @since 2.0.0 … … 893 887 */ 894 888 function stripslashes_deep($value) { 895 $value = is_array($value) ? 896 array_map('stripslashes_deep', $value) : 897 stripslashes($value); 898 899 return $value; 889 $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); 890 return $value; 900 891 } 901 892 … … 912 903 */ 913 904 function urlencode_deep($value) { 914 $value = is_array($value) ? 915 array_map('urlencode_deep', $value) : 916 urlencode($value); 917 918 return $value; 905 $value = is_array($value) ? array_map('urlencode_deep', $value) : urlencode($value); 906 return $value; 919 907 } 920 908 … … 948 936 949 937 /** 950 * _make_url_clickable_cb() - {@internal Missing Short Description}} 951 * 952 * {@internal Missing Long Description}} 953 * 954 * @since 2.5.0 938 * Callback to convert URI match to HTML A element. 939 * 940 * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link 941 * make_clickable()}. 942 * 943 * @since 2.3.2 955 944 * @access private 956 945 * 957 * @param unknown_type $matches958 * @return unknown946 * @param array $matches Single Regex Match. 947 * @return string HTML A element with URI address. 959 948 */ 960 949 function _make_url_clickable_cb($matches) { … … 973 962 974 963 /** 975 * _make_web_ftp_clickable_cb() - {@internal Missing Short Description}} 976 * 977 * {@internal Missing Long Description}} 978 * 979 * @since 2.5.0 964 * Callback to convert URL match to HTML A element. 965 * 966 * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link 967 * make_clickable()}. 968 * 969 * @since 2.3.2 980 970 * @access private 981 971 * 982 * @param unknown_type $matches983 * @return unknown972 * @param array $matches Single Regex Match. 973 * @return string HTML A element with URL address. 984 974 */ 985 975 function _make_web_ftp_clickable_cb($matches) { … … 999 989 1000 990 /** 1001 * _make_email_clickable_cb() - {@internal Missing Short Description}} 1002 * 1003 * {@internal Missing Long Description}} 1004 * 1005 * @since 2.5.0 991 * Callback to convert email address match to HTML A element. 992 * 993 * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link 994 * make_clickable()}. 995 * 996 * @since 2.3.2 1006 997 * @access private 1007 998 * 1008 * @param unknown_type $matches1009 * @return unknown999 * @param array $matches Single Regex Match. 1000 * @return string HTML A element with email address. 1010 1001 */ 1011 1002 function _make_email_clickable_cb($matches) { … … 1015 1006 1016 1007 /** 1017 * make_clickable() - {@internal Missing Short Description}} 1018 * 1019 * {@internal Missing Long Description}} 1008 * Convert plaintext URI to HTML links. 1009 * 1010 * Converts URI, www and ftp, and email addresses. Finishes by fixing links 1011 * within links. 1020 1012 * 1021 1013 * @since 0.71 1022 1014 * 1023 * @param unknown_type $ret1024 * @return unknown1015 * @param string $ret Content to convert URIs. 1016 * @return string Content with converted URIs. 1025 1017 */ 1026 1018 function make_clickable($ret) { … … 1078 1070 * @since 0.71 1079 1071 * 1080 * @param unknown_type$text1081 * @return unknown1072 * @param string $text 1073 * @return string 1082 1074 */ 1083 1075 function convert_smilies($text) { … … 1105 1097 * Checks to see if the text is a valid email address. 1106 1098 * 1107 * {@internal Missing Long Description}}1108 *1109 1099 * @since 0.71 1110 1100 * … … 1126 1116 1127 1117 /** 1128 * wp_iso_descrambler() -{@internal Missing Short Description}}1118 * {@internal Missing Short Description}} 1129 1119 * 1130 1120 * {@internal Missing Long Description}} … … 1133 1123 * @usedby wp_mail() handles charsets in email subjects 1134 1124 * 1135 * @param unknown_type$string1136 * @return unknown1125 * @param string $string 1126 * @return string 1137 1127 */ 1138 1128 function wp_iso_descrambler($string) { … … 1142 1132 } else { 1143 1133 $subject = str_replace('_', ' ', $matches[2]); 1134 /** @todo use preg_replace_callback() */ 1144 1135 $subject = preg_replace('#\=([0-9a-f]{2})#ei', "chr(hexdec(strtolower('$1')))", $subject); 1145 1136 return $subject; … … 1150 1141 * Returns a date in the GMT equivalent. 1151 1142 * 1152 * Requires and returns a date in the Y-m-d H:i:s format. 1153 * Simply subtracts thevalue of gmt_offset.1143 * Requires and returns a date in the Y-m-d H:i:s format. Simply subtracts the 1144 * value of gmt_offset. 1154 1145 * 1155 1146 * @since 1.2.0 … … 1168 1159 * Converts a GMT date into the correct format for the blog. 1169 1160 * 1170 * Requires and returns in the Y-m-d H:i:s format. Simply 1171 * adds the value ofgmt_offset.1161 * Requires and returns in the Y-m-d H:i:s format. Simply adds the value of 1162 * gmt_offset. 1172 1163 * 1173 1164 * @since 1.2.0 … … 1185 1176 /** 1186 1177 * Computes an offset in seconds from an iso8601 timezone. 1187 *1188 * {@internal Missing Long Description}}1189 1178 * 1190 1179 * @since 1.5.0 … … 1209 1198 * Converts an iso8601 date to MySQL DateTime format used by post_date[_gmt]. 1210 1199 * 1211 * {@internal Missing Long Description}}1212 *1213 1200 * @since 1.5.0 1214 1201 * 1215 1202 * @param string $date_string Date and time in ISO 8601 format {@link http://en.wikipedia.org/wiki/ISO_8601}. 1216 * @param unknown_type $timezone Optional. If set to GMT returns the time minus gmt_offset. Default USER.1203 * @param string $timezone Optional. If set to GMT returns the time minus gmt_offset. Default is 'user'. 1217 1204 * @return string The date and time in MySQL DateTime format - Y-m-d H:i:s. 1218 1205 */ … … 1270 1257 * Determines the difference between two timestamps. 1271 1258 * 1272 * The difference is returned in a human readable format such as 1273 * " 1 hour", "5 mins", "2 days".1259 * The difference is returned in a human readable format such as "1 hour", 1260 * "5 mins", "2 days". 1274 1261 * 1275 1262 * @since 1.5.0 … … 1306 1293 1307 1294 /** 1308 * Generates an excerpt from the content if needed. 1309 * 1310 * {@internal Missing Long Description}} 1295 * Generates an excerpt from the content, if needed. 1296 * 1297 * The excerpt word amount will be 55 words and if the amount is greater than 1298 * that, then the string '[...]' will be appended to the excerpt. If the string 1299 * is less than 55 words, then the content will be returned as is. 1311 1300 * 1312 1301 * @since 1.5.0 … … 1315 1304 * @return string The excerpt. 1316 1305 */ 1317 function wp_trim_excerpt($text) { // Fakes an excerpt if needed1306 function wp_trim_excerpt($text) { 1318 1307 if ( '' == $text ) { 1319 1308 $text = get_the_content(''); … … 1338 1327 * Converts named entities into numbered entities. 1339 1328 * 1340 * {@internal Missing Long Description}}1341 *1342 1329 * @since 1.5.1 1343 1330 * 1344 1331 * @param string $text The text within which entities will be converted. 1345 * @return string Text with converted entities. 1332 * @return string Text with converted entities. 1346 1333 */ 1347 1334 function ent2ncr($text) { … … 1610 1597 1611 1598 /** 1612 * Formats text for the rich text editor and applies filter.1613 * 1614 * The filter 'richedit_pre' is applied here. If $text is empty 1615 * the filter willbe applied to an empty string.1599 * Formats text for the rich text editor. 1600 * 1601 * The filter 'richedit_pre' is applied here. If $text is empty the filter will 1602 * be applied to an empty string. 1616 1603 * 1617 1604 * @since 2.0.0 … … 1632 1619 1633 1620 /** 1634 * Formats text for the HTML editor and applies a filter.1635 * 1636 * Unless $output is empty it will pass through htmlspecialchars 1637 * before the'htmledit_pre' filter is applied.1638 * 1639 * @since unknown1621 * Formats text for the HTML editor. 1622 * 1623 * Unless $output is empty it will pass through htmlspecialchars before the 1624 * 'htmledit_pre' filter is applied. 1625 * 1626 * @since 2.5.0 1640 1627 * 1641 1628 * @param string $output The text to be formatted. … … 1650 1637 1651 1638 /** 1652 * Checks and cleans a URL. 1653 * 1654 * A number of characters are removed from the URL. If the URL is 1655 * for displaying (the default behaviour) amperstands are also replaced.1656 * The 'clean_url' filteris applied to the returned cleaned URL.1639 * Checks and cleans a URL. 1640 * 1641 * A number of characters are removed from the URL. If the URL is for displaying 1642 * (the default behaviour) amperstands are also replaced. The 'clean_url' filter 1643 * is applied to the returned cleaned URL. 1657 1644 * 1658 1645 * @since 1.2.0 1659 1646 * @uses wp_kses_bad_protocol() To only permit protocols in the URL set 1660 * via $protocols or the common ones set in the function.1647 * via $protocols or the common ones set in the function. 1661 1648 * 1662 1649 * @param string $url The URL to be cleaned. 1663 * @param array $protocols Optional. An array of acceptable protocols. 1664 * Defaults to 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet' if not set.1665 * @param string $context Optional. How the URL will be used. Default is 'display'. 1650 * @param array $protocols Optional. An array of acceptable protocols. 1651 * Defaults to 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet' if not set. 1652 * @param string $context Optional. How the URL will be used. Default is 'display'. 1666 1653 * @return string The cleaned $url after the 'cleaned_url' filter is applied. 1667 1654 */ … … 1712 1699 * Convert entities, while preserving already-encoded entities. 1713 1700 * 1714 * {@internal Missing Long Description}}1715 *1716 1701 * @link http://www.php.net/htmlentities Borrowed from the PHP Manual user notes. 1717 1702 * … … 1747 1732 * Escaping for HTML attributes. 1748 1733 * 1749 * @since unknown1734 * @since 2.0.6 1750 1735 * 1751 1736 * @param string $text … … 1760 1745 * Escape a HTML tag name. 1761 1746 * 1762 * @since unknown1747 * @since 2.5.0 1763 1748 * 1764 1749 * @param string $tag_name … … 1773 1758 * Escapes text for SQL LIKE special characters % and _. 1774 1759 * 1775 * @since unknown1760 * @since 2.5.0 1776 1761 * 1777 1762 * @param string $text The text to be escaped. … … 1783 1768 1784 1769 /** 1785 * {@internal Missing Short Description}} 1786 * 1787 * @since unknown 1788 * 1789 * @param string $link 1790 * @return string 1770 * Convert full URL paths to absolute paths. 1771 * 1772 * Removes the http or https protocols and the domain. Keeps the path '/' at the 1773 * beginning, so it isn't a true relative link, but from the web root base. 1774 * 1775 * @since 2.1.0 1776 * 1777 * @param string $link Full URL path. 1778 * @return string Absolute path. 1791 1779 */ 1792 1780 function wp_make_link_relative( $link ) { 1793 return preg_replace( '|https?://[^/]+(/.*)|i', '$1', $link );1781 return preg_replace( '|https?://[^/]+(/.*)|i', '$1', $link ); 1794 1782 } 1795 1783 … … 1797 1785 * Sanitises various option values based on the nature of the option. 1798 1786 * 1799 * This is basically a switch statement which will pass $value through 1800 * a numberof functions depending on the $option.1787 * This is basically a switch statement which will pass $value through a number 1788 * of functions depending on the $option. 1801 1789 * 1802 1790 * @since 2.0.5 … … 1806 1794 * @return string Sanitized value. 1807 1795 */ 1808 function sanitize_option($option, $value) { // Remember to call stripslashes!1796 function sanitize_option($option, $value) { 1809 1797 1810 1798 switch ($option) { … … 1883 1871 * Parses a string into variables to be stored in an array. 1884 1872 * 1885 * Uses {@link http://www.php.net/parse_str parse_str()} and stripslashes 1886 * if{@link http://www.php.net/magic_quotes magic_quotes_gpc} is on.1873 * Uses {@link http://www.php.net/parse_str parse_str()} and stripslashes if 1874 * {@link http://www.php.net/magic_quotes magic_quotes_gpc} is on. 1887 1875 * 1888 1876 * @since 2.2.1 … … 1902 1890 * Convert lone less than signs. 1903 1891 * 1904 * KSES already converts lone greater than signs. 1892 * KSES already converts lone greater than signs. 1905 1893 * 1906 1894 * @uses wp_pre_kses_less_than_callback in the callback function. 1907 * @since unknown1895 * @since 2.3.0 1908 1896 * 1909 1897 * @param string $text Text to be converted. … … 1917 1905 * Callback function used by preg_replace. 1918 1906 * 1919 * @since unknown1920 1907 * @uses wp_specialchars to format the $matches text. 1908 * @since 2.3.0 1921 1909 * 1922 1910 * @param array $matches Populated by matches to preg_replace. … … 1932 1920 * WordPress implementation of PHP sprintf() with filters. 1933 1921 * 1934 * @since unknown1922 * @since 2.5.0 1935 1923 * @link http://www.php.net/sprintf 1936 1924 * … … 1992 1980 1993 1981 /** 1994 * List specifier %l for wp_sprintf. 1995 * 1996 * @since unknown 1997 * 1998 * @param unknown_type $pattern 1999 * @param unknown_type $args 2000 * @return unknown 1982 * Localize list items before the rest of the content. 1983 * 1984 * The '%l' must be at the first characters can then contain the rest of the 1985 * content. The list items will have ', ', ', and', and ' and ' added depending 1986 * on the amount of list items in the $args parameter. 1987 * 1988 * @since 2.5.0 1989 * 1990 * @param string $pattern Content containing '%l' at the beginning. 1991 * @param array $args List items to prepend to the content and replace '%l'. 1992 * @return string Localized list items and rest of the content. 2001 1993 */ 2002 1994 function wp_sprintf_l($pattern, $args) { … … 2038 2030 * 3, etc. 2039 2031 * 2032 * @since 2.5.0 2033 * 2040 2034 * @param integer $str String to get the excerpt from. 2041 2035 * @param integer $count Maximum number of characters to take. … … 2053 2047 * Add a Base url to relative links in passed content. 2054 2048 * 2055 * By default it supports the 'src' and 'href' attributes, 2056 * However this may be changed via the 3rd param. 2057 * 2058 * @package WordPress 2059 * @since 2.7 2049 * By default it supports the 'src' and 'href' attributes. However this can be 2050 * changed via the 3rd param. 2051 * 2052 * @since 2.7.0 2060 2053 * 2061 2054 * @param string $content String to search for links in. … … 2074 2067 * Callback to add a base url to relative links in passed content. 2075 2068 * 2076 * 2077 * @package WordPress 2078 * @since 2.7 2069 * @since 2.7.0 2070 * @access private 2079 2071 * 2080 2072 * @param string $m The matched link. … … 2094 2086 * Adds a Target attribute to all links in passed content. 2095 2087 * 2096 * This function by default only applies to <a> tags, 2097 * however this can bemodified by the 3rd param.2098 * NOTE: Any current target attributed will be striped and replaced.2099 * 2100 * @package WordPress2101 * @since 2.7 2088 * This function by default only applies to <a> tags, however this can be 2089 * modified by the 3rd param. 2090 * 2091 * <b>NOTE:</b> Any current target attributed will be striped and replaced. 2092 * 2093 * @since 2.7.0 2102 2094 * 2103 2095 * @param string $content String to search for links in. … … 2115 2107 * Callback to add a target attribute to all links in passed content. 2116 2108 * 2117 * 2118 * @package WordPress 2119 * @since 2.7 2109 * @since 2.7.0 2110 * @access private 2120 2111 * 2121 2112 * @param string $m The matched link.
Note: See TracChangeset
for help on using the changeset viewer.