wp/wp-includes/class-walker-comment.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    33 	 * @var array
    33 	 * @var array
    34 	 *
    34 	 *
    35 	 * @see Walker::$db_fields
    35 	 * @see Walker::$db_fields
    36 	 * @todo Decouple this
    36 	 * @todo Decouple this
    37 	 */
    37 	 */
    38 	public $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID');
    38 	public $db_fields = array(
       
    39 		'parent' => 'comment_parent',
       
    40 		'id'     => 'comment_ID',
       
    41 	);
    39 
    42 
    40 	/**
    43 	/**
    41 	 * Starts the list before the elements are added.
    44 	 * Starts the list before the elements are added.
    42 	 *
    45 	 *
    43 	 * @since 2.7.0
    46 	 * @since 2.7.0
   124 	 * @param int        $depth             Depth of the current element.
   127 	 * @param int        $depth             Depth of the current element.
   125 	 * @param array      $args              An array of arguments.
   128 	 * @param array      $args              An array of arguments.
   126 	 * @param string     $output            Used to append additional content. Passed by reference.
   129 	 * @param string     $output            Used to append additional content. Passed by reference.
   127 	 */
   130 	 */
   128 	public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
   131 	public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
   129 		if ( !$element )
   132 		if ( ! $element ) {
   130 			return;
   133 			return;
       
   134 		}
   131 
   135 
   132 		$id_field = $this->db_fields['id'];
   136 		$id_field = $this->db_fields['id'];
   133 		$id = $element->$id_field;
   137 		$id       = $element->$id_field;
   134 
   138 
   135 		parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
   139 		parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
   136 
   140 
   137 		/*
   141 		/*
   138 		 * If at the max depth, and the current element still has children, loop over those
   142 		 * If at the max depth, and the current element still has children, loop over those
   139 		 * and display them at this level. This is to prevent them being orphaned to the end
   143 		 * and display them at this level. This is to prevent them being orphaned to the end
   140 		 * of the list.
   144 		 * of the list.
   141 		 */
   145 		 */
   142 		if ( $max_depth <= $depth + 1 && isset( $children_elements[$id]) ) {
   146 		if ( $max_depth <= $depth + 1 && isset( $children_elements[ $id ] ) ) {
   143 			foreach ( $children_elements[ $id ] as $child )
   147 			foreach ( $children_elements[ $id ] as $child ) {
   144 				$this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output );
   148 				$this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output );
       
   149 			}
   145 
   150 
   146 			unset( $children_elements[ $id ] );
   151 			unset( $children_elements[ $id ] );
   147 		}
   152 		}
   148 
   153 
   149 	}
   154 	}
   165 	 * @param int        $id      Optional. ID of the current comment. Default 0 (unused).
   170 	 * @param int        $id      Optional. ID of the current comment. Default 0 (unused).
   166 	 */
   171 	 */
   167 	public function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) {
   172 	public function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) {
   168 		$depth++;
   173 		$depth++;
   169 		$GLOBALS['comment_depth'] = $depth;
   174 		$GLOBALS['comment_depth'] = $depth;
   170 		$GLOBALS['comment'] = $comment;
   175 		$GLOBALS['comment']       = $comment;
   171 
   176 
   172 		if ( !empty( $args['callback'] ) ) {
   177 		if ( ! empty( $args['callback'] ) ) {
   173 			ob_start();
   178 			ob_start();
   174 			call_user_func( $args['callback'], $comment, $args, $depth );
   179 			call_user_func( $args['callback'], $comment, $args, $depth );
   175 			$output .= ob_get_clean();
   180 			$output .= ob_get_clean();
   176 			return;
   181 			return;
   177 		}
   182 		}
   203 	 * @param WP_Comment $comment The current comment object. Default current comment.
   208 	 * @param WP_Comment $comment The current comment object. Default current comment.
   204 	 * @param int        $depth   Optional. Depth of the current comment. Default 0.
   209 	 * @param int        $depth   Optional. Depth of the current comment. Default 0.
   205 	 * @param array      $args    Optional. An array of arguments. Default empty array.
   210 	 * @param array      $args    Optional. An array of arguments. Default empty array.
   206 	 */
   211 	 */
   207 	public function end_el( &$output, $comment, $depth = 0, $args = array() ) {
   212 	public function end_el( &$output, $comment, $depth = 0, $args = array() ) {
   208 		if ( !empty( $args['end-callback'] ) ) {
   213 		if ( ! empty( $args['end-callback'] ) ) {
   209 			ob_start();
   214 			ob_start();
   210 			call_user_func( $args['end-callback'], $comment, $args, $depth );
   215 			call_user_func( $args['end-callback'], $comment, $args, $depth );
   211 			$output .= ob_get_clean();
   216 			$output .= ob_get_clean();
   212 			return;
   217 			return;
   213 		}
   218 		}
   214 		if ( 'div' == $args['style'] )
   219 		if ( 'div' == $args['style'] ) {
   215 			$output .= "</div><!-- #comment-## -->\n";
   220 			$output .= "</div><!-- #comment-## -->\n";
   216 		else
   221 		} else {
   217 			$output .= "</li><!-- #comment-## -->\n";
   222 			$output .= "</li><!-- #comment-## -->\n";
       
   223 		}
   218 	}
   224 	}
   219 
   225 
   220 	/**
   226 	/**
   221 	 * Outputs a pingback comment.
   227 	 * Outputs a pingback comment.
   222 	 *
   228 	 *
   228 	 * @param int        $depth   Depth of the current comment.
   234 	 * @param int        $depth   Depth of the current comment.
   229 	 * @param array      $args    An array of arguments.
   235 	 * @param array      $args    An array of arguments.
   230 	 */
   236 	 */
   231 	protected function ping( $comment, $depth, $args ) {
   237 	protected function ping( $comment, $depth, $args ) {
   232 		$tag = ( 'div' == $args['style'] ) ? 'div' : 'li';
   238 		$tag = ( 'div' == $args['style'] ) ? 'div' : 'li';
   233 ?>
   239 		?>
   234 		<<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( '', $comment ); ?>>
   240 		<<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( '', $comment ); ?>>
   235 			<div class="comment-body">
   241 			<div class="comment-body">
   236 				<?php _e( 'Pingback:' ); ?> <?php comment_author_link( $comment ); ?> <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
   242 				<?php _e( 'Pingback:' ); ?> <?php comment_author_link( $comment ); ?> <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
   237 			</div>
   243 			</div>
   238 <?php
   244 		<?php
   239 	}
   245 	}
   240 
   246 
   241 	/**
   247 	/**
   242 	 * Outputs a single comment.
   248 	 * Outputs a single comment.
   243 	 *
   249 	 *
   249 	 * @param int        $depth   Depth of the current comment.
   255 	 * @param int        $depth   Depth of the current comment.
   250 	 * @param array      $args    An array of arguments.
   256 	 * @param array      $args    An array of arguments.
   251 	 */
   257 	 */
   252 	protected function comment( $comment, $depth, $args ) {
   258 	protected function comment( $comment, $depth, $args ) {
   253 		if ( 'div' == $args['style'] ) {
   259 		if ( 'div' == $args['style'] ) {
   254 			$tag = 'div';
   260 			$tag       = 'div';
   255 			$add_below = 'comment';
   261 			$add_below = 'comment';
   256 		} else {
   262 		} else {
   257 			$tag = 'li';
   263 			$tag       = 'li';
   258 			$add_below = 'div-comment';
   264 			$add_below = 'div-comment';
   259 		}
   265 		}
   260 ?>
   266 
       
   267 		$commenter = wp_get_current_commenter();
       
   268 		if ( $commenter['comment_author_email'] ) {
       
   269 			$moderation_note = __( 'Your comment is awaiting moderation.' );
       
   270 		} else {
       
   271 			$moderation_note = __( 'Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.' );
       
   272 		}
       
   273 
       
   274 		?>
   261 		<<?php echo $tag; ?> <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?> id="comment-<?php comment_ID(); ?>">
   275 		<<?php echo $tag; ?> <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?> id="comment-<?php comment_ID(); ?>">
   262 		<?php if ( 'div' != $args['style'] ) : ?>
   276 		<?php if ( 'div' != $args['style'] ) : ?>
   263 		<div id="div-comment-<?php comment_ID(); ?>" class="comment-body">
   277 		<div id="div-comment-<?php comment_ID(); ?>" class="comment-body">
   264 		<?php endif; ?>
   278 		<?php endif; ?>
   265 		<div class="comment-author vcard">
   279 		<div class="comment-author vcard">
   266 			<?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
   280 			<?php
       
   281 			if ( 0 != $args['avatar_size'] ) {
       
   282 				echo get_avatar( $comment, $args['avatar_size'] );}
       
   283 			?>
   267 			<?php
   284 			<?php
   268 				/* translators: %s: comment author link */
   285 				/* translators: %s: comment author link */
   269 				printf( __( '%s <span class="says">says:</span>' ),
   286 				printf(
       
   287 					__( '%s <span class="says">says:</span>' ),
   270 					sprintf( '<cite class="fn">%s</cite>', get_comment_author_link( $comment ) )
   288 					sprintf( '<cite class="fn">%s</cite>', get_comment_author_link( $comment ) )
   271 				);
   289 				);
   272 			?>
   290 			?>
   273 		</div>
   291 		</div>
   274 		<?php if ( '0' == $comment->comment_approved ) : ?>
   292 		<?php if ( '0' == $comment->comment_approved ) : ?>
   275 		<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ) ?></em>
   293 		<em class="comment-awaiting-moderation"><?php echo $moderation_note; ?></em>
   276 		<br />
   294 		<br />
   277 		<?php endif; ?>
   295 		<?php endif; ?>
   278 
   296 
   279 		<div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment, $args ) ); ?>">
   297 		<div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment, $args ) ); ?>">
   280 			<?php
   298 			<?php
   281 				/* translators: 1: comment date, 2: comment time */
   299 				/* translators: 1: comment date, 2: comment time */
   282 				printf( __( '%1$s at %2$s' ), get_comment_date( '', $comment ),  get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), '&nbsp;&nbsp;', '' );
   300 				printf( __( '%1$s at %2$s' ), get_comment_date( '', $comment ), get_comment_time() );
   283 			?>
   301 			?>
       
   302 				</a>
       
   303 				<?php
       
   304 				edit_comment_link( __( '(Edit)' ), '&nbsp;&nbsp;', '' );
       
   305 				?>
   284 		</div>
   306 		</div>
   285 
   307 
   286 		<?php comment_text( $comment, array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
       
   287 
       
   288 		<?php
   308 		<?php
   289 		comment_reply_link( array_merge( $args, array(
   309 		comment_text(
   290 			'add_below' => $add_below,
   310 			$comment,
   291 			'depth'     => $depth,
   311 			array_merge(
   292 			'max_depth' => $args['max_depth'],
   312 				$args,
   293 			'before'    => '<div class="reply">',
   313 				array(
   294 			'after'     => '</div>'
   314 					'add_below' => $add_below,
   295 		) ) );
   315 					'depth'     => $depth,
       
   316 					'max_depth' => $args['max_depth'],
       
   317 				)
       
   318 			)
       
   319 		);
       
   320 		?>
       
   321 
       
   322 		<?php
       
   323 		comment_reply_link(
       
   324 			array_merge(
       
   325 				$args,
       
   326 				array(
       
   327 					'add_below' => $add_below,
       
   328 					'depth'     => $depth,
       
   329 					'max_depth' => $args['max_depth'],
       
   330 					'before'    => '<div class="reply">',
       
   331 					'after'     => '</div>',
       
   332 				)
       
   333 			)
       
   334 		);
   296 		?>
   335 		?>
   297 
   336 
   298 		<?php if ( 'div' != $args['style'] ) : ?>
   337 		<?php if ( 'div' != $args['style'] ) : ?>
   299 		</div>
   338 		</div>
   300 		<?php endif; ?>
   339 		<?php endif; ?>
   301 <?php
   340 		<?php
   302 	}
   341 	}
   303 
   342 
   304 	/**
   343 	/**
   305 	 * Outputs a comment in the HTML5 format.
   344 	 * Outputs a comment in the HTML5 format.
   306 	 *
   345 	 *
   312 	 * @param int        $depth   Depth of the current comment.
   351 	 * @param int        $depth   Depth of the current comment.
   313 	 * @param array      $args    An array of arguments.
   352 	 * @param array      $args    An array of arguments.
   314 	 */
   353 	 */
   315 	protected function html5_comment( $comment, $depth, $args ) {
   354 	protected function html5_comment( $comment, $depth, $args ) {
   316 		$tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
   355 		$tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
   317 ?>
   356 
       
   357 		$commenter = wp_get_current_commenter();
       
   358 		if ( $commenter['comment_author_email'] ) {
       
   359 			$moderation_note = __( 'Your comment is awaiting moderation.' );
       
   360 		} else {
       
   361 			$moderation_note = __( 'Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.' );
       
   362 		}
       
   363 
       
   364 		?>
   318 		<<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?>>
   365 		<<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?>>
   319 			<article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
   366 			<article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
   320 				<footer class="comment-meta">
   367 				<footer class="comment-meta">
   321 					<div class="comment-author vcard">
   368 					<div class="comment-author vcard">
   322 						<?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
   369 						<?php
       
   370 						if ( 0 != $args['avatar_size'] ) {
       
   371 							echo get_avatar( $comment, $args['avatar_size'] );}
       
   372 						?>
   323 						<?php
   373 						<?php
   324 							/* translators: %s: comment author link */
   374 							/* translators: %s: comment author link */
   325 							printf( __( '%s <span class="says">says:</span>' ),
   375 							printf(
       
   376 								__( '%s <span class="says">says:</span>' ),
   326 								sprintf( '<b class="fn">%s</b>', get_comment_author_link( $comment ) )
   377 								sprintf( '<b class="fn">%s</b>', get_comment_author_link( $comment ) )
   327 							);
   378 							);
   328 						?>
   379 						?>
   329 					</div><!-- .comment-author -->
   380 					</div><!-- .comment-author -->
   330 
   381 
   339 						</a>
   390 						</a>
   340 						<?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
   391 						<?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
   341 					</div><!-- .comment-metadata -->
   392 					</div><!-- .comment-metadata -->
   342 
   393 
   343 					<?php if ( '0' == $comment->comment_approved ) : ?>
   394 					<?php if ( '0' == $comment->comment_approved ) : ?>
   344 					<p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></p>
   395 					<em class="comment-awaiting-moderation"><?php echo $moderation_note; ?></em>
   345 					<?php endif; ?>
   396 					<?php endif; ?>
   346 				</footer><!-- .comment-meta -->
   397 				</footer><!-- .comment-meta -->
   347 
   398 
   348 				<div class="comment-content">
   399 				<div class="comment-content">
   349 					<?php comment_text(); ?>
   400 					<?php comment_text(); ?>
   350 				</div><!-- .comment-content -->
   401 				</div><!-- .comment-content -->
   351 
   402 
   352 				<?php
   403 				<?php
   353 				comment_reply_link( array_merge( $args, array(
   404 				comment_reply_link(
   354 					'add_below' => 'div-comment',
   405 					array_merge(
   355 					'depth'     => $depth,
   406 						$args,
   356 					'max_depth' => $args['max_depth'],
   407 						array(
   357 					'before'    => '<div class="reply">',
   408 							'add_below' => 'div-comment',
   358 					'after'     => '</div>'
   409 							'depth'     => $depth,
   359 				) ) );
   410 							'max_depth' => $args['max_depth'],
       
   411 							'before'    => '<div class="reply">',
       
   412 							'after'     => '</div>',
       
   413 						)
       
   414 					)
       
   415 				);
   360 				?>
   416 				?>
   361 			</article><!-- .comment-body -->
   417 			</article><!-- .comment-body -->
   362 <?php
   418 		<?php
   363 	}
   419 	}
   364 }
   420 }