*/ function aksrt_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('aksrt_get_page_header_slider_config')) { /** @return array */ function aksrt_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('aksrt_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. */ function aksrt_header_slide_current_page_type(): string { if ((string) get_query_var('aksrt_message_view') !== '') { return 'page'; } if (is_author() || (function_exists('aksrt_is_user_home_page') && aksrt_is_user_home_page())) { return 'author'; } if (function_exists('aksrt_is_user_center_page') && aksrt_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 (aksrt_header_slide_excluded_page_templates() as $template) { if (is_page_template($template)) { return ''; } } return 'page'; } if (is_home()) { return 'home'; } return ''; } } if (!function_exists('aksrt_header_slide_matches_query')) { function aksrt_header_slide_matches_query(string $type): bool { $type = sanitize_key($type); if ($type === 'user_home') { $type = 'author'; } return $type !== '' && $type === aksrt_header_slide_current_page_type(); } } if (!function_exists('aksrt_header_slide_is_show')) { function aksrt_header_slide_is_show(): bool { global $wp_query; if (is_admin() || !($wp_query instanceof WP_Query)) { return false; } if ((int) $wp_query->get('paged') > 1 || (int) $wp_query->get('page') > 1) { return false; } $settings = class_exists('\\AKSRT\\Settings\\Settings') ? \AKSRT\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 (aksrt_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 = aksrt_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('aksrt_get_header_slider_args')) { /** @return array */ function aksrt_get_header_slider_args(): array { $page_config = aksrt_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('\\AKSRT\\Settings\\Settings') ? \AKSRT\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('aksrt_header_slider_allowed_html')) { /** @return array> */ function aksrt_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('aksrt_get_header_slider_markup')) { /** @param array $options */ function aksrt_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(); $slides_html = ''; $slide_count = 0; $allow = aksrt_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)); $alt = $alt !== '' ? $alt . $site_suffix : __('幻灯片', 'aksrt') . $site_suffix; $slide_class = trim((string) ($slide['class'] ?? '')); $background_html = ''; if ($background_video !== '' && !$is_mobile) { $slide_class .= ' slide-background-video'; $background_html = '
'; } elseif ($video !== '') { $slide_class .= ' slide-dplayer'; $background_html = ''; if ($background !== '') { $background_html .= '
' . esc_attr($alt) . '
'; } } elseif ($background !== '') { $background_html = '' . esc_attr($alt) . ''; } if ($background_html === '') { continue; } $blur_html = ''; if (!empty($options['blur_bg']) && $background !== '') { $blur_html = '
' . esc_attr($alt) . '
'; } $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 .= '
' . esc_attr($alt) . '
'; } $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 = '
' . wp_kses($title, $allow) . '
'; if (!empty($text['desc'])) { $text_html .= '
' . wp_kses((string) $text['desc'], $allow) . '
'; } $text_html .= '
'; $parallax = (int) ($text['parallax'] ?? 0); if ($parallax !== 0) { $text_html = '
' . $text_html . '
'; } } $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 .= '
' . $blur_html; $slides_html .= $url !== '' ? '' : ''; $slides_html .= $background_html . $layers_html . $text_html; $slides_html .= $url !== '' ? '' : ''; $slides_html .= '
'; $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 .= '
'; } 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 .= '
'; } return '
' . $slides_html . '
' . $controls . '
'; } } if (!function_exists('aksrt_header_slide')) { function aksrt_header_slide(): void { if (!aksrt_header_slide_is_show()) { return; } $args = aksrt_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 (aksrt_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'] !== '' ? '
' . wp_kses((string) $search_options['before_html'], aksrt_header_slider_allowed_html()) . '
' : ''; $after = $search_options['after_html'] !== '' ? '
' . wp_kses((string) $search_options['after_html'], aksrt_header_slider_allowed_html()) . '
' : ''; unset($search_options['before_html'], $search_options['after_html']); $box = function_exists('aksrt_get_search_box') ? (string) aksrt_get_search_box($search_options) : ''; $search_html = ''; } $cards_html = ''; $card_count = 0; if (aksrt_header_slider_device_is_visible($args['header_slider_card_s'] ?? [])) { $card_options = wp_parse_args((array) ($args['header_slider_card_option'] ?? []), [ 'icon_radius4' => false, 'cards' => [], ]); $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['icon_class'] = trim((string) ($card['icon_class'] ?? '') . (!empty($card_options['icon_radius4']) ? ' radius4' : '')); $inner = function_exists('aksrt_icon_cover_card') ? aksrt_icon_cover_card($card) : ''; if ($inner === '') { continue; } $items .= '
' . $inner . '
'; $card_count++; } if ($items !== '') { $cards_html = '
' . '
' . $items . '
'; } } $nav_color = sanitize_hex_color((string) ($args['header_slider_nav_color'] ?? '')); if ($nav_color && $nav_color !== '#ffffff') { echo ''; } $settings = class_exists('\\AKSRT\\Settings\\Settings') ? \AKSRT\Settings\Settings::get_header_slider_settings() : []; $filter_blur = aksrt_header_slider_device_is_visible($settings['filter_blur'] ?? []); $slider_html = aksrt_get_header_slider_markup($options); if ($slider_html === '') { return; } echo '
'; 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 '
'; } }