function love_class( $class = '', $comment_id = null, $post_id = null, $echo = true) {// Separates classes with a single space, collates classes for comment DIV$class = 'class="' . join( ' ', love_comment_class( $class, $comment_id, $post_id ) ) . '"';
if ( $echo)
echo $class;
else
return $class;
}
function love_comment_class( $class = '', $comment_id = null, $post_id = null ) {
global $comment_alt, $comment_depth, $comment_thread_alt;
$comment = get_comment($comment_id);
$classes = array();
// Get the comment type (comment, trackback),
$classes[] = ( empty( $comment->comment_type ) ) ? 'comment' : $comment->comment_type;
// If the comment author has an id (registered), then print the log in name
if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) {
// For all registered users, 'byuser'
$classes[] = 'byuser comment-author-' . $user->user_nicename;
// For comment authors who are the author of the post
if ( $post = get_post($post_id) ) {
if ( $comment->user_id === $post->post_author )
$classes[] = 'bypostauthor';
}
}
if ( empty($comment_alt) )
$comment_alt = 0;
if ( empty($comment_depth) )
$comment_depth = 1;
if ( empty($comment_thread_alt) )
$comment_thread_alt = 0;
if ( $comment_alt % 2 ) {
if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) {
$classes[] = 'odd-' . $user->user_login;
$classes[] = 'alt-' . $user->user_login;
} else {
$classes[] = 'odd';
$classes[] = 'alt';
}
} else {
if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) {
$classes[] = 'even-' . $user->user_login;
} else {
$classes[] = 'even';
}
}
$comment_alt++;
// Alt for top-level comments
if ( 1 == $comment_depth ) {
if ( $comment_thread_alt % 2 ) {
$classes[] = 'thread-odd';
$classes[] = 'thread-alt';
} else {
$classes[] = 'thread-even';
}
$comment_thread_alt++;
}
$classes[] = "depth-$comment_depth";
if ( !empty($class) ) {
if ( !is_array( $class ) )
$class = preg_split('#s+#', $class);
$classes = array_merge($classes, $class);
}
return apply_filters('comment_class', $classes, $class, $comment_id, $post_id);
} |