Changeset 1373 for trunk/wp-includes/functions.php
- Timestamp:
- 05/31/2004 05:22:25 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.php
r1366 r1373 1207 1207 $rewritereplace = 1208 1208 array( 1209 '([0-9]{4}) ?',1210 '([0-9]{1,2}) ?',1211 '([0-9]{1,2}) ?',1212 '([0-9]{1,2}) ?',1213 '([0-9]{1,2}) ?',1214 '([0-9]{1,2}) ?',1215 '([_0-9a-z-]+) ?',1216 '([0-9]+) ?'1209 '([0-9]{4})', 1210 '([0-9]{1,2})', 1211 '([0-9]{1,2})', 1212 '([0-9]{1,2})', 1213 '([0-9]{1,2})', 1214 '([0-9]{1,2})', 1215 '([_0-9a-z-]+)', 1216 '([0-9]+)' 1217 1217 ); 1218 1218 … … 1229 1229 ); 1230 1230 1231 1232 $match = str_replace('/', '/?', $permalink_structure); 1233 $match = preg_replace('|/[?]|', '', $match, 1); 1234 1235 $match = str_replace($rewritecode, $rewritereplace, $match); 1236 $match = preg_replace('|[?]|', '', $match, 1); 1237 1238 $feedmatch = trailingslashit(str_replace('?/?', '/', $match)); 1239 $trackbackmatch = $feedmatch; 1240 1231 $feedregex = '(feed|rdf|rss|rss2|atom)/?$'; 1232 $trackbackregex = 'trackback/?$'; 1233 $pageregex = 'page/?([0-9]{1,})/?$'; 1234 1235 $front = substr($permalink_structure, 0, strpos($permalink_structure, '%')); 1241 1236 preg_match_all('/%.+?%/', $permalink_structure, $tokens); 1242 1237 1243 $query = 'index.php?'; 1244 $feedquery = 'wp-feed.php?'; 1245 $trackbackquery = 'wp-trackback.php?'; 1246 for ($i = 0; $i < count($tokens[0]); ++$i) { 1238 $num_tokens = count($tokens[0]); 1239 1240 $index = 'index.php'; 1241 $feedindex = 'wp-feed.php'; 1242 $trackbackindex = 'wp-trackback.php'; 1243 for ($i = 0; $i < $num_tokens; ++$i) { 1247 1244 if (0 < $i) { 1248 $query .= '&'; 1249 $feedquery .= '&'; 1250 $trackbackquery .= '&'; 1245 $queries[$i] = $queries[$i - 1] . '&'; 1251 1246 } 1252 1247 1253 1248 $query_token = str_replace($rewritecode, $queryreplace, $tokens[0][$i]) . preg_index($i+1, $matches); 1254 $query .= $query_token; 1255 $feedquery .= $query_token; 1256 $trackbackquery .= $query_token; 1249 $queries[$i] .= $query_token; 1257 1250 } 1258 ++$i; 1259 1260 // Add post paged stuff 1261 $match .= '([0-9]+)?/?$'; 1262 $query .= '&page=' . preg_index($i, $matches); 1263 1264 // Add post feed stuff 1265 $feedregex = '(feed|rdf|rss|rss2|atom)/?$'; 1266 $feedmatch .= $feedregex; 1267 $feedquery .= '&feed=' . preg_index($i, $matches); 1268 1269 // Add post trackback stuff 1270 $trackbackregex = 'trackback/?$'; 1271 $trackbackmatch .= $trackbackregex; 1251 1252 $structure = str_replace($front, '', $permalink_structure); 1253 $structure = trim($structure, '/'); 1254 $dirs = explode('/', $structure); 1255 $num_dirs = count($dirs); 1256 1257 $front = preg_replace('|^/+|', '', $front); 1258 1259 $post_rewrite = array(); 1260 $struct = $front; 1261 for ($j = 0; $j < $num_dirs; ++$j) { 1262 $struct .= $dirs[$j] . '/'; 1263 $match = str_replace($rewritecode, $rewritereplace, $struct); 1264 $num_toks = preg_match_all('/%.+?%/', $struct, $toks); 1265 $query = $queries[$num_toks - 1]; 1266 1267 $pagematch = $match . $pageregex; 1268 $pagequery = $index . '?' . $query . '&paged=' . preg_index($num_toks + 1, $matches); 1269 1270 $feedmatch = $match . $feedregex; 1271 $feedquery = $feedindex . '?' . $query . '&feed=' . preg_index($num_toks + 1, $matches); 1272 1273 $post = 0; 1274 if (strstr($struct, '%postname%') || strstr($struct, '%post_id%')) { 1275 $post = 1; 1276 $trackbackmatch = $match . $trackbackregex; 1277 $trackbackquery = $trackbackindex . '?' . $query; 1278 $match = $match . '?([0-9]+)?/?$'; 1279 $query = $index . '?' . $query . '&page=' . preg_index($num_toks + 1, $matches); 1280 } else { 1281 $match .= '?'; 1282 $query = $index . '?' . $query; 1283 } 1284 1285 $post_rewrite = array($feedmatch => $feedquery, $pagematch => $pagequery, $match => $query) + $post_rewrite; 1286 1287 if ($post) { 1288 $post_rewrite = array($trackbackmatch => $trackbackquery) + $post_rewrite; 1289 } 1290 } 1291 1292 // If the permalink does not have year, month, and day, we need to create a 1293 // separate archive rule. 1294 // TODO: Need to write separate rules for each component of the permalink. 1295 $doarchive = false; 1296 if (! (strstr($permalink_structure, '%year') && strstr($permalink_structure, '%monthnum') && strstr($permalink_structure, '%day')) ) { 1297 $doarchive = true; 1298 $archivematch = $front . '([0-9]{4})/?([0-9]{1,2})?/?([0-9]{1,2})?/?$'; 1299 $archivequery = 'index.php?year=' . preg_index(1, $matches) . '&monthnum=' . preg_index(2, $matches) . '&day=' . preg_index(3, $matches) ; 1300 } 1272 1301 1273 1302 // Site feed … … 1275 1304 $sitefeedquery = 'wp-feed.php?feed=' . preg_index(1, $matches); 1276 1305 1306 $sitepagematch = $pageregex; 1307 $sitepagequery = 'index.php?paged=' . preg_index(1, $matches); 1308 1277 1309 // Site comment feed 1278 1310 $sitecommentfeedmatch = 'comments/feed/?([_0-9a-z-]+)?/?$'; 1279 1311 $sitecommentfeedquery = 'wp-feed.php?feed=' . preg_index(1, $matches) . '&withcomments=1'; 1280 1312 1281 // Code for nice categories and authors, currently not very flexible 1282 $front = substr($permalink_structure, 0, strpos($permalink_structure, '%')); 1313 // Code for nice categories and authors. 1283 1314 if ( '' == get_settings('category_base') ) 1284 1315 $catmatch = $front . 'category/'; … … 1290 1321 $catfeedquery = 'wp-feed.php?category_name=' . preg_index(1, $matches) . '&feed=' . preg_index(2, $matches); 1291 1322 1323 $catpagematch = $catmatch . '(.*)/' . $pageregex; 1324 $catpagequery = 'index.php?category_name=' . preg_index(1, $matches) . '&paged=' . preg_index(2, $matches); 1325 1292 1326 $catmatch = $catmatch . '?(.*)'; 1293 1327 $catquery = 'index.php?category_name=' . preg_index(1, $matches); … … 1299 1333 $authorfeedquery = 'wp-feed.php?author_name=' . preg_index(1, $matches) . '&feed=' . preg_index(2, $matches); 1300 1334 1335 $authorpagematch = $authormatch . '(.*)/' . $pageregex; 1336 $authorpagequery = 'index.php?author_name=' . preg_index(1, $matches) . '&paged=' . preg_index(2, $matches); 1337 1301 1338 $authormatch = $authormatch . '?(.*)'; 1302 1339 $authorquery = 'index.php?author_name=' . preg_index(1, $matches); 1303 1340 1304 1341 $rewrite = array( 1342 $sitefeedmatch => $sitefeedquery, 1343 $sitecommentfeedmatch => $sitecommentfeedquery, 1344 $sitepagematch => $sitepagequery, 1305 1345 $catfeedmatch => $catfeedquery, 1346 $catpagematch => $catpagequery, 1306 1347 $catmatch => $catquery, 1307 1348 $authorfeedmatch => $authorfeedquery, 1308 $authormatch => $authorquery, 1309 $match => $query, 1310 $feedmatch => $feedquery, 1311 $trackbackmatch => $trackbackquery, 1312 $sitefeedmatch => $sitefeedquery, 1313 $sitecommentfeedmatch => $sitecommentfeedquery 1349 $authorpagematch => $authorpagequery, 1350 $authormatch => $authorquery 1314 1351 ); 1352 1353 $rewrite = $rewrite + $post_rewrite; 1354 1355 if ($doarchive) { 1356 $rewrite = $rewrite + array($archivematch => $archivequery); 1357 } 1315 1358 1316 1359 return $rewrite;
Note: See TracChangeset
for help on using the changeset viewer.