fix(report): fall back to schema defaults when the ban/report section was never saved

ban_settings()/report_settings() read the raw aksrt_settings option, so on
sites that never saved the ban/report admin section the keys are absent and
the preset reasons resolved to an empty list (frontend hard-coded fallback).
Read the section through SchemaProvider instead — read_section_settings
merges schema defaults, matching the reference theme _pz(key, default)
semantics. Also drop the dead user_report_categories parse chain that fed
a key nobody stores or consumes.
This commit is contained in:
2026-09-20 14:35:17 +08:00
parent 2882b83c21
commit 67547fdf23
2 changed files with 23 additions and 31 deletions
+17 -31
View File
@@ -178,7 +178,6 @@ class UserRuntime {
'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'),
'categories' => self::parse_report_categories((string) ($settings['user_report_categories'] ?? "spam|垃圾信息\nabuse|人身攻击\ncopyright|版权投诉")),
],
];
}
@@ -196,11 +195,26 @@ class UserRuntime {
}
}
/**
* 禁封/举报分区的运行时读取。
*
* get_all() 是裸 option:用户从未保存过“禁封/举报”分区时,
* ban_preset_reason / user_report_img_s / user_report_desc 等键不存在,
* schema 默认值只活在后台 UI 里。参考主题 _pz($key, $default) 的语义是
* 缺键即用默认值,因此这里改走 SchemaProvider 的带默认读取。
*/
private static function read_report_section(): array {
$settings = class_exists('\AKSRT\Admin\SchemaProvider')
? Settings::read_domain('users', 'report')
: [];
return is_array($settings) && $settings ? $settings : Settings::get_all();
}
/**
* 禁封设置
*/
public static function ban_settings(): array {
$settings = Settings::get_all();
$settings = self::read_report_section();
// 预置原因:group 数组 [{t:...}](对齐参考主题)或旧版每行一条文本
$reasons_raw = $settings['ban_preset_reason'] ?? null;
@@ -251,7 +265,7 @@ class UserRuntime {
* 举报设置
*/
public static function report_settings(): array {
$settings = Settings::get_all();
$settings = self::read_report_section();
return [
// 默认开启:对齐后台 schema default true 与参考主题 _pz('user_report_s', true)。
'enabled' => (bool) ($settings['user_report_s'] ?? $settings['user_report_enabled'] ?? true),
@@ -390,32 +404,4 @@ class UserRuntime {
unset($raw);
return [];
}
/**
* @return array<int,array{slug:string,label:string}>
*/
public static function parse_report_categories(string $raw): array {
$lines = preg_split('/[\r\n]+/', $raw, -1, PREG_SPLIT_NO_EMPTY);
$items = [];
foreach ((array) $lines as $line) {
$parts = array_map('trim', explode('|', (string) $line));
if (count($parts) < 2) {
continue;
}
$slug = sanitize_key((string) $parts[0]);
$label = sanitize_text_field((string) $parts[1]);
if ($slug === '' || $label === '') {
continue;
}
$items[] = [
'slug' => $slug,
'label' => $label,
];
}
return $items;
}
}