Ticket #13939: get_page_of_comment.2.diff
| File get_page_of_comment.2.diff, 4.4 KB (added by , 16 years ago) |
|---|
-
wp-includes/comment.php
703 703 * @return int|null Comment page number or null on error. 704 704 */ 705 705 function get_page_of_comment( $comment_ID, $args = array() ) { 706 global $wpdb ;706 global $wpdb, $user_ID; 707 707 708 708 if ( !$comment = get_comment( $comment_ID ) ) 709 709 return; … … 712 712 $args = wp_parse_args( $args, $defaults ); 713 713 714 714 if ( '' === $args['per_page'] && get_option('page_comments') ) 715 $args['per_page'] = get_ query_var('comments_per_page');715 $args['per_page'] = get_option('comments_per_page'); 716 716 if ( empty($args['per_page']) ) { 717 717 $args['per_page'] = 0; 718 718 $args['page'] = 0; 719 719 } 720 720 if ( $args['per_page'] < 1 ) 721 return 1; 721 return 1; // apply_filters ? 722 722 723 723 if ( '' === $args['max_depth'] ) { 724 724 if ( get_option('thread_comments') ) … … 731 731 if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent ) 732 732 return get_page_of_comment( $comment->comment_parent, $args ); 733 733 734 // wp_list_comments allows: all, comment, trackback, pingback, and pings 734 735 $allowedtypes = array( 735 736 'comment' => '', 736 737 'pingback' => 'pingback', 737 738 'trackback' => 'trackback', 738 739 ); 739 740 740 $comtypewhere = ( 'all' != $args['type'] && isset($allowedtypes[$args['type']]) ) ? " AND comment_type = '" . $allowedtypes[$args['type']] . "'" : ''; 741 $comtypewhere = ( 'all' != $args['type'] && 'pings' != $args['type'] && isset($allowedtypes[$args['type']]) ) ? " AND comment_type = '" . $allowedtypes[$args['type']] . "'" : ''; 742 if ( 'pings' == $args['type'] ) $comtypewhere = " AND (comment_type = 'pingback' OR comment_type = 'trackback')"; 741 743 744 if ( $args['max_depth'] > 1 ) 745 $where_comment_parent = ' AND comment_parent = 0'; 746 else 747 $where_comment_parent = ''; 748 749 /** 750 * Comment author information fetched from the comment cookies. 751 * 752 * @uses wp_get_current_commenter() 753 */ 754 $commenter = wp_get_current_commenter(); 755 756 /** 757 * The name of the current comment author escaped for use in attributes. 758 */ 759 $comment_author = $commenter['comment_author']; // Escaped by sanitize_comment_cookies() 760 761 /** 762 * The email address of the current comment author escaped for use in attributes. 763 */ 764 $comment_author_email = $commenter['comment_author_email']; // Escaped by sanitize_comment_cookies() 765 742 766 // Count comments older than this one 743 $oldercoms = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = 0 AND comment_approved = '1' AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt ) ); 767 // Partially copied from the comments_template function 768 if ( $user_ID ) 769 $prepared = $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d" . $where_comment_parent . " AND (comment_approved = '1' OR (user_id = %d AND comment_approved = '0')) AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $user_ID, $comment->comment_date_gmt ); 770 else if ( empty($comment_author) ) 771 $prepared = $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d" . $where_comment_parent . " AND comment_approved = '1' AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt ); 772 else 773 $prepared = $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d" . $where_comment_parent . " AND (comment_approved = '1' OR (comment_author = %s AND comment_author_email = %s AND comment_approved = '0')) AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, wp_specialchars_decode($comment_author,ENT_QUOTES), $comment_author_email, $comment->comment_date_gmt ); 744 774 745 // No older comments? Then it's page #1. 746 if ( 0 == $oldercoms ) 747 return 1; 775 $oldercoms = $wpdb->get_var( $prepared ); 748 776 749 // Divide comments older than this one by comments per page to get this comment's page number 750 return ceil( ( $oldercoms + 1 ) / $args['per_page'] ); 777 if ( 0 == $oldercoms ) { 778 // No older comments? Then it's page #1. 779 $page = 1; 780 } 781 else { 782 // Divide comments older than this one by comments per page to get this comment's page number 783 $page = ceil( ( $oldercoms + 1 ) / $args['per_page'] ); 784 } 785 786 return apply_filters( 'get_page_of_comment', $page, $args ); 751 787 } 752 788 753 789 /**
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)