Changeset 9808
- Timestamp:
- 11/20/2008 06:41:55 AM (17 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/comment-template.php
r9781 r9808 442 442 * 443 443 * @param object|string|int $comment Comment to retrieve. 444 * @param string|int $page The comment's page if known. Optional. Avoids extra database query.444 * @param array $args Optional args. 445 445 * @return string The permalink to the current comment 446 446 */ 447 function get_comment_link( $comment = null, $ page = null) {448 global $wp_rewrite ;447 function get_comment_link( $comment = null, $args = array() ) { 448 global $wp_rewrite, $in_comment_loop; 449 449 450 450 $comment = get_comment($comment); 451 451 452 if ( get_option('page_comments') ) { 453 $page = ( null !== $page ) ? (int) $page : get_page_of_comment( $comment->comment_ID ); 452 // Backwards compat 453 if ( !is_array($args) ) { 454 $page = $args; 455 $args = array(); 456 $args['page'] = $page; 457 } 458 459 $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' ); 460 $args = wp_parse_args( $args, $defaults ); 461 462 if ( '' === $args['per_page'] && get_option('page_comments') ) 463 $args['per_page'] = get_query_var('comments_per_page'); 464 465 if ( empty($args['per_page']) ) { 466 $args['per_page'] = 0; 467 $args['page'] = 0; 468 } 469 470 if ( $args['per_page'] ) { 471 if ( '' == $args['page'] ) 472 $args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args ); 454 473 455 474 if ( $wp_rewrite->using_permalinks() ) 456 return user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . "comment-page-$page", 'comment' ) . '#comment-' . $comment->comment_ID;475 return user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . 'comment-page-' . $args['page'], 'comment' ) . '#comment-' . $comment->comment_ID; 457 476 else 458 return add_query_arg( 'cpage', $ page, get_permalink( $comment->comment_post_ID ) ) . '#comment-' . $comment->comment_ID;477 return add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) ) . '#comment-' . $comment->comment_ID; 459 478 } else { 460 479 return get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID; … … 1163 1182 <?php endif; ?> 1164 1183 1165 <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID , $page) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date('F jS, Y'), get_comment_time()) ?></a><?php edit_comment_link('edit',' ','') ?></div>1184 <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date('F jS, Y'), get_comment_time()) ?></a><?php edit_comment_link('edit',' ','') ?></div> 1166 1185 1167 1186 <?php comment_text() ?> … … 1210 1229 */ 1211 1230 function wp_list_comments($args = array(), $comments = null ) { 1212 global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage; 1231 global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop; 1232 1233 $in_comment_loop = true; 1213 1234 1214 1235 $comment_alt = $comment_thread_alt = 0; … … 1286 1307 $walker->paged_walk($_comments, $max_depth, $page, $per_page, $r); 1287 1308 $wp_query->max_num_comment_pages = $walker->max_pages; 1309 1310 $in_comment_loop = false; 1288 1311 } 1289 1312 -
trunk/wp-includes/comment.php
r9782 r9808 549 549 * 550 550 * @param int $comment_ID Comment ID. 551 * @param int $per_page Optional comments per page.551 * @param array $args Optional args. 552 552 * @return int|null Comment page number or null on error. 553 553 */ 554 function get_page_of_comment( $comment_ID, $ per_page = null, $threaded = null) {554 function get_page_of_comment( $comment_ID, $args = array() ) { 555 555 global $wpdb; 556 556 … … 558 558 return; 559 559 560 if ( !get_option('page_comments') ) 560 $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' ); 561 $args = wp_parse_args( $args, $defaults ); 562 563 if ( '' === $args['per_page'] && get_option('page_comments') ) 564 $args['per_page'] = get_query_var('comments_per_page'); 565 if ( empty($args['per_page']) ) { 566 $args['per_page'] = 0; 567 $args['page'] = 0; 568 } 569 if ( $args['per_page'] < 1 ) 561 570 return 1; 562 571 563 if ( null === $per_page ) 564 $per_page = get_option('comments_per_page'); 565 566 if ( null === $threaded ) 567 $threaded = get_option('thread_comments'); 572 if ( '' === $args['max_depth'] ) { 573 if ( get_option('thread_comments') ) 574 $args['max_depth'] = get_option('thread_comments_depth'); 575 else 576 $args['max_depth'] = -1; 577 } 568 578 569 579 // Find this comment's top level parent if threading is enabled 570 if ( $threaded && 0 != $comment->comment_parent ) 571 return get_page_of_comment( $comment->comment_parent, $per_page, $threaded ); 580 if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent ) 581 return get_page_of_comment( $comment->comment_parent, $args ); 582 583 $allowedtypes = array( 584 'comment' => '', 585 'pingback' => 'pingback', 586 'trackback' => 'trackback', 587 ); 588 589 $comtypewhere = ( 'all' != $args['type'] && isset($allowedtypes[$args['type']]) ) ? " AND comment_type = '" . $allowedtypes[$args['type']] . "'" : ''; 572 590 573 591 // Count comments older than this one 574 $oldercoms = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = 0 AND comment_date_gmt < '%s'" , $comment->comment_post_ID, $comment->comment_date_gmt ) );592 $oldercoms = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = 0 AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt ) ); 575 593 576 594 // No older comments? Then it's page #1. … … 579 597 580 598 // Divide comments older than this one by comments per page to get this comment's page number 581 return ceil( ( $oldercoms + 1 ) / $ per_page);599 return ceil( ( $oldercoms + 1 ) / $args['per_page'] ); 582 600 } 583 601
Note: See TracChangeset
for help on using the changeset viewer.