feat(admin): rebuild page display settings
This commit is contained in:
+69
-131
@@ -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 = [];
|
||||
|
||||
Reference in New Issue
Block a user