feat(navigation): hard-switch to Zibll navigation and Font Awesome 5
This commit is contained in:
1 parent
3c3ddac8be
commit
a0b84977a2
630 files changed
+101647
-11293
No files matched your search
@@ -9,28 +9,104 @@
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
if (!function_exists('aksrt_save_history_search')) :
|
||||
/** Store the Zibll history_search cookie (newest first, maximum thirty). */
|
||||
function aksrt_save_history_search(string $search): void {
|
||||
$search = trim(wp_strip_all_tags($search));
|
||||
$search_text = aksrt_get_search_keywords_text($search);
|
||||
if ($search_text === '' || mb_strlen($search_text) >= 30 || headers_sent()) {
|
||||
return;
|
||||
}
|
||||
$history = aksrt_get_search_history_keywords();
|
||||
$history = array_values(array_filter($history, static function (string $item) use ($search_text): bool {
|
||||
return aksrt_get_search_keywords_text($item) !== $search_text;
|
||||
}));
|
||||
array_unshift($history, $search);
|
||||
$history = array_slice($history, 0, 30);
|
||||
setcookie('history_search', wp_json_encode($history), [
|
||||
'expires' => time() + MONTH_IN_SECONDS,
|
||||
'path' => COOKIEPATH ?: '/',
|
||||
'domain' => COOKIE_DOMAIN,
|
||||
'secure' => is_ssl(),
|
||||
'httponly' => false,
|
||||
'samesite' => 'Lax',
|
||||
]);
|
||||
$_COOKIE['history_search'] = wp_json_encode($history);
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_get_main_search')) :
|
||||
/** Zibll main-search defaults backed only by the reference option IDs. */
|
||||
function aksrt_get_main_search(array $args = [], bool $echo = false) {
|
||||
$settings = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_all() : [];
|
||||
$search_cat = !array_key_exists('search_cat', $settings) || !empty($settings['search_cat']);
|
||||
$search_type = !array_key_exists('search_type', $settings) || !empty($settings['search_type']);
|
||||
$defaults = [
|
||||
'class' => '',
|
||||
'show_keywords' => !array_key_exists('search_popular_key', $settings) || !empty($settings['search_popular_key']),
|
||||
'show_history' => !array_key_exists('search_history', $settings) || !empty($settings['search_history']),
|
||||
'show_posts' => !array_key_exists('search_posts', $settings) || !empty($settings['search_posts']),
|
||||
'show_input_cat' => $search_cat,
|
||||
'more_cats' => $search_cat ? (array) ($settings['search_more_cat_obj'] ?? []) : [],
|
||||
'in_cat' => $search_cat ? ($settings['search_cat_in'] ?? '') : '',
|
||||
'show_type' => $search_type,
|
||||
'in_type' => $search_type ? sanitize_key((string) ($settings['search_type_in'] ?? 'post')) : '',
|
||||
'in_user' => '',
|
||||
];
|
||||
return aksrt_get_search_box(wp_parse_args($args, $defaults), $echo);
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_get_search_history_keywords')) :
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
function aksrt_get_search_history_keywords(): array {
|
||||
$hist = [];
|
||||
if (is_user_logged_in()) {
|
||||
$saved = get_user_meta(get_current_user_id(), 'aksrt_search_history', true);
|
||||
if (is_array($saved)) {
|
||||
foreach (array_slice($saved, 0, 10) as $item) {
|
||||
if (is_array($item) && !empty($item['keyword'])) {
|
||||
$hist[] = (string) $item['keyword'];
|
||||
} elseif (is_string($item) && $item !== '') {
|
||||
$hist[] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
$raw = isset($_COOKIE['history_search'])
|
||||
? wp_unslash((string) $_COOKIE['history_search'])
|
||||
: '';
|
||||
$decoded = $raw !== '' ? json_decode(stripslashes($raw), true) : [];
|
||||
if (!is_array($decoded)) {
|
||||
return [];
|
||||
}
|
||||
$hist = array_map(
|
||||
static fn($item): string => sanitize_text_field((string) $item),
|
||||
array_slice($decoded, 0, 30)
|
||||
);
|
||||
return array_values(array_unique(array_filter(array_map('trim', $hist))));
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_get_search_keywords_text')) :
|
||||
function aksrt_get_search_keywords_text(string $search): string {
|
||||
$search = str_replace('&type', '&type', $search);
|
||||
$index = strpos($search, '&type=');
|
||||
return trim($index === false ? $search : substr($search, 0, $index));
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_update_search_keywords')) :
|
||||
function aksrt_update_search_keywords(string $search): void {
|
||||
$search = trim(wp_strip_all_tags($search));
|
||||
$text = aksrt_get_search_keywords_text($search);
|
||||
if (mb_strlen($text) < 2 || mb_strlen($text) > 8) {
|
||||
return;
|
||||
}
|
||||
if (class_exists('\AKSRT\Settings\Settings') && !\AKSRT\Settings\Settings::hot_search_enabled()) {
|
||||
return;
|
||||
}
|
||||
$keywords = get_option('search_keywords', []);
|
||||
$keywords = is_array($keywords) ? $keywords : [];
|
||||
$limit = class_exists('\AKSRT\Settings\Settings')
|
||||
? max(10, min(50, (int) \AKSRT\Settings\Settings::get_value('search_popular_key_num', 20)))
|
||||
: 20;
|
||||
$keywords = array_slice($keywords, 0, $limit + 10, true);
|
||||
$keywords[$search] = isset($keywords[$search]) ? (int) $keywords[$search] + 1 : 1;
|
||||
arsort($keywords, SORT_NUMERIC);
|
||||
update_option('search_keywords', $keywords, false);
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_get_search_keywords_but')) :
|
||||
/**
|
||||
* Render keyword chip links.
|
||||
@@ -48,9 +124,14 @@ if (!function_exists('aksrt_get_search_keywords_but')) :
|
||||
if ($kw === '') {
|
||||
continue;
|
||||
}
|
||||
$text = aksrt_get_search_keywords_text($kw);
|
||||
$query = ['s' => $text];
|
||||
if (preg_match('/&type=([a-z0-9_-]+)/i', $kw, $match)) {
|
||||
$query['type'] = sanitize_key($match[1]);
|
||||
}
|
||||
$out .= '<a class="search_keywords muted-2-color but em09 mr6 mb6" data-search-keyword="' . esc_attr($kw) . '" href="'
|
||||
. esc_url(home_url('/?s=' . rawurlencode($kw))) . '">'
|
||||
. esc_html($kw) . '</a> ';
|
||||
. esc_url(add_query_arg($query, home_url('/'))) . '">'
|
||||
. esc_html($text) . '</a> ';
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
@@ -178,12 +259,12 @@ if (!function_exists('aksrt_get_search_box')) :
|
||||
$input_html .= '<div class="scale-placeholder' . ($s !== '' ? ' is-focus' : '') . '" default="'
|
||||
. $args['placeholder'] . '">' . $args['placeholder'] . '</div>';
|
||||
$input_html .= '<div class="abs-right muted-color"><button type="submit" tabindex="2" class="null" aria-label="'
|
||||
. esc_attr__('搜索', 'aksrt') . '"><i class="fas fa-search" aria-hidden="true"></i></button></div>';
|
||||
. esc_attr__('搜索', 'aksrt') . '"><i class="fa fas fa-search" aria-hidden="true"></i></button></div>';
|
||||
$input_html .= '</div>';
|
||||
|
||||
$input_html .= '<input type="hidden" name="aksrt_search_type" value="' . esc_attr($in_type) . '">';
|
||||
$input_html .= '<input type="hidden" name="type" value="' . esc_attr($in_type) . '">';
|
||||
if ($cat_html !== '' || (string) $args['in_cat'] !== '') {
|
||||
$input_html .= '<input type="hidden" name="aksrt_category" value="'
|
||||
$input_html .= '<input type="hidden" name="trem" value="'
|
||||
. esc_attr((string) ($args['in_cat'] !== '' ? $args['in_cat'] : ($state['category_id'] ?? 0))) . '">';
|
||||
}
|
||||
if ((string) $args['in_user'] !== '') {
|
||||
@@ -196,7 +277,7 @@ if (!function_exists('aksrt_get_search_box')) :
|
||||
}
|
||||
|
||||
$form_html = '<form method="get" class="padding-10 search-form" action="'
|
||||
. esc_url(home_url('/')) . '" role="search" data-aksrt-search-form="box">'
|
||||
. esc_url(home_url('/')) . '">'
|
||||
. $type_html
|
||||
. '<div class="line-form">' . $cat_html . $input_html . '</div>'
|
||||
. '</form>';
|
||||
@@ -233,19 +314,14 @@ if (!function_exists('aksrt_get_search_box')) :
|
||||
}
|
||||
if ($show_h) {
|
||||
$hist = aksrt_get_search_history_keywords();
|
||||
// Empty shell still rendered so client localStorage can fill it.
|
||||
$keyword_link = aksrt_get_search_keywords_but($hist, 'history');
|
||||
$history_html = '<div class="search-keywords history-search" data-aksrt-menu-history="1">';
|
||||
$history_html .= '<p class="muted-color"><span>' . esc_html__('历史搜索', 'aksrt') . '</span>';
|
||||
$history_html .= '<a class="pull-right trash-history-search muted-3-color" href="javascript:;" data-aksrt-clear-menu-history="1" aria-label="'
|
||||
. esc_attr__('清空历史', 'aksrt') . '"><i class="fas fa-trash-alt em12" aria-hidden="true"></i></a></p>';
|
||||
$history_html .= '<div class="history-search-list">';
|
||||
if ($keyword_link !== '') {
|
||||
$history_html .= $keyword_link;
|
||||
} else {
|
||||
$history_html .= '<span class="muted-3-color em09" data-empty="1">' . esc_html__('暂无历史', 'aksrt') . '</span>';
|
||||
$history_html = '<div class="search-keywords history-search">';
|
||||
$history_html .= '<p class="muted-color"><span>' . esc_html__('历史搜索', 'aksrt') . '</span>';
|
||||
$history_html .= '<a class="pull-right trash-history-search muted-3-color" href="javascript:;" aria-label="'
|
||||
. esc_attr__('清空历史', 'aksrt') . '"><i class="fa fas fa-trash-alt em12" aria-hidden="true"></i></a></p>';
|
||||
$history_html .= '<div>' . $keyword_link . '</div></div>';
|
||||
}
|
||||
$history_html .= '</div></div>';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,12 +345,9 @@ if (!function_exists('aksrt_get_search_box')) :
|
||||
}
|
||||
}
|
||||
|
||||
// Live suggestions mount (AKSRT extension; does not break zibll classes).
|
||||
$suggest = '<div class="aksrt-menu-search-suggest mt10" data-aksrt-menu-suggest="1" hidden></div>';
|
||||
|
||||
$class = $args['class'] ? ' ' . sanitize_html_class((string) $args['class']) : '';
|
||||
$html = '<div class="search-input' . esc_attr($class) . '">'
|
||||
. $form_html . $keywords_html . $history_html . $posts_html . $suggest
|
||||
. $form_html . $keywords_html . $history_html . $posts_html
|
||||
. '</div>';
|
||||
|
||||
if ($echo) {
|
||||
|
||||
@@ -67,7 +67,7 @@ if (!function_exists('aksrt_get_search_posts')) :
|
||||
: (string) $views;
|
||||
$time_ago = human_time_diff(get_the_time('U', $post_id), current_time('timestamp'));
|
||||
$info = '<item>' . esc_html(sprintf(/* translators: %s: relative time */ __('%s前', 'aksrt'), $time_ago))
|
||||
. '</item><item class="pull-right"><i class="fas fa-eye" aria-hidden="true"></i> '
|
||||
. '</item><item class="pull-right"><i class="fa fas fa-eye" aria-hidden="true"></i> '
|
||||
. esc_html((string) $views_txt) . '</item>';
|
||||
|
||||
$lists .= '<div class="swiper-slide em09 mr10" style="width:160px;">';
|
||||
|
||||
Reference in new issue
Block a user