Fix for strange slash nav errors for paged nice links, and validation fixes.

git-svn-id: https://develop.svn.wordpress.org/trunk@1383 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Matt Mullenweg 2004-06-02 07:44:43 +00:00
parent 640004f5ca
commit 4530008ec8
2 changed files with 195 additions and 236 deletions

View File

@ -227,4 +227,199 @@ function edit_comment_link($link = 'Edit This', $before = '', $after = '') {
echo "$before <a href='$location'>$link</a> $after"; echo "$before <a href='$location'>$link</a> $after";
} }
// Navigation links
function previous_post($format='%', $previous='previous post: ', $title='yes', $in_same_cat='no', $limitprev=1, $excluded_categories='') {
global $id, $post, $wpdb;
global $p, $posts, $posts_per_page, $s, $single;
global $querystring_start, $querystring_equal, $querystring_separator;
if(($p) || ($posts_per_page == 1) || 1 == $single) {
$current_post_date = $post->post_date;
$current_category = $post->post_category;
$sqlcat = '';
if ($in_same_cat != 'no') {
$sqlcat = " AND post_category = '$current_category' ";
}
$sql_exclude_cats = '';
if (!empty($excluded_categories)) {
$blah = explode('and', $excluded_categories);
foreach($blah as $category) {
$category = intval($category);
$sql_exclude_cats .= " AND post_category != $category";
}
}
$limitprev--;
$lastpost = @$wpdb->get_row("SELECT ID, post_title FROM $wpdb->posts WHERE post_date < '$current_post_date' AND post_status = 'publish' $sqlcat $sql_exclude_cats ORDER BY post_date DESC LIMIT $limitprev, 1");
if ($lastpost) {
$string = '<a href="'.get_permalink($lastpost->ID).'">'.$previous;
if ($title == 'yes') {
$string .= wptexturize(stripslashes($lastpost->post_title));
}
$string .= '</a>';
$format = str_replace('%', $string, $format);
echo $format;
}
}
}
function next_post($format='%', $next='next post: ', $title='yes', $in_same_cat='no', $limitnext=1, $excluded_categories='') {
global $posts_per_page, $post, $wpdb, $single;
if(1 == $posts_per_page || 1 == $single) {
$current_post_date = $post->post_date;
$current_category = $post->post_category;
$sqlcat = '';
if ($in_same_cat != 'no') {
$sqlcat = " AND post_category='$current_category' ";
}
$sql_exclude_cats = '';
if (!empty($excluded_categories)) {
$blah = explode('and', $excluded_categories);
foreach($blah as $category) {
$category = intval($category);
$sql_exclude_cats .= " AND post_category != $category";
}
}
$now = current_time('mysql');
$limitnext--;
$nextpost = @$wpdb->get_row("SELECT ID,post_title FROM $wpdb->posts WHERE post_date > '$current_post_date' AND post_date < '$now' AND post_status = 'publish' $sqlcat $sql_exclude_cats AND ID != $post->ID ORDER BY post_date ASC LIMIT $limitnext,1");
if ($nextpost) {
$string = '<a href="'.get_permalink($nextpost->ID).'">'.$next;
if ($title=='yes') {
$string .= wptexturize(stripslashes($nextpost->post_title));
}
$string .= '</a>';
$format = str_replace('%', $string, $format);
echo $format;
}
}
}
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', '/', $home_root);
$qstr = str_replace($home_root . '/', '', $qstr);
$qstr = preg_replace('|^/+|', '', $qstr);
return preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', 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')) {
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 &raquo;', $max_page=0) {
global $p, $paged, $result, $request, $posts_per_page, $what_to_show, $wpdb;
if ($what_to_show == 'paged') {
if (!$max_page) {
$nxt_request = $request;
//if the query includes a limit clause, call it again without that
//limit clause!
if ($pos = strpos(strtoupper($request), 'LIMIT')) {
$nxt_request = substr($request, 0, $pos);
}
$nxt_result = $wpdb->query($nxt_request);
$numposts = $wpdb->num_rows;
$max_page = ceil($numposts / $posts_per_page);
}
if (!$paged)
$paged = 1;
$nextpage = intval($paged) + 1;
if (empty($p) && (empty($paged) || $nextpage <= $max_page)) {
echo '<a href="';
next_posts($max_page);
echo '">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>';
}
}
}
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')) {
$nextpage = intval($paged) - 1;
if ($nextpage < 1) $nextpage = 1;
echo get_pagenum_link($nextpage);
}
}
function previous_posts_link($label='&laquo; Previous Page') {
global $p, $paged, $what_to_show;
if (empty($p) && ($paged > 1) && ($what_to_show == 'paged')) {
echo '<a href="';
previous_posts();
echo '">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>';
}
}
function posts_nav_link($sep=' &#8212; ', $prelabel='&laquo; Previous Page', $nxtlabel='Next Page &raquo;') {
global $p, $what_to_show, $request, $posts_per_page, $wpdb;
if (empty($p) && ($what_to_show == 'paged')) {
$nxt_request = $request;
if ($pos = strpos(strtoupper($request), 'LIMIT')) {
$nxt_request = substr($request, 0, $pos);
}
$nxt_result = $wpdb->query($nxt_request);
$numposts = $wpdb->num_rows;
$max_page = ceil($numposts / $posts_per_page);
if ($max_page > 1) {
previous_posts_link($prelabel);
echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $sep);
next_posts_link($nxtlabel, $max_page);
}
}
}
?> ?>

