Changes from trunk/wp-includes/canonical.php at r17031 to branches/3.0/wp-includes/canonical.php at r15708
- File:
-
- 1 edited
-
branches/3.0/wp-includes/canonical.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/3.0/wp-includes/canonical.php
r17031 r15708 35 35 * not needed or the string of the URL 36 36 */ 37 function redirect_canonical( $requested_url = null, $do_redirect = true) {38 global $wp_rewrite, $is_ iis7, $wp_query, $wpdb;39 40 if ( is_trackback() || is_search() || is_comments_popup() || is_admin() || !empty($_POST) || is_preview() || is_robots() || ( $is_iis7 && !iis7_supports_permalinks()) )37 function redirect_canonical($requested_url=null, $do_redirect=true) { 38 global $wp_rewrite, $is_IIS, $wp_query, $wpdb; 39 40 if ( is_trackback() || is_search() || is_comments_popup() || is_admin() || $is_IIS || ( isset($_POST) && count($_POST) ) || is_preview() || is_robots() ) 41 41 return; 42 42 … … 147 147 148 148 $term_count = 0; 149 foreach ( $wp_query->tax_query->queries as $tax_query ) 150 $term_count += count( $tax_query['terms'] ); 149 foreach ( array('category__in', 'category__not_in', 'category__and', 'post__in', 'post__not_in', 150 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and') as $key ) 151 $term_count += count($wp_query->query_vars[$key]); 151 152 152 153 $obj = $wp_query->get_queried_object(); 153 if ( $term_count <= 1 && !empty($obj->term_id) && ( $tax_url = get_term_link((int)$obj->term_id, $obj->taxonomy) ) && !is_wp_error($tax_url) ) { 154 if ( !empty($redirect['query']) ) {155 if ( is_category()) {156 $redirect['query'] = remove_query_arg( array( 'category_name', 'category', 'cat'), $redirect['query']);157 } elseif ( is_tag() ) {158 $redirect['query'] = remove_query_arg( array( 'tag', 'tag_id'), $redirect['query']);159 } elseif ( is_tax() ) { // Custom taxonomies will have a custom query var, remove those too:160 $tax = get_taxonomy( $obj->taxonomy );161 if ( false !== $tax->query_var)162 $redirect['query'] = remove_query_arg($tax->query_var, $redirect['query']);163 else164 $redirect['query'] = remove_query_arg( array( 'term', 'taxonomy'), $redirect['query']);165 }154 155 if ( $term_count <= 1 && !empty($obj->term_id) && ( $tax_url = get_term_link((int)$obj->term_id, $obj->taxonomy) ) 156 && !is_wp_error($tax_url) && $redirect['query'] ) { 157 if ( is_category() ) { 158 $redirect['query'] = remove_query_arg( array( 'category_name', 'category', 'cat'), $redirect['query']); 159 } elseif ( is_tag() ) { 160 $redirect['query'] = remove_query_arg( array( 'tag', 'tag_id'), $redirect['query']); 161 } elseif ( is_tax() ) { // Custom taxonomies will have a custom query var, remove those too: 162 $tax = get_taxonomy( $obj->taxonomy ); 163 if ( false !== $tax->query_var) 164 $redirect['query'] = remove_query_arg($tax->query_var, $redirect['query']); 165 else 166 $redirect['query'] = remove_query_arg( array( 'term', 'taxonomy'), $redirect['query']); 166 167 } 168 167 169 $tax_url = parse_url($tax_url); 168 170 if ( ! empty($tax_url['query']) ) { // Custom taxonomies may only be accessable via ?taxonomy=..&term=.. … … 172 174 $redirect['path'] = $tax_url['path']; 173 175 } 176 174 177 } 175 178 } elseif ( is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false ) { … … 188 191 // paging and feeds 189 192 if ( get_query_var('paged') || is_feed() || get_query_var('cpage') ) { 190 while ( preg_match( "#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", $redirect['path'] ) || preg_match( '#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#', $redirect['path'] ) || preg_match( '#/comment-page-[0-9]+(/+)?$#', $redirect['path'] ) ) { 193 if ( !$redirect_url ) 194 $redirect_url = $requested_url; 195 $paged_redirect = @parse_url($redirect_url); 196 while ( preg_match( '#/page/?[0-9]+?(/+)?$#', $paged_redirect['path'] ) || preg_match( '#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#', $paged_redirect['path'] ) || preg_match( '#/comment-page-[0-9]+(/+)?$#', $paged_redirect['path'] ) ) { 191 197 // Strip off paging and feed 192 $ redirect['path'] = preg_replace("#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", '/', $redirect['path']); // strip off any existing paging193 $ redirect['path'] = preg_replace('#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $redirect['path']); // strip off feed endings194 $ redirect['path'] = preg_replace('#/comment-page-[0-9]+?(/+)?$#', '/', $redirect['path']); // strip off any existing comment paging198 $paged_redirect['path'] = preg_replace('#/page/?[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any existing paging 199 $paged_redirect['path'] = preg_replace('#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $paged_redirect['path']); // strip off feed endings 200 $paged_redirect['path'] = preg_replace('#/comment-page-[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any existing comment paging 195 201 } 196 202 … … 209 215 if ( !is_feed() ) { 210 216 if ( $paged > 1 && !is_single() ) { 211 $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit(" $wp_rewrite->pagination_base/$paged", 'paged');217 $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit("page/$paged", 'paged'); 212 218 } elseif ( !is_single() ) { 213 219 $addl_path = !empty( $addl_path ) ? trailingslashit($addl_path) : ''; … … 223 229 } 224 230 225 $ redirect['path'] = user_trailingslashit( preg_replace('|/index.php/?$|', '/', $redirect['path']) ); // strip off trailing /index.php/226 if ( !empty( $addl_path ) && $wp_rewrite->using_index_permalinks() && strpos($ redirect['path'], '/index.php/') === false )227 $ redirect['path'] = trailingslashit($redirect['path']) . 'index.php/';231 $paged_redirect['path'] = user_trailingslashit( preg_replace('|/index.php/?$|', '/', $paged_redirect['path']) ); // strip off trailing /index.php/ 232 if ( !empty( $addl_path ) && $wp_rewrite->using_index_permalinks() && strpos($paged_redirect['path'], '/index.php/') === false ) 233 $paged_redirect['path'] = trailingslashit($paged_redirect['path']) . 'index.php/'; 228 234 if ( !empty( $addl_path ) ) 229 $redirect['path'] = trailingslashit($redirect['path']) . $addl_path; 230 $redirect_url = $redirect['scheme'] . '://' . $redirect['host'] . $redirect['path']; 235 $paged_redirect['path'] = trailingslashit($paged_redirect['path']) . $addl_path; 236 $redirect_url = $paged_redirect['scheme'] . '://' . $paged_redirect['host'] . $paged_redirect['path']; 237 $redirect['path'] = $paged_redirect['path']; 231 238 } 232 239 } … … 235 242 $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] ); 236 243 if ( $redirect_url && !empty($redirect['query']) ) { 237 parse_str( $redirect['query'], $_parsed_query ); 238 $redirect = @parse_url($redirect_url); 239 240 if ( ! empty( $_parsed_query['name'] ) && ! empty( $redirect['query'] ) ) { 241 parse_str( $redirect['query'], $_parsed_redirect_query ); 242 243 if ( empty( $_parsed_redirect_query['name'] ) ) 244 unset( $_parsed_query['name'] ); 245 } 246 247 $redirect_url = add_query_arg( $_parsed_query, $redirect_url ); 244 if ( strpos($redirect_url, '?') !== false ) 245 $redirect_url .= '&'; 246 else 247 $redirect_url .= '?'; 248 $redirect_url .= $redirect['query']; 248 249 } 249 250 … … 345 346 if ( !$redirect_url || $redirect_url == $requested_url ) 346 347 return false; 347 348 // Hex encoded octets are case-insensitive. 348 349 // Hex encoded octets are case-insensitive. 349 350 if ( false !== strpos($requested_url, '%') ) { 350 351 if ( !function_exists('lowercase_octets') ) { 351 function lowercase_octets($matches) { 352 return strtolower( $matches[0] ); 353 } 352 function lowercase_octets($matches) { 353 return strtolower( $matches[0] ); 354 } 354 355 } 355 356 $requested_url = preg_replace_callback('|%[a-fA-F0-9][a-fA-F0-9]|', 'lowercase_octets', $requested_url); … … 392 393 return false; 393 394 394 $where = $wpdb->prepare("post_name LIKE %s", like_escape( get_query_var('name')) . '%');395 $where = $wpdb->prepare("post_name LIKE %s", get_query_var('name') . '%'); 395 396 396 397 // if any of post_type, year, monthnum, or day are set, use them to refine the query
Note: See TracChangeset
for help on using the changeset viewer.