评论区硬切换实现
This commit is contained in:
1 parent
ed914d2eec
commit
b8ef4d81a4
32 files changed
+946
-1008
No files matched your search
@@ -39,9 +39,9 @@ if (!function_exists('aksrt_get_input_expand_but')) :
|
||||
/**
|
||||
* legacy-style expand toolbar button + dropdown (legacy: legacy).
|
||||
*
|
||||
* @param string $type code|image|quick|link.
|
||||
* @param string $type code|image|link.
|
||||
* @param mixed $arg1 Type-specific arg.
|
||||
* @param array<string,mixed> $ctx Optional context (upload, phrases).
|
||||
* @param array<string,mixed> $ctx Optional context (upload).
|
||||
* @return string
|
||||
*/
|
||||
function aksrt_get_input_expand_but(string $type, $arg1 = null, array $ctx = []): string {
|
||||
@@ -59,25 +59,6 @@ if (!function_exists('aksrt_get_input_expand_but')) :
|
||||
$dropdown .= '</div>';
|
||||
break;
|
||||
|
||||
case 'quick':
|
||||
$phrases = [];
|
||||
if (is_string($arg1) && $arg1 !== '') {
|
||||
$phrases = array_values(array_filter(array_map('trim', preg_split('/\r\n|\r|\n/', $arg1) ?: [])));
|
||||
} elseif (!empty($ctx['quick_phrases']) && is_array($ctx['quick_phrases'])) {
|
||||
$phrases = $ctx['quick_phrases'];
|
||||
}
|
||||
$sys_lists = '';
|
||||
foreach ($phrases as $p) {
|
||||
$sys_lists .= '<div class="quick-reply-item">' . esc_html((string) $p) . '</div>';
|
||||
}
|
||||
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 '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">';
|
||||
@@ -114,15 +95,14 @@ endif;
|
||||
|
||||
if (!function_exists('aksrt_render_comment_expand_toolbar')) :
|
||||
/**
|
||||
* Render left-side expand tools based on settings (legacy order: code/image/link/quick).
|
||||
* Render left-side expand tools based on settings (legacy order: code/image/link).
|
||||
*
|
||||
* @param array<string,mixed> $ctx Comments context.
|
||||
*/
|
||||
function aksrt_render_comment_expand_toolbar(array $ctx): void {
|
||||
$toolbar = is_array($ctx['toolbar'] ?? null) ? $ctx['toolbar'] : [];
|
||||
$upload = !empty($ctx['upload_enabled']);
|
||||
$phrases = is_array($ctx['quick_phrases'] ?? null) ? $ctx['quick_phrases'] : [];
|
||||
$quick_s = !isset($ctx['quick_s']) || !empty($ctx['quick_s']);
|
||||
$link_s = !empty($ctx['link_enabled']);
|
||||
|
||||
if (!empty($toolbar['code'])) {
|
||||
echo aksrt_get_input_expand_but('code'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
@@ -130,8 +110,8 @@ if (!function_exists('aksrt_render_comment_expand_toolbar')) :
|
||||
if (!empty($toolbar['image'])) {
|
||||
echo aksrt_get_input_expand_but('image', $upload, ['upload' => $upload]); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
if ($quick_s) {
|
||||
echo aksrt_get_input_expand_but('quick', null, ['quick_phrases' => $phrases]); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
if ($link_s) {
|
||||
echo aksrt_get_input_expand_but('link'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
}
|
||||
endif;
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Comment sprite icons — <use> references into the runtime svg-icon sprite.
|
||||
*
|
||||
* Mirrors zib_get_svg() from the reference comments module. Symbol
|
||||
* definitions are injected by assets/js/runtime/svg-icon.js, which the
|
||||
* vendor runtime lazy-loads on every page (main.js: tbquire(['svg-icon'])).
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
if (!function_exists('aksrt_get_comment_icon')) :
|
||||
/**
|
||||
* Sprite-referenced SVG icon (legacy: zib_get_svg).
|
||||
*
|
||||
* @param string $name Sprite key (like / topping / approve / menu_2 / signup).
|
||||
* @param string $class Classes for the svg element.
|
||||
* @return string
|
||||
*/
|
||||
function aksrt_get_comment_icon(string $name, string $class = 'icon'): string {
|
||||
return '<svg class="' . esc_attr($class) . '" aria-hidden="true"><use xlink:href="#icon-' . esc_attr($name) . '"></use></svg>';
|
||||
}
|
||||
endif;
|
||||
@@ -29,13 +29,15 @@ if (!function_exists('aksrt_get_comment_like_html')) :
|
||||
$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' . ($is_liked ? ' actived' : '');
|
||||
$icon = function_exists('aksrt_get_comment_icon') ? aksrt_get_comment_icon('like', 'icon mr3') : '';
|
||||
|
||||
return sprintf(
|
||||
'<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>',
|
||||
'<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">%5$s<text></text><count>%6$s</count></a>',
|
||||
esc_attr($classes),
|
||||
$comment_id,
|
||||
$is_liked ? '1' : '0',
|
||||
$is_liked ? 'true' : 'false',
|
||||
$icon, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- fixed sprite markup.
|
||||
esc_html((string) $like_count)
|
||||
);
|
||||
}
|
||||
@@ -88,7 +90,8 @@ if (!function_exists('aksrt_get_comments_user_name_html')) :
|
||||
|
||||
$topping = '';
|
||||
if ($is_pinned) {
|
||||
$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>';
|
||||
$topping_icon = function_exists('aksrt_get_comment_icon') ? aksrt_get_comment_icon('topping') : '';
|
||||
$topping = '<badge class="badge-topping jb-blue mr6 flex0" title="' . esc_attr__('置顶评论', 'aksrt') . '" data-toggle="tooltip">' . $topping_icon . '</badge>';
|
||||
}
|
||||
|
||||
$user_name = '';
|
||||
@@ -166,10 +169,11 @@ if (!function_exists('aksrt_get_comments_action_dropdown_html')) :
|
||||
$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'])) {
|
||||
$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>';
|
||||
$text = $is_pending ? __('批准', 'aksrt') : __('驳回', 'aksrt');
|
||||
$class = $is_pending ? 'approve' : 'unapprove';
|
||||
$action = $is_pending ? 'approve' : 'hold';
|
||||
$approve_icon = function_exists('aksrt_get_comment_icon') ? aksrt_get_comment_icon('approve', 'mr10 icon fa-fw') : '';
|
||||
$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:;">' . $approve_icon . '<text>' . esc_html($text) . '</text></a></li>';
|
||||
}
|
||||
if (!empty($perms['can_delete'])) {
|
||||
$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>';
|
||||
@@ -179,7 +183,8 @@ if (!function_exists('aksrt_get_comments_action_dropdown_html')) :
|
||||
return '';
|
||||
}
|
||||
|
||||
$icon_a = '<a href="javascript:;" class="muted-color padding-6" data-toggle="dropdown"><i class="fa fa-ellipsis-h" aria-hidden="true"></i></a>';
|
||||
$menu_icon = function_exists('aksrt_get_comment_icon') ? aksrt_get_comment_icon('menu_2') : '';
|
||||
$icon_a = '<a href="javascript:;" class="muted-color padding-6" data-toggle="dropdown">' . $menu_icon . '</a>';
|
||||
|
||||
return '<span class="dropdown drop-fixed-sm padding-6">' . $icon_a . '<ul class="dropdown-menu">' . $lists . '</ul></span>';
|
||||
}
|
||||
@@ -198,6 +203,8 @@ if (!function_exists('aksrt_get_comment_footer_html')) :
|
||||
function aksrt_get_comment_footer_html(WP_Comment $comment, array $args, int $depth, array $settings = []): string {
|
||||
$is_pending = '0' === (string) $comment->comment_approved;
|
||||
|
||||
$is_mobile = wp_is_mobile();
|
||||
|
||||
$badg_approve = '';
|
||||
if ($is_pending) {
|
||||
$badg_approve = '<span class="badg c-red badg-sm">' . esc_html__('待审核', 'aksrt') . '</span>';
|
||||
@@ -208,7 +215,7 @@ if (!function_exists('aksrt_get_comment_footer_html')) :
|
||||
$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>';
|
||||
$time_html = '<span class="comt-author"' . ($is_mobile ? ' data-toggle="tooltip"' : '') . ' title="' . esc_attr($absolute) . '">' . esc_html($ago) . '</span>';
|
||||
|
||||
$city_html = function_exists('aksrt_get_comment_city_badge_html')
|
||||
? aksrt_get_comment_city_badge_html($comment)
|
||||
@@ -236,6 +243,8 @@ if (!function_exists('aksrt_get_comment_footer_html')) :
|
||||
if ($link) {
|
||||
// 去掉 WP 内联 onclick(addComment.moveForm),回复由 comment-move-form.js 事件委托处理。
|
||||
$link = preg_replace('/ onclick="[^"]*"/i', '', $link);
|
||||
// legacy 契约:aria-label 换成 tooltip 触发属性。
|
||||
$link = preg_replace('# aria-label=#', $is_mobile ? ' title=' : ' data-toggle="tooltip" title=', $link);
|
||||
if (strpos($link, 'data-commentid') === false) {
|
||||
$link = str_replace(
|
||||
'comment-reply-link',
|
||||
|
||||
Reference in new issue
Block a user