Files
wordpress-theme-aksrt/inc/helpers/homepage/content.php
T
kate522andClaude Opus 5 427968a721 chore(branding): remove leftover upstream theme identifiers
The theme was renamed Zibll/子比 → AKSRT → Jio, but upstream branding
survived the sweeps in CSS classes, the SVG sprite prefix, a persisted
widget field ID, JS events, admin Vue class names, test infrastructure
and docblocks.

Renames:
- zib-widget / zib-widget-wrap / zib-slider → jio-widget-box /
  jio-widget-box-wrap / jio-slider-box (jio-widget is taken by the modern
  widget shell, jio-box-* by the card primitives)
- zib-partners-scroll + zps-* → jio-partners-scroll + jps-*
- zib-combo-info-card + zci-* → jio-combo-info-card + jci-*
- zibsvg- → jiosvg-, including the exported picker helpers and the
  fa-zibsvg- family-prefix guard
- zibpay_type → pay_type; the dual-read fallback in PostQuery collapses
  to a single key
- [zibajax="submit"] dropped (no PHP emitter); zib_ajax.success →
  jio_ajax.success
- aks-* admin Vue classes → jio-*
- zib_palette() → palette()

User-facing vendor traces are gone: the floating "more" button default no
longer ships a zibll.com link or 子比主题 marketing copy, the notice
widget ships no preset promo entries, and the four 官网教程 links are
removed from the post-list admin schema.

Test infrastructure renamed to neutral names (docker-compose.reference.yml,
Caddyfile, article-baseline.json, modern-widgets-contract.test.cjs) with
their DB/volume/env/slug identifiers following.

Kept intentionally, documented in tests/fixtures/README.md: the golden
fixture reference fingerprint (a SHA-256 record of an external directory,
read by validate-widget-golden / generate-widget-golden-fixture /
audit-widget-system), the doesNotMatch guards that prove the old tokens are
gone, and the reference theme's own meta key in the visual fixtures.

No backward-compat or data migration: saved widget configs holding old
icon keys or the old field ID silently lose them, per the project's
rewrite-over-compatibility rule.

Verified: 132/132 node contract tests, php tests/widget-system/run.php
(146 assertions), audit-admin-contracts, audit-psr4-paths and
validate-widget-golden all green; tracked bundles regenerated and in sync.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-11-02 00:06:54 +08:00

298 lines
8.3 KiB
PHP

<?php
/**
* Homepage queries, sidebars, post stream, and pagination.
*
* @package Jio
*/
defined('ABSPATH') || exit;
if (!function_exists('jio_homepage_get_latest_query')) {
/**
* Homepage main-stream query.
*/
function jio_homepage_get_latest_query(): WP_Query {
static $query = null;
if ($query instanceof WP_Query) {
return $query;
}
$query_args = [
'post_type' => jio_homepage_get_post_types(),
'post_status' => 'publish',
'posts_per_page' => max(1, (int) get_option('posts_per_page')),
'paged' => jio_homepage_get_current_page(),
'ignore_sticky_posts' => false,
'orderby' => 'date',
'order' => 'DESC',
'no_found_rows' => false,
];
$exclude_ids = class_exists('\Jio\Settings\Settings')
? \Jio\Settings\Settings::home_exclude_post_ids()
: [];
if (!empty($exclude_ids)) {
$query_args['post__not_in'] = $exclude_ids;
}
$exclude_cat_ids = class_exists('\Jio\Settings\Settings')
? \Jio\Settings\Settings::home_exclude_category_ids()
: [];
if (!empty($exclude_cat_ids)) {
$query_args['category__not_in'] = $exclude_cat_ids;
}
// 排序菜单的 ?orderby= 优先于后台默认排序。
$request_sort = jio_homepage_get_request_sort();
$query = new WP_Query(
$request_sort !== ''
? jio_homepage_apply_named_sort_args($query_args, $request_sort)
: jio_homepage_apply_sort_args($query_args)
);
return $query;
}
}
if (!function_exists('jio_homepage_has_active_sidebars')) {
/**
* Check whether any sidebar in the given stack is active.
*
* @param string[] $sidebar_ids
*/
function jio_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('jio_homepage_render_widget_zone')) {
/**
* Render a stacked widget zone.
*
* @param string[] $sidebar_ids
* @param string $wrapper_class
*/
function jio_homepage_render_widget_zone(array $sidebar_ids, string $wrapper_class = ''): void {
if (!jio_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('jio_homepage_render_sidebar')) {
/**
* Render the homepage aside column.
*
* Visibility is jio_is_show_sidebar() alone; its filter already
* collapses the layout when the sidebar widget stack is empty.
*/
function jio_homepage_render_sidebar(): void {
if (!jio_is_show_sidebar()) {
return;
}
echo '<div class="sidebar jio-homepage__aside" role="complementary" aria-label="' . esc_attr__('Homepage Sidebar', 'jio') . '">';
if (is_active_sidebar('all_sidebar_top')) {
dynamic_sidebar('all_sidebar_top');
}
if (is_active_sidebar('home_sidebar')) {
dynamic_sidebar('home_sidebar');
}
if (is_active_sidebar('all_sidebar_bottom')) {
dynamic_sidebar('all_sidebar_bottom');
}
echo '</div>';
}
}
if (!function_exists('jio_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 jio_homepage_get_latest_panel_contract(): array {
$query = jio_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 = jio_resolve_post_list_render_config(['context' => 'home']);
$render_config['skip_wrapper'] = true;
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('jio_homepage_render_pagination')) {
/**
* Render pagination for the fixed homepage latest stream.
*/
function jio_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 : jio_homepage_get_current_page()), $max_pages);
$pagination_mode = class_exists('\Jio\Settings\Settings')
? \Jio\Settings\Settings::get_post_pagination_mode()
: 'numbered';
if ($pagination_mode === 'numbered') {
$base_url = (string) get_query_var('jio_homepage_pagination_base_url');
$base_args = [
'format' => '',
'current' => $current_page,
'total' => $max_pages,
'mid_size' => 2,
'prev_text' => '<span aria-hidden="true">&#8249;</span>',
'next_text' => '<span aria-hidden="true">&#8250;</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', 'jio'); ?>">
<div class="nav-links">
<?php foreach ($links as $link) : ?>
<?php echo wp_kses_post($link); ?>
<?php endforeach; ?>
</div>
</nav>
<?php
return;
}
$contract = jio_homepage_get_latest_panel_contract();
jio_render_pagination($query, [
'query_context' => $contract['query_context'],
'render_config' => $contract['render_config_array'],
'current_page' => $current_page,
]);
}
}
if (!function_exists('jio_get_post_gallery_images')) {
/**
* Collect gallery images for homepage mult-thumb cards.
*
* @return string[]
*/
function jio_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 = 'jio_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('jio_homepage_render_posts_grid')) {
/**
* Render a list block for the fixed homepage.
*/
function jio_homepage_render_posts_grid(?WP_Query $query = null, bool $with_pagination = false): void {
$query = $query instanceof WP_Query ? $query : jio_homepage_get_latest_query();
$config = jio_resolve_post_list_render_config(['context' => 'home']);
$config['skip_wrapper'] = true;
// Panel already provides posts-row.ajaxpager; avoid nested wrapper.
jio_render_post_list($config, $query, true);
if ($with_pagination) {
jio_homepage_render_pagination($query);
}
}
}