fix(frontend): align reward modal with shared runtime
This commit is contained in:
1 parent
6037ca184b
commit
356f7fe5bd
14 files changed
+337
-630
No files matched your search
@@ -25,9 +25,11 @@ if (!function_exists('aksrt_get_rewards_button')) {
|
||||
$settings = \AKSRT\Settings\Settings::get_post_page_settings();
|
||||
$label = (string) ($settings['rewards_btn_text'] ?? __('赞赏', 'aksrt'));
|
||||
$icon = function_exists('aksrt_icon_markup') ? aksrt_icon_markup('zibsvg-money') : '';
|
||||
$template_id = 'aksrt-reward-template-' . $user_id . '-' . $post_id;
|
||||
return sprintf(
|
||||
'<button type="button" class="%1$s aksrt-reward-open" data-aksrt-reward-open data-user-id="%2$d" data-post-id="%3$d">%4$s<text>%5$s</text></button>',
|
||||
'<button type="button" class="%1$s aksrt-reward-open" data-aksrt-reward-open data-template-id="%2$s" data-user-id="%3$d" data-post-id="%4$d">%5$s<text>%6$s</text></button>',
|
||||
esc_attr($class),
|
||||
esc_attr($template_id),
|
||||
$user_id,
|
||||
$post_id,
|
||||
$icon, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- fixed sprite markup.
|
||||
@@ -36,8 +38,8 @@ if (!function_exists('aksrt_get_rewards_button')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_render_rewards_modal_for_user')) {
|
||||
function aksrt_render_rewards_modal_for_user(int $user_id, int $post_id = 0): void {
|
||||
if (!function_exists('aksrt_render_rewards_template_for_user')) {
|
||||
function aksrt_render_rewards_template_for_user(int $user_id, int $post_id = 0): void {
|
||||
static $done = [];
|
||||
$key = $user_id . ':' . $post_id;
|
||||
if ($user_id <= 0 || isset($done[$key]) || !aksrt_rewards_enabled()) {
|
||||
@@ -58,27 +60,34 @@ if (!function_exists('aksrt_render_rewards_modal_for_user')) {
|
||||
}
|
||||
}
|
||||
$recipient = get_userdata($user_id);
|
||||
$template_id = 'aksrt-reward-template-' . $user_id . '-' . $post_id;
|
||||
$title = (string) ($settings['rewards_text'] ?? __('赞赏', 'aksrt'));
|
||||
$money_icon = function_exists('aksrt_icon_markup') ? aksrt_icon_markup('zibsvg-money') : '<i class="fa fas fa-money-bill-wave" aria-hidden="true"></i>';
|
||||
$close_icon = function_exists('aksrt_icon_markup') ? aksrt_icon_markup('zibsvg-close', 'ic-close') : '<i class="fa fas fa-times" aria-hidden="true"></i>';
|
||||
?>
|
||||
<div class="reward-modal" id="reward-modal-<?php echo (int) $user_id; ?>" data-user-id="<?php echo (int) $user_id; ?>" data-post-id="<?php echo (int) $post_id; ?>" aria-hidden="true">
|
||||
<div class="reward-modal__overlay" data-aksrt-reward-close></div>
|
||||
<div class="reward-modal__dialog" role="dialog" aria-modal="true" aria-labelledby="reward-title-<?php echo (int) $user_id; ?>">
|
||||
<button type="button" class="reward-modal__close" data-aksrt-reward-close aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>"><i class="fa fas fa-times" aria-hidden="true"></i></button>
|
||||
<div class="reward-modal__content">
|
||||
<h3 id="reward-title-<?php echo (int) $user_id; ?>"><?php echo esc_html((string) ($settings['rewards_text'] ?? __('赞赏', 'aksrt'))); ?></h3>
|
||||
<p class="muted-2-color em09"><?php printf(esc_html__('赞赏将直接进入 %s 的站内余额', 'aksrt'), esc_html($recipient ? $recipient->display_name : __('作者', 'aksrt'))); ?></p>
|
||||
<div class="reward-amounts" data-aksrt-reward-amounts>
|
||||
<?php foreach ($render_amounts as $index => $amount) : ?>
|
||||
<button type="button" class="reward-amount<?php echo $index === 0 ? ' is-active' : ''; ?>" data-reward-amount="<?php echo esc_attr($amount); ?>">¥<?php echo esc_html($amount); ?></button>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php if (!empty($settings['rewards_custom'])) : ?>
|
||||
<label class="reward-custom"><span><?php esc_html_e('自定义金额', 'aksrt'); ?></span><input type="number" min="<?php echo esc_attr((string) ($settings['rewards_min'] ?? 1)); ?>" max="<?php echo esc_attr((string) ($settings['rewards_max'] ?? 1000)); ?>" step="0.01" data-aksrt-reward-custom placeholder="<?php esc_attr_e('输入金额', 'aksrt'); ?>"></label>
|
||||
<?php endif; ?>
|
||||
<button type="button" class="btn-primary reward-modal__submit" data-aksrt-reward-submit><?php esc_html_e('余额赞赏', 'aksrt'); ?></button>
|
||||
<div class="reward-modal__message" data-aksrt-reward-message role="status"></div>
|
||||
<template id="<?php echo esc_attr($template_id); ?>" data-user-id="<?php echo (int) $user_id; ?>" data-post-id="<?php echo (int) $post_id; ?>">
|
||||
<div class="modal-colorful-header colorful-bg jb-blue">
|
||||
<button type="button" class="close" data-aksrt-modal-close aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>"><?php echo $close_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- fixed theme icon markup. ?></button>
|
||||
<div class="colorful-make"></div>
|
||||
<div class="text-center">
|
||||
<div class="em2x"><?php echo $money_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- fixed theme icon markup. ?></div>
|
||||
<div class="mt10 em12 padding-w10 aksrt-reward__title" role="heading" aria-level="2"><?php echo esc_html($title); ?></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-body aksrt-reward__body">
|
||||
<p class="aksrt-reward__desc muted-2-color em09"><?php printf(esc_html__('赞赏将直接进入 %s 的站内余额', 'aksrt'), esc_html($recipient ? $recipient->display_name : __('作者', 'aksrt'))); ?></p>
|
||||
<div class="aksrt-reward__amounts">
|
||||
<?php foreach ($render_amounts as $index => $amount) : ?>
|
||||
<button type="button" class="aksrt-reward__amount<?php echo $index === 0 ? ' is-active' : ''; ?>" data-reward-amount="<?php echo esc_attr($amount); ?>" aria-pressed="<?php echo $index === 0 ? 'true' : 'false'; ?>"><span class="aksrt-reward__currency">¥</span><span class="aksrt-reward__value"><?php echo esc_html($amount); ?></span></button>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php if (!empty($settings['rewards_custom'])) : ?>
|
||||
<label class="aksrt-reward__custom"><span><?php esc_html_e('自定义金额', 'aksrt'); ?></span><input class="aksrt-reward__input" type="number" min="<?php echo esc_attr((string) ($settings['rewards_min'] ?? 1)); ?>" max="<?php echo esc_attr((string) ($settings['rewards_max'] ?? 1000)); ?>" step="0.01" data-aksrt-reward-custom placeholder="<?php esc_attr_e('输入金额', 'aksrt'); ?>"></label>
|
||||
<?php endif; ?>
|
||||
<button type="button" class="but jb-blue btn-block aksrt-reward__submit" data-aksrt-reward-submit><?php esc_html_e('余额赞赏', 'aksrt'); ?></button>
|
||||
<div class="aksrt-reward__message" data-aksrt-reward-message role="status" aria-live="polite"></div>
|
||||
</div>
|
||||
</template>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ if (!function_exists('aksrt_single_render_actions')) :
|
||||
: '';
|
||||
if ($reward_btn !== '') {
|
||||
echo $reward_btn; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
aksrt_render_rewards_modal_for_user($reward_author, $post_id);
|
||||
aksrt_render_rewards_template_for_user($reward_author, $post_id);
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
Reference in new issue
Block a user