fix(homepage): unify runtime rendering contract
This commit is contained in:
@@ -310,9 +310,9 @@ class GlobalController extends ControllerBase {
|
||||
'overrides' => $overrides,
|
||||
])
|
||||
: array_merge(['mode' => ($mode !== '' ? $mode : 'list'), 'context' => 'home'], $overrides);
|
||||
$render_config['skip_wrapper'] = true;
|
||||
$html = aksrt_render_post_list($query, $render_config, false);
|
||||
} elseif ($query->have_posts()) {
|
||||
$html = '<div class="posts-row aksrt-homepage__posts" data-view="' . esc_attr($mode) . '">';
|
||||
while ($query->have_posts()) {
|
||||
$query->the_post();
|
||||
if (function_exists('aksrt_homepage_render_post_card')) {
|
||||
@@ -321,7 +321,6 @@ class GlobalController extends ControllerBase {
|
||||
$html .= ob_get_clean();
|
||||
}
|
||||
}
|
||||
$html .= '</div>';
|
||||
wp_reset_postdata();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,17 +30,13 @@ trait HomepageSettingsRest {
|
||||
$allowed_sorts = \AKSRT\Settings\HomeCms::homepage_allowed_sorts();
|
||||
$settings = [];
|
||||
|
||||
// --- Zibll main list contract ---
|
||||
if (array_key_exists('home_posts_list_s', $params) || array_key_exists('home_posts_list_enabled', $params)) {
|
||||
$settings['home_posts_list_s'] = array_key_exists('home_posts_list_s', $params)
|
||||
? !empty($params['home_posts_list_s'])
|
||||
: !empty($params['home_posts_list_enabled']);
|
||||
// --- Canonical Zibll main list contract ---
|
||||
if (array_key_exists('home_posts_list_s', $params)) {
|
||||
$settings['home_posts_list_s'] = !empty($params['home_posts_list_s']);
|
||||
}
|
||||
|
||||
if (array_key_exists('home_list1_orderby_s', $params) || array_key_exists('home_list_sort_enabled', $params)) {
|
||||
$settings['home_list1_orderby_s'] = array_key_exists('home_list1_orderby_s', $params)
|
||||
? !empty($params['home_list1_orderby_s'])
|
||||
: !empty($params['home_list_sort_enabled']);
|
||||
if (array_key_exists('home_list1_orderby_s', $params)) {
|
||||
$settings['home_list1_orderby_s'] = !empty($params['home_list1_orderby_s']);
|
||||
}
|
||||
|
||||
if (isset($params['home_list1_orderby_option']) && is_array($params['home_list1_orderby_option'])) {
|
||||
@@ -48,45 +44,22 @@ trait HomepageSettingsRest {
|
||||
$params['home_list1_orderby_option'],
|
||||
$allowed_sorts
|
||||
);
|
||||
} elseif (isset($params['home_list_sort_options']) && is_array($params['home_list_sort_options'])) {
|
||||
$settings['home_list1_orderby_option'] = $this->sanitize_home_list1_orderby_option(
|
||||
[
|
||||
'orderby' => $params['homepage_default_sort'] ?? 'modified',
|
||||
'options' => $params['home_list_sort_options'],
|
||||
],
|
||||
$allowed_sorts
|
||||
);
|
||||
} elseif (isset($params['homepage_default_sort'])) {
|
||||
$default = sanitize_key((string) $params['homepage_default_sort']);
|
||||
if (!in_array($default, $allowed_sorts, true)) {
|
||||
$default = 'modified';
|
||||
}
|
||||
$settings['home_list1_orderby_option'] = [
|
||||
'orderby' => $default,
|
||||
'options' => array_values(array_unique(array_merge([$default], ['date', 'views', 'likes', 'comments']))),
|
||||
];
|
||||
}
|
||||
|
||||
if (array_key_exists('index_list_title', $params) || array_key_exists('home_list_title', $params)) {
|
||||
$title = array_key_exists('index_list_title', $params)
|
||||
? (string) $params['index_list_title']
|
||||
: (string) $params['home_list_title'];
|
||||
$settings['index_list_title'] = sanitize_text_field($title);
|
||||
if (array_key_exists('index_list_title', $params)) {
|
||||
$settings['index_list_title'] = sanitize_text_field((string) $params['index_list_title']);
|
||||
}
|
||||
|
||||
if (isset($params['home_exclude_posts']) || isset($params['home_exclude_post_ids'])) {
|
||||
$raw = $params['home_exclude_posts'] ?? $params['home_exclude_post_ids'];
|
||||
$settings['home_exclude_posts'] = $this->sanitize_id_list($raw);
|
||||
if (array_key_exists('home_exclude_posts', $params)) {
|
||||
$settings['home_exclude_posts'] = $this->sanitize_id_list($params['home_exclude_posts']);
|
||||
}
|
||||
|
||||
if (isset($params['home_exclude_cats']) || isset($params['home_exclude_category_ids'])) {
|
||||
$raw = $params['home_exclude_cats'] ?? $params['home_exclude_category_ids'];
|
||||
$settings['home_exclude_cats'] = $this->sanitize_id_list($raw);
|
||||
if (array_key_exists('home_exclude_cats', $params)) {
|
||||
$settings['home_exclude_cats'] = $this->sanitize_id_list($params['home_exclude_cats']);
|
||||
}
|
||||
|
||||
if (isset($params['home_lists']) || isset($params['homepage_tabs'])) {
|
||||
$raw_tabs = $params['home_lists'] ?? $params['homepage_tabs'];
|
||||
$settings['home_lists'] = $this->sanitize_home_lists($raw_tabs, $allowed_sorts);
|
||||
if (array_key_exists('home_lists', $params)) {
|
||||
$settings['home_lists'] = $this->sanitize_home_lists($params['home_lists'], $allowed_sorts);
|
||||
}
|
||||
|
||||
// --- AKSRT presentation extras (optional, not Zibll dual-write) ---
|
||||
@@ -140,7 +113,7 @@ trait HomepageSettingsRest {
|
||||
$current[$key] = $value;
|
||||
}
|
||||
|
||||
// Drop superseded AKSRT-only keys when canonical Zibll keys are written.
|
||||
// Canonical writes also remove superseded aliases from persisted settings.
|
||||
$superseded = [
|
||||
'home_posts_list_enabled',
|
||||
'home_list_sort_enabled',
|
||||
@@ -152,38 +125,7 @@ trait HomepageSettingsRest {
|
||||
'homepage_default_sort',
|
||||
];
|
||||
foreach ($superseded as $dead_key) {
|
||||
if (array_key_exists($dead_key, $current) && (
|
||||
array_key_exists('home_posts_list_s', $settings)
|
||||
|| array_key_exists('home_list1_orderby_s', $settings)
|
||||
|| array_key_exists('home_list1_orderby_option', $settings)
|
||||
|| array_key_exists('index_list_title', $settings)
|
||||
|| array_key_exists('home_exclude_posts', $settings)
|
||||
|| array_key_exists('home_exclude_cats', $settings)
|
||||
|| array_key_exists('home_lists', $settings)
|
||||
)) {
|
||||
// Only strip keys we actually replaced in this request.
|
||||
}
|
||||
}
|
||||
if (array_key_exists('home_posts_list_s', $settings)) {
|
||||
unset($current['home_posts_list_enabled']);
|
||||
}
|
||||
if (array_key_exists('home_list1_orderby_s', $settings)) {
|
||||
unset($current['home_list_sort_enabled']);
|
||||
}
|
||||
if (array_key_exists('home_list1_orderby_option', $settings)) {
|
||||
unset($current['home_list_sort_options'], $current['homepage_default_sort']);
|
||||
}
|
||||
if (array_key_exists('index_list_title', $settings)) {
|
||||
unset($current['home_list_title']);
|
||||
}
|
||||
if (array_key_exists('home_exclude_posts', $settings)) {
|
||||
unset($current['home_exclude_post_ids']);
|
||||
}
|
||||
if (array_key_exists('home_exclude_cats', $settings)) {
|
||||
unset($current['home_exclude_category_ids']);
|
||||
}
|
||||
if (array_key_exists('home_lists', $settings)) {
|
||||
unset($current['homepage_tabs']);
|
||||
unset($current[$dead_key]);
|
||||
}
|
||||
|
||||
update_option($option_key, $current);
|
||||
|
||||
@@ -1036,10 +1036,17 @@ $hmb_js = get_template_directory() . '/assets/js/header-newadd.js';
|
||||
$enqueue_module('header-components'); // header-slider / hero
|
||||
$enqueue_module('post-card');
|
||||
$homepage_css_path = get_template_directory() . '/assets/css/frontend/homepage-fixed.css';
|
||||
$homepage_style_deps = file_exists($frontend_bundle)
|
||||
? ['aksrt-frontend-bundle', 'aksrt-header-components', 'aksrt-post-card']
|
||||
: ['aksrt-zibll-compat-vars', 'aksrt-layout', 'aksrt-widgets', 'aksrt-header-components', 'aksrt-post-card'];
|
||||
$homepage_style_deps = array_values(array_filter(
|
||||
$homepage_style_deps,
|
||||
static fn(string $handle): bool => wp_style_is($handle, 'registered')
|
||||
));
|
||||
wp_enqueue_style(
|
||||
'aksrt-homepage-fixed',
|
||||
$base_uri . '/assets/css/frontend/homepage-fixed.css',
|
||||
['aksrt-zibll-compat-vars', 'aksrt-layout', 'aksrt-widgets', 'aksrt-post-card'],
|
||||
$homepage_style_deps,
|
||||
file_exists($homepage_css_path) ? (string) filemtime($homepage_css_path) : $version
|
||||
);
|
||||
}
|
||||
|
||||
@@ -173,24 +173,18 @@ class HomeCms {
|
||||
$s = Settings::get_all();
|
||||
$allowed_sorts = self::homepage_allowed_sorts();
|
||||
|
||||
// Zibll-aligned primary list contract.
|
||||
$main_list_enabled = array_key_exists('home_posts_list_s', $s)
|
||||
? !empty($s['home_posts_list_s'])
|
||||
: (!isset($s['home_posts_list_enabled']) || !empty($s['home_posts_list_enabled']));
|
||||
// Canonical Zibll-aligned primary list contract.
|
||||
$main_list_enabled = !array_key_exists('home_posts_list_s', $s) || !empty($s['home_posts_list_s']);
|
||||
$sort_bar_enabled = !array_key_exists('home_list1_orderby_s', $s) || !empty($s['home_list1_orderby_s']);
|
||||
|
||||
$sort_bar_enabled = array_key_exists('home_list1_orderby_s', $s)
|
||||
? !empty($s['home_list1_orderby_s'])
|
||||
: (!isset($s['home_list_sort_enabled']) || !empty($s['home_list_sort_enabled']));
|
||||
|
||||
$orderby_option = [];
|
||||
if (isset($s['home_list1_orderby_option']) && is_array($s['home_list1_orderby_option'])) {
|
||||
$orderby_option = $s['home_list1_orderby_option'];
|
||||
}
|
||||
$default_sort = sanitize_key((string) ($orderby_option['orderby'] ?? $s['homepage_default_sort'] ?? 'date'));
|
||||
$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'));
|
||||
if (!in_array($default_sort, $allowed_sorts, true)) {
|
||||
$default_sort = 'date';
|
||||
}
|
||||
$sort_options_raw = $orderby_option['options'] ?? $s['home_list_sort_options'] ?? [];
|
||||
$sort_options_raw = $orderby_option['options'] ?? [];
|
||||
if (!is_array($sort_options_raw)) {
|
||||
$sort_options_raw = [];
|
||||
}
|
||||
@@ -200,29 +194,14 @@ class HomeCms {
|
||||
$sort_options = array_values(array_unique($sort_options));
|
||||
}
|
||||
|
||||
$list_title = '';
|
||||
if (array_key_exists('index_list_title', $s)) {
|
||||
$list_title = sanitize_text_field((string) $s['index_list_title']);
|
||||
} elseif (array_key_exists('home_list_title', $s)) {
|
||||
$list_title = sanitize_text_field((string) $s['home_list_title']);
|
||||
}
|
||||
$list_title = sanitize_text_field((string) ($s['index_list_title'] ?? ''));
|
||||
if ($list_title === '') {
|
||||
$list_title = __('最新发布', 'aksrt');
|
||||
}
|
||||
|
||||
$exclude_posts = self::normalize_int_array(
|
||||
$s['home_exclude_posts'] ?? $s['home_exclude_post_ids'] ?? []
|
||||
);
|
||||
$exclude_cats = self::normalize_int_array(
|
||||
$s['home_exclude_cats'] ?? $s['home_exclude_category_ids'] ?? []
|
||||
);
|
||||
|
||||
$tabs_raw = [];
|
||||
if (isset($s['home_lists']) && is_array($s['home_lists'])) {
|
||||
$tabs_raw = $s['home_lists'];
|
||||
} elseif (isset($s['homepage_tabs']) && is_array($s['homepage_tabs'])) {
|
||||
$tabs_raw = $s['homepage_tabs'];
|
||||
}
|
||||
$exclude_posts = self::normalize_int_array($s['home_exclude_posts'] ?? []);
|
||||
$exclude_cats = self::normalize_int_array($s['home_exclude_cats'] ?? []);
|
||||
$tabs_raw = isset($s['home_lists']) && is_array($s['home_lists']) ? $s['home_lists'] : [];
|
||||
|
||||
$settings = [
|
||||
// Canonical Zibll keys.
|
||||
@@ -237,16 +216,6 @@ class HomeCms {
|
||||
'home_exclude_cats' => $exclude_cats,
|
||||
'home_lists' => self::normalize_homepage_tabs($tabs_raw),
|
||||
|
||||
// Convenience aliases for existing PHP/Vue callers during cutover of this slice.
|
||||
'home_posts_list_enabled' => $main_list_enabled,
|
||||
'home_list_sort_enabled' => $sort_bar_enabled,
|
||||
'homepage_default_sort' => $default_sort,
|
||||
'home_list_sort_options' => $sort_options,
|
||||
'home_list_title' => $list_title,
|
||||
'home_exclude_post_ids' => $exclude_posts,
|
||||
'home_exclude_category_ids' => $exclude_cats,
|
||||
'homepage_tabs' => self::normalize_homepage_tabs($tabs_raw),
|
||||
|
||||
// AKSRT presentation extras.
|
||||
'homepage_card_style' => isset($s['homepage_card_style']) ? sanitize_key((string) $s['homepage_card_style']) : 'default',
|
||||
'homepage_multi_thumb_enabled' => !empty($s['homepage_multi_thumb_enabled']),
|
||||
|
||||
Reference in New Issue
Block a user