WordPress.org

Make WordPress Core

Changeset 9367


Ignore:
Timestamp:
10/27/08 16:31:26 (6 years ago)
Author:
ryan
Message:

Make get_comment_link() paging aware. Props Viper007Bond. see #7956

Location:
trunk/wp-includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/canonical.php

    r9322 r9367  
    250250        $redirect_url = $redirect['scheme'] . '://' . $redirect['host']; 
    251251        if ( !empty($redirect['port']) ) 
    252             $redirect_url .= ':' . $redirect['port']; 
     252            $redirect_url .= ':' . $redirect['port']; 
    253253        $redirect_url .= $redirect['path']; 
    254254        if ( !empty($redirect['query']) ) 
     
    257257 
    258258    if ( !$redirect_url || $redirect_url == $requested_url ) 
    259         return false; 
     259        return false; 
    260260 
    261261    // Note that you can use the "redirect_canonical" filter to cancel a canonical redirect for whatever reason by returning FALSE 
     
    263263 
    264264    if ( !$redirect_url || $redirect_url == $requested_url ) // yes, again -- in case the filter aborted the request 
    265         return false; 
     265        return false; 
    266266 
    267267    if ( $do_redirect ) { 
  • trunk/wp-includes/comment-template.php

    r9317 r9367  
    403403 
    404404/** 
    405  * Retrieve the link to the current comment. 
     405 * Retrieve the link to a given comment. 
    406406 * 
    407407 * @since 1.5.0 
     
    412412 */ 
    413413function get_comment_link($comment = null) { 
     414    global $wp_rewrite; 
     415 
    414416    $comment = get_comment($comment); 
    415     return get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID; 
     417 
     418    if ( get_option('page_comments') ) { 
     419        $page = get_page_of_comment( $comment->comment_ID ); 
     420 
     421        if ( $wp_rewrite->using_permalinks() ) 
     422            return user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . "comment-page-$page", 'comment' ) . '#comment-' . $comment->comment_ID; 
     423        else 
     424            return add_query_arg( 'cpage', $page, get_permalink( $comment->comment_post_ID ) ) . '#comment-' . $comment->comment_ID; 
     425    } else { 
     426        return get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID; 
     427    } 
    416428} 
    417429 
     
    10861098<?php endif; ?> 
    10871099 
    1088         <div class="comment-meta commentmetadata"><a href="#comment-<?php comment_ID() ?>" title=""><?php printf(__('%1$s at %2$s'), get_comment_date('F jS, Y'),  get_comment_time()) ?></a><?php edit_comment_link('edit','&nbsp;&nbsp;','') ?></div> 
     1100        <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','&nbsp;&nbsp;','') ?></div> 
    10891101 
    10901102        <?php echo apply_filters('comment_text', get_comment_text()) ?> 
  • trunk/wp-includes/comment.php

    r9335 r9367  
    521521 
    522522/** 
     523 * Calculate what page number a comment will appear on for comment paging. 
     524 * 
     525 * @since 2.7.0 
     526 * 
     527 * @param int $comment_ID Comment ID. 
     528 * @param int $per_page Optional comments per page. 
     529 * @return int|null Comment page number or null on error. 
     530 */ 
     531function get_page_of_comment( $comment_ID, $per_page = null, $threaded = null ) { 
     532    if ( !$comment = get_comment( $comment_ID ) ) 
     533        return; 
     534 
     535    if ( !get_option('page_comments') ) 
     536        return 1; 
     537 
     538    $comments = array_reverse( get_comments( $comment->comment_post_ID ) ); 
     539 
     540    if ( null === $per_page ) 
     541        $per_page = get_option('comments_per_page'); 
     542 
     543    if ( null === $threaded ) 
     544        $threaded = get_option('thread_comments'); 
     545 
     546    // Find this comment's top level parent 
     547    if ( $threaded ) { 
     548        while ( 0 != $comment->comment_parent ) 
     549            $comment = get_comment( $comment->comment_parent ); 
     550    } 
     551 
     552    // Start going through the comments until we find what page number the above top level comment is on 
     553    $page = 1; 
     554    $comthispage = 0; 
     555    foreach ( $comments as $com ) { 
     556        if ( $threaded && 0 != $com->comment_parent ) 
     557            continue; 
     558 
     559        if ( $com->comment_ID == $comment->comment_ID ) 
     560            return $page; 
     561 
     562        $comthispage++; 
     563 
     564        if ( $comthispage >= $per_page ) { 
     565            $page++; 
     566            $comthispage = 0; 
     567        } 
     568    } 
     569} 
     570 
     571/** 
    523572 * Does comment contain blacklisted characters or words. 
    524573 * 
Note: See TracChangeset for help on using the changeset viewer.