Ticket #5638: 5638.r8665.diff
File 5638.r8665.diff, 18.9 KB (added by , 16 years ago) |
---|
-
formatting.php
1 1 <?php 2 2 /** 3 * Main Wordpress Formatting API 3 * Main Wordpress Formatting API. 4 4 * 5 * Handles many functions for formatting output 5 * Handles many functions for formatting output. 6 6 * 7 7 * @package WordPress 8 8 **/ … … 18 18 * <code> 19 19 * ’cause today’s effort makes it worth tomorrow’s “holiday”… 20 20 * </code> 21 * Code within certain html blocks are skipped. 21 * Code within certain html blocks are skipped. 22 22 * 23 23 * @since 0.71 24 24 * @uses $wp_cockneyreplace Array of formatted entities for certain common phrases … … 76 76 } 77 77 78 78 /** 79 * Accepts matches array from preg_replace_callback in wpautop() or a string 79 * Accepts matches array from preg_replace_callback in wpautop() or a string. 80 80 * 81 * Ensures that the contents of a <<pre>>...<</pre>> HTML block are not converted into paragraphs or line-breaks. 81 * Ensures that the contents of a <<pre>>...<</pre>> HTML block are not 82 * converted into paragraphs or line-breaks. 82 83 * 83 84 * @since 1.2.0 84 85 * 85 * @param array|string $matches The array or string 86 * @param array|string $matches The array or string 86 87 * @return string The pre block without paragraph/line-break conversion. 87 88 */ 88 89 function clean_pre($matches) { … … 99 100 } 100 101 101 102 /** 102 * Replaces double line-breaks with paragraph elements 103 * Replaces double line-breaks with paragraph elements. 103 104 * 104 * A group of regex replaces used to identify text formatted with newlines and replace105 * double line-breaks with HTML paragraph tags. The remaining line-breaks after conversion106 * become <<br />> tags, unless $br is set to '0' or 'false'.107 * 105 * A group of regex replaces used to identify text formatted with newlines and 106 * replace double line-breaks with HTML paragraph tags. The remaining 107 * line-breaks after conversion become <<br />> tags, unless $br is set to '0' 108 * or 'false'. 108 109 * 109 110 * @since 0.71 110 111 * 111 112 * @param string $pee The text which has to be formatted. 112 * @param int|bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true. 113 * @return string Text which has been converted into correct paragraph tags. 113 * @param int|bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true. 114 * @return string Text which has been converted into correct paragraph tags. 114 115 */ 115 116 function wpautop($pee, $br = 1) { 116 117 $pee = $pee . "\n"; // just to make things a little easier, pad the end … … 179 180 } 180 181 181 182 /** 182 * Converts a number of special characters into their HTML entities 183 * Converts a number of special characters into their HTML entities. 183 184 * 184 * Differs from htmlspecialchars as existing HTML entities will not be encoded. Specificically185 * changes: & to &, < to < and > to >.185 * Differs from htmlspecialchars as existing HTML entities will not be encoded. 186 * Specificically changes: & to &, < to < and > to >. 186 187 * 187 * $quotes can be set to 'single' to encode ' to ', 'double' to encode " to ", or '1' to do both.188 * Default is 0 where no quotes are encoded.188 * $quotes can be set to 'single' to encode ' to ', 'double' to encode " to 189 * ", or '1' to do both. Default is 0 where no quotes are encoded. 189 190 * 190 191 * @since 1.2.2 191 192 * 192 * @param string $text The text which is to be encoded 193 * @param mixed $quotes Optional. Converts single quotes if set to 'single', double if set to 'double' or both if otherwise set. Default 0. 194 * @return string The encoded text with HTML entities. 193 * @param string $text The text which is to be encoded. 194 * @param mixed $quotes Optional. Converts single quotes if set to 'single', double if set to 'double' or both if otherwise set. Default 0. 195 * @return string The encoded text with HTML entities. 195 196 */ 196 197 function wp_specialchars( $text, $quotes = 0 ) { 197 198 // Like htmlspecialchars except don't double-encode HTML entities … … 264 265 } 265 266 266 267 /** 267 * Replaces accents in a string 268 * Replaces accents in a string. 268 269 * 269 270 * {@internal Missing Long Description}} 270 271 * … … 404 405 } 405 406 406 407 /** 407 * Filters certain characters from the file name. 408 * Filters certain characters from the file name. 408 409 * 409 410 * {@internal Missing Long Description}} 410 411 * … … 426 427 } 427 428 428 429 /** 429 * Removes characters from the username 430 * Removes characters from the username. 430 431 * 431 * If $strict is true, only alphanumeric characters (as well as _, space, ., -, @) are returned. 432 * If $strict is true, only alphanumeric characters (as well as _, space, ., -, 433 * @) are returned. 432 434 * 433 435 * @since 2.0.0 434 436 * 435 * @param string $username The username to be sanitized. 436 * @param bool $strict If set limits $username to specific characters. Default false. 437 * @return string The sanitized username, after passing through filters. 437 * @param string $username The username to be sanitized. 438 * @param bool $strict If set limits $username to specific characters. Default false. 439 * @return string The sanitized username, after passing through filters. 438 440 */ 439 441 function sanitize_user( $username, $strict = false ) { 440 442 $raw_username = $username; … … 451 453 } 452 454 453 455 /** 454 * Returns a string which has been sanitized. 456 * Returns a string which has been sanitized. 455 457 * 456 * Specifically, HTML and PHP tags are stripped. Further actions can be added via the 457 * plugin API. If $title is empty and $fallback_title is set, the latter will be used. 458 * Specifically, HTML and PHP tags are stripped. Further actions can be added 459 * via the plugin API. If $title is empty and $fallback_title is set, the latter 460 * will be used. 458 461 * 459 462 * @since 1.0.0 460 463 * 461 * @param string $title The string to be sanitized. 462 * @param string $fallback_title Optional. A title to use if $title is empty. 463 * @return string The sanitized string. 464 * @param string $title The string to be sanitized. 465 * @param string $fallback_title Optional. A title to use if $title is empty. 466 * @return string The sanitized string. 464 467 */ 465 468 function sanitize_title($title, $fallback_title = '') { 466 469 $title = strip_tags($title); … … 473 476 } 474 477 475 478 /** 476 * Replaces the string with safe characters. Whitespace becomes a dash. 479 * Replaces the string with safe characters. Whitespace becomes a dash. 477 480 * 478 * Limits the output to alphanumeric characters, underscore (_) and dash (-). 481 * Limits the output to alphanumeric characters, underscore (_) and dash (-). 479 482 * 480 483 * @since 1.2.0 481 484 * … … 510 513 } 511 514 512 515 /** 513 * Ensures a string is a valid SQL order by clause. 516 * Ensures a string is a valid SQL order by clause. 514 517 * 515 * Accepts one or more columns, with or without ASC/DESC, and also accepts RAND() 518 * Accepts one or more columns, with or without ASC/DESC, and also accepts 519 * RAND(). 516 520 * 517 521 * @since 2.5.1 518 522 * … … 527 531 } 528 532 529 533 /** 530 * Converts a number of characters from a string 534 * Converts a number of characters from a string. 531 535 * 532 * Metadata tags <<title>> and <<category>> are removed, <<br>> and <<hr>> are converted into correct 533 * XHTML and Unicode characters are converted to the valid range. 536 * Metadata tags <<title>> and <<category>> are removed, <<br>> and <<hr>> are 537 * converted into correct XHTML and Unicode characters are converted to the 538 * valid range. 534 539 * 535 540 * @since 0.71 536 541 * … … 593 598 } 594 599 595 600 /** 596 * Fixes javascript bugs in browsers. 601 * Fixes javascript bugs in browsers. 597 602 * 598 603 * {@internal Missing Long Description}} 599 604 * … … 751 756 } 752 757 753 758 /** 754 * Acts on text which is about to be edited 759 * Acts on text which is about to be edited. 755 760 * 756 * Unless $richedit is set, it is simply a holder for the 'format_to_edit' filter. If $richedit757 * is set true htmlspecialchars() will be run on the content, converting special characters to758 * HTMl entities.761 * Unless $richedit is set, it is simply a holder for the 'format_to_edit' 762 * filter. If $richedit is set true htmlspecialchars() will be run on the 763 * content, converting special characters to HTMl entities. 759 764 * 760 765 * @since 0.71 761 766 * 762 * @param string $content The text about to be edited. 763 * @param bool $richedit Whether or not the $content should pass through htmlspecialchars(). Default false. 764 * @return string The text after the filter (and possibly htmlspecialchars()) has been run. 767 * @param string $content The text about to be edited. 768 * @param bool $richedit Whether or not the $content should pass through htmlspecialchars(). Default false. 769 * @return string The text after the filter (and possibly htmlspecialchars()) has been run. 765 770 */ 766 771 function format_to_edit($content, $richedit = false) { 767 772 $content = apply_filters('format_to_edit', $content); … … 778 783 * @since 0.71 779 784 * 780 785 * @param string $content The text to pass through the filter. 781 * @return string Text returned from the 'format_to_post' filter. 786 * @return string Text returned from the 'format_to_post' filter. 782 787 */ 783 788 function format_to_post($content) { 784 789 $content = apply_filters('format_to_post', $content); … … 786 791 } 787 792 788 793 /** 789 * Add leading zeros when necessary 794 * Add leading zeros when necessary. 790 795 * 791 796 * {@internal Missing Long Description}} 792 797 * … … 817 822 } 818 823 819 824 /** 820 * Appends a trailing slash 825 * Appends a trailing slash. 821 826 * 822 * Will remove trailing slash if it exists already before adding 823 * a trailing slash. This prevents double slashing a string or 824 * path. 827 * Will remove trailing slash if it exists already before adding a trailing 828 * slash. This prevents double slashing a string or path. 825 829 * 826 * The primary use of this is for paths and thus should be used 827 * for paths. It is not restricted to paths and offers no specific 828 * path support. 830 * The primary use of this is for paths and thus should be used for paths. It is 831 * not restricted to paths and offers no specific path support. 829 832 * 830 833 * @since 1.2.0 831 834 * @uses untrailingslashit() Unslashes string if it was slashed already … … 838 841 } 839 842 840 843 /** 841 * Removes trailing slash if it exists 844 * Removes trailing slash if it exists. 842 845 * 843 * The primary use of this is for paths and thus should be used 844 * for paths. It is not restricted to paths and offers no specific 845 * path support. 846 * The primary use of this is for paths and thus should be used for paths. It is 847 * not restricted to paths and offers no specific path support. 846 848 * 847 849 * @since 2.2.0 848 850 * … … 942 944 * 943 945 * {@internal Missing Long Description}} 944 946 * 945 * @since 2.5 947 * @since 2.5.0 946 948 * @access private 947 949 * 948 950 * @param unknown_type $matches … … 967 969 * 968 970 * {@internal Missing Long Description}} 969 971 * 970 * @since 2.5 972 * @since 2.5.0 971 973 * @access private 972 974 * 973 975 * @param unknown_type $matches … … 993 995 * 994 996 * {@internal Missing Long Description}} 995 997 * 996 * @since 2.5 998 * @since 2.5.0 997 999 * @access private 998 1000 * 999 1001 * @param unknown_type $matches … … 1138 1140 } 1139 1141 1140 1142 /** 1141 * get_gmt_from_date() - Give it a date, it will give you the same date as GMT1143 * Give it a date, it will give you the same date as GMT. 1142 1144 * 1143 1145 * {@internal Missing Long Description}} 1144 1146 * … … 1156 1158 } 1157 1159 1158 1160 /** 1159 * get_date_from_gmt() - Give it a GMT date, it will give you the same date with $time_difference added1161 * Give it a GMT date, it will give you the same date with $time_difference added. 1160 1162 * 1161 1163 * {@internal Missing Long Description}} 1162 1164 * … … 1174 1176 } 1175 1177 1176 1178 /** 1177 * iso8601_timezone_to_offset() - Computes an offset in seconds from an iso8601 timezone1179 * Computes an offset in seconds from an iso8601 timezone. 1178 1180 * 1179 1181 * {@internal Missing Long Description}} 1180 1182 * … … 1197 1199 } 1198 1200 1199 1201 /** 1200 * iso8601_to_datetime() - Converts an iso8601 date to MySQL DateTime format used by post_date[_gmt]1202 * Converts an iso8601 date to MySQL DateTime format used by post_date[_gmt]. 1201 1203 * 1202 1204 * {@internal Missing Long Description}} 1203 1205 * … … 1229 1231 } 1230 1232 1231 1233 /** 1232 * Adds a element attributes to open links in new windows 1234 * Adds a element attributes to open links in new windows. 1233 1235 * 1234 * Comment text in popup windows should be filtered through this. Right 1235 * now it's a moderately dumb function, ideally it would detect whether 1236 * a target or rel attribute was already there and adjust its actions 1237 * accordingly. 1236 * Comment text in popup windows should be filtered through this. Right now it's 1237 * a moderately dumb function, ideally it would detect whether a target or rel 1238 * attribute was already there and adjust its actions accordingly. 1238 1239 * 1239 1240 * @since 0.71 1240 1241 * … … 1247 1248 } 1248 1249 1249 1250 /** 1250 * Strips out all characters that are not allowable in an email 1251 * Strips out all characters that are not allowable in an email. 1251 1252 * 1252 1253 * @since 1.5.0 1253 1254 * … … 1620 1621 return apply_filters('richedit_pre', $output); 1621 1622 } 1622 1623 1624 /** 1625 * {@internal Missing Short Description}} 1626 * 1627 * {@internal Missing Long Description}} 1628 * 1629 * @since unknown 1630 * 1631 * @param string $output {@internal Missing Description}} 1632 * @return string {@internal Missing Description}} 1633 */ 1623 1634 function wp_htmledit_pre($output) { 1624 1635 if ( !empty($output) ) 1625 1636 $output = htmlspecialchars($output, ENT_NOQUOTES); // convert only < > & … … 1683 1694 } 1684 1695 1685 1696 /** 1686 * Convert entities, while preserving already-encoded entities 1697 * Convert entities, while preserving already-encoded entities. 1687 1698 * 1688 1699 * {@internal Missing Long Description}} 1689 1700 * … … 1701 1712 } 1702 1713 1703 1714 /** 1704 * Escape single quotes, specialchar double quotes, and fix line endings 1715 * Escape single quotes, specialchar double quotes, and fix line endings. 1705 1716 * 1706 1717 * {@internal Missing Long Description}} 1707 1718 * … … 1717 1728 return apply_filters('js_escape', $safe_text, $text); 1718 1729 } 1719 1730 1720 // Escaping for HTML attributes 1731 /** 1732 * Escaping for HTML attributes. 1733 * 1734 * @since unknown 1735 * 1736 * @param string $text 1737 * @return string 1738 */ 1721 1739 function attribute_escape($text) { 1722 1740 $safe_text = wp_specialchars($text, true); 1723 1741 return apply_filters('attribute_escape', $safe_text, $text); 1724 1742 } 1725 1743 1726 // Escape a HTML tag name 1744 /** 1745 * Escape a HTML tag name. 1746 * 1747 * @since unknown 1748 * 1749 * @param string $tag_name 1750 * @return string 1751 */ 1727 1752 function tag_escape($tag_name) { 1728 1753 $safe_tag = strtolower( preg_replace('[^a-zA-Z_:]', '', $tag_name) ); 1729 1754 return apply_filters('tag_escape', $safe_tag, $tag_name); 1730 1755 } 1731 1756 1732 1757 /** 1733 * Escapes text for SQL LIKE special characters % and _ 1758 * Escapes text for SQL LIKE special characters % and _. 1734 1759 * 1760 * @since unknown 1761 * 1735 1762 * @param string text the text to be escaped 1736 1763 * @return string text, safe for inclusion in LIKE query 1737 1764 */ … … 1739 1766 return str_replace(array("%", "_"), array("\\%", "\\_"), $text); 1740 1767 } 1741 1768 1769 /** 1770 * {@internal Missing Short Description}} 1771 * 1772 * @since unknown 1773 * 1774 * @param string $link 1775 * @return string 1776 */ 1742 1777 function wp_make_link_relative( $link ) { 1743 1778 return preg_replace('|https?://[^/]+(/.*)|i', '$1', $link ); 1744 1779 } … … 1835 1870 $array = apply_filters( 'wp_parse_str', $array ); 1836 1871 } 1837 1872 1838 // Convert lone less than signs. KSES already converts lone greater than signs. 1873 /** 1874 * Convert lone less than signs. 1875 * 1876 * KSES already converts lone greater than signs. 1877 * 1878 * @since unknown 1879 * 1880 * @param string $text 1881 * @return string 1882 */ 1839 1883 function wp_pre_kses_less_than( $text ) { 1840 1884 return preg_replace_callback('%<[^>]*?((?=<)|>|$)%', 'wp_pre_kses_less_than_callback', $text); 1841 1885 } 1842 1886 1887 /** 1888 * {@internal Missing Short Description}} 1889 * 1890 * @since unknown 1891 * 1892 * @param unknown_type $matches 1893 * @return unknown 1894 */ 1843 1895 function wp_pre_kses_less_than_callback( $matches ) { 1844 1896 if ( false === strpos($matches[0], '>') ) 1845 1897 return wp_specialchars($matches[0]); … … 1847 1899 } 1848 1900 1849 1901 /** 1850 * wp_sprintf() - sprintf() with filters 1902 * WordPress implementation of PHP sprintf() with filters. 1903 * 1904 * @since unknown 1905 * 1906 * @param unknown_type $pattern 1907 * @return unknown 1851 1908 */ 1852 1909 function wp_sprintf( $pattern ) { 1853 1910 $args = func_get_args( ); … … 1902 1959 } 1903 1960 1904 1961 /** 1905 * wp_sprintf_l - List specifier %l for wp_sprintf1962 * List specifier %l for wp_sprintf. 1906 1963 * 1964 * @since unknown 1965 * 1907 1966 * @param unknown_type $pattern 1908 1967 * @param unknown_type $args 1909 1968 * @return unknown … … 1942 2001 /** 1943 2002 * Safely extracts not more than the first $count characters from html string 1944 2003 * 1945 * UTF-8, tags and entities safe prefix extraction. Entities inside will *NOT* be 1946 * counted as one character. For example & will be counted as 4, < as 3, etc. 2004 * UTF-8, tags and entities safe prefix extraction. Entities inside will *NOT* 2005 * be counted as one character. For example & will be counted as 4, < as 2006 * 3, etc. 1947 2007 * 1948 2008 * @param integer $str String to get the excerpt from 1949 2009 * @param integer $count Maximum number of characters to take … … 1960 2020 /** 1961 2021 * Add a Base url to relative links in passed content. 1962 2022 * 1963 * By default it supports the 'src' and 'href' attributes, 1964 * However this may bechanged via the 3rd param.2023 * By default it supports the 'src' and 'href' attributes, However this may be 2024 * changed via the 3rd param. 1965 2025 * 1966 * @package WordPress1967 2026 * @since 2.7 1968 2027 * 1969 2028 * @param string $content String to search for links in 1970 2029 * @param string $base The base URL to prefix to links 1971 2030 * @param array $attrs The attributes which should be processed. 1972 * @ eaturn string The processed content.2031 * @return string The processed content. 1973 2032 */ 1974 2033 function links_add_base_url( $content, $base, $attrs = array('src', 'href') ) { 1975 2034 $attrs = implode('|', (array)$attrs); … … 1981 2040 /** 1982 2041 * Callback to add a base url to relative links in passed content. 1983 2042 * 1984 *1985 * @package WordPress1986 2043 * @since 2.7 2044 * @access private 1987 2045 * 1988 * @internal1989 2046 * @param string $m The matched link 1990 2047 * @param string $base The base URL to prefix to links 1991 * @ eaturn string The processed link2048 * @return string The processed link 1992 2049 */ 1993 2050 function _links_add_base($m, $base) { 1994 2051 //1 = attribute name 2 = quotation mark 3 = URL … … 2002 2059 /** 2003 2060 * Adds a Target attribute to all links in passed content. 2004 2061 * 2005 * This function by default only applies to <a> tags, 2006 * however this can be modified by the 3rd param. 2062 * This function by default only applies to <a> tags, however this can be 2063 * modified by the 3rd param. 2064 * 2007 2065 * NOTE: Any current target attributed will be striped and replaced. 2008 2066 * 2009 * @package WordPress2010 2067 * @since 2.7 2011 2068 * 2012 2069 * @param string $content String to search for links in 2013 2070 * @param string $target The Target to add to the links 2014 2071 * @param array $tags An array of tags to apply to. 2015 * @ eaturn string The processed content.2072 * @return string The processed content. 2016 2073 */ 2017 2074 function links_add_target( $content, $target = '_blank', $tags = array('a') ) { 2018 2075 $tags = implode('|', (array)$tags); … … 2021 2078 $content); 2022 2079 } 2023 2080 /** 2024 * Callback to add a target attribute to all links in passed content 2081 * Callback to add a target attribute to all links in passed content. 2025 2082 * 2026 *2027 * @package WordPress2028 2083 * @since 2.7 2084 * @access private 2029 2085 * 2030 * @internal2031 2086 * @param string $m The matched link 2032 2087 * @param string $target The Target to add to the links 2033 * @ eaturn string The processed link.2088 * @return string The processed link. 2034 2089 */ 2035 2090 function _links_add_target( $m, $target ) { 2036 2091 $tag = $m[1];