refactor: flatten src/AKSRT → src (drop theme-identifier dir)
Move all domain folders from src/AKSRT/{Domain} to src/{Domain}; remap
Composer PSR-4 "AKSRT\\": "src/"; update audit script + README + ADR
paths; remove dead tools/build-psr4-map.php (scanned deleted inc/classes).
This commit is contained in:
@@ -0,0 +1,285 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
namespace AKSRT\Settings;
|
||||
|
||||
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', []) ?: [];
|
||||
|
||||
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 = Settings::get_all();
|
||||
return !empty($settings['header_components_search_enabled']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hero 搜索组件详细配置(PC/移动分别 + 子选项)
|
||||
*
|
||||
* @return array{pc:bool,mobile:bool,show:bool,show_keywords:bool,popular_limit:int,show_input_cat:bool,show_type:bool,keywords:string[],categories:array,type_options:array,before_html:string,after_html:string}
|
||||
*/
|
||||
public static function get_header_components_search_config(): array {
|
||||
$settings = 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(50, (int) ($settings['header_components_search_popular_limit'] ?? 6)));
|
||||
$show_cat = !empty($settings['header_components_search_show_input_cat']);
|
||||
$show_type = !empty($settings['header_components_search_show_type']);
|
||||
$in_cat = sanitize_text_field((string) ($settings['header_components_search_in_cat'] ?? ''));
|
||||
$in_type = sanitize_key((string) ($settings['header_components_search_in_type'] ?? 'post')) ?: 'post';
|
||||
$more_cats = isset($settings['header_components_search_more_cats'])
|
||||
? array_values(array_filter(array_map('absint', (array) $settings['header_components_search_more_cats'])))
|
||||
: [];
|
||||
|
||||
// Mobile: hide hot keywords (zibll).
|
||||
if ($is_mobile) {
|
||||
$show_kw = false;
|
||||
}
|
||||
|
||||
$keywords = [];
|
||||
if ($show && $show_kw) {
|
||||
if (function_exists('aksrt_get_search_hot_keywords')) {
|
||||
$keywords = (array) aksrt_get_search_hot_keywords();
|
||||
} else {
|
||||
$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', array_values($keywords)), 0, $kw_limit);
|
||||
}
|
||||
|
||||
$categories = [];
|
||||
if ($show && $show_cat) {
|
||||
$cat_args = ['hide_empty' => true, 'number' => 50];
|
||||
if ($more_cats) {
|
||||
$cat_args['include'] = $more_cats;
|
||||
$cat_args['orderby'] = 'include';
|
||||
$cat_args['hide_empty'] = false;
|
||||
}
|
||||
$cats = get_categories($cat_args);
|
||||
foreach ($cats as $cat) {
|
||||
$categories[] = ['id' => (int) $cat->term_id, 'name' => (string) $cat->name];
|
||||
}
|
||||
}
|
||||
|
||||
$type_options = [];
|
||||
if ($show && $show_type) {
|
||||
$types = Settings::get_search_content_types();
|
||||
$labels = [
|
||||
'post' => __('文章', 'aksrt'),
|
||||
'user' => __('用户', 'aksrt'),
|
||||
'page' => __('页面', 'aksrt'),
|
||||
];
|
||||
$enabled = $types['enabled'] ?? $types;
|
||||
if (is_array($enabled)) {
|
||||
foreach ($enabled as $type_key => $type_value) {
|
||||
// Support both map[key=>bool] and list of keys.
|
||||
if (is_int($type_key) && is_string($type_value)) {
|
||||
$k = $type_value;
|
||||
$on = true;
|
||||
} else {
|
||||
$k = (string) $type_key;
|
||||
$on = (bool) $type_value;
|
||||
}
|
||||
if (!$on || $k === '') {
|
||||
continue;
|
||||
}
|
||||
$type_options[] = [
|
||||
'key' => $k,
|
||||
'label' => $labels[$k] ?? $k,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$before_html = isset($settings['header_components_search_before_html'])
|
||||
? (string) $settings['header_components_search_before_html']
|
||||
: '';
|
||||
$after_html = isset($settings['header_components_search_after_html'])
|
||||
? (string) $settings['header_components_search_after_html']
|
||||
: '';
|
||||
|
||||
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,
|
||||
'in_cat' => $in_cat,
|
||||
'in_type' => $in_type,
|
||||
'more_cats' => $more_cats,
|
||||
'keywords' => $keywords,
|
||||
'categories' => $categories,
|
||||
'type_options' => $type_options,
|
||||
'before_html' => $before_html,
|
||||
'after_html' => $after_html,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public static function header_components_cards_enabled(): bool {
|
||||
$settings = Settings::get_all();
|
||||
return !empty($settings['header_components_cards_enabled']);
|
||||
}
|
||||
|
||||
public static function homepage_module_hero_enabled(): bool {
|
||||
$settings = 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 = 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 = $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 = 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 = 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 = Settings::get_all();
|
||||
return !empty($settings['header_components_card_bg']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全局背景设置
|
||||
*/
|
||||
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'] ?? '')),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user