[wp-cvs] wordpress/wp-includes functions.php, 1.107,
1.108 template-functions-links.php, 1.12,
1.13 template-functions-post.php, 1.23, 1.24
Ryan Boren
rboren at users.sourceforge.net
Mon May 31 12:22:27 CDT 2004
Update of /cvsroot/cafelog/wordpress/wp-includes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15045/wp-includes
Modified Files:
functions.php template-functions-links.php
template-functions-post.php
Log Message:
Revamp rewrite rule generation. Add clean page links. Credit to Jaykul for get_pagenum_link().
Index: template-functions-links.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-includes/template-functions-links.php,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** template-functions-links.php 24 May 2004 08:22:18 -0000 1.12
--- template-functions-links.php 31 May 2004 17:22:25 -0000 1.13
***************
*** 84,90 ****
if (!$month) $month = gmdate('m', time()+(get_settings('gmt_offset') * 3600));
if ('' != get_settings('permalink_structure')) {
! $off = strpos(get_settings('permalink_structure'), '%monthnum%');
$offset = $off + 11;
! $monthlink = substr(get_settings('permalink_structure'), 0, $offset);
if ('/' != substr($monthlink, -1)) $monthlink = substr($monthlink, 0, -1);
$monthlink = str_replace('%year%', $year, $monthlink);
--- 84,99 ----
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')) ) {
! $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);
***************
*** 103,109 ****
if (!$day) $day = gmdate('j', time()+(get_settings('gmt_offset') * 3600));
if ('' != get_settings('permalink_structure')) {
! $off = strpos(get_settings('permalink_structure'), '%day%');
$offset = $off + 6;
! $daylink = substr(get_settings('permalink_structure'), 0, $offset);
if ('/' != substr($daylink, -1)) $daylink = substr($daylink, 0, -1);
$daylink = str_replace('%year%', $year, $daylink);
--- 112,127 ----
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')) ) {
! $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);
Index: functions.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-includes/functions.php,v
retrieving revision 1.107
retrieving revision 1.108
diff -C2 -d -r1.107 -r1.108
*** functions.php 27 May 2004 13:53:27 -0000 1.107
--- functions.php 31 May 2004 17:22:25 -0000 1.108
***************
*** 1207,1218 ****
$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]+)?'
);
--- 1207,1218 ----
$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]+)'
);
***************
*** 1229,1273 ****
);
! $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;
!
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) {
if (0 < $i) {
! $query .= '&';
! $feedquery .= '&';
! $trackbackquery .= '&';
}
$query_token = str_replace($rewritecode, $queryreplace, $tokens[0][$i]) . preg_index($i+1, $matches);
! $query .= $query_token;
! $feedquery .= $query_token;
! $trackbackquery .= $query_token;
}
- ++$i;
! // Add post paged stuff
! $match .= '([0-9]+)?/?$';
! $query .= '&page=' . preg_index($i, $matches);
! // Add post feed stuff
! $feedregex = '(feed|rdf|rss|rss2|atom)/?$';
! $feedmatch .= $feedregex;
! $feedquery .= '&feed=' . preg_index($i, $matches);
! // Add post trackback stuff
! $trackbackregex = 'trackback/?$';
! $trackbackmatch .= $trackbackregex;
// Site feed
--- 1229,1302 ----
);
+ $feedregex = '(feed|rdf|rss|rss2|atom)/?$';
+ $trackbackregex = 'trackback/?$';
+ $pageregex = 'page/?([0-9]{1,})/?$';
! $front = substr($permalink_structure, 0, strpos($permalink_structure, '%'));
preg_match_all('/%.+?%/', $permalink_structure, $tokens);
! $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) {
! $queries[$i] = $queries[$i - 1] . '&';
}
$query_token = str_replace($rewritecode, $queryreplace, $tokens[0][$i]) . preg_index($i+1, $matches);
! $queries[$i] .= $query_token;
}
! $structure = str_replace($front, '', $permalink_structure);
! $structure = trim($structure, '/');
! $dirs = explode('/', $structure);
! $num_dirs = count($dirs);
! $front = preg_replace('|^/+|', '', $front);
! $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
***************
*** 1275,1284 ****
$sitefeedquery = 'wp-feed.php?feed=' . 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, '%'));
if ( '' == get_settings('category_base') )
$catmatch = $front . 'category/';
--- 1304,1315 ----
$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.
if ( '' == get_settings('category_base') )
$catmatch = $front . 'category/';
***************
*** 1290,1293 ****
--- 1321,1327 ----
$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);
***************
*** 1299,1317 ****
$authorfeedquery = 'wp-feed.php?author_name=' . preg_index(1, $matches) . '&feed=' . preg_index(2, $matches);
$authormatch = $authormatch . '?(.*)';
$authorquery = 'index.php?author_name=' . preg_index(1, $matches);
$rewrite = array(
$catfeedmatch => $catfeedquery,
$catmatch => $catquery,
$authorfeedmatch => $authorfeedquery,
! $authormatch => $authorquery,
! $match => $query,
! $feedmatch => $feedquery,
! $trackbackmatch => $trackbackquery,
! $sitefeedmatch => $sitefeedquery,
! $sitecommentfeedmatch => $sitecommentfeedquery
);
return $rewrite;
}
--- 1333,1360 ----
$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,
! $authorpagematch => $authorpagequery,
! $authormatch => $authorquery
);
+ $rewrite = $rewrite + $post_rewrite;
+
+ if ($doarchive) {
+ $rewrite = $rewrite + array($archivematch => $archivequery);
+ }
+
return $rewrite;
}
Index: template-functions-post.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-includes/template-functions-post.php,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** template-functions-post.php 24 May 2004 08:22:18 -0000 1.23
--- template-functions-post.php 31 May 2004 17:22:25 -0000 1.24
***************
*** 351,379 ****
}
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;
! }
! }
}
--- 351,427 ----
}
+ 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')) {
! if (!$paged) $paged = 1;
! $nextpage = intval($paged) + 1;
! if (!$max_page || $max_page >= $nextpage) {
! echo get_pagenum_link($nextpage);
! }
! }
}
***************
*** 407,430 ****
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;
! }
}
--- 455,484 ----
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')) {
! $nextpage = intval($paged) - 1;
! if ($nextpage < 1) $nextpage = 1;
! echo get_pagenum_link($nextpage);
! }
}
More information about the cvs
mailing list