feat(user-center): task list go-to actions for free points
Add per-task CTAs (去签到 / 去完成 / 去看看) on the free points tasks list, with sign-in proxying to the asset-card button and bbs actions gated on forum availability.
This commit is contained in:
1 parent
17cb9b8542
commit
a3585b0f96
3 files changed
+150
-4
No files matched your search
@@ -11,6 +11,94 @@ if (!class_exists('AKSRT_Points_Free') || !AKSRT_Points_Free::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');
|
||||
}
|
||||
|
||||
$forum_on = false;
|
||||
$forum_home = '';
|
||||
$forum_compose = '';
|
||||
if (class_exists('AKSRT_Settings') && method_exists('AKSRT_Settings', 'get_forum_settings')) {
|
||||
$f = AKSRT_Settings::get_forum_settings();
|
||||
$forum_on = !empty($f['enabled']);
|
||||
}
|
||||
if ($forum_on) {
|
||||
if (function_exists('aksrt_get_forum_home_url')) {
|
||||
$forum_home = (string) aksrt_get_forum_home_url();
|
||||
}
|
||||
if (function_exists('aksrt_get_forum_compose_url')) {
|
||||
$forum_compose = (string) aksrt_get_forum_compose_url();
|
||||
}
|
||||
}
|
||||
|
||||
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':
|
||||
return [
|
||||
'type' => 'link',
|
||||
'label' => __('去完成', 'aksrt'),
|
||||
'href' => $home,
|
||||
];
|
||||
case 'login':
|
||||
case 'post_like':
|
||||
case 'post_favorite':
|
||||
case 'followed':
|
||||
case 'comment_like':
|
||||
return [
|
||||
'type' => 'link',
|
||||
'label' => __('去看看', 'aksrt'),
|
||||
'href' => $home,
|
||||
];
|
||||
case 'bbs_posts_new':
|
||||
case 'bbs_reply':
|
||||
if (!$forum_on) {
|
||||
return ['type' => 'none', 'label' => ''];
|
||||
}
|
||||
$href = $forum_compose !== '' ? $forum_compose : $forum_home;
|
||||
if ($href === '') {
|
||||
return ['type' => 'none', 'label' => ''];
|
||||
}
|
||||
return [
|
||||
'type' => 'link',
|
||||
'label' => __('去完成', 'aksrt'),
|
||||
'href' => $href,
|
||||
];
|
||||
case 'bbs_essence':
|
||||
case 'bbs_adopt':
|
||||
case 'bbs_posts_hot':
|
||||
case 'bbs_comment_hot':
|
||||
case 'bbs_score_extra':
|
||||
if (!$forum_on || $forum_home === '') {
|
||||
return ['type' => 'none', 'label' => ''];
|
||||
}
|
||||
return [
|
||||
'type' => 'link',
|
||||
'label' => __('去看看', 'aksrt'),
|
||||
'href' => $forum_home,
|
||||
];
|
||||
default:
|
||||
return ['type' => 'none', 'label' => ''];
|
||||
}
|
||||
};
|
||||
|
||||
$user_id = (int) ($user_id ?? get_current_user_id());
|
||||
$today = AKSRT_Points_Free::today_total($user_id);
|
||||
$day_max = (int) AKSRT_Points_Free::settings()['day_max'];
|
||||
@@ -76,15 +164,30 @@ $pane = isset($points_tasks_pane) ? sanitize_key((string) $points_tasks_pane)
|
||||
|
||||
<?php if ($tasks) : ?>
|
||||
<?php foreach ($tasks as $task) : ?>
|
||||
<div class="border-bottom padding-h10">
|
||||
<?php
|
||||
$task_key = sanitize_key((string) ($task['key'] ?? ''));
|
||||
$action = $aksrt_points_task_action($task_key);
|
||||
?>
|
||||
<div class="border-bottom padding-h10 uc-points-tasks__row" data-task-key="<?php echo esc_attr($task_key); ?>">
|
||||
<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>
|
||||
</div>
|
||||
<span class="focus-color em14 shrink0">
|
||||
<i class="fas fa-coins mr6 em09" aria-hidden="true"></i>+ <?php echo esc_html((string) (int) $task['points']); ?>
|
||||
</span>
|
||||
<div class="uc-points-tasks__meta shrink0 text-right">
|
||||
<div class="focus-color em14">
|
||||
<i class="fas fa-coins mr6 em09" aria-hidden="true"></i>+ <?php echo esc_html((string) (int) $task['points']); ?>
|
||||
</div>
|
||||
<?php if (($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 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 fa-angle-right em12 ml3" aria-hidden="true"></i>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
Reference in new issue
Block a user