$normalized_tabs, 'tabs_order' => $ordered, 'tabs_pc_hide' => $pc_hide, 'tabs_mobile_hide' => $mobile_hide, // Public author page is full-width (Zibll author.php). Sidebar option kept as no-op reserved key. 'sidebar' => false, 'cover' => !isset($settings['user_home_cover']) || !empty($settings['user_home_cover']), 'follow' => !isset($settings['user_home_follow']) || !empty($settings['user_home_follow']), 'posts_per_page' => max(5, min(50, (int) ($settings['user_home_posts_per_page'] ?? 10))), 'avatar' => !isset($settings['user_home_avatar']) || !empty($settings['user_home_avatar']), 'name' => !isset($settings['user_home_name']) || !empty($settings['user_home_name']), 'desc' => !isset($settings['user_home_desc']) || !empty($settings['user_home_desc']), // Body stats row removed; counts live in tabs like Zibll. 'stats' => false, 'social' => !isset($settings['user_home_social']) || !empty($settings['user_home_social']), 'tab_swiper' => !empty($settings['author_main_tab_swiper']), 'message' => !isset($settings['user_home_message']) || !empty($settings['user_home_message']), 'private' => !isset($settings['user_home_private']) || !empty($settings['user_home_private']), 'paging_ajax' => !isset($settings['user_home_paging_ajax']) || !empty($settings['user_home_paging_ajax']), ]; } /** * Private user-center display settings. * * @return array{tabs:string[],avatar_upload:bool,cover_upload:bool,social_links:bool} */ public static function get_user_center_settings(): array { $settings = Settings::get_all(); $raw_tabs = $settings['user_center_tabs'] ?? 'profile,level,posts,comments,credits,promotion,favorites,auth'; $tabs = is_array($raw_tabs) ? $raw_tabs : preg_split('/[\s,]+/', (string) $raw_tabs, -1, PREG_SPLIT_NO_EMPTY); // Built-in switchable panels. VIP is always auto-injected when enabled // by AKSRT\User\Center — keep it allowed for explicit config too. $allowed_tabs = ['profile', 'level', 'posts', 'comments', 'favorites', 'credits', 'promotion', 'vip', 'orders', 'auth', 'settings']; $normalized_tabs = ['profile']; foreach ((array) $tabs as $tab) { $tab = sanitize_key((string) $tab); if ($tab === 'profile') { continue; } if (in_array($tab, $allowed_tabs, true) && !in_array($tab, $normalized_tabs, true)) { $normalized_tabs[] = $tab; } } if (!in_array('posts', $normalized_tabs, true) && !in_array('comments', $normalized_tabs, true)) { $normalized_tabs[] = 'posts'; } // Ensure VIP appears in configured tabs when membership is on, even if // the stored option string is older and omits it. $vip_on = !empty(Settings::get_payment_vip_settings()['enabled']); if ($vip_on && !in_array('vip', $normalized_tabs, true)) { // Prefer after credits, else after favorites, else append before settings. $insert_at = count($normalized_tabs); foreach (['credits', 'favorites', 'posts'] as $anchor) { $idx = array_search($anchor, $normalized_tabs, true); if ($idx !== false) { $insert_at = (int) $idx + 1; break; } } array_splice($normalized_tabs, $insert_at, 0, ['vip']); } if (!$vip_on) { $normalized_tabs = array_values(array_filter( $normalized_tabs, static fn(string $t): bool => $t !== 'vip' )); } return [ 'tabs' => $normalized_tabs, 'avatar_upload' => !isset($settings['allow_avatar_upload']) || !empty($settings['allow_avatar_upload']), 'cover_upload' => !isset($settings['user_cover_upload']) || !empty($settings['user_cover_upload']), 'social_links' => !isset($settings['user_social_links']) || !empty($settings['user_social_links']), ]; } /** * User identity, level, medal, and report governance settings. * * @return array{ * verify:array{enabled:bool,public_display:bool,allow_apply:bool,disable_desc:string,desc:string,types:array}, * level:array{enabled:bool,public_display:bool,source:string,label_prefix:string,thresholds:array}, * medal:array{enabled:bool,public_display:bool,limit:int,categories:array}>,items_by_slug:array}, * badge:array{enabled:bool,public_display:bool,limit:int,dictionary:array}, * report:array{enabled:bool,public_entry:bool,public_notice:bool,ban_notice_text:string,categories:array} * } */ public static function get_user_identity_settings(): array { $settings = Settings::get_all(); $ban_notice_text = trim((string) ($settings['user_report_ban_notice_text'] ?? '')); $verify_types = [ 'personal' => [ 'slug' => 'personal', 'label' => __('个人认证', 'aksrt'), 'badge_text' => trim((string) ($settings['user_verify_personal_badge_text'] ?? '')) ?: __('个人认证', 'aksrt'), 'fee' => max(0, round((float) ($settings['user_verify_personal_fee'] ?? 0), 2)), 'free_applications' => max(0, (int) ($settings['user_verify_personal_free_applications'] ?? 0)), 'require_real_name' => true, ], 'enterprise' => [ 'slug' => 'enterprise', 'label' => __('企业认证', 'aksrt'), 'badge_text' => trim((string) ($settings['user_verify_enterprise_badge_text'] ?? '')) ?: __('企业认证', 'aksrt'), 'fee' => max(0, round((float) ($settings['user_verify_enterprise_fee'] ?? 0), 2)), 'free_applications' => max(0, (int) ($settings['user_verify_enterprise_free_applications'] ?? 0)), 'require_real_name' => true, ], ]; $medal = self::parse_medal_catalog($settings); $provider = sanitize_key((string) ($settings['user_verify_provider'] ?? 'aliyun')); if (!in_array($provider, ['aliyun', 'tencent'], true)) { $provider = 'aliyun'; } return [ 'verify' => [ 'enabled' => !isset($settings['user_verify_enabled']) || !empty($settings['user_verify_enabled']), 'public_display' => !isset($settings['user_verify_public_display']) || !empty($settings['user_verify_public_display']), 'allow_apply' => !isset($settings['user_verify_allow_apply']) || !empty($settings['user_verify_allow_apply']), 'disable_desc' => (string) ($settings['user_verify_disable_desc'] ?? ''), 'desc' => (string) ($settings['user_verify_desc'] ?? ''), 'provider' => $provider, 'allow_manual_fallback' => !isset($settings['user_verify_allow_manual_fallback']) || !empty($settings['user_verify_allow_manual_fallback']), 'poll_interval_seconds' => max(3, min(60, (int) ($settings['user_verify_poll_interval_seconds'] ?? 5))), 'types' => $verify_types, ], 'level' => [ 'enabled' => !isset($settings['user_level_s']) || !empty($settings['user_level_s']), 'public_display' => !isset($settings['user_level_public_display']) || !empty($settings['user_level_public_display']), 'max' => max(3, min(30, (int) ($settings['user_level_max'] ?? 10))), ], 'medal' => $medal, // Alias for existing call sites that still read badge.*; dictionary is derived from medal catalog. 'badge' => [ 'enabled' => $medal['enabled'], 'public_display' => $medal['public_display'], 'limit' => $medal['limit'], 'dictionary' => array_values(array_map(static function (array $item): array { return [ 'slug' => $item['slug'], 'label' => $item['name'], 'tone' => 'info', 'icon_url' => $item['icon'], ]; }, $medal['items_by_slug'])), ], 'report' => [ 'enabled' => !empty($settings['user_report_enabled']), '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|版权投诉")), ], ]; } /** * 禁封设置 */ public static function ban_settings(): array { $settings = Settings::get_all(); $reasons_raw = (string) ($settings['ban_preset_reason'] ?? "spam|垃圾信息\nabuse|人身攻击\nviolation|违规操作"); $reasons = []; foreach (preg_split('/\r\n|\r|\n/', $reasons_raw) as $line) { $line = trim($line); if ($line === '') { continue; } $parts = explode('|', $line, 2); $reasons[] = [ 'slug' => sanitize_key($parts[0]), 'name' => sanitize_text_field($parts[1] ?? $parts[0]), ]; } $appeal_keys_raw = (string) ($settings['ban_appeal_keys'] ?? ''); $appeal_keys = array_filter(array_map('trim', explode(',', $appeal_keys_raw))); return [ 'reasons' => $reasons, 'appeal_desc' => wp_kses_post((string) ($settings['ban_appeal_desc'] ?? '')), 'appeal_keys' => array_values($appeal_keys), ]; } /** * 举报设置 */ public static function report_settings(): array { $settings = Settings::get_all(); return [ 'enabled' => !empty($settings['user_report_enabled']), 'public_entry' => !empty($settings['user_report_public_entry']), 'public_notice' => !empty($settings['user_report_public_notice']), 'ban_notice_text' => sanitize_text_field((string) ($settings['user_report_ban_notice_text'] ?? '')), 'img_enabled' => !empty($settings['user_report_img_s']), 'desc' => wp_kses_post((string) ($settings['user_report_desc'] ?? '')), ]; } /** * Parse structured user_medal_args catalog (rewrite; no badge dictionary dual-read). * * @param array $settings * @return array{enabled:bool,public_display:bool,limit:int,categories:array,items_by_slug:array} */ public static function parse_medal_catalog(array $settings): array { $enabled = !empty($settings['user_medal_s']); $public = !isset($settings['user_medal_public_display']) || !empty($settings['user_medal_public_display']); $limit = max(1, min(8, (int) ($settings['user_medal_limit'] ?? 3))); $allowed_types = [ 'registration_time', 'checkin_all_day', 'new_post', 'comment', 'followed', 'like', 'comment_like', 'views', 'pay_income', 'pay_rebate', 'manually_add', ]; $raw = $settings['user_medal_args'] ?? null; if (is_string($raw) && $raw !== '') { $decoded = json_decode($raw, true); $raw = is_array($decoded) ? $decoded : []; } if (!is_array($raw)) { $raw = []; } $categories = []; $items_by_slug = []; foreach ($raw as $cat) { if (!is_array($cat)) { continue; } $cat_name = sanitize_text_field((string) ($cat['cat_name'] ?? $cat['name'] ?? '')); if ($cat_name === '') { $cat_name = __('未命名', 'aksrt'); } $items_out = []; $items = is_array($cat['items'] ?? null) ? $cat['items'] : []; foreach ($items as $item) { if (!is_array($item)) { continue; } $slug = sanitize_key((string) ($item['slug'] ?? '')); $name = sanitize_text_field((string) ($item['name'] ?? '')); if ($slug === '' || $name === '') { continue; } $get_type = sanitize_key((string) ($item['get_type'] ?? 'manually_add')); if (!in_array($get_type, $allowed_types, true)) { $get_type = 'manually_add'; } $icon = esc_url_raw((string) ($item['icon'] ?? $item['icon_url'] ?? '')); $row = [ 'slug' => $slug, 'name' => $name, 'desc' => sanitize_text_field((string) ($item['desc'] ?? '')), 'icon' => $icon, 'get_type' => $get_type, 'get_val' => max(0, (int) ($item['get_val'] ?? 0)), 'cat_name' => $cat_name, ]; $items_out[] = $row; $items_by_slug[$slug] = $row; } $categories[] = [ 'cat_name' => $cat_name, 'items' => $items_out, ]; } return [ 'enabled' => $enabled, 'public_display' => $public, 'limit' => $limit, 'categories' => $categories, 'items_by_slug' => $items_by_slug, ]; } /** * @return array */ public static function parse_level_thresholds(string $raw): array { $lines = preg_split('/[\r\n]+/', $raw, -1, PREG_SPLIT_NO_EMPTY); $thresholds = []; foreach ((array) $lines as $line) { $parts = preg_split('/[|:,]/', trim($line), 2); if (!is_array($parts) || count($parts) < 2) { continue; } $level = (int) trim((string) $parts[0]); $value = (int) trim((string) $parts[1]); if ($level <= 0 || $value < 0) { continue; } $thresholds[$level] = $value; } if (empty($thresholds)) { $thresholds = [1 => 0, 2 => 30, 3 => 100, 4 => 300]; } ksort($thresholds, SORT_NUMERIC); return $thresholds; } /** * @deprecated Removed — medal catalog is structured user_medal_args. Method kept empty stub intentionally deleted. * @return array */ public static function parse_badge_dictionary(string $raw): array { // Rewrite policy: no dual-read of pipe dictionary. Callers must use parse_medal_catalog / get_user_identity_settings()['medal']. unset($raw); return []; } /** * @return array */ 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; } }