wp/wp-includes/class-wp.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * WordPress environment setup class.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
class WP {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
	 * Public query variables.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
	 * Long list of public query variables.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    18
	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', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage', 'post_type');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
	 * Private query variables.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
	 * Long list of private query variables.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    28
	public $private_query_vars = array( 'offset', 'posts_per_page', 'posts_per_archive_page', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm', 'comments_per_page', 'post__in', 'post__not_in', 'post_parent', 'post_parent__in', 'post_parent__not_in' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
	 * Extra query variables set by the user.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    36
	public $extra_query_vars = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
	 * Query variables for setting up the WordPress Query Loop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    44
	public $query_vars;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
	 * String parsed to set the query variables.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    52
	public $query_string;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
	 * Permalink or requested URI.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    60
	public $request;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
	 * Rewrite rule the request matched.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    68
	public $matched_rule;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
	 * Rewrite query the request matched.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    76
	public $matched_query;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
	 * Whether already did the permalink.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    84
	public $did_permalink = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
	 * Add name to list of public query variables.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
	 * @param string $qv Query variable name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    93
	public function add_query_var($qv) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
		if ( !in_array($qv, $this->public_query_vars) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
			$this->public_query_vars[] = $qv;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
	 * Set the value of a query variable.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
	 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
	 * @param string $key Query variable name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
	 * @param mixed $value Query variable value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   106
	public function set_query_var($key, $value) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
		$this->query_vars[$key] = $value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
	 * Parse request to find correct WordPress query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
	 * Sets up the query variables based on the request. There are also many
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
	 * filters and actions that can be used to further manipulate the result.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
	 * @param array|string $extra_query_vars Set the extra query variables.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   120
	public function parse_request($extra_query_vars = '') {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
		global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   123
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   124
		 * Filter whether to parse the request.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   125
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   126
		 * @since 3.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   127
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   128
		 * @param bool         $bool             Whether or not to parse the request. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   129
		 * @param WP           $this             Current WordPress environment instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   130
		 * @param array|string $extra_query_vars Extra passed query variables.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   131
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
		if ( ! apply_filters( 'do_parse_request', true, $this, $extra_query_vars ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
		$this->query_vars = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
		$post_type_query_vars = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   138
		if ( is_array( $extra_query_vars ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
			$this->extra_query_vars = & $extra_query_vars;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   140
		} elseif ( ! empty( $extra_query_vars ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   141
			parse_str( $extra_query_vars, $this->extra_query_vars );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   142
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
		// Process PATH_INFO, REQUEST_URI, and 404 for permalinks.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
		// Fetch the rewrite rules.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
		$rewrite = $wp_rewrite->wp_rewrite_rules();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
		if ( ! empty($rewrite) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
			// If we match a rewrite rule, this will be cleared.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
			$error = '404';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
			$this->did_permalink = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
			$pathinfo = isset( $_SERVER['PATH_INFO'] ) ? $_SERVER['PATH_INFO'] : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
			list( $pathinfo ) = explode( '?', $pathinfo );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
			$pathinfo = str_replace( "%", "%25", $pathinfo );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
			list( $req_uri ) = explode( '?', $_SERVER['REQUEST_URI'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
			$self = $_SERVER['PHP_SELF'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
			$home_path = trim( parse_url( home_url(), PHP_URL_PATH ), '/' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
			// Trim path info from the end and the leading home path from the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
			// front. For path info requests, this leaves us with the requesting
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
			// filename, if any. For 404 requests, this leaves us with the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
			// requested permalink.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
			$req_uri = str_replace($pathinfo, '', $req_uri);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
			$req_uri = trim($req_uri, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
			$req_uri = preg_replace("|^$home_path|i", '', $req_uri);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
			$req_uri = trim($req_uri, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
			$pathinfo = trim($pathinfo, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
			$pathinfo = preg_replace("|^$home_path|i", '', $pathinfo);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
			$pathinfo = trim($pathinfo, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
			$self = trim($self, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
			$self = preg_replace("|^$home_path|i", '', $self);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
			$self = trim($self, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
			// The requested permalink is in $pathinfo for path info requests and
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
			//  $req_uri for other requests.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
			if ( ! empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
				$request = $pathinfo;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
				// If the request uri is the index, blank it out so that we don't try to match it against a rule.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
				if ( $req_uri == $wp_rewrite->index )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
					$req_uri = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
				$request = $req_uri;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
			$this->request = $request;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
			// Look for matches.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
			$request_match = $request;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
			if ( empty( $request_match ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
				// An empty request could only match against ^$ regex
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
				if ( isset( $rewrite['$'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
					$this->matched_rule = '$';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
					$query = $rewrite['$'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
					$matches = array('');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
				foreach ( (array) $rewrite as $match => $query ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
					// If the requesting file is the anchor of the match, prepend it to the path info.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
					if ( ! empty($req_uri) && strpos($match, $req_uri) === 0 && $req_uri != $request )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
						$request_match = $req_uri . '/' . $request;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
					if ( preg_match("#^$match#", $request_match, $matches) ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
						preg_match("#^$match#", urldecode($request_match), $matches) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
						if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   208
							// This is a verbose page match, let's check to be sure about it.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
							if ( ! get_page_by_path( $matches[ $varmatch[1] ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
						 		continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
						// Got a match.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
						$this->matched_rule = $match;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
						break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
			if ( isset( $this->matched_rule ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
				// Trim the query of everything up to the '?'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
				$query = preg_replace("!^.+\?!", '', $query);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
				// Substitute the substring matches into the query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
				$query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
				$this->matched_query = $query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
				// Parse the query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
				parse_str($query, $perma_query_vars);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
				// If we're processing a 404 request, clear the error var since we found something.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
				if ( '404' == $error )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
					unset( $error, $_GET['error'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
			// If req_uri is empty or if it is a request for ourself, unset error.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
			if ( empty($request) || $req_uri == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
				unset( $error, $_GET['error'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
				if ( isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
					unset( $perma_query_vars );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
				$this->did_permalink = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   248
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   249
		 * Filter the query variables whitelist before processing.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   250
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   251
		 * Allows (publicly allowed) query vars to be added, removed, or changed prior
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   252
		 * to executing the query. Needed to allow custom rewrite rules using your own arguments
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   253
		 * to work, or any other custom query variables you want to be publicly available.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   254
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   255
		 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   256
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   257
		 * @param array $public_query_vars The array of whitelisted query variables.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   258
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   259
		$this->public_query_vars = apply_filters( 'query_vars', $this->public_query_vars );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
		foreach ( get_post_types( array(), 'objects' ) as $post_type => $t )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
			if ( $t->query_var )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
				$post_type_query_vars[$t->query_var] = $post_type;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
		foreach ( $this->public_query_vars as $wpvar ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
			if ( isset( $this->extra_query_vars[$wpvar] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
				$this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
			elseif ( isset( $_POST[$wpvar] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
				$this->query_vars[$wpvar] = $_POST[$wpvar];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
			elseif ( isset( $_GET[$wpvar] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
				$this->query_vars[$wpvar] = $_GET[$wpvar];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
			elseif ( isset( $perma_query_vars[$wpvar] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
				$this->query_vars[$wpvar] = $perma_query_vars[$wpvar];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
			if ( !empty( $this->query_vars[$wpvar] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
				if ( ! is_array( $this->query_vars[$wpvar] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
					$this->query_vars[$wpvar] = (string) $this->query_vars[$wpvar];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
					foreach ( $this->query_vars[$wpvar] as $vkey => $v ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
						if ( !is_object( $v ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
							$this->query_vars[$wpvar][$vkey] = (string) $v;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
				if ( isset($post_type_query_vars[$wpvar] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
					$this->query_vars['post_type'] = $post_type_query_vars[$wpvar];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
					$this->query_vars['name'] = $this->query_vars[$wpvar];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
		// Convert urldecoded spaces back into +
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
		foreach ( get_taxonomies( array() , 'objects' ) as $taxonomy => $t )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
			if ( $t->query_var && isset( $this->query_vars[$t->query_var] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
				$this->query_vars[$t->query_var] = str_replace( ' ', '+', $this->query_vars[$t->query_var] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
		// Limit publicly queried post_types to those that are publicly_queryable
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
		if ( isset( $this->query_vars['post_type']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
			$queryable_post_types = get_post_types( array('publicly_queryable' => true) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
			if ( ! is_array( $this->query_vars['post_type'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
				if ( ! in_array( $this->query_vars['post_type'], $queryable_post_types ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
					unset( $this->query_vars['post_type'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
				$this->query_vars['post_type'] = array_intersect( $this->query_vars['post_type'], $queryable_post_types );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
		foreach ( (array) $this->private_query_vars as $var) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
			if ( isset($this->extra_query_vars[$var]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
				$this->query_vars[$var] = $this->extra_query_vars[$var];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
		if ( isset($error) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
			$this->query_vars['error'] = $error;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   317
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   318
		 * Filter the array of parsed query variables.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   319
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   320
		 * @since 2.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   321
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   322
		 * @param array $query_vars The array of requested query variables.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   323
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   324
		$this->query_vars = apply_filters( 'request', $this->query_vars );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   326
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   327
		 * Fires once all query variables for the current request have been parsed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   328
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   329
		 * @since 2.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   330
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   331
		 * @param WP &$this Current WordPress environment instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   332
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   333
		do_action_ref_array( 'parse_request', array( &$this ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
	 * Send additional HTTP headers for caching, content type, etc.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
	 * Sets the X-Pingback header, 404 status (if 404), Content-type. If showing
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
	 * a feed, it will also send last-modified, etag, and 304 status if needed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   344
	public function send_headers() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
		$headers = array('X-Pingback' => get_bloginfo('pingback_url'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
		$status = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
		$exit_required = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
		if ( is_user_logged_in() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
			$headers = array_merge($headers, wp_get_nocache_headers());
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
		if ( ! empty( $this->query_vars['error'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
			$status = (int) $this->query_vars['error'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
			if ( 404 === $status ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
				if ( ! is_user_logged_in() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
					$headers = array_merge($headers, wp_get_nocache_headers());
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
				$headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
			} elseif ( in_array( $status, array( 403, 500, 502, 503 ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
				$exit_required = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
			}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   360
		} elseif ( empty( $this->query_vars['feed'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
			$headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
			// We're showing a feed, so WP is indeed the only thing that last changed
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
			if ( !empty($this->query_vars['withcomments'])
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
				|| false !== strpos( $this->query_vars['feed'], 'comments-' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
				|| ( empty($this->query_vars['withoutcomments'])
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
					&& ( !empty($this->query_vars['p'])
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
						|| !empty($this->query_vars['name'])
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
						|| !empty($this->query_vars['page_id'])
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
						|| !empty($this->query_vars['pagename'])
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
						|| !empty($this->query_vars['attachment'])
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
						|| !empty($this->query_vars['attachment_id'])
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
					)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
				)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
			)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
				$wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastcommentmodified('GMT'), 0).' GMT';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
				$wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0).' GMT';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
			$wp_etag = '"' . md5($wp_last_modified) . '"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
			$headers['Last-Modified'] = $wp_last_modified;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
			$headers['ETag'] = $wp_etag;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
			// Support for Conditional GET
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
			if (isset($_SERVER['HTTP_IF_NONE_MATCH']))
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
				$client_etag = wp_unslash( $_SERVER['HTTP_IF_NONE_MATCH'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
			else $client_etag = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
			$client_last_modified = empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? '' : trim($_SERVER['HTTP_IF_MODIFIED_SINCE']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
			// If string is empty, return 0. If not, attempt to parse into a timestamp
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
			$client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
			// Make a timestamp for our most recent modification...
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
			$wp_modified_timestamp = strtotime($wp_last_modified);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
			if ( ($client_last_modified && $client_etag) ?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
					 (($client_modified_timestamp >= $wp_modified_timestamp) && ($client_etag == $wp_etag)) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
					 (($client_modified_timestamp >= $wp_modified_timestamp) || ($client_etag == $wp_etag)) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
				$status = 304;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
				$exit_required = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   403
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   404
		 * Filter the HTTP headers before they're sent to the browser.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   405
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   406
		 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   407
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   408
		 * @param array $headers The list of headers to be sent.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   409
		 * @param WP    $this    Current WordPress environment instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   410
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   411
		$headers = apply_filters( 'wp_headers', $headers, $this );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
		if ( ! empty( $status ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
			status_header( $status );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
		// If Last-Modified is set to false, it should not be sent (no-cache situation).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
		if ( isset( $headers['Last-Modified'] ) && false === $headers['Last-Modified'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
			unset( $headers['Last-Modified'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
			// In PHP 5.3+, make sure we are not sending a Last-Modified header.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
			if ( function_exists( 'header_remove' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
				@header_remove( 'Last-Modified' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
				// In PHP 5.2, send an empty Last-Modified header, but only as a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
				// last resort to override a header already sent. #WP23021
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
				foreach ( headers_list() as $header ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
					if ( 0 === stripos( $header, 'Last-Modified' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
						$headers['Last-Modified'] = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
						break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
		foreach( (array) $headers as $name => $field_value )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
			@header("{$name}: {$field_value}");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
		if ( $exit_required )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
			exit();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   441
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   442
		 * Fires once the requested HTTP headers for caching, content type, etc. have been sent.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   443
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   444
		 * @since 2.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   445
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   446
		 * @param WP &$this Current WordPress environment instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   447
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   448
		do_action_ref_array( 'send_headers', array( &$this ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
	 * Sets the query string property based off of the query variable property.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
	 * The 'query_string' filter is deprecated, but still works. Plugins should
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
	 * use the 'request' filter instead.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   459
	public function build_query_string() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
		$this->query_string = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
		foreach ( (array) array_keys($this->query_vars) as $wpvar) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
			if ( '' != $this->query_vars[$wpvar] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
				$this->query_string .= (strlen($this->query_string) < 1) ? '' : '&';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
				if ( !is_scalar($this->query_vars[$wpvar]) ) // Discard non-scalars.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
					continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
				$this->query_string .= $wpvar . '=' . rawurlencode($this->query_vars[$wpvar]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   470
		if ( has_filter( 'query_string' ) ) {  // Don't bother filtering and parsing if no plugins are hooked in.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   471
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   472
			 * Filter the query string before parsing.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   473
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   474
			 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   475
			 * @deprecated 2.1.0 Use 'query_vars' or 'request' filters instead.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   476
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   477
			 * @param string $query_string The query string to modify.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   478
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   479
			$this->query_string = apply_filters( 'query_string', $this->query_string );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
			parse_str($this->query_string, $this->query_vars);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
	 * Set up the WordPress Globals.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
	 * The query_vars property will be extracted to the GLOBALS. So care should
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
	 * be taken when naming global variables that might interfere with the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
	 * WordPress environment.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
	 * @global string $query_string Query string for the loop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
	 * @global array $posts The found posts.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
	 * @global WP_Post|null $post The current post, if available.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
	 * @global string $request The SQL statement for the request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
	 * @global int $more Only set, if single page or post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
	 * @global int $single If single page or post. Only set, if single page or post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
	 * @global WP_User $authordata Only set, if author archive.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   501
	public function register_globals() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
		global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
		// Extract updated query vars back into global namespace.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
		foreach ( (array) $wp_query->query_vars as $key => $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
			$GLOBALS[ $key ] = $value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
		$GLOBALS['query_string'] = $this->query_string;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
		$GLOBALS['posts'] = & $wp_query->posts;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
		$GLOBALS['post'] = isset( $wp_query->post ) ? $wp_query->post : null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
		$GLOBALS['request'] = $wp_query->request;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
		if ( $wp_query->is_single() || $wp_query->is_page() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
			$GLOBALS['more']   = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
			$GLOBALS['single'] = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
		if ( $wp_query->is_author() && isset( $wp_query->post ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
			$GLOBALS['authordata'] = get_userdata( $wp_query->post->post_author );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
	 * Set up the current user.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   528
	public function init() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
		wp_get_current_user();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
	 * Set up the Loop based on the query variables.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   537
	public function query_posts() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
		global $wp_the_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
		$this->build_query_string();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
		$wp_the_query->query($this->query_vars);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
 	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
 	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   544
	 * Set the Headers for 404, if nothing is found for requested URL.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
	 * Issue a 404 if a request doesn't match any posts and doesn't match
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
	 * any object (e.g. an existing-but-empty category, tag, author) and a 404 was not already
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
	 * issued, and if the request was not a search or the homepage.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
	 * Otherwise, issue a 200.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
 	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   554
	public function handle_404() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
		global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
		// If we've already issued a 404, bail.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
		if ( is_404() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
		// Never 404 for the admin, robots, or if we found posts.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
		if ( is_admin() || is_robots() || $wp_query->posts ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
			status_header( 200 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
		// We will 404 for paged queries, as no posts were found.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
		if ( ! is_paged() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   570
			// Don't 404 for authors without posts as long as they matched an author on this site.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   571
			$author = get_query_var( 'author' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   572
			if ( is_author() && is_numeric( $author ) && $author > 0 && is_user_member_of_blog( $author ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   573
				status_header( 200 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   574
				return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   575
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   576
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
			// Don't 404 for these queries if they matched an object.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   578
			if ( ( is_tag() || is_category() || is_tax() || is_post_type_archive() ) && get_queried_object() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
				status_header( 200 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
			// Don't 404 for these queries either.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   584
			if ( is_home() || is_search() || is_feed() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
				status_header( 200 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
		// Guess it's time to 404.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
		$wp_query->set_404();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
		status_header( 404 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
		nocache_headers();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
	 * Sets up all of the variables required by the WordPress environment.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
	 * The action 'wp' has one parameter that references the WP object. It
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
	 * allows for accessing the properties and methods to further manipulate the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
	 * object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
	 * @param string|array $query_args Passed to {@link parse_request()}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   607
	public function main($query_args = '') {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
		$this->init();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
		$this->parse_request($query_args);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
		$this->send_headers();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
		$this->query_posts();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
		$this->handle_404();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
		$this->register_globals();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   614
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   615
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   616
		 * Fires once the WordPress environment has been set up.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   617
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   618
		 * @since 2.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   619
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   620
		 * @param WP &$this Current WordPress environment instance (passed by reference).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   621
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   622
		do_action_ref_array( 'wp', array( &$this ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
 * Helper class to remove the need to use eval to replace $matches[] in query strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
class WP_MatchesMapRegex {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
	 * store for matches
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   639
	private $_matches;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
	 * store for mapping result
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   647
	public $output;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
	 * subject to perform mapping on (query string containing $matches[] references
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   655
	private $_subject;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
	 * regexp pattern to match $matches[] references
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   662
	public $_pattern = '(\$matches\[[1-9]+[0-9]*\])'; // magic number
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
	 * constructor
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
	 * @param string $subject subject if regex
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
	 * @param array  $matches data to use in map
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   670
	public function __construct($subject, $matches) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
		$this->_subject = $subject;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
		$this->_matches = $matches;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
		$this->output = $this->_map();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
	 * Substitute substring matches in subject.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
	 * static helper function to ease use
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
	 * @param string $subject subject
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
	 * @param array  $matches data used for substitution
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
	 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
	public static function apply($subject, $matches) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
		$oSelf = new WP_MatchesMapRegex($subject, $matches);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
		return $oSelf->output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
	 * do the actual mapping
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
	 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   697
	private function _map() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
		$callback = array($this, 'callback');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
		return preg_replace_callback($this->_pattern, $callback, $this->_subject);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
	 * preg_replace_callback hook
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
	 * @param  array $matches preg_replace regexp matches
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
	 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   709
	public function callback($matches) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
		$index = intval(substr($matches[0], 9, -1));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
		return ( isset( $this->_matches[$index] ) ? urlencode($this->_matches[$index]) : '' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
}