WordPress.org

Make WordPress Core

Changeset 9697


Ignore:
Timestamp:
11/14/08 22:48:22 (6 years ago)
Author:
markjaquith
Message:

Make Canonical feeds and paging play nice with each other and with PATHINFO URL structures. fixes #8076

File:
1 edited

Legend:

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

    r9649 r9697  
    134134                $redirect_url = $requested_url; 
    135135            $paged_redirect = @parse_url($redirect_url); 
    136             while ( preg_match( '#page/[0-9]+?(/+)?$#', $paged_redirect['path'] ) || preg_match( '#/feed(/[a-z0-9-]*?(/+)?)?$#', $paged_redirect['path'] ) || preg_match( '#comment-page-[0-9]+/?$#', $paged_redirect['path'] ) ) { 
     136            while ( preg_match( '#/page/[0-9]+?(/+)?$#', $paged_redirect['path'] ) || preg_match( '#/(feed|rss|rdf|atom|rss2)(/+)?$#', $paged_redirect['path'] ) || preg_match( '#/comment-page-[0-9]+(/+)?$#', $paged_redirect['path'] ) ) { 
    137137                // Strip off paging and feed 
    138138                $paged_redirect['path'] = preg_replace('#/page/[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any existing paging 
    139                 $paged_redirect['path'] = preg_replace('#/feed(/[a-z0-9-]*?(/+)?)?$#', '/', $paged_redirect['path']); // strip off any existing feed 
    140                 $paged_redirect['path'] = preg_replace('#comment-page-[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any existing comment paging 
    141             } 
    142  
    143             $paged_redirect['path'] = preg_replace('|/index.php/?$|', '/', $paged_redirect['path']); // strip off trailing /index.php/ 
     139                $paged_redirect['path'] = preg_replace('#/(feed|rss2?|rdf|atom)(/+)?$#', '/', $paged_redirect['path']); // strip off feed endings 
     140                $paged_redirect['path'] = preg_replace('#/comment-page-[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any existing comment paging 
     141            } 
     142 
     143            $addl_path = ''; 
     144            if ( is_feed() ) { 
     145                $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit( 'feed/' . ( ( 'rss2' ==  get_query_var('feed') || 'feed' == get_query_var('feed') ) ? '' : get_query_var('feed') ), 'feed' ); 
     146                $redirect['query'] = remove_query_arg( 'feed', $redirect['query'] ); 
     147            } 
     148 
    144149            if ( get_query_var('paged') > 0 ) { 
    145150                $paged = get_query_var('paged'); 
    146                 if ( $paged > 1 && !is_single() ) { 
    147                     $paged_redirect['path'] = trailingslashit($paged_redirect['path']); 
    148                     if ( $wp_rewrite->using_index_permalinks() && strpos($paged_redirect['path'], '/index.php/') === false ) 
    149                         $paged_redirect['path'] .= 'index.php/'; 
    150                     $paged_redirect['path'] .= user_trailingslashit("page/$paged", 'paged'); 
    151                 } elseif ( !is_single() ) { 
    152                     $paged_redirect['path'] = user_trailingslashit($paged_redirect['path'], 'paged'); 
     151                $redirect['query'] = remove_query_arg( 'paged', $redirect['query'] ); 
     152                if ( !is_feed() ) { 
     153                    if ( $paged > 1 && !is_single() ) { 
     154                        $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit("page/$paged", 'paged'); 
     155                    } elseif ( !is_single() ) { 
     156                        $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit($paged_redirect['path'], 'paged'); 
     157                    } 
     158                } elseif ( $paged > 1 ) { 
     159                    $redirect['query'] = add_query_arg( 'paged', $paged, $redirect['query'] ); 
    153160                } 
    154161            } 
    155             if ( is_feed() ) { 
    156                 $paged_redirect['path'] = user_trailingslashit( trailingslashit( $paged_redirect['path'] ) . 'feed/' . ( ( 'rss2' ==  get_query_var('feed') || 'feed' == get_query_var('feed') ) ? '' : get_query_var('feed') ), 'feed' ); 
    157             } 
     162 
    158163            if ( get_option('page_comments') && ( ( 'newest' == get_option('default_comments_page') && get_query_var('cpage') > 0 ) || ( 'newest' != get_option('default_comments_page') && get_query_var('cpage') > 1 ) ) ) { 
    159                 $paged_redirect['path'] = user_trailingslashit( trailingslashit( $paged_redirect['path'] ) . 'comment-page-' . get_query_var('cpage'), 'commentpaged' ); 
    160             } 
     164                $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit( 'comment-page-' . get_query_var('cpage'), 'commentpaged' ); 
     165                $redirect['query'] = remove_query_arg( 'cpage', $redirect['query'] ); 
     166            } 
     167 
     168            $paged_redirect['path'] = trailingslashit( preg_replace('|/index.php/?$|', '/', $paged_redirect['path']) ); // strip off trailing /index.php/ 
     169            if ( !empty( $addl_path ) && $wp_rewrite->using_index_permalinks() && strpos($paged_redirect['path'], '/index.php/') === false ) 
     170                $paged_redirect['path'] .= 'index.php/'; 
     171            $paged_redirect['path'] .= $addl_path; 
    161172            $redirect_url = $paged_redirect['scheme'] . '://' . $paged_redirect['host'] . $paged_redirect['path']; 
    162173            $redirect['path'] = $paged_redirect['path']; 
    163             $redirect['query'] = remove_query_arg( 'paged', $redirect['query'] ); 
    164             $redirect['query'] = remove_query_arg( 'feed', $redirect['query'] ); 
    165             $redirect['query'] = remove_query_arg( 'cpage', $redirect['query'] ); 
    166174        } 
    167175    } 
    168176 
    169177    // tack on any additional query vars 
     178    $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] ); 
    170179    if ( $redirect_url && !empty($redirect['query']) ) { 
    171180        if ( strpos($redirect_url, '?') !== false ) 
     
    206215 
    207216        // Remove redundant leading ampersands 
    208         $redirect['query'] = preg_replace( '#^\??&+#', '', $redirect['query'] ); 
     217        $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] ); 
    209218    } 
    210219 
Note: See TracChangeset for help on using the changeset viewer.