+/**
+ * Retrieve HTML content for reply to comment link.
+ *
+ * The default arguments that can be override are 'add_below', 'respond_id',
+ * 'reply_text', 'login_text', and 'depth'. The 'login_text' argument will be
+ * used, if the user must log in or register first before posting a comment. The
+ * 'reply_text' will be used, if they can post a reply. The 'add_below' and
+ * 'respond_id' arguments are for the JavaScript moveAddCommentForm() function
+ * parameters.
+ *
+ * @since 2.7.0
+ *
+ * @param array $args Optional. Override default options.
+ * @param int $comment Optional. Comment being replied to.
+ * @param int $post Optional. Post that the comment is going to be displayed on.
+ * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
+ */
+function get_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'), 'depth' => 0, 'before' => '', 'after' => '');
+
+ $args = wp_parse_args($args, $defaults);
+
+ if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] )
+ return;
+
+ extract($args, EXTR_SKIP);
+
+ $comment = get_comment($comment);
+ $post = get_post($post);
+
+ if ( !comments_open($post->ID) )
+ return false;
+
+ $link = '';
+
+ if ( get_option('comment_registration') && !$user_ID )
+ $link = '<a rel="nofollow" class="comment-reply-login" href="' . esc_url( wp_login_url( get_permalink() ) ) . '">' . $login_text . '</a>';
+ else
+ $link = "<a rel='nofollow' class='comment-reply-link' href='" . esc_url( add_query_arg( 'replytocom', $comment->comment_ID ) ) . "#" . $respond_id . "' onclick='return addComment.moveForm(\"$add_below-$comment->comment_ID\", \"$comment->comment_ID\", \"$respond_id\", \"$post->ID\")'>$reply_text</a>";
+ return apply_filters('comment_reply_link', $before . $link . $after, $args, $comment, $post);
+}
+
+/**
+ * Displays the HTML content for reply to comment link.
+ *
+ * @since 2.7.0
+ * @see get_comment_reply_link() Echoes result
+ *
+ * @param array $args Optional. Override default options.
+ * @param int $comment Optional. Comment being replied to.
+ * @param int $post Optional. Post that the comment is going to be displayed on.
+ * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
+ */
+function comment_reply_link($args = array(), $comment = null, $post = null) {
+ echo get_comment_reply_link($args, $comment, $post);
+}
+
+/**
+ * Retrieve HTML content for reply to post link.
+ *
+ * The default arguments that can be override are 'add_below', 'respond_id',
+ * 'reply_text', 'login_text', and 'depth'. The 'login_text' argument will be
+ * used, if the user must log in or register first before posting a comment. The
+ * 'reply_text' will be used, if they can post a reply. The 'add_below' and
+ * 'respond_id' arguments are for the JavaScript moveAddCommentForm() function
+ * parameters.
+ *
+ * @since 2.7.0
+ *
+ * @param array $args Optional. Override default options.
+ * @param int|object $post Optional. Post that the comment is going to be displayed on. Defaults to current post.
+ * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
+ */
+function get_post_reply_link($args = array(), $post = null) {
+ global $user_ID;
+
+ $defaults = array('add_below' => 'post', 'respond_id' => 'respond', 'reply_text' => __('Leave a Comment'),
+ 'login_text' => __('Log in to leave a Comment'), 'before' => '', 'after' => '');
+
+ $args = wp_parse_args($args, $defaults);
+ extract($args, EXTR_SKIP);
+ $post = get_post($post);
+
+ if ( !comments_open($post->ID) )
+ return false;
+
+ if ( get_option('comment_registration') && !$user_ID ) {
+ $link = '<a rel="nofollow" href="' . wp_login_url( get_permalink() ) . '">' . $login_text . '</a>';
+ } else {
+ $link = "<a rel='nofollow' class='comment-reply-link' href='" . get_permalink($post->ID) . "#$respond_id' onclick='return addComment.moveForm(\"$add_below-$post->ID\", \"0\", \"$respond_id\", \"$post->ID\")'>$reply_text</a>";
+ }
+ return apply_filters('post_comments_link', $before . $link . $after, $post);
+}
+
+/**
+ * Displays the HTML content for reply to post link.
+ * @since 2.7.0
+ * @see get_post_reply_link()
+ *
+ * @param array $args Optional. Override default options.
+ * @param int|object $post Optional. Post that the comment is going to be displayed on.
+ * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
+ */
+function post_reply_link($args = array(), $post = null) {
+ echo get_post_reply_link($args, $post);
+}
+
+/**
+ * Retrieve HTML content for cancel comment reply link.
+ *
+ * @since 2.7.0
+ *
+ * @param string $text Optional. Text to display for cancel reply link.
+ */
+function get_cancel_comment_reply_link($text = '') {
+ if ( empty($text) )
+ $text = __('Click here to cancel reply.');
+
+ $style = isset($_GET['replytocom']) ? '' : ' style="display:none;"';
+ $link = esc_html( remove_query_arg('replytocom') ) . '#respond';
+ return apply_filters('cancel_comment_reply_link', '<a rel="nofollow" id="cancel-comment-reply-link" href="' . $link . '"' . $style . '>' . $text . '</a>', $link, $text);
+}
+
+/**
+ * Display HTML content for cancel comment reply link.
+ *
+ * @since 2.7.0
+ *
+ * @param string $text Optional. Text to display for cancel reply link.
+ */
+function cancel_comment_reply_link($text = '') {
+ echo get_cancel_comment_reply_link($text);
+}
+
+/**
+ * Output hidden input HTML for replying to comments.
+ *
+ * @since 2.7.0
+ */
+function comment_id_fields() {
+ global $id;
+
+ $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
+ echo "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n";
+ echo "<input type='hidden' name='comment_parent' id='comment_parent' value='$replytoid' />\n";
+}
+
+/**
+ * Display text based on comment reply status. Only affects users with Javascript disabled.
+ *
+ * @since 2.7.0
+ *
+ * @param string $noreplytext Optional. Text to display when not replying to a comment.
+ * @param string $replytext Optional. Text to display when replying to a comment. Accepts "%s" for the author of the comment being replied to.
+ * @param string $linktoparent Optional. Boolean to control making the author's name a link to their comment.
+ */
+function comment_form_title( $noreplytext = false, $replytext = false, $linktoparent = TRUE ) {
+ global $comment;
+
+ if ( false === $noreplytext ) $noreplytext = __( 'Leave a Reply' );
+ if ( false === $replytext ) $replytext = __( 'Leave a Reply to %s' );
+
+ $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
+
+ if ( 0 == $replytoid )
+ echo $noreplytext;
+ else {
+ $comment = get_comment($replytoid);
+ $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author() . '</a>' : get_comment_author();
+ printf( $replytext, $author );
+ }
+}
+
+/**
+ * HTML comment list class.
+ *
+ * @package WordPress
+ * @uses Walker
+ * @since unknown
+ */
+class Walker_Comment extends Walker {
+ /**
+ * @see Walker::$tree_type
+ * @since unknown
+ * @var string
+ */
+ var $tree_type = 'comment';
+
+ /**
+ * @see Walker::$db_fields
+ * @since unknown
+ * @var array
+ */
+ var $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID');
+
+ /**
+ * @see Walker::start_lvl()
+ * @since unknown
+ *
+ * @param string $output Passed by reference. Used to append additional content.
+ * @param int $depth Depth of comment.
+ * @param array $args Uses 'style' argument for type of HTML list.
+ */
+ function start_lvl(&$output, $depth, $args) {
+ $GLOBALS['comment_depth'] = $depth + 1;
+
+ switch ( $args['style'] ) {
+ case 'div':
+ break;
+ case 'ol':
+ echo "<ol class='children'>\n";
+ break;
+ default:
+ case 'ul':
+ echo "<ul class='children'>\n";
+ break;
+ }
+ }
+
+ /**
+ * @see Walker::end_lvl()
+ * @since unknown
+ *
+ * @param string $output Passed by reference. Used to append additional content.
+ * @param int $depth Depth of comment.
+ * @param array $args Will only append content if style argument value is 'ol' or 'ul'.
+ */
+ function end_lvl(&$output, $depth, $args) {
+ $GLOBALS['comment_depth'] = $depth + 1;
+
+ switch ( $args['style'] ) {
+ case 'div':
+ break;
+ case 'ol':
+ echo "</ol>\n";
+ break;
+ default:
+ case 'ul':
+ echo "</ul>\n";
+ break;
+ }
+ }
+
+ /**
+ * @see Walker::start_el()
+ * @since unknown
+ *
+ * @param string $output Passed by reference. Used to append additional content.
+ * @param object $comment Comment data object.
+ * @param int $depth Depth of comment in reference to parents.
+ * @param array $args
+ */
+ function start_el(&$output, $comment, $depth, $args) {
+ $depth++;
+ $GLOBALS['comment_depth'] = $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';
+ $add_below = 'comment';
+ } else {
+ $tag = 'li';
+ $add_below = 'div-comment';
+ }
+?>
+ <<?php echo $tag ?> <?php comment_class(empty( $args['has_children'] ) ? '' : 'parent') ?> id="comment-<?php comment_ID() ?>">
+ <?php if ( 'ul' == $args['style'] ) : ?>
+ <div id="div-comment-<?php comment_ID() ?>" class="comment-body">
+ <?php endif; ?>
+ <div class="comment-author vcard">
+ <?php if ($args['avatar_size'] != 0) echo get_avatar( $comment, $args['avatar_size'] ); ?>
+ <?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), 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="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date(), get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),' ','') ?></div>
+
+ <?php comment_text() ?>
+
+ <div class="reply">
+ <?php comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
+ </div>
+ <?php if ( 'ul' == $args['style'] ) : ?>
+ </div>
+ <?php endif; ?>
+<?php
+ }
+
+ /**
+ * @see Walker::end_el()
+ * @since unknown
+ *
+ * @param string $output Passed by reference. Used to append additional content.
+ * @param object $comment
+ * @param int $depth Depth of comment.
+ * @param array $args
+ */
+ function end_el(&$output, $comment, $depth, $args) {
+ if ( !empty($args['end-callback']) ) {
+ call_user_func($args['end-callback'], $comment, $args, $depth);
+ return;
+ }
+ 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.0
+ * @uses Walker_Comment
+ *
+ * @param string|array $args Formatting options
+ * @param array $comments Optional array of comment objects. Defaults to $wp_query->comments
+ */
+function wp_list_comments($args = array(), $comments = null ) {
+ global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
+
+ $in_comment_loop = true;
+
+ $comment_alt = $comment_thread_alt = 0;
+ $comment_depth = 1;
+
+ $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all',
+ 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '');
+
+ $r = wp_parse_args( $args, $defaults );
+
+ // Figure out what comments we'll be looping through ($_comments)
+ if ( null !== $comments ) {
+ $comments = (array) $comments;
+ if ( empty($comments) )
+ return;
+ if ( 'all' != $r['type'] ) {
+ $comments_by_type = &separate_comments($comments);
+ if ( empty($comments_by_type[$r['type']]) )
+ return;
+ $_comments = $comments_by_type[$r['type']];
+ } else {
+ $_comments = $comments;
+ }
+ } else {
+ if ( empty($wp_query->comments) )
+ return;
+ if ( 'all' != $r['type'] ) {
+ if ( empty($wp_query->comments_by_type) )
+ $wp_query->comments_by_type = &separate_comments($wp_query->comments);
+ if ( empty($wp_query->comments_by_type[$r['type']]) )
+ return;
+ $_comments = $wp_query->comments_by_type[$r['type']];
+ } else {
+ $_comments = $wp_query->comments;
+ }
+ }
+
+ if ( '' === $r['per_page'] && get_option('page_comments') )
+ $r['per_page'] = get_query_var('comments_per_page');
+
+ if ( empty($r['per_page']) ) {
+ $r['per_page'] = 0;
+ $r['page'] = 0;
+ }
+
+ if ( '' === $r['max_depth'] ) {
+ if ( get_option('thread_comments') )
+ $r['max_depth'] = get_option('thread_comments_depth');
+ else
+ $r['max_depth'] = -1;
+ }
+
+ if ( '' === $r['page'] ) {
+ if ( empty($overridden_cpage) ) {
+ $r['page'] = get_query_var('cpage');
+ } else {
+ $threaded = ( -1 == $r['max_depth'] ) ? false : true;
+ $r['page'] = ( 'newest' == get_option('default_comments_page') ) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
+ set_query_var( 'cpage', $r['page'] );
+ }
+ }
+ // Validation check
+ $r['page'] = intval($r['page']);
+ if ( 0 == $r['page'] && 0 != $r['per_page'] )
+ $r['page'] = 1;
+
+ if ( null === $r['reverse_top_level'] )
+ $r['reverse_top_level'] = ( 'desc' == get_option('comment_order') ) ? TRUE : FALSE;
+
+ extract( $r, EXTR_SKIP );
+
+ if ( empty($walker) )
+ $walker = new Walker_Comment;
+
+ $walker->paged_walk($_comments, $max_depth, $page, $per_page, $r);
+ $wp_query->max_num_comment_pages = $walker->max_pages;
+
+ $in_comment_loop = false;
+}
+
+?>