!empty($s['header_theme_custom']), 'bg_custom' => sanitize_hex_color((string) ($s['header_theme_bg_custom'] ?? '')) ?: '', 'bg' => self::normalize_palette_hex((string) ($s['header_theme_bg'] ?? '')), 'color_custom' => sanitize_hex_color((string) ($s['header_theme_color_custom'] ?? '')) ?: '', ]; } private static function normalize_palette_hex(string $value): string { $value = ltrim(trim($value), '#'); return preg_match('/^[0-9a-f]{6}$/i', $value) ? '#' . strtolower($value) : ''; } /** * Category archive display settings. * * @return array */ public static function get_category_page_settings(): array { $settings = self::read_domain('page_display', 'category'); $orderby_option = self::normalize_page_orderby_option($settings['cat_orderby_option'] ?? []); $orderby = sanitize_key((string) (($orderby_option['lists'][0] ?? 'modified'))); $ajax_category_enabled = !empty($settings['ajax_list_cat_cat']); $ajax_tag_enabled = !empty($settings['ajax_list_cat_tag']); $orderby_enabled = !empty($settings['cat_orderby_s']); $post_count = !empty($settings['cat_post_count_s']); return [ 'header_style' => !empty($settings['page_cover_cat_s']) ? 'cover' : 'simple', 'cover_enabled' => !empty($settings['page_cover_cat_s']), 'desc_enabled' => true, 'default_cover' => esc_url_raw((string) ($settings['cat_default_cover'] ?? '')), 'list_mode' => 'grid', 'filter_bar' => $ajax_category_enabled || $ajax_tag_enabled || $orderby_enabled || $post_count, 'sidebar' => true, 'per_page' => max(1, (int) get_option('posts_per_page', 10)), 'post_count' => $post_count, 'orderby' => $orderby, 'orderby_enabled'=> $orderby_enabled, 'orderby_option' => $orderby_option, 'ajax_category_enabled' => $ajax_category_enabled, 'ajax_tag_enabled' => $ajax_tag_enabled, 'ajax_category' => is_array($settings['ajax_list_option_cat_cat'] ?? null) ? $settings['ajax_list_option_cat_cat'] : [], 'ajax_tag' => is_array($settings['ajax_list_option_cat_tag'] ?? null) ? $settings['ajax_list_option_cat_tag'] : [], ]; } /** * Tag archive display settings. * * @return array */ public static function get_tag_page_settings(): array { $settings = self::read_domain('page_display', 'tag'); $orderby_option = self::normalize_page_orderby_option($settings['tag_orderby_option'] ?? []); $orderby = sanitize_key((string) (($orderby_option['lists'][0] ?? 'modified'))); $ajax_category_enabled = !empty($settings['ajax_list_tag_cat']); $ajax_tag_enabled = !empty($settings['ajax_list_tag_tag']); $orderby_enabled = !empty($settings['tag_orderby_s']); $post_count = !empty($settings['tag_post_count_s']); return [ 'header_style' => !empty($settings['page_cover_tag_s']) ? 'cover' : 'simple', 'cover_enabled' => !empty($settings['page_cover_tag_s']), 'default_cover' => esc_url_raw((string) ($settings['tag_default_cover'] ?? '')), 'list_mode' => 'grid', 'sidebar' => true, 'per_page' => max(1, (int) get_option('posts_per_page', 10)), 'post_count' => $post_count, 'filter_bar' => $ajax_category_enabled || $ajax_tag_enabled || $orderby_enabled || $post_count, 'orderby' => $orderby, 'orderby_enabled'=> $orderby_enabled, 'orderby_option' => $orderby_option, 'ajax_category_enabled' => $ajax_category_enabled, 'ajax_tag_enabled' => $ajax_tag_enabled, 'ajax_category' => is_array($settings['ajax_list_option_tag_cat'] ?? null) ? $settings['ajax_list_option_tag_cat'] : [], 'ajax_tag' => is_array($settings['ajax_list_option_tag_tag'] ?? null) ? $settings['ajax_list_option_tag_tag'] : [], ]; } /** @return array{header_style:string,header_cover_img:string} */ public static function get_other_page_settings(): array { $settings = self::read_domain('page_display', 'other'); $header_style = sanitize_key((string) ($settings['page_header_style'] ?? '')); if (!in_array($header_style, ['', '1', '2', '3'], true)) { $header_style = ''; } return [ 'header_style' => $header_style, 'header_cover_img' => esc_url_raw((string) ($settings['page_header_cover_img'] ?? '')), ]; } /** @param mixed $value */ private static function normalize_page_orderby_option($value): array { $option = is_array($value) ? $value : []; $allowed = self::homepage_allowed_sorts(); $lists = is_array($option['lists'] ?? null) ? $option['lists'] : []; $lists = array_values(array_intersect(array_map('sanitize_key', $lists), $allowed)); if ($lists === []) { $lists = ['modified', 'views', 'like', 'comment_count']; } return [ 'lists' => $lists, 'dropdown' => !empty($option['dropdown']), ]; } /** * Share and poster settings. * * @return array{wechat_enabled:bool,wechat_appid:string,wechat_app_secret:string,only_logo:bool,compatible_s:bool,poster_img:string,poster_logo:string,share_img:string,share_desc:string} */ public static function get_share_settings(): array { $settings = self::get_all(); return [ 'wechat_enabled' => !empty($settings['share_wechat_s']), 'wechat_appid' => sanitize_text_field((string) ($settings['share_wechat_appid'] ?? '')), 'wechat_app_secret' => sanitize_text_field((string) ($settings['share_wechat_app_secret'] ?? '')), 'only_logo' => !empty($settings['share_only_logo']), 'compatible_s' => !empty($settings['share_img_compatible_s']), 'poster_img' => esc_url_raw((string) ($settings['share_img_byimg'] ?? '')), 'poster_logo' => esc_url_raw((string) ($settings['share_logo'] ?? '')), 'share_img' => esc_url_raw((string) ($settings['share_img'] ?? '')), 'share_desc' => sanitize_textarea_field((string) ($settings['share_desc'] ?? '')) ?: __('扫一扫 立即查看', 'aksrt'), ]; } /** * Single post/page display settings. * * @return array */ public static function get_post_page_settings(): array { // Canonical assembly lives in the post-display helper (related style/source split, aliases). if (class_exists('AKSRT\\Settings\\PostDisplay')) { return PostDisplay::get_post_page_settings(); } $settings = self::get_all(); return [ 'reading_progress' => !isset($settings['post_reading_progress']) || !empty($settings['post_reading_progress']), 'breadcrumbs' => !isset($settings['breadcrumbs_single_s']) || !empty($settings['breadcrumbs_single_s']), 'breadcrumbs_home' => trim((string) ($settings['breadcrumbs_home_text'] ?? '')) ?: __('首页', 'aksrt'), 'related_enabled' => !isset($settings['post_related_s']) || !empty($settings['post_related_s']), 'related_count' => max(4, min(12, (int) ($settings['post_related_n'] ?? 6))), 'related_style' => in_array(($settings['post_related_type'] ?? 'img'), ['img', 'list', 'text'], true) ? (string) $settings['post_related_type'] : 'img', 'related_orderby' => 'views', 'related_title' => sanitize_text_field((string) ($settings['related_title'] ?? '相关推荐')), ]; } /** * 获取备案配置。 * @return array {icp_enabled, icp_filing, police_enabled, police_filing} */ public static function get_filing_settings(): array { $s = self::get_all(); $icp_enabled = !isset($s['footer_icp']) || !empty($s['footer_icp']); $police_enabled = !isset($s['footer_police']) || !empty($s['footer_police']); $icp_filing = trim((string) ($s['icp_filing'] ?? '')); $police_filing = trim((string) ($s['police_filing'] ?? '')); return [ 'icp_enabled' => $icp_enabled, 'icp_filing' => $icp_filing, 'police_enabled' => $police_enabled, 'police_filing' => $police_filing, ]; } /** 获取页脚附加文字 */ public static function footer_text(): string { return trim((string) self::get_value('footer_text', '')); } /** 获取 ICP 备案号 */ public static function icp_filing(): string { return trim((string) self::get_value('icp_filing', '')); } /** 获取公安备案号 */ public static function police_filing(): string { return trim((string) self::get_value('police_filing', '')); } /** 获取导航 Logo 宽度 */ public static function logo_width(): int { $width = (int) self::get_value('logo_width', 150); return max(50, min(400, $width)); } /** 获取Favicon URL */ public static function custom_favicon_url(): string { $favicon = (string) self::get_value('site_favicon', ''); return $favicon !== '' ? $favicon : ''; } public static function favicon_url(): string { $custom = self::custom_favicon_url(); if ($custom !== '') { return $custom; } $site_icon = get_site_icon_url(512); return $site_icon ? (string) $site_icon : self::default_asset_url('default-favicon.svg'); } /** 获取About显示名 */ /** * 让 SEO 设置中的 Favicon 覆盖 WordPress 原生 site_icon 输出链路。 * * @param string $url * @param int $size * @param int $blog_id * @return string */ public static function filter_site_icon_url($url, $size, $blog_id): string { $custom = self::custom_favicon_url(); return $custom !== '' ? $custom : (string) $url; } /** * 尝试把自定义 favicon 同步到 WordPress 原生 site_icon 选项。 * * 仅当 URL 能映射到媒体库附件时才同步;外链仍通过 get_site_icon_url 过滤覆盖。 */ public static function sync_native_site_icon(string $favicon_url): void { $favicon_url = trim(esc_url_raw($favicon_url)); if ($favicon_url === '') { return; } $attachment_id = attachment_url_to_postid($favicon_url); if ($attachment_id > 0 && (int) get_option('site_icon', 0) !== $attachment_id) { update_option('site_icon', $attachment_id); } } /** 启动时对齐原生 site_icon,同步自定义 site_favicon 到原生 site_icon。 */ public static function maybe_sync_native_site_icon(): void { $custom = self::custom_favicon_url(); if ($custom === '') { return; } self::sync_native_site_icon($custom); } public static function about_display_name(): string { $s = self::get_all(); return !empty($s['about_display_name']) ? $s['about_display_name'] : get_bloginfo('name'); } /** 获取About简介 */ public static function about_bio(): string { $s = self::get_all(); return !empty($s['about_bio']) ? $s['about_bio'] : get_bloginfo('description'); } /** 获取About头像URL */ public static function about_avatar(): string { $s = self::get_all(); return $s['about_avatar'] ?? ($s['admin_avatar_url'] ?? ''); } /** 获取SEO关键词 */ public static function seo_keywords(): string { $s = self::get_all(); return $s['seo_keywords'] ?? ''; } /** 获取自定义头部代码 */ public static function custom_head_code(): string { $code = (string) self::get_value('head_code', ''); if ($code === '') { $code = (string) self::get_value('custom_js_header', ''); } return $code; } /** 获取自定义 CSS */ public static function custom_css(): string { return (string) self::get_value('custom_css', ''); } /** 获取自定义底部代码 */ public static function custom_footer_code(): string { $code = (string) self::get_value('foot_code', ''); if ($code === '') { $code = (string) self::get_value('custom_js_footer', ''); } return $code; } /** 获取统计代码 */ public static function trackcode(): string { return trim((string) self::get_value('trackcode', '')); } /** 获取SMTP配置 */ public static function get_smtp(): array { return get_option('aksrt_mail_smtp', [ 'enabled' => false, 'host' => '', 'port' => 465, 'username' => '', 'password' => '', 'encryption' => 'ssl', 'from_name' => '', 'from_address' => '', ]); } /** 获取邮件品牌设置(发件人昵称/标题前缀/底部内容) */ public static function get_mail_branding(): array { $s = self::get_all(); return [ 'showname' => trim((string) ($s['mail_showname'] ?? '')), 'title_prefix' => trim((string) ($s['mail_title_prefix'] ?? '')), 'description' => trim((string) ($s['mail_description'] ?? '')), 'more_content' => trim((string) ($s['mail_more_content'] ?? '')), ]; } }