feat(comments): 评论区按 Zibll 1:1 全量复刻

- 评论项/表单/工具栏/筛选/分页/空状态 DOM 全部替换为 zibll 原始类名
  (li.comment、comt-main、comt-meta、list-inline、dropup 工具栏、
  theme-pagination/pagenav、post_ajax_loader 骨架等)
- 移植 zibll main.css L9412–9751 桌面 + 移动端评论样式,
  缺失基础组件(title-theme/dropdown-menu/line-form/tab-nav-theme 等)
  以 #comments 作用域补齐
- 删除全部 aksrt-comment__* 旧类名与旧样式,无兼容层
- JS 选择器对齐 zibll DOM:片段整块替换 #postcomments、骨架加载、
  跳页输入、prepend 插入、addComment onclick 剥离,
  移除 WP comment-reply enqueue 避免双 moveForm
- 表情资源替换为 zibll 全套 gif(内容逐字节一致,git 无差异)
- REST 后端 (CommentActions) 不变

验证:php -l 全部通过;5 个改动 JS 语法校验通过;
node --test tests/widget-system/post-visual-contract.test.cjs 12/12 通过
This commit is contained in:
2026-08-22 13:29:51 +08:00
parent 251fe86527
commit e1f176429b
15 changed files with 1286 additions and 1439 deletions
+11
View File
@@ -114,6 +114,17 @@ if (!function_exists('aksrt_render_comment_content')) :
['<pre class="comment-code"><code>', '</code></pre>'],
(string) $rendered
);
// [link=url target=_blank]text[/link] / [link=url]text[/link]
$rendered = preg_replace(
'/\[link=(https?:\/\/[^\s\[\]]+) target=_blank\]([^\[]*)\[\/link\]/i',
'<a href="$1" target="_blank" rel="nofollow">$2</a>',
(string) $rendered
);
$rendered = preg_replace(
'/\[link=(https?:\/\/[^\s\[\]]+)\]([^\[]*)\[\/link\]/i',
'<a href="$1" rel="nofollow">$2</a>',
(string) $rendered
);
// [g=key]
$rendered = preg_replace_callback(
'/\[g=([^\]]+)\]/i',
+74 -54
View File
@@ -1,6 +1,9 @@
<?php
/**
* Comment form partials — virtual-input, expand toolbar, respond shell helpers.
* Comment form partials — virtual-input + expand toolbar (Zibll DOM contract).
*
* Mirrors zib_get_respond_mobile() and zib_get_input_expand_but()
* from zibll/inc/functions.
*
* @package AKSRT
*/
@@ -9,18 +12,19 @@ defined('ABSPATH') || exit;
if (!function_exists('aksrt_get_comment_virtual_input_html')) :
/**
* Mobile virtual input bar that opens FixedInput #respond.
* Mobile virtual input bar (zibll: zib_get_respond_mobile).
*
* @param string $placeholder Placeholder text.
* @param string $target CSS selector for FixedInput target.
* @param string $target CSS selector for the FixedInput target.
* @return string
*/
function aksrt_get_comment_virtual_input_html(string $placeholder = '', string $target = '#respond'): string {
$user_id = get_current_user_id();
$avatar = get_avatar($user_id, 36, '', '', ['class' => 'avatar-img']);
$avatar = get_avatar($user_id, 36, '', '', ['class' => 'avatar']);
if ($placeholder === '') {
$placeholder = __('说点什么吧...', 'aksrt');
}
$html = '<div class="flex ac jsb virtual-input hide-pc" fixed-input="' . esc_attr($target) . '">';
$html = '<div class="flex ac jsb virtual-input" fixed-input="' . esc_attr($target) . '">';
$html .= '<div class="flex flex1 ac">';
$html .= $avatar;
$html .= '<div class="text-ellipsis simulation mr10">' . esc_html($placeholder) . '</div>';
@@ -33,46 +37,27 @@ endif;
if (!function_exists('aksrt_get_input_expand_but')) :
/**
* zibll-style expand toolbar button + dropdown.
* zibll-style expand toolbar button + dropdown (zibll: zib_get_input_expand_but).
*
* @param string $type smilie|code|image|quick|upload.
* @param mixed $arg1 Type-specific.
* @param array<string,mixed> $ctx Optional context (upload enabled, phrases).
* @param string $type smilie|code|image|quick|link.
* @param mixed $arg1 Type-specific arg.
* @param array<string,mixed> $ctx Optional context (upload, phrases).
* @return string
*/
function aksrt_get_input_expand_but(string $type = 'smilie', $arg1 = null, array $ctx = []): string {
$but = '';
$dropdown = '';
switch ($type) {
case 'smilie':
$map = function_exists('aksrt_comment_smilie_map') ? aksrt_comment_smilie_map() : [];
$icons = '';
foreach ($map as $key => $url) {
$icons .= '<a class="smilie-icon" href="javascript:;" data-smilie="' . esc_attr((string) $key) . '"><img' . aksrt_get_lazy_attr('lazy_comment', (string) $url, '', aksrt_get_lazy_thumb('sm')) . ' alt="[' . esc_attr((string) $key) . ']" width="28" height="28"></a>';
}
$but = '<a class="but btn-input-expand input-smilie mr6" href="javascript:;" data-toggle-class="open" data-target=".dropdown-smilie-wrap" title="' . esc_attr__('表情', 'aksrt') . '"><i class="fa fas fa-fw fa-smile" aria-hidden="true"></i><span class="hide-sm">' . esc_html__('表情', 'aksrt') . '</span></a>';
$drop = '<div class="dropdown-smilie-wrap relative dropup"><div class="dropdown-smilie scroll-y mini-scrollbar dropdown-menu">' . $icons . '</div></div>';
return '<span class="dropup relative input-expand-wrap input-expand-smilie">' . $but . $drop . '</span>';
case 'code':
$but = '<a class="but btn-input-expand input-code mr6" href="javascript:;" data-toggle-class="open" data-target=".dropdown-code" title="' . esc_attr__('代码', 'aksrt') . '"><i class="fa fas fa-fw fa-code" aria-hidden="true"></i><span class="hide-sm">' . esc_html__('代码', 'aksrt') . '</span></a>';
$drop = '<div class="dropdown-code dropdown-menu box-body" style="width:280px;">'
. '<p class="muted-2-color em09 mb6">' . esc_html__('插入代码块', 'aksrt') . '</p>'
. '<textarea class="form-control mb6" rows="4" placeholder="' . esc_attr__('粘贴代码…', 'aksrt') . '"></textarea>'
. '<button type="button" class="but c-blue pw-1em input-code-submit">' . esc_html__('插入', 'aksrt') . '</button>'
. '</div>';
return '<span class="dropup relative input-expand-wrap input-expand-code">' . $but . $drop . '</span>';
case 'image':
$upload = !empty($arg1) || !empty($ctx['upload']);
$but = '<a class="but btn-input-expand input-image mr6" href="javascript:;" data-toggle-class="open" data-target=".dropdown-image" title="' . esc_attr__('图片', 'aksrt') . '"><i class="fa fas fa-fw fa-image" aria-hidden="true"></i><span class="hide-sm">' . esc_html__('图片', 'aksrt') . '</span></a>';
$upload_btn = $upload
? '<button type="button" class="but hollow mr6 input-image-upload" data-toolbar-action="upload-image">' . esc_html__('上传', 'aksrt') . '</button>'
: '';
$drop = '<div class="dropdown-image dropdown-menu box-body" style="width:280px;">'
. '<p class="muted-2-color em09 mb6">' . esc_html__('插入图片地址', 'aksrt') . '</p>'
. '<input type="url" class="form-control mb6 input-image-url" placeholder="https://" />'
. $upload_btn
. '<button type="button" class="but c-blue pw-1em input-image-submit">' . esc_html__('插入', 'aksrt') . '</button>'
. '</div>';
return '<span class="dropup relative input-expand-wrap input-expand-image">' . $but . $drop . '</span>';
case 'link':
$but = '<a class="but btn-input-expand input-link mr6" href="javascript:;"><i class="fa fa-fw fa-link" aria-hidden="true"></i><span class="hide-sm">' . esc_html__('链接', 'aksrt') . '</span></a>';
$dropdown = '<div class="dropdown-link">';
$dropdown .= '<p>' . esc_html__('请输入链接:', 'aksrt') . '</p>';
$dropdown .= '<p><textarea rows="2" tabindex="1" class="form-control input-textarea link-textarea" style="height:55px;" placeholder="https://..."></textarea></p>';
$dropdown .= '<p><input type="text" class="form-control link-text" placeholder="' . esc_attr__('链接文本', 'aksrt') . '"></p>';
$dropdown .= '<div class="text-right"><a type="submit" class="but c-blue pw-1em input-link-submit" href="javascript:;">' . esc_html__('确认', 'aksrt') . '</a></div>';
$dropdown .= '</div>';
break;
case 'quick':
$phrases = [];
@@ -81,30 +66,65 @@ if (!function_exists('aksrt_get_input_expand_but')) :
} elseif (!empty($ctx['quick_phrases']) && is_array($ctx['quick_phrases'])) {
$phrases = $ctx['quick_phrases'];
}
if (empty($phrases)) {
$phrases = [
__('不错,学习了', 'aksrt'),
__('感谢分享', 'aksrt'),
__('期待更新', 'aksrt'),
];
}
$items = '';
$sys_lists = '';
foreach ($phrases as $p) {
$items .= '<a class="quick-reply-item" href="javascript:;" data-text="' . esc_attr((string) $p) . '">' . esc_html((string) $p) . '</a>';
$sys_lists .= '<div class="quick-reply-item">' . esc_html((string) $p) . '</div>';
}
$but = '<a class="but btn-input-expand input-quick mr6" href="javascript:;" data-toggle-class="open" data-target=".dropdown-quick" title="' . esc_attr__('快捷', 'aksrt') . '"><i class="fa fas fa-fw fa-bolt" aria-hidden="true"></i><span class="hide-sm">' . esc_html__('快捷', 'aksrt') . '</span></a>';
$drop = '<div class="dropdown-quick dropdown-menu box-body scroll-y mini-scrollbar" style="max-height:220px;min-width:160px;">' . $items . '</div>';
return '<span class="dropup relative input-expand-wrap input-expand-quick">' . $but . $drop . '</span>';
if ($sys_lists === '') {
$sys_lists = '<div class="text-center muted-2-color" style="margin: 60px 0;">' . esc_html__('系统暂无快捷回复', 'aksrt') . '</div>';
}
$but = '<a class="but btn-input-expand input-quick mr6" href="javascript:;"><i class="fa fa-fw fa-bolt" aria-hidden="true"></i><span class="hide-sm">' . esc_html__('快捷回复', 'aksrt') . '</span></a>';
$dropdown = '<div class="relative dropdown-quick-often"><div class="quick-often-box scroll-y mini-scrollbar">' . $sys_lists . '</div></div>';
break;
case 'smilie':
$map = function_exists('aksrt_comment_smilie_map') ? aksrt_comment_smilie_map() : [];
$smilie_icon = '';
foreach ($map as $key => $url) {
$smilie_icon .= '<a class="smilie-icon" href="javascript:;" data-smilie="' . esc_attr((string) $key) . '"><img src="' . esc_url((string) $url) . '" alt="[' . esc_attr((string) $key) . ']" /></a>';
}
$but = '<a class="but btn-input-expand input-smilie mr6" href="javascript:;"><i class="fa fa-fw fa-smile-o" aria-hidden="true"></i><span class="hide-sm">' . esc_html__('表情', 'aksrt') . '</span></a>';
$dropdown = '<div class="dropdown-smilie scroll-y mini-scrollbar">' . $smilie_icon . '</div>';
break;
case 'code':
$but = '<a class="but btn-input-expand input-code mr6" href="javascript:;"><i class="fa fa-fw fa-code" aria-hidden="true"></i><span class="hide-sm">' . esc_html__('代码', 'aksrt') . '</span></a>';
$dropdown = '<div class="dropdown-code">';
$dropdown .= '<p>' . esc_html__('请输入代码:', 'aksrt') . '</p>';
$dropdown .= '<p><textarea rows="6" tabindex="1" class="form-control input-textarea" placeholder="' . esc_attr__('在此处粘贴或输入代码', 'aksrt') . '"></textarea></p>';
$dropdown .= '<div class="text-right"><a type="submit" class="but c-blue pw-1em input-code-submit" href="javascript:;">' . esc_html__('确认', 'aksrt') . '</a></div>';
$dropdown .= '</div>';
break;
case 'image':
$upload = !empty($arg1) || !empty($ctx['upload']);
$but = '<a class="but btn-input-expand input-image mr6" href="javascript:;"><i class="fa fa-fw fa-image" aria-hidden="true"></i><span class="hide-sm">' . esc_html__('图片', 'aksrt') . '</span></a>';
$dropdown = '<div class="dropdown-image">';
$dropdown .= '<p>' . esc_html__('请填写图片地址:', 'aksrt') . '</p>';
$dropdown .= '<p><textarea rows="2" tabindex="1" class="form-control input-textarea input-image-url" style="height:95px;" placeholder="http://..."></textarea></p>';
$dropdown .= '<div class="text-right">';
if ($upload) {
$dropdown .= '<a class="but c-yellow mr10 pw-1em input-image-upload" href="javascript:;">' . esc_html__('上传图片', 'aksrt') . '</a>';
}
$dropdown .= '<a type="submit" class="but c-blue pw-1em input-image-submit" href="javascript:;">' . esc_html__('确认', 'aksrt') . '</a>';
$dropdown .= '</div>';
$dropdown .= '</div>';
break;
default:
return '';
}
$con = $but . '<div class="dropdown-menu">' . $dropdown . '</div>';
return '<span class="dropup relative ' . esc_attr($type) . '">' . $con . '</span>';
}
endif;
if (!function_exists('aksrt_render_comment_expand_toolbar')) :
/**
* Render left-side expand tools based on settings.
* Render left-side expand tools based on settings (zibll order: smilie/code/image/link/quick).
*
* @param array<string,mixed> $ctx Comments context.
*/
+144 -102
View File
@@ -1,6 +1,9 @@
<?php
/**
* Comment list item renderer — zibll DOM contract.
* Comment list item renderer — Zibll DOM contract (1:1).
*
* Mirrors zib_comments_list / zib_get_comment_header / zib_get_comment_footer
* from zibll/inc/functions/zib-comments-list.php.
*
* @package AKSRT
*/
@@ -9,7 +12,11 @@ defined('ABSPATH') || exit;
if (!function_exists('aksrt_get_comment_like_html')) :
/**
* Header like control (zibll places like in comment-header).
* Header like control (zibll: zib_get_comment_like).
*
* @param WP_Comment $comment Comment.
* @param bool $enabled Like enabled.
* @return string
*/
function aksrt_get_comment_like_html($comment, bool $enabled = true): string {
if (!$enabled) {
@@ -19,29 +26,59 @@ if (!function_exists('aksrt_get_comment_like_html')) :
if ($comment_id <= 0) {
return '';
}
$like_count = function_exists('aksrt_get_comment_likes') ? aksrt_get_comment_likes($comment_id) : 0;
$like_count = function_exists('aksrt_get_comment_likes') ? (int) 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 : '';
$classes = 'action action-comment-like muted-2-color flex0 ml10' . ($is_liked ? ' actived' : '');
return sprintf(
'<a href="javascript:;" class="%1$s" data-comment-action="like" data-active="%2$s" data-pid="%3$d" aria-pressed="%4$s"><i class="%5$s fa-thumbs-up" aria-hidden="true"></i><count class="aksrt-comment__like-count"%6$s>%7$s</count></a>',
'<a href="javascript:;" data-comment-action="like" data-action="comment_like" class="%1$s" data-pid="%2$d" data-active="%3$s" aria-pressed="%4$s"><i class="fa fa-thumbs-up mr3" aria-hidden="true"></i><count>%5$s</count></a>',
esc_attr($classes),
$is_liked ? '1' : '0',
$comment_id,
$is_liked ? '1' : '0',
$is_liked ? 'true' : 'false',
$is_liked ? 'fa' : 'fa',
$like_count > 0 ? '' : ' hidden',
esc_html($count_attr)
esc_html((string) $like_count)
);
}
endif;
if (!function_exists('aksrt_get_comment_avatar_box')) :
/**
* Comment avatar box (zibll: zib_get_comment_avatar_box).
*
* @param WP_Comment $comment Comment.
* @param string $class Classes for the avatar wrapper.
* @param bool $link Wrap in a link when a target URL exists.
* @return string
*/
function aksrt_get_comment_avatar_box(WP_Comment $comment, string $class = 'avatar-img comt-avatar', bool $link = true): string {
$user_id = (int) $comment->user_id;
$size = 45;
$avatar = $user_id > 0
? get_avatar($user_id, $size, '', '', ['class' => 'avatar'])
: get_avatar($comment->comment_author_email, $size, '', '', ['class' => 'avatar']);
$html = '<span class="' . esc_attr($class) . '">' . $avatar . '</span>';
if (!$link) {
return $html;
}
if ($user_id > 0) {
$url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($user_id) : get_author_posts_url($user_id);
return '<a href="' . esc_url($url) . '">' . $html . '</a>';
}
if (!empty($comment->comment_author_url)) {
return '<a rel="nofollow" href="' . esc_url($comment->comment_author_url) . '">' . $html . '</a>';
}
return $html;
}
endif;
if (!function_exists('aksrt_get_comments_user_name_html')) :
/**
* Name row: topping + author link + identity + author/hot badges.
* Name row (zibll: zib_get_comments_user_name) — topping + author + badges.
*
* @param WP_Comment $comment Comment.
* @param array<string,mixed> $settings Display settings.
* @return string
*/
function aksrt_get_comments_user_name_html(WP_Comment $comment, array $settings = []): string {
$user_id = (int) $comment->user_id;
@@ -51,55 +88,65 @@ if (!function_exists('aksrt_get_comments_user_name_html')) :
$topping = '';
if ($is_pinned) {
$topping = '<badge class="badge-topping badge-topping jb-blue mr6 flex0 aksrt-comment__badge aksrt-comment__badge--pinned" title="' . esc_attr__('置顶评论', 'aksrt') . '"><i class="fa fas fa-thumbtack" aria-hidden="true"></i></badge>';
$topping = '<badge class="badge-topping jb-blue mr6 flex0" title="' . esc_attr__('置顶评论', 'aksrt') . '" data-toggle="tooltip"><i class="fa fa-thumbtack" aria-hidden="true"></i></badge>';
}
$user_name = '';
if ($user_id > 0) {
$user = get_userdata($user_id);
$display = $user instanceof WP_User ? $user->display_name : get_comment_author($comment);
$url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($user_id) : get_author_posts_url($user_id);
$name = '<a class="text-ellipsis font-bold aksrt-comment__author" href="' . esc_url($url) . '">' . esc_html($display) . '</a>';
if (function_exists('aksrt_render_user_identity_chips')) {
$name .= aksrt_render_user_identity_chips($user_id, 'comment');
if ($user instanceof WP_User) {
$url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($user_id) : get_author_posts_url($user_id);
$user_name = '<a class="text-ellipsis font-bold" href="' . esc_url($url) . '">' . esc_html($user->display_name) . '</a>';
if (function_exists('aksrt_render_user_identity_chips')) {
$user_name .= aksrt_render_user_identity_chips($user_id, 'comment');
}
}
} else {
$name = '<b class="mr6 aksrt-comment__author">' . esc_html(get_comment_author($comment)) . '</b>';
} elseif (!empty($comment->comment_author_url)) {
$user_name = '<a class="text-ellipsis font-bold" rel="nofollow" href="' . esc_url($comment->comment_author_url) . '">' . esc_html($comment->comment_author) . '</a>';
}
$badges = '';
$user_name = $user_name !== '' ? $user_name : '<b class="mr6 text-ellipsis">' . esc_html($comment->comment_author) . '</b>';
$badge = '';
if ($show_author_tag && $is_post_author) {
$badges .= '<span class="badg c-green badg-sm flex0 ml3 aksrt-comment__badge">' . esc_html__('作者', 'aksrt') . '</span>';
}
if (function_exists('aksrt_is_blog_comment_hot') && aksrt_is_blog_comment_hot($comment)) {
$badges .= '<span class="badg c-yellow badg-sm flex0 ml3 aksrt-comment__badge aksrt-comment__badge--hot"><i class="fa fas fa-fire" aria-hidden="true"></i> ' . esc_html__('神评', 'aksrt') . '</span>';
$badge .= '<span class="badg c-green badg-sm flex0 ml3">' . esc_html__('作者', 'aksrt') . '</span>';
}
return '<name class="flex ac flex1">' . $topping . $name . $badges . '</name>';
return '<name class="flex ac flex1">' . $topping . $user_name . $badge . '</name>';
}
endif;
if (!function_exists('aksrt_get_comment_header_html')) :
/**
* Comment header (zibll: zib_get_comment_header).
*
* @param WP_Comment $comment Comment.
* @param array<string,mixed> $settings Settings.
* @return string
*/
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']);
$avatar = aksrt_get_comment_avatar_box($comment, 'avatar-img comt-avatar');
$name = aksrt_get_comments_user_name_html($comment, $settings);
$like = aksrt_get_comment_like_html($comment, $like_enabled);
$inner = '<div class="author-box flex ac">' . $avatar . $name . $like . '</div>';
return '<div class="comment-header mb10 aksrt-comment__header">' . $inner . '</div>';
$html = '<div class="author-box flex ac">';
$html .= $avatar;
$html .= $name;
$html .= $like;
$html .= '</div>';
return '<div class="comment-header mb10">' . $html . '</div>';
}
endif;
if (!function_exists('aksrt_get_comments_action_dropdown_html')) :
/**
* More menu: pin / edit / approve / delete (REST-driven via data-comment-action).
* More-actions menu (zibll: zib_get_comments_action_list) — pin / edit / approve / delete.
*
* @param WP_Comment $comment Comment.
* @param int $depth Depth.
* @return string
*/
function aksrt_get_comments_action_dropdown_html(WP_Comment $comment, int $depth = 0): string {
$perms = function_exists('aksrt_comment_action_permissions')
@@ -107,95 +154,86 @@ if (!function_exists('aksrt_get_comments_action_dropdown_html')) :
: ['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 .= '<li><a href="javascript:;" class="comment-topping-link" data-comment-action="pin" data-pinned="' . ($is_pinned ? '1' : '0') . '"><i class="fa fas fa-thumbtack fa-fw mr10" aria-hidden="true"></i>' . esc_html($label) . '</a></li>';
$label = $is_pinned ? __('取消置顶', 'aksrt') : __('设置置顶', 'aksrt');
$lists .= '<li><a class="comment-topping wp-ajax-submit" data-comment-action="pin" data-pinned="' . ($is_pinned ? '1' : '0') . '" href="javascript:;"><i class="fa fa-thumbtack mr10 fa-fw" aria-hidden="true"></i>' . esc_html($label) . '</a></li>';
}
if (!empty($perms['can_edit'])) {
$lists .= '<li><a href="javascript:;" class="comment-edit-link" data-comment-action="edit" data-commentid="' . (int) $comment->comment_ID . '" data-postid="' . (int) $comment->comment_post_ID . '"><i class="fa fas fa-edit fa-fw mr10" aria-hidden="true"></i>' . esc_html__('编辑', 'aksrt') . '</a></li>';
$lists .= '<li><a class="comment-edit-link" data-commentid="' . (int) $comment->comment_ID . '" data-postid="' . (int) $comment->comment_post_ID . '" href="javascript:;"><i class="fa fa-edit mr10 fa-fw" aria-hidden="true"></i>' . esc_html__('编辑', 'aksrt') . '</a></li>';
}
if (!empty($perms['can_moderate'])) {
if ($is_pending) {
$lists .= '<li><a href="javascript:;" class="comment-approve-link approve" data-comment-action="approve"><i class="fa fas fa-check fa-fw mr10" aria-hidden="true"></i><text>' . esc_html__('批准', 'aksrt') . '</text></a></li>';
} elseif (!$is_spam) {
$lists .= '<li><a href="javascript:;" class="comment-approve-link unapprove" data-comment-action="hold"><i class="fa fas fa-eye-slash fa-fw mr10" aria-hidden="true"></i><text>' . esc_html__('驳回', 'aksrt') . '</text></a></li>';
}
$lists .= '<li><a href="javascript:;" class="comment-spam-link" data-comment-action="spam"><i class="fa fas fa-ban fa-fw mr10" aria-hidden="true"></i>' . esc_html__('垃圾', 'aksrt') . '</a></li>';
$text = $is_pending ? __('批准', 'aksrt') : __('驳回', 'aksrt');
$class = $is_pending ? 'approve' : 'unapprove';
$action = $is_pending ? 'approve' : 'hold';
$lists .= '<li><a class="comment-approve-link ' . $class . '" data-comment-action="' . $action . '" data-commentid="' . (int) $comment->comment_ID . '" data-postid="' . (int) $comment->comment_post_ID . '" href="javascript:;"><i class="fa fa-check mr10 fa-fw" aria-hidden="true"></i><text>' . esc_html($text) . '</text></a></li>';
}
if (!empty($perms['can_delete'])) {
$lists .= '<li><a href="javascript:;" class="comment-trash-link c-red" data-comment-action="delete" data-commentid="' . (int) $comment->comment_ID . '"><i class="fa fas fa-trash-alt fa-fw mr10" aria-hidden="true"></i>' . esc_html__('删除', 'aksrt') . '</a></li>';
$lists .= '<li><a class="comment-trash-link c-red" data-comment-action="delete" data-commentid="' . (int) $comment->comment_ID . '" data-postid="' . (int) $comment->comment_post_ID . '" href="javascript:;"><i class="fa fa-trash-o mr10 fa-fw" aria-hidden="true"></i>' . esc_html__('删除', 'aksrt') . '</a></li>';
}
if ($lists === '') {
return '';
}
return '<span class="dropdown drop-fixed-sm padding-6 comment-action-dropdown">'
. '<a href="javascript:;" class="muted-color padding-6" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" aria-label="' . esc_attr__('更多操作', 'aksrt') . '"><i class="fa fas fa-ellipsis-h" aria-hidden="true"></i></a>'
. '<ul class="dropdown-menu">' . $lists . '</ul>'
. '</span>';
$icon_a = '<a href="javascript:;" class="muted-color padding-6" data-toggle="dropdown"><i class="fa fa-ellipsis-h" aria-hidden="true"></i></a>';
return '<span class="dropdown drop-fixed-sm padding-6">' . $icon_a . '<ul class="dropdown-menu">' . $lists . '</ul></span>';
}
endif;
if (!function_exists('aksrt_get_comment_footer_html')) :
/**
* comt-meta: time-ago · city · @parent · approve · reply · dropdown.
* comt-meta row (zibll: zib_get_comment_footer).
*
* @param WP_Comment $comment Comment.
* @param array $args wp_list_comments args.
* @param int $depth Depth.
* @param array<string,mixed> $settings Settings.
* @return string
*/
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));
$badg_approve = '';
if ($is_pending) {
$badg_approve = '<span class="badg c-red badg-sm">' . esc_html__('待审核', 'aksrt') . '</span>';
}
$badg_approve = '<span class="badge-approve">' . $badg_approve . '</span>';
$absolute = date_i18n(__('Y年m月d日 H:i:s', 'aksrt'), 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 = '<span class="comt-author" title="' . esc_attr($absolute) . '">' . esc_html($ago) . '</span>';
// 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 = '<span>@<a rel="nofollow" class="url" href="javascript:;" data-scroll-to="#comment-' . (int) $comment->comment_parent . '">' . esc_html($parent_author) . '</a></span>';
}
// Pending badge.
$approve_html = '<span class="badge-approve">';
if ($is_pending) {
$approve_html .= '<span class="badg c-red badg-sm">' . esc_html__('待审核', 'aksrt') . '</span>';
}
$approve_html .= '</span>';
// 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,
]
),
[
'add_below' => 'div-comment',
'reply_text' => __('回复', 'aksrt'),
'login_text' => __('回复', 'aksrt'),
'depth' => $depth,
'max_depth' => $max_depth,
],
$comment
);
if ($link) {
// Ensure data-commentid for moveForm path.
// 去掉 WP 内联 onclick(addComment.moveForm),回复由 comment-move-form.js 事件委托处理。
$link = preg_replace('/ onclick="[^"]*"/i', '', $link);
if (strpos($link, 'data-commentid') === false) {
$link = str_replace(
'comment-reply-link',
@@ -208,15 +246,49 @@ if (!function_exists('aksrt_get_comment_footer_html')) :
}
$actions = aksrt_get_comments_action_dropdown_html($comment, $depth);
$info = $time_html . $city_html . $parent_html . $approve_html . $reply_html;
$info = $time_html . $city_html . $parent_html . $badg_approve . $reply_html;
return '<div class="comt-meta muted-2-color aksrt-comment__actions">' . $info . $actions . '</div>';
return '<div class="comt-meta muted-2-color">' . $info . $actions . '</div>';
}
endif;
if (!function_exists('aksrt_get_comments_list_html')) :
/**
* Single comment item HTML (zibll: zib_get_comments_list).
*
* @param WP_Comment $comment Comment.
* @param array $args Args.
* @param int $depth Depth.
* @param array $settings Settings.
* @return string
*/
function aksrt_get_comments_list_html(WP_Comment $comment, array $args = [], int $depth = 0, array $settings = []): string {
$comment_id = (int) $comment->comment_ID;
$con = function_exists('aksrt_render_comment_content')
? aksrt_render_comment_content((string) get_comment_text($comment))
: wp_kses_post((string) get_comment_text($comment));
$header = aksrt_get_comment_header_html($comment, $settings);
$footer = aksrt_get_comment_footer_html($comment, $args, $depth, $settings);
$html = '<li ' . comment_class('', $comment, null, false) . ' id="comment-' . esc_attr((string) $comment_id) . '">';
$html .= '<ul class="list-inline">';
$html .= '<li class="comt-main" id="div-comment-' . esc_attr((string) $comment_id) . '">';
$html .= $header;
$html .= '<div class="comment-footer">';
$html .= '<div class="mb10 comment-content" id="comment-content-' . esc_attr((string) $comment_id) . '">' . $con . '</div>';
$html .= $footer;
$html .= '</div>';
$html .= '</li>';
$html .= '</ul>';
return $html;
}
endif;
if (!function_exists('aksrt_comment_callback')) :
/**
* Canonical comment list item renderer (zibll structure).
* Canonical wp_list_comments callback (zibll: zib_comments_list).
*
* The closing </li> is emitted by the walker after children.
*
* @param WP_Comment $comment Comment.
* @param array $args Args.
@@ -230,37 +302,7 @@ if (!function_exists('aksrt_comment_callback')) :
$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 = '<p class="awaiting-moderation">' . esc_html__('您的评论正在等待审核。', 'aksrt') . '</p>';
} 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 '<li ';
comment_class('aksrt-comment ' . $li_classes);
echo ' id="comment-' . esc_attr((string) $comment_id) . '" data-comment-id="' . esc_attr((string) $comment_id) . '" data-comment-status="' . esc_attr((string) $comment->comment_approved) . '">';
echo '<ul class="list-inline">';
echo '<li class="comt-main" id="div-comment-' . esc_attr((string) $comment_id) . '">';
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- composed helpers escape.
echo $header;
echo '<div class="comment-footer">';
echo '<div class="mb10 comment-content aksrt-comment__text" id="comment-content-' . esc_attr((string) $comment_id) . '">' . $body . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $footer;
echo '</div>';
echo '</li>';
echo '</ul>';
// Closing </li> is emitted by Walker_Comment after children.
echo aksrt_get_comments_list_html($comment, is_array($args) ? $args : [], (int) $depth, $settings);
}
endif;