diff --git a/wp-admin/options-permalink.php b/wp-admin/options-permalink.php index 8bbd41b368..7fe987858d 100644 --- a/wp-admin/options-permalink.php +++ b/wp-admin/options-permalink.php @@ -125,12 +125,15 @@ RewriteBase $rewrite = rewrite_rules('', $permalink_structure); $rules = ''; foreach ($rewrite as $match => $query) { - if (strstr($query, 'index.php')) $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA]\n"; - $rules .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA]\n"; + if (strstr($query, 'index.php')) { + $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA]\n"; + } else { + $rules .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA]\n"; + } } echo apply_filters('rewrite_rules', $rules); ?> - +
If your.htaccess
file is writable by WordPress, you can edit it through your template interface.'), 'templates.php?file=.htaccess') ?>
diff --git a/wp-includes/functions.php b/wp-includes/functions.php
index a3a6cc4a8a..dad5f4ef37 100644
--- a/wp-includes/functions.php
+++ b/wp-includes/functions.php
@@ -1206,14 +1206,14 @@ function rewrite_rules($matches = '', $permalink_structure = '') {
$rewritereplace =
array(
- '([0-9]{4})?',
- '([0-9]{1,2})?',
- '([0-9]{1,2})?',
- '([0-9]{1,2})?',
- '([0-9]{1,2})?',
- '([0-9]{1,2})?',
- '([_0-9a-z-]+)?',
- '([0-9]+)?'
+ '([0-9]{4})',
+ '([0-9]{1,2})',
+ '([0-9]{1,2})',
+ '([0-9]{1,2})',
+ '([0-9]{1,2})',
+ '([0-9]{1,2})',
+ '([_0-9a-z-]+)',
+ '([0-9]+)'
);
$queryreplace =
@@ -1228,58 +1228,89 @@ function rewrite_rules($matches = '', $permalink_structure = '') {
'p='
);
+ $feedregex = '(feed|rdf|rss|rss2|atom)/?$';
+ $trackbackregex = 'trackback/?$';
+ $pageregex = 'page/?([0-9]{1,})/?$';
- $match = str_replace('/', '/?', $permalink_structure);
- $match = preg_replace('|/[?]|', '', $match, 1);
-
- $match = str_replace($rewritecode, $rewritereplace, $match);
- $match = preg_replace('|[?]|', '', $match, 1);
-
- $feedmatch = trailingslashit(str_replace('?/?', '/', $match));
- $trackbackmatch = $feedmatch;
-
+ $front = substr($permalink_structure, 0, strpos($permalink_structure, '%'));
preg_match_all('/%.+?%/', $permalink_structure, $tokens);
- $query = 'index.php?';
- $feedquery = 'wp-feed.php?';
- $trackbackquery = 'wp-trackback.php?';
- for ($i = 0; $i < count($tokens[0]); ++$i) {
+ $num_tokens = count($tokens[0]);
+
+ $index = 'index.php';
+ $feedindex = 'wp-feed.php';
+ $trackbackindex = 'wp-trackback.php';
+ for ($i = 0; $i < $num_tokens; ++$i) {
if (0 < $i) {
- $query .= '&';
- $feedquery .= '&';
- $trackbackquery .= '&';
+ $queries[$i] = $queries[$i - 1] . '&';
}
$query_token = str_replace($rewritecode, $queryreplace, $tokens[0][$i]) . preg_index($i+1, $matches);
- $query .= $query_token;
- $feedquery .= $query_token;
- $trackbackquery .= $query_token;
+ $queries[$i] .= $query_token;
}
- ++$i;
- // Add post paged stuff
- $match .= '([0-9]+)?/?$';
- $query .= '&page=' . preg_index($i, $matches);
+ $structure = str_replace($front, '', $permalink_structure);
+ $structure = trim($structure, '/');
+ $dirs = explode('/', $structure);
+ $num_dirs = count($dirs);
- // Add post feed stuff
- $feedregex = '(feed|rdf|rss|rss2|atom)/?$';
- $feedmatch .= $feedregex;
- $feedquery .= '&feed=' . preg_index($i, $matches);
+ $front = preg_replace('|^/+|', '', $front);
- // Add post trackback stuff
- $trackbackregex = 'trackback/?$';
- $trackbackmatch .= $trackbackregex;
+ $post_rewrite = array();
+ $struct = $front;
+ for ($j = 0; $j < $num_dirs; ++$j) {
+ $struct .= $dirs[$j] . '/';
+ $match = str_replace($rewritecode, $rewritereplace, $struct);
+ $num_toks = preg_match_all('/%.+?%/', $struct, $toks);
+ $query = $queries[$num_toks - 1];
+
+ $pagematch = $match . $pageregex;
+ $pagequery = $index . '?' . $query . '&paged=' . preg_index($num_toks + 1, $matches);
+
+ $feedmatch = $match . $feedregex;
+ $feedquery = $feedindex . '?' . $query . '&feed=' . preg_index($num_toks + 1, $matches);
+
+ $post = 0;
+ if (strstr($struct, '%postname%') || strstr($struct, '%post_id%')) {
+ $post = 1;
+ $trackbackmatch = $match . $trackbackregex;
+ $trackbackquery = $trackbackindex . '?' . $query;
+ $match = $match . '?([0-9]+)?/?$';
+ $query = $index . '?' . $query . '&page=' . preg_index($num_toks + 1, $matches);
+ } else {
+ $match .= '?';
+ $query = $index . '?' . $query;
+ }
+
+ $post_rewrite = array($feedmatch => $feedquery, $pagematch => $pagequery, $match => $query) + $post_rewrite;
+
+ if ($post) {
+ $post_rewrite = array($trackbackmatch => $trackbackquery) + $post_rewrite;
+ }
+ }
+
+ // If the permalink does not have year, month, and day, we need to create a
+ // separate archive rule.
+ // TODO: Need to write separate rules for each component of the permalink.
+ $doarchive = false;
+ if (! (strstr($permalink_structure, '%year') && strstr($permalink_structure, '%monthnum') && strstr($permalink_structure, '%day')) ) {
+ $doarchive = true;
+ $archivematch = $front . '([0-9]{4})/?([0-9]{1,2})?/?([0-9]{1,2})?/?$';
+ $archivequery = 'index.php?year=' . preg_index(1, $matches) . '&monthnum=' . preg_index(2, $matches) . '&day=' . preg_index(3, $matches) ;
+ }
// Site feed
$sitefeedmatch = 'feed/?([_0-9a-z-]+)?/?$';
$sitefeedquery = 'wp-feed.php?feed=' . preg_index(1, $matches);
+ $sitepagematch = $pageregex;
+ $sitepagequery = 'index.php?paged=' . preg_index(1, $matches);
+
// Site comment feed
$sitecommentfeedmatch = 'comments/feed/?([_0-9a-z-]+)?/?$';
$sitecommentfeedquery = 'wp-feed.php?feed=' . preg_index(1, $matches) . '&withcomments=1';
- // Code for nice categories and authors, currently not very flexible
- $front = substr($permalink_structure, 0, strpos($permalink_structure, '%'));
+ // Code for nice categories and authors.
if ( '' == get_settings('category_base') )
$catmatch = $front . 'category/';
else
@@ -1289,6 +1320,9 @@ function rewrite_rules($matches = '', $permalink_structure = '') {
$catfeedmatch = $catmatch . '(.*)/' . $feedregex;
$catfeedquery = 'wp-feed.php?category_name=' . preg_index(1, $matches) . '&feed=' . preg_index(2, $matches);
+ $catpagematch = $catmatch . '(.*)/' . $pageregex;
+ $catpagequery = 'index.php?category_name=' . preg_index(1, $matches) . '&paged=' . preg_index(2, $matches);
+
$catmatch = $catmatch . '?(.*)';
$catquery = 'index.php?category_name=' . preg_index(1, $matches);
@@ -1298,21 +1332,30 @@ function rewrite_rules($matches = '', $permalink_structure = '') {
$authorfeedmatch = $authormatch . '(.*)/' . $feedregex;
$authorfeedquery = 'wp-feed.php?author_name=' . preg_index(1, $matches) . '&feed=' . preg_index(2, $matches);
+ $authorpagematch = $authormatch . '(.*)/' . $pageregex;
+ $authorpagequery = 'index.php?author_name=' . preg_index(1, $matches) . '&paged=' . preg_index(2, $matches);
+
$authormatch = $authormatch . '?(.*)';
$authorquery = 'index.php?author_name=' . preg_index(1, $matches);
$rewrite = array(
+ $sitefeedmatch => $sitefeedquery,
+ $sitecommentfeedmatch => $sitecommentfeedquery,
+ $sitepagematch => $sitepagequery,
$catfeedmatch => $catfeedquery,
+ $catpagematch => $catpagequery,
$catmatch => $catquery,
$authorfeedmatch => $authorfeedquery,
- $authormatch => $authorquery,
- $match => $query,
- $feedmatch => $feedquery,
- $trackbackmatch => $trackbackquery,
- $sitefeedmatch => $sitefeedquery,
- $sitecommentfeedmatch => $sitecommentfeedquery
+ $authorpagematch => $authorpagequery,
+ $authormatch => $authorquery
);
+ $rewrite = $rewrite + $post_rewrite;
+
+ if ($doarchive) {
+ $rewrite = $rewrite + array($archivematch => $archivequery);
+ }
+
return $rewrite;
}
diff --git a/wp-includes/template-functions-links.php b/wp-includes/template-functions-links.php
index 5dfb1765bd..1e223213be 100644
--- a/wp-includes/template-functions-links.php
+++ b/wp-includes/template-functions-links.php
@@ -83,9 +83,18 @@ function get_month_link($year, $month) {
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')) {
- $off = strpos(get_settings('permalink_structure'), '%monthnum%');
+ $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')) ) {
+ $front = substr($permalink, 0, strpos($permalink, '%'));
+ $permalink = $front . '%year%/%monthnum%/';
+ }
+
+ $off = strpos($permalink, '%monthnum%');
$offset = $off + 11;
- $monthlink = substr(get_settings('permalink_structure'), 0, $offset);
+ $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);
@@ -102,9 +111,18 @@ function get_day_link($year, $month, $day) {
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')) {
- $off = strpos(get_settings('permalink_structure'), '%day%');
+ $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')) ) {
+ $front = substr($permalink, 0, strpos($permalink, '%'));
+ $permalink = $front . '%year%/%monthnum%/%day%/';
+ }
+
+ $off = strpos($permalink, '%day%');
$offset = $off + 6;
- $daylink = substr(get_settings('permalink_structure'), 0, $offset);
+ $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);
diff --git a/wp-includes/template-functions-post.php b/wp-includes/template-functions-post.php
index 110b4e5b44..a0aedcb80d 100644
--- a/wp-includes/template-functions-post.php
+++ b/wp-includes/template-functions-post.php
@@ -350,31 +350,79 @@ function next_post($format='%', $next='next post: ', $title='yes', $in_same_cat=
}
}
+function get_pagenum_link($pagenum = 1){
+ $qstr = $_SERVER['REQUEST_URI'];
+
+ $page_querystring = "paged";
+ $page_modstring = "page/";
+ $page_modregex = "page/?";
+
+ // if we already have a QUERY style page string
+ if( stristr( $qstr, $page_querystring ) ) {
+ $replacement = "$page_querystring=$pagenum";
+ $qstr = preg_replace("/".$page_querystring."[^\d]+\d+/", $replacement, $qstr);
+ // if we already have a mod_rewrite style page string
+ } elseif ( preg_match( '|'.$page_modregex.'\d+|', $qstr ) ){
+ $qstr = preg_replace('|'.$page_modregex.'\d+|',"$page_modstring$pagenum",$qstr);
+
+ // if we don't have a page string at all ...
+ // lets see what sort of URL we have...
+ } else {
+ // we need to know the way queries are being written
+ global $querystring_start, $querystring_equal, $querystring_separator;
+ // if there's a querystring_start (a "?" usually), it's deffinitely not mod_rewritten
+ if ( stristr( $qstr, $querystring_start ) ){
+ // so append the query string (using &, since we already have ?)
+ $qstr .= $querystring_separator.$page_querystring.$querystring_equal.$pagenum;
+ // otherwise, it could be rewritten, OR just the default index ...
+ } elseif( '' != get_settings('permalink_structure')) {
+ $qstr = preg_replace('|(.*)/[^/]*|', '$1/', $qstr).$page_modstring.$pagenum;
+ } else {
+ $qstr = get_settings('blogfilename') . $querystring_start.$page_querystring.$querystring_equal.$pagenum;
+ }
+ }
+
+ $home_root = str_replace('http://', '', trim(get_settings('home')));
+ $home_root = preg_replace('|([^/]*)(.*)|i', '$2', $home_root);
+ if ('/' != substr($home_root, -1)) $home_root = $home_root . '/';
+
+ $qstr = str_replace($home_root, '', $qstr);
+ return trailingslashit(get_settings('home')).$qstr;
+}
+
function next_posts($max_page = 0) { // original by cfactor at cooltux.org
global $p, $paged, $what_to_show, $pagenow;
global $querystring_start, $querystring_equal, $querystring_separator;
- if (empty($p) && ($what_to_show == 'paged')) {
- $qstr = $_SERVER['QUERY_STRING'];
- if (!empty($qstr)) {
- $qstr = preg_replace('/&paged=\d{0,}/', '', $qstr);
- $qstr = preg_replace('/paged=\d{0,}/', '', $qstr);
- } elseif (stristr($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'] )) {
- if ('' != $qstr = str_replace($_SERVER['SCRIPT_NAME'], '',
- $_SERVER['REQUEST_URI']) ) {
- $qstr = preg_replace('/^\//', '', $qstr);
- $qstr = preg_replace('/paged\/\d{0,}\//', '', $qstr);
- $qstr = preg_replace('/paged\/\d{0,}/', '', $qstr);
- $qstr = preg_replace('/\/$/', '', $qstr);
- }
- }
- if (!$paged) $paged = 1;
- $nextpage = intval($paged) + 1;
- if (!$max_page || $max_page >= $nextpage) {
- echo get_settings('home') .'/'.$pagenow.$querystring_start.
- ($qstr == '' ? '' : $qstr.$querystring_separator) .
- 'paged'.$querystring_equal.$nextpage;
- }
- }
+// if (empty($p) && ($what_to_show == 'paged')) {
+// $qstr = $_SERVER['QUERY_STRING'];
+// if (!empty($qstr)) {
+// $qstr = preg_replace('/&paged=\d{0,}/', '', $qstr);
+// $qstr = preg_replace('/paged=\d{0,}/', '', $qstr);
+// } elseif (stristr($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'] )) {
+// if ('' != $qstr = str_replace($_SERVER['SCRIPT_NAME'], '',
+// $_SERVER['REQUEST_URI']) ) {
+// $qstr = preg_replace('/^\//', '', $qstr);
+// $qstr = preg_replace('/paged\/\d{0,}\//', '', $qstr);
+// $qstr = preg_replace('/paged\/\d{0,}/', '', $qstr);
+// $qstr = preg_replace('/\/$/', '', $qstr);
+// }
+// }
+// if (!$paged) $paged = 1;
+// $nextpage = intval($paged) + 1;
+// if (!$max_page || $max_page >= $nextpage) {
+// echo get_settings('home') .'/'.$pagenow.$querystring_start.
+// ($qstr == '' ? '' : $qstr.$querystring_separator) .
+// 'paged'.$querystring_equal.$nextpage;
+// }
+// }
+
+ if (empty($p) && ($what_to_show == 'paged')) {
+ if (!$paged) $paged = 1;
+ $nextpage = intval($paged) + 1;
+ if (!$max_page || $max_page >= $nextpage) {
+ echo get_pagenum_link($nextpage);
+ }
+ }
}
function next_posts_link($label='Next Page »', $max_page=0) {
@@ -406,26 +454,32 @@ function next_posts_link($label='Next Page »', $max_page=0) {
function previous_posts() { // original by cfactor at cooltux.org
global $_SERVER, $p, $paged, $what_to_show, $pagenow;
global $querystring_start, $querystring_equal, $querystring_separator;
- if (empty($p) && ($what_to_show == 'paged')) {
- $qstr = $_SERVER['QUERY_STRING'];
- if (!empty($qstr)) {
- $qstr = preg_replace('/&paged=\d{0,}/', '', $qstr);
- $qstr = preg_replace('/paged=\d{0,}/', '', $qstr);
- } elseif (stristr($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'] )) {
- if ('' != $qstr = str_replace($_SERVER['SCRIPT_NAME'], '',
- $_SERVER['REQUEST_URI']) ) {
- $qstr = preg_replace('/^\//', '', $qstr);
- $qstr = preg_replace("/paged\/\d{0,}\//", '', $qstr);
- $qstr = preg_replace('/paged\/\d{0,}/', '', $qstr);
- $qstr = preg_replace('/\/$/', '', $qstr);
- }
- }
- $nextpage = intval($paged) - 1;
- if ($nextpage < 1) $nextpage = 1;
- echo get_settings('home') .'/'.$pagenow.$querystring_start.
- ($qstr == '' ? '' : $qstr.$querystring_separator) .
- 'paged'.$querystring_equal.$nextpage;
- }
+// if (empty($p) && ($what_to_show == 'paged')) {
+// $qstr = $_SERVER['QUERY_STRING'];
+// if (!empty($qstr)) {
+// $qstr = preg_replace('/&paged=\d{0,}/', '', $qstr);
+// $qstr = preg_replace('/paged=\d{0,}/', '', $qstr);
+// } elseif (stristr($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'] )) {
+// if ('' != $qstr = str_replace($_SERVER['SCRIPT_NAME'], '',
+// $_SERVER['REQUEST_URI']) ) {
+// $qstr = preg_replace('/^\//', '', $qstr);
+// $qstr = preg_replace("/paged\/\d{0,}\//", '', $qstr);
+// $qstr = preg_replace('/paged\/\d{0,}/', '', $qstr);
+// $qstr = preg_replace('/\/$/', '', $qstr);
+// }
+// }
+// $nextpage = intval($paged) - 1;
+// if ($nextpage < 1) $nextpage = 1;
+// echo get_settings('home') .'/'.$pagenow.$querystring_start.
+// ($qstr == '' ? '' : $qstr.$querystring_separator) .
+// 'paged'.$querystring_equal.$nextpage;
+// }
+
+ if (empty($p) && ($what_to_show == 'paged')) {
+ $nextpage = intval($paged) - 1;
+ if ($nextpage < 1) $nextpage = 1;
+ echo get_pagenum_link($nextpage);
+ }
}
function previous_posts_link($label='« Previous Page') {