Add zibll-like check-in details remote modal (REST/AJAX), history endpoint, header details link, and keep oneline posts + tilt showcase widgets from this batch.
177 lines
6.3 KiB
PHP
177 lines
6.3 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;
|
|
}
|
|
|
|
$details = '';
|
|
if (function_exists('aksrt_get_remote_modal_link')) {
|
|
$details = aksrt_get_remote_modal_link([
|
|
'tag' => 'a',
|
|
'class' => 'aksrt-header-checkin-details muted-2-color em09 mt6 block text-center',
|
|
'text' => __('签到详情', 'aksrt'),
|
|
'query_arg' => ['action' => 'aksrt_checkin_details_modal'],
|
|
'data_class' => 'modal-mini full-sm',
|
|
'height' => 420,
|
|
'mobile_bottom' => true,
|
|
]);
|
|
}
|
|
|
|
if ($signed) {
|
|
return '<button type="button" class="but block c-yellow aksrt-header-checkin is-done" disabled>'
|
|
. '<i class="fa fa-calendar-check-o" aria-hidden="true"></i> '
|
|
. esc_html__('今日已签到', 'aksrt')
|
|
. '</button>'
|
|
. $details;
|
|
}
|
|
|
|
return '<button type="button" class="but block c-yellow aksrt-header-checkin" data-aksrt-checkin="1">'
|
|
. '<i class="fa fa-calendar-check-o" aria-hidden="true"></i> '
|
|
. esc_html__('签到领取今日奖励', 'aksrt')
|
|
. '</button>'
|
|
. $details;
|
|
}
|
|
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('assets') : '#';
|
|
|
|
$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 '';
|
|
}
|
|
$chips = aksrt_render_user_identity_chips($user_id, 'card');
|
|
if ($chips === '') {
|
|
return '';
|
|
}
|
|
return '<div class="em09 author-tag mb10 mt6 flex jc aksrt-header-badges">' . $chips . '</div>';
|
|
}
|
|
endif;
|
|
|
|
if (!function_exists('aksrt_header_payvip_bar')) :
|
|
/**
|
|
* VIP status / open CTA bar.
|
|
*/
|
|
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 '';
|
|
}
|
|
$badge = function_exists('aksrt_render_vip_badge') ? aksrt_render_vip_badge($user_id, 'md') : '';
|
|
if ($badge !== '') {
|
|
return '<div class="mt10 em09 aksrt-header-payvip">' . $badge . '</div>';
|
|
}
|
|
// Guest-style open VIP for non-members if VIP feature on.
|
|
$vip_url = function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url('vip') : '#';
|
|
$enabled = true;
|
|
if (class_exists('\AKSRT\Settings\Settings') && method_exists('\AKSRT\Settings\Settings', 'get_vip_settings')) {
|
|
$vs = \AKSRT\Settings\Settings::get_vip_settings();
|
|
$enabled = !empty($vs['enabled']) || !empty($vs['vip1_enabled']) || !empty($vs['vip2_enabled']);
|
|
}
|
|
if (!$enabled) {
|
|
return '';
|
|
}
|
|
return '<div class="mt10 em09 aksrt-header-payvip">'
|
|
. '<a class="but jb-red radius4 payvip-icon btn-block" href="' . esc_url($vip_url) . '">'
|
|
. '<i class="fa fa-diamond mr6" aria-hidden="true"></i>'
|
|
. esc_html__('开通会员 尊享会员权益', 'aksrt')
|
|
. '</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;
|