Make WordPress Core

Changeset 8869


Ignore:
Timestamp:
09/11/2008 07:25:50 PM (18 years ago)
Author:
ryan
Message:

wp_list_comments() and threaded comment support. First cut. see #7635

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-content/themes/default/comments.php

    r8800 r8869  
    88                return;
    99        }
    10 
    11         /* This variable is for alternating comment background */
    12         $oddcomment = 'alt';
    1310?>
    1411
    1512<!-- You can start editing here. -->
    1613
    17 <?php if ($comments) : ?>
     14<?php if ( have_comments() ) : ?>
    1815        <h3 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?> to &#8220;<?php the_title(); ?>&#8221;</h3>
    1916
    2017        <ol class="commentlist">
    21 
    22         <?php foreach ($comments as $comment) : ?>
    23 
    24                 <li <?php comment_class($oddcomment) ?> id="comment-<?php comment_ID() ?>">
    25                         <?php echo get_avatar( $comment, 32 ); ?>
    26                         <cite><?php comment_author_link() ?></cite> Says:
    27                         <?php if ($comment->comment_approved == '0') : ?>
    28                         <em>Your comment is awaiting moderation.</em>
    29                         <?php endif; ?>
    30                         <br />
    31 
    32                         <small class="commentmetadata"><a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('F jS, Y') ?> at <?php comment_time() ?></a> <?php edit_comment_link('edit','&nbsp;&nbsp;',''); ?></small>
    33 
    34                         <?php comment_text() ?>
    35 
    36                 </li>
    37 
    38         <?php
    39                 /* Changes every other comment to a different class */
    40                 $oddcomment = ( empty( $oddcomment ) ) ? 'alt' : '';
    41         ?>
    42 
    43         <?php endforeach; /* end for each comment */ ?>
    44 
     18        <?php wp_list_comments($comments); ?>
    4519        </ol>
    4620
     
    6034<?php if ('open' == $post->comment_status) : ?>
    6135
    62 <h3 id="respond">Leave a Reply</h3>
     36<div id="respond">
     37
     38<h3>Leave a Reply</h3>
     39
     40<div id="cancel-comment-reply" style="display: none;">
     41        <small><?php echo cancel_comment_reply_link() ?></small>
     42</div>
    6343
    6444<?php if ( get_option('comment_registration') && !$user_ID ) : ?>
     
    9171<p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
    9272<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
     73<input type="hidden" name="comment_parent" id="comment-parent" value="0" />
    9374</p>
    9475<?php do_action('comment_form', $post->ID); ?>
    9576
    9677</form>
     78</div>
    9779
    9880<?php endif; // If registration required and not logged in ?>
  • trunk/wp-content/themes/default/header.php

    r8408 r8869  
    2525</style>
    2626
     27<?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?>
     28
    2729<?php wp_head(); ?>
    2830</head>
  • trunk/wp-includes/comment-template.php

    r8800 r8869  
    228228 * @param int $post_id An optional post ID
    229229 */
    230 function comment_class( $class = '', $comment_id = null, $post_id = null ) {
    231         // Separates classes with a single space, collates classes for post DIV
    232         echo 'class="' . join( ' ', get_comment_class( $class, $comment_id, $post_id ) ) . '"';
     230function comment_class( $class = '', $comment_id = null, $post_id = null, $echo = true ) {
     231        // Separates classes with a single space, collates classes for comment DIV
     232        $class = 'class="' . join( ' ', get_comment_class( $class, $comment_id, $post_id ) ) . '"';
     233        if ( $echo)
     234                echo $class;
     235        else
     236                return $class;
    233237}
    234238
     
    267271                $comment_alt = 0;
    268272
    269         if ( $comment_alt % 2 )
     273        if ( $comment_alt % 2 ) {
    270274                $classes[] = 'odd';
    271         else
     275                $classes[] = 'alt';
     276        } else {
    272277                $classes[] = 'even';
     278        }
    273279
    274280        $comment_alt++;
     
    836842}
    837843
     844function comment_reply_link($args = array(), $comment = null, $post = null) {
     845        global $user_ID;
     846
     847        $defaults = array('add_below' => 'comment', 'respond_id' => 'respond', 'reply_text' => __('Reply'),
     848                'login_text' => __('Log in to Reply'));
     849
     850        $args = wp_parse_args($args, $defaults);
     851
     852        extract($args, EXTR_SKIP);
     853
     854        $comment = get_comment($comment);
     855        $post = get_post($post);
     856
     857        if ( 'open' != $post->comment_status )
     858                return false;
     859
     860        $link = '';
     861
     862        if ( get_option('comment_registration') && !$user_ID )
     863                $link = '<a href="' . site_url('wp-login.php?redirect_to=' . get_permalink()) . '">' . $login_text . '</a>';
     864        else
     865                $link = "<a href='#' onclick='moveAddCommentForm(\"$add_below-$comment->comment_ID\", $comment->comment_ID, \"$respond_id\"); return false;'>$reply_text</a>";
     866
     867        return $link;
     868}
     869
     870function cancel_comment_reply_link($text = '', $respond_id = 'respond') {
     871        if ( empty($text) )
     872                $text = __('Click here to cancel reply.');
     873        echo '<a href="#" onclick="cancelCommentReply(\'' . $respond_id . '\'); return false;">' . $text . '</a>';
     874}
     875
     876class Walker_Comment extends Walker {
     877        var $tree_type = 'comment';
     878        var $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID');
     879
     880        function start_lvl(&$output, $depth, $args) {
     881                if ( 'div' == $args['style'] )
     882                        return;
     883
     884                echo "<ul class='children'>\n";
     885        }
     886
     887        function end_lvl(&$output, $depth, $args) {
     888                if ( 'div' == $args['style'] )
     889                        return;
     890
     891                echo "</ul>\n";
     892        }
     893
     894        function start_el(&$output, $comment, $depth, $args) {
     895                $depth++;
     896
     897                if ( !empty($args['callback']) ) {
     898                        call_user_func($args['callback'], $comment, $args, $depth);
     899                        return;
     900                }
     901
     902                $GLOBALS['comment'] = $comment;
     903                extract($args, EXTR_SKIP);
     904
     905                if ( 'div' == $args['style'] )
     906                        $tag = 'div';
     907                else
     908                        $tag = 'li';
    838909?>
     910                <<?php echo $tag ?> "<?php comment_class() ?>" id="comment-<?php comment_ID() ?>">
     911                <?php if ( 'list' == $args['style'] ) : ?>
     912                <div id="div-comment-<?php comment_ID() ?>">
     913                <?php endif; ?>
     914                <div class="comment-author vcard">
     915                <?php echo get_avatar( $comment, 32 ) ?>
     916                <?php printf(__('<cite>%s</cite> Says:'), get_comment_author_link()) ?>
     917                </div>
     918<?php if ($comment->comment_approved == '0') : ?>
     919                <em><?php _e('Your comment is awaiting moderation.') ?></em>
     920                <br />
     921<?php endif; ?>
     922
     923                <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>
     924
     925                <?php echo apply_filters('comment_text', get_comment_text()) ?>
     926
     927                <div class='reply'>
     928                <?php if ( $depth < $args['depth'] ) echo comment_reply_link(array('add_below' => 'div-comment')) ?>
     929                <?php if ( 'list' == $args['style'] ) : ?>
     930                </div>
     931                <?php endif; ?>
     932                </div>
     933<?php
     934        }
     935
     936        function end_el(&$output, $comment, $depth, $args) {
     937                if ( 'div' == $args['style'] )
     938                        echo "</div>\n";
     939                else
     940                        echo "</li>\n";
     941        }
     942
     943}
     944
     945/**
     946 * List comments
     947 *
     948 * Used in the comments.php template to list comments for a particular post
     949 *
     950 * @since 2.7
     951 * @uses Walker_Comment
     952 *
     953 * @param $comments array Array of comment object to list
     954 * @param $args string|array Additional arguments
     955 */
     956function wp_list_comments(&$comments, $args = array() ) {
     957        $defaults = array('walker' => null, 'depth' => 3, 'style' => 'list', 'callback' => null);
     958
     959        $r = wp_parse_args( $args, $defaults );
     960
     961        extract( $r, EXTR_SKIP );
     962
     963        if ( empty($walker) )
     964                $walker = new Walker_Comment;
     965
     966        $walker->walk($comments, $depth, $r);
     967}
     968
     969?>
  • trunk/wp-includes/link-template.php

    r8758 r8869  
    532532}
    533533
    534 function edit_comment_link( $link = 'Edit This', $before = '', $after = '' ) {
     534function edit_comment_link( $link = 'Edit This', $before = '', $after = '', $echo = true ) {
    535535        global $comment, $post;
    536536
     
    545545
    546546        $link = '<a href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . __( 'Edit comment' ) . '">' . $link . '</a>';
    547         echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after;
     547        $link = $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after;
     548        if ( $echo )
     549                echo $link;
     550        else
     551                return $link;
    548552}
    549553
  • trunk/wp-includes/script-loader.php

    r8860 r8869  
    141141        $scripts->add( 'jquery-ui-resizable', '/wp-includes/js/jquery/ui.resizable.js', array('jquery-ui-core'), '1.5.2' );
    142142        $scripts->add( 'jquery-ui-dialog', '/wp-includes/js/jquery/ui.dialog.js', array('jquery-ui-resizable', 'jquery-ui-draggable'), '1.5.2' );
     143
     144        $scripts->add( 'comment-reply', '/wp-includes/js/comment-reply.js', false, '20080828');
    143145
    144146        if ( is_admin() ) {
Note: See TracChangeset for help on using the changeset viewer.