feat(nav): deep 1:1 zibll search-box + navbar-search + newposts unify

Port aksrt_get_search_box/posts for menu_search and layout 1/3 slide;
unify publish switch; expand user-box admin row; CSS/JS remote-box parity.
This commit is contained in:
kate522 committed 2026-07-22 17:06:24 +08:00
1 parent 70f7ef71e1
commit 1d1fef50af
19 files changed
+980 -267

No files matched your search

+29 -102
View File
@@ -1,6 +1,6 @@
<?php
/**
* Layout-2 menu search remote panel (zibll menu_search parity subset).
* Layout-2 menu search remote panel (zibll menu_search / zib_get_search_box).
*
* @package AKSRT
*/
@@ -20,21 +20,10 @@ if (!function_exists('aksrt_ajax_menu_search')) :
}
}
$html = aksrt_get_menu_search_panel_html();
if ($html === '') {
if (!function_exists('aksrt_get_search_box')) {
wp_die('0');
}
echo '<div class="dropdown-menu hover-show-con navbar-inline-search-panel is-open">' . $html . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
wp_die();
}
endif;
if (!function_exists('aksrt_get_menu_search_panel_html')) :
/**
* Build inner search panel HTML (no outer dropdown wrapper).
*/
function aksrt_get_menu_search_panel_html(): string {
$show_keywords = true;
$show_history = true;
$show_posts = true;
@@ -50,100 +39,38 @@ if (!function_exists('aksrt_get_menu_search_panel_html')) :
: !empty(\AKSRT\Settings\Settings::get_value('search_posts', true));
}
$out = '';
$search = aksrt_get_search_box([
'show_form' => false,
'show_keywords' => $show_keywords,
'show_history' => $show_history,
'show_posts' => $show_posts,
]);
// History (client may also fill via localStorage; server returns logged-in history).
if ($show_history) {
$hist = [];
if (is_user_logged_in()) {
$saved = get_user_meta(get_current_user_id(), 'aksrt_search_history', true);
if (is_array($saved)) {
foreach (array_slice($saved, 0, 10) as $item) {
if (is_array($item) && !empty($item['keyword'])) {
$hist[] = (string) $item['keyword'];
} elseif (is_string($item) && $item !== '') {
$hist[] = $item;
}
}
}
}
$out .= '<div class="aksrt-menu-search-history" data-aksrt-menu-history="1">';
$out .= '<div class="flex jsb ac mb6"><span class="muted-2-color em09">' . esc_html__('搜索历史', 'aksrt') . '</span>';
$out .= '<a href="javascript:;" class="muted-2-color em09" data-aksrt-clear-menu-history="1">' . esc_html__('清空', 'aksrt') . '</a></div>';
$out .= '<div class="aksrt-menu-search-history__list">';
if ($hist) {
foreach ($hist as $kw) {
$out .= '<a class="but jb-sm" href="' . esc_url(home_url('/?s=' . rawurlencode($kw))) . '">' . esc_html($kw) . '</a> ';
}
} else {
$out .= '<span class="muted-3-color em09" data-empty="1">' . esc_html__('暂无历史', 'aksrt') . '</span>';
}
$out .= '</div></div>';
if ($search === '' || $search === null) {
wp_die('0');
}
// Search type chips (when multi-type search enabled).
$types = [];
if (function_exists('aksrt_get_search_type_options')) {
$types = aksrt_get_search_type_options();
}
if (is_array($types) && count($types) > 1) {
$out .= '<div class="aksrt-menu-search-types flex jc mb10">';
foreach ($types as $k => $label) {
$out .= '<a href="javascript:;" class="but" data-aksrt-menu-search-type="' . esc_attr((string) $k) . '">' . esc_html((string) $label) . '</a>';
}
$out .= '</div>';
}
// zibll contract: outer dropdown + inner .search-input.
echo '<div class="dropdown-menu hover-show-con">' . $search . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
wp_die();
}
endif;
// Hot keywords.
if ($show_keywords) {
$hots = function_exists('aksrt_get_search_hot_keywords') ? aksrt_get_search_hot_keywords() : [];
if ($hots) {
$title = class_exists('\AKSRT\Settings\Settings') && method_exists('\AKSRT\Settings\Settings', 'search_popular_title')
? \AKSRT\Settings\Settings::search_popular_title()
: __('热门搜索', 'aksrt');
$out .= '<div class="aksrt-menu-search-hots mt10">';
$out .= '<div class="muted-2-color em09 mb6">' . esc_html($title) . '</div>';
$out .= '<div class="navbar-inline-search-hots">';
foreach ($hots as $kw) {
$kw = trim((string) $kw);
if ($kw === '') {
continue;
}
$out .= '<a class="but jb-sm" href="' . esc_url(home_url('/?s=' . rawurlencode($kw))) . '">' . esc_html($kw) . '</a> ';
}
$out .= '</div></div>';
}
// Panel builder retained as thin alias for any external callers.
if (!function_exists('aksrt_get_menu_search_panel_html')) :
/**
* @return string Inner HTML (without dropdown wrapper).
*/
function aksrt_get_menu_search_panel_html(): string {
if (!function_exists('aksrt_get_search_box')) {
return '';
}
// Latest / popular posts (optional).
if ($show_posts) {
$posts = get_posts([
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 6,
'ignore_sticky_posts' => true,
'no_found_rows' => true,
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
]);
if ($posts) {
$out .= '<div class="aksrt-menu-search-posts mt10">';
$out .= '<div class="muted-2-color em09 mb6">' . esc_html__('推荐内容', 'aksrt') . '</div>';
$out .= '<div class="aksrt-menu-search-posts__list">';
foreach ($posts as $p) {
$out .= '<a class="aksrt-menu-search-posts__item" href="' . esc_url(get_permalink($p)) . '">';
$out .= '<span class="title text-ellipsis">' . esc_html(get_the_title($p)) . '</span>';
$out .= '<span class="meta muted-3-color em09">' . esc_html(get_the_date('', $p)) . '</span>';
$out .= '</a>';
}
$out .= '</div></div>';
}
}
// Live suggestions mount point.
$out .= '<div class="aksrt-menu-search-suggest mt10" data-aksrt-menu-suggest="1" hidden></div>';
return $out;
return (string) aksrt_get_search_box([
'show_form' => false,
'show_keywords' => true,
'show_history' => true,
'show_posts' => true,
]);
}
endif;
+1 -1
View File
@@ -77,7 +77,7 @@ if (!function_exists('aksrt_nav_mobile_content')) :
$top_btns .= '</a>';
}
if ($m_layout !== 'center' && !empty($ctx['search_enabled'])) {
$top_btns .= '<a href="javascript:;" class="toggle-radius main-search-btn" data-toggle-class data-target=".navbar-search" aria-label="'
$top_btns .= '<a href="javascript:;" class="toggle-radius main-search-btn" data-toggle-class="show" data-target=".navbar-search" aria-label="'
. esc_attr__('打开搜索', 'aksrt') . '"><i class="fas fa-search" aria-hidden="true"></i></a>';
}
if (function_exists('aksrt_get_translate_language_btn')) {
+27 -22
View File
@@ -77,7 +77,7 @@ if (!function_exists('aksrt_navbar_header')) :
$button .= '<i class="em12 css-icon i-menu"><i></i></i></button>';
if (($ctx['mobile_layout'] ?? 'center') === 'center' && !empty($ctx['search_enabled'])) {
$button .= '<button type="button" class="navbar-toggle main-search-btn nav-search-btn" data-toggle-class data-target=".navbar-search" aria-label="'
$button .= '<button type="button" class="navbar-toggle main-search-btn nav-search-btn" data-toggle-class="show" data-target=".navbar-search" aria-label="'
. esc_attr__('打开搜索', 'aksrt') . '">';
$button .= '<i class="fas fa-search" aria-hidden="true"></i></button>';
}
@@ -100,33 +100,27 @@ if (!function_exists('aksrt_get_menu_search')) :
return;
}
$placeholder = (string) ($ctx['search_placeholder'] ?? __('搜索内容', 'aksrt'));
$state = is_array($ctx['search_state'] ?? null) ? $ctx['search_state'] : [];
$type = (string) ($state['type'] ?? 'post');
$cat_enabled = !empty($state['category_enabled']);
$cat_id = (int) ($state['category_id'] ?? 0);
// zibll remote-box: panel HTML loaded via ajax action menu_search.
$remote_url = add_query_arg(
[
'action' => 'aksrt_menu_search',
],
admin_url('admin-ajax.php')
);
// zibll: form + input + remote-box (action=menu_search).
echo '<form method="get" class="navbar-form navbar-left hover-show" action="' . esc_url(home_url('/')) . '" role="search" data-aksrt-search-form="inline">';
echo '<div class="form-group relative dropdown">';
echo '<input type="hidden" name="aksrt_search_type" value="' . esc_attr($type) . '">';
if ($cat_enabled) {
echo '<input type="hidden" name="aksrt_category" value="' . esc_attr((string) $cat_id) . '">';
}
echo '<input type="text" class="form-control search-input focus-show" name="s" value="'
. esc_attr(get_search_query()) . '" placeholder="' . esc_attr($placeholder) . '" autocomplete="off">';
echo '<div class="abs-right muted-3-color"><button type="submit" class="null" aria-label="'
. esc_attr__('搜索', 'aksrt') . '"><i class="fas fa-search" aria-hidden="true"></i></button></div>';
// Remote panel mount (zibll remote-box / lazyload-action=ias).
echo '<div class="aksrt-remote-box lazyload" remote-box="' . esc_url($remote_url) . '" lazyload-action="ias" data-aksrt-menu-search-remote="1">';
echo '<i class="loading-spot"><i></i></i>';
echo '</div>';
if (function_exists('aksrt_get_remote_box')) {
echo aksrt_get_remote_box([ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
'class' => '',
'loader' => ' ',
'query' => [
'action' => 'menu_search',
],
]);
} else {
$remote_url = add_query_arg(['action' => 'menu_search'], admin_url('admin-ajax.php'));
echo '<div class="lazyload" remote-box="' . esc_url($remote_url) . '" lazyload-action="ias">';
echo '<i class="loading-spot"><i></i></i></div>';
}
echo '</div></form>';
}
endif;
@@ -224,6 +218,17 @@ if (!function_exists('aksrt_header_user_box_html')) :
$href .= '<a rel="nofollow" target="_blank" href="' . esc_url((string) $ctx['theme_settings_url']) . '">';
$href .= '<div class="badg mb6 toggle-radius c-yellow"><i class="fas fa-sliders-h" aria-hidden="true"></i></div>';
$href .= '<div class="c-yellow">' . esc_html__('主题设置', 'aksrt') . '</div></a>';
// zibll: 模块布局 → widgets.
$href .= '<a rel="nofollow" target="_blank" href="' . esc_url(admin_url('widgets.php')) . '">';
$href .= '<div class="badg mb6 toggle-radius c-yellow"><i class="fas fa-chart-pie" aria-hidden="true"></i></div>';
$href .= '<div class="c-yellow">' . esc_html__('模块布局', 'aksrt') . '</div></a>';
// zibll: 商城中心.
$shop_url = post_type_exists('aksrt_product')
? admin_url('edit.php?post_type=aksrt_product')
: admin_url('admin.php?page=aksrt_pay');
$href .= '<a rel="nofollow" target="_blank" href="' . esc_url($shop_url) . '">';
$href .= '<div class="badg mb6 toggle-radius c-yellow"><i class="fas fa-shopping-bag" aria-hidden="true"></i></div>';
$href .= '<div class="c-yellow">' . esc_html__('商城中心', 'aksrt') . '</div></a>';
$href .= '<a rel="nofollow" target="_blank" href="' . esc_url(admin_url()) . '">';
$href .= '<div class="badg mb6 toggle-radius c-yellow"><i class="fas fa-cog" aria-hidden="true"></i></div>';
$href .= '<div class="c-yellow">' . esc_html__('后台管理', 'aksrt') . '</div></a>';
@@ -346,7 +351,7 @@ if (!function_exists('aksrt_menu_button')) :
$search_but = '';
if ('2' !== $layout && !empty($ctx['search_enabled'])) {
$search_but = '<li class="relative"><a href="javascript:;" class="btn nav-search-btn main-search-btn" data-toggle-class data-target=".navbar-search" aria-label="'
$search_but = '<li class="relative"><a href="javascript:;" class="btn nav-search-btn main-search-btn" data-toggle-class="show" data-target=".navbar-search" aria-label="'
. esc_attr__('打开搜索', 'aksrt') . '"><i class="fas fa-search" aria-hidden="true"></i></a></li>';
}
+11 -3
View File
@@ -183,8 +183,16 @@ if (!function_exists('aksrt_header')) :
aksrt_nav_mobile_shell($ctx);
}
if (function_exists('aksrt_render_signout_modal')) {
aksrt_render_signout_modal();
}
// Layout 1/3 search slide (zibll .navbar-search). Layout-2 uses inline menu_search.
if (!empty($ctx['search_enabled'])) {
$navbar_search = locate_template('templates/parts/navbar-search.php');
if ($navbar_search) {
include $navbar_search;
}
}
if (function_exists('aksrt_render_signout_modal')) {
aksrt_render_signout_modal();
}
}
endif;