[], 'quick_links' => [], 'more_links' => [], 'hot_categories' => 5, 'copyright_text' => '', 'layout_template' => 'default', ]; $footer = get_option('aksrt_footer_settings', []); $merged = array_merge($defaults, $footer); $s = AKSRT_Settings::get_all(); $bridge_keys = [ 'footer_columns', 'footer_copyright', 'footer_icp', 'icp_number', 'footer_police', 'police_number', 'footer_theme_custom', 'footer_theme_bg_custom', 'footer_theme_bg', 'footer_theme_color_custom', 'footer_contact_wechat_img', 'footer_contact_qq', 'footer_contact_weibo', 'footer_contact_email', ]; foreach ($bridge_keys as $key) { if (isset($s[$key])) { $merged[$key] = $s[$key]; } } return $merged; } public static function get_footer_contacts(): array { $footer = self::get_footer_settings(); return array_filter($footer['contacts'], fn($c) => !empty($c['enabled'])); } public static function get_quick_links(): array { $footer = self::get_footer_settings(); $links = array_filter($footer['quick_links'], fn($l) => !empty($l['enabled'])); usort($links, fn($a, $b) => ($a['sort_order'] ?? 0) <=> ($b['sort_order'] ?? 0)); return array_values($links); } public static function get_more_links(): array { $footer = self::get_footer_settings(); $links = array_filter($footer['more_links'], fn($l) => !empty($l['enabled'])); usort($links, fn($a, $b) => ($a['sort_order'] ?? 0) <=> ($b['sort_order'] ?? 0)); return array_values($links); } public static function get_hot_categories_count(): int { $footer = self::get_footer_settings(); return max(1, min(20, (int) ($footer['hot_categories'] ?? 5))); } public static function get_copyright_text(): string { $footer = self::get_footer_settings(); return $footer['copyright_text'] ?: ''; } public static function get_footer_brand_settings(): array { $f = self::get_footer_settings(); return [ 'm_s' => is_array($f['footer_t1_m_s'] ?? null) ? $f['footer_t1_m_s'] : ['pc', 'mobile'], 'img' => (string) ($f['footer_t1_img'] ?? ''), 'img_dark' => (string) ($f['footer_t1_img_dark'] ?? ''), 'title' => (string) ($f['footer_t1_t'] ?? ''), 'custom_code' => (string) ($f['fcode_t1_code'] ?? ''), ]; } public static function get_footer_contact_extended_settings(): array { $f = self::get_footer_settings(); return [ 'm_s' => is_array($f['footer_contact_m_s'] ?? null) ? $f['footer_contact_m_s'] : ['pc', 'mobile'], 'wechat_img' => (string) ($f['footer_contact_wechat_img'] ?? ''), 'qq' => (string) ($f['footer_contact_qq'] ?? ''), 'weibo' => (string) ($f['footer_contact_weibo'] ?? ''), 'email' => (string) ($f['footer_contact_email'] ?? ''), 'more' => is_array($f['footer_contact_more'] ?? null) ? $f['footer_contact_more'] : [], 'code_1' => (string) ($f['fcode_t2_code_1'] ?? ''), 'code_2' => (string) ($f['fcode_t2_code_2'] ?? ''), ]; } public static function get_footer_mini_img_settings(): array { $f = self::get_footer_settings(); return [ 'm_s' => is_array($f['footer_mini_img_m_s'] ?? null) ? $f['footer_mini_img_m_s'] : ['pc', 'mobile'], 'items' => is_array($f['footer_mini_img'] ?? null) ? $f['footer_mini_img'] : [], ]; } public static function get_footer_customize_code(): string { $f = self::get_footer_settings(); return (string) ($f['fcode_customize_code'] ?? ''); } public static function get_footer_theme_config(): array { $s = AKSRT_Settings::get_all(); return [ 'custom' => !empty($s['footer_theme_custom']), 'bg_custom' => sanitize_hex_color((string) ($s['footer_theme_bg_custom'] ?? '')) ?: '', 'bg' => sanitize_hex_color((string) ($s['footer_theme_bg'] ?? '')) ?: '', 'color_custom' => sanitize_hex_color((string) ($s['footer_theme_color_custom'] ?? '')) ?: '', ]; } public static function get_site_profile(): string { return 'cms'; } public static function get_cms_features(): array { $defaults = [ 'resource_cpt_enabled' => true, 'download_login' => true, 'download_credit' => true, 'download_captcha' => false, 'search_include_resource' => true, ]; $s = AKSRT_Settings::get_all(); $saved = isset($s['cms_features']) && is_array($s['cms_features']) ? $s['cms_features'] : []; return array_merge($defaults, $saved); } public static function cms_feature(string $key, $default = null) { $f = self::get_cms_features(); return array_key_exists($key, $f) ? $f[$key] : $default; } public static function homepage_allowed_sorts(): array { return ['modified', 'date', 'views', 'likes', 'comments', 'favorites', 'downloads', 'rand']; } public static function homepage_sort_labels(): array { return [ 'modified' => __('更新', 'aksrt'), 'date' => __('发布', 'aksrt'), 'views' => __('浏览', 'aksrt'), 'likes' => __('点赞', 'aksrt'), 'comments' => __('评论', 'aksrt'), 'favorites' => __('收藏', 'aksrt'), 'downloads' => __('下载', 'aksrt'), 'rand' => __('随机', 'aksrt'), ]; } public static function get_homepage_fixed_settings(): array { $s = AKSRT_Settings::get_all(); $allowed_sorts = self::homepage_allowed_sorts(); // Zibll-aligned primary list contract. $main_list_enabled = array_key_exists('home_posts_list_s', $s) ? !empty($s['home_posts_list_s']) : (!isset($s['home_posts_list_enabled']) || !empty($s['home_posts_list_enabled'])); $sort_bar_enabled = array_key_exists('home_list1_orderby_s', $s) ? !empty($s['home_list1_orderby_s']) : (!isset($s['home_list_sort_enabled']) || !empty($s['home_list_sort_enabled'])); $orderby_option = []; if (isset($s['home_list1_orderby_option']) && is_array($s['home_list1_orderby_option'])) { $orderby_option = $s['home_list1_orderby_option']; } $default_sort = sanitize_key((string) ($orderby_option['orderby'] ?? $s['homepage_default_sort'] ?? 'modified')); if (!in_array($default_sort, $allowed_sorts, true)) { $default_sort = 'modified'; } $sort_options_raw = $orderby_option['options'] ?? $s['home_list_sort_options'] ?? []; if (!is_array($sort_options_raw)) { $sort_options_raw = []; } $sort_options = self::normalize_sort_options($sort_options_raw); if (!in_array($default_sort, $sort_options, true)) { array_unshift($sort_options, $default_sort); $sort_options = array_values(array_unique($sort_options)); } $list_title = ''; if (array_key_exists('index_list_title', $s)) { $list_title = sanitize_text_field((string) $s['index_list_title']); } elseif (array_key_exists('home_list_title', $s)) { $list_title = sanitize_text_field((string) $s['home_list_title']); } if ($list_title === '') { $list_title = __('最新发布', 'aksrt'); } $exclude_posts = self::normalize_int_array( $s['home_exclude_posts'] ?? $s['home_exclude_post_ids'] ?? [] ); $exclude_cats = self::normalize_int_array( $s['home_exclude_cats'] ?? $s['home_exclude_category_ids'] ?? [] ); $tabs_raw = []; if (isset($s['home_lists']) && is_array($s['home_lists'])) { $tabs_raw = $s['home_lists']; } elseif (isset($s['homepage_tabs']) && is_array($s['homepage_tabs'])) { $tabs_raw = $s['homepage_tabs']; } $settings = [ // Canonical Zibll keys. 'home_posts_list_s' => $main_list_enabled, 'home_list1_orderby_s' => $sort_bar_enabled, 'home_list1_orderby_option' => [ 'orderby' => $default_sort, 'options' => $sort_options, ], 'index_list_title' => $list_title, 'home_exclude_posts' => $exclude_posts, 'home_exclude_cats' => $exclude_cats, 'home_lists' => self::normalize_homepage_tabs($tabs_raw), // Convenience aliases for existing PHP/Vue callers during cutover of this slice. 'home_posts_list_enabled' => $main_list_enabled, 'home_list_sort_enabled' => $sort_bar_enabled, 'homepage_default_sort' => $default_sort, 'home_list_sort_options' => $sort_options, 'home_list_title' => $list_title, 'home_exclude_post_ids' => $exclude_posts, 'home_exclude_category_ids' => $exclude_cats, 'homepage_tabs' => self::normalize_homepage_tabs($tabs_raw), // AKSRT presentation extras. 'homepage_card_style' => isset($s['homepage_card_style']) ? sanitize_key((string) $s['homepage_card_style']) : 'default', 'homepage_multi_thumb_enabled' => !isset($s['homepage_multi_thumb_enabled']) || !empty($s['homepage_multi_thumb_enabled']), 'homepage_multi_thumb_min_images' => (int) ($s['homepage_multi_thumb_min_images'] ?? 3), 'homepage_sidebar_mini_enabled' => !isset($s['homepage_sidebar_mini_enabled']) || !empty($s['homepage_sidebar_mini_enabled']), 'homepage_default_view' => isset($s['homepage_default_view']) ? sanitize_key((string) $s['homepage_default_view']) : 'list', 'homepage_sort_ajax_enabled' => !isset($s['homepage_sort_ajax_enabled']) || !empty($s['homepage_sort_ajax_enabled']), 'homepage_sticky_tabs_enabled' => !isset($s['homepage_sticky_tabs_enabled']) || !empty($s['homepage_sticky_tabs_enabled']), 'homepage_content_model' => isset($s['homepage_content_model']) && in_array($s['homepage_content_model'], ['post', 'mixed'], true) ? $s['homepage_content_model'] : 'mixed', 'home_list_sort_dropdown' => !empty($s['home_list_sort_dropdown']), 'homepage_tab_posts_per_page' => max(1, min(20, (int) ($s['homepage_tab_posts_per_page'] ?? 6))), 'homepage_tab_limit' => max(1, min(12, (int) ($s['homepage_tab_limit'] ?? 4))), 'homepage_module_hero_enabled' => !isset($s['homepage_module_hero_enabled']) || !empty($s['homepage_module_hero_enabled']), 'homepage_module_banner_enabled' => !isset($s['homepage_module_banner_enabled']) || !empty($s['homepage_module_banner_enabled']), ]; if (!in_array($settings['homepage_card_style'], ['default', 'style2', 'style3'], true)) { $settings['homepage_card_style'] = 'default'; } $settings['homepage_multi_thumb_min_images'] = max(2, min(4, $settings['homepage_multi_thumb_min_images'])); if (!in_array($settings['homepage_default_view'], ['list', 'card'], true)) { $settings['homepage_default_view'] = 'list'; } return $settings; } public static function homepage_content_model(): string { $settings = self::get_homepage_fixed_settings(); return $settings['homepage_content_model']; } public static function homepage_tabs(): array { $settings = self::get_homepage_fixed_settings(); return $settings['home_lists']; } /** @return array */ public static function home_lists(): array { return self::homepage_tabs(); } public static function homepage_card_style(): string { $settings = self::get_homepage_fixed_settings(); return $settings['homepage_card_style']; } public static function homepage_multi_thumb_enabled(): bool { $settings = self::get_homepage_fixed_settings(); return !empty($settings['homepage_multi_thumb_enabled']); } public static function homepage_multi_thumb_min_images(): int { $settings = self::get_homepage_fixed_settings(); return (int) $settings['homepage_multi_thumb_min_images']; } public static function homepage_sidebar_mini_enabled(): bool { $settings = self::get_homepage_fixed_settings(); return !empty($settings['homepage_sidebar_mini_enabled']); } public static function homepage_default_sort(): string { $settings = self::get_homepage_fixed_settings(); return $settings['home_list1_orderby_option']['orderby'] ?? 'modified'; } public static function homepage_default_view(): string { $settings = self::get_homepage_fixed_settings(); return $settings['homepage_default_view']; } public static function homepage_sort_ajax_enabled(): bool { $settings = self::get_homepage_fixed_settings(); return !empty($settings['homepage_sort_ajax_enabled']); } public static function homepage_sticky_tabs_enabled(): bool { $settings = self::get_homepage_fixed_settings(); return !empty($settings['homepage_sticky_tabs_enabled']); } public static function home_posts_list_enabled(): bool { $settings = self::get_homepage_fixed_settings(); return !empty($settings['home_posts_list_s']); } public static function home_list_title(): string { $settings = self::get_homepage_fixed_settings(); return (string) $settings['index_list_title']; } public static function home_list_sort_enabled(): bool { $settings = self::get_homepage_fixed_settings(); return !empty($settings['home_list1_orderby_s']); } public static function home_list_sort_options(): array { $settings = self::get_homepage_fixed_settings(); return $settings['home_list1_orderby_option']['options'] ?? ['modified', 'date', 'views', 'likes', 'comments']; } public static function home_list_sort_dropdown(): bool { $settings = self::get_homepage_fixed_settings(); return !empty($settings['home_list_sort_dropdown']); } public static function home_exclude_post_ids(): array { $settings = self::get_homepage_fixed_settings(); return $settings['home_exclude_posts']; } public static function home_exclude_category_ids(): array { $settings = self::get_homepage_fixed_settings(); return $settings['home_exclude_cats']; } public static function homepage_tab_posts_per_page(): int { $settings = self::get_homepage_fixed_settings(); return (int) $settings['homepage_tab_posts_per_page']; } public static function homepage_tab_limit(): int { $settings = self::get_homepage_fixed_settings(); return (int) $settings['homepage_tab_limit']; } public static function get_paid_content_settings(): array { $settings = AKSRT_Settings::get_all(); $features = self::get_cms_features(); $catalog_note = trim((string) ($settings['payment_paid_catalog_note'] ?? '')); $manual_note = trim((string) ($settings['payment_manual_delivery_note'] ?? '')); $box_position = sanitize_key((string) ($settings['payment_paid_box_position'] ?? 'top')); if (!in_array($box_position, ['top', 'bottom'], true)) { $box_position = 'top'; } return [ 'download_login' => !empty($features['download_login']), 'download_credit' => !empty($features['download_credit']) && AKSRT_Settings::credits_enabled(), 'download_captcha' => !empty($features['download_captcha']), 'default_cost' => AKSRT_Settings::download_default_cost(), 'paid_post_types' => self::parse_slug_list((string) ($settings['payment_paid_post_types'] ?? 'post'), ['post']), 'vip_free_download' => !empty($settings['payment_vip_free_download']), 'vip_exempt_roles' => self::parse_slug_list((string) ($settings['payment_vip_exempt_roles'] ?? '')), 'catalog_note' => $catalog_note, 'manual_delivery_note' => $manual_note !== '' ? $manual_note : __('付费或人工确认内容请在订单备注中记录交付方式。', 'aksrt'), 'no_logged_in' => !isset($settings['payment_no_logged_in']) || !empty($settings['payment_no_logged_in']), 'display' => [ 'mark' => sanitize_text_field((string) ($settings['payment_paid_mark'] ?? '付费')), 'currency_symbol' => sanitize_text_field((string) ($settings['payment_currency_symbol'] ?? '¥')), 'show_user' => !isset($settings['payment_paid_show_user']) || !empty($settings['payment_paid_show_user']), 'show_paycount' => !isset($settings['payment_paid_show_paycount']) || !empty($settings['payment_paid_show_paycount']), 'box_position' => $box_position, ], 'download' => [ 'enabled' => !empty($settings['payment_download_enable']), 'remote' => !isset($settings['payment_download_remote_s']) || !empty($settings['payment_download_remote_s']), 'verify_nonce' => !isset($settings['payment_download_verify_nonce']) || !empty($settings['payment_download_verify_nonce']), 'user_log' => max(0, min(9999, (int) ($settings['payment_download_user_log'] ?? 50))), 'post_log' => max(0, min(9999, (int) ($settings['payment_download_post_log'] ?? 50))), 'remote_size' => max(1, (int) ($settings['payment_download_remote_size'] ?? 2048)), 'remote_ext' => sanitize_text_field((string) ($settings['payment_download_remote_ext'] ?? 'zip,rar,7z')), ], ]; } public static function get_payment_recharge_settings(): array { $settings = AKSRT_Settings::get_all(); $mode = sanitize_key((string) ($settings['payment_recharge_mode'] ?? 'manual_review')); if (!in_array($mode, ['manual_review', 'test_gateway'], true)) { $mode = 'manual_review'; } $packages = (string) ($settings['payment_recharge_packages'] ?? "30|30|入门包\n98|108|推荐包"); $help_text = trim((string) ($settings['payment_recharge_help'] ?? '')); return [ 'enabled' => !empty($settings['payment_recharge_enabled']), 'mode' => $mode, 'desc' => sanitize_textarea_field((string) ($settings['payment_recharge_desc'] ?? '')), 'auto_to_balance' => !isset($settings['payment_recharge_auto_to_balance']) || !empty($settings['payment_recharge_auto_to_balance']), 'packages_raw' => $packages, 'package_count' => self::count_structured_lines($packages), 'help_text' => $help_text !== '' ? $help_text : __('当前支持人工确认与测试联调;接入真实网关时复用同一组字段。', 'aksrt'), 'product' => [ 'name' => sanitize_text_field((string) ($settings['payment_recharge_product'] ?? '')), 'price' => max(0, min(99999, (int) ($settings['payment_recharge_price'] ?? 0))), 'tag' => sanitize_text_field((string) ($settings['payment_recharge_tag'] ?? '元')), 'tag_class' => sanitize_text_field((string) ($settings['payment_recharge_tag_class'] ?? '')), 'custom_s' => !isset($settings['payment_recharge_custom_s']) || !empty($settings['payment_recharge_custom_s']), 'custom_limit' => max(1, min(99999, (int) ($settings['payment_recharge_custom_limit'] ?? 9999))), ], 'transfer' => [ 'enabled' => !empty($settings['payment_balance_transfer_s']), 'service_charge' => max(0, min(50, (int) ($settings['payment_balance_transfer_service_charge'] ?? 0))), 'desc' => sanitize_textarea_field((string) ($settings['payment_balance_transfer_desc'] ?? '')), ], 'pass_charge' => [ 'enabled' => !empty($settings['payment_recharge_pass_charge_s']), 'desc' => sanitize_textarea_field((string) ($settings['payment_recharge_pass_charge_desc'] ?? '')), 'only_password' => !empty($settings['payment_recharge_pass_charge_only_password']), ], 'exchange' => [ 'enabled' => !empty($settings['payment_recharge_exchange_s']), 'rate' => max(1, min(10000, (int) ($settings['payment_recharge_exchange_rate'] ?? 100))), 'desc' => sanitize_textarea_field((string) ($settings['payment_recharge_exchange_desc'] ?? '')), ], ]; } public static function get_payment_vip_settings(): array { $settings = AKSRT_Settings::get_all(); $packages = (string) ($settings['payment_vip_packages'] ?? "30|30|月卡\n365|365|年卡"); $help_text = trim((string) ($settings['payment_vip_help'] ?? '')); $name = trim((string) ($settings['payment_vip_name'] ?? '')); $badge = trim((string) ($settings['payment_vip_badge_text'] ?? '')); $renew_price_type = sanitize_key((string) ($settings['payment_vip_renew_price_type'] ?? 'same')); if (!in_array($renew_price_type, ['same', 'discount'], true)) { $renew_price_type = 'same'; } return [ 'enabled' => !empty($settings['payment_vip_enabled']), 'name' => $name !== '' ? $name : __('VIP会员', 'aksrt'), 'badge_text' => $badge !== '' ? $badge : __('VIP', 'aksrt'), 'desc' => sanitize_textarea_field((string) ($settings['payment_vip_desc'] ?? '')), 'packages_raw' => $packages, 'package_count' => self::count_structured_lines($packages), 'help_text' => $help_text !== '' ? $help_text : __('会员权益以免扣下载和身份展示为主,开通后立即生效。', 'aksrt'), 'benefit' => [ 'download_limit' => max(0, min(9999, (int) ($settings['payment_vip_download_limit'] ?? 0))), 'download_speed' => max(0, min(99999, (int) ($settings['payment_vip_download_speed'] ?? 0))), 'discount' => max(1, min(100, (int) ($settings['payment_vip_discount'] ?? 100))), 'pass_charge' => !empty($settings['payment_vip_pass_charge']), 'pass_charge_desc' => sanitize_textarea_field((string) ($settings['payment_vip_pass_charge_desc'] ?? '')), ], 'renew' => [ 'enabled' => !isset($settings['payment_vip_renew']) || !empty($settings['payment_vip_renew']), 'desc' => sanitize_textarea_field((string) ($settings['payment_vip_renew_desc'] ?? '')), 'price_type' => $renew_price_type, 'discount' => max(1, min(100, (int) ($settings['payment_vip_renew_discount'] ?? 100))), 'reduce' => max(0, min(9999, (int) ($settings['payment_vip_renew_reduce'] ?? 0))), ], 'upgrade' => [ 'enabled' => !isset($settings['payment_vip_upgrade']) || !empty($settings['payment_vip_upgrade']), 'desc' => sanitize_textarea_field((string) ($settings['payment_vip_upgrade_desc'] ?? '')), 'product' => sanitize_text_field((string) ($settings['payment_vip_upgrade_product'] ?? '')), ], 'price' => [ 'month' => max(0, min(99999, (int) ($settings['payment_vip_month_price'] ?? 0))), 'year' => max(0, min(99999, (int) ($settings['payment_vip_year_price'] ?? 0))), 'permanent' => max(0, min(99999, (int) ($settings['payment_vip_permanent_price'] ?? 0))), 'unit' => max(0, min(99999, (int) ($settings['payment_vip_unit_price'] ?? 0))), 'unit_tag' => sanitize_text_field((string) ($settings['payment_vip_unit_tag'] ?? '元')), 'jump' => max(0, min(99999, (int) ($settings['payment_vip_jump_price'] ?? 0))), ], ]; } public static function get_payment_revenue_settings(): array { $settings = AKSRT_Settings::get_all(); $note = trim((string) ($settings['payment_revenue_note'] ?? '')); return [ 'enabled' => !empty($settings['payment_revenue_enabled']), 'share_ratio' => max(0, min(100, (int) ($settings['payment_revenue_share_ratio'] ?? 70))), 'ratio_vip1' => max(0, min(100, (int) ($settings['payment_revenue_ratio_vip1'] ?? 0))), 'ratio_vip2' => max(0, min(100, (int) ($settings['payment_revenue_ratio_vip2'] ?? 0))), 'settlement_threshold' => max(0, (int) ($settings['payment_revenue_settlement_threshold'] ?? 100)), 'cycle_days' => max(1, min(365, (int) ($settings['payment_revenue_cycle_days'] ?? 30))), 'points_rule' => sanitize_textarea_field((string) ($settings['payment_revenue_points_rule'] ?? '')), 'note' => $note !== '' ? $note : __('分成策略和台账结构已就绪,订单入账后自动按比例结算。', 'aksrt'), 'display' => [ 'desc_details' => sanitize_textarea_field((string) ($settings['payment_revenue_desc_details'] ?? '')), 'desc_page' => esc_url_raw((string) ($settings['payment_revenue_desc_page'] ?? '')), ], ]; } public static function get_payment_affiliate_settings(): array { $settings = AKSRT_Settings::get_all(); $note = trim((string) ($settings['payment_affiliate_note'] ?? '')); return [ 'enabled' => !empty($settings['payment_affiliate_enabled']), 'ratio' => max(0, min(100, (int) ($settings['payment_affiliate_ratio'] ?? 10))), 'window_days' => max(1, min(365, (int) ($settings['payment_affiliate_window_days'] ?? 30))), 'require_paid_order' => !isset($settings['payment_affiliate_require_paid_order']) || !empty($settings['payment_affiliate_require_paid_order']), 'self_s' => !isset($settings['payment_affiliate_self_s']) || !empty($settings['payment_affiliate_self_s']), 'show_users' => !isset($settings['payment_affiliate_show_users']) || !empty($settings['payment_affiliate_show_users']), 'note' => $note !== '' ? $note : __('返佣链路复用邀请体系,订单归因和结算自动衔接当前策略字段。', 'aksrt'), 'user_ratio' => [ 'user' => max(0, min(100, (int) ($settings['payment_affiliate_user_ratio'] ?? 10))), 'vip1' => max(0, min(100, (int) ($settings['payment_affiliate_vip1_ratio'] ?? 0))), 'vip2' => max(0, min(100, (int) ($settings['payment_affiliate_vip2_ratio'] ?? 0))), ], 'poster' => [ 'enabled' => !isset($settings['payment_affiliate_poster_s']) || !empty($settings['payment_affiliate_poster_s']), 'img' => esc_url_raw((string) ($settings['payment_affiliate_poster_img'] ?? '')), 'title' => sanitize_text_field((string) ($settings['payment_affiliate_poster_title'] ?? '')), 'desc' => sanitize_text_field((string) ($settings['payment_affiliate_poster_desc'] ?? '')), ], 'text' => [ 'desc' => sanitize_textarea_field((string) ($settings['payment_affiliate_text_desc'] ?? '')), 'details_title' => sanitize_text_field((string) ($settings['payment_affiliate_text_details_title'] ?? '')), 'details' => sanitize_textarea_field((string) ($settings['payment_affiliate_text_details'] ?? '')), 'discount' => sanitize_text_field((string) ($settings['payment_affiliate_text_discount'] ?? '')), ], ]; } public static function get_payment_gateway_settings(): array { $settings = AKSRT_Settings::get_all(); $mode = sanitize_key((string) ($settings['payment_gateway_mode'] ?? 'manual_review')); if (!in_array($mode, ['manual_review', 'test_gateway', 'adapter_ready'], true)) { $mode = 'manual_review'; } $help_text = trim((string) ($settings['payment_gateway_help'] ?? '')); $gateway_keys = ['wechat', 'alipay', 'paypal', 'stripe', 'balance', 'card_pass', 'xunhupay', 'xhpay', 'payjs', 'epay', 'vmq', 'codepay']; $gateways = []; foreach ($gateway_keys as $gw) { $gateways[$gw] = !empty($settings["payment_{$gw}_enabled"]); } return [ 'mode' => $mode, 'test_enabled' => !isset($settings['payment_gateway_test_enabled']) || !empty($settings['payment_gateway_test_enabled']), 'manual_review' => !isset($settings['payment_gateway_manual_review']) || !empty($settings['payment_gateway_manual_review']), 'callback_secret' => sanitize_text_field((string) ($settings['payment_gateway_callback_secret'] ?? '')), 'help_text' => $help_text !== '' ? $help_text : __('未接真实支付网关时,建议使用测试网关或人工确认模式完成联调。', 'aksrt'), 'gateways' => $gateways, 'xunhupay' => [ 'appid' => sanitize_text_field((string) ($settings['xunhupay_appid'] ?? '')), 'appsecret' => sanitize_text_field((string) ($settings['xunhupay_appsecret'] ?? '')), ], 'xhpay' => [ 'mchid' => sanitize_text_field((string) ($settings['xhpay_mchid'] ?? '')), 'alipay_v2' => sanitize_text_field((string) ($settings['xhpay_alipay_v2'] ?? '')), 'wx_h5' => sanitize_text_field((string) ($settings['xhpay_wx_h5'] ?? '')), ], 'payjs' => [ 'mchid' => sanitize_text_field((string) ($settings['payjs_mchid'] ?? '')), 'key' => sanitize_text_field((string) ($settings['payjs_key'] ?? '')), ], 'epay' => [ 'apiurl' => esc_url_raw((string) ($settings['epay_apiurl'] ?? '')), 'pid' => sanitize_text_field((string) ($settings['epay_pid'] ?? '')), 'key' => sanitize_text_field((string) ($settings['epay_key'] ?? '')), ], 'alipay_extra' => [ 'return_url' => esc_url_raw((string) ($settings['alipay_return_url'] ?? '')), 'notify_url' => esc_url_raw((string) ($settings['alipay_notify_url'] ?? '')), ], ]; } public static function get_order_settings(): array { $s = AKSRT_Settings::get_all(); $expiry = max(5, min(1440, (int) ($s['payment_order_expiry'] ?? 30))); $cookie_day = max(1, min(31, (int) ($s['payment_cookie_day'] ?? 15))); $max_minutes = max(5, min(1440, (int) ($s['payment_order_max_minutes'] ?? 30))); $box_position = sanitize_key((string) ($s['payment_box_position'] ?? 'top')); if (!in_array($box_position, ['top', 'bottom'], true)) { $box_position = 'top'; } $status_keys = ['pending', 'paid', 'completed', 'cancelled', 'refunded', 'refunding', 'processing']; $status_defaults = ['待支付', '已支付', '已完成', '已取消', '已退款', '退款中', '处理中']; $status_texts = []; foreach ($status_keys as $i => $key) { $val = trim((string) ($s["payment_order_status_{$key}"] ?? '')); $status_texts[$key] = $val !== '' ? $val : $status_defaults[$i]; } return [ 'prefix' => sanitize_text_field((string) ($s['payment_order_prefix'] ?? 'AKSRT')), 'expiry' => $expiry, 'show_user' => !isset($s['payment_show_user']) || !empty($s['payment_show_user']), 'show_paycount' => !isset($s['payment_show_paycount']) || !empty($s['payment_show_paycount']), 'no_logged_in' => !isset($s['payment_no_logged_in']) || !empty($s['payment_no_logged_in']), 'cookie_day' => $cookie_day, 'no_logged_remind' => sanitize_textarea_field((string) ($s['payment_no_logged_remind'] ?? '')), 'wait_float' => !isset($s['payment_wait_float_s']) || !empty($s['payment_wait_float_s']), 'order_max_minutes' => $max_minutes, 'mark' => sanitize_text_field((string) ($s['payment_mark'] ?? '付费')), 'box_position' => $box_position, 'free_logged_show' => !empty($s['payment_free_logged_show']), 'show_ip' => !empty($s['payment_show_ip']), 'show_device' => !empty($s['payment_show_device']), 'show_order_no' => !isset($s['payment_show_order_no']) || !empty($s['payment_show_order_no']), 'show_create_time' => !isset($s['payment_show_create_time']) || !empty($s['payment_show_create_time']), 'show_pay_time' => !isset($s['payment_show_pay_time']) || !empty($s['payment_show_pay_time']), 'status_texts' => $status_texts, 'service' => [ 'text' => sanitize_textarea_field((string) ($s['payment_service'] ?? '')), 'icon' => sanitize_text_field((string) ($s['payment_service_icon'] ?? '')), 'value' => sanitize_text_field((string) ($s['payment_service_value'] ?? '')), 'qq' => sanitize_text_field((string) ($s['payment_service_qq'] ?? '')), 'wechat' => esc_url_raw((string) ($s['payment_service_wechat'] ?? '')), ], ]; } public static function get_card_pass_settings(): array { $s = AKSRT_Settings::get_all(); $type = sanitize_key((string) ($s['card_pass_type'] ?? 'balance')); if (!in_array($type, ['balance', 'vip', 'credits'], true)) { $type = 'balance'; } $success_msg = trim((string) ($s['card_pass_success_msg'] ?? '')); $fail_msg = trim((string) ($s['card_pass_fail_msg'] ?? '')); return [ 'enabled' => !empty($s['card_pass_enabled']), 'desc' => sanitize_textarea_field((string) ($s['card_pass_desc'] ?? '')), 'type' => $type, 'prefix' => sanitize_text_field((string) ($s['card_pass_prefix'] ?? 'AK')), 'length' => max(8, min(32, (int) ($s['card_pass_length'] ?? 16))), 'batch_size' => max(1, min(500, (int) ($s['card_pass_batch_size'] ?? 50))), 'max_redeem' => max(1, min(100, (int) ($s['card_pass_max_redeem'] ?? 1))), 'expiry_days' => max(0, (int) ($s['card_pass_expiry'] ?? 0)), 'amount' => max(1, min(9999, (int) ($s['card_pass_amount'] ?? 10))), 'vip_days' => max(1, min(3650, (int) ($s['card_pass_vip_days'] ?? 30))), 'credits' => max(0, min(99999, (int) ($s['card_pass_credits'] ?? 0))), 'redeem_page' => esc_url_raw((string) ($s['card_pass_redeem_page'] ?? '')), 'success_msg' => $success_msg !== '' ? $success_msg : __('兑换成功!', 'aksrt'), 'fail_msg' => $fail_msg !== '' ? $fail_msg : __('卡号无效或已过期', 'aksrt'), ]; } public static function get_withdrawal_settings(): array { $s = AKSRT_Settings::get_all(); return [ 'min_amount' => max(1, min(99999, (int) ($s['pay_rebate_withdraw_lowest_money'] ?? 50))), 'service_charge_rate' => max(0, min(50, (int) ($s['withdraw_service_charge'] ?? 0))), 'text' => sanitize_textarea_field((string) ($s['pay_rebate_withdraw_text_details'] ?? '')), ]; } private static function normalize_sort_options(array $raw): array { $allowed = self::homepage_allowed_sorts(); $result = []; $seen = []; foreach ($raw as $key) { $key = sanitize_key((string) $key); if (in_array($key, $allowed, true) && !isset($seen[$key])) { $result[] = $key; $seen[$key] = true; } } if (empty($result)) { $result = ['modified', 'date', 'views', 'likes', 'comments']; } return $result; } private static function normalize_int_array($raw): array { if (!is_array($raw)) { return []; } return array_values(array_filter(array_map('absint', $raw), static fn($v) => $v > 0)); } private static function normalize_homepage_tabs(array $raw_tabs): array { $allowed_orderby = self::homepage_allowed_sorts(); $tabs = []; foreach ($raw_tabs as $tab) { if (!is_array($tab)) { continue; } $term_id = absint($tab['term_id'] ?? 0); if ($term_id <= 0) { continue; } $orderby = sanitize_key($tab['orderby'] ?? 'date'); if (!in_array($orderby, $allowed_orderby, true)) { $orderby = 'date'; } $tabs[] = [ 'term_id' => $term_id, 'title' => sanitize_text_field($tab['title'] ?? ''), 'orderby' => $orderby, 'enabled' => !empty($tab['enabled']), ]; } return $tabs; } private static function parse_slug_list(string $raw, array $fallback = []): array { $items = preg_split('/[\s,]+/', $raw, -1, PREG_SPLIT_NO_EMPTY); $normalized = []; foreach ((array) $items as $item) { $slug = sanitize_key((string) $item); if ($slug !== '' && !in_array($slug, $normalized, true)) { $normalized[] = $slug; } } return !empty($normalized) ? $normalized : $fallback; } private static function count_structured_lines(string $raw): int { $lines = preg_split('/[\r\n]+/', $raw, -1, PREG_SPLIT_NO_EMPTY); $count = 0; foreach ((array) $lines as $line) { if (trim((string) $line) !== '') { $count++; } } return $count; } }