- * HTML comment list class.
- *
- * @package WordPress
- * @uses Walker
- * @since 2.7.0
- */
-class Walker_Comment extends Walker {
- /**
- * @see Walker::$tree_type
- * @since 2.7.0
- * @var string
- */
- var $tree_type = 'comment';
-
- /**
- * @see Walker::$db_fields
- * @since 2.7.0
- * @var array
- */
- var $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID');
-
- /**
- * @see Walker::start_lvl()
- * @since 2.7.0
- *
- * @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 2.7.0
- *
- * @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;
- }
- }
-
- /**
- * This function is designed to enhance Walker::display_element() to
- * display children of higher nesting levels than selected inline on
- * the highest depth level displayed. This prevents them being orphaned
- * at the end of the comment list.
- *
- * Example: max_depth = 2, with 5 levels of nested content.
- * 1
- * 1.1
- * 1.1.1
- * 1.1.1.1
- * 1.1.1.1.1
- * 1.1.2
- * 1.1.2.1
- * 2
- * 2.2
- *
- */
- function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
-
- if ( !$element )
- return;
-
- $id_field = $this->db_fields['id'];
- $id = $element->$id_field;
-
- parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
-
- // If we're at the max depth, and the current element still has children, loop over those and display them at this level
- // This is to prevent them being orphaned to the end of the list.
- if ( $max_depth <= $depth + 1 && isset( $children_elements[$id]) ) {
- foreach ( $children_elements[ $id ] as $child )
- $this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output );
-
- unset( $children_elements[ $id ] );
- }
-
- }
-
- /**
- * @see Walker::start_el()
- * @since 2.7.0
- *
- * @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 ( 'div' != $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 class="comment-awaiting-moderation"><?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
- /* translators: 1: date, 2: time */
- 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 ( 'div' != $args['style'] ) : ?>
- </div>
- <?php endif; ?>
-<?php
- }
-
- /**
- * @see Walker::end_el()
- * @since 2.7.0
- *
- * @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