Files
wordpress-theme-aksrt/inc/helpers/header/aksrt-header-mobile.php
T

124 lines
4.3 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') {
$touch_attr = ' mini-touch="mobile-nav" 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">' . $logo_inner . '</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') . '"><svg class="ic-close" aria-hidden="true"><use xlink:href="#icon-close"></use></svg></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="fa fas fa-toggle-theme" aria-hidden="true"></i>';
$top_btns .= '</a>';
}
if ($m_layout !== 'center') {
$top_btns .= '<a href="javascript:;" class="toggle-radius main-search-btn" aria-label="'
. esc_attr__('打开搜索', 'aksrt') . '"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-search"></use></svg></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()
: 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.
echo aksrt_header_user_box_html($ctx); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
endif;