($banner['position'] ?? '') === $position); } usort($banners, fn($a, $b) => ($a['sort_order'] ?? 0) - ($b['sort_order'] ?? 0)); return array_filter($banners, fn($banner) => ($banner['status'] ?? 'enabled') === 'enabled'); } /** 保存Banner */ public static function save_banner(array $data): int { $banners = get_option('aksrt_banners', []); if (!empty($data['id'])) { $banners[$data['id']] = $data; } else { $data['id'] = uniqid('banner_'); $banners[] = $data; } update_option('aksrt_banners', $banners); return $data['id']; } /** 删除Banner */ public static function delete_banner(string $id): void { $banners = get_option('aksrt_banners', []); unset($banners[$id]); update_option('aksrt_banners', array_values($banners)); } /** 获取友链列表 */ public static function get_friend_links(): array { $links = get_option('aksrt_friend_links', []) ?: []; return array_values(array_filter($links, static function ($link) { return !empty($link['active']); })); } /** 保存友链 */ public static function save_friend_links(array $links): void { update_option('aksrt_friend_links', $links); } /** * 是否显示顶部组件搜索覆盖框 */ public static function header_components_search_enabled(): bool { $settings = AKSRT_Settings::get_all(); return !empty($settings['header_components_search_enabled']); } /** * Hero 搜索组件详细配置(PC/移动分别 + 子选项) * * @return array{pc:bool,mobile:bool,show_keywords:bool,popular_limit:int,show_input_cat:bool,show_type:bool,keywords:string[],categories:array,type_options:array} */ public static function get_header_components_search_config(): array { $settings = AKSRT_Settings::get_all(); $master = self::header_components_search_enabled(); $is_mobile = function_exists('wp_is_mobile') && wp_is_mobile(); $pc_on = $master && (!isset($settings['header_components_search_pc']) || !empty($settings['header_components_search_pc'])); $mobile_on = $master && (!isset($settings['header_components_search_mobile']) || !empty($settings['header_components_search_mobile'])); $show = $is_mobile ? $mobile_on : $pc_on; $show_kw = !empty($settings['header_components_search_show_keywords']); $kw_limit = max(1, min(20, (int) ($settings['header_components_search_popular_limit'] ?? 5))); $show_cat = !empty($settings['header_components_search_show_input_cat']); $show_type = !empty($settings['header_components_search_show_type']); $keywords = []; if ($show && $show_kw) { $raw = $settings['hot_search_keywords'] ?? ''; $keywords = is_array($raw) ? $raw : preg_split('/[\s,]+/', (string) $raw, -1, PREG_SPLIT_NO_EMPTY); $keywords = array_slice(array_map('sanitize_text_field', $keywords), 0, $kw_limit); } $categories = []; if ($show && $show_cat) { $cats = get_categories(['hide_empty' => false, 'number' => 50]); foreach ($cats as $cat) { $categories[] = ['id' => $cat->term_id, 'name' => $cat->name]; } } $type_options = []; if ($show && $show_type) { $types = AKSRT_Settings::get_search_content_types(); foreach (($types['enabled'] ?? []) as $type_key => $type_value) { if ($type_value) { $type_options[] = ['key' => $type_key, 'label' => $type_key]; } } } return [ 'pc' => $pc_on, 'mobile' => $mobile_on, 'show' => $show, 'show_keywords' => $show_kw, 'popular_limit' => $kw_limit, 'show_input_cat' => $show_cat, 'show_type' => $show_type, 'keywords' => $keywords, 'categories' => $categories, 'type_options' => $type_options, ]; } /** * 是否显示顶部组件图标卡片覆盖 */ public static function header_components_cards_enabled(): bool { $settings = AKSRT_Settings::get_all(); return !empty($settings['header_components_cards_enabled']); } public static function homepage_module_hero_enabled(): bool { $settings = AKSRT_Settings::get_all(); return !isset($settings['homepage_module_hero_enabled']) || !empty($settings['homepage_module_hero_enabled']); } public static function homepage_module_banner_enabled(): bool { $settings = AKSRT_Settings::get_all(); return !isset($settings['homepage_module_banner_enabled']) || !empty($settings['homepage_module_banner_enabled']); } /** * Global slider configuration shared by Hero and Banner. * * @return array */ public static function get_slider_config(): array { $settings = AKSRT_Settings::get_all(); $config = $settings['slider_config'] ?? []; return [ 'effect' => in_array($config['effect'] ?? '', ['fade', 'slide', 'cube', 'coverflow', 'flip'], true) ? $config['effect'] : 'fade', 'direction' => in_array($settings['slider_config_direction'] ?? ($config['direction'] ?? ''), ['horizontal', 'vertical'], true) ? ($settings['slider_config_direction'] ?? ($config['direction'] ?? 'horizontal')) : 'horizontal', 'loop' => !isset($config['loop']) || !empty($config['loop']), 'autoplay_interval' => max(1000, min(30000, (int) ($config['autoplay_interval'] ?? 5000))), 'pagination' => !isset($config['pagination']) || !empty($config['pagination']), 'navigation' => !isset($config['navigation']) || !empty($config['navigation']), 'button' => isset($settings['slider_config_button']) ? !empty($settings['slider_config_button']) : (!isset($config['button']) || !empty($config['button'])), 'auto_height' => !empty($config['auto_height']), 'pc_height' => isset($config['pc_height']) && $config['pc_height'] !== '' ? sanitize_text_field($config['pc_height']) : '', 'mobile_height' => isset($config['mobile_height']) && $config['mobile_height'] !== '' ? sanitize_text_field($config['mobile_height']) : '', 'max_height' => isset($settings['slider_config_max_height']) && $settings['slider_config_max_height'] !== '' ? sanitize_text_field($settings['slider_config_max_height']) : (isset($config['max_height']) && $config['max_height'] !== '' ? sanitize_text_field($config['max_height']) : ''), 'min_height' => isset($settings['slider_config_min_height']) && $settings['slider_config_min_height'] !== '' ? sanitize_text_field($settings['slider_config_min_height']) : (isset($config['min_height']) && $config['min_height'] !== '' ? sanitize_text_field($config['min_height']) : ''), 'scale_height' => !empty($settings['slider_config_scale_height'] ?? ($config['scale_height'] ?? false)), 'scale' => !empty($settings['slider_config_scale'] ?? ($config['scale'] ?? false)), 'speed' => max(100, min(3000, (int) ($settings['slider_config_speed'] ?? ($config['speed'] ?? 300)))), 'space_between' => max(0, min(100, (int) ($config['space_between'] ?? 0))), 'nav_color' => sanitize_hex_color((string) ($settings['header_components_nav_color'] ?? '')) ?: '', ]; } public static function get_header_components_icon_cards(): array { $settings = AKSRT_Settings::get_all(); $cards = $settings['header_components_icon_cards'] ?? []; return is_array($cards) ? array_values($cards) : []; } public static function get_header_components_card_columns(): int { $settings = AKSRT_Settings::get_all(); $columns = (int) ($settings['header_components_card_columns'] ?? 4); return max(2, min(6, $columns)); } public static function header_components_card_bg_enabled(): bool { $settings = AKSRT_Settings::get_all(); return !empty($settings['header_components_card_bg']); } /** * 获取全局背景设置 */ public static function get_global_background_settings(): array { $settings = AKSRT_Settings::get_all(); $valid_sizes = ['cover', 'contain', 'auto', '100%', '100% 100%']; $size = sanitize_text_field((string) ($settings['bg_size'] ?? '100%')); if (!in_array($size, $valid_sizes, true)) { $size = '100%'; } $valid_positions = ['center center', 'top center', 'bottom center']; $position = sanitize_text_field((string) ($settings['bg_position'] ?? 'center center')); if (!in_array($position, $valid_positions, true)) { $position = 'center center'; } $valid_repeats = ['no-repeat', 'repeat', 'repeat-x', 'repeat-y']; $repeat = sanitize_key((string) ($settings['bg_repeat'] ?? 'no-repeat')); if (!in_array($repeat, $valid_repeats, true)) { $repeat = 'no-repeat'; } $attachment = sanitize_key((string) ($settings['bg_attachment'] ?? 'fixed')); if (!in_array($attachment, ['fixed', 'scroll'], true)) { $attachment = 'fixed'; } return [ 'bg_color' => sanitize_hex_color((string) ($settings['bg_color'] ?? '')) ?: '', 'bg_image' => esc_url_raw((string) ($settings['bg_image'] ?? '')), 'bg_size' => $size, 'bg_position' => $position, 'bg_repeat' => $repeat, 'bg_attachment' => $attachment, 'bg_dark_color' => sanitize_hex_color((string) ($settings['bg_dark_color'] ?? '')) ?: '', 'bg_dark_image' => esc_url_raw((string) ($settings['bg_dark_image'] ?? '')), 'bg_overlay' => !empty($settings['bg_overlay']), 'bg_overlay_color' => sanitize_text_field((string) ($settings['bg_overlay_color'] ?? 'rgba(0, 0, 0, 0.3)')), 'page_bg_color' => sanitize_hex_color((string) ($settings['page_bg_color'] ?? '')) ?: '', 'page_bg_image' => esc_url_raw((string) ($settings['page_bg_image'] ?? '')), ]; } }