Files
wordpress-theme-aksrt/inc/helpers/header/aksrt-header-mobile.php
T
kate522 1d1fef50af 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.
2026-07-22 17:06:24 +08:00

132 lines
4.7 KiB
PHP

<?php
/**
* Mobile drawer (zibll zib_nav_mobile + mobile-header shell).
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
if (!function_exists('aksrt_nav_mobile_shell')) :
/**
* Full mobile header drawer + fixed-body.
*
* @param array<string,mixed> $ctx
*/
function aksrt_nav_mobile_shell(array $ctx): void {
$align = (string) ($ctx['mobile_align'] ?? 'left');
if (!in_array($align, ['top', 'left', 'right'], true)) {
$align = 'left';
}
$m_layout = (string) ($ctx['mobile_layout'] ?? 'center');
$fixed = !empty($ctx['fixed']);
$touch_attr = '';
if ($align !== 'top') {
// mini-touch.js reads data-mini-touch; direction via data-touch-direction.
$touch_attr = ' data-mini-touch="mobile-nav" data-touch-direction="' . esc_attr($align) . '"';
}
echo '<div class="mobile-header">';
echo '<nav' . $touch_attr . ' class="mobile-navbar visible-xs-block scroll-y mini-scrollbar '
. esc_attr($align) . '">';
if (!$fixed) {
aksrt_navbar_header($ctx);
}
$brand_name = (string) ($ctx['brand_name'] ?? get_bloginfo('name'));
$logo_inner = !empty($ctx['logo_html'])
? $ctx['logo_html']
: '<span class="navbar-logo-text">' . esc_html($brand_name) . '</span>';
echo '<div class="flex jsb ac mb20">';
echo '<div class="navbar-logo"><a href="' . esc_url(home_url('/')) . '">' . $logo_inner . '</a></div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '<button type="button" data-toggle-class="mobile-navbar-show" data-target="body" class="close" aria-label="'
. esc_attr__('关闭菜单', 'aksrt') . '"><i class="fas fa-times" aria-hidden="true"></i></button>';
echo '</div>';
aksrt_nav_mobile_content($ctx, $m_layout);
if (is_active_sidebar('mobile_nav_fluid')) {
echo '<div class="mobile-nav-widget">';
dynamic_sidebar('mobile_nav_fluid');
echo '</div>';
}
echo '</nav>';
echo '<div class="fixed-body" data-toggle-class="mobile-navbar-show" data-target="body"></div>';
echo '</div>';
}
endif;
if (!function_exists('aksrt_nav_mobile_content')) :
/**
* Mobile menu list + top toggles + user box.
*
* @param array<string,mixed> $ctx
* @param string $m_layout center|left
*/
function aksrt_nav_mobile_content(array $ctx, string $m_layout = 'center'): void {
$top_btns = '';
if (in_array('m_menu', (array) ($ctx['theme_positions'] ?? []), true)) {
$top_btns .= '<a href="javascript:;" class="toggle-theme toggle-radius" id="theme-toggle-mobile" title="'
. esc_attr__('切换亮暗色', 'aksrt') . '">';
$top_btns .= '<i class="fas fa-moon theme-icon-moon" aria-hidden="true"></i>';
$top_btns .= '<i class="fas fa-sun theme-icon-sun" aria-hidden="true" style="display:none"></i>';
$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="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')) {
$top_btns .= aksrt_get_translate_language_btn('pull-right');
}
if ($top_btns !== '') {
echo '<div class="flex ac pull-right" style="margin-right: -3px;">' . $top_btns . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
$location = has_nav_menu('mobile') ? 'mobile' : 'primary';
$walker = class_exists('\AKSRT\Frontend\NavWalker')
? new \AKSRT\Frontend\NavWalker(
function_exists('aksrt_get_menu_decoration_settings')
? aksrt_get_menu_decoration_settings()
: []
)
: null;
$args = [
'container' => false,
'echo' => false,
'fallback_cb' => false,
'depth' => 2,
'items_wrap' => '<ul class="mobile-menus theme-box">%3$s</ul>',
'theme_location' => $location,
];
if ($walker) {
$args['walker'] = $walker;
}
$menu = has_nav_menu($location) ? (string) wp_nav_menu($args) : '';
if ($menu === '' && $location !== 'primary' && has_nav_menu('primary')) {
$args['theme_location'] = 'primary';
$menu = (string) wp_nav_menu($args);
}
if ($menu === '' && is_super_admin()) {
$menu = '<ul class="mobile-menus theme-box"><li><a href="' . esc_url(admin_url('nav-menus.php')) . '">'
. esc_html__('添加导航菜单', 'aksrt') . '</a></li></ul>';
}
echo $menu; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
if (is_singular('post')) {
echo '<div class="posts-nav-box" data-title="' . esc_attr__('文章目录', 'aksrt') . '"></div>';
}
// User box at bottom of drawer.
if (!empty($ctx['user_menu'])) {
echo aksrt_header_user_box_html($ctx); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
endif;