Changeset 1373
- Timestamp:
- 05/31/2004 05:22:25 PM (20 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/options-permalink.php
r1350 r1373 126 126 $rules = ''; 127 127 foreach ($rewrite as $match => $query) { 128 if (strstr($query, 'index.php')) $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA]\n"; 129 $rules .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA]\n"; 128 if (strstr($query, 'index.php')) { 129 $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA]\n"; 130 } else { 131 $rules .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA]\n"; 132 } 130 133 } 131 134 echo apply_filters('rewrite_rules', $rules); 132 135 ?> 133 136 </textarea> 134 137 </p> 135 138 <?php printf(__('<p>If your <code>.htaccess</code> file is writable by WordPress, you can <a href="%s">edit it through your template interface</a>.</p>'), 'templates.php?file=.htaccess') ?> -
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; -
trunk/wp-includes/template-functions-links.php
r1355 r1373 84 84 if (!$month) $month = gmdate('m', time()+(get_settings('gmt_offset') * 3600)); 85 85 if ('' != get_settings('permalink_structure')) { 86 $off = strpos(get_settings('permalink_structure'), '%monthnum%'); 86 $permalink = get_settings('permalink_structure'); 87 88 // If the permalink structure does not contain year and month, make 89 // one that does. 90 if (! (strstr($permalink, '%year') && strstr($permalink, '%monthnum')) ) { 91 $front = substr($permalink, 0, strpos($permalink, '%')); 92 $permalink = $front . '%year%/%monthnum%/'; 93 } 94 95 $off = strpos($permalink, '%monthnum%'); 87 96 $offset = $off + 11; 88 $monthlink = substr( get_settings('permalink_structure'), 0, $offset);97 $monthlink = substr($permalink, 0, $offset); 89 98 if ('/' != substr($monthlink, -1)) $monthlink = substr($monthlink, 0, -1); 90 99 $monthlink = str_replace('%year%', $year, $monthlink); … … 103 112 if (!$day) $day = gmdate('j', time()+(get_settings('gmt_offset') * 3600)); 104 113 if ('' != get_settings('permalink_structure')) { 105 $off = strpos(get_settings('permalink_structure'), '%day%'); 114 $permalink = get_settings('permalink_structure'); 115 116 // If the permalink structure does not contain year, month, and day, 117 // make one that does. 118 if (! (strstr($permalink, '%year') && strstr($permalink, '%monthnum')) ) { 119 $front = substr($permalink, 0, strpos($permalink, '%')); 120 $permalink = $front . '%year%/%monthnum%/%day%/'; 121 } 122 123 $off = strpos($permalink, '%day%'); 106 124 $offset = $off + 6; 107 $daylink = substr( get_settings('permalink_structure'), 0, $offset);125 $daylink = substr($permalink, 0, $offset); 108 126 if ('/' != substr($daylink, -1)) $daylink = substr($daylink, 0, -1); 109 127 $daylink = str_replace('%year%', $year, $daylink); -
trunk/wp-includes/template-functions-post.php
r1355 r1373 351 351 } 352 352 353 function get_pagenum_link($pagenum = 1){ 354 $qstr = $_SERVER['REQUEST_URI']; 355 356 $page_querystring = "paged"; 357 $page_modstring = "page/"; 358 $page_modregex = "page/?"; 359 360 // if we already have a QUERY style page string 361 if( stristr( $qstr, $page_querystring ) ) { 362 $replacement = "$page_querystring=$pagenum"; 363 $qstr = preg_replace("/".$page_querystring."[^\d]+\d+/", $replacement, $qstr); 364 // if we already have a mod_rewrite style page string 365 } elseif ( preg_match( '|'.$page_modregex.'\d+|', $qstr ) ){ 366 $qstr = preg_replace('|'.$page_modregex.'\d+|',"$page_modstring$pagenum",$qstr); 367 368 // if we don't have a page string at all ... 369 // lets see what sort of URL we have... 370 } else { 371 // we need to know the way queries are being written 372 global $querystring_start, $querystring_equal, $querystring_separator; 373 // if there's a querystring_start (a "?" usually), it's deffinitely not mod_rewritten 374 if ( stristr( $qstr, $querystring_start ) ){ 375 // so append the query string (using &, since we already have ?) 376 $qstr .= $querystring_separator.$page_querystring.$querystring_equal.$pagenum; 377 // otherwise, it could be rewritten, OR just the default index ... 378 } elseif( '' != get_settings('permalink_structure')) { 379 $qstr = preg_replace('|(.*)/[^/]*|', '$1/', $qstr).$page_modstring.$pagenum; 380 } else { 381 $qstr = get_settings('blogfilename') . $querystring_start.$page_querystring.$querystring_equal.$pagenum; 382 } 383 } 384 385 $home_root = str_replace('http://', '', trim(get_settings('home'))); 386 $home_root = preg_replace('|([^/]*)(.*)|i', '$2', $home_root); 387 if ('/' != substr($home_root, -1)) $home_root = $home_root . '/'; 388 389 $qstr = str_replace($home_root, '', $qstr); 390 return trailingslashit(get_settings('home')).$qstr; 391 } 392 353 393 function next_posts($max_page = 0) { // original by cfactor at cooltux.org 354 394 global $p, $paged, $what_to_show, $pagenow; 355 395 global $querystring_start, $querystring_equal, $querystring_separator; 356 if (empty($p) && ($what_to_show == 'paged')) { 357 $qstr = $_SERVER['QUERY_STRING']; 358 if (!empty($qstr)) { 359 $qstr = preg_replace('/&paged=\d{0,}/', '', $qstr); 360 $qstr = preg_replace('/paged=\d{0,}/', '', $qstr); 361 } elseif (stristr($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'] )) { 362 if ('' != $qstr = str_replace($_SERVER['SCRIPT_NAME'], '', 363 $_SERVER['REQUEST_URI']) ) { 364 $qstr = preg_replace('/^\//', '', $qstr); 365 $qstr = preg_replace('/paged\/\d{0,}\//', '', $qstr); 366 $qstr = preg_replace('/paged\/\d{0,}/', '', $qstr); 367 $qstr = preg_replace('/\/$/', '', $qstr); 368 } 369 } 370 if (!$paged) $paged = 1; 371 $nextpage = intval($paged) + 1; 372 if (!$max_page || $max_page >= $nextpage) { 373 echo get_settings('home') .'/'.$pagenow.$querystring_start. 374 ($qstr == '' ? '' : $qstr.$querystring_separator) . 375 'paged'.$querystring_equal.$nextpage; 376 } 377 } 396 // if (empty($p) && ($what_to_show == 'paged')) { 397 // $qstr = $_SERVER['QUERY_STRING']; 398 // if (!empty($qstr)) { 399 // $qstr = preg_replace('/&paged=\d{0,}/', '', $qstr); 400 // $qstr = preg_replace('/paged=\d{0,}/', '', $qstr); 401 // } elseif (stristr($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'] )) { 402 // if ('' != $qstr = str_replace($_SERVER['SCRIPT_NAME'], '', 403 // $_SERVER['REQUEST_URI']) ) { 404 // $qstr = preg_replace('/^\//', '', $qstr); 405 // $qstr = preg_replace('/paged\/\d{0,}\//', '', $qstr); 406 // $qstr = preg_replace('/paged\/\d{0,}/', '', $qstr); 407 // $qstr = preg_replace('/\/$/', '', $qstr); 408 // } 409 // } 410 // if (!$paged) $paged = 1; 411 // $nextpage = intval($paged) + 1; 412 // if (!$max_page || $max_page >= $nextpage) { 413 // echo get_settings('home') .'/'.$pagenow.$querystring_start. 414 // ($qstr == '' ? '' : $qstr.$querystring_separator) . 415 // 'paged'.$querystring_equal.$nextpage; 416 // } 417 // } 418 419 if (empty($p) && ($what_to_show == 'paged')) { 420 if (!$paged) $paged = 1; 421 $nextpage = intval($paged) + 1; 422 if (!$max_page || $max_page >= $nextpage) { 423 echo get_pagenum_link($nextpage); 424 } 425 } 378 426 } 379 427 … … 407 455 global $_SERVER, $p, $paged, $what_to_show, $pagenow; 408 456 global $querystring_start, $querystring_equal, $querystring_separator; 409 if (empty($p) && ($what_to_show == 'paged')) { 410 $qstr = $_SERVER['QUERY_STRING']; 411 if (!empty($qstr)) { 412 $qstr = preg_replace('/&paged=\d{0,}/', '', $qstr); 413 $qstr = preg_replace('/paged=\d{0,}/', '', $qstr); 414 } elseif (stristr($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'] )) { 415 if ('' != $qstr = str_replace($_SERVER['SCRIPT_NAME'], '', 416 $_SERVER['REQUEST_URI']) ) { 417 $qstr = preg_replace('/^\//', '', $qstr); 418 $qstr = preg_replace("/paged\/\d{0,}\//", '', $qstr); 419 $qstr = preg_replace('/paged\/\d{0,}/', '', $qstr); 420 $qstr = preg_replace('/\/$/', '', $qstr); 421 } 422 } 423 $nextpage = intval($paged) - 1; 424 if ($nextpage < 1) $nextpage = 1; 425 echo get_settings('home') .'/'.$pagenow.$querystring_start. 426 ($qstr == '' ? '' : $qstr.$querystring_separator) . 427 'paged'.$querystring_equal.$nextpage; 428 } 457 // if (empty($p) && ($what_to_show == 'paged')) { 458 // $qstr = $_SERVER['QUERY_STRING']; 459 // if (!empty($qstr)) { 460 // $qstr = preg_replace('/&paged=\d{0,}/', '', $qstr); 461 // $qstr = preg_replace('/paged=\d{0,}/', '', $qstr); 462 // } elseif (stristr($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'] )) { 463 // if ('' != $qstr = str_replace($_SERVER['SCRIPT_NAME'], '', 464 // $_SERVER['REQUEST_URI']) ) { 465 // $qstr = preg_replace('/^\//', '', $qstr); 466 // $qstr = preg_replace("/paged\/\d{0,}\//", '', $qstr); 467 // $qstr = preg_replace('/paged\/\d{0,}/', '', $qstr); 468 // $qstr = preg_replace('/\/$/', '', $qstr); 469 // } 470 // } 471 // $nextpage = intval($paged) - 1; 472 // if ($nextpage < 1) $nextpage = 1; 473 // echo get_settings('home') .'/'.$pagenow.$querystring_start. 474 // ($qstr == '' ? '' : $qstr.$querystring_separator) . 475 // 'paged'.$querystring_equal.$nextpage; 476 // } 477 478 if (empty($p) && ($what_to_show == 'paged')) { 479 $nextpage = intval($paged) - 1; 480 if ($nextpage < 1) $nextpage = 1; 481 echo get_pagenum_link($nextpage); 482 } 429 483 } 430 484
Note: See TracChangeset
for help on using the changeset viewer.