Changeset 881
- Timestamp:
- 02/17/2004 02:50:57 AM (22 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
wp-blog-header.php (modified) (2 diffs)
-
wp-includes/functions.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-blog-header.php
r863 r881 10 10 11 11 require($curpath.'/wp-config.php'); 12 13 /* Process PATH_INFO, if set. */ 14 $path_info = array(); 15 if (! empty($_SERVER['PATH_INFO'])) { 16 // Fetch the rewrite rules. 17 $rewrite = rewrite_rules('matches'); 18 19 $pathinfo = $_SERVER['PATH_INFO']; 20 // Trim leading '/'. 21 $pathinfo = preg_replace("!^/!", '', $pathinfo); 22 23 if (! empty($rewrite)) { 24 // Get the name of the file requesting path info. 25 $req_uri = $HTTP_SERVER_VARS['REQUEST_URI']; 26 $req_uri = str_replace($pathinfo, '', $req_uri); 27 $req_uri = preg_replace("!/+$!", '', $req_uri); 28 $req_uri = explode('/', $req_uri); 29 $req_uri = $req_uri[count($req_uri)-1]; 30 31 // Look for matches. 32 $pathinfomatch = $pathinfo; 33 foreach ($rewrite as $match => $query) { 34 // If the request URI is the anchor of the match, prepend it 35 // to the path info. 36 if (preg_match("!^$req_uri!", $match)) { 37 $pathinfomatch = $req_uri . '/' . $pathinfo; 38 } 39 40 if (preg_match("!^$match!", $pathinfomatch, $matches)) { 41 // Got a match. 42 // Trim the query of everything up to the '?'. 43 $query = preg_replace("!^.+\?!", '', $query); 44 45 // Substitute the substring matches into the query. 46 eval("\$query = \"$query\";"); 47 48 // Parse the query. 49 parse_str($query, $path_info); 50 } 51 } 52 } 53 } 12 54 13 55 $wpvarstoreset = array('m','p','posts','w', 'cat','withcomments','s','search','exact', 'sentence','poststart','postend','preview','debug', 'calendar','page','paged','more','tb', 'pb','author','order','orderby', 'year', 'monthnum', 'day', 'name', 'category_name', 'feed', 'author_name'); … … 17 59 if (!isset($$wpvar)) { 18 60 if (empty($HTTP_POST_VARS[$wpvar])) { 19 if (empty($HTTP_GET_VARS[$wpvar]) ) {61 if (empty($HTTP_GET_VARS[$wpvar]) && empty($path_info[$wpvar])) { 20 62 $$wpvar = ''; 63 } elseif (!empty($HTTP_GET_VARS[$wpvar])) { 64 $$wpvar = $HTTP_GET_VARS[$wpvar]; 21 65 } else { 22 $$wpvar = $ HTTP_GET_VARS[$wpvar];66 $$wpvar = $path_info[$wpvar]; 23 67 } 24 68 } else { -
trunk/wp-includes/functions.php
r870 r881 1331 1331 } 1332 1332 1333 /* rewrite_rules 1334 * Construct rewrite matches and queries from permalink structure. 1335 * matches - The name of the match array to use in the query strings. 1336 * If empty, $1, $2, $3, etc. are used. 1337 * Returns an associate array of matches and queries. 1338 */ 1339 function rewrite_rules($matches = '') { 1340 1341 function preg_index($number, $matches = '') { 1342 $match_prefix = '$'; 1343 $match_suffix = ''; 1344 1345 if (! empty($matches)) { 1346 $match_prefix = '$' . $matches . '['; 1347 $match_suffix = ']'; 1348 } 1349 1350 return "$match_prefix$number$match_suffix"; 1351 } 1352 1353 $rewrite = array(); 1354 1355 $permalink_structure = get_settings('permalink_structure'); 1356 1357 if (empty($permalink_structure)) { 1358 return $rewrite; 1359 } 1360 1361 $rewritecode = array( 1362 '%year%', 1363 '%monthnum%', 1364 '%day%', 1365 '%postname%', 1366 '%post_id%' 1367 ); 1368 1369 $rewritereplace = array( 1370 '([0-9]{4})?', 1371 '([0-9]{1,2})?', 1372 '([0-9]{1,2})?', 1373 '([0-9a-z-]+)?', 1374 '([0-9]+)?' 1375 ); 1376 1377 $queryreplace = array ( 1378 'year=', 1379 'monthnum=', 1380 'day=', 1381 'name=', 1382 'p=' 1383 ); 1384 1385 1386 $match = str_replace('/', '/?', $permalink_structure); 1387 $match = preg_replace('|/[?]|', '', $match, 1); 1388 1389 $match = str_replace($rewritecode, $rewritereplace, $match); 1390 $match = preg_replace('|[?]|', '', $match, 1); 1391 1392 $feedmatch = str_replace('?/?', '/', $match); 1393 $trackbackmatch = $feedmatch; 1394 1395 preg_match_all('/%.+?%/', $permalink_structure, $tokens); 1396 1397 $query = 'index.php?'; 1398 $feedquery = 'wp-feed.php?'; 1399 $trackbackquery = 'wp-trackback.php?'; 1400 for ($i = 0; $i < count($tokens[0]); ++$i) { 1401 if (0 < $i) { 1402 $query .= '&'; 1403 $feedquery .= '&'; 1404 $trackbackquery .= '&'; 1405 } 1406 1407 $query_token = str_replace($rewritecode, $queryreplace, $tokens[0][$i]) . preg_index($i+1, $matches); 1408 $query .= $query_token; 1409 $feedquery .= $query_token; 1410 $trackbackquery .= $query_token; 1411 } 1412 ++$i; 1413 1414 // Add post paged stuff 1415 $match .= '([0-9]+)?/?'; 1416 $query .= '&page=' . preg_index($i, $matches); 1417 1418 // Add post feed stuff 1419 $feedregex = '(feed|rdf|rss|rss2|atom)/?'; 1420 $feedmatch .= $feedregex; 1421 $feedquery .= '&feed=' . preg_index($i, $matches); 1422 1423 // Add post trackback stuff 1424 $trackbackregex = 'trackback/?'; 1425 $trackbackmatch .= $trackbackregex; 1426 1427 // Site feed 1428 $sitefeedmatch = 'feed/?([0-9a-z-]+)?/?$'; 1429 $sitefeedquery = $site_root . 'wp-feed.php?feed=' . preg_index(1, $matches); 1430 1431 // Site comment feed 1432 $sitecommentfeedmatch = 'comments/feed/?([0-9a-z-]+)?/?$'; 1433 $sitecommentfeedquery = $site_root . 'wp-feed.php?feed=' . preg_index(1, $matches) . '&withcomments=1'; 1434 1435 // Code for nice categories and authors, currently not very flexible 1436 $front = substr($permalink_structure, 0, strpos($permalink_structure, '%')); 1437 $catmatch = $front . 'category/'; 1438 $catmatch = preg_replace('|^/+|', '', $catmatch); 1439 1440 $catfeedmatch = $catmatch . '(.*)/' . $feedregex; 1441 $catfeedquery = 'wp-feed.php?category_name=' . preg_index(1, $matches) . '&feed=' . preg_index(2, $matches); 1442 1443 $catmatch = $catmatch . '?(.*)'; 1444 $catquery = 'index.php?category_name=' . preg_index(1, $matches); 1445 1446 $authormatch = $front . 'author/'; 1447 $authormatch = preg_replace('|^/+|', '', $authormatch); 1448 1449 $authorfeedmatch = $authormatch . '(.*)/' . $feedregex; 1450 $authorfeedquery = 'wp-feed.php?author_name=' . preg_index(1, $matches) . '&feed=' . preg_index(2, $matches); 1451 1452 $authormatch = $authormatch . '?(.*)'; 1453 $authorquery = 'index.php?author_name=' . preg_index(1, $matches); 1454 1455 $rewrite = array( 1456 $catfeedmatch => $catfeedquery, 1457 $catmatch => $catquery, 1458 $authorfeedmatch => $authorfeedquery, 1459 $authormatch => $authorquery, 1460 $match => $query, 1461 $feedmatch => $feedquery, 1462 $trackbackmatch => $tracbackquery, 1463 $sitefeedmatch => $sitefeedquery, 1464 $sitecommentfeedmatch => $sitecommentfeedquery 1465 ); 1466 1467 return $rewrite; 1468 } 1469 1333 1470 ?>
Note: See TracChangeset
for help on using the changeset viewer.