Changeset 42343 for trunk/src/wp-includes/class-wp.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp.php
r42228 r42343 15 15 * @var array 16 16 */ 17 public $public_query_vars = array( 'm', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage', 'post_type', 'embed' );17 public $public_query_vars = array( 'm', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage', 'post_type', 'embed' ); 18 18 19 19 /** … … 90 90 * @param string $qv Query variable name. 91 91 */ 92 public function add_query_var( $qv) {93 if ( ! in_array($qv, $this->public_query_vars) )92 public function add_query_var( $qv ) { 93 if ( ! in_array( $qv, $this->public_query_vars ) ) { 94 94 $this->public_query_vars[] = $qv; 95 } 95 96 } 96 97 … … 114 115 * @param mixed $value Query variable value. 115 116 */ 116 public function set_query_var( $key, $value) {117 $this->query_vars[ $key] = $value;117 public function set_query_var( $key, $value ) { 118 $this->query_vars[ $key ] = $value; 118 119 } 119 120 … … 130 131 * @param array|string $extra_query_vars Set the extra query variables. 131 132 */ 132 public function parse_request( $extra_query_vars = '') {133 public function parse_request( $extra_query_vars = '' ) { 133 134 global $wp_rewrite; 134 135 … … 142 143 * @param array|string $extra_query_vars Extra passed query variables. 143 144 */ 144 if ( ! apply_filters( 'do_parse_request', true, $this, $extra_query_vars ) ) 145 if ( ! apply_filters( 'do_parse_request', true, $this, $extra_query_vars ) ) { 145 146 return; 146 147 $this->query_vars = array(); 147 } 148 149 $this->query_vars = array(); 148 150 $post_type_query_vars = array(); 149 151 … … 158 160 $rewrite = $wp_rewrite->wp_rewrite_rules(); 159 161 160 if ( ! empty( $rewrite) ) {162 if ( ! empty( $rewrite ) ) { 161 163 // If we match a rewrite rule, this will be cleared. 162 $error = '404';164 $error = '404'; 163 165 $this->did_permalink = true; 164 166 165 $pathinfo = isset( $_SERVER['PATH_INFO'] ) ? $_SERVER['PATH_INFO'] : '';167 $pathinfo = isset( $_SERVER['PATH_INFO'] ) ? $_SERVER['PATH_INFO'] : ''; 166 168 list( $pathinfo ) = explode( '?', $pathinfo ); 167 $pathinfo = str_replace( "%", "%25", $pathinfo );169 $pathinfo = str_replace( '%', '%25', $pathinfo ); 168 170 169 171 list( $req_uri ) = explode( '?', $_SERVER['REQUEST_URI'] ); 170 $self = $_SERVER['PHP_SELF'];171 $home_path = trim( parse_url( home_url(), PHP_URL_PATH ), '/' );172 $self = $_SERVER['PHP_SELF']; 173 $home_path = trim( parse_url( home_url(), PHP_URL_PATH ), '/' ); 172 174 $home_path_regex = sprintf( '|^%s|i', preg_quote( $home_path, '|' ) ); 173 175 … … 176 178 // filename, if any. For 404 requests, this leaves us with the 177 179 // requested permalink. 178 $req_uri = str_replace($pathinfo, '', $req_uri);179 $req_uri = trim($req_uri, '/');180 $req_uri = preg_replace( $home_path_regex, '', $req_uri );181 $req_uri = trim($req_uri, '/');182 $pathinfo = trim( $pathinfo, '/');180 $req_uri = str_replace( $pathinfo, '', $req_uri ); 181 $req_uri = trim( $req_uri, '/' ); 182 $req_uri = preg_replace( $home_path_regex, '', $req_uri ); 183 $req_uri = trim( $req_uri, '/' ); 184 $pathinfo = trim( $pathinfo, '/' ); 183 185 $pathinfo = preg_replace( $home_path_regex, '', $pathinfo ); 184 $pathinfo = trim( $pathinfo, '/');185 $self = trim($self, '/');186 $self = preg_replace( $home_path_regex, '', $self );187 $self = trim($self, '/');186 $pathinfo = trim( $pathinfo, '/' ); 187 $self = trim( $self, '/' ); 188 $self = preg_replace( $home_path_regex, '', $self ); 189 $self = trim( $self, '/' ); 188 190 189 191 // The requested permalink is in $pathinfo for path info requests and 190 192 // $req_uri for other requests. 191 if ( ! empty( $pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo) ) {193 if ( ! empty( $pathinfo ) && ! preg_match( '|^.*' . $wp_rewrite->index . '$|', $pathinfo ) ) { 192 194 $requested_path = $pathinfo; 193 195 } else { 194 196 // If the request uri is the index, blank it out so that we don't try to match it against a rule. 195 if ( $req_uri == $wp_rewrite->index ) 197 if ( $req_uri == $wp_rewrite->index ) { 196 198 $req_uri = ''; 199 } 197 200 $requested_path = $req_uri; 198 201 } … … 207 210 if ( isset( $rewrite['$'] ) ) { 208 211 $this->matched_rule = '$'; 209 $query = $rewrite['$'];210 $matches = array('');212 $query = $rewrite['$']; 213 $matches = array( '' ); 211 214 } 212 215 } else { 213 216 foreach ( (array) $rewrite as $match => $query ) { 214 217 // If the requested file is the anchor of the match, prepend it to the path info. 215 if ( ! empty( $requested_file) && strpos($match, $requested_file) === 0 && $requested_file != $requested_path )218 if ( ! empty( $requested_file ) && strpos( $match, $requested_file ) === 0 && $requested_file != $requested_path ) { 216 219 $request_match = $requested_file . '/' . $requested_path; 217 218 if ( preg_match("#^$match#", $request_match, $matches) || 219 preg_match("#^$match#", urldecode($request_match), $matches) ) { 220 } 221 222 if ( preg_match( "#^$match#", $request_match, $matches ) || 223 preg_match( "#^$match#", urldecode( $request_match ), $matches ) ) { 220 224 221 225 if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) { … … 223 227 $page = get_page_by_path( $matches[ $varmatch[1] ] ); 224 228 if ( ! $page ) { 225 229 continue; 226 230 } 227 231 … … 242 246 if ( isset( $this->matched_rule ) ) { 243 247 // Trim the query of everything up to the '?'. 244 $query = preg_replace( "!^.+\?!", '', $query);248 $query = preg_replace( '!^.+\?!', '', $query ); 245 249 246 250 // Substitute the substring matches into the query. 247 $query = addslashes( WP_MatchesMapRegex::apply($query, $matches));251 $query = addslashes( WP_MatchesMapRegex::apply( $query, $matches ) ); 248 252 249 253 $this->matched_query = $query; 250 254 251 255 // Parse the query. 252 parse_str( $query, $perma_query_vars);256 parse_str( $query, $perma_query_vars ); 253 257 254 258 // If we're processing a 404 request, clear the error var since we found something. 255 if ( '404' == $error ) 259 if ( '404' == $error ) { 256 260 unset( $error, $_GET['error'] ); 261 } 257 262 } 258 263 259 264 // If req_uri is empty or if it is a request for ourself, unset error. 260 if ( empty( $requested_path) || $requested_file == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) {265 if ( empty( $requested_path ) || $requested_file == $self || strpos( $_SERVER['PHP_SELF'], 'wp-admin/' ) !== false ) { 261 266 unset( $error, $_GET['error'] ); 262 267 263 if ( isset( $perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false )268 if ( isset( $perma_query_vars ) && strpos( $_SERVER['PHP_SELF'], 'wp-admin/' ) !== false ) { 264 269 unset( $perma_query_vars ); 270 } 265 271 266 272 $this->did_permalink = false; … … 283 289 foreach ( get_post_types( array(), 'objects' ) as $post_type => $t ) { 284 290 if ( is_post_type_viewable( $t ) && $t->query_var ) { 285 $post_type_query_vars[ $t->query_var] = $post_type;291 $post_type_query_vars[ $t->query_var ] = $post_type; 286 292 } 287 293 } 288 294 289 295 foreach ( $this->public_query_vars as $wpvar ) { 290 if ( isset( $this->extra_query_vars[$wpvar] ) ) 291 $this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar]; 292 elseif ( isset( $_POST[$wpvar] ) ) 293 $this->query_vars[$wpvar] = $_POST[$wpvar]; 294 elseif ( isset( $_GET[$wpvar] ) ) 295 $this->query_vars[$wpvar] = $_GET[$wpvar]; 296 elseif ( isset( $perma_query_vars[$wpvar] ) ) 297 $this->query_vars[$wpvar] = $perma_query_vars[$wpvar]; 298 299 if ( !empty( $this->query_vars[$wpvar] ) ) { 300 if ( ! is_array( $this->query_vars[$wpvar] ) ) { 301 $this->query_vars[$wpvar] = (string) $this->query_vars[$wpvar]; 296 if ( isset( $this->extra_query_vars[ $wpvar ] ) ) { 297 $this->query_vars[ $wpvar ] = $this->extra_query_vars[ $wpvar ]; 298 } elseif ( isset( $_POST[ $wpvar ] ) ) { 299 $this->query_vars[ $wpvar ] = $_POST[ $wpvar ]; 300 } elseif ( isset( $_GET[ $wpvar ] ) ) { 301 $this->query_vars[ $wpvar ] = $_GET[ $wpvar ]; 302 } elseif ( isset( $perma_query_vars[ $wpvar ] ) ) { 303 $this->query_vars[ $wpvar ] = $perma_query_vars[ $wpvar ]; 304 } 305 306 if ( ! empty( $this->query_vars[ $wpvar ] ) ) { 307 if ( ! is_array( $this->query_vars[ $wpvar ] ) ) { 308 $this->query_vars[ $wpvar ] = (string) $this->query_vars[ $wpvar ]; 302 309 } else { 303 foreach ( $this->query_vars[ $wpvar] as $vkey => $v ) {304 if ( ! is_object( $v ) ) {305 $this->query_vars[ $wpvar][$vkey] = (string) $v;310 foreach ( $this->query_vars[ $wpvar ] as $vkey => $v ) { 311 if ( ! is_object( $v ) ) { 312 $this->query_vars[ $wpvar ][ $vkey ] = (string) $v; 306 313 } 307 314 } 308 315 } 309 316 310 if ( isset( $post_type_query_vars[$wpvar] ) ) {311 $this->query_vars['post_type'] = $post_type_query_vars[ $wpvar];312 $this->query_vars['name'] = $this->query_vars[$wpvar];317 if ( isset( $post_type_query_vars[ $wpvar ] ) ) { 318 $this->query_vars['post_type'] = $post_type_query_vars[ $wpvar ]; 319 $this->query_vars['name'] = $this->query_vars[ $wpvar ]; 313 320 } 314 321 } … … 316 323 317 324 // Convert urldecoded spaces back into + 318 foreach ( get_taxonomies( array() , 'objects' ) as $taxonomy => $t ) 319 if ( $t->query_var && isset( $this->query_vars[$t->query_var] ) ) 320 $this->query_vars[$t->query_var] = str_replace( ' ', '+', $this->query_vars[$t->query_var] ); 325 foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy => $t ) { 326 if ( $t->query_var && isset( $this->query_vars[ $t->query_var ] ) ) { 327 $this->query_vars[ $t->query_var ] = str_replace( ' ', '+', $this->query_vars[ $t->query_var ] ); 328 } 329 } 321 330 322 331 // Don't allow non-publicly queryable taxonomies to be queried from the front end. … … 334 343 335 344 // Limit publicly queried post_types to those that are publicly_queryable 336 if ( isset( $this->query_vars['post_type'] ) ) {337 $queryable_post_types = get_post_types( array( 'publicly_queryable' => true) );345 if ( isset( $this->query_vars['post_type'] ) ) { 346 $queryable_post_types = get_post_types( array( 'publicly_queryable' => true ) ); 338 347 if ( ! is_array( $this->query_vars['post_type'] ) ) { 339 if ( ! in_array( $this->query_vars['post_type'], $queryable_post_types ) ) 348 if ( ! in_array( $this->query_vars['post_type'], $queryable_post_types ) ) { 340 349 unset( $this->query_vars['post_type'] ); 350 } 341 351 } else { 342 352 $this->query_vars['post_type'] = array_intersect( $this->query_vars['post_type'], $queryable_post_types ); … … 347 357 $this->query_vars = wp_resolve_numeric_slug_conflicts( $this->query_vars ); 348 358 349 foreach ( (array) $this->private_query_vars as $var) { 350 if ( isset($this->extra_query_vars[$var]) ) 351 $this->query_vars[$var] = $this->extra_query_vars[$var]; 352 } 353 354 if ( isset($error) ) 359 foreach ( (array) $this->private_query_vars as $var ) { 360 if ( isset( $this->extra_query_vars[ $var ] ) ) { 361 $this->query_vars[ $var ] = $this->extra_query_vars[ $var ]; 362 } 363 } 364 365 if ( isset( $error ) ) { 355 366 $this->query_vars['error'] = $error; 367 } 356 368 357 369 /** … … 384 396 */ 385 397 public function send_headers() { 386 $headers = array();387 $status = null;398 $headers = array(); 399 $status = null; 388 400 $exit_required = false; 389 401 390 if ( is_user_logged_in() ) 391 $headers = array_merge($headers, wp_get_nocache_headers()); 402 if ( is_user_logged_in() ) { 403 $headers = array_merge( $headers, wp_get_nocache_headers() ); 404 } 392 405 if ( ! empty( $this->query_vars['error'] ) ) { 393 406 $status = (int) $this->query_vars['error']; 394 407 if ( 404 === $status ) { 395 if ( ! is_user_logged_in() ) 396 $headers = array_merge($headers, wp_get_nocache_headers()); 397 $headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset'); 408 if ( ! is_user_logged_in() ) { 409 $headers = array_merge( $headers, wp_get_nocache_headers() ); 410 } 411 $headers['Content-Type'] = get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ); 398 412 } elseif ( in_array( $status, array( 403, 500, 502, 503 ) ) ) { 399 413 $exit_required = true; 400 414 } 401 415 } elseif ( empty( $this->query_vars['feed'] ) ) { 402 $headers['Content-Type'] = get_option( 'html_type') . '; charset=' . get_option('blog_charset');416 $headers['Content-Type'] = get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ); 403 417 } else { 404 418 // Set the correct content type for feeds … … 433 447 $wp_last_modified .= ' GMT'; 434 448 435 $wp_etag = '"' . md5($wp_last_modified) . '"';449 $wp_etag = '"' . md5( $wp_last_modified ) . '"'; 436 450 $headers['Last-Modified'] = $wp_last_modified; 437 $headers['ETag'] = $wp_etag;451 $headers['ETag'] = $wp_etag; 438 452 439 453 // Support for Conditional GET 440 if ( isset($_SERVER['HTTP_IF_NONE_MATCH']))454 if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ) { 441 455 $client_etag = wp_unslash( $_SERVER['HTTP_IF_NONE_MATCH'] ); 442 else $client_etag = false; 443 444 $client_last_modified = empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? '' : trim($_SERVER['HTTP_IF_MODIFIED_SINCE']); 456 } else { 457 $client_etag = false; 458 } 459 460 $client_last_modified = empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ? '' : trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ); 445 461 // If string is empty, return 0. If not, attempt to parse into a timestamp 446 $client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified) : 0;462 $client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0; 447 463 448 464 // Make a timestamp for our most recent modification... 449 $wp_modified_timestamp = strtotime( $wp_last_modified);450 451 if ( ( $client_last_modified && $client_etag) ?452 ( ($client_modified_timestamp >= $wp_modified_timestamp) && ($client_etag == $wp_etag)) :453 ( ($client_modified_timestamp >= $wp_modified_timestamp) || ($client_etag == $wp_etag)) ) {454 $status = 304;465 $wp_modified_timestamp = strtotime( $wp_last_modified ); 466 467 if ( ( $client_last_modified && $client_etag ) ? 468 ( ( $client_modified_timestamp >= $wp_modified_timestamp ) && ( $client_etag == $wp_etag ) ) : 469 ( ( $client_modified_timestamp >= $wp_modified_timestamp ) || ( $client_etag == $wp_etag ) ) ) { 470 $status = 304; 455 471 $exit_required = true; 456 472 } … … 467 483 $headers = apply_filters( 'wp_headers', $headers, $this ); 468 484 469 if ( ! empty( $status ) ) 485 if ( ! empty( $status ) ) { 470 486 status_header( $status ); 487 } 471 488 472 489 // If Last-Modified is set to false, it should not be sent (no-cache situation). … … 489 506 } 490 507 491 foreach ( (array) $headers as $name => $field_value ) 492 @header("{$name}: {$field_value}"); 493 494 if ( $exit_required ) 508 foreach ( (array) $headers as $name => $field_value ) { 509 @header( "{$name}: {$field_value}" ); 510 } 511 512 if ( $exit_required ) { 495 513 exit(); 514 } 496 515 497 516 /** … … 515 534 public function build_query_string() { 516 535 $this->query_string = ''; 517 foreach ( (array) array_keys( $this->query_vars) as $wpvar) {518 if ( '' != $this->query_vars[ $wpvar] ) {519 $this->query_string .= ( strlen($this->query_string) < 1) ? '' : '&';520 if ( ! is_scalar($this->query_vars[$wpvar]) )// Discard non-scalars.536 foreach ( (array) array_keys( $this->query_vars ) as $wpvar ) { 537 if ( '' != $this->query_vars[ $wpvar ] ) { 538 $this->query_string .= ( strlen( $this->query_string ) < 1 ) ? '' : '&'; 539 if ( ! is_scalar( $this->query_vars[ $wpvar ] ) ) { // Discard non-scalars. 521 540 continue; 522 $this->query_string .= $wpvar . '=' . rawurlencode($this->query_vars[$wpvar]); 541 } 542 $this->query_string .= $wpvar . '=' . rawurlencode( $this->query_vars[ $wpvar ] ); 523 543 } 524 544 } … … 534 554 */ 535 555 $this->query_string = apply_filters( 'query_string', $this->query_string ); 536 parse_str( $this->query_string, $this->query_vars);556 parse_str( $this->query_string, $this->query_vars ); 537 557 } 538 558 } … … 565 585 566 586 $GLOBALS['query_string'] = $this->query_string; 567 $GLOBALS['posts'] = & $wp_query->posts;568 $GLOBALS['post'] = isset( $wp_query->post ) ? $wp_query->post : null;569 $GLOBALS['request'] = $wp_query->request;587 $GLOBALS['posts'] = & $wp_query->posts; 588 $GLOBALS['post'] = isset( $wp_query->post ) ? $wp_query->post : null; 589 $GLOBALS['request'] = $wp_query->request; 570 590 571 591 if ( $wp_query->is_single() || $wp_query->is_page() ) { … … 574 594 } 575 595 576 if ( $wp_query->is_author() && isset( $wp_query->post ) ) 596 if ( $wp_query->is_author() && isset( $wp_query->post ) ) { 577 597 $GLOBALS['authordata'] = get_userdata( $wp_query->post->post_author ); 598 } 578 599 } 579 600 … … 597 618 global $wp_the_query; 598 619 $this->build_query_string(); 599 $wp_the_query->query( $this->query_vars);600 601 602 620 $wp_the_query->query( $this->query_vars ); 621 } 622 623 /** 603 624 * Set the Headers for 404, if nothing is found for requested URL. 604 625 * … … 614 635 * 615 636 * @since 2.0.0 616 637 * 617 638 * @global WP_Query $wp_query 618 639 */ 619 640 public function handle_404() { 620 641 global $wp_query; … … 636 657 637 658 // If we've already issued a 404, bail. 638 if ( is_404() ) 659 if ( is_404() ) { 639 660 return; 661 } 640 662 641 663 // Never 404 for the admin, robots, or if we found posts. … … 658 680 $next = '<!--nextpage-->'; 659 681 if ( $p && false !== strpos( $p->post_content, $next ) && ! empty( $this->query_vars['page'] ) ) { 660 $page = trim( $this->query_vars['page'], '/' );682 $page = trim( $this->query_vars['page'], '/' ); 661 683 $success = (int) $page <= ( substr_count( $p->post_content, $next ) + 1 ); 662 684 } … … 709 731 * @param string|array $query_args Passed to parse_request(). 710 732 */ 711 public function main( $query_args = '') {733 public function main( $query_args = '' ) { 712 734 $this->init(); 713 $this->parse_request( $query_args);735 $this->parse_request( $query_args ); 714 736 $this->send_headers(); 715 737 $this->query_posts();
Note: See TracChangeset
for help on using the changeset viewer.