- assets/vendor 全量迁移: fontawesome5→assets/fontawesome5, css→assets/css, js→assets/js/runtime(避开 14 个同名自有文件), img 合并去重→assets/img, fonts→assets/fonts; 删除 assets/vendor - libs 五个与 widgets/third-party 字节相同的库不重复入库, loader paths 改指向 - 运行时切换: _win.uri=assets 根, loader baseUrl=/js/runtime, enlighter 注入 路径同步; PHP 7 个引用文件切换并改名 $zibll_*→$runtime_* - 去品牌: Qinver 头注释/品牌 console.log/演示链接清除, 默认文案中性化 - 功能标识符改名: zib__→aksrt__, zib_ajax→aksrt_ajax, window.zib→ window.aksrtLegacy, zibllblock/*→aksrtblock/*, .zib-widget→.aksrt-panel, .zib-slider→.aksrt-slider, zib_menu_options meta 键等 - 自有 CSS 改名: legacy-utilities/compat-vars/footer shell - admin SPA 重建; 契约测试同步(路径/断言/文件更名) - 例外保留: tests/visual 对照环境与 fixtures 前缀(外部 Zibll 产品引用) 验证: php -l 133 个改动文件通过; runtime 86 个 JS node --check 通过; 契约测试 68/70(2 个失败经 stash 对照确认为存量问题)
330 lines
9.4 KiB
PHP
330 lines
9.4 KiB
PHP
<?php
|
|
/**
|
|
* AKSRT Fixed Homepage Helpers
|
|
*
|
|
* Rebuilds the homepage around a fixed legacy-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'.
|
|
* Preserves every configured row in the saved order.
|
|
*
|
|
* @return array<int, array{term:WP_Term, title:string, orderby:string, term_id:int}>
|
|
*/
|
|
function aksrt_homepage_get_tab_configs(): array {
|
|
if (!class_exists('\AKSRT\Settings\Settings')) {
|
|
return [];
|
|
}
|
|
|
|
$structured_tabs = \AKSRT\Settings\Settings::homepage_tabs();
|
|
if (empty($structured_tabs)) {
|
|
return [];
|
|
}
|
|
|
|
$excluded_cat_ids = array_flip(\AKSRT\Settings\Settings::home_exclude_category_ids());
|
|
$configs = [];
|
|
|
|
foreach ($structured_tabs as $tab) {
|
|
if ($tab['term_id'] <= 0) {
|
|
continue;
|
|
}
|
|
if (isset($excluded_cat_ids[$tab['term_id']])) {
|
|
continue;
|
|
}
|
|
|
|
$term = get_term($tab['term_id']);
|
|
if (!$term || is_wp_error($term)) {
|
|
continue;
|
|
}
|
|
if ($term->taxonomy !== 'category') {
|
|
continue;
|
|
}
|
|
|
|
$configs[] = [
|
|
'term' => $term,
|
|
'term_id' => (int) $tab['term_id'],
|
|
'title' => $tab['title'] !== '' ? $tab['title'] : $term->name,
|
|
'orderby' => $tab['orderby'] ?: 'modified',
|
|
];
|
|
}
|
|
|
|
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\Settings')) {
|
|
$count = \AKSRT\Settings\Settings::homepage_tab_posts_per_page();
|
|
if ($count > 0) {
|
|
return max(1, min(20, $count));
|
|
}
|
|
}
|
|
|
|
return 6;
|
|
}
|
|
}
|
|
|
|
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\Settings')) {
|
|
return \AKSRT\Settings\Settings::homepage_sticky_tabs_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\Settings')
|
|
? \AKSRT\Settings\Settings::homepage_allowed_sorts()
|
|
: ['modified', 'date', 'views', 'like', 'comment_count', 'favorite', 'rand'];
|
|
$default_sort = class_exists('\AKSRT\Settings\Settings')
|
|
? \AKSRT\Settings\Settings::homepage_default_sort()
|
|
: 'modified';
|
|
$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\Settings')
|
|
? \AKSRT\Settings\Settings::homepage_sort_labels()
|
|
: [
|
|
'modified' => '更新', 'date' => '发布', 'views' => '浏览',
|
|
'like' => '点赞', 'comment_count' => '评论', 'favorite' => '收藏', 'rand' => '随机',
|
|
];
|
|
|
|
$enabled_keys = class_exists('\AKSRT\Settings\Settings')
|
|
? \AKSRT\Settings\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 'views':
|
|
// Canonical public views key (align hotspot consumers later).
|
|
$args = $apply_meta_sort($args, 'aksrt_post_views');
|
|
break;
|
|
case 'like':
|
|
$args = $apply_meta_sort($args, '_aksrt_like_count');
|
|
break;
|
|
case 'favorite':
|
|
$args = $apply_meta_sort($args, '_aksrt_favorite_count');
|
|
break;
|
|
case 'comment_count':
|
|
$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\Settings')
|
|
? \AKSRT\Settings\Settings::homepage_allowed_sorts()
|
|
: ['modified', 'date', 'views', 'like', 'comment_count', 'favorite', 'rand'];
|
|
|
|
if (!in_array($sort_mode, $allowed, true)) {
|
|
$sort_mode = 'modified';
|
|
}
|
|
|
|
$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\Settings') && !\AKSRT\Settings\Settings::home_list_sort_enabled()) {
|
|
return;
|
|
}
|
|
|
|
$current = aksrt_homepage_get_sort_mode();
|
|
$sort_ajax_enabled = class_exists('\AKSRT\Settings\Settings')
|
|
? \AKSRT\Settings\Settings::homepage_sort_ajax_enabled()
|
|
: true;
|
|
$is_dropdown = class_exists('\AKSRT\Settings\Settings')
|
|
? \AKSRT\Settings\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\Settings')
|
|
? \AKSRT\Settings\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="fa 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; ?>
|
|
</div>
|
|
<?php
|
|
}
|
|
}
|