feat(admin): rebuild page display settings

This commit is contained in:
2026-08-19 00:07:13 +08:00
parent 09b1e8fd35
commit 480e2bf07e
117 changed files with 1815 additions and 9081 deletions
+1 -6
View File
@@ -50,7 +50,7 @@ trait DisplayPageGroups {
* 获取顶部多功能组件设置
*/
public static function get_header_slider_settings(): array {
$s = self::get_all();
$s = self::read_domain('page_display', 'header-components');
$allowed_page_types = [
'home',
'category',
@@ -59,10 +59,6 @@ trait DisplayPageGroups {
'single',
'search',
'page',
'topics',
'forum_home',
'forum_plate',
'forum_post',
];
$show_on = isset($s['header_slider_show']) ? (array) $s['header_slider_show'] : [];
$show_on = array_values(array_intersect(
@@ -218,7 +214,6 @@ trait DisplayPageGroups {
'tag' => self::get_tag_page_settings(),
'user_home' => self::get_user_home_settings(),
'other' => self::get_other_page_settings(),
'background' => self::get_global_background_settings(),
];
}
-112
View File
@@ -9,39 +9,6 @@ defined('ABSPATH') || exit;
class DisplayRuntime {
/** 获取Banner列表 */
public static function get_banners(string $position = ''): array {
$banners = get_option('aksrt_banners', []) ?: [];
if ($position) {
$banners = array_filter($banners, fn($banner) => ($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', []) ?: [];
@@ -56,83 +23,4 @@ class DisplayRuntime {
update_option('aksrt_friend_links', $links);
}
public static function homepage_module_banner_enabled(): bool {
$settings = 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<string,mixed>
*/
public static function get_slider_config(): array {
$settings = Settings::get_all();
$config = is_array($settings['header_slider_option'] ?? null) ? $settings['header_slider_option'] : [];
return [
'effect' => in_array($config['effect'] ?? '', ['fade', 'slide', 'cube', 'coverflow', 'flip'], true) ? $config['effect'] : 'fade',
'direction' => in_array($config['direction'] ?? '', ['horizontal', 'vertical'], true) ? $config['direction'] : 'horizontal',
'loop' => !isset($config['loop']) || !empty($config['loop']),
'autoplay_interval' => max(0, min(20000, (int) ($config['interval'] ?? 6) * 1000)),
'pagination' => !isset($config['pagination']) || !empty($config['pagination']),
'navigation' => !isset($config['navigation']) || !empty($config['navigation']),
'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['m_height']) && $config['m_height'] !== '' ? sanitize_text_field($config['m_height']) : '',
'max_height' => isset($config['max_height']) && $config['max_height'] !== '' ? sanitize_text_field($config['max_height']) : '',
'min_height' => isset($config['min_height']) && $config['min_height'] !== '' ? sanitize_text_field($config['min_height']) : '',
'scale_height' => !empty($config['scale_height']),
'scale' => (int) ($config['scale'] ?? 40),
'speed' => max(0, min(3000, (int) ($config['speed'] ?? 0))),
'space_between' => max(0, min(500, (int) ($config['spacebetween'] ?? 0))),
'nav_color' => sanitize_hex_color((string) ($settings['header_slider_nav_color'] ?? '')) ?: '',
];
}
/**
* 获取全局背景设置
*/
public static function get_global_background_settings(): array {
$settings = 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'] ?? '')),
];
}
}
-7
View File
@@ -27,13 +27,6 @@ trait DomainGroups {
Integration::update_wechat_settings($settings);
}
/**
* 获取全局背景设置
*/
public static function get_global_background_settings(): array {
return DisplayRuntime::get_global_background_settings();
}
/**
* 获取页脚布局模板
*/
+78 -81
View File
@@ -14,16 +14,21 @@ trait FacadeBulk {
* @return array{custom:bool,bg_custom:string,bg:string,color_custom:string}
*/
public static function get_header_theme_config(): array {
$s = self::get_all();
$s = self::read_domain('page_display', 'header-nav');
return [
'custom' => !empty($s['header_theme_custom']),
'bg_custom' => sanitize_hex_color((string) ($s['header_theme_bg_custom'] ?? '')) ?: '',
'bg' => sanitize_hex_color((string) ($s['header_theme_bg'] ?? '')) ?: '',
'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) : '';
}
/**
@@ -31,36 +36,32 @@ trait FacadeBulk {
*
* @return array
*/
public static function get_category_page_settings(): array {
$settings = self::get_all();
$header_style = sanitize_key((string) ($settings['category_header_style'] ?? 'cover'));
$list_mode = sanitize_key((string) ($settings['category_list_mode'] ?? 'grid'));
$per_page = (int) ($settings['category_per_page'] ?? 12);
$orderby = sanitize_key((string) ($settings['category_orderby'] ?? 'modified'));
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']);
if (!in_array($header_style, ['cover', 'simple', 'none'], true)) {
$header_style = 'cover';
}
if (!in_array($list_mode, ['grid', 'list', 'compact'], true)) {
$list_mode = 'grid';
}
if (!in_array($orderby, ['modified', 'date', 'views', 'comments', 'likes'], true)) {
$orderby = 'modified';
}
return [
'header_style' => $header_style,
'cover_enabled' => !isset($settings['category_cover_enabled']) || !empty($settings['category_cover_enabled']),
'desc_enabled' => !isset($settings['category_desc_enabled']) || !empty($settings['category_desc_enabled']),
'default_cover' => esc_url_raw((string) ($settings['category_default_cover'] ?? '')),
'list_mode' => $list_mode,
'filter_bar' => !isset($settings['category_filter_bar']) || !empty($settings['category_filter_bar']),
'sidebar' => !isset($settings['category_sidebar']) || !empty($settings['category_sidebar']),
'per_page' => max(4, min(48, $per_page)),
'post_count' => !empty($settings['category_post_count']),
'orderby' => $orderby,
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'] : [],
];
}
@@ -71,68 +72,64 @@ trait FacadeBulk {
*
* @return array
*/
public static function get_tag_page_settings(): array {
$settings = self::get_all();
$header_style = sanitize_key((string) ($settings['tag_header_style'] ?? 'simple'));
$list_mode = sanitize_key((string) ($settings['tag_list_mode'] ?? 'grid'));
$per_page = (int) ($settings['tag_per_page'] ?? 12);
$orderby = sanitize_key((string) ($settings['tag_orderby'] ?? 'count'));
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']);
if (!in_array($header_style, ['cover', 'simple', 'none'], true)) {
$header_style = 'simple';
}
if (!in_array($list_mode, ['grid', 'list'], true)) {
$list_mode = 'grid';
}
if (!in_array($orderby, ['count', 'name', 'modified'], true)) {
$orderby = 'count';
}
return [
'header_style' => $header_style,
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' => $list_mode,
'sidebar' => !isset($settings['tag_sidebar']) || !empty($settings['tag_sidebar']),
'per_page' => max(4, min(48, $per_page)),
'post_count' => !empty($settings['tag_post_count']),
'orderby' => $orderby,
'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'] : [],
];
}
/**
* Misc page display settings (404, search, author).
*
* @return array
*/
public static function get_other_page_settings(): array {
$settings = self::get_all();
$message = trim((string) ($settings['page_404_message'] ?? ''));
$search_per_page = max(4, min(48, (int) ($settings['page_search_per_page'] ?? 12)));
$author_per_page = max(4, min(48, (int) ($settings['page_author_posts_per_page'] ?? 12)));
$header_style = sanitize_key((string) ($settings['page_header_style'] ?? '1'));
/** @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 = '1';
}
$header_style = '';
}
return [
'header_style' => $header_style,
'header_cover_img' => esc_url_raw((string) ($settings['page_header_cover_img'] ?? '')),
'page_404_message' => $message !== '' ? $message : __('页面未找到', 'aksrt'),
'page_404_search' => !isset($settings['page_404_search']) || !empty($settings['page_404_search']),
'page_404_popular' => !isset($settings['page_404_popular']) || !empty($settings['page_404_popular']),
'page_404_back' => !isset($settings['page_404_back']) || !empty($settings['page_404_back']),
'page_search_sidebar' => !isset($settings['page_search_sidebar']) || !empty($settings['page_search_sidebar']),
'page_search_per_page' => $search_per_page,
'page_author_cover' => !isset($settings['page_author_cover']) || !empty($settings['page_author_cover']),
'page_author_sidebar' => !isset($settings['page_author_sidebar']) || !empty($settings['page_author_sidebar']),
'page_author_posts_per_page' => $author_per_page,
'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.
*
+69 -131
View File
@@ -9,65 +9,19 @@ defined('ABSPATH') || exit;
class HomeCms {
public static function get_footer_settings(): array {
$defaults = [
'contacts' => [],
'quick_links' => [],
'more_links' => [],
'hot_categories' => 5,
'copyright_text' => '',
'layout_template' => 'template_1',
];
$footer = get_option('aksrt_footer_settings', []);
$merged = array_merge($defaults, is_array($footer) ? $footer : []);
public static function get_footer_settings(): array {
return Settings::read_domain('page_display', 'footer');
}
$s = Settings::get_all();
$bridge_keys = [
'footer_columns', 'footer_copyright', 'footer_icp', 'footer_police',
'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_template(): string {
$template = sanitize_key((string) (self::get_footer_settings()['fcode_template'] ?? 'template_1'));
return $template === 'template_1' ? $template : 'template_1';
}
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'],
'm_s' => !empty($f['footer_t1_m_s']) ? ['pc', 'mobile'] : ['pc'],
'img' => (string) ($f['footer_t1_img'] ?? ''),
'img_dark' => (string) ($f['footer_t1_img_dark'] ?? ''),
'title' => (string) ($f['footer_t1_t'] ?? ''),
@@ -78,7 +32,7 @@ class HomeCms {
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'],
'm_s' => !empty($f['footer_contact_m_s']) ? ['pc', 'mobile'] : ['pc'],
'wechat_img' => (string) ($f['footer_contact_wechat_img'] ?? ''),
'qq' => (string) ($f['footer_contact_qq'] ?? ''),
'weibo' => (string) ($f['footer_contact_weibo'] ?? ''),
@@ -91,26 +45,10 @@ class HomeCms {
public static function get_footer_mini_img_settings(): array {
$f = self::get_footer_settings();
$raw_items = is_array($f['footer_mini_img'] ?? null) ? $f['footer_mini_img'] : [];
$items = [];
foreach ($raw_items as $item) {
if (!is_array($item)) {
continue;
}
$img = (string) ($item['img'] ?? $item['image'] ?? '');
if ($img === '') {
continue;
}
$items[] = [
'img' => $img,
'image' => $img,
'text' => (string) ($item['text'] ?? $item['label'] ?? ''),
'label' => (string) ($item['label'] ?? $item['text'] ?? ''),
];
}
return [
'm_s' => is_array($f['footer_mini_img_m_s'] ?? null) ? $f['footer_mini_img_m_s'] : ['pc', 'mobile'],
'items' => $items,
'm_s' => !empty($f['footer_mini_img_m_s']) ? ['pc', 'mobile'] : ['pc'],
'items' => self::normalize_footer_images($f['footer_mini_img'] ?? []),
'items_2' => self::normalize_footer_images($f['footer_mini_img_2'] ?? []),
];
}
@@ -120,11 +58,11 @@ class HomeCms {
}
public static function get_footer_theme_config(): array {
$s = Settings::get_all();
$s = self::get_footer_settings();
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'] ?? '')) ?: '',
'bg' => self::normalize_palette_hex((string) ($s['footer_theme_bg'] ?? '')),
'color_custom' => sanitize_hex_color((string) ($s['footer_theme_color_custom'] ?? '')) ?: '',
];
}
@@ -149,7 +87,7 @@ class HomeCms {
}
public static function homepage_allowed_sorts(): array {
return ['modified', 'date', 'views', 'likes', 'comments', 'favorites', 'downloads', 'rand'];
return ['modified', 'date', 'views', 'like', 'comment_count', 'favorite', 'rand'];
}
public static function homepage_sort_labels(): array {
@@ -157,16 +95,15 @@ class HomeCms {
'modified' => __('更新', 'aksrt'),
'date' => __('发布', 'aksrt'),
'views' => __('浏览', 'aksrt'),
'likes' => __('点赞', 'aksrt'),
'comments' => __('评论', 'aksrt'),
'favorites' => __('收藏', 'aksrt'),
'downloads' => __('下载', 'aksrt'),
'like' => __('点赞', 'aksrt'),
'comment_count' => __('评论', 'aksrt'),
'favorite' => __('收藏', 'aksrt'),
'rand' => __('随机', 'aksrt'),
];
}
public static function get_homepage_fixed_settings(): array {
$s = Settings::get_all();
$s = Settings::read_domain('page_display', 'homepage');
$allowed_sorts = self::homepage_allowed_sorts();
// Canonical Zibll-aligned primary list contract.
@@ -176,24 +113,21 @@ class HomeCms {
$orderby_option = isset($s['home_list1_orderby_option']) && is_array($s['home_list1_orderby_option'])
? $s['home_list1_orderby_option']
: [];
$default_sort = sanitize_key((string) ($orderby_option['orderby'] ?? 'date'));
$sort_options_raw = $orderby_option['lists'] ?? [];
if (!is_array($sort_options_raw)) {
$sort_options_raw = [];
}
$sort_options = self::normalize_sort_options($sort_options_raw);
$default_sort = sanitize_key((string) ($sort_options[0] ?? 'modified'));
if (!in_array($default_sort, $allowed_sorts, true)) {
$default_sort = 'date';
$default_sort = 'modified';
}
$sort_options_raw = $orderby_option['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 = sanitize_text_field((string) ($s['index_list_title'] ?? ''));
if ($list_title === '') {
$list_title = __('最新发布', 'aksrt');
}
$list_title = wp_kses_post((string) ($s['index_list_title'] ?? ''));
$exclude_posts = self::normalize_int_array($s['home_exclude_posts'] ?? []);
$exclude_cats = self::normalize_int_array($s['home_exclude_cats'] ?? []);
@@ -203,22 +137,11 @@ class HomeCms {
// 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,
],
'home_list1_orderby_option' => ['lists' => $sort_options, 'dropdown' => !empty($orderby_option['dropdown'])],
'index_list_title' => $list_title,
'home_exclude_posts' => $exclude_posts,
'home_exclude_cats' => $exclude_cats,
'home_lists' => self::normalize_homepage_tabs($tabs_raw),
'homepage_sidebar_mini_enabled' => !isset($s['homepage_sidebar_mini_enabled']) || !empty($s['homepage_sidebar_mini_enabled']),
'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']),
'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_banner_enabled' => !isset($s['homepage_module_banner_enabled']) || !empty($s['homepage_module_banner_enabled']),
'home_lists' => self::normalize_homepage_tabs($tabs_raw),
];
return $settings;
@@ -238,29 +161,26 @@ class HomeCms {
return $settings['home_lists'];
}
/** @return array<int, array{term_id:int,title:string,orderby:string,enabled:bool}> */
/** @return array<int, array{term_id:int,title:string,orderby:string}> */
public static function home_lists(): array {
return self::homepage_tabs();
}
public static function homepage_sidebar_mini_enabled(): bool {
$settings = self::get_homepage_fixed_settings();
return !empty($settings['homepage_sidebar_mini_enabled']);
return true;
}
public static function homepage_default_sort(): string {
$settings = self::get_homepage_fixed_settings();
return $settings['home_list1_orderby_option']['orderby'] ?? 'date';
return $settings['home_list1_orderby_option']['lists'][0] ?? 'modified';
}
public static function homepage_sort_ajax_enabled(): bool {
$settings = self::get_homepage_fixed_settings();
return !empty($settings['homepage_sort_ajax_enabled']);
return true;
}
public static function homepage_sticky_tabs_enabled(): bool {
$settings = self::get_homepage_fixed_settings();
return !empty($settings['homepage_sticky_tabs_enabled']);
return true;
}
public static function home_posts_list_enabled(): bool {
@@ -278,14 +198,14 @@ class HomeCms {
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_options(): array {
$settings = self::get_homepage_fixed_settings();
return $settings['home_list1_orderby_option']['lists'] ?? ['modified', 'views', 'like', 'comment_count'];
}
public static function home_list_sort_dropdown(): bool {
$settings = self::get_homepage_fixed_settings();
return !empty($settings['home_list_sort_dropdown']);
return !empty($settings['home_list1_orderby_option']['dropdown']);
}
public static function home_exclude_post_ids(): array {
@@ -299,13 +219,7 @@ class HomeCms {
}
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'];
return 6;
}
public static function get_paid_content_settings(): array {
@@ -361,8 +275,8 @@ class HomeCms {
}
}
if (empty($result)) {
$result = ['modified', 'date', 'views', 'likes', 'comments'];
if (empty($result)) {
$result = ['modified', 'views', 'like', 'comment_count'];
}
return $result;
@@ -389,22 +303,46 @@ class HomeCms {
continue;
}
$orderby = sanitize_key($tab['orderby'] ?? 'date');
$orderby = sanitize_key($tab['orderby'] ?? 'modified');
if (!in_array($orderby, $allowed_orderby, true)) {
$orderby = 'date';
$orderby = 'modified';
}
$tabs[] = [
'term_id' => $term_id,
'title' => sanitize_text_field($tab['title'] ?? ''),
'title' => wp_kses_post((string) ($tab['title'] ?? '')),
'orderby' => $orderby,
'enabled' => !empty($tab['enabled']),
];
}
return $tabs;
}
private static function normalize_footer_images($raw_items): array {
if (!is_array($raw_items)) {
return [];
}
$items = [];
foreach ($raw_items as $item) {
if (!is_array($item) || empty($item['image'])) {
continue;
}
$items[] = [
'image' => (string) $item['image'],
'text' => (string) ($item['text'] ?? ''),
'link' => is_array($item['link'] ?? null) ? $item['link'] : [],
];
}
return $items;
}
private static function normalize_palette_hex(string $value): string {
$value = ltrim(trim($value), '#');
return preg_match('/^[0-9a-f]{6}$/i', $value) ? '#' . strtolower($value) : '';
}
private static function parse_slug_list(string $raw, array $fallback = []): array {
$items = preg_split('/[\s,]+/', $raw, -1, PREG_SPLIT_NO_EMPTY);
$normalized = [];
+1 -25
View File
@@ -48,7 +48,7 @@ trait HomepageReader {
/**
* Structured homepage tabs.
*
* @return array<int, array{term_id:int, title:string, orderby:string, enabled:bool}>
* @return array<int, array{term_id:int, title:string, orderby:string}>
*/
public static function homepage_tabs(): array {
return HomeCms::homepage_tabs();
@@ -144,30 +144,6 @@ trait HomepageReader {
return HomeCms::homepage_tab_posts_per_page();
}
/**
* Maximum number of category tabs to display.
*/
public static function homepage_tab_limit(): int {
return HomeCms::homepage_tab_limit();
}
/**
* 获取顶部组件图标卡片配置
* @return array
*/
public static function homepage_module_banner_enabled(): bool {
return DisplayRuntime::homepage_module_banner_enabled();
}
/**
* Global slider configuration shared by Hero and Banner.
*
* @return array<string,mixed>
*/
public static function get_slider_config(): array {
return DisplayRuntime::get_slider_config();
}
/**
* 获取页脚配色配置
*/
+1 -59
View File
@@ -38,13 +38,11 @@ class Settings {
'aksrt_oauth',
'aksrt_captcha_config',
'aksrt_moderation_config',
'aksrt_footer_settings',
'aksrt_footer_tabbar',
'aksrt_floating_buttons',
'aksrt_credit_settings',
'aksrt_notification_settings',
'aksrt_friend_links',
'aksrt_banners',
'aksrt_category_recommend',
'aksrt_identity_secrets',
];
@@ -719,27 +717,6 @@ class Settings {
/** 获取Banner列表 */
public static function get_banners(string $position = ''): array {
return DisplayRuntime::get_banners($position);
}
/** 保存Banner */
public static function save_banner(array $data): int {
return DisplayRuntime::save_banner($data);
}
/** 删除Banner */
public static function delete_banner(string $id): void {
DisplayRuntime::delete_banner($id);
}
/** 获取友链列表 */
public static function get_friend_links(): array {
return DisplayRuntime::get_friend_links();
@@ -841,7 +818,7 @@ class Settings {
// ============================================
/**
* 获取底部信息完整配置(统一 aksrt_footer_settings + aksrt_settings page-display footer 字段)
* 获取页面&显示中的页脚配置。
* @return array
*/
public static function get_footer_settings(): array {
@@ -850,41 +827,6 @@ class Settings {
/** 获取联系图标列表(仅返回启用的) */
public static function get_footer_contacts(): array {
return HomeCms::get_footer_contacts();
}
/** 获取快速链接列表(仅返回启用的,按排序) */
public static function get_quick_links(): array {
return HomeCms::get_quick_links();
}
/** 获取更多链接列表(仅返回启用的,按排序) */
public static function get_more_links(): array {
return HomeCms::get_more_links();
}
/** 获取热门分类显示数量 */
public static function get_hot_categories_count(): int {
return HomeCms::get_hot_categories_count();
}
/** 获取版权文字 */
public static function get_copyright_text(): string {
return HomeCms::get_copyright_text();
}
/**
* 获取页脚品牌列(第一列)配置
* @return array {m_s, img, img_dark, title, custom_code}
+4 -4
View File
@@ -101,14 +101,14 @@ class ThemeSearch {
}
public static function search_custom_key(): array {
$raw = Settings::get_value('search_custom_key', ['title', 'content', 'excerpt', 'post_tag', 'forum_topic', 'shop_cat', 'shop_discount']);
$raw = Settings::get_value('search_custom_key', ['title', 'content', 'excerpt', 'category', 'post_tag']);
if (is_array($raw)) {
$items = $raw;
} else {
$items = preg_split('/[,,\s]+/', (string) $raw) ?: [];
}
$items = array_map(static fn($k) => trim(sanitize_key((string) $k)), $items);
$valid = ['title', 'content', 'excerpt', 'category', 'post_tag', 'topics', 'coment', 'user', 'forum_topic', 'forum_tag', 'shop_cat', 'shop_tag', 'shop_discount'];
$valid = ['title', 'content', 'excerpt', 'category', 'post_tag', 'coment', 'user'];
return array_values(array_intersect(array_filter(array_unique($items)), $valid));
}
@@ -175,7 +175,7 @@ class ThemeSearch {
$terms = [(string) $query->get('s')];
}
$groups = [];
$taxonomies = ['post_tag', 'category', 'topics', 'forum_tag', 'forum_topic', 'shop_tag', 'shop_cat', 'shop_discount'];
$taxonomies = ['post_tag', 'category'];
foreach ($terms as $term) {
$like = (!empty($query->query_vars['exact']) ? '' : '%') . $wpdb->esc_like((string) $term) . (!empty($query->query_vars['exact']) ? '' : '%');
$parts = [];
@@ -212,7 +212,7 @@ class ThemeSearch {
if (in_array('user', $keys, true)) {
$join .= " LEFT JOIN {$wpdb->users} AS aksrt_search_users ON ({$wpdb->posts}.post_author = aksrt_search_users.ID)";
}
if (array_intersect(['post_tag', 'category', 'topics', 'forum_tag', 'forum_topic', 'shop_tag', 'shop_cat', 'shop_discount'], $keys)) {
if (array_intersect(['post_tag', 'category'], $keys)) {
$join .= " LEFT JOIN {$wpdb->term_relationships} AS aksrt_search_tr ON ({$wpdb->posts}.ID = aksrt_search_tr.object_id)";
$join .= " LEFT JOIN {$wpdb->term_taxonomy} AS aksrt_search_tt ON (aksrt_search_tr.term_taxonomy_id = aksrt_search_tt.term_taxonomy_id)";
$join .= " LEFT JOIN {$wpdb->terms} AS aksrt_search_terms ON (aksrt_search_tt.term_id = aksrt_search_terms.term_id)";
+39 -51
View File
@@ -15,65 +15,53 @@ class UserRuntime {
* @return array
*/
public static function get_user_home_settings(): array {
$settings = Settings::get_all();
$allowed_tabs = ['posts', 'comments', 'favorites', 'credits', 'follow'];
$parse_csv = function (string $key, string $fallback) use ($settings, $allowed_tabs): array {
$raw = $settings[$key] ?? $fallback;
$items = is_array($raw) ? $raw : preg_split('/[\s,]+/', (string) $raw, -1, PREG_SPLIT_NO_EMPTY);
$clean = [];
foreach ((array) $items as $v) {
$v = sanitize_key((string) $v);
if (in_array($v, $allowed_tabs, true) && !in_array($v, $clean, true)) {
$clean[] = $v;
}
}
return $clean;
};
// Public profile tabs supported by this theme.
$normalized_tabs = $parse_csv('user_home_tabs', 'posts,favorites,comments,follow');
if (empty($normalized_tabs)) {
$normalized_tabs = ['posts', 'favorites', 'comments', 'follow'];
}
$raw_order = $parse_csv('user_home_tabs_order', '');
$ordered = [];
foreach ($raw_order as $tab) {
if (in_array($tab, $normalized_tabs, true)) {
$ordered[] = $tab;
}
}
foreach ($normalized_tabs as $tab) {
if (!in_array($tab, $ordered, true)) {
$ordered[] = $tab;
}
}
$pc_hide = $parse_csv('user_home_tabs_pc_hide', '');
$mobile_hide = $parse_csv('user_home_tabs_mobile_hide', '');
$settings = Settings::read_domain('page_display', 'user-home');
$tab_options = is_array($settings['author_main_tab_opt'] ?? null)
? $settings['author_main_tab_opt']
: [
'post' => ['pc_s' => true, 'm_s' => true],
'favorite' => ['pc_s' => true, 'm_s' => true],
'comment' => ['pc_s' => true, 'm_s' => true],
'follow' => ['pc_s' => true, 'm_s' => true],
];
$map = ['post' => 'posts', 'favorite' => 'favorites', 'comment' => 'comments', 'follow' => 'follow'];
$ordered = [];
$pc_hide = [];
$mobile_hide = [];
foreach ($tab_options as $key => $option) {
$key = sanitize_key((string) $key);
if (!isset($map[$key]) || !is_array($option)) {
continue;
}
$tab = $map[$key];
$ordered[] = $tab;
if (empty($option['pc_s'])) {
$pc_hide[] = $tab;
}
if (empty($option['m_s'])) {
$mobile_hide[] = $tab;
}
}
return [
'route_identifier' => (($settings['user_home_route_identifier'] ?? 'nicename') === 'uid') ? 'uid' : 'nicename',
'tabs' => $normalized_tabs,
'route_identifier' => 'nicename',
'tabs' => $ordered,
'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.
'cover' => true,
'follow' => true,
'posts_per_page' => max(1, (int) get_option('posts_per_page', 10)),
'avatar' => true,
'name' => true,
'desc' => true,
'stats' => false,
'social' => !isset($settings['user_home_social']) || !empty($settings['user_home_social']),
'social' => true,
'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']),
'message' => true,
'private' => true,
'paging_ajax' => true,
];
}