fix(frontend): align search and header components with reference

This commit is contained in:
kate522 committed 2026-10-29 22:21:01 +08:00
1 parent 4c13ef478c
commit 542daca457
34 files changed
+803 -705

No files matched your search

+2 -2
View File
@@ -11,12 +11,12 @@ if (!function_exists('aksrt_get_ajax_null')) {
/**
* Empty state for AJAX list replace.
*/
function aksrt_get_ajax_null(?string $text = null, $margin = 60, string $img = 'null.svg'): string {
function aksrt_get_ajax_null(?string $text = null, $margin = 60, string $img = 'null.svg', int $width = 280): string {
if (null === $text) {
$text = __('内容空空如也', 'aksrt');
}
if (function_exists('aksrt_get_null')) {
return aksrt_get_null($text, $margin, $img, 'ajax-item aksrt-ajax-null');
return aksrt_get_null($text, $margin, $img, 'ajax-item aksrt-ajax-null', $width);
}
return '<div class="text-center ajax-item aksrt-ajax-null" style="padding:' . esc_attr((string) $margin) . 'px 0;">'
. '<p class="muted-3-color">' . esc_html((string) $text) . '</p></div>';
+8 -4
View File
@@ -214,7 +214,7 @@ if (!function_exists('aksrt_author_minicard')) :
* @param string $class
* @param bool $blur_bg
*/
function aksrt_author_minicard(int $user_id, string $class = '', bool $blur_bg = false): string {
function aksrt_author_minicard(int $user_id, string $class = '', bool $blur_bg = false, string $highlight_query = ''): string {
if ($user_id <= 0) {
return '';
}
@@ -240,6 +240,7 @@ if (!function_exists('aksrt_author_minicard')) :
'medal' => true,
'auth' => true,
'level' => true,
'highlight_query' => $highlight_query,
])
: '<a href="' . esc_url($home) . '">' . esc_html($user->display_name) . '</a>';
@@ -248,20 +249,23 @@ if (!function_exists('aksrt_author_minicard')) :
? aksrt_get_user_follow('focus-color px12 ml10 follow flex0 but', $user_id)
: '';
$desc = function_exists('aksrt_get_user_description') ? aksrt_get_user_description($user_id) : trim((string) get_user_meta($user_id, 'description', true));
$blur = '';
if ($blur_bg) {
$blur = '<div class="abs-blur-bg blur"><img' . aksrt_get_lazy_attr('lazy_avatar', $avatar_url, '', aksrt_get_lazy_thumb('sm')) . ' alt=""></div>';
}
$description = function_exists('aksrt_get_user_description') ? aksrt_get_user_description($user_id) : trim((string) get_user_meta($user_id, 'description', true));
$description_html = $highlight_query !== '' && function_exists('aksrt_renderer_highlight_text')
? aksrt_renderer_highlight_text($description, $highlight_query)
: esc_html($description);
return '<div class="author-minicard radius8 relative-h ' . esc_attr($class) . '">'
. $blur
. '<ul class="list-inline relative">'
. '<li>' . $avatar_box . '</li>'
. '<li><dl>'
. '<dt class="flex ac">' . $name . $follow . '</dt>'
. '<dd class="mt6 em09 muted-color text-ellipsis">' . esc_html($desc) . '</dd>'
. '<dd class="mt6 em09 muted-color text-ellipsis">' . $description_html . '</dd>'
. '</dl></li>'
. '</ul></div>';
}
+5 -1
View File
@@ -186,6 +186,7 @@ if (!function_exists('aksrt_get_user_name')) {
'auth' => true,
'level' => true,
'follow' => false,
'highlight_query' => '',
];
if (is_numeric($args)) {
$defaults['id'] = (int) $args;
@@ -221,7 +222,10 @@ if (!function_exists('aksrt_get_user_name')) {
}
}
$name_class = trim('display-name text-ellipsis ' . (string) $args['name_class']);
$name_link = '<a class="' . esc_attr($name_class) . '" href="' . esc_url($home) . '">' . esc_html($display) . '</a>';
$name_markup = !empty($args['highlight_query']) && function_exists('aksrt_renderer_highlight_text')
? aksrt_renderer_highlight_text((string) $display, (string) $args['highlight_query'])
: esc_html($display);
$name_link = '<a class="' . esc_attr($name_class) . '" href="' . esc_url($home) . '">' . $name_markup . '</a>';
$auth_html = '';
$medal_html = '';
+32 -9
View File
@@ -114,8 +114,11 @@ if (!function_exists('aksrt_header_slide_is_show')) {
return false;
}
// legacy (Zibll) renders the slider on paged archive pages too; no
// pagination exclusion here.
// Zibll only displays this component on the first archive page.
if ((int) $wp_query->get('paged') > 1) {
return false;
}
$settings = class_exists('\\AKSRT\\Settings\\Settings')
? \AKSRT\Settings\Settings::get_header_slider_settings()
: [];
@@ -199,6 +202,18 @@ if (!function_exists('aksrt_header_slider_allowed_html')) {
}
}
if (!function_exists('aksrt_header_slider_image')) {
/** @param string $src @param string $class @param string $alt */
function aksrt_header_slider_image(string $src, string $class, string $alt): string {
$lazy = function_exists('aksrt_is_lazy') && aksrt_is_lazy('lazy_sider');
if ($lazy) {
$class .= ' swiper-lazy';
}
$attrs = aksrt_get_lazy_attr('lazy_sider', $src, $class, aksrt_get_lazy_thumb('lg'));
return '<img' . $attrs . ' alt="' . esc_attr($alt) . '">';
}
}
if (!function_exists('aksrt_get_header_slider_markup')) {
/** @param array<string,mixed> $options */
function aksrt_get_header_slider_markup(array $options): string {
@@ -228,6 +243,7 @@ if (!function_exists('aksrt_get_header_slider_markup')) {
}
$is_mobile = wp_is_mobile();
$lazy = function_exists('aksrt_is_lazy') && aksrt_is_lazy('lazy_sider');
$slides_html = '';
$slide_count = 0;
$allow = aksrt_header_slider_allowed_html();
@@ -249,23 +265,30 @@ if (!function_exists('aksrt_get_header_slider_markup')) {
$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 : __('幻灯片', 'aksrt') . $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 playsinline class="fit-cover radius8" src="' . esc_url($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 = '<video controls playsinline preload="metadata" class="fit-cover radius8" src="' . esc_url($video) . '"'
. ($background !== '' ? ' poster="' . esc_url($background) . '"' : '') . '></video>';
$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="fa fa-play-circle fa-4x muted-3-color opacity5" aria-hidden="true"></i></div></div></div>';
if ($background !== '') {
$background_html .= '<div class="absolute dplayer-poster"><img class="no-imgbox radius8" src="' . esc_url($background) . '" alt="' . esc_attr($alt) . '"><div class="absolute flex jc play-icon"><span class="toggle-radius"><i class="fa fas fa-play" aria-hidden="true"></i></span></div></div>';
$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 . '>'
. aksrt_header_slider_image($background, 'no-imgbox radius8', $alt)
. '<div class="absolute flex jc play-icon"><span class="toggle-radius"><i class="fa fa-play" aria-hidden="true"></i></span></div></div>';
}
} elseif ($background !== '') {
$background_html = '<img class="radius8" src="' . esc_url($background) . '" alt="' . esc_attr($alt) . '">';
$background_html = aksrt_header_slider_image($background, 'radius8', $alt);
}
if ($background_html === '') {
@@ -274,7 +297,7 @@ if (!function_exists('aksrt_get_header_slider_markup')) {
$blur_html = '';
if (!empty($options['blur_bg']) && $background !== '') {
$blur_html = '<div class="slide-blur-bg"><img class="no-imgbox" src="' . esc_url($background) . '" alt="' . esc_attr($alt) . '"></div>';
$blur_html = '<div class="slide-blur-bg">' . aksrt_header_slider_image($background, 'no-imgbox', $alt) . '</div>';
}
$layers_html = '';
@@ -300,7 +323,7 @@ if (!function_exists('aksrt_get_header_slider_markup')) {
if ($scale !== 100) {
$layer_attrs .= ' data-swiper-parallax-scale="' . esc_attr((string) ($scale / 100)) . '"';
}
$layers_html .= '<div class="' . esc_attr($layer_class) . '"' . $layer_attrs . '><img class="radius8" src="' . esc_url((string) $layer['image']) . '" alt="' . esc_attr($alt) . '"></div>';
$layers_html .= '<div class="' . esc_attr($layer_class) . '"' . $layer_attrs . '>' . aksrt_header_slider_image((string) $layer['image'], 'radius8', $alt) . '</div>';
}
$text_html = '';
+11 -2
View File
@@ -111,8 +111,17 @@ if (!function_exists('aksrt_renderer_highlight_text')) {
if (!$words) {
return esc_html($text);
}
$pattern = '/' . implode('|', array_map(static fn(string $word): string => preg_quote($word, '/'), $words)) . '/iu';
return (string) preg_replace($pattern, '<span class="focus-color">$0</span>', esc_html($text));
$pattern = '/(' . implode('|', array_map(static fn(string $word): string => preg_quote($word, '/'), $words)) . ')/iu';
$parts = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE);
if (!is_array($parts)) {
return esc_html($text);
}
$html = '';
foreach ($parts as $index => $part) {
$escaped = esc_html($part);
$html .= ($index % 2) === 1 ? '<b class="focus-color">' . $escaped . '</b>' : $escaped;
}
return $html;
}
}
+62 -45
View File
@@ -180,15 +180,6 @@ if (!function_exists('aksrt_get_search_box')) :
}
$args['placeholder'] = esc_attr((string) $args['placeholder']);
// Settings gates when caller left defaults on.
if (class_exists('\AKSRT\Settings\Settings')) {
if (!array_key_exists('show_keywords_forced', $args)
&& method_exists('\AKSRT\Settings\Settings', 'hot_search_enabled')
&& !\AKSRT\Settings\Settings::hot_search_enabled()) {
// Keep explicit false from caller; only gate when show_keywords true by default path.
}
}
$form_html = '';
if (!empty($args['show_form'])) {
$state = function_exists('aksrt_get_search_form_state')
@@ -201,33 +192,36 @@ if (!function_exists('aksrt_get_search_box')) :
'categories' => [],
];
$type_html = '';
$types = is_array($state['types'] ?? null) ? $state['types'] : [];
$in_type = (string) ($args['in_type'] ?: ($state['type'] ?? 'post'));
if (!empty($args['show_type']) && count($types) > 1) {
$type_items = '';
foreach ($types as $k => $v) {
$cls = $in_type === (string) $k ? ' active' : '';
$type_items .= '<a class="but' . esc_attr($cls) . '" data-for="type" data-value="'
. esc_attr((string) $k) . '" href="javascript:;">' . esc_html((string) $v) . '</a>';
}
$type_html = '<div class="flex jc mb10 search-type-but-average">';
$type_html .= '<div class="but-average radius">' . $type_items . '</div></div>';
}
$cat_html = '';
if (!empty($args['show_input_cat']) && !empty($state['category_enabled'])
&& !empty($state['categories']) && is_array($state['categories'])) {
$in_cat_id = (int) ($args['in_cat'] ?: ($state['category_id'] ?? 0));
$in_cat_name = '';
$all_cat = '<li data-for="trem" data-value="null"><a href="javascript:;" class="text-ellipsis">'
$category_terms = [];
if (!empty($args['show_input_cat'])) {
$category_ids = is_array($args['more_cats'])
? $args['more_cats']
: (preg_split('/[,,\s]+/', (string) $args['more_cats']) ?: []);
if ($category_ids && function_exists('aksrt_get_search_categories')) {
$category_terms = aksrt_get_search_categories($category_ids);
}
if ((int) $args['in_cat'] > 0) {
$selected_term = get_term((int) $args['in_cat']);
if ($selected_term && !is_wp_error($selected_term)) {
$selected_term_name = (string) $selected_term->name;
if (!$category_terms) {
$category_terms = [$selected_term];
}
}
}
}
if ($category_terms) {
$in_cat_id = (int) $args['in_cat'];
$in_cat_name = $in_cat_id > 0 ? (string) ($selected_term_name ?? '') : '';
$all_cat = '<li data-for="trem" data-value="null"><a href="javascript:;" class="text-ellipsis">'
. esc_html__('全部', 'aksrt') . '</a></li>';
foreach ($state['categories'] as $cat) {
if (!is_array($cat)) {
foreach ($category_terms as $cat) {
if (!$cat instanceof WP_Term) {
continue;
}
$cid = (int) ($cat['id'] ?? 0);
$cname = (string) ($cat['name'] ?? '');
$cid = (int) $cat->term_id;
$cname = (string) $cat->name;
if ($cid <= 0 || $cname === '') {
continue;
}
@@ -249,37 +243,57 @@ if (!function_exists('aksrt_get_search_box')) :
. $input_cat . '</div></div>';
}
$s = esc_attr(wp_strip_all_tags((string) $args['s']));
if ($s === '' && is_search()) {
$s = esc_attr(get_search_query());
$type_html = '';
$type_dropdown_html = '';
$types = is_array($state['types'] ?? null) ? $state['types'] : [];
$in_type = (string) ($args['in_type'] ?: ($state['type'] ?? 'post'));
if (!empty($args['show_type']) && count($types) > 1) {
$type_name = (string) ($types[$in_type] ?? reset($types));
if ($cat_html !== '') {
$type_items = '';
foreach ($types as $key => $label) {
$cls = $in_type === (string) $key ? ' active' : '';
$type_items .= '<a class="but' . esc_attr($cls) . '" data-for="type" data-value="'
. esc_attr((string) $key) . '" href="javascript:;">' . esc_html((string) $label) . '</a>';
}
$type_html = '<div class="flex jc mb10 search-type-but-average"><div class="but-average radius">'
. $type_items . '</div></div>';
} else {
$type_items = '';
foreach ($types as $key => $label) {
$type_items .= '<li><a href="javascript:;" class="text-ellipsis" data-for="type" data-value="'
. esc_attr((string) $key) . '">' . esc_html((string) $label) . '</a></li>';
}
$type_dropdown_html = '<div class="option-dropdown splitters-this-r search-drop"><div class="dropdown">'
. '<a href="javascript:;" class="padding-h10" data-toggle="dropdown"><span name="type">'
. esc_html($type_name) . '</span><i class="fa ml6 fa-sort opacity5" aria-hidden="true"></i></a>'
. '<ul class="dropdown-menu">' . $type_items . '</ul></div></div>';
}
}
$s = esc_attr(wp_strip_all_tags((string) $args['s']));
$input_html = '<div class="search-input-text">';
$input_html .= '<input type="text" name="s" class="line-form-input" tabindex="1" value="' . $s . '">';
$input_html .= '<i class="line-form-line"></i>';
$input_html .= '<div class="scale-placeholder' . ($s !== '' ? ' is-focus' : '') . '" default="'
. $args['placeholder'] . '">' . $args['placeholder'] . '</div>';
$input_html .= '<div class="abs-right muted-color"><button type="submit" tabindex="2" class="null" aria-label="'
. esc_attr__('搜索', 'aksrt') . '"><i class="fa fas fa-search" aria-hidden="true"></i></button></div>';
. esc_attr__('搜索', 'aksrt') . '"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-search"></use></svg></button></div>';
$input_html .= '</div>';
$input_html .= '<input type="hidden" name="type" value="' . esc_attr($in_type) . '">';
if ($cat_html !== '' || (string) $args['in_cat'] !== '') {
$input_html .= '<input type="hidden" name="trem" value="'
. esc_attr((string) ($args['in_cat'] !== '' ? $args['in_cat'] : ($state['category_id'] ?? 0))) . '">';
. esc_attr((string) $args['in_cat']) . '">';
}
if ((string) $args['in_user'] !== '') {
$input_html .= '<input type="hidden" name="user" value="' . esc_attr((string) $args['in_user']) . '">';
}
if ($cat_html === '') {
$cat_html = $type_html;
$type_html = '';
}
$form_html = '<form method="get" class="padding-10 search-form" action="'
. esc_url(home_url('/')) . '">'
. $type_html
. '<div class="line-form">' . $cat_html . $input_html . '</div>'
. '<div class="line-form">' . ($cat_html !== '' ? $cat_html : $type_dropdown_html) . $input_html . '</div>'
. '</form>';
}
@@ -318,7 +332,8 @@ if (!function_exists('aksrt_get_search_box')) :
if ($keyword_link !== '') {
$history_html = '<div class="search-keywords history-search">';
$history_html .= '<p class="muted-color"><span>' . esc_html__('历史搜索', 'aksrt') . '</span>';
$history_html .= '<a class="pull-right trash-history-search muted-3-color" href="javascript:;" aria-label="'
$history_html .= '<a class="pull-right trash-history-search muted-3-color" href="javascript:;" data-cookie-path="'
. esc_attr(COOKIEPATH ?: '/') . '" data-cookie-domain="' . esc_attr(COOKIE_DOMAIN) . '" aria-label="'
. esc_attr__('清空历史', 'aksrt') . '"><i class="fa fas fa-trash-alt em12" aria-hidden="true"></i></a></p>';
$history_html .= '<div>' . $keyword_link . '</div></div>';
}
@@ -345,7 +360,9 @@ if (!function_exists('aksrt_get_search_box')) :
}
}
$class = $args['class'] ? ' ' . sanitize_html_class((string) $args['class']) : '';
$class_tokens = preg_split('/\s+/', trim((string) $args['class'])) ?: [];
$class_tokens = array_values(array_filter(array_map('sanitize_html_class', $class_tokens)));
$class = $class_tokens ? ' ' . implode(' ', $class_tokens) : '';
$html = '<div class="search-input' . esc_attr($class) . '">'
. $form_html . $keywords_html . $history_html . $posts_html
. '</div>';
-67
View File
@@ -7,73 +7,6 @@
defined('ABSPATH') || exit;
// ============================================================
// 模板标签:图标覆盖卡片(顶部多功能组件叠加层)
// 完全模仿 legacy 的 legacy
// ============================================================
if (!function_exists('aksrt_render_icon_cover_card')):
/**
* 渲染单个图标覆盖卡片(模仿 legacy 的 legacy)
*
* 结构:左侧圆形/方形图标 + 右侧标题和描述
*
* @param array $card 卡片配置
* - icon: string Font Awesome 类名 (如 'fa fas fa-magic')
* - custom_icon: string 自定义 SVG/HTML 图标(优先于 icon)
* - icon_class: string 图标颜色类 (c-yellow, c-blue, c-green, c-red, c-orange, c-cyan, c-pink, jb-cyan, jb-green, jb-orange)
* - icon_shape: string 图标形状 'circle' | 'square'
* - title: string 主标题
* - desc: string 描述文字
* - url: string 跳转链接
* - target: string 链接打开方式 '_blank' | '_self'
* @return string HTML
*/
function aksrt_render_icon_cover_card(array $card): string {
// Prefer canonical legacy-aligned renderer.
if (function_exists('aksrt_icon_cover_card')) {
return aksrt_icon_cover_card($card);
}
$icon = $card['icon'] ?? 'fa fas fa-star';
$custom_icon = $card['custom_icon'] ?? ($card['customize_icon'] ?? '');
$icon_class = trim((string) ($card['icon_class'] ?? 'c-blue'));
if (($card['icon_shape'] ?? '') === 'square' && !str_contains($icon_class, 'radius4')) {
$icon_class .= ' radius4';
}
$title = $card['title'] ?? '';
$desc = $card['desc'] ?? '';
$url = $card['url'] ?? ($card['link']['url'] ?? '');
$target = $card['target'] ?? ($card['link']['target'] ?? '');
$tgt = ($target !== '' && $target !== '_self') ? ' target="' . esc_attr((string) $target) . '"' : '';
$icon_html = $custom_icon !== ''
? wp_kses_post((string) $custom_icon)
: '<i class="' . esc_attr((string) $icon) . ' em09" aria-hidden="true"></i>';
$icon_container = '<div class="icon-cover-icon badg cir ' . esc_attr($icon_class) . '" style="font-size: 25px;">' . $icon_html . '</div>';
$text_html = '<div class="icon-cover-desc ml10 flex1 px12-sm">';
if ($title !== '') {
$text_html .= '<div class="em12 text-ellipsis font-bold"> ' . aksrt_icon_card_kses((string) $title) . '</div>';
}
if ($desc !== '') {
$text_html .= '<div class="muted-color mt6 text-ellipsis"> ' . aksrt_icon_card_kses((string) $desc) . '</div>';
}
$text_html .= '</div>';
$card_inner = $icon_container . $text_html;
$cls = 'icon-cover-card flex ac ' . esc_attr((string) ($card['class'] ?? 'aksrt-panel'));
if ($url !== '') {
return '<a class="main-color" ' . ($tgt !== '' ? ltrim($tgt) . ' ' : '') . 'href="' . esc_url((string) $url) . '"><div class="' . $cls . '">' . $card_inner . '</div></a>';
}
return '<div class="' . $cls . '">' . $card_inner . '</div>';
}
endif;
// ============================================================
// 模板标签:友情链接
// ============================================================
+9 -3
View File
@@ -227,8 +227,14 @@ if (!function_exists('aksrt_get_search_categories')):
*
* @return WP_Term[]
*/
function aksrt_get_search_categories(): array {
$include = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::search_more_cat_obj() : [];
function aksrt_get_search_categories(?array $include = null): array {
if ($include === null) {
$include = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::search_more_cat_obj() : [];
}
$include = array_values(array_filter(array_map('absint', (array) $include)));
if (!$include) {
return [];
}
$args = [
'taxonomy' => 'category',
'hide_empty' => true,
@@ -335,7 +341,7 @@ if (!function_exists('aksrt_get_search_filter_url')):
/** Build a search filter URL while preserving the reference request contract. */
function aksrt_get_search_filter_url(array $changes): string {
$params = [
's' => get_search_query(),
's' => get_search_query(false),
'type' => function_exists('aksrt_get_search_form_type') ? aksrt_get_search_form_type() : 'post',
'trem' => isset($_REQUEST['trem']) ? absint(wp_unslash($_REQUEST['trem'])) : 0,
'user' => isset($_REQUEST['user']) ? absint(wp_unslash($_REQUEST['user'])) : 0,