$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 '';
}
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 .= '';
}
if (!empty($perms['can_edit'])) {
$lists .= '';
}
if (!empty($perms['can_moderate'])) {
if ($is_pending) {
$lists .= '';
} elseif (!$is_spam) {
$lists .= '';
}
$lists .= '';
}
if (!empty($perms['can_delete'])) {
$lists .= '';
}
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;
// 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 (!$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 '';
}
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 ' is emitted by Walker_Comment after children.
}
endif;