mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
git-svn-id: https://develop.svn.wordpress.org/trunk@8961 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
+50
-13
@@ -26,7 +26,7 @@ class WP {
|
||||
* @access public
|
||||
* @var array
|
||||
*/
|
||||
var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term');
|
||||
var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage');
|
||||
|
||||
/**
|
||||
* Private query variables.
|
||||
@@ -36,7 +36,7 @@ class WP {
|
||||
* @since 2.0.0
|
||||
* @var array
|
||||
*/
|
||||
var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm');
|
||||
var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm', 'comments_per_page');
|
||||
|
||||
/**
|
||||
* Extra query variables set by the user.
|
||||
@@ -730,6 +730,15 @@ class Walker {
|
||||
*/
|
||||
var $db_fields;
|
||||
|
||||
/**
|
||||
* Max number of pages walked by the paged walker
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @var int
|
||||
* @access protected
|
||||
*/
|
||||
var $max_pages = 1;
|
||||
|
||||
/**
|
||||
* Starts the list before the elements are added.
|
||||
*
|
||||
@@ -947,7 +956,7 @@ class Walker {
|
||||
function paged_walk( $elements, $max_depth, $page_num, $per_page ) {
|
||||
|
||||
/* sanity check */
|
||||
if ( empty($elements) || $max_depth < 0 )
|
||||
if ( empty($elements) || $max_depth < -1 )
|
||||
return '';
|
||||
|
||||
$args = array_slice( func_get_args(), 4 );
|
||||
@@ -956,6 +965,38 @@ class Walker {
|
||||
$id_field = $this->db_fields['id'];
|
||||
$parent_field = $this->db_fields['parent'];
|
||||
|
||||
$count = -1;
|
||||
if ( -1 == $max_depth )
|
||||
$total_top = count( $elements );
|
||||
if ( $page_num < 1 || $per_page < 0 ) {
|
||||
// No paging
|
||||
$paging = false;
|
||||
$start = 0;
|
||||
if ( -1 == $max_depth )
|
||||
$end = $total_top;
|
||||
$this->max_pages = 1;
|
||||
} else {
|
||||
$paging = true;
|
||||
$start = ( (int)$page_num - 1 ) * (int)$per_page;
|
||||
$end = $start + $per_page;
|
||||
if ( -1 == $max_depth )
|
||||
$this->max_pages = ceil($total_top / $per_page);
|
||||
}
|
||||
|
||||
// flat display
|
||||
if ( -1 == $max_depth ) {
|
||||
$empty_array = array();
|
||||
foreach ( $elements as $e ) {
|
||||
$count++;
|
||||
if ( $count < $start )
|
||||
continue;
|
||||
if ( $count >= $end )
|
||||
break;
|
||||
$this->display_element( $e, $empty_array, 1, 0, $args, $output );
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/*
|
||||
* seperate elements into two buckets: top level and children elements
|
||||
* children_elements is two dimensional array, eg.
|
||||
@@ -970,15 +1011,10 @@ class Walker {
|
||||
$children_elements[ $e->$parent_field ][] = $e;
|
||||
}
|
||||
|
||||
$count = -1;
|
||||
$total_top = count( $top_level_elements );
|
||||
if ( $page_num < 1 || $per_page < 0 ) {
|
||||
$start = 0;
|
||||
$end = $total_top;
|
||||
} else {
|
||||
$start = ( (int)$page_num - 1 ) * (int)$per_page;
|
||||
$end = $start + $per_page;
|
||||
}
|
||||
|
||||
if ( $paging )
|
||||
$this->max_pages = ceil($total_top / $per_page);
|
||||
|
||||
foreach( $top_level_elements as $e ){
|
||||
$count++;
|
||||
@@ -996,7 +1032,7 @@ class Walker {
|
||||
$this->display_element( $e, $children_elements, $max_depth, 0, $args, $output );
|
||||
}
|
||||
|
||||
if ( $end >= $total_top && count( $children_elements ) > 0 ){
|
||||
if ( $end >= $total_top && count( $children_elements ) > 0 ) {
|
||||
$empty_array = array();
|
||||
foreach ( $children_elements as $orphans )
|
||||
foreach( $orphans as $op )
|
||||
@@ -1030,7 +1066,8 @@ class Walker {
|
||||
foreach ( (array)$children_elements[$id] as $child )
|
||||
$this->unset_children( $child, $children_elements );
|
||||
|
||||
unset( $children_elements[$id] );
|
||||
if ( isset($children_elements[$id]) )
|
||||
unset( $children_elements[$id] );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -850,7 +850,7 @@ function comment_reply_link($args = array(), $comment = null, $post = null) {
|
||||
|
||||
$args = wp_parse_args($args, $defaults);
|
||||
|
||||
if ( 0 == $args['depth'] || $args['max_depth'] < $args['depth'] )
|
||||
if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] )
|
||||
return;
|
||||
|
||||
extract($args, EXTR_SKIP);
|
||||
@@ -973,15 +973,34 @@ class Walker_Comment extends Walker {
|
||||
* @uses Walker_Comment
|
||||
*
|
||||
* @param $args string|array Formatting options
|
||||
* @param $comments array Optional array of comment objects. Defaults to $wp_query->comments
|
||||
* @param $comments array Optional array of comment objects. Defaults to $wp_query->comments
|
||||
*/
|
||||
function wp_list_comments($args = array(), $comments = null ) {
|
||||
global $wp_query;
|
||||
|
||||
$defaults = array('walker' => null, 'depth' => 3, 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all');
|
||||
$defaults = array('walker' => null, 'depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all',
|
||||
'page' => get_query_var('cpage'), 'per_page' => '');
|
||||
|
||||
$r = wp_parse_args( $args, $defaults );
|
||||
|
||||
if ( '' === $r['per_page'] && get_option('page_comments') )
|
||||
$r['per_page'] = get_query_var('comments_per_page');
|
||||
|
||||
if ( empty($r['per_page']) ) {
|
||||
$r['page'] = 0;
|
||||
} else {
|
||||
$r['page'] = intval($r['page']);
|
||||
if ( empty($r['page']) )
|
||||
$r['page'] = 1;
|
||||
}
|
||||
|
||||
if ( '' === $r['depth'] ) {
|
||||
if ( get_option('thread_comments') )
|
||||
$r['depth'] = get_option('thread_comments_depth');
|
||||
else
|
||||
$r['depth'] = -1;
|
||||
}
|
||||
|
||||
extract( $r, EXTR_SKIP );
|
||||
|
||||
if ( empty($walker) )
|
||||
@@ -995,19 +1014,25 @@ function wp_list_comments($args = array(), $comments = null ) {
|
||||
$wp_query->comments_by_type = &separate_comments($wp_query->comments);
|
||||
if ( empty($wp_query->comments_by_type[$type]) )
|
||||
return;
|
||||
return $walker->walk($wp_query->comments_by_type[$type], $depth, $r);
|
||||
$walker->paged_walk($wp_query->comments_by_type[$type], $depth, $page, $per_page, $r);
|
||||
$wp_query->max_num_comment_pages = $walker->max_pages;
|
||||
return;
|
||||
}
|
||||
$walker->walk($wp_query->comments, $depth, $r);
|
||||
$walker->paged_walk($wp_query->comments, $depth, $page, $per_page, $r);
|
||||
$wp_query->max_num_comment_pages = $walker->max_pages;
|
||||
} else {
|
||||
if ( empty($comments) )
|
||||
return;
|
||||
if ( 'all' != $type ) {
|
||||
$comments_by_type = separate_comments($comments);
|
||||
$comments_by_type = &separate_comments($comments);
|
||||
if ( empty($comments_by_type[$type]) )
|
||||
return;
|
||||
return $walker->walk($comments_by_type[$type], $depth, $r);
|
||||
$walker->paged_walk($comments_by_type[$type], $depth, $page, $per_page, $r);
|
||||
$wp_query->max_num_comment_pages = $walker->max_pages;
|
||||
return;
|
||||
}
|
||||
$walker->walk($comments, $depth, $r);
|
||||
$walker->paged_walk($comments, $depth, $page, $per_page, $r);
|
||||
$wp_query->max_num_comment_pages = $walker->max_pages;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1820,6 +1820,9 @@ function sanitize_option($option, $value) {
|
||||
case 'default_category':
|
||||
case 'default_email_category':
|
||||
case 'default_link_category':
|
||||
case 'close_comments_days_old':
|
||||
case 'comments_per_page':
|
||||
case 'thread_comments_depth':
|
||||
$value = abs((int) $value);
|
||||
break;
|
||||
|
||||
|
||||
@@ -793,6 +793,84 @@ function posts_nav_link($sep=' — ', $prelabel='« Previous Page', $nx
|
||||
}
|
||||
}
|
||||
|
||||
function get_comments_pagenum_link($pagenum = 1) {
|
||||
global $wp_rewrite;
|
||||
|
||||
$pagenum = (int) $pagenum;
|
||||
|
||||
$request = remove_query_arg( 'cpage' );
|
||||
|
||||
$home_root = parse_url(get_option('home'));
|
||||
$home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
|
||||
$home_root = preg_quote( trailingslashit( $home_root ), '|' );
|
||||
|
||||
$request = preg_replace('|^'. $home_root . '|', '', $request);
|
||||
$request = preg_replace('|^/+|', '', $request);
|
||||
|
||||
$base = trailingslashit( get_bloginfo( 'home' ) );
|
||||
|
||||
if ( $pagenum > 1 ) {
|
||||
$result = add_query_arg( 'cpage', $pagenum, $base . $request );
|
||||
} else {
|
||||
$result = $base . $request;
|
||||
}
|
||||
|
||||
$result = apply_filters('get_comments_pagenum_link', $result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function next_comments_link($label='', $max_page = 0) {
|
||||
global $wp_query;
|
||||
|
||||
if ( !is_singular() )
|
||||
return;
|
||||
|
||||
$page = get_query_var('cpage');
|
||||
|
||||
if ( !$page )
|
||||
$page = 1;
|
||||
|
||||
if ( !$page )
|
||||
$page = 1;
|
||||
|
||||
$nextpage = intval($page) + 1;
|
||||
|
||||
if ( empty($max_page) )
|
||||
$max_page = $wp_query->max_num_comment_pages;
|
||||
|
||||
if ( $nextpage > $max_page )
|
||||
return;
|
||||
|
||||
if ( empty($label) )
|
||||
$label = __('» Newer Comments');
|
||||
|
||||
echo '<a href="' . clean_url(get_comments_pagenum_link($nextpage));
|
||||
$attr = apply_filters( 'next_comments_link_attributes', '' );
|
||||
echo "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
|
||||
}
|
||||
|
||||
function previous_comments_link($label='') {
|
||||
global $wp_query;
|
||||
|
||||
if ( !is_singular() )
|
||||
return;
|
||||
|
||||
$page = get_query_var('cpage');
|
||||
|
||||
if ( $page <= 1 )
|
||||
return;
|
||||
|
||||
$nextpage = intval($page) - 1;
|
||||
|
||||
if ( empty($label) )
|
||||
$label = __('« Older Comments');
|
||||
|
||||
echo '<a href="' . clean_url(get_comments_pagenum_link($nextpage));
|
||||
$attr = apply_filters( 'previous_comments_link_attributes', '' );
|
||||
echo "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
|
||||
}
|
||||
|
||||
function get_shortcut_link() {
|
||||
$link = "javascript:
|
||||
var d=document,
|
||||
|
||||
@@ -843,6 +843,15 @@ class WP_Query {
|
||||
*/
|
||||
var $max_num_pages = 0;
|
||||
|
||||
/**
|
||||
* The amount of comment pages.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @access public
|
||||
* @var int
|
||||
*/
|
||||
var $max_num_comment_pages = 0;
|
||||
|
||||
/**
|
||||
* Set if query is single post.
|
||||
*
|
||||
@@ -1612,6 +1621,9 @@ class WP_Query {
|
||||
else if ( $q['posts_per_page'] == 0 )
|
||||
$q['posts_per_page'] = 1;
|
||||
|
||||
if ( !isset($q['comments_per_page']) || $q['comments_per_page'] == 0 )
|
||||
$q['comments_per_page'] = get_option('comments_per_page');
|
||||
|
||||
if ( $this->is_home && (empty($this->query) || $q['preview'] == 'true') && ( 'page' == get_option('show_on_front') ) && get_option('page_on_front') ) {
|
||||
$this->is_page = true;
|
||||
$this->is_home = false;
|
||||
|
||||
Reference in New Issue
Block a user