All pastes #544546 Raw Edit

For thread http://wordpress.org/

public php v1 · immutable
·published 2007-06-06 14:10 UTC
rendered paste body
<?phpclass WP {	var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots');	var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type');	var $extra_query_vars = array();	var $query_vars;	var $query_string;	var $request;	var $matched_rule;	var $matched_query;	var $did_permalink = false;	function add_query_var($qv) {		$this->public_query_vars[] = $qv;	}	function parse_request($extra_query_vars = '') {		global $wp_rewrite;		$this->query_vars = array();		if ( is_array($extra_query_vars) )			$this->extra_query_vars = & $extra_query_vars;		else if (! empty($extra_query_vars))			parse_str($extra_query_vars, $this->extra_query_vars);		// Process PATH_INFO, REQUEST_URI, and 404 for permalinks.		// Fetch the rewrite rules.		$rewrite = $wp_rewrite->wp_rewrite_rules();		if (! empty($rewrite)) {			// If we match a rewrite rule, this will be cleared.			$error = '404';			$this->did_permalink = true;			if ( isset($_SERVER['PATH_INFO']) )				$pathinfo = $_SERVER['PATH_INFO'];			else				$pathinfo = '';			$pathinfo_array = explode('?', $pathinfo);			$pathinfo = str_replace("%", "%25", $pathinfo_array[0]);			$req_uri = $_SERVER['REQUEST_URI'];			$req_uri_array = explode('?', $req_uri);			$req_uri = $req_uri_array[0];			$self = $_SERVER['PHP_SELF'];			$home_path = parse_url(get_option('home'));			if ( isset($home_path['path']) )				$home_path = $home_path['path'];			else				$home_path = '';			$home_path = trim($home_path, '/');			// Trim path info from the end and the leading home path from the			// front.  For path info requests, this leaves us with the requesting			// filename, if any.  For 404 requests, this leaves us with the			// requested permalink.			$req_uri = str_replace($pathinfo, '', $req_uri);			$req_uri = trim($req_uri, '/');			$req_uri = preg_replace("|^$home_path|", '', $req_uri);			$req_uri = trim($req_uri, '/');			$pathinfo = trim($pathinfo, '/');			$pathinfo = preg_replace("|^$home_path|", '', $pathinfo);			$pathinfo = trim($pathinfo, '/');			$self = trim($self, '/');			$self = preg_replace("|^$home_path|", '', $self);			$self = str_replace($home_path, '', $self);			$self = trim($self, '/');			// The requested permalink is in $pathinfo for path info requests and			//  $req_uri for other requests.			if ( ! empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo) ) {				$request = $pathinfo;			} else {				// If the request uri is the index, blank it out so that we don't try to match it against a rule.				if ( $req_uri == $wp_rewrite->index )					$req_uri = '';				$request = $req_uri;			}			$this->request = $request;			// Look for matches.			$request_match = $request;			foreach ($rewrite as $match => $query) {				// If the requesting file is the anchor of the match, prepend it				// to the path info.				if ((! empty($req_uri)) && (strpos($match, $req_uri) === 0) && ($req_uri != $request)) {					$request_match = $req_uri . '/' . $request;				}				if (preg_match("!^$match!", $request_match, $matches) ||					preg_match("!^$match!", urldecode($request_match), $matches)) {					// Got a match.					$this->matched_rule = $match;					// Trim the query of everything up to the '?'.					$query = preg_replace("!^.+\?!", '', $query);					// Substitute the substring matches into the query.					eval("\$query = \"$query\";");					$this->matched_query = $query;					// Parse the query.					parse_str($query, $perma_query_vars);					// If we're processing a 404 request, clear the error var					// since we found something.					if (isset($_GET['error']))						unset($_GET['error']);					if (isset($error))						unset($error);					break;				}			}			// If req_uri is empty or if it is a request for ourself, unset error.			if ( empty($request) || $req_uri == $self || strstr($_SERVER['PHP_SELF'], 'wp-admin/') ) {				if (isset($_GET['error']))					unset($_GET['error']);				if (isset($error))					unset($error);				if ( isset($perma_query_vars) && strstr($_SERVER['PHP_SELF'], 'wp-admin/') )					unset($perma_query_vars);				$this->did_permalink = false;			}		}		$this->public_query_vars = apply_filters('query_vars', $this->public_query_vars);		for ($i=0; $i<count($this->public_query_vars); $i += 1) {			$wpvar = $this->public_query_vars[$i];			if (isset($this->extra_query_vars[$wpvar]))				$this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar];			elseif (isset($GLOBALS[$wpvar]))				$this->query_vars[$wpvar] = $GLOBALS[$wpvar];			elseif (!empty($_POST[$wpvar]))				$this->query_vars[$wpvar] = $_POST[$wpvar];			elseif (!empty($_GET[$wpvar]))				$this->query_vars[$wpvar] = $_GET[$wpvar];			elseif (!empty($perma_query_vars[$wpvar]))				$this->query_vars[$wpvar] = $perma_query_vars[$wpvar];			if ( !empty( $this->query_vars[$wpvar] ) )				$this->query_vars[$wpvar] = (string) $this->query_vars[$wpvar];		}