fix(header): wire multi-function page-type enable like zibll
Connect header_components_show_on through aksrt_header_slide_is_show with zibll page-type matching, drop the homepage-only gate, align admin options, apply nav color, enqueue by is_show, remove dead float-btn schema, and consume footer_tabbar_single extend mode on post singles.
This commit is contained in:
1 parent
3e3a4631f0
commit
bfb64211ee
12 files changed
+445
-285
No files matched your search
@@ -78,13 +78,16 @@ class AKSRT_Admin_Schema_Page_Display {
|
||||
['key' => 'header_components_cards_enabled', 'label' => '启用图标卡片', 'type' => 'switch', 'default' => false],
|
||||
['key' => 'header_components_show_on', 'label' => '按页面类型启用', 'type' => 'checkbox', 'default' => ['home'], 'options' => [
|
||||
['label' => '首页', 'value' => 'home'],
|
||||
['label' => '文章', 'value' => 'single'],
|
||||
['label' => '页面', 'value' => 'page'],
|
||||
['label' => '分类', 'value' => 'category'],
|
||||
['label' => '标签', 'value' => 'tag'],
|
||||
['label' => '搜索', 'value' => 'search'],
|
||||
['label' => '归档', 'value' => 'archive'],
|
||||
['label' => '专题', 'value' => 'special'],
|
||||
['label' => '专题页', 'value' => 'topics'],
|
||||
['label' => '分类页', 'value' => 'category'],
|
||||
['label' => '标签页', 'value' => 'tag'],
|
||||
['label' => '用户页', 'value' => 'author'],
|
||||
['label' => '文章页', 'value' => 'single'],
|
||||
['label' => '搜索页', 'value' => 'search'],
|
||||
['label' => '[论坛]首页', 'value' => 'forum_home'],
|
||||
['label' => '[论坛]板块页面', 'value' => 'forum_plate'],
|
||||
['label' => '[论坛]帖子页面', 'value' => 'forum_post'],
|
||||
['label' => '其它页面', 'value' => 'page'],
|
||||
]],
|
||||
['key' => 'header_components_device_visibility', 'label' => '设备显示规则', 'type' => 'radio', 'default' => '', 'options' => [
|
||||
['label' => '全部', 'value' => ''],
|
||||
@@ -494,37 +497,6 @@ class AKSRT_Admin_Schema_Page_Display {
|
||||
]],
|
||||
],
|
||||
],
|
||||
'float-btn' => [
|
||||
'key' => 'float-btn',
|
||||
'title' => '悬浮按钮',
|
||||
'version' => '1.1.0',
|
||||
'option_key' => 'aksrt_settings',
|
||||
'groups' => [
|
||||
['key' => 'basic', 'title' => '悬浮按钮设置', 'fields' => [
|
||||
['key' => 'float_btn_style', 'label' => '按钮风格', 'type' => 'radio', 'default' => 'round', 'options' => [
|
||||
['label' => '圆形', 'value' => 'round'],
|
||||
['label' => '方形', 'value' => 'square'],
|
||||
]],
|
||||
['key' => 'float_btn_position', 'label' => '按钮位置', 'type' => 'radio', 'default' => 'bottom', 'options' => [
|
||||
['label' => '底部', 'value' => 'bottom'],
|
||||
['label' => '居中', 'value' => 'center'],
|
||||
]],
|
||||
['key' => 'float_btn_scroll_hide', 'label' => '滚动时隐藏', 'type' => 'switch', 'default' => false],
|
||||
['key' => 'float_btn_scroll_down_hide', 'label' => '下滑时隐藏', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'float_btn_max', 'label' => '最大显示数', 'type' => 'number', 'default' => 5, 'min' => 1, 'max' => 10],
|
||||
['key' => 'float_btn_size', 'label' => '按钮尺寸', 'type' => 'number', 'default' => 44, 'min' => 32, 'max' => 64],
|
||||
['key' => 'float_btn_spacing', 'label' => '按钮间距', 'type' => 'number', 'default' => 10, 'min' => 4, 'max' => 24],
|
||||
['key' => 'float_btn_shadow', 'label' => '显示阴影', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'float_btn_animation', 'label' => '悬停动画', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'float_btn_opacity', 'label' => '按钮透明度', 'type' => 'number', 'default' => 100, 'min' => 30, 'max' => 100],
|
||||
['key' => 'float_btn_active_color', 'label' => '激活颜色', 'type' => 'color', 'default' => ''],
|
||||
['key' => 'float_btn_bg_color', 'label' => '背景颜色', 'type' => 'color', 'default' => ''],
|
||||
['key' => 'float_btn_pc_s', 'label' => 'PC端显示', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'float_btn_m_s', 'label' => '移动端显示', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'float_btn_filter_css', 'label' => '过滤CSS', 'type' => 'textarea', 'default' => ''],
|
||||
]],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -177,15 +177,19 @@ trait AKSRT_Scripts_Part_1b {
|
||||
|
||||
// CMS 形态判定(可能在博客流页面也需要 grid-cms 卡片样式)
|
||||
$is_cms_mode = function_exists('aksrt_is_cms_mode') ? aksrt_is_cms_mode() : false;
|
||||
// 首页/归档/搜索:卡片 + 顶部多功能组件 + 侧栏
|
||||
// 首页/归档/搜索:卡片 + 侧栏
|
||||
if ($is_home_or_archive) {
|
||||
$enqueue_module('header-components');
|
||||
$enqueue_module('post-card');
|
||||
$enqueue_module('widgets');
|
||||
$enqueue_module('sidebar');
|
||||
$enqueue_module('breadcrumb');
|
||||
}
|
||||
|
||||
// 顶部多功能组件:按 page-type 启用结果入队(对齐 zibll,不绑死首页)
|
||||
if (function_exists('aksrt_header_slide_is_show') && aksrt_header_slide_is_show()) {
|
||||
$enqueue_module('header-components');
|
||||
}
|
||||
|
||||
// 单篇文章:所有 single 相关样式
|
||||
if ($is_single_post) {
|
||||
$enqueue_module('single-post');
|
||||
|
||||
@@ -51,7 +51,24 @@ trait AKSRT_Settings_Display_Page_Groups {
|
||||
*/
|
||||
public static function get_header_components_settings(): array {
|
||||
$s = self::get_all();
|
||||
$allowed_page_types = [
|
||||
'home',
|
||||
'topics',
|
||||
'category',
|
||||
'tag',
|
||||
'author',
|
||||
'single',
|
||||
'search',
|
||||
'forum_home',
|
||||
'forum_plate',
|
||||
'forum_post',
|
||||
'page',
|
||||
];
|
||||
$show_on = isset($s['header_components_show_on']) ? (array) $s['header_components_show_on'] : ['home'];
|
||||
$show_on = array_values(array_intersect(
|
||||
array_map('sanitize_key', $show_on),
|
||||
$allowed_page_types
|
||||
));
|
||||
$show_type = $s['header_components_device_visibility'] ?? '';
|
||||
if (!in_array($show_type, ['', 'only_pc', 'only_sm'], true)) {
|
||||
$show_type = '';
|
||||
@@ -60,7 +77,7 @@ trait AKSRT_Settings_Display_Page_Groups {
|
||||
'search_enabled' => self::header_components_search_enabled(),
|
||||
'search_config' => self::get_header_components_search_config(),
|
||||
'cards_enabled' => self::header_components_cards_enabled(),
|
||||
'show_on_pages' => array_values(array_filter(array_map('sanitize_key', $show_on))),
|
||||
'show_on_pages' => $show_on,
|
||||
'show_type' => $show_type,
|
||||
'filter_blur' => isset($s['header_components_filter_blur_devices']) ? array_values(array_intersect(array_map('sanitize_key', (array) $s['header_components_filter_blur_devices']), ['pc', 'mobile'])) : [],
|
||||
'card_show' => isset($s['header_components_card_show_devices']) ? array_values(array_intersect(array_map('sanitize_key', (array) $s['header_components_card_show_devices']), ['pc', 'mobile'])) : ['pc', 'mobile'],
|
||||
|
||||
@@ -822,27 +822,165 @@ if (!function_exists('aksrt_homepage_render_section')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_header_components_page_type_keys')) {
|
||||
/**
|
||||
* Allowed page-type keys for header multi-function (zibll CFS_Module::page_type).
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
function aksrt_header_components_page_type_keys(): array {
|
||||
return [
|
||||
'home',
|
||||
'topics',
|
||||
'category',
|
||||
'tag',
|
||||
'author',
|
||||
'single',
|
||||
'search',
|
||||
'forum_home',
|
||||
'forum_plate',
|
||||
'forum_post',
|
||||
'page',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_header_slide_excluded_page_templates')) {
|
||||
/**
|
||||
* Page templates excluded from the generic "page" type (zibll parity).
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
function aksrt_header_slide_excluded_page_templates(): array {
|
||||
return [
|
||||
'templates/pages/page-sign.php',
|
||||
'templates/pages/page-login.php',
|
||||
'templates/pages/page-register.php',
|
||||
'templates/pages/page-reset-password.php',
|
||||
'templates/pages/page-bind-account.php',
|
||||
'templates/pages/page-verify-email.php',
|
||||
'templates/pages/page-download.php',
|
||||
'templates/pages/page-download-file.php',
|
||||
'templates/pages/page-forums.php',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_header_slide_match_page_type')) {
|
||||
/**
|
||||
* Whether the current main query matches a header-slider page-type key.
|
||||
*
|
||||
* Mirrors zibll zib_header_slide_is_show() matching rules.
|
||||
*/
|
||||
function aksrt_header_slide_match_page_type(string $type): bool {
|
||||
global $wp_query;
|
||||
|
||||
$type = sanitize_key($type);
|
||||
if ($type === '' || !($wp_query instanceof WP_Query)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$raw_post_type = $wp_query->get('post_type');
|
||||
if (is_array($raw_post_type)) {
|
||||
$post_type = (string) reset($raw_post_type);
|
||||
} else {
|
||||
$post_type = (string) $raw_post_type;
|
||||
}
|
||||
|
||||
// Special keys that are not plain is_{$type} flags.
|
||||
if ($type === 'topics') {
|
||||
return is_tax('topics');
|
||||
}
|
||||
|
||||
if ($type === 'forum_home') {
|
||||
return is_page_template('templates/pages/page-forums.php');
|
||||
}
|
||||
|
||||
if ($type === 'forum_plate') {
|
||||
return is_singular('aksrt_forum_plate') || $post_type === 'aksrt_forum_plate';
|
||||
}
|
||||
|
||||
if ($type === 'forum_post') {
|
||||
return is_singular('aksrt_forum_topic') || $post_type === 'aksrt_forum_topic';
|
||||
}
|
||||
|
||||
// Generic WP_Query is_* flags (home/category/tag/author/single/search/page).
|
||||
$query_flag = 'is_' . $type;
|
||||
if (empty($wp_query->{$query_flag})) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($type === 'single') {
|
||||
// Only ordinary posts; CPTs use dedicated keys.
|
||||
return $post_type === '' || $post_type === 'post';
|
||||
}
|
||||
|
||||
if ($type === 'page') {
|
||||
foreach (aksrt_header_slide_excluded_page_templates() as $template) {
|
||||
if (is_page_template($template)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_header_slide_is_show')) {
|
||||
/**
|
||||
* Whether the header multi-function slider should render (zibll header-slider contract).
|
||||
*
|
||||
* Master switch: non-empty header_components_show_on + current page-type match.
|
||||
* Device rule: header_components_device_visibility (only_pc / only_sm).
|
||||
*/
|
||||
function aksrt_header_slide_is_show(): bool {
|
||||
if (is_admin()) {
|
||||
global $wp_query;
|
||||
|
||||
if (is_admin() || !($wp_query instanceof WP_Query)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Match zibll: only first page of the posts index / front page.
|
||||
if (!(is_front_page() || is_home())) {
|
||||
// Not on paginated views (zibll: query_vars['paged'] non-empty).
|
||||
$paged = (int) $wp_query->get('paged');
|
||||
if ($paged > 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (function_exists('aksrt_homepage_get_current_page') && aksrt_homepage_get_current_page() > 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return function_exists('aksrt_homepage_module_hero_enabled')
|
||||
? aksrt_homepage_module_hero_enabled()
|
||||
: true;
|
||||
$settings = class_exists('AKSRT_Settings')
|
||||
? AKSRT_Settings::get_header_components_settings()
|
||||
: [];
|
||||
$show_on = isset($settings['show_on_pages']) ? (array) $settings['show_on_pages'] : [];
|
||||
$allowed = array_values(array_intersect(
|
||||
array_map('sanitize_key', $show_on),
|
||||
aksrt_header_components_page_type_keys()
|
||||
));
|
||||
|
||||
// Empty selection = feature off (zibll header_slider_show).
|
||||
if ($allowed === []) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Device visibility (zibll header_slider_show_type).
|
||||
$show_type = (string) ($settings['show_type'] ?? '');
|
||||
if ($show_type === 'only_pc' && wp_is_mobile()) {
|
||||
return false;
|
||||
}
|
||||
if ($show_type === 'only_sm' && !wp_is_mobile()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($allowed as $type) {
|
||||
if (aksrt_header_slide_match_page_type($type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1283,3 +1283,104 @@ add_action('save_post_aksrt_banner', 'aksrt_flush_banner_cache');
|
||||
add_action('deleted_post', 'aksrt_flush_banner_cache');
|
||||
add_action('trashed_post', 'aksrt_flush_banner_cache');
|
||||
endif;
|
||||
|
||||
|
||||
if (!function_exists('aksrt_should_use_footer_tabbar_single_extend')) :
|
||||
/**
|
||||
* Whether single-post extended footer tabbar should replace the default items.
|
||||
* Zibll: footer_tabbar_single.s === extend && is_single(post).
|
||||
*/
|
||||
function aksrt_should_use_footer_tabbar_single_extend(): bool {
|
||||
if (!is_singular('post')) {
|
||||
return false;
|
||||
}
|
||||
if (!class_exists('AKSRT_Settings') || !method_exists('AKSRT_Settings', 'get_footer_tabbar_single')) {
|
||||
return false;
|
||||
}
|
||||
return AKSRT_Settings::get_footer_tabbar_single() === 'extend';
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_render_footer_tabbar_single_extend')) :
|
||||
/**
|
||||
* Render single-post extended footer tabbar actions (like / favorite / share / comment).
|
||||
*
|
||||
* @param bool $show_text Whether to show text labels under icons.
|
||||
*/
|
||||
function aksrt_render_footer_tabbar_single_extend(bool $show_text = true): void {
|
||||
$post_id = (int) get_the_ID();
|
||||
if ($post_id <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$settings = function_exists('aksrt_resolve_single_post_display_settings')
|
||||
? aksrt_resolve_single_post_display_settings($post_id)
|
||||
: [];
|
||||
$like_on = !isset($settings['like_enabled']) || !empty($settings['like_enabled']);
|
||||
$favorite_on = !isset($settings['favorite_enabled']) || !empty($settings['favorite_enabled']);
|
||||
$share_on = !isset($settings['share_enabled']) || !empty($settings['share_enabled']);
|
||||
$comments_open = comments_open($post_id)
|
||||
&& !(function_exists('aksrt_are_comments_closed') && aksrt_are_comments_closed());
|
||||
|
||||
$like_count = function_exists('aksrt_get_post_likes') ? (int) aksrt_get_post_likes($post_id) : 0;
|
||||
$favorite_count = function_exists('aksrt_get_post_favorites') ? (int) aksrt_get_post_favorites($post_id) : 0;
|
||||
$is_liked = function_exists('aksrt_is_post_liked') ? aksrt_is_post_liked($post_id) : false;
|
||||
$is_favorited = function_exists('aksrt_is_post_favorited') ? aksrt_is_post_favorited($post_id) : false;
|
||||
$comment_count = (int) get_comments_number($post_id);
|
||||
|
||||
if ($like_on) :
|
||||
?>
|
||||
<button type="button"
|
||||
class="tabbar-item single-action-tabbar action-like<?php echo $is_liked ? ' is-active' : ''; ?>"
|
||||
data-type="like"
|
||||
data-post-id="<?php echo esc_attr((string) $post_id); ?>"
|
||||
data-initial-active="<?php echo $is_liked ? '1' : '0'; ?>"
|
||||
aria-label="<?php esc_attr_e('点赞', 'aksrt'); ?>">
|
||||
<i class="<?php echo $is_liked ? 'fas' : 'far'; ?> fa-heart" aria-hidden="true"></i>
|
||||
<?php if ($show_text) : ?><span data-stat-count="likes" data-base-count="<?php echo esc_attr((string) $like_count); ?>"><?php echo esc_html((string) $like_count); ?></span><?php endif; ?>
|
||||
</button>
|
||||
<?php
|
||||
endif;
|
||||
|
||||
if ($favorite_on) :
|
||||
?>
|
||||
<button type="button"
|
||||
class="tabbar-item single-action-tabbar action-favorite<?php echo $is_favorited ? ' is-active' : ''; ?>"
|
||||
data-type="favorite"
|
||||
data-post-id="<?php echo esc_attr((string) $post_id); ?>"
|
||||
data-initial-active="<?php echo $is_favorited ? '1' : '0'; ?>"
|
||||
aria-label="<?php esc_attr_e('收藏', 'aksrt'); ?>">
|
||||
<i class="<?php echo $is_favorited ? 'fas' : 'far'; ?> fa-star" aria-hidden="true"></i>
|
||||
<?php if ($show_text) : ?><span data-stat-count="favorites" data-base-count="<?php echo esc_attr((string) $favorite_count); ?>"><?php echo esc_html((string) $favorite_count); ?></span><?php endif; ?>
|
||||
</button>
|
||||
<?php
|
||||
endif;
|
||||
|
||||
if ($share_on) :
|
||||
?>
|
||||
<button type="button"
|
||||
class="tabbar-item single-action-tabbar action-share"
|
||||
data-type="share"
|
||||
aria-haspopup="true"
|
||||
aria-expanded="false"
|
||||
aria-label="<?php esc_attr_e('分享', 'aksrt'); ?>">
|
||||
<i class="fas fa-share-alt" aria-hidden="true"></i>
|
||||
<?php if ($show_text) : ?><span><?php esc_html_e('分享', 'aksrt'); ?></span><?php endif; ?>
|
||||
</button>
|
||||
<?php
|
||||
endif;
|
||||
|
||||
if ($comments_open) :
|
||||
?>
|
||||
<a href="#comments"
|
||||
class="tabbar-item single-action-tabbar"
|
||||
data-type="comment"
|
||||
aria-label="<?php esc_attr_e('评论', 'aksrt'); ?>">
|
||||
<i class="far fa-comment" aria-hidden="true"></i>
|
||||
<?php if ($show_text) : ?><span><?php echo esc_html((string) $comment_count); ?></span><?php endif; ?>
|
||||
</a>
|
||||
<?php
|
||||
endif;
|
||||
}
|
||||
endif;
|
||||
|
||||
Reference in new issue
Block a user