Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/formatting.php

    r17172 r17459  
    5757        $static_replacements = array_merge(array('—', ' — ', '–', ' – ', 'xn--', '…', $opening_quote, $closing_quote, ' ™'), $cockneyreplace);
    5858
    59         $dynamic_characters = array('/\'(\d\d(?:&#8217;|\')?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(?:&#8217;|\')?s)/', '/\'(\d)/', '/(\s|\A|[([{<]|")\'/', '/(\d)"/', '/(\d)\'/', '/(\S)\'([^\'\s])/', '/(\s|\A|[([{<])"(?!\s)/', '/"(\s|\S|\Z)/', '/\'([\s.]|\Z)/', '/\b(\d+)x(\d+)\b/');
    6060        $dynamic_replacements = array('&#8217;$1','&#8217;$1', '$1&#8216;', '$1&#8243;', '$1&#8242;', '$1&#8217;$2', '$1' . $opening_quote . '$2', $closing_quote . '$1', '&#8217;$1', '$1&#215;$2');
    6161
     
    7474        $curl = $textarr[$i];
    7575
    76         if ( !empty($curl) && '<' != $curl{0} && '[' != $curl{0}
     76        if ( !empty($curl) && '<' != $curl[0] && '[' != $curl[0]
    7777                && empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack)) {
    7878            // This is not a tag, nor is the texturization disabled
     
    8686             * tag opening
    8787             */
    88             if ('<' == $curl{0})
     88            if ('<' == $curl[0])
    8989                _wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>');
    90             elseif ('[' == $curl{0})
     90            elseif ('[' == $curl[0])
    9191                _wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']');
    9292        }
     
    209209    $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee);
    210210    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);
    212212        $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks
    213213        $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
     
    220220
    221221    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 */
     232function _autop_newline_preservation_helper( $matches ) {
     233    return str_replace("\n", "<WPPreserveNewline />", $matches[0]);
    222234}
    223235
     
    539551        chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
    540552        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',
    546559        chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
    547560        chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
     
    549562        chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
    550563        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',
    555569        chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
    556570        chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
    557571        chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
    558572        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',
    565580        chr(195).chr(191) => 'y',
    566581        // Decompositions for Latin Extended-A
     
    629644        chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
    630645        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',
    631649        // Euro Sign
    632650        chr(226).chr(130).chr(172) => 'E',
     
    719737 * Sanitize username stripping out unsafe characters.
    720738 *
    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.
    727743 *
    728744 * @since 2.0.0
     
    746762        $username = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $username );
    747763
     764    $username = trim( $username );
    748765    // Consolidate contiguous whitespace
    749766    $username = preg_replace( '|\s+|', ' ', $username );
     
    755772 * Sanitize a string key.
    756773 *
    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.
    758775 *
    759776 * @since 3.0.0
     
    764781function sanitize_key( $key ) {
    765782    $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 );
    777786}
    778787
     
    788797 * @param string $title The string to be sanitized.
    789798 * @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
    790800 * @return string The sanitized string.
    791801 */
    792 function sanitize_title($title, $fallback_title = '') {
     802function sanitize_title($title, $fallback_title = '', $context = 'save') {
    793803    $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);
    796809
    797810    if ( '' === $title || false === $title )
     
    799812
    800813    return $title;
     814}
     815
     816function sanitize_title_for_query($title) {
     817    return sanitize_title($title, '', 'query');
    801818}
    802819
     
    821838    $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);
    822839
    823     $title = remove_accents($title);
    824840    if (seems_utf8($title)) {
    825841        if (function_exists('mb_strtolower')) {
     
    981997 *
    982998 * @author Leonard Lin <leonard@acm.org>
    983  * @license GPL v2.0
     999 * @license GPL
    9841000 * @copyright November 4, 2001
    9851001 * @version 1.1
     
    10991115 *
    11001116 * 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 the
    1102  * content, converting special characters to HTMl entities.
     1117 * filter. If $richedit is set true htmlspecialchars(), through esc_textarea(),
     1118 * will be run on the content, converting special characters to HTML entities.
    11031119 *
    11041120 * @since 0.71
     
    11081124 * @return string The text after the filter (and possibly htmlspecialchars()) has been run.
    11091125 */
    1110 function format_to_edit($content, $richedit = false) {
    1111     $content = apply_filters('format_to_edit', $content);
    1112     if (! $richedit )
    1113         $content = htmlspecialchars($content);
     1126function format_to_edit( $content, $richedit = false ) {
     1127    $content = apply_filters( 'format_to_edit', $content );
     1128    if ( ! $richedit )
     1129        $content = esc_textarea( $content );
    11141130    return $content;
    11151131}
     
    12971313function _make_url_clickable_cb($matches) {
    12981314    $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    }
    12991322
    13001323    $url = esc_url($url);
     
    13021325        return $matches[0];
    13031326
    1304     return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>";
     1327    return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>" . $suffix;
    13051328}
    13061329
     
    13641387    $ret = ' ' . $ret;
    13651388    // 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);
    13671390    $ret = preg_replace_callback('#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is', '_make_web_ftp_clickable_cb', $ret);
    13681391    $ret = preg_replace_callback('#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret);
     
    14251448    }
    14261449
    1427     $siteurl = get_option( 'siteurl' );
    1428 
    14291450    $smiley = trim(reset($smiley));
    14301451    $img = $wpsmiliestrans[$smiley];
    14311452    $smiley_masked = esc_attr($smiley);
    14321453
    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());
    14341455
    14351456    return " <img src='$srcurl' alt='$smiley_masked' class='wp-smiley' /> ";
     
    14571478        for ($i = 0; $i < $stop; $i++) {
    14581479            $content = $textarr[$i];
    1459             if ((strlen($content) > 0) && ('<' != $content{0})) { // If it's not a tag
     1480            if ((strlen($content) > 0) && ('<' != $content[0])) { // If it's not a tag
    14601481                $content = preg_replace_callback($wp_smiliessearch, 'translate_smiley', $content);
    14611482            }
     
    14771498 *
    14781499 * @param string $email Email address to verify.
    1479  * @param boolean $deprecated. Deprecated.
     1500 * @param boolean $deprecated Deprecated.
    14801501 * @return string|bool Either false or the valid email address.
    14811502 */
     
    15541575    } else {
    15551576        $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);
    15571578        return $subject;
    15581579    }
     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 */
     1589function _wp_iso_convert( $match ) {
     1590    return chr( hexdec( strtolower( $match[1] ) ) );
    15591591}
    15601592
     
    17441776
    17451777        // Test for invalid characters
    1746         $sub = preg_replace( '/^[^a-z0-9-]+$/i', '', $sub );
     1778        $sub = preg_replace( '/[^a-z0-9-]+/i', '', $sub );
    17471779
    17481780        // If there's anything left, add it to the valid subs
     
    23302362
    23312363/**
     2364 * Escaping for textarea values.
     2365 *
     2366 * @since 3.1
     2367 *
     2368 * @param string $text
     2369 * @return string
     2370 */
     2371function esc_textarea( $text ) {
     2372    $safe_text = htmlspecialchars( $text, ENT_QUOTES );
     2373    return apply_filters( 'esc_textarea', $safe_text, $text );
     2374}
     2375
     2376/**
    23322377 * Escape a HTML tag name.
    23332378 *
     
    25812626
    25822627        // Fragment has a specifier
    2583         if ( $pattern{$start} == '%' ) {
     2628        if ( $pattern[$start] == '%' ) {
    25842629            // Find numbered arguments or take the next one in order
    25852630            if ( preg_match('/^%(\d+)\$/', $fragment, $matches) ) {
     
    26902735 */
    26912736function links_add_base_url( $content, $base, $attrs = array('src', 'href') ) {
     2737    global $_links_add_base;
     2738    $_links_add_base = $base;
    26922739    $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 );
    26962741}
    26972742
     
    27032748 *
    27042749 * @param string $m The matched link.
    2705  * @param string $base The base URL to prefix to links.
    27062750 * @return string The processed link.
    27072751 */
    2708 function _links_add_base($m, $base) {
     2752function _links_add_base($m) {
     2753    global $_links_add_base;
    27092754    //1 = attribute name  2 = quotation mark  3 = URL
    27102755    return $m[1] . '=' . $m[2] .
    27112756        (strpos($m[3], 'http://') === false ?
    2712             path_join($base, $m[3]) :
     2757            path_join($_links_add_base, $m[3]) :
    27132758            $m[3])
    27142759        . $m[2];
     
    27312776 */
    27322777function links_add_target( $content, $target = '_blank', $tags = array('a') ) {
     2778    global $_links_add_target;
     2779    $_links_add_target = $target;
    27332780    $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 );
    27372782}
    27382783
     
    27442789 *
    27452790 * @param string $m The matched link.
    2746  * @param string $target The Target to add to the links.
    27472791 * @return string The processed link.
    27482792 */
    2749 function _links_add_target( $m, $target ) {
     2793function _links_add_target( $m ) {
     2794    global $_links_add_target;
    27502795    $tag = $m[1];
    27512796    $link = preg_replace('|(target=[\'"](.*?)[\'"])|i', '', $m[2]);
    2752     return '<' . $tag . $link . ' target="' . $target . '">';
     2797    return '<' . $tag . $link . ' target="' . esc_attr( $_links_add_target ) . '">';
    27532798}
    27542799
     
    28212866
    28222867/**
     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 */
     2876function wp_basename( $path, $suffix = '' ) {
     2877    return urldecode( basename( str_replace( '%2F', '/', urlencode( $path ) ), $suffix ) );
     2878}
     2879
     2880/**
    28232881 * Forever eliminate "Wordpress" from the planet (or at least the little bit we can influence).
    28242882 *
     
    28272885 * @since 3.0.0
    28282886 */
    2829 
    28302887function capital_P_dangit( $text ) {
    28312888    // Simple replacement for titles
Note: See TracChangeset for help on using the changeset viewer.