feat(nav): rewrite top header to zibll 1:1 DOM/CSS/JS contract
Replace hybrid site-nav/drawer shell with zibll navbar-top layouts 1/2/3, body.mobile-navbar-show drawer, wired NavWalker + aksrt_menu_options meta, nav_folding/chevron, VIP switches, and SPA/PHP schema parity. No dual-class compat paths.
This commit is contained in:
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
/**
|
||||
* Header shell orchestration (zibll zib_header contract).
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
if (!function_exists('aksrt_get_header_nav_context')) :
|
||||
/**
|
||||
* Shared header render context (settings + brand + user flags).
|
||||
*
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
function aksrt_get_header_nav_context(): array {
|
||||
static $ctx = null;
|
||||
if ($ctx !== null) {
|
||||
return $ctx;
|
||||
}
|
||||
|
||||
$settings = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::get_header_nav_settings()
|
||||
: [
|
||||
'fixed' => true,
|
||||
'search_enabled' => true,
|
||||
'user_menu' => true,
|
||||
'publish_btn' => true,
|
||||
'mobile_drawer' => true,
|
||||
'nav_style' => 'default',
|
||||
'max_width' => 1200,
|
||||
'scroll_down_hide' => true,
|
||||
'layout' => '1',
|
||||
'mobile_layout' => 'center',
|
||||
'mobile_align' => 'left',
|
||||
'nav_pay_vip' => true,
|
||||
'nav_user_pay_vip' => true,
|
||||
];
|
||||
|
||||
$site_name = get_bloginfo('name');
|
||||
$brand_name = function_exists('aksrt_get_site_logo_text') ? aksrt_get_site_logo_text() : $site_name;
|
||||
$brand_name = $brand_name !== '' ? $brand_name : $site_name;
|
||||
$logo_url = function_exists('aksrt_get_site_logo_url') ? trim((string) aksrt_get_site_logo_url()) : '';
|
||||
$logo_dark = function_exists('aksrt_get_site_logo_dark_url') ? trim((string) aksrt_get_site_logo_dark_url()) : '';
|
||||
$logo_width = function_exists('aksrt_get_site_logo_width') ? aksrt_get_site_logo_width() : 150;
|
||||
$logo_more = $logo_width > 0
|
||||
? 'style="height:36px;width:auto;max-width:' . max(36, (int) $logo_width) . 'px"'
|
||||
: 'style="height:36px;width:auto"';
|
||||
$logo_html = '';
|
||||
if ($logo_url !== '' || $logo_dark !== '') {
|
||||
$logo_html = function_exists('aksrt_get_adaptive_theme_img')
|
||||
? aksrt_get_adaptive_theme_img($logo_url, $logo_dark, $brand_name, $logo_more)
|
||||
: '';
|
||||
}
|
||||
|
||||
$theme_positions = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::get_theme_mode_button_positions()
|
||||
: ['pc_nav', 'm_menu'];
|
||||
|
||||
$can_publish = !empty($settings['publish_btn']) && (
|
||||
current_user_can('manage_options')
|
||||
|| (class_exists('\AKSRT\Core\FrontSubmit') && \AKSRT\Core\FrontSubmit::get_instance()->can_submit())
|
||||
);
|
||||
|
||||
$show_slide = function_exists('aksrt_header_slide_is_show')
|
||||
? aksrt_header_slide_is_show()
|
||||
: false;
|
||||
|
||||
$current_user = wp_get_current_user();
|
||||
$user_id = (int) $current_user->ID;
|
||||
$user_desc = $user_id > 0 ? (string) get_user_meta($user_id, 'description', true) : '';
|
||||
if ($user_desc === '' && $user_id > 0) {
|
||||
$user_desc = (string) $current_user->user_email;
|
||||
}
|
||||
|
||||
$ctx = [
|
||||
'settings' => $settings,
|
||||
'layout' => (string) ($settings['layout'] ?? '1'),
|
||||
'mobile_layout' => (string) ($settings['mobile_layout'] ?? 'center'),
|
||||
'mobile_align' => (string) ($settings['mobile_align'] ?? 'left'),
|
||||
'fixed' => !empty($settings['fixed']),
|
||||
'scroll_down_hide' => !empty($settings['scroll_down_hide']) && !empty($settings['fixed']),
|
||||
'search_enabled' => !empty($settings['search_enabled']),
|
||||
'user_menu' => !empty($settings['user_menu']),
|
||||
'mobile_drawer' => !empty($settings['mobile_drawer']),
|
||||
'nav_pay_vip' => !isset($settings['nav_pay_vip']) || !empty($settings['nav_pay_vip']),
|
||||
'nav_user_pay_vip' => !isset($settings['nav_user_pay_vip']) || !empty($settings['nav_user_pay_vip']),
|
||||
'max_width' => (int) ($settings['max_width'] ?? 1200),
|
||||
'brand_name' => $brand_name,
|
||||
'logo_html' => $logo_html,
|
||||
'has_logo' => $logo_html !== '',
|
||||
'theme_positions' => is_array($theme_positions) ? $theme_positions : [],
|
||||
'can_publish' => $can_publish,
|
||||
'show_slide' => $show_slide,
|
||||
'current_user' => $current_user,
|
||||
'user_id' => $user_id,
|
||||
'user_desc' => $user_desc,
|
||||
'unread_count' => ($user_id > 0 && function_exists('aksrt_get_user_unread_notification_count'))
|
||||
? (int) aksrt_get_user_unread_notification_count($user_id)
|
||||
: 0,
|
||||
'messages_url' => function_exists('aksrt_get_messages_page_url') ? aksrt_get_messages_page_url() : '',
|
||||
'orders_url' => function_exists('aksrt_get_orders_page_url') ? aksrt_get_orders_page_url() : '',
|
||||
'publish_url' => function_exists('aksrt_get_new_post_url') ? aksrt_get_new_post_url() : admin_url('post-new.php'),
|
||||
'theme_settings_url' => function_exists('aksrt_get_admin_settings_url')
|
||||
? aksrt_get_admin_settings_url('')
|
||||
: admin_url('admin.php?page=aksrt-settings'),
|
||||
'search_state' => function_exists('aksrt_get_search_form_state')
|
||||
? aksrt_get_search_form_state()
|
||||
: [
|
||||
'type' => 'post',
|
||||
'types' => ['post' => __('文章', 'aksrt')],
|
||||
'category_id' => 0,
|
||||
'category_enabled' => false,
|
||||
'categories' => [],
|
||||
],
|
||||
'search_placeholder' => function_exists('aksrt_get_search_placeholder')
|
||||
? aksrt_get_search_placeholder()
|
||||
: __('开启精彩搜索', 'aksrt'),
|
||||
'search_hot_keywords' => function_exists('aksrt_get_search_hot_keywords')
|
||||
? aksrt_get_search_hot_keywords()
|
||||
: [],
|
||||
];
|
||||
|
||||
if ($ctx['publish_url'] === '') {
|
||||
$ctx['publish_url'] = admin_url('post-new.php');
|
||||
}
|
||||
|
||||
return $ctx;
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_header')) :
|
||||
/**
|
||||
* Render top header + mobile drawer (+ optional slide after caller).
|
||||
*/
|
||||
function aksrt_header(): void {
|
||||
$ctx = aksrt_get_header_nav_context();
|
||||
$layout = $ctx['layout'];
|
||||
$header_class = [
|
||||
'header',
|
||||
'header-layout-' . $layout,
|
||||
];
|
||||
if (!empty($ctx['show_slide'])) {
|
||||
$header_class[] = 'show-slide';
|
||||
}
|
||||
if (!empty($ctx['scroll_down_hide'])) {
|
||||
$header_class[] = 'scroll-down-hide';
|
||||
}
|
||||
|
||||
$nav_class = [
|
||||
'navbar',
|
||||
'navbar-top',
|
||||
$ctx['mobile_layout'],
|
||||
];
|
||||
|
||||
$nav_style = '';
|
||||
if ((int) $ctx['max_width'] > 0) {
|
||||
$nav_style = ' style="--nav-max-width:' . (int) $ctx['max_width'] . 'px"';
|
||||
}
|
||||
|
||||
echo '<header class="' . esc_attr(implode(' ', array_map('sanitize_html_class', $header_class))) . '">';
|
||||
echo '<nav class="' . esc_attr(implode(' ', array_map('sanitize_html_class', $nav_class))) . '"' . $nav_style . '>';
|
||||
echo '<div class="container-fluid container-header">';
|
||||
|
||||
aksrt_navbar_header($ctx);
|
||||
|
||||
echo '<div class="collapse navbar-collapse">';
|
||||
if ('3' !== $layout) {
|
||||
aksrt_menu_items('primary', true);
|
||||
}
|
||||
if ('2' === $layout && !empty($ctx['search_enabled'])) {
|
||||
aksrt_get_menu_search($ctx);
|
||||
}
|
||||
aksrt_menu_button($ctx);
|
||||
if ('3' === $layout) {
|
||||
echo '<div class="navbar-right">';
|
||||
aksrt_menu_items('primary', true);
|
||||
echo '</div>';
|
||||
}
|
||||
echo '</div></div></nav></header>';
|
||||
|
||||
if (!empty($ctx['mobile_drawer'])) {
|
||||
aksrt_nav_mobile_shell($ctx);
|
||||
}
|
||||
|
||||
if (function_exists('aksrt_render_signout_modal')) {
|
||||
aksrt_render_signout_modal();
|
||||
}
|
||||
}
|
||||
endif;
|
||||
Reference in New Issue
Block a user