Wire settings-driven sidebar visibility and body site-layout classes, replace content-layout CSS grid with Zibll float geometry, move sidebar DOM to content-wrap sibling across single/archive/page/home, and add post meta show_layout overrides.
1021 lines
32 KiB
PHP
1021 lines
32 KiB
PHP
<?php
|
|
/**
|
|
* AKSRT Fixed Homepage Helpers
|
|
*
|
|
* Rebuilds the homepage around a fixed Zibll-like skeleton instead of the
|
|
* old freeform home modules canvas.
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
if (!function_exists('aksrt_is_fixed_homepage_request')) {
|
|
/**
|
|
* Whether the current request should use the fixed homepage layout.
|
|
*/
|
|
function aksrt_is_fixed_homepage_request(): bool {
|
|
if (is_admin()) {
|
|
return false;
|
|
}
|
|
|
|
return is_front_page() || is_home();
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_get_current_page')) {
|
|
/**
|
|
* Resolve the current homepage page number for both blog and static-front
|
|
* pagination contexts.
|
|
*/
|
|
function aksrt_homepage_get_current_page(): int {
|
|
return max(1, (int) get_query_var('paged'), (int) get_query_var('page'));
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_get_post_types')) {
|
|
/**
|
|
* Homepage latest feed post types.
|
|
* Resources are ordinary posts with meta — always post.
|
|
*
|
|
* @return string[]
|
|
*/
|
|
function aksrt_homepage_get_post_types(): array {
|
|
return ['post'];
|
|
}
|
|
}
|
|
|
|
|
|
if (!function_exists('aksrt_homepage_get_tab_terms')) {
|
|
/**
|
|
* Homepage category tabs with full config.
|
|
*
|
|
* Returns enabled tabs in config order, each with 'term', 'title', 'orderby'.
|
|
* Uses homepage_tab_limit from settings.
|
|
*
|
|
* @return array<int, array{term:WP_Term, title:string, orderby:string, term_id:int}>
|
|
*/
|
|
function aksrt_homepage_get_tab_configs(): array {
|
|
$limit = class_exists('AKSRT_Settings')
|
|
? AKSRT_Settings::homepage_tab_limit()
|
|
: 4;
|
|
|
|
if (!class_exists('AKSRT_Settings')) {
|
|
return [];
|
|
}
|
|
|
|
$structured_tabs = AKSRT_Settings::homepage_tabs();
|
|
if (empty($structured_tabs)) {
|
|
return [];
|
|
}
|
|
|
|
$excluded_cat_ids = array_flip(AKSRT_Settings::home_exclude_category_ids());
|
|
$configs = [];
|
|
|
|
foreach ($structured_tabs as $tab) {
|
|
if (empty($tab['enabled']) || $tab['term_id'] <= 0) {
|
|
continue;
|
|
}
|
|
if (count($configs) >= $limit) {
|
|
break;
|
|
}
|
|
if (isset($excluded_cat_ids[$tab['term_id']])) {
|
|
continue;
|
|
}
|
|
|
|
$term = get_term($tab['term_id']);
|
|
if (!$term || is_wp_error($term)) {
|
|
continue;
|
|
}
|
|
if (!in_array($term->taxonomy, ['category', 'topics'], true)) {
|
|
continue;
|
|
}
|
|
|
|
$configs[] = [
|
|
'term' => $term,
|
|
'term_id' => (int) $tab['term_id'],
|
|
'title' => $tab['title'] !== '' ? $tab['title'] : $term->name,
|
|
'orderby' => $tab['orderby'] ?: 'date',
|
|
];
|
|
}
|
|
|
|
return $configs;
|
|
}
|
|
|
|
/**
|
|
* Homepage category tabs — returns WP_Term objects for backward compat.
|
|
*
|
|
* @param int $limit Unused, reads from settings.
|
|
* @return WP_Term[]
|
|
*/
|
|
function aksrt_homepage_get_tab_terms(int $limit = 4): array {
|
|
$configs = aksrt_homepage_get_tab_configs();
|
|
return array_column($configs, 'term');
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_get_tab_posts_per_page')) {
|
|
/**
|
|
* Per-tab homepage post count.
|
|
*/
|
|
function aksrt_homepage_get_tab_posts_per_page(): int {
|
|
if (class_exists('AKSRT_Settings')) {
|
|
$count = AKSRT_Settings::homepage_tab_posts_per_page();
|
|
if ($count > 0) {
|
|
return max(1, min(20, $count));
|
|
}
|
|
}
|
|
|
|
return 6;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_get_default_view_mode')) {
|
|
/**
|
|
* Default homepage view mode.
|
|
*/
|
|
function aksrt_homepage_get_default_view_mode(): string {
|
|
if (class_exists('AKSRT_Settings')) {
|
|
return AKSRT_Settings::homepage_default_view();
|
|
}
|
|
|
|
return 'list';
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_sticky_tabs_enabled')) {
|
|
/**
|
|
* Whether homepage tabs should stick below the primary nav.
|
|
*/
|
|
function aksrt_homepage_sticky_tabs_enabled(): bool {
|
|
if (class_exists('AKSRT_Settings')) {
|
|
return AKSRT_Settings::homepage_sticky_tabs_enabled();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_module_hero_enabled')) {
|
|
/**
|
|
* Whether the fixed homepage should render the built-in hero section.
|
|
*/
|
|
function aksrt_homepage_module_hero_enabled(): bool {
|
|
if (class_exists('AKSRT_Settings')) {
|
|
return AKSRT_Settings::homepage_module_hero_enabled();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_module_banner_enabled')) {
|
|
/**
|
|
* Whether the fixed homepage should render the built-in banner section.
|
|
*/
|
|
function aksrt_homepage_module_banner_enabled(): bool {
|
|
if (class_exists('AKSRT_Settings')) {
|
|
return AKSRT_Settings::homepage_module_banner_enabled();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_get_sort_mode')) {
|
|
/**
|
|
* Current homepage main-stream sort mode.
|
|
*/
|
|
function aksrt_homepage_get_sort_mode(): string {
|
|
$allowed = class_exists('AKSRT_Settings')
|
|
? AKSRT_Settings::homepage_allowed_sorts()
|
|
: ['modified', 'date', 'views', 'likes', 'comments', 'favorites', 'downloads', 'rand'];
|
|
$default_sort = class_exists('AKSRT_Settings')
|
|
? AKSRT_Settings::homepage_default_sort()
|
|
: 'date';
|
|
$override_sort = get_query_var('aksrt_homepage_sort_override');
|
|
$sort = is_string($override_sort) && $override_sort !== ''
|
|
? sanitize_key($override_sort)
|
|
: (isset($_GET['home_sort']) ? sanitize_key(wp_unslash((string) $_GET['home_sort'])) : $default_sort);
|
|
|
|
return in_array($sort, $allowed, true) ? $sort : $default_sort;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_get_sort_items')) {
|
|
/**
|
|
* Configured sort bar items for the main stream.
|
|
*
|
|
* @return array<string,string>
|
|
*/
|
|
function aksrt_homepage_get_sort_items(): array {
|
|
$all_labels = class_exists('AKSRT_Settings')
|
|
? AKSRT_Settings::homepage_sort_labels()
|
|
: [
|
|
'modified' => '更新', 'date' => '发布', 'views' => '浏览',
|
|
'likes' => '点赞', 'comments' => '评论', 'favorites' => '收藏',
|
|
'downloads' => '下载', 'rand' => '随机',
|
|
];
|
|
|
|
$enabled_keys = class_exists('AKSRT_Settings')
|
|
? AKSRT_Settings::home_list_sort_options()
|
|
: array_keys($all_labels);
|
|
|
|
$items = [];
|
|
foreach ($enabled_keys as $key) {
|
|
if (isset($all_labels[$key])) {
|
|
$items[$key] = $all_labels[$key];
|
|
}
|
|
}
|
|
|
|
return !empty($items) ? $items : ['modified' => '更新', 'date' => '发布'];
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_apply_sort_args')) {
|
|
/**
|
|
* Apply sort args to a query configuration.
|
|
*/
|
|
function aksrt_homepage_apply_sort_args(array $args): array {
|
|
$sort_mode = aksrt_homepage_get_sort_mode();
|
|
|
|
// Meta sorts: keep posts without the meta key via OR NOT EXISTS so lists never collapse empty.
|
|
$apply_meta_sort = static function (array $args, string $meta_key): array {
|
|
$args['meta_key'] = $meta_key;
|
|
$args['orderby'] = [
|
|
'meta_value_num' => 'DESC',
|
|
'date' => 'DESC',
|
|
];
|
|
$args['meta_query'] = [
|
|
'relation' => 'OR',
|
|
[
|
|
'key' => $meta_key,
|
|
'compare' => 'EXISTS',
|
|
],
|
|
[
|
|
'key' => $meta_key,
|
|
'compare' => 'NOT EXISTS',
|
|
],
|
|
];
|
|
return $args;
|
|
};
|
|
|
|
switch ($sort_mode) {
|
|
case 'modified':
|
|
$args['orderby'] = 'modified';
|
|
$args['order'] = 'DESC';
|
|
break;
|
|
case 'downloads':
|
|
$args = $apply_meta_sort($args, '_aksrt_res_download_count');
|
|
break;
|
|
case 'views':
|
|
// Canonical public views key (align hotspot consumers later).
|
|
$args = $apply_meta_sort($args, 'aksrt_post_views');
|
|
break;
|
|
case 'likes':
|
|
$args = $apply_meta_sort($args, '_aksrt_like_count');
|
|
break;
|
|
case 'favorites':
|
|
$args = $apply_meta_sort($args, '_aksrt_favorite_count');
|
|
break;
|
|
case 'comments':
|
|
$args['orderby'] = 'comment_count';
|
|
$args['order'] = 'DESC';
|
|
break;
|
|
case 'rand':
|
|
$args['orderby'] = 'rand';
|
|
unset($args['order']);
|
|
break;
|
|
case 'date':
|
|
default:
|
|
$args['orderby'] = 'date';
|
|
$args['order'] = 'DESC';
|
|
break;
|
|
}
|
|
|
|
return $args;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_apply_named_sort_args')) {
|
|
/**
|
|
* Apply a specific named sort to query args (used by per-tab orderby).
|
|
*/
|
|
function aksrt_homepage_apply_named_sort_args(array $args, string $sort_mode): array {
|
|
$allowed = class_exists('AKSRT_Settings')
|
|
? AKSRT_Settings::homepage_allowed_sorts()
|
|
: ['modified', 'date', 'views', 'likes', 'comments', 'favorites', 'downloads', 'rand'];
|
|
|
|
if (!in_array($sort_mode, $allowed, true)) {
|
|
$sort_mode = 'date';
|
|
}
|
|
|
|
$previous = get_query_var('aksrt_homepage_sort_override');
|
|
set_query_var('aksrt_homepage_sort_override', $sort_mode);
|
|
$result = aksrt_homepage_apply_sort_args($args);
|
|
set_query_var('aksrt_homepage_sort_override', $previous);
|
|
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_render_sortbar')) {
|
|
/**
|
|
* Render the main-stream sort bar.
|
|
*/
|
|
function aksrt_homepage_render_sortbar(): void {
|
|
if (class_exists('AKSRT_Settings') && !AKSRT_Settings::home_list_sort_enabled()) {
|
|
return;
|
|
}
|
|
|
|
$current = aksrt_homepage_get_sort_mode();
|
|
$sort_ajax_enabled = class_exists('AKSRT_Settings')
|
|
? AKSRT_Settings::homepage_sort_ajax_enabled()
|
|
: true;
|
|
$is_dropdown = class_exists('AKSRT_Settings')
|
|
? AKSRT_Settings::home_list_sort_dropdown()
|
|
: false;
|
|
$base_url = remove_query_arg('home_sort', get_pagenum_link(aksrt_homepage_get_current_page()));
|
|
$sort_items = aksrt_homepage_get_sort_items();
|
|
$all_labels = class_exists('AKSRT_Settings')
|
|
? AKSRT_Settings::homepage_sort_labels()
|
|
: $sort_items;
|
|
?>
|
|
<div class="aksrt-homepage__sortbar" data-sort-ajax="<?php echo $sort_ajax_enabled ? 'true' : 'false'; ?>" aria-label="<?php esc_attr_e('Homepage Sort', 'aksrt'); ?>">
|
|
<?php if ($is_dropdown) : ?>
|
|
<div class="aksrt-homepage__sortbar-dropdown">
|
|
<button type="button" class="aksrt-homepage__sortbar-current" data-sort-dropdown-trigger>
|
|
<?php echo esc_html($all_labels[$current] ?? $current); ?>
|
|
<i class="fas fa-caret-down" aria-hidden="true"></i>
|
|
</button>
|
|
<div class="aksrt-homepage__sortbar-dropdown-menu" hidden>
|
|
<?php foreach ($sort_items as $sort_key => $label) : ?>
|
|
<a
|
|
class="aksrt-homepage__sortbar-dropdown-item<?php echo $sort_key === $current ? ' is-active' : ''; ?>"
|
|
href="<?php echo esc_url(add_query_arg('home_sort', $sort_key, $base_url)); ?>"
|
|
data-sort="<?php echo esc_attr($sort_key); ?>"
|
|
>
|
|
<?php echo esc_html($label); ?>
|
|
</a>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
<?php else : ?>
|
|
<div class="aksrt-homepage__sortbar-links">
|
|
<?php foreach ($sort_items as $sort_key => $label) : ?>
|
|
<a
|
|
class="aksrt-homepage__sortbar-link<?php echo $sort_key === $current ? ' is-active' : ''; ?>"
|
|
href="<?php echo esc_url(add_query_arg('home_sort', $sort_key, $base_url)); ?>"
|
|
data-sort="<?php echo esc_attr($sort_key); ?>"
|
|
>
|
|
<?php echo esc_html($label); ?>
|
|
</a>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php
|
|
$view_mode = 'list';
|
|
if (function_exists('aksrt_resolve_post_list_render_config')) {
|
|
$home_view_cfg = aksrt_resolve_post_list_render_config(['context' => 'home']);
|
|
$view_mode = (($home_view_cfg['mode'] ?? 'list') === 'card') ? 'card' : 'list';
|
|
}
|
|
?>
|
|
<div class="aksrt-homepage__view-toggle" data-aksrt-view-toggle>
|
|
<button type="button" class="aksrt-homepage__view-btn<?php echo $view_mode === 'list' ? ' is-active' : ''; ?>" data-view-mode="list" aria-label="<?php esc_attr_e('列表视图', 'aksrt'); ?>">
|
|
<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M1 3h14v2H1V3zm0 4h14v2H1V7zm0 4h14v2H1v-2z"/></svg>
|
|
</button>
|
|
<button type="button" class="aksrt-homepage__view-btn<?php echo $view_mode === 'card' ? ' is-active' : ''; ?>" data-view-mode="card" aria-label="<?php esc_attr_e('卡片视图', 'aksrt'); ?>">
|
|
<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M1 1h4v4H1V1zm5 0h4v4H6V1zm5 0h4v4h-4V1zM1 6h4v4H1V6zm5 0h4v4H6V6zm5 0h4v4h-4V6zM1 11h4v4H1v-4zm5 0h4v4H6v-4zm5 0h4v4h-4v-4z"/></svg>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<?php
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_get_latest_query')) {
|
|
/**
|
|
* Homepage main-stream query.
|
|
*/
|
|
function aksrt_homepage_get_latest_query(): WP_Query {
|
|
static $query = null;
|
|
|
|
if ($query instanceof WP_Query) {
|
|
return $query;
|
|
}
|
|
|
|
$query_args = [
|
|
'post_type' => aksrt_homepage_get_post_types(),
|
|
'post_status' => 'publish',
|
|
'posts_per_page' => max(1, (int) get_option('posts_per_page')),
|
|
'paged' => aksrt_homepage_get_current_page(),
|
|
'ignore_sticky_posts' => false,
|
|
'orderby' => 'date',
|
|
'order' => 'DESC',
|
|
'no_found_rows' => false,
|
|
];
|
|
|
|
$exclude_ids = class_exists('AKSRT_Settings')
|
|
? AKSRT_Settings::home_exclude_post_ids()
|
|
: [];
|
|
if (!empty($exclude_ids)) {
|
|
$query_args['post__not_in'] = $exclude_ids;
|
|
}
|
|
|
|
$exclude_cat_ids = class_exists('AKSRT_Settings')
|
|
? AKSRT_Settings::home_exclude_category_ids()
|
|
: [];
|
|
if (!empty($exclude_cat_ids)) {
|
|
$query_args['category__not_in'] = $exclude_cat_ids;
|
|
}
|
|
|
|
$query = new WP_Query(aksrt_homepage_apply_sort_args($query_args));
|
|
|
|
return $query;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_get_tab_query')) {
|
|
/**
|
|
* Build a category-tab query.
|
|
*/
|
|
function aksrt_homepage_get_tab_query(int $term_id, string $orderby = 'date'): WP_Query {
|
|
static $queries = [];
|
|
|
|
$cache_key = $term_id . '_' . $orderby;
|
|
if (isset($queries[$cache_key]) && $queries[$cache_key] instanceof WP_Query) {
|
|
return $queries[$cache_key];
|
|
}
|
|
|
|
$term = get_term($term_id);
|
|
$taxonomy = ($term && !is_wp_error($term)) ? (string) $term->taxonomy : 'category';
|
|
if (!in_array($taxonomy, ['category', 'topics'], true)) {
|
|
$taxonomy = 'category';
|
|
}
|
|
|
|
$query_args = [
|
|
'post_type' => aksrt_homepage_get_post_types(),
|
|
'post_status' => 'publish',
|
|
'posts_per_page' => class_exists('AKSRT_Settings')
|
|
? AKSRT_Settings::homepage_tab_posts_per_page()
|
|
: 6,
|
|
'ignore_sticky_posts' => true,
|
|
'orderby' => 'date',
|
|
'order' => 'DESC',
|
|
'no_found_rows' => true,
|
|
'tax_query' => [
|
|
[
|
|
'taxonomy' => $taxonomy,
|
|
'field' => 'term_id',
|
|
'terms' => [$term_id],
|
|
],
|
|
],
|
|
];
|
|
|
|
$exclude_ids = class_exists('AKSRT_Settings')
|
|
? AKSRT_Settings::home_exclude_post_ids()
|
|
: [];
|
|
if (!empty($exclude_ids)) {
|
|
$query_args['post__not_in'] = $exclude_ids;
|
|
}
|
|
|
|
$queries[$cache_key] = new WP_Query(
|
|
aksrt_homepage_apply_named_sort_args($query_args, $orderby)
|
|
);
|
|
|
|
return $queries[$cache_key];
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_has_active_sidebars')) {
|
|
/**
|
|
* Check whether any sidebar in the given stack is active.
|
|
*
|
|
* @param string[] $sidebar_ids
|
|
*/
|
|
function aksrt_homepage_has_active_sidebars(array $sidebar_ids): bool {
|
|
foreach ($sidebar_ids as $sidebar_id) {
|
|
if (is_active_sidebar($sidebar_id)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_render_widget_zone')) {
|
|
/**
|
|
* Render a stacked widget zone.
|
|
*
|
|
* @param string[] $sidebar_ids
|
|
* @param string $wrapper_class
|
|
*/
|
|
function aksrt_homepage_render_widget_zone(array $sidebar_ids, string $wrapper_class = ''): void {
|
|
if (!aksrt_homepage_has_active_sidebars($sidebar_ids)) {
|
|
wp_reset_postdata();
|
|
return;
|
|
}
|
|
|
|
echo '<div class="' . esc_attr(trim($wrapper_class)) . '">';
|
|
foreach ($sidebar_ids as $sidebar_id) {
|
|
if (is_active_sidebar($sidebar_id)) {
|
|
dynamic_sidebar($sidebar_id);
|
|
}
|
|
}
|
|
echo '</div>';
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_has_sidebar')) {
|
|
/**
|
|
* Whether the fixed homepage should render an aside column.
|
|
*/
|
|
function aksrt_homepage_has_sidebar(): bool {
|
|
if (function_exists('aksrt_is_show_sidebar')) {
|
|
return aksrt_is_show_sidebar();
|
|
}
|
|
return aksrt_homepage_has_active_sidebars([
|
|
'all_sidebar_top',
|
|
'home_sidebar',
|
|
'all_sidebar_bottom',
|
|
'sidebar-blog',
|
|
]);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_render_sidebar')) {
|
|
/**
|
|
* Render the homepage aside column.
|
|
*/
|
|
function aksrt_homepage_render_sidebar(): void {
|
|
if (!aksrt_homepage_has_sidebar()) {
|
|
return;
|
|
}
|
|
|
|
echo '<div class="sidebar aksrt-homepage__aside" role="complementary" aria-label="' . esc_attr__('Homepage Sidebar', 'aksrt') . '">';
|
|
|
|
if (is_active_sidebar('all_sidebar_top')) {
|
|
dynamic_sidebar('all_sidebar_top');
|
|
}
|
|
|
|
if (is_active_sidebar('home_sidebar')) {
|
|
dynamic_sidebar('home_sidebar');
|
|
} elseif (is_active_sidebar('sidebar-blog')) {
|
|
dynamic_sidebar('sidebar-blog');
|
|
}
|
|
|
|
if (is_active_sidebar('all_sidebar_bottom')) {
|
|
dynamic_sidebar('all_sidebar_bottom');
|
|
}
|
|
|
|
echo '</div>';
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_get_latest_panel_contract')) {
|
|
/**
|
|
* Public-safe latest stream contract shared by homepage pagination/AJAX.
|
|
*
|
|
* @return array{query_context:string,query_vars:string,render_config:string,render_config_array:array<string,mixed>}
|
|
*/
|
|
function aksrt_homepage_get_latest_panel_contract(): array {
|
|
$query = aksrt_homepage_get_latest_query();
|
|
$query_vars = $query instanceof WP_Query ? $query->query_vars : [];
|
|
if (!is_array($query_vars)) {
|
|
$query_vars = [];
|
|
}
|
|
|
|
unset($query_vars['paged'], $query_vars['page']);
|
|
|
|
$render_config = function_exists('aksrt_resolve_post_list_render_config')
|
|
? aksrt_resolve_post_list_render_config(['context' => 'home'])
|
|
: [
|
|
'mode' => 'list',
|
|
'context' => 'home',
|
|
];
|
|
|
|
return [
|
|
'query_context' => 'homepage_latest',
|
|
'query_vars' => (string) wp_json_encode($query_vars),
|
|
'render_config' => (string) wp_json_encode($render_config),
|
|
'render_config_array' => $render_config,
|
|
];
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_render_pagination')) {
|
|
/**
|
|
* Render pagination for the fixed homepage latest stream.
|
|
*/
|
|
function aksrt_homepage_render_pagination(WP_Query $query): void {
|
|
$max_pages = (int) $query->max_num_pages;
|
|
if ($max_pages < 2) {
|
|
return;
|
|
}
|
|
|
|
$query_page = (int) $query->get('paged');
|
|
$current_page = min(max(1, $query_page > 0 ? $query_page : aksrt_homepage_get_current_page()), $max_pages);
|
|
$pagination_mode = class_exists('AKSRT_Settings')
|
|
? AKSRT_Settings::get_post_pagination_mode()
|
|
: 'numbered';
|
|
|
|
if ($pagination_mode === 'numbered') {
|
|
$base_url = (string) get_query_var('aksrt_homepage_pagination_base_url');
|
|
$base_args = [
|
|
'format' => '',
|
|
'current' => $current_page,
|
|
'total' => $max_pages,
|
|
'mid_size' => 2,
|
|
'prev_text' => '<span aria-hidden="true">‹</span>',
|
|
'next_text' => '<span aria-hidden="true">›</span>',
|
|
'type' => 'array',
|
|
];
|
|
|
|
if ($base_url !== '') {
|
|
$base_args['base'] = add_query_arg(
|
|
'paged',
|
|
'%#%',
|
|
remove_query_arg(['paged', 'page'], $base_url)
|
|
);
|
|
} else {
|
|
$base_args['base'] = str_replace(999999999, '%#%', esc_url(get_pagenum_link(999999999)));
|
|
}
|
|
|
|
$links = paginate_links($base_args);
|
|
if (!$links || !is_array($links)) {
|
|
return;
|
|
}
|
|
?>
|
|
<nav class="navigation pagination" aria-label="<?php esc_attr_e('Posts', 'aksrt'); ?>">
|
|
<div class="nav-links">
|
|
<?php foreach ($links as $link) : ?>
|
|
<?php echo wp_kses_post($link); ?>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</nav>
|
|
<?php
|
|
return;
|
|
}
|
|
|
|
$contract = aksrt_homepage_get_latest_panel_contract();
|
|
?>
|
|
<div class="ajax-pagination aksrt-pagination-ajax"
|
|
data-mode="<?php echo esc_attr($pagination_mode); ?>"
|
|
data-next-page="<?php echo esc_attr($current_page + 1); ?>"
|
|
data-max-pages="<?php echo esc_attr($max_pages); ?>"
|
|
data-query-context="<?php echo esc_attr($contract['query_context']); ?>"
|
|
data-query-vars="<?php echo esc_attr($contract['query_vars']); ?>"
|
|
data-render-config="<?php echo esc_attr($contract['render_config']); ?>"
|
|
data-page="<?php echo esc_attr($current_page); ?>"
|
|
data-tab="latest">
|
|
<a href="javascript:;" class="ajax-next aksrt-load-more-btn">
|
|
<?php esc_html_e('加载更多', 'aksrt'); ?>
|
|
</a>
|
|
<div class="aksrt-loading-indicator" style="display:none;" aria-hidden="true">
|
|
<i class="fas fa-spinner fa-spin"></i>
|
|
<span><?php esc_html_e('加载中...', 'aksrt'); ?></span>
|
|
</div>
|
|
</div>
|
|
<?php
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_get_post_gallery_images')) {
|
|
/**
|
|
* Collect gallery images for homepage mult-thumb cards.
|
|
*
|
|
* @return string[]
|
|
*/
|
|
function aksrt_get_post_gallery_images(int $post_id, int $limit = 4): array {
|
|
static $request_cache = [];
|
|
|
|
$post_id = max(0, $post_id);
|
|
$limit = max(1, min(8, $limit));
|
|
|
|
if ($post_id <= 0) {
|
|
return [];
|
|
}
|
|
|
|
if (isset($request_cache[$post_id]) && is_array($request_cache[$post_id])) {
|
|
return array_slice($request_cache[$post_id], 0, $limit);
|
|
}
|
|
|
|
$modified_gmt = (string) get_post_field('post_modified_gmt', $post_id);
|
|
$transient_key = 'aksrt_home_gallery_' . $post_id . '_' . md5($modified_gmt !== '' ? $modified_gmt : (string) $post_id);
|
|
$cached_images = get_transient($transient_key);
|
|
|
|
if (is_array($cached_images)) {
|
|
$request_cache[$post_id] = $cached_images;
|
|
return array_slice($cached_images, 0, $limit);
|
|
}
|
|
|
|
$images = [];
|
|
$featured_image = has_post_thumbnail($post_id)
|
|
? (string) get_the_post_thumbnail_url($post_id, 'medium_large')
|
|
: '';
|
|
|
|
if ($featured_image !== '') {
|
|
$images[] = esc_url_raw($featured_image);
|
|
}
|
|
|
|
$content = (string) get_post_field('post_content', $post_id, 'raw');
|
|
if ($content !== '') {
|
|
if (preg_match_all('/<img[^>]+src=["\x27]([^"\x27]+)["\x27]/i', $content, $html_matches) && !empty($html_matches[1])) {
|
|
foreach ($html_matches[1] as $raw_url) {
|
|
$images[] = esc_url_raw((string) $raw_url);
|
|
}
|
|
}
|
|
|
|
if (preg_match_all('/"url"\s*:\s*"([^"]+)"/i', $content, $block_matches) && !empty($block_matches[1])) {
|
|
foreach ($block_matches[1] as $raw_url) {
|
|
$images[] = esc_url_raw((string) $raw_url);
|
|
}
|
|
}
|
|
}
|
|
|
|
$images = array_values(array_unique(array_filter($images, static function ($url) {
|
|
return is_string($url) && $url !== '';
|
|
})));
|
|
|
|
set_transient($transient_key, $images, DAY_IN_SECONDS);
|
|
$request_cache[$post_id] = $images;
|
|
|
|
return array_slice($images, 0, $limit);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_render_post_card')) {
|
|
/**
|
|
* Render a homepage post card inline.
|
|
*/
|
|
function aksrt_homepage_render_post_card(): void {
|
|
if (!function_exists('aksrt_render_post')) {
|
|
return;
|
|
}
|
|
|
|
$config = function_exists('aksrt_resolve_post_list_render_config')
|
|
? aksrt_resolve_post_list_render_config(['context' => 'home'])
|
|
: [
|
|
'mode' => 'list',
|
|
'context' => 'home',
|
|
];
|
|
|
|
echo aksrt_render_post($config); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_render_posts_grid')) {
|
|
/**
|
|
* Render a list block for the fixed homepage.
|
|
*/
|
|
function aksrt_homepage_render_posts_grid(?WP_Query $query = null, bool $with_pagination = false): void {
|
|
$query = $query instanceof WP_Query ? $query : aksrt_homepage_get_latest_query();
|
|
$config = function_exists('aksrt_resolve_post_list_render_config')
|
|
? aksrt_resolve_post_list_render_config(['context' => 'home'])
|
|
: [
|
|
'mode' => 'list',
|
|
'context' => 'home',
|
|
];
|
|
$config['skip_wrapper'] = true;
|
|
$view = (($config['mode'] ?? 'list') === 'card') ? 'card' : 'list';
|
|
|
|
if (function_exists('aksrt_render_post_list')) {
|
|
// Panel already provides posts-row.ajaxpager; avoid nested wrapper.
|
|
aksrt_render_post_list($query, $config, true);
|
|
} else {
|
|
if (!$query->have_posts()) {
|
|
echo '<div class="no-results"><p>' . esc_html__('暂无文章', 'aksrt') . '</p></div>';
|
|
} else {
|
|
echo '<div class="posts-row aksrt-homepage__posts" data-view="' . esc_attr($view) . '">';
|
|
while ($query->have_posts()) {
|
|
$query->the_post();
|
|
aksrt_homepage_render_post_card();
|
|
}
|
|
echo '</div>';
|
|
}
|
|
wp_reset_postdata();
|
|
}
|
|
|
|
if ($with_pagination) {
|
|
aksrt_homepage_render_pagination($query);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_render_section')) {
|
|
/**
|
|
* Render a first-class homepage section (hero / banner).
|
|
*
|
|
* These are fixed homepage sections, not a freeform module canvas bridge.
|
|
*/
|
|
function aksrt_homepage_render_section(string $type): void {
|
|
$type = sanitize_key($type);
|
|
if (!in_array($type, ['hero', 'banner'], true)) {
|
|
return;
|
|
}
|
|
|
|
// Fixed homepage owns these sections directly.
|
|
// Keep the existing hero/banner templates as section implementations,
|
|
// but do not re-wrap them in a freeform module bridge.
|
|
get_template_part('templates/parts/home-modules/module', $type);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_header_slide_is_show')) {
|
|
/**
|
|
* Whether the header multi-function slider should render (zibll header-slider contract).
|
|
*/
|
|
function aksrt_header_slide_is_show(): bool {
|
|
if (is_admin()) {
|
|
return false;
|
|
}
|
|
|
|
// Match zibll: only first page of the posts index / front page.
|
|
if (!(is_front_page() || is_home())) {
|
|
return false;
|
|
}
|
|
|
|
if (function_exists('aksrt_homepage_get_current_page') && aksrt_homepage_get_current_page() > 1) {
|
|
return false;
|
|
}
|
|
|
|
return function_exists('aksrt_homepage_module_hero_enabled')
|
|
? aksrt_homepage_module_hero_enabled()
|
|
: true;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_header_slide')) {
|
|
/**
|
|
* Render header slider after the site header (outside main).
|
|
*/
|
|
function aksrt_header_slide(): void {
|
|
if (!aksrt_header_slide_is_show()) {
|
|
return;
|
|
}
|
|
|
|
// Reuse existing hero partial as the slider implementation.
|
|
get_template_part('templates/parts/home-modules/module', 'hero');
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_homepage_render_layout')) {
|
|
/**
|
|
* Render the fixed homepage layout (Zibll latest-first content stream).
|
|
*
|
|
* Order (zibll-aligned):
|
|
* fluid top → main.container → top content → banner → tabs/list → bottom content → sidebar
|
|
* → fluid bottom. Hero/header-slider is rendered from header.php, not here.
|
|
*/
|
|
function aksrt_homepage_render_layout(): void {
|
|
$current_page = aksrt_homepage_get_current_page();
|
|
$show_tabs = $current_page === 1;
|
|
$tab_configs = $show_tabs ? aksrt_homepage_get_tab_configs() : [];
|
|
$latest_contract = aksrt_homepage_get_latest_panel_contract();
|
|
$has_sidebar = aksrt_homepage_has_sidebar();
|
|
$banner_on = $show_tabs && aksrt_homepage_module_banner_enabled();
|
|
$main_list_enabled = !class_exists('AKSRT_Settings') || AKSRT_Settings::home_posts_list_enabled();
|
|
$list_title = class_exists('AKSRT_Settings')
|
|
? AKSRT_Settings::home_list_title()
|
|
: __('最新发布', 'aksrt');
|
|
|
|
// Fluid zones live outside <main>, once only (removed from header.php).
|
|
aksrt_homepage_render_widget_zone(
|
|
['all_top_fluid', 'home_top_fluid'],
|
|
'fluid-widget-wrap aksrt-homepage__fluid-zone aksrt-homepage__fluid-zone--top'
|
|
);
|
|
?>
|
|
<main id="main-content" role="main" class="container site-main aksrt-homepage" tabindex="-1">
|
|
<div class="content-wrap aksrt-homepage__shell">
|
|
<div class="content-layout<?php echo $has_sidebar ? '' : ' content-layout--no-sidebar'; ?> aksrt-homepage__content-layout">
|
|
<div class="content-layout__primary aksrt-homepage__primary">
|
|
<?php
|
|
aksrt_homepage_render_widget_zone(
|
|
['home_top_content'],
|
|
'aksrt-homepage__content-zone aksrt-homepage__content-zone--top'
|
|
);
|
|
|
|
if ($banner_on && function_exists('aksrt_homepage_render_section')) {
|
|
aksrt_homepage_render_section('banner');
|
|
}
|
|
?>
|
|
|
|
<?php if ($main_list_enabled) : ?>
|
|
<section class="aksrt-homepage__stream home-tab-content" aria-label="<?php esc_attr_e('Homepage Content', 'aksrt'); ?>">
|
|
<?php if ($show_tabs && !empty($tab_configs)) : ?>
|
|
<div class="index-tab affix-header-sm relative home-tab-nav-box aksrt-homepage__tabs mb10" data-sticky-tabs="<?php echo aksrt_homepage_sticky_tabs_enabled() ? 'true' : 'false'; ?>" offset-top="-8">
|
|
<ul class="list-inline scroll-x no-scrollbar aksrt-homepage__tab-list" role="tablist" data-aksrt-home-tabs style="width:100%;">
|
|
<li class="aksrt-homepage__tab-item is-active" role="presentation">
|
|
<button type="button" class="aksrt-homepage__tab-button" role="tab" aria-selected="true" data-home-tab-target="latest">
|
|
<?php echo esc_html($list_title !== '' ? $list_title : __('最新发布', 'aksrt')); ?>
|
|
</button>
|
|
</li>
|
|
<?php foreach ($tab_configs as $tab_cfg) : ?>
|
|
<li class="aksrt-homepage__tab-item" role="presentation">
|
|
<button
|
|
type="button"
|
|
class="aksrt-homepage__tab-button"
|
|
role="tab"
|
|
aria-selected="false"
|
|
data-home-tab-target="term-<?php echo (int) $tab_cfg['term_id']; ?>"
|
|
data-tab-orderby="<?php echo esc_attr($tab_cfg['orderby']); ?>"
|
|
>
|
|
<?php echo esc_html($tab_cfg['title']); ?>
|
|
</button>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php if (function_exists('aksrt_render_admin_quick_link')) { aksrt_render_admin_quick_link('page-display/homepage', __('首页设置', 'aksrt'), 'aksrt-admin-quicklink aksrt-homepage__admin-link'); } ?>
|
|
</div>
|
|
<?php elseif ($current_page > 1) : ?>
|
|
<div class="box-body notop nobottom aksrt-homepage__titlebox">
|
|
<div class="title-theme">
|
|
<?php echo esc_html($list_title !== '' ? $list_title : __('最新发布', 'aksrt')); ?>
|
|
<small class="aksrt-homepage__page-indicator ml10">
|
|
<?php echo esc_html(sprintf(__('第 %d 页', 'aksrt'), $current_page)); ?>
|
|
</small>
|
|
</div>
|
|
</div>
|
|
<?php elseif ($list_title !== '') : ?>
|
|
<div class="box-body notop nobottom aksrt-homepage__titlebox">
|
|
<div class="title-theme"><?php echo esc_html($list_title); ?></div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php aksrt_homepage_render_sortbar(); ?>
|
|
|
|
<div class="aksrt-homepage__panels tab-content">
|
|
<div class="aksrt-homepage__panel posts-row ajaxpager tab-pane is-active show" role="tabpanel" data-home-tab-panel="latest" id="index-tab-main">
|
|
<div
|
|
class="aksrt-homepage__panel-contract"
|
|
data-query-context="<?php echo esc_attr($latest_contract['query_context']); ?>"
|
|
data-query-vars="<?php echo esc_attr($latest_contract['query_vars']); ?>"
|
|
data-render-config="<?php echo esc_attr($latest_contract['render_config']); ?>"
|
|
data-page="1"
|
|
data-tab="latest"
|
|
></div>
|
|
<?php aksrt_homepage_render_posts_grid(aksrt_homepage_get_latest_query(), true); ?>
|
|
</div>
|
|
|
|
<?php if ($show_tabs && !empty($tab_configs)) : ?>
|
|
<?php foreach ($tab_configs as $tab_cfg) : ?>
|
|
<div
|
|
class="aksrt-homepage__panel posts-row ajaxpager tab-pane"
|
|
role="tabpanel"
|
|
data-home-tab-panel="term-<?php echo (int) $tab_cfg['term_id']; ?>"
|
|
data-tab-orderby="<?php echo esc_attr($tab_cfg['orderby']); ?>"
|
|
hidden
|
|
></div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</section>
|
|
<?php else : ?>
|
|
<section class="aksrt-homepage__stream home-tab-content aksrt-homepage__stream--disabled" aria-label="<?php esc_attr_e('Homepage Content', 'aksrt'); ?>">
|
|
<div class="no-results box-body">
|
|
<p><?php esc_html_e('首页主列表已关闭。', 'aksrt'); ?></p>
|
|
<?php if (current_user_can('manage_options') && function_exists('aksrt_render_admin_quick_link')) : ?>
|
|
<?php aksrt_render_admin_quick_link('page-display/homepage', __('打开首页设置并启用主列表', 'aksrt'), 'aksrt-admin-quicklink'); ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</section>
|
|
<?php endif; ?>
|
|
|
|
<?php
|
|
aksrt_homepage_render_widget_zone(
|
|
['home_bottom_content'],
|
|
'aksrt-homepage__content-zone aksrt-homepage__content-zone--bottom'
|
|
);
|
|
?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php aksrt_homepage_render_sidebar(); ?>
|
|
</main>
|
|
<?php
|
|
aksrt_homepage_render_widget_zone(
|
|
['home_bottom_fluid', 'all_bottom_fluid'],
|
|
'fluid-widget-wrap aksrt-homepage__fluid-zone aksrt-homepage__fluid-zone--bottom'
|
|
);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_render_fixed_homepage')) {
|
|
/**
|
|
* Render the new fixed homepage layout.
|
|
*/
|
|
function aksrt_render_fixed_homepage(): bool {
|
|
if (!aksrt_is_fixed_homepage_request()) {
|
|
return false;
|
|
}
|
|
|
|
get_header();
|
|
aksrt_homepage_render_layout();
|
|
get_footer();
|
|
|
|
return true;
|
|
}
|
|
}
|