评论区硬切换实现
This commit is contained in:
1 parent
ed914d2eec
commit
b8ef4d81a4
32 files changed
+946
-1008
No files matched your search
@@ -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