Files
wordpress-theme-aksrt/inc/helpers/homepage/header-components.php
T
kate522 00ae62f62b fix(auth): close the modal regressions and keep the header component off /sign/
Three defects slipped into the sign-card rebuild:

The hidden-glyph rule was dropped. `.fa` sets display:inline-block, which
outranks the UA [hidden] rule, so every hidden glyph stayed visible — most
visibly a spinner rendered beside the login button at rest. `.sign [hidden]`
restores the override.

Closing account login produced an empty shell. The whole sign-in pane was
gated on `!$close_signin`, and the social block carried the same gate, so a
site with account login off but registration on still opened on an empty
panel with no social entry. The pane is now rendered in three shapes: open
registration falls through to the signup tab, a QR entry falls through to
the QR tab, social-only renders a notice plus the social bar, and when
nothing is available it states that login is closed.

The modal close button sat in normal flow and pushed the card content down;
`#u_sign .sign > .close` pins it back to the top-right corner.

The /sign/ route is `index.php?jio_sign=1`, so WordPress reports it as home.
The header multifunction component resolves page type by query flags and the
home branch won, so the component appeared on the auth page whenever "首页"
was in its scope — even though the sign page template itself was already
excluded. `jio_header_slide_current_page_type()` now bails out on `jio_sign`
before any of the is_* checks.

The breakpoint overrides that were fighting the shared sheet between 641px
and 991px are narrowed to the one offset that actually needed adjusting.

Verification: the modal was rendered through a PHP stub, served with the real
theme stylesheets, and driven by the real auth.js in a headless browser —
tab switching, signin-mode switching, password reveal, close button and
geometry at 1440/1100/900/760/500/390px. The header harness gained a
`jio_sign` case asserting no markup, and 860 widget/navigation tests pass.
2026-11-04 16:51:41 +08:00

494 lines
20 KiB
PHP

