feat(ban): mirror reference theme ban/restriction prompt surface
修复公开主页禁封提示框为空的问题,并对齐参考主题(Zibll)全部前台禁封提示入口: - fix(profile): 资料卡下方治理提示框渲染为空——模板读取的 tone/message 键与 数据层实际输出的 state/label/text 契约不匹配;现按禁封类型展示 「违规已封号/小黑屋禁封中/禁言中」+ 可配置说明文案 - feat(ban): 用户中心页头展示治理状态徽章 + 查看详情入口,直达禁封申诉页 (参考主题 user_page_header_desc / zib_get_user_ban_info_link) - feat(ban): 评论拒绝态区分禁封/小黑屋/禁言,附状态徽章与申诉链接 (参考主题 zib_get_user_ban_nocan_info,原为笼统的无权限文案) - feat(ban): 禁封申诉页补全状态信息卡(状态/开始时间/结束时间/原因/说明/ 申诉权限),对齐 zib_get_ban_info_modal;此前仅有「禁封原因」一行且无入口 - feat(ban): 昵称旁禁封徽章 + 头像禁封角标(覆盖 VIP 位,参考主题 user_name_badge / user_avatar_badge 钩子语义),main.css 与入队的 main.min.css 同步新增角标样式 - fix(ban): 举报入口对已封禁/小黑屋目标隐藏(评论、文章下拉、封面菜单三处, 对齐 zib_get_report_link 排除语义;禁言为轻量限制不隐藏) - refactor(ban): 治理展示态收敛为单一数据源 Restriction::get_display_state() + state_labels(),资料卡/用户中心/评论拒绝态/昵称徽章共用 - feat(ban): 小黑屋用户开放申诉(对齐参考主题 zib_user_is_ban 双类型语义), 禁封站内信附加申诉页链接 - test: report-ban 契约测试 +3(展示态单一数据源、提示面入口矩阵、举报排除), 45 个测试文件全部通过
This commit is contained in:
@@ -237,16 +237,24 @@ if (!function_exists('aksrt_get_avatar_box')) {
|
||||
$img = aksrt_get_avatar_html($subject, 80, ['class' => 'avatar']);
|
||||
|
||||
$badge = '';
|
||||
if ($vip && $user_id > 0 && function_exists('aksrt_get_user_vip_level') && aksrt_get_user_vip_level($user_id) > 0) {
|
||||
$icon_url = '';
|
||||
if (class_exists('\AKSRT\Settings\Settings')) {
|
||||
$vip_settings = \AKSRT\Settings\Settings::get_payment_vip_settings();
|
||||
$level = aksrt_get_user_vip_level($user_id);
|
||||
$icon_url = esc_url((string) ($vip_settings['levels'][$level]['img_icon'] ?? ''));
|
||||
}
|
||||
if ($icon_url !== '') {
|
||||
$badge_text = function_exists('aksrt_get_vip_badge_text') ? aksrt_get_vip_badge_text($user_id) : 'VIP';
|
||||
$badge = '<img class="avatar-badge" src="' . $icon_url . '" title="' . esc_attr($badge_text) . '" alt="' . esc_attr($badge_text) . '">';
|
||||
if ($vip && $user_id > 0) {
|
||||
// 禁封角标覆盖 VIP 角标位(参考主题 user_avatar_badge 过滤器覆盖语义)。
|
||||
$ban_badge = function_exists('aksrt_get_user_ban_avatar_badge')
|
||||
? aksrt_get_user_ban_avatar_badge($user_id)
|
||||
: '';
|
||||
if ($ban_badge !== '') {
|
||||
$badge = $ban_badge;
|
||||
} elseif (function_exists('aksrt_get_user_vip_level') && aksrt_get_user_vip_level($user_id) > 0) {
|
||||
$icon_url = '';
|
||||
if (class_exists('\AKSRT\Settings\Settings')) {
|
||||
$vip_settings = \AKSRT\Settings\Settings::get_payment_vip_settings();
|
||||
$level = aksrt_get_user_vip_level($user_id);
|
||||
$icon_url = esc_url((string) ($vip_settings['levels'][$level]['img_icon'] ?? ''));
|
||||
}
|
||||
if ($icon_url !== '') {
|
||||
$badge_text = function_exists('aksrt_get_vip_badge_text') ? aksrt_get_vip_badge_text($user_id) : 'VIP';
|
||||
$badge = '<img class="avatar-badge" src="' . $icon_url . '" title="' . esc_attr($badge_text) . '" alt="' . esc_attr($badge_text) . '">';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -455,14 +455,23 @@ if (!function_exists('aksrt_comments_render_form')) :
|
||||
? aksrt_user_can('comment_add', get_current_user_id(), $post_id)
|
||||
: $is_logged_in;
|
||||
|
||||
if (!$can_comment) {
|
||||
if (!$is_logged_in) {
|
||||
aksrt_comments_render_signarea($ctx);
|
||||
if (!$can_comment) {
|
||||
if (!$is_logged_in) {
|
||||
aksrt_comments_render_signarea($ctx);
|
||||
} else {
|
||||
// 治理状态区分提示(参考主题 zib_get_user_ban_nocan_info 语义:
|
||||
// 禁封中/小黑屋/禁言显示状态徽章与查看入口,而非笼统的无权限文案)。
|
||||
$ban_nocan = function_exists('aksrt_get_user_ban_nocan_html')
|
||||
? aksrt_get_user_ban_nocan_html(get_current_user_id(), __('暂时无法发表评论', 'aksrt'))
|
||||
: '';
|
||||
if ($ban_nocan !== '') {
|
||||
echo $ban_nocan; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- helper escapes internally.
|
||||
} else {
|
||||
echo '<p class="comments-permission-denied muted-2-color">' . esc_html__('当前账号没有发表评论的权限。', 'aksrt') . '</p>';
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (function_exists('aksrt_get_comment_virtual_input_html')) {
|
||||
echo aksrt_get_comment_virtual_input_html($placeholder, '#respond'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
|
||||
@@ -191,8 +191,14 @@ if (!function_exists('aksrt_get_user_name')) {
|
||||
: get_author_posts_url($user_id);
|
||||
$display = $user->display_name;
|
||||
$vip_html = '';
|
||||
if (!empty($args['vip']) && function_exists('aksrt_render_vip_badge')) {
|
||||
$vip_html = (string) aksrt_render_vip_badge($user_id, 'sm');
|
||||
if (!empty($args['vip'])) {
|
||||
// 禁封徽章占据 VIP 图标位(参考主题 user_name_badge 过滤器覆盖语义)。
|
||||
$vip_html = function_exists('aksrt_get_user_ban_name_badge')
|
||||
? aksrt_get_user_ban_name_badge($user_id)
|
||||
: '';
|
||||
if ($vip_html === '' && function_exists('aksrt_render_vip_badge')) {
|
||||
$vip_html = (string) aksrt_render_vip_badge($user_id, 'sm');
|
||||
}
|
||||
}
|
||||
$name_class = trim('display-name text-ellipsis ' . (string) $args['name_class']);
|
||||
$name_link = '<a class="' . esc_attr($name_class) . '" href="' . esc_url($home) . '">' . esc_html($display) . '</a>';
|
||||
|
||||
@@ -142,7 +142,8 @@ if (!function_exists('aksrt_get_single_meta_box')) :
|
||||
$more .= '<a href="' . esc_url($edit_link) . '" class="post-drop-meta__item"><i class="fa fas fa-edit" aria-hidden="true"></i><span>' . esc_html__('编辑文章', 'aksrt') . '</span></a>';
|
||||
}
|
||||
$more .= '<button type="button" class="post-drop-meta__item" data-share-copy data-share-url="' . esc_url((string) $permalink) . '"><i class="fa fas fa-link" aria-hidden="true"></i><span>' . esc_html__('复制链接', 'aksrt') . '</span></button>';
|
||||
if ($ban_item === '' && is_user_logged_in()) {
|
||||
$post_author_id = (int) get_post_field('post_author', $post_id);
|
||||
if ($ban_item === '' && is_user_logged_in() && !(function_exists('aksrt_is_user_ban_restricted') && $post_author_id > 0 && aksrt_is_user_ban_restricted($post_author_id))) {
|
||||
$report_payload = wp_json_encode([
|
||||
'target_type' => 'post',
|
||||
'target_id' => (int) $post_id,
|
||||
|
||||
@@ -26,7 +26,7 @@ defined('ABSPATH') || exit;
|
||||
* @type array $profile_details Server-filtered fixed public profile fields.
|
||||
* @type array $profile_signals Identity chips (verified, level, badges).
|
||||
* @type array $verify_state Verification tri-state {state,label} for the details dialog.
|
||||
* @type array $profile_notice Ban/restriction notice, if any.
|
||||
* @type array $profile_notice Ban/restriction notice {state,label,text}, if any.
|
||||
* @type string $background_url Cover image URL.
|
||||
* @type float $credit_balance Credit balance (own profile only).
|
||||
* @type string $currency_name Currency/credits display name.
|
||||
|
||||
@@ -162,6 +162,10 @@ if (!function_exists('aksrt_get_comment_report_html')) :
|
||||
if ($author_id > 0 && $author_id === $reporter_id) {
|
||||
return '';
|
||||
}
|
||||
// 已封禁/小黑屋用户不再显示举报入口(参考主题 zib_get_report_link 排除语义)。
|
||||
if ($author_id > 0 && function_exists('aksrt_is_user_ban_restricted') && aksrt_is_user_ban_restricted($author_id)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$settings = \AKSRT\Settings\Settings::get_user_identity_settings();
|
||||
if (empty($settings['report']['enabled'])) {
|
||||
|
||||
@@ -13,6 +13,162 @@
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* 用户治理展示态(禁封 / 小黑屋 / 禁言),含请求级缓存。
|
||||
*
|
||||
* 单一数据源为 \AKSRT\User\Restriction::get_display_state() / state_labels();
|
||||
* 本 helper 供用户中心页头、评论拒绝态、昵称徽章等位置复用,避免重复查库。
|
||||
*
|
||||
* 对齐参考主题:
|
||||
* zib_user_is_ban → aksrt_get_user_ban_state(状态判定)
|
||||
* zib_ban_author_header_identity_filter → 资料卡/用户中心身份行徽章
|
||||
*
|
||||
* @return array{state:string,label:string,icon:string}|array{} state 为空串表示无治理状态。
|
||||
*/
|
||||
function aksrt_get_user_ban_state(int $user_id): array
|
||||
{
|
||||
static $cache = [];
|
||||
if ($user_id <= 0) {
|
||||
return [];
|
||||
}
|
||||
if (isset($cache[$user_id])) {
|
||||
return $cache[$user_id];
|
||||
}
|
||||
|
||||
$state = '';
|
||||
if (class_exists('\AKSRT\User\Restriction')) {
|
||||
$state = (string) \AKSRT\User\Restriction::get_instance()->get_display_state($user_id);
|
||||
}
|
||||
if ($state === '') {
|
||||
return $cache[$user_id] = [];
|
||||
}
|
||||
|
||||
$labels = class_exists('\AKSRT\User\Restriction') ? \AKSRT\User\Restriction::state_labels() : [];
|
||||
$icons = [
|
||||
'banned' => 'ban',
|
||||
'restricted' => 'ban',
|
||||
'muted' => 'comment-slash',
|
||||
];
|
||||
return $cache[$user_id] = [
|
||||
'state' => $state,
|
||||
'label' => (string) ($labels[$state] ?? ''),
|
||||
'icon' => (string) ($icons[$state] ?? 'ban'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 目标是否处于封禁/小黑屋状态(举报入口隐藏判定,参考主题
|
||||
* zib_get_report_link 中 zib_user_is_ban($user_id) 的排除语义;
|
||||
* 禁言为轻量评论域限制,不隐藏举报入口)。
|
||||
*/
|
||||
function aksrt_is_user_ban_restricted(int $user_id): bool
|
||||
{
|
||||
$state = aksrt_get_user_ban_state($user_id);
|
||||
return in_array((string) ($state['state'] ?? ''), ['banned', 'restricted'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁封申诉页 URL(自定义页面模板 templates/pages/page-ban-appeal.php,
|
||||
* 即参考主题 zib_get_ban_info_modal / zib_get_user_ban_info_link 的落地视图)。
|
||||
* 站点未创建该页面时返回空串,调用方应降级为纯文本徽章。
|
||||
*/
|
||||
function aksrt_get_ban_appeal_page_url(): string
|
||||
{
|
||||
static $url = null;
|
||||
if (null !== $url) {
|
||||
return $url;
|
||||
}
|
||||
$pages = get_posts([
|
||||
'post_type' => 'page',
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => 1,
|
||||
'fields' => 'ids',
|
||||
'no_found_rows' => true,
|
||||
'meta_query' => [
|
||||
[
|
||||
'key' => '_wp_page_template',
|
||||
'value' => 'templates/pages/page-ban-appeal.php',
|
||||
],
|
||||
],
|
||||
]);
|
||||
return $url = !empty($pages) ? (string) get_permalink((int) $pages[0]) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 治理状态徽章 +「查看详情」入口(用户中心页头,参考主题
|
||||
* user_page_header_desc 钩子 / zib_get_user_ban_info_link 语义)。
|
||||
*/
|
||||
function aksrt_get_user_ban_notice_html(int $user_id): string
|
||||
{
|
||||
$state = aksrt_get_user_ban_state($user_id);
|
||||
if (empty($state['state'])) {
|
||||
return '';
|
||||
}
|
||||
$tone = 'banned' === $state['state'] ? 'c-red' : 'c-yellow';
|
||||
$chip = '<span class="badg badg-sm ' . $tone . '" title="' . esc_attr((string) $state['label']) . '">'
|
||||
. '<i class="fa fas fa-' . esc_attr((string) $state['icon']) . ' mr6" aria-hidden="true"></i>'
|
||||
. esc_html((string) $state['label']) . '</span>';
|
||||
$link = aksrt_get_ban_appeal_page_url();
|
||||
if ($link === '') {
|
||||
return $chip;
|
||||
}
|
||||
return '<a class="aksrt-user-ban-notice" href="' . esc_url($link) . '">' . $chip
|
||||
. '<i class="fa fas fa-angle-right em09 ml6" aria-hidden="true"></i></a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* 昵称旁禁封徽章(参考主题 user_name_badge 钩子语义:占据 VIP 图标位,
|
||||
* 头像角标 user_avatar_badge 为可选项,见 aksrt_get_user_ban_avatar_badge)。
|
||||
*/
|
||||
function aksrt_get_user_ban_name_badge(int $user_id): string
|
||||
{
|
||||
$state = aksrt_get_user_ban_state($user_id);
|
||||
if (empty($state['state'])) {
|
||||
return '';
|
||||
}
|
||||
$tone = 'banned' === $state['state'] ? 'c-red' : 'c-yellow';
|
||||
return '<i class="fa fas fa-' . esc_attr((string) $state['icon']) . ' ' . $tone . ' ml3 aksrt-user-ban-badge"'
|
||||
. ' title="' . esc_attr((string) $state['label']) . '" aria-hidden="true"></i>';
|
||||
}
|
||||
|
||||
/**
|
||||
* 头像禁封角标(参考主题 user_avatar_badge 钩子语义:覆盖 VIP 角标位)。
|
||||
*/
|
||||
function aksrt_get_user_ban_avatar_badge(int $user_id): string
|
||||
{
|
||||
$state = aksrt_get_user_ban_state($user_id);
|
||||
if (empty($state['state'])) {
|
||||
return '';
|
||||
}
|
||||
$tone = 'banned' === $state['state'] ? 'is-banned' : 'is-restricted';
|
||||
return '<span class="avatar-badge aksrt-avatar-ban-badge ' . $tone . '" title="' . esc_attr((string) $state['label']) . '">'
|
||||
. '<i class="fa fas fa-' . esc_attr((string) $state['icon']) . '" aria-hidden="true"></i></span>';
|
||||
}
|
||||
|
||||
/**
|
||||
* 受限位置治理提示(评论拒绝态,参考主题 zib_get_user_ban_nocan_info 语义:
|
||||
* 状态徽章 +「暂时无法操作」+ 查看禁封状态入口)。
|
||||
*
|
||||
* @param string $msg 具体受阻的操作描述,如「发表评论」。
|
||||
*/
|
||||
function aksrt_get_user_ban_nocan_html(int $user_id, string $msg = ''): string
|
||||
{
|
||||
$state = aksrt_get_user_ban_state($user_id);
|
||||
if (empty($state['state'])) {
|
||||
return '';
|
||||
}
|
||||
$text = (string) $state['label'] . ($msg !== '' ? ',' . $msg : '');
|
||||
$tone = 'banned' === $state['state'] ? 'c-red' : 'c-yellow';
|
||||
$link = aksrt_get_ban_appeal_page_url();
|
||||
$inner = '<i class="fa fas fa-' . esc_attr((string) $state['icon']) . ' mr6" aria-hidden="true"></i>'
|
||||
. '<span class="' . $tone . '">' . esc_html($text) . '</span>';
|
||||
if ($link !== '') {
|
||||
$inner .= ' <a class="c-blue" href="' . esc_url($link) . '">' . esc_html__('查看禁封状态', 'aksrt')
|
||||
. '<i class="fa fas fa-angle-right em09 ml3" aria-hidden="true"></i></a>';
|
||||
}
|
||||
return '<p class="comments-permission-denied aksrt-user-ban-nocan">' . $inner . '</p>';
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁封功能开关(后台“用户&互动 → 禁封/举报 → 禁封功能”,
|
||||
* 对齐参考主题 _pz('user_ban_s', true):缺键默认开启)。
|
||||
|
||||
@@ -45,8 +45,15 @@ extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_
|
||||
<?php echo aksrt_render_user_identity_chips((int) $user_id, 'author', ['include_vip' => true, 'skip_badges' => true]); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
<?php endif; ?>
|
||||
</h1>
|
||||
<div class="uc-header__meta desc user-identity flex ac hh">
|
||||
<?php if (function_exists('aksrt_render_user_medal_entry')) : ?>
|
||||
<div class="uc-header__meta desc user-identity flex ac hh">
|
||||
<?php
|
||||
// 治理状态提示(参考主题 user_page_header_desc 钩子 / zib_get_user_ban_info_link:
|
||||
// 徽章 +「查看禁封状态」入口,直达禁封申诉页)。
|
||||
if (function_exists('aksrt_get_user_ban_notice_html')) {
|
||||
echo aksrt_get_user_ban_notice_html((int) $user_id); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- helper escapes internally.
|
||||
}
|
||||
?>
|
||||
<?php if (function_exists('aksrt_render_user_medal_entry')) : ?>
|
||||
<?php echo aksrt_render_user_medal_entry((int) $user_id, 'user-center', true); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
<?php endif; ?>
|
||||
<span class="uc-header__meta-item" title="<?php esc_attr_e('用户名', 'aksrt'); ?>">
|
||||
|
||||
Reference in New Issue
Block a user