count_verify_status('pending'); if ($pending_verify > 0) { $url = admin_url('users.php?page=aksrt_user_auth&status=pending'); echo '

' . esc_html__('用户身份认证申请待处理', 'aksrt') . '

'; echo '

' . esc_html(sprintf( /* translators: %d count */ __('您有 %d 个用户身份认证申请待处理', 'aksrt'), $pending_verify )) . '

'; echo '

' . esc_html__('立即处理', 'aksrt') . '

'; } } if ($page !== 'aksrt_user_ban' && class_exists('\AKSRT\Messages\ReportCenter')) { $pending_reports = (int) \AKSRT\Messages\ReportCenter::get_instance()->get_pending_count(); if ($pending_reports > 0) { $url = admin_url('users.php?page=aksrt_user_ban&tab=reports&status=pending'); echo '

' . esc_html__('举报待处理', 'aksrt') . '

'; echo '

' . esc_html(sprintf( /* translators: %d count */ __('您有 %d 条举报待处理', 'aksrt'), $pending_reports )) . '

'; echo '

' . esc_html__('立即处理', 'aksrt') . '

'; } } if ($page !== 'aksrt_user_ban' && class_exists('\AKSRT\User\BanAppeal')) { $pending_appeals = count(get_users([ 'meta_key' => \AKSRT\User\BanAppeal::META_STATUS, 'meta_value' => 'pending', 'number' => 50, 'fields' => 'ID', ])); if ($pending_appeals > 0) { $url = admin_url('users.php?page=aksrt_user_ban&tab=appeals&status=pending'); echo '

' . esc_html__('禁封申诉待处理', 'aksrt') . '

'; echo '

' . esc_html(sprintf(__('您有 %d 条禁封申诉待处理', 'aksrt'), $pending_appeals)) . '

'; echo '

' . esc_html__('立即处理', 'aksrt') . '

'; } } } private function ensure_cap(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('您没有权限访问此页面。', 'aksrt')); } } private function flash(): void { if (empty($_GET['aksrt_users_msg'])) { return; } $code = sanitize_key((string) wp_unslash($_GET['aksrt_users_msg'])); $map = [ 'message_sent' => __('消息已发送。', 'aksrt'), 'message_failed' => __('消息发送失败。', 'aksrt'), 'verify_updated' => __('认证状态已更新。', 'aksrt'), 'verify_deleted' => __('认证记录已删除。', 'aksrt'), 'verify_failed' => __('认证审核失败。', 'aksrt'), 'report_updated' => __('举报状态已更新。', 'aksrt'), 'report_failed' => __('举报更新失败。', 'aksrt'), 'restriction_added' => __('限制已添加。', 'aksrt'), 'restriction_removed' => __('限制已移除。', 'aksrt'), 'restriction_failed' => __('限制操作失败。', 'aksrt'), 'appeal_approved' => __('申诉已通过,限制已解除。', 'aksrt'), 'appeal_rejected' => __('申诉已驳回。', 'aksrt'), 'appeal_failed' => __('申诉处理失败。', 'aksrt'), 'vip_updated' => __('会员状态已更新。', 'aksrt'), 'vip_partial' => __('部分用户的会员状态已更新。', 'aksrt'), 'vip_failed' => __('会员操作失败。', 'aksrt'), ]; if (!isset($map[$code])) { return; } $class = str_contains($code, 'failed') ? 'notice-error' : 'notice-success'; $message = $map[$code]; if ($code === 'verify_failed' && isset($_GET['aksrt_verify_error'])) { $message = sanitize_text_field((string) wp_unslash($_GET['aksrt_verify_error'])); } if ($code === 'vip_failed' && isset($_GET['aksrt_vip_error'])) { $message = sanitize_text_field((string) wp_unslash($_GET['aksrt_vip_error'])); } if (in_array($code, ['vip_updated', 'vip_partial'], true)) { $message .= ' ' . sprintf( __('成功:%1$d;失败:%2$d;跳过:%3$d。', 'aksrt'), absint($_GET['aksrt_vip_ok'] ?? 0), absint($_GET['aksrt_vip_failed_count'] ?? 0), absint($_GET['aksrt_vip_skipped'] ?? 0) ); } echo '

' . esc_html($message) . '

'; } private function redirect(string $page, string $msg, array $extra = []): void { wp_safe_redirect(add_query_arg(array_merge(['page' => $page, 'aksrt_users_msg' => $msg], $extra), admin_url('users.php'))); exit; } /* ------------------------------------------------------------------ * Messages * ----------------------------------------------------------------*/ public function render_messages_page(): void { $this->ensure_cap(); echo '

' . esc_html__('消息管理', 'aksrt') . '

'; $this->flash(); echo '

' . esc_html__('发送系统消息', 'aksrt') . '

'; echo '
'; echo ''; wp_nonce_field('aksrt_users_send_message'); echo '

'; echo '

'; echo '

'; submit_button(__('发送', 'aksrt')); echo '
'; $page_num = max(1, (int) ($_GET['paged'] ?? 1)); $per_page = 30; $offset = ($page_num - 1) * $per_page; $table = class_exists('\AKSRT\Core\DBMigrator') ? \AKSRT\Core\DBMigrator::table('notification') : ''; if ($table === '') { echo '

' . esc_html__('通知表不可用。', 'aksrt') . '

'; return; } global $wpdb; $total = (int) $wpdb->get_var("SELECT COUNT(*) FROM {$table}"); $items = $wpdb->get_results($wpdb->prepare( "SELECT * FROM {$table} ORDER BY created_at DESC LIMIT %d OFFSET %d", $per_page, $offset ), ARRAY_A); $pages = max(1, (int) ceil(max(1, $total) / $per_page)); echo '

' . esc_html__('最近消息', 'aksrt') . '

'; echo ''; echo ''; echo ''; if (!$items) { echo ''; } foreach ((array) $items as $row) { $user_id = (int) ($row['user_id'] ?? 0); $user = $user_id > 0 ? get_userdata($user_id) : null; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
ID' . esc_html__('用户', 'aksrt') . '' . esc_html__('类型', 'aksrt') . '' . esc_html__('标题', 'aksrt') . '' . esc_html__('已读', 'aksrt') . '' . esc_html__('时间', 'aksrt') . '
' . esc_html__('暂无消息', 'aksrt') . '
' . esc_html((string) ($row['id'] ?? '')) . '' . ($user ? esc_html($user->display_name . ' (#' . $user_id . ')') : esc_html((string) $user_id)) . '' . esc_html((string) ($row['type'] ?? '')) . '' . esc_html((string) ($row['title'] ?? $row['description'] ?? '')) . '' . (!empty($row['is_read']) ? esc_html__('是', 'aksrt') : esc_html__('否', 'aksrt')) . '' . esc_html((string) ($row['created_at'] ?? '')) . '
'; $this->pagination($pages, $page_num); echo ''; } public function handle_send_message(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } check_admin_referer('aksrt_users_send_message'); $user_id = isset($_POST['user_id']) ? (int) $_POST['user_id'] : 0; $title = isset($_POST['title']) ? sanitize_text_field((string) wp_unslash($_POST['title'])) : ''; $content = isset($_POST['content']) ? sanitize_textarea_field((string) wp_unslash($_POST['content'])) : ''; if ($user_id <= 0) { $user_id = get_current_user_id(); } $ok = false; if ($content !== '' && class_exists('\AKSRT\Messages\Message')) { $ok = \AKSRT\Messages\Message::get_instance()->send($user_id, 'system', $content, ['title' => $title !== '' ? $title : $content]); } $this->redirect('aksrt_messages', $ok ? 'message_sent' : 'message_failed'); } /* ------------------------------------------------------------------ * Ban / reports * ----------------------------------------------------------------*/ public function render_ban_page(): void { $this->ensure_cap(); echo '

' . esc_html__('举报&禁封', 'aksrt') . '

'; $this->flash(); $tab = isset($_GET['tab']) ? sanitize_key((string) wp_unslash($_GET['tab'])) : 'reports'; echo ''; if ($tab === 'restrictions') { $this->render_restrictions_tab(); } elseif ($tab === 'appeals') { $this->render_appeals_tab(); } else { $this->render_reports_tab(); } echo '
'; } private function render_reports_tab(): void { if (!class_exists('\AKSRT\Messages\ReportCenter')) { echo '

' . esc_html__('举报中心未初始化。', 'aksrt') . '

'; return; } $status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : 'pending'; $svc = \AKSRT\Messages\ReportCenter::get_instance(); $counts = $svc->get_status_counts(); echo '

' . esc_html(sprintf( /* translators: 1 pending 2 total */ __('待处理 %1$d / 共 %2$d', 'aksrt'), (int) ($counts['pending'] ?? 0), (int) ($counts['total'] ?? 0) )) . '

'; echo '
'; echo ''; echo ' '; submit_button(__('筛选', 'aksrt'), 'secondary', '', false); echo '
'; $items = $svc->get_reports(['status' => $status, 'limit' => 50, 'offset' => 0]); echo ''; echo ''; echo ''; if (!$items) { echo ''; } foreach ($items as $row) { $id = (int) ($row['id'] ?? 0); $st = (string) ($row['status'] ?? ''); $rid = (int) ($row['reporter_id'] ?? 0); $ru = $rid > 0 ? get_userdata($rid) : null; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
ID' . esc_html__('举报人', 'aksrt') . '' . esc_html__('目标', 'aksrt') . '' . esc_html__('原因', 'aksrt') . '' . esc_html__('状态', 'aksrt') . '' . esc_html__('时间', 'aksrt') . '' . esc_html__('操作', 'aksrt') . '
' . esc_html__('暂无举报', 'aksrt') . '
' . esc_html((string) $id) . '' . ($ru ? esc_html($ru->display_name) : esc_html((string) $rid)) . '' . esc_html((string) ($row['target_type'] ?? '') . ' #' . (string) ($row['target_id'] ?? '')) . '' . esc_html((string) ($row['reason'] ?? '')) . '' . esc_html($st) . '' . esc_html((string) ($row['created_at'] ?? '')) . '
'; echo ''; echo ''; wp_nonce_field('aksrt_users_update_report_' . $id); echo ''; echo ''; submit_button(__('更新', 'aksrt'), 'small', '', false); echo '
'; } private function render_restrictions_tab(): void { if (!class_exists('\AKSRT\User\Restriction')) { echo '

' . esc_html__('限制模块未初始化。', 'aksrt') . '

'; return; } $svc = \AKSRT\User\Restriction::get_instance(); $stats = $svc->get_stats(); echo '

' . esc_html(sprintf( /* translators: 1 total 2 active 3 banned */ __('限制记录 %1$d · 生效中 %2$d · 封禁中 %3$d', 'aksrt'), (int) ($stats['total'] ?? 0), (int) ($stats['active'] ?? 0), (int) ($stats['banned'] ?? 0) )) . '

'; echo '

' . esc_html__('添加限制', 'aksrt') . '

'; echo '
'; echo ''; wp_nonce_field('aksrt_users_add_restriction'); echo '

'; echo '

'; echo '

'; echo '

'; submit_button(__('添加', 'aksrt'), 'primary', '', false); echo '
'; global $wpdb; $table = class_exists('\AKSRT\Core\DBMigrator') ? \AKSRT\Core\DBMigrator::table('user_restriction') : ''; if ($table === '') { echo '

' . esc_html__('限制表不可用。', 'aksrt') . '

'; return; } $items = $wpdb->get_results("SELECT * FROM {$table} ORDER BY id DESC LIMIT 100", ARRAY_A); echo ''; echo ''; echo ''; if (!$items) { echo ''; } foreach ((array) $items as $row) { $id = (int) ($row['id'] ?? 0); $user_id = (int) ($row['user_id'] ?? 0); $user = $user_id > 0 ? get_userdata($user_id) : null; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
ID' . esc_html__('用户', 'aksrt') . '' . esc_html__('类型', 'aksrt') . '' . esc_html__('范围', 'aksrt') . '' . esc_html__('原因', 'aksrt') . '' . esc_html__('过期', 'aksrt') . '' . esc_html__('操作', 'aksrt') . '
' . esc_html__('暂无限制记录', 'aksrt') . '
' . esc_html((string) $id) . '' . ($user ? esc_html($user->display_name) : esc_html((string) $user_id)) . '' . esc_html((string) ($row['type'] ?? '')) . '' . esc_html((string) ($row['scope'] ?? '')) . '' . esc_html((string) ($row['reason'] ?? '')) . '' . esc_html((string) ($row['expires_at'] ?? '—')) . '
'; echo ''; echo ''; wp_nonce_field('aksrt_users_remove_restriction_' . $id); submit_button(__('移除', 'aksrt'), 'small', '', false); echo '
'; } public function handle_update_report(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } $id = isset($_POST['report_id']) ? (int) $_POST['report_id'] : 0; $new_status = isset($_POST['new_status']) ? sanitize_key((string) wp_unslash($_POST['new_status'])) : ''; $note = isset($_POST['note']) ? sanitize_textarea_field((string) wp_unslash($_POST['note'])) : ''; check_admin_referer('aksrt_users_update_report_' . $id); $ok = $id > 0 && class_exists('\AKSRT\Messages\ReportCenter') && \AKSRT\Messages\ReportCenter::get_instance()->update_status($id, $new_status, $note); $this->redirect('aksrt_user_ban', $ok ? 'report_updated' : 'report_failed', ['tab' => 'reports']); } public function handle_add_restriction(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } check_admin_referer('aksrt_users_add_restriction'); $user_id = isset($_POST['user_id']) ? (int) $_POST['user_id'] : 0; $type = isset($_POST['type']) ? sanitize_key((string) wp_unslash($_POST['type'])) : 'warn'; $scope = isset($_POST['scope']) ? sanitize_key((string) wp_unslash($_POST['scope'])) : 'global'; $reason = isset($_POST['reason']) ? sanitize_text_field((string) wp_unslash($_POST['reason'])) : ''; $ok = false; if ($user_id > 0 && $reason !== '' && class_exists('\AKSRT\User\Restriction')) { $result = \AKSRT\User\Restriction::get_instance()->restrict($user_id, $type, $reason, $scope, '', get_current_user_id()); $ok = !empty($result['id']) || !empty($result['success']) || is_array($result); } $this->redirect('aksrt_user_ban', $ok ? 'restriction_added' : 'restriction_failed', ['tab' => 'restrictions']); } public function handle_remove_restriction(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } $id = isset($_POST['restriction_id']) ? (int) $_POST['restriction_id'] : 0; check_admin_referer('aksrt_users_remove_restriction_' . $id); $ok = $id > 0 && class_exists('\AKSRT\User\Restriction') && \AKSRT\User\Restriction::get_instance()->remove_restriction($id); $this->redirect('aksrt_user_ban', $ok ? 'restriction_removed' : 'restriction_failed', ['tab' => 'restrictions']); } private function render_appeals_tab(): void { if (!class_exists('\AKSRT\User\BanAppeal')) { echo '

' . esc_html__('申诉模块未初始化。', 'aksrt') . '

'; return; } $status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : 'pending'; if (!in_array($status, ['pending', 'approved', 'rejected', 'all'], true)) { $status = 'pending'; } echo '
'; echo ''; echo ' '; submit_button(__('筛选', 'aksrt'), 'secondary', '', false); echo '
'; $users = get_users([ 'meta_key' => \AKSRT\User\BanAppeal::META_STATUS, 'meta_compare' => 'EXISTS', 'number' => 100, 'fields' => ['ID', 'display_name', 'user_login', 'user_email'], 'orderby' => 'ID', 'order' => 'DESC', ]); echo ''; echo ''; echo ''; $shown = 0; foreach ($users as $u) { $uid = (int) $u->ID; $st = \AKSRT\User\BanAppeal::get_status($uid); if ($st === '') { continue; } if ($status !== 'all' && $st !== $status) { continue; } $payload = \AKSRT\User\BanAppeal::get_payload($uid); $shown++; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } if ($shown < 1) { echo ''; } echo '
UID' . esc_html__('用户', 'aksrt') . '' . esc_html__('状态', 'aksrt') . '' . esc_html__('类型', 'aksrt') . '' . esc_html__('说明', 'aksrt') . '' . esc_html__('提交时间', 'aksrt') . '' . esc_html__('操作', 'aksrt') . '
' . esc_html((string) $uid) . '' . esc_html($u->display_name . ' (' . $u->user_login . ')') . '
' . esc_html($u->user_email) . '
' . esc_html($st) . '' . esc_html((string) ($payload['reason_key'] ?? '—')) . '' . esc_html((string) ($payload['reason'] ?? '')) . '' . esc_html((string) ($payload['time'] ?? '—')) . ''; if ($st === 'pending') { echo '
'; echo ''; echo ''; wp_nonce_field('aksrt_users_process_appeal_' . $uid); echo ''; echo ''; echo ''; echo '
'; } else { echo '—'; } echo '
' . esc_html__('暂无申诉', 'aksrt') . '
'; } public function handle_process_appeal(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } $user_id = isset($_POST['user_id']) ? (int) $_POST['user_id'] : 0; $decision = isset($_POST['decision']) ? sanitize_key((string) wp_unslash($_POST['decision'])) : ''; $note = isset($_POST['note']) ? sanitize_textarea_field((string) wp_unslash($_POST['note'])) : ''; check_admin_referer('aksrt_users_process_appeal_' . $user_id); if ($user_id <= 0 || !in_array($decision, ['approve', 'reject'], true) || !class_exists('\AKSRT\User\BanAppeal')) { $this->redirect('aksrt_user_ban', 'appeal_failed', ['tab' => 'appeals']); } $status = $decision === 'approve' ? 'approved' : 'rejected'; update_user_meta($user_id, \AKSRT\User\BanAppeal::META_STATUS, $status); $payload = \AKSRT\User\BanAppeal::get_payload($user_id); $payload['admin_note'] = $note; $payload['handled_at'] = current_time('Y-m-d H:i'); $payload['handled_by'] = get_current_user_id(); $payload['decision'] = $status; update_user_meta($user_id, \AKSRT\User\BanAppeal::META_PAYLOAD, $payload); $history = get_user_meta($user_id, \AKSRT\User\BanAppeal::META_HISTORY, true); $history = is_array($history) ? $history : []; $history[] = $payload; update_user_meta($user_id, \AKSRT\User\BanAppeal::META_HISTORY, array_slice($history, -30)); if ($decision === 'approve' && class_exists('\AKSRT\User\Restriction')) { global $wpdb; $table = class_exists('\AKSRT\Core\DBMigrator') ? \AKSRT\Core\DBMigrator::table('user_restriction') : ''; if ($table !== '') { $wpdb->query($wpdb->prepare( "UPDATE {$table} SET status = 'lifted', expires_at = %s WHERE user_id = %d AND type IN ('ban','suspend','mute')", current_time('mysql'), $user_id )); } $svc = \AKSRT\User\Restriction::get_instance(); if (method_exists($svc, 'clear_user_bans')) { $svc->clear_user_bans($user_id); } elseif (method_exists($svc, 'lift_ban')) { $svc->lift_ban($user_id); } } if (class_exists('\AKSRT\Messages\Message')) { $msg = $decision === 'approve' ? __('你的禁封申诉已通过,限制已解除。', 'aksrt') : __('你的禁封申诉未通过,可修改后重新提交。', 'aksrt'); if ($note !== '') { $msg .= ' ' . sprintf(__('备注:%s', 'aksrt'), $note); } \AKSRT\Messages\Message::get_instance()->send( $user_id, 'ban_appeal', $msg, [ 'title' => $decision === 'approve' ? __('申诉通过', 'aksrt') : __('申诉驳回', 'aksrt'), ] ); } do_action('aksrt_ban_appeal_processed', $user_id, $decision, $note); $this->redirect( 'aksrt_user_ban', $decision === 'approve' ? 'appeal_approved' : 'appeal_rejected', ['tab' => 'appeals'] ); } private function pagination(int $pages, int $page_num): void { if ($pages <= 1) { return; } echo '
'; echo paginate_links([ 'base' => add_query_arg('paged', '%#%'), 'format' => '', 'prev_text' => '«', 'next_text' => '»', 'total' => $pages, 'current' => $page_num, ]); echo '
'; } }