181 lines
6.3 KiB
PHP
181 lines
6.3 KiB
PHP
<?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::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 ? (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' => $layout,
|
|
'mobile_layout' => $mobile_layout,
|
|
'mobile_align' => $mobile_align,
|
|
'fixed' => $nav_fixed,
|
|
'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,
|
|
'messages_url' => 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 '<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))) . '">';
|
|
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) {
|
|
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>';
|
|
|
|
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;
|