<?php
/**
* legacy header slider visibility and rendering.
*
* This is the only header-slider rendering path. It consumes the original
* legacy option IDs and the serialized page_config post meta contract.
*
* @package Jio
*/
defined('ABSPATH') || exit;
if (!function_exists('jio_header_slider_device_is_visible')) {
/** @param mixed $value */
function jio_header_slider_device_is_visible($value): bool {
$devices = array_map('sanitize_key', (array) $value);
return wp_is_mobile()
? in_array('m_s', $devices, true)
: in_array('pc_s', $devices, true);
}
}
if (!function_exists('jio_header_slide_excluded_page_templates')) {
/** @return list<string> */
function jio_header_slide_excluded_page_templates(): array {
return [
'templates/pages/page-sign.php',
'templates/pages/page-download.php',
'templates/pages/page-download-file.php',
];
}
}
if (!function_exists('jio_get_page_header_slider_config')) {
/** @return array<string,mixed> */
function jio_get_page_header_slider_config(): array {
if (!is_page()) {
return [];
}
$config = get_post_meta(get_queried_object_id(), 'page_config', true);
return is_array($config) && !empty($config['header_slider_show']) ? $config : [];
}
}
if (!function_exists('jio_header_slide_current_page_type')) {
/**
* Resolve one mutually exclusive page type for the header component.
*
* Custom rewrite requests can retain WordPress's is_home flag, so the
* explicit theme surfaces must win before the home fallback is evaluated.
* Utility rewrites (go-link confirm) are error / hand-off surfaces and
* opt out entirely, like the excluded templates.
*/
function jio_header_slide_current_page_type(): string {
// The /sign/ route is `index.php?jio_sign=1`, which WordPress reports as
// home — the auth surface must never inherit the home component scope.
// (Pages using the sign template are already excluded further down.)
if ((string) get_query_var('jio_sign') !== '') {
return '';
}
if ((string) get_query_var('jio_go_redirect') !== '') {
return '';
}
if ((string) get_query_var('jio_message_view') !== '') {
return 'page';
}
if (is_author() || (function_exists('jio_is_user_home_page') && jio_is_user_home_page())) {
return 'author';
}
if (function_exists('jio_is_user_center_page') && jio_is_user_center_page()) {
return 'user_center';
}
if (is_front_page()) {
return 'home';
}
if (is_category()) {
return 'category';
}
if (is_tag()) {
return 'tag';
}
if (is_singular('post')) {
return 'single';
}
if (is_search()) {
return 'search';
}
if (is_page()) {
foreach (jio_header_slide_excluded_page_templates() as $template) {
if (is_page_template($template)) {
return '';
}
}
return 'page';
}
if (is_home()) {
return 'home';
}
return '';
}
}
if (!function_exists('jio_header_slide_matches_query')) {
function jio_header_slide_matches_query(string $type): bool {
$type = sanitize_key($type);
if ($type === 'user_home') {
$type = 'author';
}
return $type !== '' && $type === jio_header_slide_current_page_type();
}
}
if (!function_exists('jio_header_slide_is_show')) {
function jio_header_slide_is_show(): bool {
global $wp_query;
if (is_admin() || !($wp_query instanceof WP_Query)) {
return false;
}
// This component only displays on the first archive page.
if ((int) $wp_query->get('paged') > 1) {
return false;
}
$settings = class_exists('\\Jio\\Settings\\Settings')
? \Jio\Settings\Settings::get_header_slider_settings()
: [];
$show_type = sanitize_key((string) ($settings['show_type'] ?? ''));
if (($show_type === 'only_pc' && wp_is_mobile()) || ($show_type === 'only_sm' && !wp_is_mobile())) {
return false;
}
$matches_global_scope = false;
foreach ((array) ($settings['show_on_pages'] ?? []) as $type) {
if (jio_header_slide_matches_query((string) $type)) {
$matches_global_scope = true;
break;
}
}
if (!$matches_global_scope) {
return false;
}
// Per-page data may customize an already-enabled component, but it must
// never bypass the global page scope selected in the theme settings.
$page_config = jio_get_page_header_slider_config();
if ($page_config) {
$page_show_type = sanitize_key((string) ($page_config['header_slider_show_type'] ?? ''));
return !($page_show_type === 'only_pc' && wp_is_mobile())
&& !($page_show_type === 'only_sm' && !wp_is_mobile());
}
return true;
}
}
if (!function_exists('jio_get_header_slider_args')) {
/** @return array<string,mixed> */
function jio_get_header_slider_args(): array {
$page_config = jio_get_page_header_slider_config();
if ($page_config) {
return [
'header_slider' => (array) ($page_config['header_slider'] ?? []),
'header_slider_option' => (array) ($page_config['header_slider_option'] ?? []),
'header_slider_show_type' => (string) ($page_config['header_slider_show_type'] ?? ''),
'header_slider_nav_color' => (string) ($page_config['header_slider_nav_color'] ?? ''),
'header_slider_search_s' => (array) ($page_config['header_slider_search_s'] ?? []),
'header_slider_search_option' => (array) ($page_config['header_slider_search_option'] ?? []),
'header_slider_card_s' => (array) ($page_config['header_slider_card_s'] ?? []),
'header_slider_card_option' => (array) ($page_config['header_slider_card_option'] ?? []),
];
}
$settings = class_exists('\\Jio\\Settings\\Settings')
? \Jio\Settings\Settings::get_header_slider_settings()
: [];
return [
'header_slider' => (array) ($settings['slides'] ?? []),
'header_slider_option' => (array) ($settings['slider_config'] ?? []),
'header_slider_show_type' => (string) ($settings['show_type'] ?? ''),
'header_slider_nav_color' => (string) ($settings['nav_color'] ?? ''),
'header_slider_search_s' => (array) ($settings['search_show'] ?? []),
'header_slider_search_option' => (array) ($settings['search_config'] ?? []),
'header_slider_card_s' => (array) ($settings['card_show'] ?? []),
'header_slider_card_option' => (array) ($settings['card_config'] ?? []),
];
}
}
if (!function_exists('jio_header_slider_allowed_html')) {
/** @return array<string,array<string,bool>> */
function jio_header_slider_allowed_html(): array {
return [
'a' => ['href' => true, 'target' => true, 'rel' => true, 'class' => true],
'b' => ['class' => true],
'badge' => ['class' => true],
'br' => [],
'div' => ['class' => true],
'em' => ['class' => true],
'i' => ['class' => true, 'aria-hidden' => true],
'small' => ['class' => true],
'span' => ['class' => true],
'strong' => ['class' => true],
];
}
}
if (!function_exists('jio_header_slider_image')) {
/** @param string $src @param string $class @param string $alt */
function jio_header_slider_image(string $src, string $class, string $alt): string {
$lazy = function_exists('jio_is_lazy') && jio_is_lazy('lazy_sider');
if ($lazy) {
$class .= ' swiper-lazy';
}
$attrs = jio_get_lazy_attr('lazy_sider', $src, $class, jio_get_lazy_thumb('lg'));
return '<img' . $attrs . ' alt="' . esc_attr($alt) . '">';
}
}
if (!function_exists('jio_get_header_slider_markup')) {
/** @param array<string,mixed> $options */
function jio_get_header_slider_markup(array $options): string {
$options = wp_parse_args($options, [
'class' => 'slide-index slide-header',
'direction' => 'horizontal',
'pagination' => true,
'pagination_type' => '',
'effect' => 'slide',
'button' => true,
'loop' => true,
'scale_height' => false,
'blur_bg' => false,
'gradient_bg' => false,
'scale' => 40,
'auto_height' => false,
'm_height' => 280,
'pc_height' => 550,
'autoplay' => true,
'interval' => 6,
'speed' => 0,
'spacebetween' => 0,
'slides' => [],
]);
if (empty($options['slides'][0])) {
return '';
}
$is_mobile = wp_is_mobile();
$lazy = function_exists('jio_is_lazy') && jio_is_lazy('lazy_sider');
$slides_html = '';
$slide_count = 0;
$allow = jio_header_slider_allowed_html();
$site_suffix = ' - ' . get_bloginfo('name');
foreach ((array) $options['slides'] as $slide) {
if (!is_array($slide)) {
continue;
}
$hide = sanitize_key((string) ($slide['hide'] ?? ''));
if ((!$is_mobile && $hide === 'pc') || ($is_mobile && $hide === 'm')) {
continue;
}
$background = esc_url((string) ($slide['background'] ?? ''));
$background_video = esc_url((string) ($slide['background_video'] ?? ''));
$video = esc_url((string) ($slide['video'] ?? ''));
$text = is_array($slide['text'] ?? null) ? $slide['text'] : [];
$link = is_array($slide['link'] ?? null) ? $slide['link'] : [];
$title = (string) ($text['title'] ?? '');
$alt = trim(wp_strip_all_tags($title));
if ($alt === '') {
$alt = trim(wp_strip_all_tags((string) ($link['text'] ?? '')));
}
$alt = $alt !== '' ? $alt . $site_suffix : __('幻灯片', 'jio') . $site_suffix;
$slide_class = trim((string) ($slide['class'] ?? ''));
$background_html = '';
if ($background_video !== '' && !$is_mobile) {
$slide_class .= ' slide-background-video';
$background_html = '<video autoplay="" loop="" muted="" class="fit-cover radius8' . ($lazy ? ' lazyload' : '') . '"'
. ($lazy ? ' data-src="' . esc_url($background_video) . '" src=""' : ' src="' . esc_url($background_video) . '"')
. ($background !== '' ? ' poster="' . esc_url($background) . '"' : '') . '></video><div class="absolute"></div>';
} elseif ($video !== '') {
$slide_class .= ' slide-dplayer';
$background_html = '<div class="new-dplayer" video-url="' . esc_url($video) . '" video-type="auto"><div class="graphic" style="padding-bottom:50%;"><div class="abs-center text-center"><i class="fas fa-play-circle fa-4x muted-3-color opacity5" aria-hidden="true"></i></div></div></div>';
if ($background !== '') {
$poster_class = 'absolute dplayer-poster' . (!empty($options['gradient_bg']) ? ' gradient-bg' : '');
$poster_attrs = !empty($options['gradient_bg']) ? ' data-opacity="0.2"' : '';
$background_html .= '<div class="' . esc_attr($poster_class) . '"' . $poster_attrs . '>'
. jio_header_slider_image($background, 'no-imgbox radius8', $alt)
. '<div class="absolute flex jc play-icon"><span class="toggle-radius"><i class="fas fa-play" aria-hidden="true"></i></span></div></div>';
}
} elseif ($background !== '') {
$background_html = jio_header_slider_image($background, 'radius8', $alt);
}
if ($background_html === '') {
continue;
}
$blur_html = '';
if (!empty($options['blur_bg']) && $background !== '') {
$blur_html = '<div class="slide-blur-bg">' . jio_header_slider_image($background, 'no-imgbox', $alt) . '</div>';
}
$layers_html = '';
foreach ((array) ($slide['image_layer'] ?? []) as $layer) {
if (!is_array($layer) || empty($layer['image'])) {
continue;
}
$layer_class = 'absolute';
if (!empty($layer['free_size'])) {
$align = in_array(($layer['align'] ?? ''), ['left', 'center', 'right'], true) ? $layer['align'] : 'center';
$layer_class .= ' slide-layer text-' . $align;
}
$layer_attrs = '';
$parallax = (int) ($layer['parallax'] ?? 0);
if ($parallax !== 0) {
$layer_attrs .= ' data-swiper-parallax="' . esc_attr((string) $parallax) . '%"';
$opacity = max(1, min(100, (int) ($layer['parallax_opacity'] ?? 100)));
if ($opacity !== 100) {
$layer_attrs .= ' data-swiper-parallax-opacity="' . esc_attr((string) ($opacity / 100)) . '"';
}
}
$scale = max(1, min(200, (int) ($layer['parallax_scale'] ?? 100)));
if ($scale !== 100) {
$layer_attrs .= ' data-swiper-parallax-scale="' . esc_attr((string) ($scale / 100)) . '"';
}
$layers_html .= '<div class="' . esc_attr($layer_class) . '"' . $layer_attrs . '>' . jio_header_slider_image((string) $layer['image'], 'radius8', $alt) . '</div>';
}
$text_html = '';
if ($title !== '') {
$align = sanitize_html_class((string) ($text['text_align'] ?? 'left-bottom'));
$text_style = '--text-size-pc:' . max(12, min(50, (int) ($text['text_size_pc'] ?? 30))) . 'px;'
. '--text-size-m:' . max(12, min(50, (int) ($text['text_size_m'] ?? 20))) . 'px;';
$text_html = '<div class="abs-center slide-text ' . esc_attr($align) . '" style="' . esc_attr($text_style) . '"><div class="slide-title">'
. wp_kses($title, $allow) . '</div>';
if (!empty($text['desc'])) {
$text_html .= '<div class="slide-desc">' . wp_kses((string) $text['desc'], $allow) . '</div>';
}
$text_html .= '</div>';
$parallax = (int) ($text['parallax'] ?? 0);
if ($parallax !== 0) {
$text_html = '<div class="absolute" data-swiper-parallax="' . esc_attr((string) $parallax) . '">' . $text_html . '</div>';
}
}
$slide_attrs = '';
if (!empty($options['gradient_bg'])) {
$slide_class .= ' gradient-bg';
$slide_attrs .= ' data-opacity="0.2"';
}
$url = esc_url((string) ($link['url'] ?? ''));
$target = !empty($link['target']) ? ' target="_blank" rel="noopener noreferrer"' : '';
$slides_html .= '<div class="swiper-slide ' . esc_attr(trim($slide_class)) . '"' . $slide_attrs . '>' . $blur_html;
$slides_html .= $url !== '' ? '<a href="' . esc_url($url) . '"' . $target . '>' : '<span>';
$slides_html .= $background_html . $layers_html . $text_html;
$slides_html .= $url !== '' ? '</a>' : '</span>';
$slides_html .= '</div>';
$slide_count++;
}
if ($slide_count === 0) {
return '';
}
$class = trim((string) $options['class']);
$class .= !empty($options['blur_bg']) ? ' blur-background' : '';
$class .= !empty($options['gradient_bg']) ? ' gradient-background' : '';
$class .= $slide_count === 1 ? ' swiper-container-initialized' : '';
$attrs = ' data-direction="' . esc_attr((string) $options['direction']) . '" data-effect="' . esc_attr((string) $options['effect']) . '"';
$attrs .= !empty($options['loop']) ? ' data-loop="true"' : '';
$attrs .= !empty($options['autoplay']) ? ' data-autoplay="1" data-interval="' . esc_attr((string) ((int) $options['interval'] < 999 ? (int) $options['interval'] * 1000 : (int) $options['interval'])) . '"' : '';
$attrs .= (int) $options['speed'] > 299 ? ' data-speed="' . esc_attr((string) (int) $options['speed']) . '"' : '';
$attrs .= isset($options['spacebetween']) ? ' data-spaceBetween="' . esc_attr((string) (int) $options['spacebetween']) . '"' : '';
if (!empty($options['pagination_type']) && !empty($options['pagination']) && $slide_count > 1) {
$attrs .= ' data-pagination-type="' . esc_attr((string) $options['pagination_type']) . '"';
}
if (!empty($options['scale_height']) && $options['direction'] !== 'vertical') {
$class .= ' scale-height';
$style = '--scale-height :' . max(10, min(300, (int) $options['scale'])) . '%';
} elseif (!empty($options['auto_height']) && $options['direction'] !== 'vertical') {
$attrs .= ' auto-height="true"';
$style = '--max-height :' . max(120, (int) ($options['max_height'] ?? 500)) . 'px;--min-height :' . max(100, (int) ($options['min_height'] ?? 180)) . 'px;';
} else {
$style = '--m-height :' . max(100, (int) $options['m_height']) . 'px;--pc-height :' . max(120, (int) $options['pc_height']) . 'px;';
}
$controls = '';
if ($slide_count > 1 && !empty($options['button'])) {
$controls .= '<div class="swiper-button-prev"></div><div class="swiper-button-next"></div>';
}
if ($slide_count > 1 && !empty($options['pagination'])) {
$pagination_class = !empty($options['pagination_type'])
? ' scroll-x no-scrollbar pagination-type-' . sanitize_html_class((string) $options['pagination_type'])
: '';
$controls .= '<div class="swiper-pagination kaoyou' . esc_attr($pagination_class) . '"></div>';
}
return '<div class="relative jio-slider"><div class="new-swiper ' . esc_attr(trim($class)) . '"' . $attrs . ' style="' . esc_attr($style) . '"><div class="swiper-wrapper">'
. $slides_html . '</div>' . $controls . '</div></div>';
}
}
if (!function_exists('jio_header_slide')) {
function jio_header_slide(): void {
if (!jio_header_slide_is_show()) {
return;
}
$args = jio_get_header_slider_args();
$slides = (array) ($args['header_slider'] ?? []);
$options = (array) ($args['header_slider_option'] ?? []);
if (empty($slides[0])) {
return;
}
$options['slides'] = $slides;
$options['class'] = 'slide-index slide-header';
$search_html = '';
if (jio_header_slider_device_is_visible($args['header_slider_search_s'] ?? [])) {
$search_options = wp_parse_args((array) ($args['header_slider_search_option'] ?? []), [
'class' => '', 'show_keywords' => false, 'show_history' => false,
'show_posts' => false, 'show_input_cat' => false, 'more_cats' => [],
'in_cat' => '', 'show_type' => false, 'in_type' => 'post', 'in_user' => '',
'before_html' => '', 'after_html' => '',
]);
if (wp_is_mobile()) {
$search_options['show_keywords'] = false;
}
$before = $search_options['before_html'] !== '' ? '<div class="header-slider-search-more text-center before">' . wp_kses((string) $search_options['before_html'], jio_header_slider_allowed_html()) . '</div>' : '';
$after = $search_options['after_html'] !== '' ? '<div class="header-slider-search-more after">' . wp_kses((string) $search_options['after_html'], jio_header_slider_allowed_html()) . '</div>' : '';
unset($search_options['before_html'], $search_options['after_html']);
$box = function_exists('jio_get_search_box') ? (string) jio_get_search_box($search_options) : '';
$search_html = '<div class="header-slider-search abs-center">' . $before . $box . $after . '</div>';
}
$cards_html = '';
$card_count = 0;
if (jio_header_slider_device_is_visible($args['header_slider_card_s'] ?? [])) {
$card_options = wp_parse_args((array) ($args['header_slider_card_option'] ?? []), [
'icon_radius4' => false, 'show_widget_bg' => false, 'cards' => [],
]);
// With module background the card shrinks to padding-10 inside a
// .jio-widget-box wrapper (.jio-panel here); the bg-less variant
// stretches each card in a .flex1 column.
$show_bg = !empty($card_options['show_widget_bg']);
$items = '';
foreach ((array) $card_options['cards'] as $card) {
if (!is_array($card) || (empty($card['icon']) && empty($card['customize_icon']) && empty($card['custom_icon']) && empty($card['icon_image']))) {
continue;
}
$card['class'] = $show_bg ? 'padding-10' : 'jio-panel';
$card['icon_class'] = trim((string) ($card['icon_class'] ?? '') . (!empty($card_options['icon_radius4']) ? ' radius4' : ''));
$inner = function_exists('jio_icon_cover_card') ? jio_icon_cover_card($card) : '';
if ($inner === '') {
continue;
}
$items .= '<div class="' . (!$show_bg ? 'flex1' : 'relative-h') . '">' . $inner . '</div>';
$card_count++;
}
if ($items !== '') {
$cards_html = '<div class="header-slider-card container">'
. ($show_bg ? '<div class="jio-panel padding-10">' : '<div class="">')
. '<div class="flex jse flex-row gutters-5 flex-col-sm-2">' . $items . '</div></div></div>';
}
}
$nav_color = \Jio\Core\Color::sanitize((string) ($args['header_slider_nav_color'] ?? ''));
if ($nav_color && $nav_color !== '#ffffff') {
echo '<style>body.nav-fixed:not(.body-scroll):not(.mobile-navbar-show) .header.show-slide{--header-color:' . esc_html($nav_color) . ';}</style>';
}
$settings = class_exists('\\Jio\\Settings\\Settings') ? \Jio\Settings\Settings::get_header_slider_settings() : [];
$filter_blur = jio_header_slider_device_is_visible($settings['filter_blur'] ?? []);
$slider_html = jio_get_header_slider_markup($options);
if ($slider_html === '') {
return;
}
echo '<div class="header-slider-container relative mb20 card-' . (int) $card_count . ($filter_blur ? ' filter-blur' : '') . '">';
echo $slider_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $search_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $cards_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '</div>';
}
}