Files
wordpress-theme-aksrt/inc/helpers/user-center-renderers/credits-points-tasks.php
T
kate522 9375b1c30c refactor(assets): vendor 资产迁入标准目录并全仓去除 zibll 标识
- assets/vendor 全量迁移: fontawesome5→assets/fontawesome5, css→assets/css,
  js→assets/js/runtime(避开 14 个同名自有文件), img 合并去重→assets/img,
  fonts→assets/fonts; 删除 assets/vendor
- libs 五个与 widgets/third-party 字节相同的库不重复入库, loader paths 改指向
- 运行时切换: _win.uri=assets 根, loader baseUrl=/js/runtime, enlighter 注入
  路径同步; PHP 7 个引用文件切换并改名 $zibll_*→$runtime_*
- 去品牌: Qinver 头注释/品牌 console.log/演示链接清除, 默认文案中性化
- 功能标识符改名: zib__→aksrt__, zib_ajax→aksrt_ajax, window.zib→
  window.aksrtLegacy, zibllblock/*→aksrtblock/*, .zib-widget→.aksrt-panel,
  .zib-slider→.aksrt-slider, zib_menu_options meta 键等
- 自有 CSS 改名: legacy-utilities/compat-vars/footer shell
- admin SPA 重建; 契约测试同步(路径/断言/文件更名)
- 例外保留: tests/visual 对照环境与 fixtures 前缀(外部 Zibll 产品引用)

验证: php -l 133 个改动文件通过; runtime 86 个 JS node --check 通过;
契约测试 68/70(2 个失败经 stash 对照确认为存量问题)
2026-08-22 16:16:30 +08:00

200 lines
7.6 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';
?>
<?php if ($pane === 'date') : ?>
<div class="uc-points-date">
<div class="flex jsb ac mb10">
<div class="font-bold"><?php esc_html_e('每日免费积分明细', 'aksrt'); ?></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 esc_html_e('暂无免费积分获取明细', 'aksrt'); ?></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,将不再获取', 'aksrt'), esc_html((string) $day_max));
} else {
printf(esc_html__('每日可免费获取 %s 积分,超过后将不再获取', 'aksrt'), esc_html((string) $day_max));
}
} else {
esc_html_e('免费积分无每日上限', 'aksrt');
}
?>
</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 esc_html_e('暂无可用积分任务', 'aksrt'); ?></p></div>
<?php endif; ?>
</div>
<?php endif; ?>