Changeset 2627 for trunk/wp-includes/classes.php
- Timestamp:
- 06/10/2005 11:15:13 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/classes.php
r2535 r2627 662 662 } 663 663 } 664 }665 666 // Make a global instance.667 if (! isset($wp_query)) {668 $wp_query = new WP_Query();669 664 } 670 665 … … 1292 1287 } 1293 1288 1294 // Make a global instance. 1295 if (! isset($wp_rewrite)) { 1296 $wp_rewrite = new WP_Rewrite(); 1289 class WP { 1290 var $public_query_vars = 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'); 1291 1292 var $private_query_vars = array('posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging'); 1293 1294 var $query_vars; 1295 var $query_string; 1296 var $did_permalink = false; 1297 1298 function parse_request($extra_query_vars = '') { 1299 global $wp_rewrite; 1300 1301 $this->query_vars = array(); 1302 1303 if (! empty($extra_query_vars)) 1304 parse_str($extra_query_vars, $extra_query_vars); 1305 1306 // Process PATH_INFO and 404. 1307 if ((isset($_GET['error']) && $_GET['error'] == '404') || 1308 ((! empty($_SERVER['PATH_INFO'])) && 1309 ('/' != $_SERVER['PATH_INFO']) && 1310 (false === strpos($_SERVER['PATH_INFO'], '.php')) 1311 )) { 1312 1313 $this->did_permalink = true; 1314 1315 // If we match a rewrite rule, this will be cleared. 1316 $error = '404'; 1317 1318 // Fetch the rewrite rules. 1319 $rewrite = $wp_rewrite->wp_rewrite_rules(); 1320 1321 if (! empty($rewrite)) { 1322 $pathinfo = $_SERVER['PATH_INFO']; 1323 $req_uri = $_SERVER['REQUEST_URI']; 1324 $home_path = parse_url(get_settings('home')); 1325 $home_path = $home_path['path']; 1326 1327 // Trim path info from the end and the leading home path from the 1328 // front. For path info requests, this leaves us with the requesting 1329 // filename, if any. For 404 requests, this leaves us with the 1330 // requested permalink. 1331 $req_uri = str_replace($pathinfo, '', $req_uri); 1332 $req_uri = str_replace($home_path, '', $req_uri); 1333 $req_uri = trim($req_uri, '/'); 1334 $pathinfo = trim($pathinfo, '/'); 1335 1336 // The requested permalink is in $pathinfo for path info requests and 1337 // $req_uri for other requests. 1338 if (! empty($pathinfo)) { 1339 $request = $pathinfo; 1340 } else { 1341 $request = $req_uri; 1342 } 1343 1344 // Look for matches. 1345 $request_match = $request; 1346 foreach ($rewrite as $match => $query) { 1347 // If the requesting file is the anchor of the match, prepend it 1348 // to the path info. 1349 if ((! empty($req_uri)) && (strpos($match, $req_uri) === 0)) { 1350 $request_match = $req_uri . '/' . $request; 1351 } 1352 1353 if (preg_match("!^$match!", $request_match, $matches)) { 1354 // Got a match. 1355 // Trim the query of everything up to the '?'. 1356 $query = preg_replace("!^.+\?!", '', $query); 1357 1358 // Substitute the substring matches into the query. 1359 eval("\$query = \"$query\";"); 1360 1361 // Parse the query. 1362 parse_str($query, $query_vars); 1363 1364 // If we're processing a 404 request, clear the error var 1365 // since we found something. 1366 if (isset($_GET['error'])) { 1367 unset($_GET['error']); 1368 } 1369 1370 if (isset($error)) { 1371 unset($error); 1372 } 1373 1374 break; 1375 } 1376 } 1377 } 1378 } 1379 1380 $this->public_query_vars = apply_filters('query_vars', $this->public_query_vars); 1381 1382 for ($i=0; $i<count($this->public_query_vars); $i += 1) { 1383 $wpvar = $this->public_query_vars[$i]; 1384 if (isset($extra_query_vars[$wpvar])) 1385 $this->query_vars[$wpvar] = $extra_query_vars[$wpvar]; 1386 elseif (isset($GLOBALS[$wpvar])) 1387 $this->query_vars[$wpvar] = $GLOBALS[$wpvar]; 1388 elseif (!empty($_POST[$wpvar])) 1389 $this->query_vars[$wpvar] = $_POST[$wpvar]; 1390 elseif (!empty($_GET[$wpvar])) 1391 $this->query_vars[$wpvar] = $_GET[$wpvar]; 1392 elseif (!empty($query_vars[$wpvar])) 1393 $this->query_vars[$wpvar] = $query_vars[$wpvar]; 1394 else 1395 $this->query_vars[$wpvar] = ''; 1396 } 1397 } 1398 1399 function send_headers() { 1400 @header('X-Pingback: '. get_bloginfo('pingback_url')); 1401 if ( !empty($this->query_vars['error']) && '404' == $this->query_vars['error'] ) { 1402 status_header( 404 ); 1403 } else if ( empty($this->query_vars['feed']) ) { 1404 @header('Content-type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); 1405 } else { 1406 // We're showing a feed, so WP is indeed the only thing that last changed 1407 if ( $this->query_vars['withcomments'] ) 1408 $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastcommentmodified('GMT'), 0).' GMT'; 1409 else 1410 $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0).' GMT'; 1411 $wp_etag = '"' . md5($wp_last_modified) . '"'; 1412 @header("Last-Modified: $wp_last_modified"); 1413 @header("ETag: $wp_etag"); 1414 1415 // Support for Conditional GET 1416 if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) $client_etag = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']); 1417 else $client_etag = false; 1418 1419 $client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE']); 1420 // If string is empty, return 0. If not, attempt to parse into a timestamp 1421 $client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0; 1422 1423 // Make a timestamp for our most recent modification... 1424 $wp_modified_timestamp = strtotime($wp_last_modified); 1425 1426 if ( ($client_last_modified && $client_etag) ? 1427 (($client_modified_timestamp >= $wp_modified_timestamp) && ($client_etag == $wp_etag)) : 1428 (($client_modified_timestamp >= $wp_modified_timestamp) || ($client_etag == $wp_etag)) ) { 1429 status_header( 304 ); 1430 exit; 1431 } 1432 } 1433 } 1434 1435 function build_query_string() { 1436 $this->query_string = ''; 1437 1438 foreach ($this->public_query_vars as $wpvar) { 1439 if (isset($this->query_vars[$wpvar]) && '' != $this->query_vars[$wpvar]) { 1440 $this->query_string .= (strlen($this->query_string) < 1) ? '' : '&'; 1441 $this->query_string .= $wpvar . '=' . rawurlencode($this->query_vars[$wpvar]); 1442 } 1443 } 1444 1445 foreach ($this->private_query_vars as $wpvar) { 1446 if (isset($GLOBALS[$wpvar]) && '' != $GLOBALS[$wpvar]) { 1447 $this->query_string .= (strlen($this->query_string) < 1) ? '' : '&'; 1448 $this->query_string .= $wpvar . '=' . rawurlencode($GLOBALS[$wpvar]); 1449 } 1450 } 1451 1452 $this->query_string = apply_filters('query_string', $this->query_string); 1453 } 1454 1455 function register_globals() { 1456 global $wp_query; 1457 // Extract updated query vars back into global namespace. 1458 foreach ($wp_query->query_vars as $key => $value) { 1459 $GLOBALS[$key] = $value; 1460 } 1461 1462 $GLOBALS['query_string'] = & $this->query_string; 1463 $GLOBALS['posts'] = & $wp_query->posts; 1464 $GLOBALS['post'] = & $wp_query->post; 1465 1466 if ( is_single() || is_page() ) { 1467 $GLOBALS['more'] = 1; 1468 $GLOBALS['single'] = 1; 1469 } 1470 } 1471 1472 function prime_caches() { 1473 update_category_cache(); 1474 get_currentuserinfo(); 1475 } 1476 1477 function query_posts() { 1478 $this->build_query_string(); 1479 query_posts($this->query_string); 1480 } 1481 1482 function handle_404() { 1483 global $wp_query; 1484 // Issue a 404 if a permalink request doesn't match any posts. Don't 1485 // issue a 404 if one was already issued, if the request was a search, 1486 // or if the request was a regular query string request rather than a 1487 // permalink request. 1488 if ( (0 == count($wp_query->posts)) && !is_404() && !is_search() 1489 && ( $this->did_permalink || (!empty($_SERVER['QUERY_STRING']) && 1490 (false === strpos($_SERVER['REQUEST_URI'], '?'))) ) ) { 1491 $wp_query->is_404 = true; 1492 status_header( 404 ); 1493 } else { 1494 status_header( 200 ); 1495 } 1496 } 1497 1498 function main($query_args = '') { 1499 $this->parse_request($query_args); 1500 $this->send_headers(); 1501 $this->prime_caches(); 1502 $this->query_posts(); 1503 $this->handle_404(); 1504 $this->register_globals(); 1505 } 1506 1507 function WP() { 1508 // Empty. 1509 } 1297 1510 } 1298 1511
Note: See TracChangeset
for help on using the changeset viewer.