删除私信分支链路

This commit is contained in:
kate522 committed 2026-08-23 13:42:35 +08:00
1 parent 1c5c6d86bb
commit c6c2c0af6d
39 files changed
+32 -1465

No files matched your search

+7 -81
View File
@@ -4,7 +4,7 @@
* Template Post Type: page
*
* 独立消息中心页面 — 两栏布局(左侧导航 + 右侧消息列表)
* 对齐 legacy msg-center:未读 / 评论 / 系统 / 私信(可开关)
* 对齐 legacy msg-center:未读 / 评论 / 系统
*
* @package AKSRT
*/
@@ -21,8 +21,6 @@ if (!is_user_logged_in()) {
}
$messages_enabled = !class_exists('\AKSRT\Settings\Settings') || \AKSRT\Settings\Settings::message_enabled();
$pm_settings = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::private_message_settings() : ['enabled' => false];
$pm_enabled = !empty($pm_settings['enabled']);
if (!$messages_enabled) :
?>
@@ -60,13 +58,8 @@ $type_groups = [
'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'],
'conversation' => ['conversation'],
];
if ($current_type === 'conversation' && !$pm_enabled) {
$current_type = 'unread';
}
$allowed_types = array_keys($type_groups);
if (!in_array($current_type, $allowed_types, true)) {
// 兼容旧 URL:msg_type=comment_reply 等
@@ -83,7 +76,7 @@ if (!in_array($current_type, $allowed_types, true)) {
$filtered = $all_notifications;
if ($current_type === 'unread') {
$filtered = array_filter($filtered, static fn($n) => empty($n['read']));
} elseif ($current_type !== 'all' && $current_type !== 'conversation') {
} elseif ($current_type !== 'all') {
$types = $type_groups[$current_type] ?? [];
$filtered = array_filter($filtered, static function ($n) use ($types) {
$t = (string) ($n['type'] ?? 'notice');
@@ -110,31 +103,19 @@ $paged_items = array_slice($filtered, $offset, $per_page);
'medal' => 0,
'ban_appeal' => 0,
'system' => 0,
'conversation' => 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', 'conversation'] as $group) {
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]++;
}
}
}
if ($pm_enabled && class_exists('\AKSRT\Messages\PrivateMessage')) {
// conversation count prefers live PM conversations when available
$pm_tmp = \AKSRT\Messages\PrivateMessage::get_instance();
if (method_exists($pm_tmp, 'get_conversations')) {
$convs = $pm_tmp->get_conversations($user_id, 100);
if (is_array($convs)) {
$type_counts['conversation'] = count($convs);
}
}
}
$nav_items = [
'unread' => __('未读消息', 'aksrt'),
'all' => __('全部消息', 'aksrt'),
@@ -146,9 +127,6 @@ $nav_items = [
'ban_appeal' => __('禁封申诉', 'aksrt'),
'system' => __('系统通知', 'aksrt'),
];
if ($pm_enabled) {
$nav_items['conversation'] = __('私信消息', 'aksrt');
}
$icon_map = [
'comment_reply' => 'fa fas fa-comment-dots',
@@ -158,9 +136,8 @@ $nav_items = [
'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',
'conversation' => 'fa fas fa-envelope',
'pay' => 'fa fas fa-file-alt',
'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',
@@ -196,7 +173,7 @@ if (!$messages_base) {
<?php foreach ($nav_items as $key => $label) :
$count = (int) ($type_counts[$key] ?? 0);
// 始终显示核心 tab;其余无数据时可隐藏(保留 unread/all/system)
if (!in_array($key, ['unread', 'all', 'system', 'conversation'], true) && $count < 1) {
if (!in_array($key, ['unread', 'all', 'system'], true) && $count < 1) {
continue;
}
$is_active = $current_type === $key;
@@ -221,58 +198,7 @@ if (!$messages_base) {
</aside>
<section class="messages-center__content">
<?php if ($current_type === 'conversation' && $pm_enabled) :
$pm = class_exists('\AKSRT\Messages\PrivateMessage') ? \AKSRT\Messages\PrivateMessage::get_instance() : null;
$conversations = $pm ? $pm->get_conversations($user_id, 30) : [];
$pm_nonce = wp_create_nonce('aksrt_pm');
$pm_placeholder = (string) ($pm_settings['placeholder'] ?? __('请输入消息...', 'aksrt'));
$pm_submit = (string) ($pm_settings['submit_text'] ?? __('发送', 'aksrt'));
?>
<div class="messages-conversations" id="aksrt-pm-conversations"
data-ajax="<?php echo esc_url(admin_url('admin-ajax.php')); ?>"
data-nonce="<?php echo esc_attr($pm_nonce); ?>">
<?php if (!empty($conversations)) : ?>
<div class="aksrt-pm__list">
<?php foreach ($conversations as $conv) : ?>
<div class="aksrt-pm__item<?php echo !empty($conv['unread']) ? ' is-unread' : ''; ?>"
data-conv-id="<?php echo esc_attr((string) ($conv['id'] ?? '')); ?>"
data-other-id="<?php echo esc_attr((string) ($conv['other_user_id'] ?? '')); ?>">
<img<?php echo aksrt_get_lazy_attr('lazy_private', (string) ($conv['other_avatar'] ?? ''), 'aksrt-pm__avatar', aksrt_get_lazy_thumb('sm')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="">
<div class="aksrt-pm__info">
<div class="aksrt-pm__name">
<?php echo esc_html((string) ($conv['other_name'] ?? '')); ?>
<?php if (!empty($conv['unread'])) : ?>
<span class="aksrt-pm__badge"><?php echo esc_html((string) $conv['unread']); ?></span>
<?php endif; ?>
</div>
<div class="aksrt-pm__preview"><?php echo esc_html(mb_substr((string) ($conv['last_message'] ?? ''), 0, 50)); ?></div>
</div>
<div class="aksrt-pm__time"><?php echo esc_html(!empty($conv['last_message_at']) ? mysql2date('m-d H:i', (string) $conv['last_message_at']) : ''); ?></div>
</div>
<?php endforeach; ?>
</div>
<?php else : ?>
<div class="messages-empty">
<span class="messages-empty__icon"><i class="fa fas fa-envelope"></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>
<?php endif; ?>
</div>
<div class="aksrt-pm__thread" id="aksrt-pm-thread" hidden>
<div class="aksrt-pm__thread-header">
<button type="button" class="aksrt-pm__back-btn" id="aksrt-pm-back"><i class="fa fas fa-arrow-left"></i> <?php esc_html_e('返回', 'aksrt'); ?></button>
<span class="aksrt-pm__thread-name" id="aksrt-pm-thread-name"></span>
</div>
<div class="aksrt-pm__messages" id="aksrt-pm-messages"></div>
<div class="aksrt-pm__compose">
<textarea id="aksrt-pm-input" rows="2" placeholder="<?php echo esc_attr($pm_placeholder); ?>"></textarea>
<button type="button" id="aksrt-pm-send" class="aksrt-pm__send-btn" aria-label="<?php echo esc_attr($pm_submit); ?>"><i class="fa fas fa-paper-plane"></i></button>
</div>
</div>
<?php elseif (!empty($paged_items)) : ?>
<?php if (!empty($paged_items)) : ?>
<div class="messages-list">
<?php foreach ($paged_items as $notice) :
$n_type = (string) ($notice['type'] ?? 'notice');
+5 -12
View File
@@ -43,8 +43,6 @@ $abs_fmt = $use_modified
$time_text = human_time_diff($rel_base, $now) . $rel_label;
$classes = trim('article-avatar ' . $extra_class);
$aksrt_pm_on = class_exists('\AKSRT\Settings\Settings') && !empty(\AKSRT\Settings\Settings::private_message_settings()['enabled']);
$aksrt_msg_url = function_exists('aksrt_get_messages_page_url') ? aksrt_get_messages_page_url() : '';
$login_url = function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url(get_permalink());
$is_self = is_user_logged_in() && get_current_user_id() === $author_id;
@@ -115,16 +113,11 @@ $is_self = is_user_logged_in() && get_current_user_id() === $author_id;
<div class="flex0 user-action">
<?php if (!$is_self) : ?>
<?php if (is_user_logged_in()) : ?>
<button type="button" class="px12-sm ml10 follow but c-red" data-aksrt-follow="<?php echo (int) $author_id; ?>">
<i class="fa fas fa-heart em09" aria-hidden="true"></i> <span><?php esc_html_e('关注', 'aksrt'); ?></span>
</button>
<?php if ($aksrt_pm_on && $aksrt_msg_url !== '') : ?>
<a href="<?php echo esc_url(add_query_arg('msg_type', 'conversation', $aksrt_msg_url)); ?>" class="ml6 but c-blue px12-sm">
<i class="fa fas fa-comment em09" aria-hidden="true"></i> <?php esc_html_e('私信', 'aksrt'); ?>
</a>
<?php endif; ?>
<?php
$reward_button = function_exists('aksrt_get_rewards_button')
<button type="button" class="px12-sm ml10 follow but c-red" data-aksrt-follow="<?php echo (int) $author_id; ?>">
<i class="fa fas fa-heart em09" aria-hidden="true"></i> <span><?php esc_html_e('关注', 'aksrt'); ?></span>
</button>
<?php
$reward_button = function_exists('aksrt_get_rewards_button')
? aksrt_get_rewards_button($author_id, 'ml6 but c-yellow px12-sm', get_the_ID())
: '';
if ($reward_button !== '') {
+3 -23
View File
@@ -55,14 +55,8 @@ if ($follower_count <= 0 && class_exists('\AKSRT\User\Follow')) {
$follower_count = (int) \AKSRT\User\Follow::get_instance()->get_follower_count($user_id);
}
$pm_enabled = class_exists('\AKSRT\Settings\Settings') && !empty(\AKSRT\Settings\Settings::private_message_settings()['enabled']);
$messages_url = function_exists('aksrt_get_messages_page_url') ? aksrt_get_messages_page_url() : '';
$pm_url = ($pm_enabled && $messages_url !== '')
? add_query_arg('msg_type', 'conversation', $messages_url)
: '';
?>
<div class="aksrt-author-hero<?php echo $show_cover ? '' : ' aksrt-author-hero--no-cover'; ?>">
?><div class="aksrt-author-hero<?php echo $show_cover ? '' : ' aksrt-author-hero--no-cover'; ?>">
<?php if ($show_cover) : ?>
<div class="aksrt-author-hero__cover">
<img<?php echo aksrt_get_lazy_attr('lazy_cover', (string) ($bg_url ? $bg_url : get_theme_file_uri('assets/img/person_background.png')), 'aksrt-author-hero__cover-img', aksrt_get_lazy_thumb('lg')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="">
@@ -165,25 +159,11 @@ $pm_url = ($pm_enabled && $messages_url !== '')
<i class="fa fas fa-heart" aria-hidden="true"></i>
<span><?php esc_html_e('登录后关注', 'aksrt'); ?></span>
</a>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
<?php if ($show_message && $pm_url !== '') : ?>
<?php if (is_user_logged_in()) : ?>
<a href="<?php echo esc_url($pm_url); ?>" class="btn-primary btn-sm">
<i class="fa fas fa-comment" aria-hidden="true"></i>
<span><?php esc_html_e('私信', 'aksrt'); ?></span>
</a>
<?php else : ?>
<a href="<?php echo esc_url(aksrt_get_login_url($home_url)); ?>" class="btn-primary btn-sm">
<i class="fa fas fa-comment" aria-hidden="true"></i>
<span><?php esc_html_e('私信', 'aksrt'); ?></span>
</a>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
<?php if ($is_author && function_exists('aksrt_render_admin_quick_link')) { aksrt_render_admin_quick_link('page-display/user-home', __('用户主页设置', 'aksrt')); } ?>
<?php if ($is_author && function_exists('aksrt_render_admin_quick_link')) { aksrt_render_admin_quick_link('page-display/user-home', __('用户主页设置', 'aksrt')); } ?>
</div>
</div>
</div>