comment_ID : (int) $comment; if ($comment_id <= 0) { return ''; } $like_count = function_exists('aksrt_get_comment_likes') ? aksrt_get_comment_likes($comment_id) : 0; $is_liked = function_exists('aksrt_is_comment_liked') && aksrt_is_comment_liked($comment_id); $classes = 'action action-comment-like muted-2-color flex0 ml10 aksrt-comment__like' . ($is_liked ? ' is-active' : ''); $count_attr = $like_count > 0 ? (string) $like_count : ''; return sprintf( '%7$s', esc_attr($classes), $is_liked ? '1' : '0', $comment_id, $is_liked ? 'true' : 'false', $is_liked ? 'fas' : 'far', $like_count > 0 ? '' : ' hidden', esc_html($count_attr) ); } endif; if (!function_exists('aksrt_get_comments_user_name_html')) : /** * Name row: topping + author link + identity + author/hot badges. * * @param WP_Comment $comment Comment. * @param array $settings Display settings. */ function aksrt_get_comments_user_name_html(WP_Comment $comment, array $settings = []): string { $user_id = (int) $comment->user_id; $show_author_tag = !isset($settings['author_tag']) || !empty($settings['author_tag']); $is_pinned = function_exists('aksrt_is_comment_pinned') && aksrt_is_comment_pinned($comment); $is_post_author = $user_id > 0 && $user_id === (int) get_post_field('post_author', $comment->comment_post_ID); $topping = ''; if ($is_pinned) { $topping = ''; } if ($user_id > 0) { $user = get_userdata($user_id); $display = $user instanceof WP_User ? $user->display_name : get_comment_author($comment); $url = get_author_posts_url($user_id); $name = '' . esc_html($display) . ''; if (function_exists('aksrt_render_user_identity_chips')) { $name .= aksrt_render_user_identity_chips($user_id, 'comment'); } } else { $name = '' . esc_html(get_comment_author($comment)) . ''; } $badges = ''; if ($show_author_tag && $is_post_author) { $badges .= '' . esc_html__('作者', 'aksrt') . ''; } if (function_exists('aksrt_is_blog_comment_hot') && aksrt_is_blog_comment_hot($comment)) { $badges .= ' ' . esc_html__('神评', 'aksrt') . ''; } return '' . $topping . $name . $badges . ''; } endif; if (!function_exists('aksrt_get_comment_header_html')) : /** * @param WP_Comment $comment Comment. * @param array $settings Settings. */ function aksrt_get_comment_header_html(WP_Comment $comment, array $settings = []): string { $avatar_size = max(24, (int) ($settings['avatar_size'] ?? 45)); $like_enabled = !isset($settings['like_enabled']) || !empty($settings['like_enabled']); $avatar = get_avatar($comment, $avatar_size, '', '', ['class' => 'avatar-img comt-avatar']); $name = aksrt_get_comments_user_name_html($comment, $settings); $like = aksrt_get_comment_like_html($comment, $like_enabled); $inner = '
' . $avatar . $name . $like . '
'; return '
' . $inner . '
'; } endif; if (!function_exists('aksrt_get_comments_action_dropdown_html')) : /** * More menu: pin / edit / approve / delete (REST-driven via data-comment-action). * * @param WP_Comment $comment Comment. * @param int $depth Depth. */ function aksrt_get_comments_action_dropdown_html(WP_Comment $comment, int $depth = 0): string { $perms = function_exists('aksrt_comment_action_permissions') ? aksrt_comment_action_permissions($comment) : ['can_edit' => false, 'can_delete' => false, 'can_moderate' => false, 'can_pin' => false]; $is_pinned = function_exists('aksrt_is_comment_pinned') && aksrt_is_comment_pinned($comment); $is_pending = '0' === (string) $comment->comment_approved; $is_spam = 'spam' === (string) $comment->comment_approved; $lists = ''; if (!empty($perms['can_pin']) && (int) $comment->comment_parent === 0) { $label = $is_pinned ? __('取消置顶', 'aksrt') : __('设置置顶', 'aksrt'); $lists .= '
  • ' . esc_html($label) . '
  • '; } if (!empty($perms['can_edit'])) { $lists .= '
  • ' . esc_html__('编辑', 'aksrt') . '
  • '; } if (!empty($perms['can_moderate'])) { if ($is_pending) { $lists .= '
  • ' . esc_html__('批准', 'aksrt') . '
  • '; } elseif (!$is_spam) { $lists .= '
  • ' . esc_html__('驳回', 'aksrt') . '
  • '; } $lists .= '
  • ' . esc_html__('垃圾', 'aksrt') . '
  • '; } if (!empty($perms['can_delete'])) { $lists .= '
  • ' . esc_html__('删除', 'aksrt') . '
  • '; } if ($lists === '') { return ''; } return '' . '' . '' . ''; } endif; if (!function_exists('aksrt_get_comment_footer_html')) : /** * comt-meta: time-ago · city · @parent · approve · reply · dropdown. * * @param WP_Comment $comment Comment. * @param array $args wp_list_comments args. * @param int $depth Depth. * @param array $settings Settings. */ function aksrt_get_comment_footer_html(WP_Comment $comment, array $args, int $depth, array $settings = []): string { $is_pending = '0' === (string) $comment->comment_approved; $allow_reply = !empty($settings['allow_reply']); // Time ago. $absolute = date_i18n('Y-m-d H:i:s', strtotime((string) $comment->comment_date)); $ago = function_exists('aksrt_time_ago') ? aksrt_time_ago((string) $comment->comment_date) : human_time_diff(strtotime((string) $comment->comment_date), current_time('timestamp')) . __('前', 'aksrt'); $time_html = '' . esc_html($ago) . ''; // City. $city_html = function_exists('aksrt_get_comment_city_badge_html') ? aksrt_get_comment_city_badge_html($comment) : ''; // @ parent. $parent_html = ''; if ((int) $comment->comment_parent > 0) { $parent_author = get_comment_author((int) $comment->comment_parent); $parent_html = '@' . esc_html($parent_author) . ''; } // Pending badge. $approve_html = ''; if ($is_pending) { $approve_html .= '' . esc_html__('待审核', 'aksrt') . ''; } $approve_html .= ''; // Reply. $reply_html = ''; if ($allow_reply && !$is_pending && $depth > 0) { $max_depth = (int) ($args['max_depth'] ?? get_option('thread_comments_depth', 5)); $link = get_comment_reply_link( array_merge( $args, [ 'add_below' => 'div-comment', 'reply_text' => __('回复', 'aksrt'), 'depth' => $depth, 'max_depth' => $max_depth, ] ), $comment ); if ($link) { // Ensure data-commentid for moveForm path. if (strpos($link, 'data-commentid') === false) { $link = str_replace( 'comment-reply-link', 'comment-reply-link" data-commentid="' . (int) $comment->comment_ID . '" data-postid="' . (int) $comment->comment_post_ID, $link ); } $reply_html = '' . $link . ''; } } $actions = aksrt_get_comments_action_dropdown_html($comment, $depth); $info = $time_html . $city_html . $parent_html . $approve_html . $reply_html; return '
    ' . $info . $actions . '
    '; } endif; if (!function_exists('aksrt_comment_callback')) : /** * Canonical comment list item renderer (zibll structure). * * @param WP_Comment $comment Comment. * @param array $args Args. * @param int $depth Depth. */ function aksrt_comment_callback($comment, $args, $depth) { $GLOBALS['comment'] = $comment; $settings = get_query_var('aksrt_comment_settings', []); $settings = is_array($settings) ? $settings : []; if (empty($settings) && class_exists('\AKSRT\Settings\Settings')) { $settings = \AKSRT\Settings\Settings::get_comment_display_settings(); } $comment_id = (int) $comment->comment_ID; $depth_class = 'aksrt-depth-' . min((int) ($settings['nested_depth'] ?? 3), (int) $depth); $is_pinned = function_exists('aksrt_is_comment_pinned') && aksrt_is_comment_pinned($comment); $is_pending = '0' === (string) $comment->comment_approved; $li_classes = trim($depth_class . ($is_pinned ? ' aksrt-comment--pinned' : '')); $header = aksrt_get_comment_header_html($comment, $settings); $footer = aksrt_get_comment_footer_html($comment, $args, (int) $depth, $settings); if ($is_pending) { $body = '

    ' . esc_html__('您的评论正在等待审核。', 'aksrt') . '

    '; } else { $body = function_exists('aksrt_render_comment_content') ? aksrt_render_comment_content((string) get_comment_text($comment)) : wp_kses_post((string) get_comment_text($comment)); } echo '
  • '; echo '
      '; echo '
    • '; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- composed helpers escape. echo $header; echo ''; echo '
    • '; echo '
    '; // Closing
  • is emitted by Walker_Comment after children. } endif;