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

130 lines
5.2 KiB
PHP

<?php
/**
* Layout-2 menu search remote panel (zibll menu_search / zib_get_search_box).
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
if (!function_exists('aksrt_ajax_menu_search')) :
/**
* AJAX: HTML panel for navbar inline search (history + hot + posts).
*/
function aksrt_ajax_menu_search(): void {
$nonce = isset($_REQUEST['nonce'])
? sanitize_text_field(wp_unslash((string) $_REQUEST['nonce']))
: '';
if (!wp_verify_nonce($nonce, 'aksrt_public_nonce')) {
wp_die('0');
}
if (!function_exists('aksrt_get_search_box')) {
wp_die('0');
}
$show_keywords = true;
$show_history = true;
$show_posts = true;
if (class_exists('\AKSRT\Settings\Settings')) {
$show_keywords = method_exists('\AKSRT\Settings\Settings', 'hot_search_enabled')
? (bool) \AKSRT\Settings\Settings::hot_search_enabled()
: true;
$show_history = method_exists('\AKSRT\Settings\Settings', 'search_history_enabled')
? (bool) \AKSRT\Settings\Settings::search_history_enabled()
: true;
$show_posts = method_exists('\AKSRT\Settings\Settings', 'search_posts_enabled')
? (bool) \AKSRT\Settings\Settings::search_posts_enabled()
: !empty(\AKSRT\Settings\Settings::get_value('search_posts', true));
}
$search = aksrt_get_search_box([
'show_form' => false,
'show_keywords' => $show_keywords,
'show_history' => $show_history,
'show_posts' => $show_posts,
]);
if ($search === '' || $search === null) {
wp_die('0');
}
// zibll contract: outer dropdown + inner .search-input.
echo '<div class="dropdown-menu hover-show-con">' . $search . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
wp_die();
}
endif;
if (!function_exists('aksrt_ajax_search_box')) :
/**
* AJAX: full Zibll search box loaded into the footer shell on first open.
*/
function aksrt_ajax_search_box(): void {
$nonce = isset($_REQUEST['nonce'])
? sanitize_text_field(wp_unslash((string) $_REQUEST['nonce']))
: '';
if (!wp_verify_nonce($nonce, 'aksrt_public_nonce') || !function_exists('aksrt_get_search_box')) {
wp_die('0');
}
echo aksrt_get_search_box([ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
'show_form' => true,
'show_keywords' => !class_exists('\\AKSRT\\Settings\\Settings') || \AKSRT\Settings\Settings::hot_search_enabled(),
'show_history' => !class_exists('\\AKSRT\\Settings\\Settings') || \AKSRT\Settings\Settings::search_history_enabled(),
'show_posts' => !class_exists('\\AKSRT\\Settings\\Settings') || \AKSRT\Settings\Settings::search_posts_enabled(),
'show_type' => !class_exists('\\AKSRT\\Settings\\Settings') || (bool) \AKSRT\Settings\Settings::get_value('search_type', true),
'show_input_cat' => !class_exists('\\AKSRT\\Settings\\Settings') || \AKSRT\Settings\Settings::search_cat_enabled(),
]);
wp_die();
}
endif;
if (!function_exists('aksrt_footer_navbar_search')) :
/**
* Zibll footer search shell. The heavy search body is loaded once via remote-box.
*/
function aksrt_footer_navbar_search(): void {
$show_on_404 = class_exists('\\AKSRT\\Settings\\Settings')
? (bool) \AKSRT\Settings\Settings::get_value('404_search_s', true)
: true;
if (is_search() || (is_404() && $show_on_404)) {
return;
}
$remote = aksrt_get_remote_box([
'type' => 'load',
'class' => '',
'loader' => '<div class="search-input"><p><i class="placeholder s1 mr6"></i><i class="placeholder s1 mr6"></i><i class="placeholder s1 mr6"></i></p><p class="placeholder k2"></p><p class="placeholder t1"></p><p><i class="placeholder s1 mr6"></i><i class="placeholder s1 mr6"></i><i class="placeholder s1 mr6"></i><i class="placeholder s1 mr6"></i></p><p class="placeholder k1"></p><p class="placeholder t1"></p><p></p><p class="placeholder k1" style="height:80px;"></p></div>',
'query' => [
'action' => 'search_box',
'nonce' => wp_create_nonce('aksrt_public_nonce'),
],
]);
echo '<div mini-touch="nav_search" touch-direction="top" class="main-search fixed-body main-bg box-body navbar-search nopw-sm">';
echo '<div class="container">';
echo '<div class="mb20 search-close-box"><button type="button" class="but cir" data-toggle-class data-target=".navbar-search" aria-label="'
. esc_attr__('关闭搜索', 'aksrt') . '"><svg class="ic-close" aria-hidden="true"><use xlink:href="#icon-close"></use></svg></button></div>';
echo $remote; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '</div></div>';
}
endif;
if (!function_exists('aksrt_ajax_zibll_current_user_ping')) :
/** Satisfy the reference runtime's one-shot user-state refresh request. */
function aksrt_ajax_zibll_current_user_ping(): void {
wp_send_json_success([
'logged_in' => is_user_logged_in(),
'user_id' => get_current_user_id(),
]);
}
endif;
add_action('wp_ajax_menu_search', 'aksrt_ajax_menu_search');
add_action('wp_ajax_nopriv_menu_search', 'aksrt_ajax_menu_search');
add_action('wp_ajax_search_box', 'aksrt_ajax_search_box');
add_action('wp_ajax_nopriv_search_box', 'aksrt_ajax_search_box');
add_action('wp_ajax_get_current_user', 'aksrt_ajax_zibll_current_user_ping');
add_action('wp_ajax_nopriv_get_current_user', 'aksrt_ajax_zibll_current_user_ping');
add_action('wp_footer', 'aksrt_footer_navbar_search', 10);