185 lines
6.7 KiB
PHP
185 lines
6.7 KiB
PHP
<?php
|
|
/**
|
|
* Header user-box density helpers (zibll zib_header_user_box subset).
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
if (!function_exists('aksrt_header_user_checkin_btn')) :
|
|
/**
|
|
* Check-in CTA for header dropdown (uses REST /aksrt/v1/signin).
|
|
*/
|
|
function aksrt_header_user_checkin_btn(int $user_id = 0): string {
|
|
$user_id = $user_id > 0 ? $user_id : get_current_user_id();
|
|
if ($user_id <= 0 || !class_exists('\AKSRT\Credits\Signin')) {
|
|
return '';
|
|
}
|
|
$cfg = class_exists('\AKSRT\Settings\Settings')
|
|
? \AKSRT\Settings\Settings::get_signin_reward_settings()
|
|
: ['enabled' => false];
|
|
if (empty($cfg['enabled'])) {
|
|
return '';
|
|
}
|
|
|
|
// Lightweight today status via private API if available.
|
|
$signed = false;
|
|
try {
|
|
$signin = \AKSRT\Credits\Signin::get_instance();
|
|
// Prefer public method if present.
|
|
if (method_exists($signin, 'is_signed_today')) {
|
|
$signed = (bool) $signin->is_signed_today($user_id);
|
|
} else {
|
|
// Fallback: direct meta/table probe via rest_today logic is heavy; use option day key.
|
|
$day = wp_date('Y-m-d');
|
|
$signed = (bool) get_user_meta($user_id, 'aksrt_signin_' . $day, true);
|
|
}
|
|
} catch (\Throwable $e) {
|
|
$signed = false;
|
|
}
|
|
|
|
if ($signed) {
|
|
return '<button type="button" class="but block c-yellow aksrt-header-checkin is-done" disabled>'
|
|
. '<i class="fas fa-calendar-check" aria-hidden="true"></i>'
|
|
. '<span>' . esc_html__('今日已签到', 'aksrt') . '</span>'
|
|
. '</button>';
|
|
}
|
|
|
|
return '<button type="button" class="but block c-yellow aksrt-header-checkin" data-aksrt-checkin="1">'
|
|
. '<i class="fas fa-calendar-check" aria-hidden="true"></i>'
|
|
. '<span>' . esc_html__('签到领取今日奖励', 'aksrt') . '</span>'
|
|
. '</button>';
|
|
}
|
|
endif;
|
|
|
|
if (!function_exists('aksrt_header_user_wallet_mini')) :
|
|
/**
|
|
* Mini wallet strip: credits + cash balance.
|
|
*/
|
|
function aksrt_header_user_wallet_mini(int $user_id = 0): string {
|
|
$user_id = $user_id > 0 ? $user_id : get_current_user_id();
|
|
if ($user_id <= 0) {
|
|
return '';
|
|
}
|
|
$credits = function_exists('aksrt_user_credits') ? (int) aksrt_user_credits($user_id) : 0;
|
|
$currency = class_exists('\AKSRT\Settings\Settings')
|
|
? \AKSRT\Settings\Settings::get_currency_name()
|
|
: __('积分', 'aksrt');
|
|
$wallet = 0.0;
|
|
if (class_exists('\AKSRT\Credits\Balance')) {
|
|
$wallet = (float) \AKSRT\Credits\Balance::balance($user_id);
|
|
}
|
|
$center = function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url('credits') : '#';
|
|
|
|
$html = '<a class="aksrt-header-wallet flex ac jsb" href="' . esc_url($center) . '">';
|
|
$html .= '<span class="aksrt-header-wallet__item"><i class="fas fa-coins" aria-hidden="true"></i> '
|
|
. esc_html($currency) . ' <b>' . esc_html(number_format_i18n($credits)) . '</b></span>';
|
|
$html .= '<span class="aksrt-header-wallet__item"><i class="fas fa-wallet" aria-hidden="true"></i> '
|
|
. esc_html__('余额', 'aksrt') . ' <b>' . esc_html(number_format_i18n($wallet, 2)) . '</b></span>';
|
|
$html .= '</a>';
|
|
return $html;
|
|
}
|
|
endif;
|
|
|
|
if (!function_exists('aksrt_header_user_badges_row')) :
|
|
/**
|
|
* Identity / medal chips under profile.
|
|
*/
|
|
function aksrt_header_user_badges_row(int $user_id = 0): string {
|
|
$user_id = $user_id > 0 ? $user_id : get_current_user_id();
|
|
if ($user_id <= 0 || !function_exists('aksrt_render_user_identity_chips')) {
|
|
return '';
|
|
}
|
|
// Certification is displayed beside the name and level icon in the profile row.
|
|
return '';
|
|
}
|
|
endif;
|
|
|
|
if (!function_exists('aksrt_header_payvip_bar')) :
|
|
/**
|
|
* VIP status / open CTA bar (zibll zib_get_header_payvip_icon parity).
|
|
*/
|
|
function aksrt_header_payvip_bar(int $user_id = 0): string {
|
|
$user_id = $user_id > 0 ? $user_id : get_current_user_id();
|
|
if ($user_id <= 0) {
|
|
return '';
|
|
}
|
|
|
|
$vip = class_exists('\AKSRT\Settings\Settings')
|
|
? \AKSRT\Settings\Settings::get_payment_vip_settings()
|
|
: ['enabled' => false, 'levels' => []];
|
|
if (empty($vip['enabled'])) {
|
|
return '';
|
|
}
|
|
|
|
$nav = class_exists('\AKSRT\Settings\Settings')
|
|
? \AKSRT\Settings\Settings::get_header_nav_settings()
|
|
: ['nav_user_pay_vip' => true];
|
|
|
|
$level = function_exists('aksrt_get_user_vip_level') ? (int) aksrt_get_user_vip_level($user_id) : 0;
|
|
if ($level > 0) {
|
|
$levels = is_array($vip['levels'] ?? null) ? $vip['levels'] : [];
|
|
$name = (string) ($levels[$level]['name'] ?? ($level === 2 ? __('二级会员', 'aksrt') : __('一级会员', 'aksrt')));
|
|
$exp_label = '';
|
|
if (function_exists('aksrt_get_vip_info')) {
|
|
$info = aksrt_get_vip_info($user_id);
|
|
$exp_label = (string) ($info['expires_label'] ?? '');
|
|
}
|
|
$html = '<div class="mt10 em09 aksrt-header-payvip is-vip">';
|
|
$html .= '<span class="radius4 payvip-icon btn-block text-center vipbg-v2 level-' . (int) $level . ' aksrt-header-payvip__active">';
|
|
$html .= '<span class="aksrt-header-payvip__level">';
|
|
$html .= '<i class="fas fa-gem" aria-hidden="true"></i>';
|
|
$html .= '<span>' . esc_html($name) . '</span>';
|
|
$html .= '</span>';
|
|
if ($exp_label !== '') {
|
|
$html .= '<span class="aksrt-header-payvip__exp">' . esc_html($exp_label) . '</span>';
|
|
}
|
|
$html .= '</span></div>';
|
|
return $html;
|
|
}
|
|
|
|
// Open-VIP CTA only when user-box switch is on (zibll nav_user_pay_vip).
|
|
if (empty($nav['nav_user_pay_vip'])) {
|
|
return '';
|
|
}
|
|
|
|
// Match check-in CTA geometry (full width, 6px radius) — not top-nav navbar-cta chips.
|
|
return '<div class="mt10 em09 aksrt-header-payvip">'
|
|
. '<a class="pay-vip but block payvip-icon aksrt-header-payvip__cta" href="javascript:;" vip-level="1">'
|
|
. '<i class="fas fa-gem" aria-hidden="true"></i>'
|
|
. '<span>' . esc_html__('开通会员 尊享会员权益', 'aksrt') . '</span>'
|
|
. '</a></div>';
|
|
}
|
|
endif;
|
|
|
|
if (!function_exists('aksrt_render_signout_modal')) :
|
|
/**
|
|
* Confirm logout modal markup (once per page).
|
|
*/
|
|
function aksrt_render_signout_modal(): void {
|
|
static $done = false;
|
|
if ($done || !is_user_logged_in()) {
|
|
return;
|
|
}
|
|
$done = true;
|
|
$logout = wp_logout_url(home_url('/'));
|
|
?>
|
|
<div class="modal fade" id="modal_signout" tabindex="-1" role="dialog" aria-hidden="true">
|
|
<div class="modal-dialog modal-mini" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-body text-center" style="padding:24px;">
|
|
<div class="em2x mb10"><i class="fa fa-sign-out" aria-hidden="true"></i></div>
|
|
<div class="mb15"><?php esc_html_e('确认退出当前账号?', 'aksrt'); ?></div>
|
|
<div class="but-average flex jc" style="gap:10px;">
|
|
<button type="button" class="but" data-dismiss="modal"><?php esc_html_e('取消', 'aksrt'); ?></button>
|
|
<a class="but c-red" href="<?php echo esc_url($logout); ?>"><?php esc_html_e('确认退出', 'aksrt'); ?></a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php
|
|
}
|
|
endif;
|