wp_list_comments() and threaded comment support. First cut. see #7635
git-svn-id: http://svn.automattic.com/wordpress/trunk@8869 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
02b3f80641
commit
5828310157
|
@ -7,41 +7,15 @@
|
|||
<?php
|
||||
return;
|
||||
}
|
||||
|
||||
/* This variable is for alternating comment background */
|
||||
$oddcomment = 'alt';
|
||||
?>
|
||||
|
||||
<!-- You can start editing here. -->
|
||||
|
||||
<?php if ($comments) : ?>
|
||||
<?php if ( have_comments() ) : ?>
|
||||
<h3 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?> to “<?php the_title(); ?>”</h3>
|
||||
|
||||
<ol class="commentlist">
|
||||
|
||||
<?php foreach ($comments as $comment) : ?>
|
||||
|
||||
<li <?php comment_class($oddcomment) ?> id="comment-<?php comment_ID() ?>">
|
||||
<?php echo get_avatar( $comment, 32 ); ?>
|
||||
<cite><?php comment_author_link() ?></cite> Says:
|
||||
<?php if ($comment->comment_approved == '0') : ?>
|
||||
<em>Your comment is awaiting moderation.</em>
|
||||
<?php endif; ?>
|
||||
<br />
|
||||
|
||||
<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',' ',''); ?></small>
|
||||
|
||||
<?php comment_text() ?>
|
||||
|
||||
</li>
|
||||
|
||||
<?php
|
||||
/* Changes every other comment to a different class */
|
||||
$oddcomment = ( empty( $oddcomment ) ) ? 'alt' : '';
|
||||
?>
|
||||
|
||||
<?php endforeach; /* end for each comment */ ?>
|
||||
|
||||
<?php wp_list_comments($comments); ?>
|
||||
</ol>
|
||||
|
||||
<?php else : // this is displayed if there are no comments so far ?>
|
||||
|
@ -59,7 +33,13 @@
|
|||
|
||||
<?php if ('open' == $post->comment_status) : ?>
|
||||
|
||||
<h3 id="respond">Leave a Reply</h3>
|
||||
<div id="respond">
|
||||
|
||||
<h3>Leave a Reply</h3>
|
||||
|
||||
<div id="cancel-comment-reply" style="display: none;">
|
||||
<small><?php echo cancel_comment_reply_link() ?></small>
|
||||
</div>
|
||||
|
||||
<?php if ( get_option('comment_registration') && !$user_ID ) : ?>
|
||||
<p>You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>">logged in</a> to post a comment.</p>
|
||||
|
@ -90,10 +70,12 @@
|
|||
|
||||
<p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
|
||||
<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
|
||||
<input type="hidden" name="comment_parent" id="comment-parent" value="0" />
|
||||
</p>
|
||||
<?php do_action('comment_form', $post->ID); ?>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php endif; // If registration required and not logged in ?>
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ if ( !empty($withcomments) && !is_single() ) {
|
|||
|
||||
</style>
|
||||
|
||||
<?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?>
|
||||
|
||||
<?php wp_head(); ?>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -227,9 +227,13 @@ function comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
|
|||
* @param int $comment_id An optional comment ID
|
||||
* @param int $post_id An optional post ID
|
||||
*/
|
||||
function comment_class( $class = '', $comment_id = null, $post_id = null ) {
|
||||
// Separates classes with a single space, collates classes for post DIV
|
||||
echo 'class="' . join( ' ', get_comment_class( $class, $comment_id, $post_id ) ) . '"';
|
||||
function comment_class( $class = '', $comment_id = null, $post_id = null, $echo = true ) {
|
||||
// Separates classes with a single space, collates classes for comment DIV
|
||||
$class = 'class="' . join( ' ', get_comment_class( $class, $comment_id, $post_id ) ) . '"';
|
||||
if ( $echo)
|
||||
echo $class;
|
||||
else
|
||||
return $class;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -266,10 +270,12 @@ function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
|
|||
if ( empty($comment_alt) )
|
||||
$comment_alt = 0;
|
||||
|
||||
if ( $comment_alt % 2 )
|
||||
if ( $comment_alt % 2 ) {
|
||||
$classes[] = 'odd';
|
||||
else
|
||||
$classes[] = 'alt';
|
||||
} else {
|
||||
$classes[] = 'even';
|
||||
}
|
||||
|
||||
$comment_alt++;
|
||||
|
||||
|
@ -835,4 +841,129 @@ function comments_popup_link( $zero = 'No Comments', $one = '1 Comment', $more =
|
|||
echo '</a>';
|
||||
}
|
||||
|
||||
function comment_reply_link($args = array(), $comment = null, $post = null) {
|
||||
global $user_ID;
|
||||
|
||||
$defaults = array('add_below' => 'comment', 'respond_id' => 'respond', 'reply_text' => __('Reply'),
|
||||
'login_text' => __('Log in to Reply'));
|
||||
|
||||
$args = wp_parse_args($args, $defaults);
|
||||
|
||||
extract($args, EXTR_SKIP);
|
||||
|
||||
$comment = get_comment($comment);
|
||||
$post = get_post($post);
|
||||
|
||||
if ( 'open' != $post->comment_status )
|
||||
return false;
|
||||
|
||||
$link = '';
|
||||
|
||||
if ( get_option('comment_registration') && !$user_ID )
|
||||
$link = '<a href="' . site_url('wp-login.php?redirect_to=' . get_permalink()) . '">' . $login_text . '</a>';
|
||||
else
|
||||
$link = "<a href='#' onclick='moveAddCommentForm(\"$add_below-$comment->comment_ID\", $comment->comment_ID, \"$respond_id\"); return false;'>$reply_text</a>";
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
function cancel_comment_reply_link($text = '', $respond_id = 'respond') {
|
||||
if ( empty($text) )
|
||||
$text = __('Click here to cancel reply.');
|
||||
echo '<a href="#" onclick="cancelCommentReply(\'' . $respond_id . '\'); return false;">' . $text . '</a>';
|
||||
}
|
||||
|
||||
class Walker_Comment extends Walker {
|
||||
var $tree_type = 'comment';
|
||||
var $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID');
|
||||
|
||||
function start_lvl(&$output, $depth, $args) {
|
||||
if ( 'div' == $args['style'] )
|
||||
return;
|
||||
|
||||
echo "<ul class='children'>\n";
|
||||
}
|
||||
|
||||
function end_lvl(&$output, $depth, $args) {
|
||||
if ( 'div' == $args['style'] )
|
||||
return;
|
||||
|
||||
echo "</ul>\n";
|
||||
}
|
||||
|
||||
function start_el(&$output, $comment, $depth, $args) {
|
||||
$depth++;
|
||||
|
||||
if ( !empty($args['callback']) ) {
|
||||
call_user_func($args['callback'], $comment, $args, $depth);
|
||||
return;
|
||||
}
|
||||
|
||||
$GLOBALS['comment'] = $comment;
|
||||
extract($args, EXTR_SKIP);
|
||||
|
||||
if ( 'div' == $args['style'] )
|
||||
$tag = 'div';
|
||||
else
|
||||
$tag = 'li';
|
||||
?>
|
||||
<<?php echo $tag ?> "<?php comment_class() ?>" id="comment-<?php comment_ID() ?>">
|
||||
<?php if ( 'list' == $args['style'] ) : ?>
|
||||
<div id="div-comment-<?php comment_ID() ?>">
|
||||
<?php endif; ?>
|
||||
<div class="comment-author vcard">
|
||||
<?php echo get_avatar( $comment, 32 ) ?>
|
||||
<?php printf(__('<cite>%s</cite> Says:'), get_comment_author_link()) ?>
|
||||
</div>
|
||||
<?php if ($comment->comment_approved == '0') : ?>
|
||||
<em><?php _e('Your comment is awaiting moderation.') ?></em>
|
||||
<br />
|
||||
<?php endif; ?>
|
||||
|
||||
<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',' ','') ?></div>
|
||||
|
||||
<?php echo apply_filters('comment_text', get_comment_text()) ?>
|
||||
|
||||
<div class='reply'>
|
||||
<?php if ( $depth < $args['depth'] ) echo comment_reply_link(array('add_below' => 'div-comment')) ?>
|
||||
<?php if ( 'list' == $args['style'] ) : ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
function end_el(&$output, $comment, $depth, $args) {
|
||||
if ( 'div' == $args['style'] )
|
||||
echo "</div>\n";
|
||||
else
|
||||
echo "</li>\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* List comments
|
||||
*
|
||||
* Used in the comments.php template to list comments for a particular post
|
||||
*
|
||||
* @since 2.7
|
||||
* @uses Walker_Comment
|
||||
*
|
||||
* @param $comments array Array of comment object to list
|
||||
* @param $args string|array Additional arguments
|
||||
*/
|
||||
function wp_list_comments(&$comments, $args = array() ) {
|
||||
$defaults = array('walker' => null, 'depth' => 3, 'style' => 'list', 'callback' => null);
|
||||
|
||||
$r = wp_parse_args( $args, $defaults );
|
||||
|
||||
extract( $r, EXTR_SKIP );
|
||||
|
||||
if ( empty($walker) )
|
||||
$walker = new Walker_Comment;
|
||||
|
||||
$walker->walk($comments, $depth, $r);
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,37 @@
|
|||
function moveAddCommentForm(theId, threadId, respondId) {
|
||||
var addComment = document.getElementById(respondId);
|
||||
var comment = document.getElementById(theId);
|
||||
addComment.parentNode.removeChild(addComment);
|
||||
|
||||
comment.appendChild(addComment);
|
||||
// if(comment.className.indexOf("alt")>-1) {
|
||||
// addComment.className = addComment.className.replace(" alt", "");
|
||||
// } else {
|
||||
// addComment.className += " alt";
|
||||
// }
|
||||
var replyId = document.getElementById("comment-parent");
|
||||
replyId.value = threadId;
|
||||
var reRootElement = document.getElementById("cancel-comment-reply");
|
||||
reRootElement.style.display = "block";
|
||||
var aTags = comment.getElementsByTagName("A");
|
||||
var anc = aTags.item(0).id;
|
||||
//document.location.href = "#"+anc;
|
||||
document.getElementById("comment").focus();
|
||||
}
|
||||
|
||||
function cancelCommentReply() {
|
||||
var addComment = document.getElementById("respond");
|
||||
var reRootElement = document.getElementById("cancel-comment-reply");
|
||||
reRootElement.style.display = "none";
|
||||
var content = document.getElementById("content-main");
|
||||
if( !content )
|
||||
content = document.getElementById("content");
|
||||
if( content ) {
|
||||
addComment.parentNode.removeChild(addComment);
|
||||
content.appendChild(addComment);
|
||||
}
|
||||
// addComment.className = addComment.className.replace(" alt", "");
|
||||
document.location.href = "#respond";
|
||||
document.getElementById("comment").focus();
|
||||
document.getElementById("comment-parent").value = "0";
|
||||
}
|
|
@ -531,7 +531,7 @@ function get_edit_comment_link( $comment_id = 0 ) {
|
|||
return apply_filters( 'get_edit_comment_link', $location );
|
||||
}
|
||||
|
||||
function edit_comment_link( $link = 'Edit This', $before = '', $after = '' ) {
|
||||
function edit_comment_link( $link = 'Edit This', $before = '', $after = '', $echo = true ) {
|
||||
global $comment, $post;
|
||||
|
||||
if ( $post->post_type == 'attachment' ) {
|
||||
|
@ -544,7 +544,11 @@ function edit_comment_link( $link = 'Edit This', $before = '', $after = '' ) {
|
|||
}
|
||||
|
||||
$link = '<a href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . __( 'Edit comment' ) . '">' . $link . '</a>';
|
||||
echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after;
|
||||
$link = $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after;
|
||||
if ( $echo )
|
||||
echo $link;
|
||||
else
|
||||
return $link;
|
||||
}
|
||||
|
||||
function get_edit_bookmark_link( $link = 0 ) {
|
||||
|
|
|
@ -141,6 +141,8 @@ function wp_default_scripts( &$scripts ) {
|
|||
$scripts->add( 'jquery-ui-resizable', '/wp-includes/js/jquery/ui.resizable.js', array('jquery-ui-core'), '1.5.2' );
|
||||
$scripts->add( 'jquery-ui-dialog', '/wp-includes/js/jquery/ui.dialog.js', array('jquery-ui-resizable', 'jquery-ui-draggable'), '1.5.2' );
|
||||
|
||||
$scripts->add( 'comment-reply', '/wp-includes/js/comment-reply.js', false, '20080828');
|
||||
|
||||
if ( is_admin() ) {
|
||||
$scripts->add( 'ajaxcat', '/wp-admin/js/cat.js', array( 'wp-lists' ), '20071101' );
|
||||
$scripts->localize( 'ajaxcat', 'catL10n', array(
|
||||
|
|
Loading…
Reference in New Issue