fix(report): unify the frontend report entry and modal

- enqueue report.js on singular pages too: the single meta box and
  comment report buttons rendered without their script handler, so
  clicking the report item did nothing
- align the report runtime default with the admin schema and the
  reference theme (user_report_s default true) so the public user
  home cover menu shows the report entry
- rebuild report.js on top of AksrtModalRuntime following the
  reference theme modal format: red warning header, preset reason
  badges with an other-reason textarea, violation link field, detail
  description and a cancel/submit footer; submit goes through the
  unified /report/submit endpoint
- keep report inside the comment three-dot dropdown and enrich the
  payload (target name/avatar) for the modal; inject configured
  report categories via aksrtData.reportCategories
- update the report contract test accordingly
This commit is contained in:
2026-09-20 13:40:05 +08:00
parent 381256ed59
commit 7c730b83d6
9 changed files with 249 additions and 112 deletions
+6 -3
View File
@@ -277,9 +277,9 @@ trait ScriptsPart1b {
// 评论区样式由上方 is_singular 统一入口按 needs_comments 加载。
}
// 用户中心 / 公开主页:路由专属 CSS
if ($is_profile_page) {
// 举报脚本(用户主页和个人中心均需要)
// 举报脚本:举报入口渲染于文章页 meta 菜单、评论区与用户主页/个人中心,
// 因此 singular 页面与 profile 路由都需要加载(文章页举报按钮此前无脚本支撑)。
if (is_singular() || $is_profile_page) {
$report_js_path = get_template_directory() . '/assets/js/report.js';
if (file_exists($report_js_path)) {
wp_enqueue_script(
@@ -290,7 +290,10 @@ trait ScriptsPart1b {
true
);
}
}
// 用户中心 / 公开主页:路由专属 CSS
if ($is_profile_page) {
// 关注脚本已在全局栈注册(ScriptsPart1c),data-aksrt-follow 按钮
// 也渲染于文章页作者栏与各处用户卡片,不能仅限本路由加载。
+8
View File
@@ -487,6 +487,14 @@ trait ScriptsPart1c {
'restUrl' => esc_url_raw(rest_url('aksrt/v1')),
// Alias used by modal-auth / follow / report (same value as restUrl).
'apiUrl' => esc_url_raw(rest_url('aksrt/v1')),
// 举报弹窗预置原因(report.js 徽章选择数据源)。
'reportCategories' => (function () {
if (!class_exists('\AKSRT\Settings\Settings')) {
return [];
}
$report = \AKSRT\Settings\Settings::get_user_identity_settings()['report'] ?? [];
return is_array($report['categories'] ?? null) ? array_values($report['categories']) : [];
})(),
'stickyEnabled' => class_exists('\AKSRT\Settings\Settings') ? !empty(\AKSRT\Settings\Settings::get_post_list_style_settings()['sticky_s']) : true,
'stickyPages' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_post_list_style_settings()['sticky_s'] : ['home', 'cat'],
'badgeShow' => class_exists('\AKSRT\Settings\Settings') ? !empty(\AKSRT\Settings\Settings::get_post_list_style_settings()['list_badge_show']) : true,
+4 -2
View File
@@ -173,7 +173,8 @@ class UserRuntime {
}, $medal['items_by_slug'])),
],
'report' => [
'enabled' => (bool) ($settings['user_report_s'] ?? $settings['user_report_enabled'] ?? false),
// 默认开启:对齐后台 schema default true 与参考主题 _pz('user_report_s', true)。
'enabled' => (bool) ($settings['user_report_s'] ?? $settings['user_report_enabled'] ?? true),
'public_entry' => !isset($settings['user_report_public_entry']) || !empty($settings['user_report_public_entry']),
'public_notice' => !isset($settings['user_report_public_notice']) || !empty($settings['user_report_public_notice']),
'ban_notice_text' => $ban_notice_text !== '' ? $ban_notice_text : __('当前账号处于限制状态,部分互动能力已关闭。', 'aksrt'),
@@ -252,7 +253,8 @@ class UserRuntime {
public static function report_settings(): array {
$settings = Settings::get_all();
return [
'enabled' => (bool) ($settings['user_report_s'] ?? $settings['user_report_enabled'] ?? false),
// 默认开启:对齐后台 schema default true 与参考主题 _pz('user_report_s', true)。
'enabled' => (bool) ($settings['user_report_s'] ?? $settings['user_report_enabled'] ?? true),
'public_entry' => !isset($settings['user_report_public_entry']) || !empty($settings['user_report_public_entry']),
'public_notice' => !isset($settings['user_report_public_notice']) || !empty($settings['user_report_public_notice']),
'ban_notice_text' => sanitize_text_field((string) ($settings['user_report_ban_notice_text'] ?? '')),