View File

@ -273,242 +273,6 @@ function link_pages($before='<br />', $after='<br />', $next_or_number='number',
} }
} }
function previous_post($format='%', $previous='previous post: ', $title='yes', $in_same_cat='no', $limitprev=1, $excluded_categories='') {
global $id, $post, $wpdb;
global $p, $posts, $posts_per_page, $s, $single;
global $querystring_start, $querystring_equal, $querystring_separator;
if(($p) || ($posts_per_page == 1) || 1 == $single) {
$current_post_date = $post->post_date;
$current_category = $post->post_category;
$sqlcat = '';
if ($in_same_cat != 'no') {
$sqlcat = " AND post_category = '$current_category' ";
}
$sql_exclude_cats = '';
if (!empty($excluded_categories)) {
$blah = explode('and', $excluded_categories);
foreach($blah as $category) {
$category = intval($category);
$sql_exclude_cats .= " AND post_category != $category";
}
}
$limitprev--;
$lastpost = @$wpdb->get_row("SELECT ID, post_title FROM $wpdb->posts WHERE post_date < '$current_post_date' AND post_status = 'publish' $sqlcat $sql_exclude_cats ORDER BY post_date DESC LIMIT $limitprev, 1");
if ($lastpost) {
$string = '<a href="'.get_permalink($lastpost->ID).'">'.$previous;
if ($title == 'yes') {
$string .= wptexturize(stripslashes($lastpost->post_title));
}
$string .= '</a>';
$format = str_replace('%', $string, $format);
echo $format;
}
}
}
function next_post($format='%', $next='next post: ', $title='yes', $in_same_cat='no', $limitnext=1, $excluded_categories='') {
global $posts_per_page, $post, $wpdb, $single;
if(1 == $posts_per_page || 1 == $single) {
$current_post_date = $post->post_date;
$current_category = $post->post_category;
$sqlcat = '';
if ($in_same_cat != 'no') {
$sqlcat = " AND post_category='$current_category' ";
}
$sql_exclude_cats = '';
if (!empty($excluded_categories)) {
$blah = explode('and', $excluded_categories);
foreach($blah as $category) {
$category = intval($category);
$sql_exclude_cats .= " AND post_category != $category";
}
}
$now = current_time('mysql');
$limitnext--;
$nextpost = @$wpdb->get_row("SELECT ID,post_title FROM $wpdb->posts WHERE post_date > '$current_post_date' AND post_date < '$now' AND post_status = 'publish' $sqlcat $sql_exclude_cats AND ID != $post->ID ORDER BY post_date ASC LIMIT $limitnext,1");
if ($nextpost) {
$string = '<a href="'.get_permalink($nextpost->ID).'">'.$next;
if ($title=='yes') {
$string .= wptexturize(stripslashes($nextpost->post_title));
}
$string .= '</a>';
$format = str_replace('%', $string, $format);
echo $format;
}
}
}
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);
}
}
}
function next_posts_link($label='Next Page &raquo;', $max_page=0) {
global $p, $paged, $result, $request, $posts_per_page, $what_to_show, $wpdb;
if ($what_to_show == 'paged') {
if (!$max_page) {
$nxt_request = $request;
//if the query includes a limit clause, call it again without that
//limit clause!
if ($pos = strpos(strtoupper($request), 'LIMIT')) {
$nxt_request = substr($request, 0, $pos);
}
$nxt_result = $wpdb->query($nxt_request);
$numposts = $wpdb->num_rows;
$max_page = ceil($numposts / $posts_per_page);
}
if (!$paged)
$paged = 1;
$nextpage = intval($paged) + 1;
if (empty($p) && (empty($paged) || $nextpage <= $max_page)) {
echo '<a href="';
next_posts($max_page);
echo '">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>';
}
}
}
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')) {
$nextpage = intval($paged) - 1;
if ($nextpage < 1) $nextpage = 1;
echo get_pagenum_link($nextpage);
}
}
function previous_posts_link($label='&laquo; Previous Page') {
global $p, $paged, $what_to_show;
if (empty($p) && ($paged > 1) && ($what_to_show == 'paged')) {
echo '<a href="';
previous_posts();
echo '">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>';
}
}
function posts_nav_link($sep=' :: ', $prelabel='<< Previous Page', $nxtlabel='Next Page >>') {
global $p, $what_to_show, $request, $posts_per_page, $wpdb;
if (empty($p) && ($what_to_show == 'paged')) {
$nxt_request = $request;
if ($pos = strpos(strtoupper($request), 'LIMIT')) {
$nxt_request = substr($request, 0, $pos);
}
$nxt_result = $wpdb->query($nxt_request);
$numposts = $wpdb->num_rows;
$max_page = ceil($numposts / $posts_per_page);
if ($max_page > 1) {
previous_posts_link($prelabel);
echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $sep);
next_posts_link($nxtlabel, $max_page);
}
}
}
/* /*
* Post-meta: Custom per-post fields. * Post-meta: Custom per-post fields.
*/ */