Changes from branches/3.0/wp-includes/canonical.php at r15708 to trunk/wp-includes/canonical.php at r17031
- File:
-
- 1 edited
-
trunk/wp-includes/canonical.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/canonical.php
r15708 r17031 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_ 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() )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() ) ) 41 41 return; 42 42 … … 147 147 148 148 $term_count = 0; 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]); 149 foreach ( $wp_query->tax_query->queries as $tax_query ) 150 $term_count += count( $tax_query['terms'] ); 152 151 153 152 $obj = $wp_query->get_queried_object(); 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 else166 $redirect['query'] = remove_query_arg( array( 'term', 'taxonomy'), $redirect['query']);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 else 164 $redirect['query'] = remove_query_arg( array( 'term', 'taxonomy'), $redirect['query']); 165 } 167 166 } 168 169 167 $tax_url = parse_url($tax_url); 170 168 if ( ! empty($tax_url['query']) ) { // Custom taxonomies may only be accessable via ?taxonomy=..&term=.. … … 174 172 $redirect['path'] = $tax_url['path']; 175 173 } 176 177 174 } 178 175 } elseif ( is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false ) { … … 191 188 // paging and feeds 192 189 if ( get_query_var('paged') || is_feed() || get_query_var('cpage') ) { 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'] ) ) { 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'] ) ) { 197 191 // Strip off paging and feed 198 $ paged_redirect['path'] = preg_replace('#/page/?[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any existing paging199 $ paged_redirect['path'] = preg_replace('#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $paged_redirect['path']); // strip off feed endings200 $ paged_redirect['path'] = preg_replace('#/comment-page-[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any existing comment paging192 $redirect['path'] = preg_replace("#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", '/', $redirect['path']); // strip off any existing paging 193 $redirect['path'] = preg_replace('#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $redirect['path']); // strip off feed endings 194 $redirect['path'] = preg_replace('#/comment-page-[0-9]+?(/+)?$#', '/', $redirect['path']); // strip off any existing comment paging 201 195 } 202 196 … … 215 209 if ( !is_feed() ) { 216 210 if ( $paged > 1 && !is_single() ) { 217 $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit(" page/$paged", 'paged');211 $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit("$wp_rewrite->pagination_base/$paged", 'paged'); 218 212 } elseif ( !is_single() ) { 219 213 $addl_path = !empty( $addl_path ) ? trailingslashit($addl_path) : ''; … … 229 223 } 230 224 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/';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/'; 234 228 if ( !empty( $addl_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']; 229 $redirect['path'] = trailingslashit($redirect['path']) . $addl_path; 230 $redirect_url = $redirect['scheme'] . '://' . $redirect['host'] . $redirect['path']; 238 231 } 239 232 } … … 242 235 $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] ); 243 236 if ( $redirect_url && !empty($redirect['query']) ) { 244 if ( strpos($redirect_url, '?') !== false ) 245 $redirect_url .= '&'; 246 else 247 $redirect_url .= '?'; 248 $redirect_url .= $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 ); 249 248 } 250 249 … … 346 345 if ( !$redirect_url || $redirect_url == $requested_url ) 347 346 return false; 348 349 // Hex encoded octets are case-insensitive. 347 348 // Hex encoded octets are case-insensitive. 350 349 if ( false !== strpos($requested_url, '%') ) { 351 350 if ( !function_exists('lowercase_octets') ) { 352 function lowercase_octets($matches) { 353 return strtolower( $matches[0] ); 354 } 351 function lowercase_octets($matches) { 352 return strtolower( $matches[0] ); 353 } 355 354 } 356 355 $requested_url = preg_replace_callback('|%[a-fA-F0-9][a-fA-F0-9]|', 'lowercase_octets', $requested_url); … … 393 392 return false; 394 393 395 $where = $wpdb->prepare("post_name LIKE %s", get_query_var('name') . '%');394 $where = $wpdb->prepare("post_name LIKE %s", like_escape( get_query_var('name') ) . '%'); 396 395 397 396 // 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.