Files
wordpress-theme-aksrt/inc/helpers/aksrt-runtime-win.php
T
kate522 b8ee6b6a43 fix(float): repair VIP rail entry front and admin
Always open VIP modal for float pay_vip, drop forced admin link,
normalize gem icon, harden pay-vip click binding and SPA form UX.
2026-07-22 10:32:00 +08:00

187 lines
6.8 KiB
PHP

<?php
/**
* Float button commerce types + runtime window._win bridge (zibll parity).
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
if (!function_exists('aksrt_get_float_shop_cart_html')) :
/**
* Floating shop cart button with badge.
*/
function aksrt_get_float_shop_cart_html(array $item = []): string {
if (!is_user_logged_in()) {
return '';
}
$shop_on = true;
if (class_exists('\AKSRT\Settings\Settings')) {
$shop = \AKSRT\Settings\Settings::get_shop_settings();
$shop_on = !empty($shop['enabled']);
}
if (!$shop_on) {
return '';
}
// Skip on cart page.
if (function_exists('is_page_template') && is_page_template('templates/pages/page-cart.php')) {
return '';
}
$url = function_exists('aksrt_get_cart_page_url') ? aksrt_get_cart_page_url() : '';
if ($url === '') {
return '';
}
$count = 0;
if (class_exists('\AKSRT\Shop\Shop')) {
$count = (int) \AKSRT\Shop\Shop::get_instance()->get_cart_count(get_current_user_id());
}
$icon = !empty($item['icon']) ? (string) $item['icon'] : 'fas fa-shopping-cart';
$style = [];
if (!empty($item['color'])) {
$style[] = '--this-color:' . esc_attr((string) $item['color']);
}
if (!empty($item['bg'])) {
$style[] = '--this-bg:' . esc_attr((string) $item['bg']);
}
$style_attr = $style ? ' style="' . implode(';', $style) . '"' : '';
$badge = $count > 0 ? (string) min(99, $count) : '';
return '<a class="float-btn float-btn-shop-cart nowave" href="' . esc_url($url) . '" title="' . esc_attr__('购物车', 'aksrt') . '"' . $style_attr . '>'
. '<i class="' . esc_attr($icon) . '" aria-hidden="true"></i>'
. '<badge cart-count="' . esc_attr($badge) . '">' . esc_html($badge) . '</badge>'
. '</a>';
}
endif;
if (!function_exists('aksrt_get_float_pay_vip_html')) :
/**
* Floating VIP open button.
*
* Always opens the site VIP modal for logged-in non-max VIP users
* (class pay-vip → assets/js/pay-vip.js). Guests get signin-loader.
* Admin "link/hover" fields are intentionally ignored for this type.
*/
function aksrt_get_float_pay_vip_html(array $item = []): string {
$show_vip = false;
if (class_exists('\AKSRT\Settings\Settings')) {
$vs = \AKSRT\Settings\Settings::get_payment_vip_settings();
$show_vip = !empty($vs['enabled']);
}
if (!$show_vip) {
return '';
}
$user_id = get_current_user_id();
$level = 0;
if ($user_id > 0 && function_exists('aksrt_get_user_vip_level')) {
$level = (int) aksrt_get_user_vip_level($user_id);
}
// Already top tier — no upsell entry on float rail.
if ($level >= 2) {
return '';
}
// Prefer admin title; fallback by upgrade vs open.
$admin_title = trim((string) ($item['text'] ?? ''));
if ($admin_title !== '') {
$title = $admin_title;
} else {
$title = $level === 1 ? __('升级会员', 'aksrt') : __('开通会员', 'aksrt');
}
$icon = trim((string) ($item['icon'] ?? ''));
if ($icon === '') {
$icon = 'fas fa-gem';
}
// FA4 leftovers from older admin data.
$icon = strtr($icon, [
'fa-diamond' => 'fa-gem',
'fa fa-' => 'fas fa-',
]);
if (!preg_match('/\b(fas|far|fab|fal|fad)\b/', $icon)) {
$icon = 'fas ' . ltrim(preg_replace('/^fa\s+/', '', $icon) ?? $icon);
}
// Logged-in: open modal. Guest: open login.
$cls = $user_id > 0 ? 'float-btn pay-vip nowave' : 'float-btn signin-loader nowave';
$style = [];
if (!empty($item['color'])) {
$style[] = '--this-color:' . esc_attr((string) $item['color']);
}
if (!empty($item['bg'])) {
$style[] = '--this-bg:' . esc_attr((string) $item['bg']);
}
// Default VIP accent when admin left color empty.
if (empty($item['color'])) {
$style[] = '--this-color:#f5a623';
}
$style_attr = $style ? ' style="' . implode(';', $style) . '"' : '';
// Prefer upgrading one tier when already VIP1.
$target_level = $user_id > 0 ? max(1, min(2, $level + 1)) : 1;
$vip_level_attr = $user_id > 0
? ' vip-level="' . esc_attr((string) $target_level) . '" data-vip-level="' . esc_attr((string) $target_level) . '"'
: '';
return '<a class="' . esc_attr($cls) . '" href="javascript:;" role="button" aria-label="' . esc_attr($title) . '" title="' . esc_attr($title) . '"' . $style_attr . $vip_level_attr . '>'
. '<i class="' . esc_attr($icon) . '" aria-hidden="true"></i>'
. '</a>';
}
endif;
if (!function_exists('aksrt_get_win_runtime_config')) :
/**
* Build window._win payload (zibll zib_win_var subset).
*
* @return array<string,mixed>
*/
function aksrt_get_win_runtime_config(): array {
$post_display = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::get_post_page_settings()
: [];
$is_mobile = wp_is_mobile();
$list_style = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::get_post_list_style_settings()
: [];
$signin = function_exists('aksrt_get_login_url')
? aksrt_get_login_url(function_exists('aksrt_get_current_url') ? aksrt_get_current_url() : home_url('/'))
: wp_login_url();
$signup = function_exists('aksrt_get_register_url')
? aksrt_get_register_url()
: wp_registration_url();
$views = 0;
if (is_singular()) {
$views = (int) get_queried_object_id();
}
return [
'views' => $views,
'www' => home_url('/'),
'uri' => get_template_directory_uri(),
'ver' => defined('AKSRT_VERSION') ? AKSRT_VERSION : '3.4.0-dev',
'imgbox' => !isset($post_display['lightbox']) || !empty($post_display['lightbox']) ? '1' : '',
'imgbox_type' => 'group',
'imgbox_thumbs' => !isset($post_display['lightbox_thumbs']) || !empty($post_display['lightbox_thumbs']) ? '1' : '',
'imgbox_zoom' => !isset($post_display['lightbox_zoom']) || !empty($post_display['lightbox_zoom']) ? '1' : '',
'imgbox_full' => !isset($post_display['lightbox_full']) || !empty($post_display['lightbox_full']) ? '1' : '',
'imgbox_play' => !empty($post_display['lightbox_play']) ? '1' : '',
'imgbox_down' => !empty($post_display['lightbox_down']) ? '1' : '',
'sign_type' => class_exists('\AKSRT\Settings\Settings')
? (string) (\AKSRT\Settings\Settings::get_all()['user_sign_type'] ?? 'page')
: 'page',
'signin_url' => $signin,
'signup_url' => $signup,
'ajax_url' => admin_url('admin-ajax.php'),
'ajaxpager' => '1',
'ajax_trigger' => (string) ($list_style['ajax_trigger_text'] ?? __('加载更多', 'aksrt')),
'ajax_nomore' => (string) ($list_style['ajax_nomore_text'] ?? __('没有更多了', 'aksrt')),
'qj_loading' => __('加载中...', 'aksrt'),
'is_mobile' => $is_mobile ? '1' : '',
'is_logged_in' => is_user_logged_in() ? '1' : '',
'user_id' => get_current_user_id(),
'rest_url' => esc_url_raw(rest_url('aksrt/v1')),
'rest_nonce' => wp_create_nonce('wp_rest'),
'nonce' => wp_create_nonce('aksrt_public_nonce'),
];
}
endif;