Make WordPress Core

Ticket #9591: 9591.3.diff

File 9591.3.diff, 4.7 KB (added by scribu, 13 years ago)

Introduce _qv_basename()

  • wp-includes/taxonomy.php

     
    534534                case 'slug':
    535535                case 'name':
    536536                        foreach ( $terms as $i => $term ) {
    537                                 $terms[$i] = sanitize_term_field('slug', $term, 0, $taxonomy, 'db');
     537                                $terms[$i] = sanitize_title_for_query( $term );
    538538                        }
    539539                        $terms = array_filter($terms);
    540540
  • wp-includes/query.php

     
    14651465                                        );
    14661466
    14671467                                        if ( $t->rewrite['hierarchical'] ) {
    1468                                                 $q[$t->query_var] = basename($q[$t->query_var]);
     1468                                                $q[$t->query_var] = $this->_qv_basename($q[$t->query_var]);
    14691469                                        }
    14701470
    14711471                                        $term = str_replace( ' ', '+', $q[$t->query_var] );
     
    17841784                }
    17851785
    17861786                if ( '' != $q['name'] ) {
    1787                         $q['name'] = sanitize_title($q['name']);
     1787                        $q['name'] = sanitize_title_for_query( $q['name'] );
    17881788                        $where .= " AND $wpdb->posts.post_name = '" . $q['name'] . "'";
    17891789                } elseif ( '' != $q['pagename'] ) {
    17901790                        if ( isset($this->queried_object_id) ) {
     
    18121812
    18131813                        $page_for_posts = get_option('page_for_posts');
    18141814                        if  ( ('page' != get_option('show_on_front') ) || empty($page_for_posts) || ( $reqpage != $page_for_posts ) ) {
    1815                                 $q['pagename'] = str_replace('%2F', '/', urlencode(urldecode($q['pagename'])));
    1816                                 $page_paths = '/' . trim($q['pagename'], '/');
    1817                                 $q['pagename'] = sanitize_title(basename($page_paths));
     1815                                $q['pagename'] = sanitize_title_for_query( $this->_qv_basename( $q['pagename'] ) );
    18181816                                $q['name'] = $q['pagename'];
    18191817                                $where .= " AND ($wpdb->posts.ID = '$reqpage')";
    18201818                                $reqpage_obj = get_page($reqpage);
     
    18261824                                }
    18271825                        }
    18281826                } elseif ( '' != $q['attachment'] ) {
    1829                         $q['attachment'] = str_replace('%2F', '/', urlencode(urldecode($q['attachment'])));
    1830                         $attach_paths = '/' . trim($q['attachment'], '/');
    1831                         $q['attachment'] = sanitize_title(basename($attach_paths));
     1827                        $q['attachment'] = sanitize_title_for_query( $this->_qv_basename( $q['attachment'] ) );
    18321828                        $q['name'] = $q['attachment'];
    18331829                        $where .= " AND $wpdb->posts.post_name = '" . $q['attachment'] . "'";
    18341830                }
     
    19611957                                        $q['author_name'] = $q['author_name'][count($q['author_name'])-2]; // there was a trailling slash
    19621958                                }
    19631959                        }
    1964                         $q['author_name'] = sanitize_title($q['author_name']);
     1960                        $q['author_name'] = sanitize_title_for_query( $q['author_name'] );
    19651961                        $q['author'] = get_user_by('slug', $q['author_name']);
    19661962                        if ( $q['author'] )
    19671963                                $q['author'] = $q['author']->ID;
     
    31343130        function is_404() {
    31353131                return (bool) $this->is_404;
    31363132        }
     3133
     3134        /**
     3135         * i18n friendly way to get the last segment in a path
     3136         *
     3137         * @since 3.1.0
     3138         * @access private
     3139         *
     3140         * @param string $path The path
     3141         * @return string
     3142         */
     3143        function _qv_basename( $path ) {
     3144                return basename( str_replace( '%2F', '/', urlencode( urldecode( $path ) ) ) );
     3145        }
    31373146}
    31383147
    31393148/**
  • wp-includes/formatting.php

     
    628628                chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
    629629                chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
    630630                chr(197).chr(190) => 'z', chr(197).chr(191) => 's',
     631                chr(200).chr(153) => 's', chr(200).chr(155) => 't',
    631632                // Euro Sign
    632633                chr(226).chr(130).chr(172) => 'E',
    633634                // GBP (Pound) Sign
     
    783784 *
    784785 * @param string $title The string to be sanitized.
    785786 * @param string $fallback_title Optional. A title to use if $title is empty.
     787 * @param string $context Optional. The operation for which the string is sanitized
    786788 * @return string The sanitized string.
    787789 */
    788 function sanitize_title($title, $fallback_title = '') {
     790function sanitize_title($title, $fallback_title = '', $context = 'save') {
    789791        $raw_title = $title;
    790         $title = strip_tags($title);
    791         $title = apply_filters('sanitize_title', $title, $raw_title);
    792792
     793        if ( 'save' == $context )
     794                $title = remove_accents($title);
     795
     796        $title = apply_filters('sanitize_title', $title, $raw_title, $context);
     797
    793798        if ( '' === $title || false === $title )
    794799                $title = $fallback_title;
    795800
    796801        return $title;
    797802}
    798803
     804function sanitize_title_for_query($title) {
     805        return sanitize_title($title, '', 'query');
     806}
     807
    799808/**
    800809 * Sanitizes title, replacing whitespace with dashes.
    801810 *
     
    816825        // Restore octets.
    817826        $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);
    818827
    819         $title = remove_accents($title);
    820828        if (seems_utf8($title)) {
    821829                if (function_exists('mb_strtolower')) {
    822830                        $title = mb_strtolower($title, 'UTF-8');