web/wp-includes/class-wp.php
changeset 204 09a1c134465b
parent 194 32102edaa81b
equal deleted inserted replaced
203:f507feede89a 204:09a1c134465b
   117 	 *
   117 	 *
   118 	 * @param array|string $extra_query_vars Set the extra query variables.
   118 	 * @param array|string $extra_query_vars Set the extra query variables.
   119 	 */
   119 	 */
   120 	function parse_request($extra_query_vars = '') {
   120 	function parse_request($extra_query_vars = '') {
   121 		global $wp_rewrite;
   121 		global $wp_rewrite;
       
   122 
       
   123 		if ( ! apply_filters( 'do_parse_request', true, $this, $extra_query_vars ) )
       
   124 			return;
   122 
   125 
   123 		$this->query_vars = array();
   126 		$this->query_vars = array();
   124 		$post_type_query_vars = array();
   127 		$post_type_query_vars = array();
   125 
   128 
   126 		if ( is_array($extra_query_vars) )
   129 		if ( is_array($extra_query_vars) )
   159 			// front. For path info requests, this leaves us with the requesting
   162 			// front. For path info requests, this leaves us with the requesting
   160 			// filename, if any. For 404 requests, this leaves us with the
   163 			// filename, if any. For 404 requests, this leaves us with the
   161 			// requested permalink.
   164 			// requested permalink.
   162 			$req_uri = str_replace($pathinfo, '', $req_uri);
   165 			$req_uri = str_replace($pathinfo, '', $req_uri);
   163 			$req_uri = trim($req_uri, '/');
   166 			$req_uri = trim($req_uri, '/');
   164 			$req_uri = preg_replace("|^$home_path|", '', $req_uri);
   167 			$req_uri = preg_replace("|^$home_path|i", '', $req_uri);
   165 			$req_uri = trim($req_uri, '/');
   168 			$req_uri = trim($req_uri, '/');
   166 			$pathinfo = trim($pathinfo, '/');
   169 			$pathinfo = trim($pathinfo, '/');
   167 			$pathinfo = preg_replace("|^$home_path|", '', $pathinfo);
   170 			$pathinfo = preg_replace("|^$home_path|i", '', $pathinfo);
   168 			$pathinfo = trim($pathinfo, '/');
   171 			$pathinfo = trim($pathinfo, '/');
   169 			$self = trim($self, '/');
   172 			$self = trim($self, '/');
   170 			$self = preg_replace("|^$home_path|", '', $self);
   173 			$self = preg_replace("|^$home_path|i", '', $self);
   171 			$self = trim($self, '/');
   174 			$self = trim($self, '/');
   172 
   175 
   173 			// The requested permalink is in $pathinfo for path info requests and
   176 			// The requested permalink is in $pathinfo for path info requests and
   174 			//  $req_uri for other requests.
   177 			//  $req_uri for other requests.
   175 			if ( ! empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo) ) {
   178 			if ( ! empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo) ) {
   190 				if ( isset( $rewrite['$'] ) ) {
   193 				if ( isset( $rewrite['$'] ) ) {
   191 					$this->matched_rule = '$';
   194 					$this->matched_rule = '$';
   192 					$query = $rewrite['$'];
   195 					$query = $rewrite['$'];
   193 					$matches = array('');
   196 					$matches = array('');
   194 				}
   197 				}
   195 			} else if ( $req_uri != 'wp-app.php' ) {
   198 			} else {
   196 				foreach ( (array) $rewrite as $match => $query ) {
   199 				foreach ( (array) $rewrite as $match => $query ) {
   197 					// If the requesting file is the anchor of the match, prepend it to the path info.
   200 					// If the requesting file is the anchor of the match, prepend it to the path info.
   198 					if ( ! empty($req_uri) && strpos($match, $req_uri) === 0 && $req_uri != $request )
   201 					if ( ! empty($req_uri) && strpos($match, $req_uri) === 0 && $req_uri != $request )
   199 						$request_match = $req_uri . '/' . $request;
   202 						$request_match = $req_uri . '/' . $request;
   200 
   203 
   224 				$this->matched_query = $query;
   227 				$this->matched_query = $query;
   225 
   228 
   226 				// Parse the query.
   229 				// Parse the query.
   227 				parse_str($query, $perma_query_vars);
   230 				parse_str($query, $perma_query_vars);
   228 
   231 
   229 				// If we're processing a 404 request, clear the error var
   232 				// If we're processing a 404 request, clear the error var since we found something.
   230 				// since we found something.
   233 				if ( '404' == $error )
   231 				unset( $_GET['error'] );
   234 					unset( $error, $_GET['error'] );
   232 				unset( $error );
       
   233 			}
   235 			}
   234 
   236 
   235 			// If req_uri is empty or if it is a request for ourself, unset error.
   237 			// If req_uri is empty or if it is a request for ourself, unset error.
   236 			if ( empty($request) || $req_uri == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) {
   238 			if ( empty($request) || $req_uri == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) {
   237 				unset( $_GET['error'] );
   239 				unset( $error, $_GET['error'] );
   238 				unset( $error );
       
   239 
   240 
   240 				if ( isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false )
   241 				if ( isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false )
   241 					unset( $perma_query_vars );
   242 					unset( $perma_query_vars );
   242 
   243 
   243 				$this->did_permalink = false;
   244 				$this->did_permalink = false;
   320 		$status = null;
   321 		$status = null;
   321 		$exit_required = false;
   322 		$exit_required = false;
   322 
   323 
   323 		if ( is_user_logged_in() )
   324 		if ( is_user_logged_in() )
   324 			$headers = array_merge($headers, wp_get_nocache_headers());
   325 			$headers = array_merge($headers, wp_get_nocache_headers());
   325 		if ( !empty($this->query_vars['error']) && '404' == $this->query_vars['error'] ) {
   326 		if ( ! empty( $this->query_vars['error'] ) ) {
   326 			$status = 404;
   327 			$status = (int) $this->query_vars['error'];
   327 			if ( !is_user_logged_in() )
   328 			if ( 404 === $status ) {
   328 				$headers = array_merge($headers, wp_get_nocache_headers());
   329 				if ( ! is_user_logged_in() )
   329 			$headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset');
   330 					$headers = array_merge($headers, wp_get_nocache_headers());
       
   331 				$headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset');
       
   332 			} elseif ( in_array( $status, array( 403, 500, 502, 503 ) ) ) {
       
   333 				$exit_required = true;
       
   334 			}
   330 		} else if ( empty($this->query_vars['feed']) ) {
   335 		} else if ( empty($this->query_vars['feed']) ) {
   331 			$headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset');
   336 			$headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset');
   332 		} else {
   337 		} else {
   333 			// We're showing a feed, so WP is indeed the only thing that last changed
   338 			// We're showing a feed, so WP is indeed the only thing that last changed
   334 			if ( !empty($this->query_vars['withcomments'])
   339 			if ( !empty($this->query_vars['withcomments'])
   374 		if ( ! empty( $status ) )
   379 		if ( ! empty( $status ) )
   375 			status_header( $status );
   380 			status_header( $status );
   376 		foreach( (array) $headers as $name => $field_value )
   381 		foreach( (array) $headers as $name => $field_value )
   377 			@header("{$name}: {$field_value}");
   382 			@header("{$name}: {$field_value}");
   378 
   383 
       
   384 		if ( isset( $headers['Last-Modified'] ) && empty( $headers['Last-Modified'] ) && function_exists( 'header_remove' ) )
       
   385 			@header_remove( 'Last-Modified' );
       
   386 
   379 		if ( $exit_required )
   387 		if ( $exit_required )
   380 			exit();
   388 			exit();
   381 
   389 
   382 		do_action_ref_array('send_headers', array(&$this));
   390 		do_action_ref_array('send_headers', array(&$this));
   383 	}
   391 	}
   599 	 *
   607 	 *
   600 	 * @access private
   608 	 * @access private
   601 	 * @return string
   609 	 * @return string
   602 	 */
   610 	 */
   603 	function _map() {
   611 	function _map() {
   604 		$callback = array(&$this, 'callback');
   612 		$callback = array($this, 'callback');
   605 		return preg_replace_callback($this->_pattern, $callback, $this->_subject);
   613 		return preg_replace_callback($this->_pattern, $callback, $this->_subject);
   606 	}
   614 	}
   607 
   615 
   608 	/**
   616 	/**
   609 	 * preg_replace_callback hook
   617 	 * preg_replace_callback hook