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:
1 parent
8d9cca2fe5
commit
7f520803ff
17 files changed
+457
-46
No files matched your search
@@ -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):缺键默认开启)。
|
||||
|
||||
Reference in new issue
Block a user