Changeset 2627 for trunk/wp-blog-header.php
- Timestamp:
- 06/10/2005 11:15:13 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-blog-header.php
r2623 r2627 12 12 require_once( dirname(__FILE__) . '/wp-config.php'); 13 13 14 $query_vars = array(); 14 wp(); 15 gzip_compression(); 15 16 16 // Process PATH_INFO and 404. 17 if ((isset($_GET['error']) && $_GET['error'] == '404') || 18 ((! empty($_SERVER['PATH_INFO'])) && 19 ('/' != $_SERVER['PATH_INFO']) && 20 (false === strpos($_SERVER['PATH_INFO'], '.php')) 21 )) { 22 23 // If we match a rewrite rule, this will be cleared. 24 $error = '404'; 25 26 // Fetch the rewrite rules. 27 $rewrite = $wp_rewrite->wp_rewrite_rules(); 28 29 if (! empty($rewrite)) { 30 $pathinfo = $_SERVER['PATH_INFO']; 31 $req_uri = $_SERVER['REQUEST_URI']; 32 $home_path = parse_url(get_settings('home')); 33 $home_path = $home_path['path']; 34 35 // Trim path info from the end and the leading home path from the 36 // front. For path info requests, this leaves us with the requesting 37 // filename, if any. For 404 requests, this leaves us with the 38 // requested permalink. 39 $req_uri = str_replace($pathinfo, '', $req_uri); 40 $req_uri = str_replace($home_path, '', $req_uri); 41 $req_uri = trim($req_uri, '/'); 42 $pathinfo = trim($pathinfo, '/'); 43 44 // The requested permalink is in $pathinfo for path info requests and 45 // $req_uri for other requests. 46 if (! empty($pathinfo)) { 47 $request = $pathinfo; 48 } else { 49 $request = $req_uri; 50 } 51 52 // Look for matches. 53 $request_match = $request; 54 foreach ($rewrite as $match => $query) { 55 // If the requesting file is the anchor of the match, prepend it 56 // to the path info. 57 if ((! empty($req_uri)) && (strpos($match, $req_uri) === 0)) { 58 $request_match = $req_uri . '/' . $request; 59 } 60 61 if (preg_match("!^$match!", $request_match, $matches)) { 62 // Got a match. 63 // Trim the query of everything up to the '?'. 64 $query = preg_replace("!^.+\?!", '', $query); 65 66 // Substitute the substring matches into the query. 67 eval("\$query = \"$query\";"); 68 69 // Parse the query. 70 parse_str($query, $query_vars); 71 72 // If we're processing a 404 request, clear the error var 73 // since we found something. 74 if (isset($_GET['error'])) { 75 unset($_GET['error']); 76 } 77 78 if (isset($error)) { 79 unset($error); 80 } 81 82 break; 83 } 84 } 85 } 86 } 87 88 $wpvarstoreset = array('m','p','posts','w', 'cat','withcomments','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'); 89 90 $wpvarstoreset = apply_filters('query_vars', $wpvarstoreset); 91 92 for ($i=0; $i<count($wpvarstoreset); $i += 1) { 93 $wpvar = $wpvarstoreset[$i]; 94 if (!isset($$wpvar)) { 95 if (empty($_POST[$wpvar])) { 96 if (empty($_GET[$wpvar]) && empty($query_vars[$wpvar])) { 97 $$wpvar = ''; 98 } elseif (!empty($_GET[$wpvar])) { 99 $$wpvar = $_GET[$wpvar]; 100 } else { 101 $$wpvar = $query_vars[$wpvar]; 102 } 103 } else { 104 $$wpvar = $_POST[$wpvar]; 105 } 106 } 107 } 108 109 // Sending HTTP headers 110 @header('X-Pingback: '. get_bloginfo('pingback_url')); 111 112 if ( !empty($error) && '404' == $error ) { 113 status_header( 404 ); 114 } else if ( empty($feed) ) { 115 @header('Content-type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); 116 } else { 117 // We're showing a feed, so WP is indeed the only thing that last changed 118 if ( $withcomments ) 119 $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastcommentmodified('GMT'), 0).' GMT'; 120 else 121 $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0).' GMT'; 122 $wp_etag = '"' . md5($wp_last_modified) . '"'; 123 @header("Last-Modified: $wp_last_modified"); 124 @header("ETag: $wp_etag"); 125 126 // Support for Conditional GET 127 if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) $client_etag = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']); 128 else $client_etag = false; 129 130 $client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE']); 131 // If string is empty, return 0. If not, attempt to parse into a timestamp 132 $client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0; 133 134 // Make a timestamp for our most recent modification... 135 $wp_modified_timestamp = strtotime($wp_last_modified); 136 137 if ( ($client_last_modified && $client_etag) ? 138 (($client_modified_timestamp >= $wp_modified_timestamp) && ($client_etag == $wp_etag)) : 139 (($client_modified_timestamp >= $wp_modified_timestamp) || ($client_etag == $wp_etag)) ) { 140 status_header( 304 ); 141 exit; 142 } 143 } 144 145 $use_gzipcompression = get_settings('gzipcompression'); 146 147 $more_wpvars = array('posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging'); 148 149 // Construct the query string. 150 $query_string = ''; 151 foreach (array_merge($wpvarstoreset, $more_wpvars) as $wpvar) { 152 if ($$wpvar != '') { 153 $query_string .= (strlen($query_string) < 1) ? '' : '&'; 154 $query_string .= $wpvar . '=' . rawurlencode($$wpvar); 155 } 156 } 157 158 $query_string = apply_filters('query_string', $query_string); 159 160 update_category_cache(); 161 get_currentuserinfo(); 162 163 // Call query posts to do the work. 164 $posts = & query_posts($query_string); 165 166 // Extract updated query vars back into global namespace. 167 extract($wp_query->query_vars); 168 169 if ( is_single() || is_page() ) { 170 $more = 1; 171 $single = 1; 172 } 173 174 // Issue a 404 if a permalink request doesn't match any posts. Don't issue a 175 // 404 if one was already issued, if the request was a search, or if the 176 // request was a regular query string request rather than a permalink request. 177 if ( (0 == count($posts)) && !is_404() && !is_search() 178 && ( isset($rewrite) || (!empty($_SERVER['QUERY_STRING']) && 179 (false === strpos($_SERVER['REQUEST_URI'], '?'))) ) ) { 180 $wp_query->is_404 = true; 181 status_header( 404 ); 182 } else { 183 status_header( 200 ); 184 } 185 186 if ($pagenow != 'post.php' && $pagenow != 'edit.php') { 187 if ( get_settings('gzipcompression') ) 188 gzip_compression(); 189 } 190 191 // Template redirection 192 if ( defined('WP_USE_THEMES') && constant('WP_USE_THEMES') ) { 193 do_action('template_redirect'); 194 if ( is_feed() && empty($doing_rss) ) { 195 include(ABSPATH . '/wp-feed.php'); 196 exit; 197 } else if ( is_trackback() && empty($doing_trackback) ) { 198 include(ABSPATH . '/wp-trackback.php'); 199 exit; 200 } else if ( is_404() && get_404_template() ) { 201 include(get_404_template()); 202 exit; 203 } else if ( is_search() && get_search_template() ) { 204 include(get_search_template()); 205 exit; 206 } else if ( is_home() && get_home_template() ) { 207 include(get_home_template()); 208 exit; 209 } else if ( is_single() && get_single_template() ) { 210 include(get_single_template()); 211 exit; 212 } else if ( is_page() && get_page_template() ) { 213 include(get_page_template()); 214 exit; 215 } else if ( is_category() && get_category_template()) { 216 include(get_category_template()); 217 exit; 218 } else if ( is_author() && get_author_template() ) { 219 include(get_author_template()); 220 exit; 221 } else if ( is_date() && get_date_template() ) { 222 include(get_date_template()); 223 exit; 224 } else if ( is_archive() && get_archive_template() ) { 225 include(get_archive_template()); 226 exit; 227 } else if ( is_comments_popup() && get_comments_popup_template() ) { 228 include(get_comments_popup_template()); 229 exit; 230 } else if ( is_paged() && get_paged_template() ) { 231 include(get_paged_template()); 232 exit; 233 } else if ( file_exists(TEMPLATEPATH . "/index.php") ) { 234 include(TEMPLATEPATH . "/index.php"); 235 exit; 236 } 237 } else { 238 // Process feeds and trackbacks even if not using themes. 239 if ( is_feed() && empty($doing_rss) ) { 240 include(ABSPATH . '/wp-feed.php'); 241 exit; 242 } else if ( is_trackback() && empty($doing_trackback) ) { 243 include(ABSPATH . '/wp-trackback.php'); 244 exit; 245 } 246 } 17 require_once(ABSPATH . WPINC . '/template-loader.php'); 247 18 248 19 endif;
Note: See TracChangeset
for help on using the changeset viewer.