Changeset 1868
- Timestamp:
- 11/19/2004 08:54:16 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/options-permalink.php
r1818 r1868 36 36 $category_base = get_settings('category_base'); 37 37 38 get_date_permastruct(); 38 39 39 40 generate_page_rewrite_rules(); -
trunk/wp-includes/functions.php
r1867 r1868 1331 1331 1332 1332 1333 function page_permastruct() {1334 $permalink_structure = get_settings('permalink_structure');1335 1336 if (empty($permalink_structure)) {1337 return '';1338 }1339 1340 $index = 'index.php';1341 $prefix = '';1342 if (using_index_permalinks()) {1343 $prefix = $index . '/';1344 }1345 1346 return '/' . $prefix . 'site/%pagename%';1347 }1348 1349 1333 function get_page_uri($page) { 1350 1334 global $wpdb; … … 1373 1357 1374 1358 return $rewrite_rules; 1359 } 1360 1361 function get_date_permastruct($permalink_structure = '') { 1362 if (empty($permalink_structure)) { 1363 $permalink_structure = get_settings('permalink_structure'); 1364 1365 if (empty($permalink_structure)) { 1366 return false; 1367 } 1368 } 1369 1370 $front = substr($permalink_structure, 0, strpos($permalink_structure, '%')); 1371 // The date permalink must have year, month, and day separated by slashes. 1372 $endians = array('%year%/%monthnum%/%day%', '%day%/%monthnum%/%year%', '%monthnum%/%day%/%year%'); 1373 1374 $date_structure = ''; 1375 1376 foreach ($endians as $endian) { 1377 if (false !== strpos($permalink_structure, $endian)) { 1378 $date_structure = $front . $endian; 1379 break; 1380 } 1381 } 1382 1383 if (empty($date_structure)) { 1384 $date_structure = $front . '%year%/%monthnum%/%day%'; 1385 } 1386 1387 return $date_structure; 1388 } 1389 1390 function get_year_permastruct($permalink_structure = '') { 1391 $structure = get_date_permastruct($permalink_structure); 1392 1393 if (empty($structure)) { 1394 return false; 1395 } 1396 1397 $structure = str_replace('%monthnum%', '', $structure); 1398 $structure = str_replace('%day%', '', $structure); 1399 1400 $structure = preg_replace('#/+#', '/', $structure); 1401 1402 return $structure; 1403 } 1404 1405 function get_month_permastruct($permalink_structure = '') { 1406 $structure = get_date_permastruct($permalink_structure); 1407 1408 if (empty($structure)) { 1409 return false; 1410 } 1411 1412 $structure = str_replace('%day%', '', $structure); 1413 1414 $structure = preg_replace('#/+#', '/', $structure); 1415 1416 return $structure; 1417 } 1418 1419 function get_day_permastruct($permalink_structure = '') { 1420 return get_date_permastruct($permalink_structure); 1375 1421 } 1376 1422 … … 1520 1566 } 1521 1567 1522 // If the permalink does not have year, month, and day, we need to create a 1523 // separate archive rule. 1524 $doarchive = false; 1525 if (! (strstr($permalink_structure, '%year%') && strstr($permalink_structure, '%monthnum%') && strstr($permalink_structure, '%day%')) || 1526 preg_match('/%category%.*(%year%|%monthnum%|%day%)/', $permalink_structure)) { 1527 $doarchive = true; 1528 $archive_structure = $front . '%year%/%monthnum%/%day%/'; 1529 $archive_rewrite = generate_rewrite_rules($archive_structure, $matches); 1530 } 1568 // Generate date rules. 1569 $date_rewrite = generate_rewrite_rules(get_date_permastruct($permalink_structure), $matches); 1531 1570 1532 1571 // Site feed … … 1573 1612 1574 1613 // Put them together. 1575 $rewrite = $pages_rewrite + $site_rewrite + $page_rewrite + $search_rewrite + $category_rewrite + $author_rewrite; 1576 1577 // Add on archive rewrite rules if needed. 1578 if ($doarchive) { 1579 $rewrite = $rewrite + $archive_rewrite; 1580 } 1614 $rewrite = $pages_rewrite + $site_rewrite + $page_rewrite + $search_rewrite + $category_rewrite + $author_rewrite + $date_rewrite; 1581 1615 1582 1616 $rewrite = $rewrite + $post_rewrite; … … 1599 1633 $rules .= "RewriteBase $home_root\n"; 1600 1634 $rewrite = rewrite_rules('', $permalink_structure); 1635 1636 $num_rules = count($rewrite); 1637 $rules .= "RewriteCond %{REQUEST_FILENAME} -f [OR]\n" . 1638 "RewriteCond %{REQUEST_FILENAME} -d\n" . 1639 "RewriteRule ^.*$ - [S=$num_rules]\n"; 1640 1601 1641 foreach ($rewrite as $match => $query) { 1602 1642 // Apache 1.3 does not support the reluctant (non-greedy) modifier. … … 1605 1645 // If the match is unanchored and greedy, prepend rewrite conditions 1606 1646 // to avoid infinite redirects and eclipsing of real files. 1607 if ($match == '(.+)/?$') { 1608 $rules .= "RewriteCond %{REQUEST_FILENAME} !-f\n" . 1609 "RewriteCond %{REQUEST_FILENAME} !-d\n"; 1647 if ($match == '(.+)/?$' || $match == '([^/]+)/?$' ) { 1648 //nada. 1610 1649 } 1611 1650 -
trunk/wp-includes/template-functions-links.php
r1860 r1868 106 106 } 107 107 108 function get_year_link($year) { 109 global $querystring_start, $querystring_equal; 110 if (!$year) $year = gmdate('Y', time()+(get_settings('gmt_offset') * 3600)); 111 $yearlink = get_year_permastruct(); 112 if (!empty($yearlink)) { 113 $yearlink = str_replace('%year%', $year, $yearlink); 114 return get_settings('home') . $yearlink; 115 } else { 116 return get_settings('home') .'/'. get_settings('blogfilename') .$querystring_start.'m'.$querystring_equal.$year; 117 } 118 } 119 108 120 function get_month_link($year, $month) { 109 121 global $querystring_start, $querystring_equal; 110 122 if (!$year) $year = gmdate('Y', time()+(get_settings('gmt_offset') * 3600)); 111 123 if (!$month) $month = gmdate('m', time()+(get_settings('gmt_offset') * 3600)); 112 if ('' != get_settings('permalink_structure')) { 113 $permalink = get_settings('permalink_structure'); 114 115 // If the permalink structure does not contain year and month, make 116 // one that does. 117 if (! (strstr($permalink, '%year%') && strstr($permalink, '%monthnum%')) 118 || preg_match('/%category%.*(%year%|%monthnum%|%day%)/', $permalink)) { 119 $front = substr($permalink, 0, strpos($permalink, '%')); 120 $permalink = $front . '%year%/%monthnum%/'; 121 } 122 123 $off = strpos($permalink, '%monthnum%'); 124 $offset = $off + 11; 125 $monthlink = substr($permalink, 0, $offset); 126 if ('/' != substr($monthlink, -1)) $monthlink = substr($monthlink, 0, -1); 124 $monthlink = get_month_permastruct(); 125 if (!empty($monthlink)) { 127 126 $monthlink = str_replace('%year%', $year, $monthlink); 128 127 $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink); 129 $monthlink = str_replace('%post_id%', '', $monthlink);130 $monthlink = str_replace('%category%', '', $monthlink);131 128 return get_settings('home') . $monthlink; 132 129 } else { … … 140 137 if (!$month) $month = gmdate('m', time()+(get_settings('gmt_offset') * 3600)); 141 138 if (!$day) $day = gmdate('j', time()+(get_settings('gmt_offset') * 3600)); 142 if ('' != get_settings('permalink_structure')) { 143 $permalink = get_settings('permalink_structure'); 144 145 // If the permalink structure does not contain year, month, and day, 146 // make one that does. 147 if (! (strstr($permalink, '%year%') && strstr($permalink, '%monthnum%')&& strstr($permalink, '%day%')) 148 || preg_match('/%category%.*(%year%|%monthnum%|%day%)/', $permalink)) { 149 $front = substr($permalink, 0, strpos($permalink, '%')); 150 $permalink = $front . '%year%/%monthnum%/%day%/'; 151 } 152 153 $off = strpos($permalink, '%day%'); 154 $offset = $off + 6; 155 $daylink = substr($permalink, 0, $offset); 156 if ('/' != substr($daylink, -1)) $daylink = substr($daylink, 0, -1); 139 140 $daylink = get_day_permastruct(); 141 if (!empty($daylink)) { 157 142 $daylink = str_replace('%year%', $year, $daylink); 158 143 $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink); 159 144 $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink); 160 $daylink = str_replace('%post_id%', '', $daylink);161 $daylink = str_replace('%category%', '', $daylink);162 145 return get_settings('home') . $daylink; 163 146 } else {
Note: See TracChangeset
for help on using the changeset viewer.