WordPress.org

Make WordPress Core

Changeset 9156


Ignore:
Timestamp:
10/14/08 05:51:01 (6 years ago)
Author:
markjaquith
Message:

Canonical Feed URLs, first try. see #7182

File:
1 edited

Legend:

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

    r8843 r9156  
    4040    global $wp_rewrite, $is_IIS, $wp_query, $wpdb; 
    4141 
    42     if ( is_feed() || is_trackback() || is_search() || is_comments_popup() || is_admin() || $is_IIS || ( isset($_POST) && count($_POST) ) || is_preview() || is_robots() ) 
     42    if ( is_trackback() || is_search() || is_comments_popup() || is_admin() || $is_IIS || ( isset($_POST) && count($_POST) ) || is_preview() || is_robots() ) 
    4343        return; 
    4444 
     
    118118        } 
    119119 
    120     // paging 
    121         if ( $paged = get_query_var('paged') ) { 
    122             if ( $paged > 0 ) { 
    123                 if ( !$redirect_url ) 
    124                     $redirect_url = $requested_url; 
    125                 $paged_redirect = @parse_url($redirect_url); 
    126                 $paged_redirect['path'] = preg_replace('|/page/[0-9]+?(/+)?$|', '/', $paged_redirect['path']); // strip off any existing paging 
    127                 $paged_redirect['path'] = preg_replace('|/index.php/?$|', '/', $paged_redirect['path']); // strip off trailing /index.php/ 
     120    // paging and feeds 
     121        if ( get_query_var('paged') || is_feed() ) { 
     122            if ( !$redirect_url ) 
     123                $redirect_url = $requested_url; 
     124            $paged_redirect = @parse_url($redirect_url); 
     125            while ( preg_match( '#page/[0-9]+?(/+)?$#', $paged_redirect['path'] ) || preg_match( '#/feed(/[a-z0-9-]*?(/+)?)?$#', $paged_redirect['path'] ) ) { 
     126                // Strip off paging and feed 
     127                $paged_redirect['path'] = preg_replace('#/page/[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any existing paging 
     128                $paged_redirect['path'] = preg_replace('#/feed(/[a-z0-9-]*?(/+)?)?$#', '/', $paged_redirect['path']); // strip off any existing feed 
     129            } 
     130 
     131            $paged_redirect['path'] = preg_replace('|/index.php/?$|', '/', $paged_redirect['path']); // strip off trailing /index.php/ 
     132            if ( get_query_var('paged') > 0 ) { 
     133                $paged = get_query_var('paged'); 
    128134                if ( $paged > 1 && !is_single() ) { 
    129135                    $paged_redirect['path'] = trailingslashit($paged_redirect['path']); 
     
    131137                        $paged_redirect['path'] .= 'index.php/'; 
    132138                    $paged_redirect['path'] .= user_trailingslashit("page/$paged", 'paged'); 
    133                 } elseif ( !is_home() && !is_single() ){ 
     139                } elseif ( !is_single() ) { 
    134140                    $paged_redirect['path'] = user_trailingslashit($paged_redirect['path'], 'paged'); 
    135141                } 
    136                 $redirect_url = $paged_redirect['scheme'] . '://' . $paged_redirect['host'] . $paged_redirect['path']; 
    137                 $redirect['path'] = $paged_redirect['path']; 
    138             } 
    139             $redirect['query'] = remove_query_arg('paged', $redirect['query']); 
     142            } 
     143            if ( is_feed() ) { 
     144                $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' ); 
     145            } 
     146            $redirect_url = $paged_redirect['scheme'] . '://' . $paged_redirect['host'] . $paged_redirect['path']; 
     147            $redirect['path'] = $paged_redirect['path']; 
     148            $redirect['query'] = remove_query_arg( 'paged', $redirect['query'] ); 
     149            $redirect['query'] = remove_query_arg(  'feed', $redirect['query'] ); 
    140150        } 
    141151    } 
     
    249259            exit(); 
    250260        } else { 
     261            // Debug 
     262            // die("1: $redirect_url<br />2: " . redirect_canonical( $redirect_url, false ) ); 
    251263            return false; 
    252264        } 
Note: See TracChangeset for help on using the changeset viewer.