*/ function aksrt_get_header_nav_context(): array { static $ctx = null; if ($ctx !== null) { return $ctx; } $settings = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::read_domain('page_display', 'header-nav') : []; $layout = sanitize_key((string) ($settings['header_layout'] ?? '1')); if (!in_array($layout, ['1', '2', '3'], true)) { $layout = '1'; } $mobile_layout = sanitize_key((string) ($settings['mobile_header_layout'] ?? 'center')); if (!in_array($mobile_layout, ['center', 'left'], true)) { $mobile_layout = 'center'; } $mobile_align = sanitize_key((string) ($settings['mobile_navbar_align'] ?? 'left')); if (!in_array($mobile_align, ['top', 'left', 'right'], true)) { $mobile_align = 'left'; } $nav_fixed = !isset($settings['nav_fixed']) || !empty($settings['nav_fixed']); $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 = (!isset($settings['nav_newposts']) || !empty($settings['nav_newposts'])) && ( 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 && function_exists('aksrt_get_user_description') ? aksrt_get_user_description($user_id) : ''; $notification_settings = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::notification_settings() : ['enabled' => false, 'icon_show' => []]; $ctx = [ 'settings' => $settings, 'layout' => $layout, 'mobile_layout' => $mobile_layout, 'mobile_align' => $mobile_align, 'scroll_down_hide' => (!isset($settings['nav_scroll_down_hide']) || !empty($settings['nav_scroll_down_hide'])) && $nav_fixed, '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, 'message_icon_positions' => (array) ($notification_settings['icon_show'] ?? []), 'messages_url' => !empty($notification_settings['enabled']) && function_exists('aksrt_get_messages_page_url') ? aksrt_get_messages_page_url() : '', 'orders_url' => function_exists('aksrt_get_user_center_tab_url') ? aksrt_get_user_center_tab_url('orders') : '', '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'], ]; echo '
'; echo '
'; aksrt_nav_mobile_shell($ctx); if (!empty($ctx['show_slide']) && function_exists('aksrt_header_slide')) { aksrt_header_slide(); } if (function_exists('aksrt_render_signout_modal')) { aksrt_render_signout_modal(); } } endif;