Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r18031 r18159  
    2929function wptexturize($text) {
    3030    global $wp_cockneyreplace;
    31     static $static_setup = false, $opening_quote, $closing_quote, $default_no_texturize_tags, $default_no_texturize_shortcodes, $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements;
    32     $output = '';
    33     $curl = '';
    34     $textarr = preg_split('/(<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    35     $stop = count($textarr);
    36 
    37     // No need to set up these variables more than once
    38     if (!$static_setup) {
     31    static $opening_quote, $closing_quote, $default_no_texturize_tags, $default_no_texturize_shortcodes, $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements;
     32
     33    // No need to set up these static variables more than once
     34    if ( empty( $opening_quote ) ) {
    3935        /* translators: opening curly quote */
    4036        $opening_quote = _x('&#8220;', 'opening curly quote');
     
    5955        $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/');
    6056        $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');
    61 
    62         $static_setup = true;
    6357    }
    6458
     
    7165    $no_texturize_shortcodes_stack = array();
    7266
    73     for ( $i = 0; $i < $stop; $i++ ) {
    74         $curl = $textarr[$i];
    75 
    76         if ( !empty($curl) && '<' != $curl[0] && '[' != $curl[0]
    77                 && empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack)) {
    78             // This is not a tag, nor is the texturization disabled
    79             // static strings
     67    $textarr = preg_split('/(<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
     68
     69    foreach ( $textarr as &$curl ) {
     70        if ( empty( $curl ) )
     71            continue;
     72
     73        // Only call _wptexturize_pushpop_element if first char is correct tag opening
     74        $first = $curl[0];
     75        if ( '<' === $first ) {
     76            _wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>');
     77        } elseif ( '[' === $first ) {
     78            _wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']');
     79        } elseif ( empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack) ) {
     80            // This is not a tag, nor is the texturization disabled static strings
    8081            $curl = str_replace($static_characters, $static_replacements, $curl);
    8182            // regular expressions
    8283            $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl);
    83         } elseif (!empty($curl)) {
    84             /*
    85              * Only call _wptexturize_pushpop_element if first char is correct
    86              * tag opening
    87              */
    88             if ('<' == $curl[0])
    89                 _wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>');
    90             elseif ('[' == $curl[0])
    91                 _wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']');
    9284        }
    93 
    9485        $curl = preg_replace('/&([^#])(?![a-zA-Z1-4]{1,8};)/', '&#038;$1', $curl);
    95         $output .= $curl;
    96     }
    97 
    98     return $output;
     86    }
     87    return implode( '', $textarr );
    9988}
    10089
     
    574563        chr(195).chr(178) => 'o', chr(195).chr(179) => 'o',
    575564        chr(195).chr(180) => 'o', chr(195).chr(181) => 'o',
    576         chr(195).chr(182) => 'o', chr(195).chr(182) => 'o',
     565        chr(195).chr(182) => 'o', chr(195).chr(184) => 'o',
    577566        chr(195).chr(185) => 'u', chr(195).chr(186) => 'u',
    578567        chr(195).chr(187) => 'u', chr(195).chr(188) => 'u',
     
    877866 * Santizes a html classname to ensure it only contains valid characters
    878867 *
    879  * Strips the string down to A-Z,a-z,0-9,'-' if this results in an empty
     868 * Strips the string down to A-Z,a-z,0-9,_,-. If this results in an empty
    880869 * string then it will return the alternative value supplied.
    881870 *
     
    891880function sanitize_html_class( $class, $fallback = '' ) {
    892881    //Strip out any % encoded octets
    893     $sanitized = preg_replace('|%[a-fA-F0-9][a-fA-F0-9]|', '', $class);
    894 
    895     //Limit to A-Z,a-z,0-9,'-'
    896     $sanitized = preg_replace('/[^A-Za-z0-9-]/', '', $sanitized);
     882    $sanitized = preg_replace( '|%[a-fA-F0-9][a-fA-F0-9]|', '', $class );
     883
     884    //Limit to A-Z,a-z,0-9,_,-
     885    $sanitized = preg_replace( '/[^A-Za-z0-9_-]/', '', $sanitized );
    897886
    898887    if ( '' == $sanitized )
     
    12391228 * @since 2.0.0
    12401229 *
    1241  * @param array|string $value The array or string to be striped.
     1230 * @param array|string $value The array or string to be stripped.
    12421231 * @return array|string Stripped array (or string in the callback).
    12431232 */
     
    16001589 * Requires and returns a date in the Y-m-d H:i:s format. Simply subtracts the
    16011590 * value of the 'gmt_offset' option. Return format can be overridden using the
    1602  * $format parameter. If PHP5 is supported, the function uses the DateTime and
    1603  * DateTimeZone objects to respect time zone differences in DST.
     1591 * $format parameter. The DateTime and DateTimeZone classes are used to respect
     1592 * time zone differences in DST.
    16041593 *
    16051594 * @since 1.2.0
     
    16131602    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);
    16141603    $tz = get_option('timezone_string');
    1615     if( class_exists('DateTime') && $tz ) {
    1616         //PHP5
     1604    if ( $tz ) {
    16171605        date_default_timezone_set( $tz );
    16181606        $datetime = new DateTime( $string );
     
    16231611
    16241612        date_default_timezone_set('UTC');
    1625     }
    1626     else {
    1627         //PHP4
     1613    } else {
    16281614        $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
    16291615        $string_gmt = gmdate($format, $string_time - get_option('gmt_offset') * 3600);
     
    26792665    // Translate and filter the delimiter set (avoid ampersands and entities here)
    26802666    $l = apply_filters('wp_sprintf_l', array(
    2681         /* translators: used between list items, there is a space after the coma */
     2667        /* translators: used between list items, there is a space after the comma */
    26822668        'between'          => __(', '),
    26832669        /* translators: used between list items, there is a space after the and */
     
    27702756 * modified by the 3rd param.
    27712757 *
    2772  * <b>NOTE:</b> Any current target attributed will be striped and replaced.
     2758 * <b>NOTE:</b> Any current target attributed will be stripped and replaced.
    27732759 *
    27742760 * @since 2.7.0
Note: See TracChangeset for help on using the changeset viewer.