修复了一些问题

This commit is contained in:
kate522 committed 2026-08-25 17:57:20 +08:00
1 parent 8eb0079bc4
commit dbb1f776f2
19 files changed
+785 -634

No files matched your search

+23 -247
View File
@@ -1,275 +1,51 @@
<?php
/**
* Template Name: 消息中心
* Template Post Type: page
*
* 独立消息中心页面 — 两栏布局(左侧导航 + 右侧消息列表)
* 展示未读、评论、资产、交易与系统通知。
* Routed message center shell.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
get_header();
\AKSRT\WidgetSystem\WidgetAreas::render('msg_top_fluid', 'fluid-widget-wrap');
if (!is_user_logged_in()) {
$login_url = function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url(get_permalink());
wp_safe_redirect($login_url);
wp_safe_redirect(function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url(aksrt_get_messages_page_url()));
exit;
}
get_header();
\AKSRT\WidgetSystem\WidgetAreas::render('msg_top_fluid', 'fluid-widget-wrap');
$messages_enabled = !class_exists('\AKSRT\Settings\Settings') || \AKSRT\Settings\Settings::message_enabled();
if (!$messages_enabled) :
?>
<main id="main-content" class="site-main content-shell" tabindex="-1">
<div class="container messages-center messages-center--disabled">
<div class="messages-empty">
<span class="messages-empty__icon"><i class="fa fas fa-bell-slash"></i></span>
<p class="messages-empty__text"><?php esc_html_e('站内消息功能未开启', 'aksrt'); ?></p>
<p class="messages-empty__hint"><?php esc_html_e('请联系管理员在后台「用户 → 消息通知」中启用。', 'aksrt'); ?></p>
</div>
</div>
</main>
<?php
\AKSRT\WidgetSystem\WidgetAreas::render('msg_bottom_fluid', 'fluid-widget-wrap');
get_footer();
return;
endif;
$user_id = get_current_user_id();
$all_notifications = function_exists('aksrt_get_user_all_notifications')
? aksrt_get_user_all_notifications($user_id)
: [];
$current_type = isset($_GET['msg_type']) ? sanitize_key(wp_unslash((string) $_GET['msg_type'])) : 'unread';
// 通知类型分组。
$type_groups = [
'unread' => null, // special: !read
'all' => null, // special: all
'comment' => ['comment_reply', 'comment_approved', 'pending_comments'],
'credits' => ['asset_points_increase', 'asset_points_decrease', 'asset_balance_increase', 'asset_balance_decrease'],
'pay' => ['pay', 'order_paid', 'order_refund', 'shop_order', 'after_sale'],
'vip' => ['vip', 'pay_vip', 'vip_expire', 'vip_upgrade'],
'medal' => ['medal', 'badge', 'level_up'],
'ban_appeal' => ['ban_appeal', 'user_ban', 'restriction'],
'system' => ['notice', 'download_ready', 'upload_moderation', 'verify_email', 'auth_apply', 'auth_apply_reply'],
];
$allowed_types = array_keys($type_groups);
if (!in_array($current_type, $allowed_types, true)) {
$mapped = 'all';
foreach ($type_groups as $group => $types) {
if (is_array($types) && in_array($current_type, $types, true)) {
$mapped = $group;
break;
}
}
$current_type = $mapped;
}
$filtered = $all_notifications;
if ($current_type === 'unread') {
$filtered = array_filter($filtered, static fn($n) => empty($n['read']));
} elseif ($current_type !== 'all') {
$types = $type_groups[$current_type] ?? [];
$filtered = array_filter($filtered, static function ($n) use ($types) {
$t = (string) ($n['type'] ?? 'notice');
return in_array($t, $types, true);
});
}
$filtered = array_values($filtered);
$per_page = 20;
$current_page = max(1, (int) ($_GET['msg_page'] ?? 1));
$total = count($filtered);
$total_pages = max(1, (int) ceil($total / $per_page));
$offset = ($current_page - 1) * $per_page;
$paged_items = array_slice($filtered, $offset, $per_page);
// 统计
$type_counts = [
'all' => count($all_notifications),
'unread' => 0,
'comment' => 0,
'credits' => 0,
'pay' => 0,
'vip' => 0,
'medal' => 0,
'ban_appeal' => 0,
'system' => 0,
];
foreach ($all_notifications as $n) {
$t = (string) ($n['type'] ?? 'notice');
if (empty($n['read'])) {
$type_counts['unread']++;
}
foreach (['comment', 'credits', 'pay', 'vip', 'medal', 'ban_appeal', 'system'] as $group) {
if (!empty($type_groups[$group]) && is_array($type_groups[$group]) && in_array($t, $type_groups[$group], true)) {
$type_counts[$group]++;
}
}
}
$nav_items = [
'unread' => __('未读消息', 'aksrt'),
'all' => __('全部消息', 'aksrt'),
'comment' => __('评论互动', 'aksrt'),
'credits' => __('资产动态', 'aksrt'),
'pay' => __('交易通知', 'aksrt'),
'vip' => __('会员动态', 'aksrt'),
'medal' => __('徽章等级', 'aksrt'),
'ban_appeal' => __('禁封申诉', 'aksrt'),
'system' => __('系统通知', 'aksrt'),
];
$icon_map = [
'comment_reply' => 'fa fas fa-comment-dots',
'comment_approved' => 'fa fas fa-check-circle',
'asset_points_increase' => 'fa fas fa-coins',
'asset_points_decrease' => 'fa fas fa-coins',
'asset_balance_increase' => 'fa fas fa-wallet',
'asset_balance_decrease' => 'fa fas fa-wallet',
'download_ready' => 'fa fas fa-download',
'upload_moderation' => 'fa fas fa-image',
'verify_email' => 'fa fas fa-envelope-open',
'pending_comments' => 'fa fas fa-clock',
'pay' => 'fa fas fa-file-alt',
'order_paid' => 'fa fas fa-file-alt',
'order_refund' => 'fa fas fa-undo',
'after_sale' => 'fa fas fa-undo',
'vip' => 'fa fas fa-certificate',
'pay_vip' => 'fa fas fa-certificate',
'medal' => 'fa fas fa-certificate',
'badge' => 'fa fas fa-certificate',
'ban_appeal' => 'fa fas fa-gavel',
'user_ban' => 'fa fas fa-ban',
'auth_apply' => 'fa fas fa-id-badge',
'auth_apply_reply' => 'fa fas fa-id-badge',
'notice' => 'fa fas fa-bell',
];
$messages_base = function_exists('aksrt_get_messages_page_url') ? aksrt_get_messages_page_url() : get_permalink();
if (!$messages_base) {
$messages_base = get_permalink();
}
$current_view = aksrt_normalize_message_view((string) get_query_var('aksrt_message_view'));
?>
<main id="main-content" class="site-main content-shell" tabindex="-1">
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
<div class="container">
<header class="messages-center__header">
<h1 class="messages-center__title"><?php esc_html_e('消息中心', 'aksrt'); ?></h1>
<p class="messages-center__subtitle"><?php esc_html_e('查看站内通知与互动提醒', 'aksrt'); ?></p>
</header>
<div class="messages-center">
<aside class="messages-center__nav" aria-label="<?php esc_attr_e('消息分类', 'aksrt'); ?>">
<ul class="messages-nav__list">
<?php foreach ($nav_items as $key => $label) :
$count = (int) ($type_counts[$key] ?? 0);
// 始终显示核心 tab;其余无数据时可隐藏(保留 unread/all/system)
if (!in_array($key, ['unread', 'all', 'system'], true) && $count < 1) {
continue;
}
$is_active = $current_type === $key;
$tab_url = add_query_arg(['msg_type' => $key, 'msg_page' => 1], $messages_base);
?>
<li>
<a href="<?php echo esc_url($tab_url); ?>"
class="messages-nav__item<?php echo $is_active ? ' is-active' : ''; ?>"
data-type="<?php echo esc_attr($key); ?>">
<span><?php echo esc_html($label); ?></span>
<?php if ($count > 0) : ?>
<span class="messages-nav__badge" data-type="<?php echo esc_attr($key); ?>" data-count="<?php echo esc_attr((string) $count); ?>"><?php echo esc_html((string) $count); ?></span>
<?php endif; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<div class="messages-nav__actions">
<button type="button" class="messages-nav__action-btn js-msg-mark-all-read"><?php esc_html_e('全部已读', 'aksrt'); ?></button>
<button type="button" class="messages-nav__action-btn js-msg-clear-read"><?php esc_html_e('清除已读', 'aksrt'); ?></button>
<?php if (!$messages_enabled) : ?>
<div class="messages-center messages-center--disabled">
<div class="messages-empty">
<span class="messages-empty__icon"><i class="fa fas fa-bell-slash"></i></span>
<p class="messages-empty__text"><?php esc_html_e('站内消息功能未开启', 'aksrt'); ?></p>
<p class="messages-empty__hint"><?php esc_html_e('请联系管理员在后台「用户 → 消息通知」中启用。', 'aksrt'); ?></p>
</div>
</aside>
<section class="messages-center__content">
<?php if (!empty($paged_items)) : ?>
<div class="messages-list">
<?php foreach ($paged_items as $notice) :
$n_type = (string) ($notice['type'] ?? 'notice');
$n_title = (string) ($notice['title'] ?? '');
$n_desc = (string) ($notice['desc'] ?? '');
$n_url = (string) ($notice['url'] ?? '');
$n_id = (string) ($notice['id'] ?? '');
$is_read = !empty($notice['read']);
$is_state = !empty($notice['stateful']);
$created = (string) ($notice['created_at'] ?? '');
$time_str = $is_state
? __('状态提醒', 'aksrt')
: ($created !== '' ? get_date_from_gmt($created, 'Y-m-d H:i') : '');
$icon_cls = $icon_map[$n_type] ?? 'fa fas fa-bell';
?>
<article class="message-item<?php echo !$is_read ? ' is-unread' : ''; ?>" data-notification-id="<?php echo esc_attr($n_id); ?>">
<span class="message-item__icon">
<i class="<?php echo esc_attr($icon_cls); ?>" aria-hidden="true"></i>
</span>
<div class="message-item__body">
<div class="message-item__title">
<?php echo esc_html($n_title); ?>
<?php if (!$is_read && !$is_state) : ?>
<span class="message-item__new-badge"><?php esc_html_e('新', 'aksrt'); ?></span>
<?php endif; ?>
</div>
<?php if ($n_desc !== '') : ?>
<div class="message-item__desc"><?php echo esc_html($n_desc); ?></div>
<?php endif; ?>
<?php if ($time_str !== '') : ?>
<div class="message-item__time"><?php echo esc_html($time_str); ?></div>
<?php endif; ?>
</div>
<div class="message-item__actions">
<?php if ($n_url !== '') : ?>
<a href="<?php echo esc_url($n_url); ?>" class="message-item__action-btn"><?php esc_html_e('查看', 'aksrt'); ?></a>
<?php endif; ?>
<?php if (!$is_state && !$is_read) : ?>
<button type="button" class="message-item__action-btn js-msg-mark-read" data-id="<?php echo esc_attr($n_id); ?>"><?php esc_html_e('已读', 'aksrt'); ?></button>
<?php endif; ?>
<?php if (!$is_state) : ?>
<button type="button" class="message-item__action-btn message-item__action-btn--danger js-msg-delete" data-id="<?php echo esc_attr($n_id); ?>"><?php esc_html_e('删除', 'aksrt'); ?></button>
<?php endif; ?>
</div>
</article>
<?php endforeach; ?>
</div>
<?php if ($total_pages > 1) : ?>
<nav class="messages-pagination" aria-label="<?php esc_attr_e('消息分页', 'aksrt'); ?>">
<?php for ($i = 1; $i <= $total_pages; $i++) :
$page_url = add_query_arg(['msg_type' => $current_type, 'msg_page' => $i], $messages_base);
?>
<?php if ($i === $current_page) : ?>
<span class="profile-status-chip is-active"><?php echo esc_html((string) $i); ?></span>
<?php else : ?>
<a href="<?php echo esc_url($page_url); ?>" class="profile-status-chip"><?php echo esc_html((string) $i); ?></a>
<?php endif; ?>
<?php endfor; ?>
</nav>
<?php endif; ?>
<?php else : ?>
<div class="messages-empty">
<span class="messages-empty__icon"><i class="fa fas fa-bell-slash"></i></span>
<p class="messages-empty__text"><?php esc_html_e('暂无消息', 'aksrt'); ?></p>
</div>
<?php endif; ?>
</section>
</div>
</div>
<?php else : ?>
<div class="messages-center" data-message-center data-view="<?php echo esc_attr($current_view); ?>">
<aside class="messages-center__nav" aria-label="<?php esc_attr_e('消息分类', 'aksrt'); ?>" data-message-nav>
<?php aksrt_render_message_center_nav($current_view, aksrt_get_message_center_counts($user_id)); ?>
</aside>
<section class="messages-center__content" data-message-content aria-live="polite" tabindex="-1">
<?php aksrt_render_message_center_list($user_id, $current_view); ?>
</section>
</div>
<?php endif; ?>
</div>
</main>