[wp-cvs] wordpress/wp-includes functions.php, 1.209,
1.210 template-functions-links.php, 1.43, 1.44
Ryan Boren
rboren at users.sourceforge.net
Fri Nov 19 20:54:19 UTC 2004
Update of /cvsroot/cafelog/wordpress/wp-includes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv734/wp-includes
Modified Files:
functions.php template-functions-links.php
Log Message:
Permalink love. Wrap mod_rewrite rules in a conditional. Make sure date permalinks are sane. Add get_year_link().
Index: template-functions-links.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-includes/template-functions-links.php,v
retrieving revision 1.43
retrieving revision 1.44
diff -C2 -d -r1.43 -r1.44
*** template-functions-links.php 17 Nov 2004 03:45:50 -0000 1.43
--- template-functions-links.php 19 Nov 2004 20:54:16 -0000 1.44
***************
*** 106,132 ****
}
function get_month_link($year, $month) {
global $querystring_start, $querystring_equal;
if (!$year) $year = gmdate('Y', time()+(get_settings('gmt_offset') * 3600));
if (!$month) $month = gmdate('m', time()+(get_settings('gmt_offset') * 3600));
! if ('' != get_settings('permalink_structure')) {
! $permalink = get_settings('permalink_structure');
!
! // If the permalink structure does not contain year and month, make
! // one that does.
! if (! (strstr($permalink, '%year%') && strstr($permalink, '%monthnum%'))
! || preg_match('/%category%.*(%year%|%monthnum%|%day%)/', $permalink)) {
! $front = substr($permalink, 0, strpos($permalink, '%'));
! $permalink = $front . '%year%/%monthnum%/';
! }
!
! $off = strpos($permalink, '%monthnum%');
! $offset = $off + 11;
! $monthlink = substr($permalink, 0, $offset);
! if ('/' != substr($monthlink, -1)) $monthlink = substr($monthlink, 0, -1);
$monthlink = str_replace('%year%', $year, $monthlink);
$monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
- $monthlink = str_replace('%post_id%', '', $monthlink);
- $monthlink = str_replace('%category%', '', $monthlink);
return get_settings('home') . $monthlink;
} else {
--- 106,129 ----
}
+ function get_year_link($year) {
+ global $querystring_start, $querystring_equal;
+ if (!$year) $year = gmdate('Y', time()+(get_settings('gmt_offset') * 3600));
+ $yearlink = get_year_permastruct();
+ if (!empty($yearlink)) {
+ $yearlink = str_replace('%year%', $year, $yearlink);
+ return get_settings('home') . $yearlink;
+ } else {
+ return get_settings('home') .'/'. get_settings('blogfilename') .$querystring_start.'m'.$querystring_equal.$year;
+ }
+ }
+
function get_month_link($year, $month) {
global $querystring_start, $querystring_equal;
if (!$year) $year = gmdate('Y', time()+(get_settings('gmt_offset') * 3600));
if (!$month) $month = gmdate('m', time()+(get_settings('gmt_offset') * 3600));
! $monthlink = get_month_permastruct();
! if (!empty($monthlink)) {
$monthlink = str_replace('%year%', $year, $monthlink);
$monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
return get_settings('home') . $monthlink;
} else {
***************
*** 140,163 ****
if (!$month) $month = gmdate('m', time()+(get_settings('gmt_offset') * 3600));
if (!$day) $day = gmdate('j', time()+(get_settings('gmt_offset') * 3600));
- if ('' != get_settings('permalink_structure')) {
- $permalink = get_settings('permalink_structure');
-
- // If the permalink structure does not contain year, month, and day,
- // make one that does.
- if (! (strstr($permalink, '%year%') && strstr($permalink, '%monthnum%')&& strstr($permalink, '%day%'))
- || preg_match('/%category%.*(%year%|%monthnum%|%day%)/', $permalink)) {
- $front = substr($permalink, 0, strpos($permalink, '%'));
- $permalink = $front . '%year%/%monthnum%/%day%/';
- }
! $off = strpos($permalink, '%day%');
! $offset = $off + 6;
! $daylink = substr($permalink, 0, $offset);
! if ('/' != substr($daylink, -1)) $daylink = substr($daylink, 0, -1);
$daylink = str_replace('%year%', $year, $daylink);
$daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
$daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
- $daylink = str_replace('%post_id%', '', $daylink);
- $daylink = str_replace('%category%', '', $daylink);
return get_settings('home') . $daylink;
} else {
--- 137,146 ----
if (!$month) $month = gmdate('m', time()+(get_settings('gmt_offset') * 3600));
if (!$day) $day = gmdate('j', time()+(get_settings('gmt_offset') * 3600));
! $daylink = get_day_permastruct();
! if (!empty($daylink)) {
$daylink = str_replace('%year%', $year, $daylink);
$daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
$daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
return get_settings('home') . $daylink;
} else {
Index: functions.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-includes/functions.php,v
retrieving revision 1.209
retrieving revision 1.210
diff -C2 -d -r1.209 -r1.210
*** functions.php 19 Nov 2004 07:37:18 -0000 1.209
--- functions.php 19 Nov 2004 20:54:16 -0000 1.210
***************
*** 1331,1350 ****
- function page_permastruct() {
- $permalink_structure = get_settings('permalink_structure');
-
- if (empty($permalink_structure)) {
- return '';
- }
-
- $index = 'index.php';
- $prefix = '';
- if (using_index_permalinks()) {
- $prefix = $index . '/';
- }
-
- return '/' . $prefix . 'site/%pagename%';
- }
-
function get_page_uri($page) {
global $wpdb;
--- 1331,1334 ----
***************
*** 1375,1378 ****
--- 1359,1424 ----
}
+ function get_date_permastruct($permalink_structure = '') {
+ if (empty($permalink_structure)) {
+ $permalink_structure = get_settings('permalink_structure');
+
+ if (empty($permalink_structure)) {
+ return false;
+ }
+ }
+
+ $front = substr($permalink_structure, 0, strpos($permalink_structure, '%'));
+ // The date permalink must have year, month, and day separated by slashes.
+ $endians = array('%year%/%monthnum%/%day%', '%day%/%monthnum%/%year%', '%monthnum%/%day%/%year%');
+
+ $date_structure = '';
+
+ foreach ($endians as $endian) {
+ if (false !== strpos($permalink_structure, $endian)) {
+ $date_structure = $front . $endian;
+ break;
+ }
+ }
+
+ if (empty($date_structure)) {
+ $date_structure = $front . '%year%/%monthnum%/%day%';
+ }
+
+ return $date_structure;
+ }
+
+ function get_year_permastruct($permalink_structure = '') {
+ $structure = get_date_permastruct($permalink_structure);
+
+ if (empty($structure)) {
+ return false;
+ }
+
+ $structure = str_replace('%monthnum%', '', $structure);
+ $structure = str_replace('%day%', '', $structure);
+
+ $structure = preg_replace('#/+#', '/', $structure);
+
+ return $structure;
+ }
+
+ function get_month_permastruct($permalink_structure = '') {
+ $structure = get_date_permastruct($permalink_structure);
+
+ if (empty($structure)) {
+ return false;
+ }
+
+ $structure = str_replace('%day%', '', $structure);
+
+ $structure = preg_replace('#/+#', '/', $structure);
+
+ return $structure;
+ }
+
+ function get_day_permastruct($permalink_structure = '') {
+ return get_date_permastruct($permalink_structure);
+ }
+
function generate_rewrite_rules($permalink_structure = '', $matches = '') {
$rewritecode =
***************
*** 1520,1532 ****
}
! // If the permalink does not have year, month, and day, we need to create a
! // separate archive rule.
! $doarchive = false;
! if (! (strstr($permalink_structure, '%year%') && strstr($permalink_structure, '%monthnum%') && strstr($permalink_structure, '%day%')) ||
! preg_match('/%category%.*(%year%|%monthnum%|%day%)/', $permalink_structure)) {
! $doarchive = true;
! $archive_structure = $front . '%year%/%monthnum%/%day%/';
! $archive_rewrite = generate_rewrite_rules($archive_structure, $matches);
! }
// Site feed
--- 1566,1571 ----
}
! // Generate date rules.
! $date_rewrite = generate_rewrite_rules(get_date_permastruct($permalink_structure), $matches);
// Site feed
***************
*** 1573,1582 ****
// Put them together.
! $rewrite = $pages_rewrite + $site_rewrite + $page_rewrite + $search_rewrite + $category_rewrite + $author_rewrite;
!
! // Add on archive rewrite rules if needed.
! if ($doarchive) {
! $rewrite = $rewrite + $archive_rewrite;
! }
$rewrite = $rewrite + $post_rewrite;
--- 1612,1616 ----
// Put them together.
! $rewrite = $pages_rewrite + $site_rewrite + $page_rewrite + $search_rewrite + $category_rewrite + $author_rewrite + $date_rewrite;
$rewrite = $rewrite + $post_rewrite;
***************
*** 1599,1602 ****
--- 1633,1642 ----
$rules .= "RewriteBase $home_root\n";
$rewrite = rewrite_rules('', $permalink_structure);
+
+ $num_rules = count($rewrite);
+ $rules .= "RewriteCond %{REQUEST_FILENAME} -f [OR]\n" .
+ "RewriteCond %{REQUEST_FILENAME} -d\n" .
+ "RewriteRule ^.*$ - [S=$num_rules]\n";
+
foreach ($rewrite as $match => $query) {
// Apache 1.3 does not support the reluctant (non-greedy) modifier.
***************
*** 1605,1611 ****
// If the match is unanchored and greedy, prepend rewrite conditions
// to avoid infinite redirects and eclipsing of real files.
! if ($match == '(.+)/?$') {
! $rules .= "RewriteCond %{REQUEST_FILENAME} !-f\n" .
! "RewriteCond %{REQUEST_FILENAME} !-d\n";
}
--- 1645,1650 ----
// If the match is unanchored and greedy, prepend rewrite conditions
// to avoid infinite redirects and eclipsing of real files.
! if ($match == '(.+)/?$' || $match == '([^/]+)/?$' ) {
! //nada.
}
More information about the cvs
mailing list