后台「积分配置 → 自定义货币名称」改名后,用户中心仍有大量硬编码 「积分」:做任务赚积分 / 购买积分 / 签到领积分、积分记录 / 积分任务、 每日可免费获取 XX 积分、我的积分、积分+1、创作中心积分收益等。 get_currency_name() 早已存在且可用,问题只是这些文案没有走它。 本PR 全部替换,无双路、无迁移: 服务端渲染(用户中心 renderers) - credits-balance.php:购买/做任务赚/签到领 + 整个购买弹窗 - profile-credits.php:积分记录 / 积分任务 页签 - credits-points-tasks.php:每日上限三态与空态 - sidebar-creator.php / profile-creator.php:积分收益 - transfer-modal.php:积分转账提示 - Signin.php:签到详情弹窗(我的积分 / 奖励 tooltip / 积分+N) - VipServiceModal.php:我的积分 / 积分兑换会员 - download-permission-card.php:购买价格 客户端渲染(JS 无法调用 PHP,注入 currencyName 到 aksrtData) - signin.js:签到状态行「已签到 N 天 +1」 - credits.js:转账标题/金额标签 + 购买提示 toast - cms-download.js:积分不足视图、我的积分 入口、余额不足文案 - pay-vip.js:积分兑换会员入口(优先 catalog.currency_name) - order-center.js:订单行单位回退 契约测试同步改为断言模板构造而非死字符串,并新增两例: 改名后跟随、未注入时回退「积分」。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
202 lines
7.9 KiB
PHP
202 lines
7.9 KiB
PHP
<?php
|
|
/**
|
|
* Free points tasks list + daily free detail (legacy points free tab).
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
if (!class_exists('\AKSRT\Credits\PointsFree') || !\AKSRT\Credits\PointsFree::enabled()) {
|
|
return;
|
|
}
|
|
|
|
/**
|
|
* Resolve a "go complete" action for a free-points task row.
|
|
*
|
|
* @return array{type:string,label:string,href?:string}
|
|
*/
|
|
$aksrt_points_task_action = static function (string $key): array {
|
|
$home = home_url('/');
|
|
$submit = '';
|
|
if (function_exists('aksrt_get_page_url_by_template')) {
|
|
$submit = (string) aksrt_get_page_url_by_template('templates/pages/page-submit.php');
|
|
}
|
|
|
|
switch ($key) {
|
|
case 'sign_in':
|
|
return [
|
|
'type' => 'signin',
|
|
'label' => __('去签到', 'aksrt'),
|
|
];
|
|
case 'post_new':
|
|
return [
|
|
'type' => 'link',
|
|
'label' => __('去完成', 'aksrt'),
|
|
'href' => $submit !== '' ? $submit : $home,
|
|
];
|
|
case 'comment_new':
|
|
$posts = get_posts(['numberposts' => 1, 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC']);
|
|
$href = $home;
|
|
if (!empty($posts[0]) && $posts[0] instanceof WP_Post) {
|
|
$link = get_permalink($posts[0]);
|
|
if (is_string($link) && $link !== '') {
|
|
$href = $link . '#comments';
|
|
}
|
|
}
|
|
return [
|
|
'type' => 'link',
|
|
'label' => __('去完成', 'aksrt'),
|
|
'href' => $href,
|
|
];
|
|
case 'login':
|
|
return [
|
|
'type' => 'none',
|
|
'label' => __('登录即可领取', 'aksrt'),
|
|
];
|
|
case 'post_like':
|
|
case 'post_favorite':
|
|
case 'comment_like':
|
|
$posts = get_posts(['numberposts' => 1, 'post_status' => 'publish', 'orderby' => 'comment_count', 'order' => 'DESC']);
|
|
$href = $home;
|
|
if (!empty($posts[0]) && $posts[0] instanceof WP_Post) {
|
|
$link = get_permalink($posts[0]);
|
|
if (is_string($link) && $link !== '') {
|
|
$href = $link;
|
|
}
|
|
}
|
|
return [
|
|
'type' => 'link',
|
|
'label' => __('去看看', 'aksrt'),
|
|
'href' => $href,
|
|
];
|
|
case 'followed':
|
|
$center = function_exists('aksrt_get_user_center_url') ? (string) aksrt_get_user_center_url() : $home;
|
|
return [
|
|
'type' => 'link',
|
|
'label' => __('去主页', 'aksrt'),
|
|
'href' => $center !== '' ? $center : $home,
|
|
];
|
|
default:
|
|
return ['type' => 'none', 'label' => ''];
|
|
}
|
|
};
|
|
|
|
$user_id = (int) ($user_id ?? get_current_user_id());
|
|
$today = \AKSRT\Credits\PointsFree::today_total($user_id);
|
|
$day_max = (int) \AKSRT\Credits\PointsFree::settings()['day_max'];
|
|
$tasks = \AKSRT\Credits\PointsFree::task_list_for_user($user_id);
|
|
$detail = \AKSRT\Credits\PointsFree::date_detail($user_id);
|
|
$pane = isset($points_tasks_pane) ? sanitize_key((string) $points_tasks_pane) : 'tasks';
|
|
// 文案里的货币名统一走自定义名称(后台「积分配置 → 自定义货币名称」)。
|
|
$currency = (string) ($currency_name ?? __('积分', 'aksrt'));
|
|
?>
|
|
|
|
<?php if ($pane === 'date') : ?>
|
|
<div class="uc-points-date">
|
|
<div class="flex jsb ac mb10">
|
|
<div class="font-bold"><?php printf(esc_html__('每日免费%s明细', 'aksrt'), esc_html($currency)); ?></div>
|
|
<button type="button" class="muted-2-color" data-aksrt-asset-tab="points_free">
|
|
<?php esc_html_e('返回任务', 'aksrt'); ?><i class="fa fas fa-angle-right ml6 em12" aria-hidden="true"></i>
|
|
</button>
|
|
</div>
|
|
<?php if ($detail) : ?>
|
|
<?php foreach ($detail as $day => $val) : ?>
|
|
<div class="border-bottom padding-h6 flex jsb ac">
|
|
<div class="em12"><?php echo esc_html((string) $day); ?></div>
|
|
<div class="text-right shrink0 focus-color em14 font-bold">+ <?php echo esc_html((string) (int) $val); ?></div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php else : ?>
|
|
<div class="uc-transactions__empty"><p><?php printf(esc_html__('暂无免费%s获取明细', 'aksrt'), esc_html($currency)); ?></p></div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php else : ?>
|
|
<div class="uc-points-tasks">
|
|
<?php if ($today > 0 || $day_max > 0) : ?>
|
|
<div class="border-bottom padding-h10">
|
|
<div class="flex jsb ac">
|
|
<div class="flex1 mr20">
|
|
<div class="font-bold mb6">
|
|
<?php
|
|
printf(
|
|
/* translators: %s: points */
|
|
esc_html__('今日累计 %s', 'aksrt'),
|
|
'<span class="focus-color">+' . esc_html((string) $today) . '</span>'
|
|
);
|
|
?>
|
|
</div>
|
|
<div class="muted-2-color em09">
|
|
<?php
|
|
if ($day_max > 0) {
|
|
if ($today >= $day_max) {
|
|
printf(esc_html__('今日获取的免费%s已达到 %s,将不再获取', 'aksrt'), esc_html($currency), esc_html((string) $day_max));
|
|
} else {
|
|
printf(esc_html__('每日可免费获取 %1$s %2$s,超过后将不再获取', 'aksrt'), esc_html((string) $day_max), esc_html($currency));
|
|
}
|
|
} else {
|
|
printf(esc_html__('免费%s无每日上限', 'aksrt'), esc_html($currency));
|
|
}
|
|
?>
|
|
</div>
|
|
</div>
|
|
<button type="button" class="muted-2-color shrink0" data-aksrt-asset-tab="points_date">
|
|
<?php esc_html_e('每日详情', 'aksrt'); ?><i class="fa fas fa-angle-right ml6 em12" aria-hidden="true"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($tasks) : ?>
|
|
<?php foreach ($tasks as $task) : ?>
|
|
<?php
|
|
$task_key = sanitize_key((string) ($task['key'] ?? ''));
|
|
$action = $aksrt_points_task_action($task_key);
|
|
$status = sanitize_key((string) ($task['status'] ?? 'todo'));
|
|
$done = in_array($status, ['done_today', 'done'], true);
|
|
?>
|
|
<div class="border-bottom padding-h10 uc-points-tasks__row<?php echo $done ? ' is-done' : ''; ?>" data-task-key="<?php echo esc_attr($task_key); ?>" data-status="<?php echo esc_attr($status); ?>">
|
|
<div class="flex jsb ac">
|
|
<div class="flex1 mr20">
|
|
<div class="font-bold mb6"><?php echo esc_html((string) $task['title']); ?></div>
|
|
<div class="muted-2-color em09"><?php echo esc_html((string) $task['desc']); ?></div>
|
|
<?php
|
|
$progress = $task['progress'] ?? null;
|
|
$target = $task['target'] ?? null;
|
|
if ($target !== null && (int) $target > 0) :
|
|
$pv = max(0, (int) $progress);
|
|
$tv = max(1, (int) $target);
|
|
$pct = (int) min(100, round(($pv / $tv) * 100));
|
|
?>
|
|
<div class="uc-points-tasks__progress mt6">
|
|
<div class="uc-points-tasks__progress-bar"><span style="width:<?php echo (int) $pct; ?>%"></span></div>
|
|
<div class="muted-2-color em09 mt3"><?php echo esc_html($pv . '/' . $tv); ?></div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<div class="uc-points-tasks__meta shrink0 text-right">
|
|
<div class="focus-color em14">
|
|
<i class="fa fas fa-money-bill mr6 em09" aria-hidden="true"></i>+ <?php echo esc_html((string) (int) $task['points']); ?>
|
|
</div>
|
|
<?php if ($done) : ?>
|
|
<span class="uc-points-tasks__action muted-color em09 mt6"><?php esc_html_e('今日已完成', 'aksrt'); ?></span>
|
|
<?php elseif (($action['type'] ?? 'none') === 'signin') : ?>
|
|
<button type="button" class="uc-points-tasks__action muted-color em09 mt6" data-aksrt-signin-goto>
|
|
<?php echo esc_html((string) $action['label']); ?><i class="fa fas fa-angle-right em12 ml3" aria-hidden="true"></i>
|
|
</button>
|
|
<?php elseif (($action['type'] ?? 'none') === 'link' && !empty($action['href'])) : ?>
|
|
<a class="uc-points-tasks__action muted-color em09 mt6" href="<?php echo esc_url((string) $action['href']); ?>">
|
|
<?php echo esc_html((string) $action['label']); ?><i class="fa fas fa-angle-right em12 ml3" aria-hidden="true"></i>
|
|
</a>
|
|
<?php elseif (($action['type'] ?? 'none') === 'none' && !empty($action['label'])) : ?>
|
|
<span class="uc-points-tasks__action muted-color em09 mt6"><?php echo esc_html((string) $action['label']); ?></span>
|
|
<?php endif; ?> </div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php else : ?>
|
|
<div class="uc-transactions__empty"><p><?php printf(esc_html__('暂无可用%s任务', 'aksrt'), esc_html($currency)); ?></p></div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|