Changeset 9697
- Timestamp:
- 11/14/2008 10:48:22 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/canonical.php
r9649 r9697 134 134 $redirect_url = $requested_url; 135 135 $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'] ) ) { 137 137 // Strip off paging and feed 138 138 $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 144 149 if ( get_query_var('paged') > 0 ) { 145 150 $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'] ); 153 160 } 154 161 } 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 158 163 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; 161 172 $redirect_url = $paged_redirect['scheme'] . '://' . $paged_redirect['host'] . $paged_redirect['path']; 162 173 $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'] );166 174 } 167 175 } 168 176 169 177 // tack on any additional query vars 178 $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] ); 170 179 if ( $redirect_url && !empty($redirect['query']) ) { 171 180 if ( strpos($redirect_url, '?') !== false ) … … 206 215 207 216 // Remove redundant leading ampersands 208 $redirect['query'] = preg_replace( '#^\??& +#', '', $redirect['query'] );217 $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] ); 209 218 } 210 219
Note: See TracChangeset
for help on using the changeset viewer.