Files
wordpress-theme-aksrt/templates/pages/page-download.php
T
kate522 8241570ca2 feat(users): govern profiles and access
Normalize fixed profile fields, profile actions, and the five-column capability matrix for comments, uploads, and downloads.
2026-08-13 00:24:54 +08:00

227 lines
12 KiB
PHP

<?php
/**
* Template Name: AKSRT - Download Center
* Template Post Type: page
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
get_header();
$paged = max(1, (int) get_query_var('paged'));
$per_page = 12;
$type_filter = isset($_GET['resource_type']) ? sanitize_key((string) $_GET['resource_type']) : '';
$resource_type_labels = function_exists('aksrt_get_pay_types') ? aksrt_get_pay_types() : [];
unset($resource_type_labels[\AKSRT\Core\DomainModel::PAY_TYPE_READING]);
if ($type_filter !== '' && !isset($resource_type_labels[$type_filter])) {
$type_filter = '';
}
$query_args = [
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => $per_page,
'paged' => $paged,
'orderby' => 'date',
'order' => 'DESC',
'ignore_sticky_posts' => true,
'meta_query' => [
[
'key' => \AKSRT\Core\DomainModel::PAY_TYPE_KEY,
'value' => \AKSRT\Core\DomainModel::PAY_TYPE_DOWNLOAD,
'compare' => '=',
],
],
];
if ($type_filter !== '') {
$query_args['meta_query'][] = [
'key' => \AKSRT\Core\DomainModel::PAY_TYPE_KEY,
'value' => $type_filter,
];
}
$resource_query = new WP_Query($query_args);
$is_logged_in = is_user_logged_in();
$user_credits = 0;
$user_download_count = 0;
if ($is_logged_in) {
$uid = get_current_user_id();
if (class_exists('\AKSRT\Credits\Credits')) {
$user_credits = \AKSRT\Credits\Credits::balance($uid);
}
$dl_meta = get_user_meta($uid, '_aksrt_downloaded_resources', true);
$user_download_count = is_array($dl_meta) ? count($dl_meta) : 0;
}
$currency_name = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_currency_name() : __('积分', 'aksrt');
$dl_requires_login = function_exists('aksrt_user_can') && !aksrt_user_can('resource_download', get_current_user_id());
?>
<main id="main-content" class="site-main container" tabindex="-1">
<?php get_template_part('templates/parts/download/download-hero'); ?>
<div class="aksrt-download-center container">
<div class="content-wrap">
<div class="content-layout">
<div class="content-layout__primary">
<div class="aksrt-dl-status-bar">
<?php if ($is_logged_in) : ?>
<div class="aksrt-dl-status-bar__item">
<i class="fas fa-coins" aria-hidden="true"></i>
<span class="aksrt-dl-status-bar__label"><?php echo esc_html($currency_name); ?></span>
<span class="aksrt-dl-status-bar__value"><?php echo esc_html(number_format_i18n($user_credits)); ?></span>
</div>
<div class="aksrt-dl-status-bar__item">
<i class="fas fa-download" aria-hidden="true"></i>
<span class="aksrt-dl-status-bar__label"><?php esc_html_e('已下载', 'aksrt'); ?></span>
<span class="aksrt-dl-status-bar__value"><?php echo esc_html(number_format_i18n($user_download_count)); ?></span>
</div>
<div class="aksrt-dl-status-bar__item aksrt-dl-status-bar__item--hint">
<i class="fas fa-info-circle" aria-hidden="true"></i>
<span><?php esc_html_e('下载能力已归入统一内容付费模型,可从文章内容页直接解锁和下载。', 'aksrt'); ?></span>
</div>
<?php else : ?>
<div class="aksrt-dl-status-bar__item aksrt-dl-status-bar__item--hint">
<i class="fas fa-lock" aria-hidden="true"></i>
<span>
<?php if ($dl_requires_login) : ?>
<?php esc_html_e('登录后可查看下载状态、积分余额并解锁可下载内容', 'aksrt'); ?>
<?php else : ?>
<?php esc_html_e('登录后可管理下载记录和积分余额', 'aksrt'); ?>
<?php endif; ?>
</span>
</div>
<div class="aksrt-dl-status-bar__actions">
<a href="<?php echo esc_url(aksrt_get_login_url()); ?>" class="btn-outline btn-sm"><?php esc_html_e('登录', 'aksrt'); ?></a>
<?php if (get_option('users_can_register')) : ?>
<a href="<?php echo esc_url(aksrt_get_register_url()); ?>" class="btn-primary btn-sm"><?php esc_html_e('注册', 'aksrt'); ?></a>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<div class="aksrt-download-center__layout">
<div class="aksrt-download-center__main">
<div class="theme-box box-body aksrt-download-center__intro">
<h2><?php esc_html_e('内容下载中心(兼容入口)', 'aksrt'); ?></h2>
<p><?php esc_html_e('这里汇总所有已启用“付费下载”能力的文章,下载只是统一付费体系中的一种交付方式;普通文章内容页仍是主消费入口。', 'aksrt'); ?></p>
</div>
<?php if ($resource_query->have_posts()) : ?>
<div class="aksrt-download-center__grid">
<?php while ($resource_query->have_posts()) : $resource_query->the_post(); ?>
<article class="aksrt-download-card<?php echo function_exists('aksrt_is_resource_post') && aksrt_is_resource_post(get_the_ID()) ? ' is-resource' : ''; ?>">
<?php if (has_post_thumbnail()) : ?>
<div class="aksrt-download-card__thumb">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('medium'); ?>
</a>
</div>
<?php endif; ?>
<div class="aksrt-download-card__body">
<p class="aksrt-download-card__eyebrow">
<?php echo esc_html(function_exists('aksrt_is_resource_post') && aksrt_is_resource_post(get_the_ID()) ? __('资源内容入口', 'aksrt') : __('内容付费入口', 'aksrt')); ?>
</p>
<h3 class="aksrt-download-card__title">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h3>
<p class="aksrt-download-card__excerpt"><?php echo esc_html(wp_trim_words(get_the_excerpt(), 20)); ?></p>
<div class="aksrt-download-card__meta">
<span class="aksrt-download-card__date">
<i class="fas fa-clock"></i>
<?php echo esc_html(get_the_date()); ?>
</span>
<?php
$dl_count = (int) get_post_meta(get_the_ID(), \AKSRT\Core\DomainModel::RESOURCE_DOWNLOAD_COUNT_KEY, true);
if ($dl_count > 0) :
?>
<span class="aksrt-download-card__downloads">
<i class="fas fa-download"></i>
<?php echo esc_html(number_format_i18n($dl_count)); ?>
</span>
<?php endif; ?>
</div>
<?php
$card_meta = function_exists('aksrt_get_download_box_meta') ? aksrt_get_download_box_meta(get_the_ID()) : [];
$price_label = function_exists('aksrt_get_pay_price_label')
? aksrt_get_pay_price_label(get_the_ID())
: ['text' => __('免费', 'aksrt'), 'free' => true];
?>
<div class="aksrt-download-card__footer">
<span class="aksrt-download-card__price<?php echo !empty($price_label['free']) ? ' is-free' : ' is-paid'; ?>">
<?php echo esc_html((string) ($price_label['text'] ?? '')); ?>
</span>
<a href="<?php the_permalink(); ?>" class="aksrt-download-card__action">
<?php esc_html_e('进入内容页', 'aksrt'); ?>
<i class="fas fa-arrow-right" aria-hidden="true"></i>
</a>
</div>
</div>
</article>
<?php endwhile; ?>
</div>
<?php
if (function_exists('aksrt_render_pagination')) {
aksrt_render_pagination($resource_query);
}
wp_reset_postdata();
?>
<?php else : ?>
<div class="aksrt-download-center__empty">
<i class="fas fa-folder-open"></i>
<p><?php esc_html_e('暂无启用下载能力的内容。', 'aksrt'); ?></p>
</div>
<?php endif; ?>
</div>
<aside class="aksrt-download-center__sidebar sidebar">
<?php get_template_part('templates/parts/download/download-permission-card'); ?>
<div class="aksrt-dl-sidebar-card">
<h3 class="aksrt-dl-sidebar-card__title">
<i class="fas fa-folder"></i>
<?php esc_html_e('下载类型', 'aksrt'); ?>
</h3>
<?php if (!empty($resource_type_labels)) : ?>
<ul class="aksrt-dl-sidebar-card__list">
<li class="<?php echo $type_filter === '' ? 'is-active' : ''; ?>">
<a href="<?php echo esc_url(get_permalink()); ?>">
<?php esc_html_e('全部可下载内容', 'aksrt'); ?>
</a>
</li>
<?php foreach ($resource_type_labels as $type_key => $type_label) : ?>
<li class="<?php echo $type_filter === $type_key ? 'is-active' : ''; ?>">
<a href="<?php echo esc_url(add_query_arg('resource_type', $type_key, get_permalink())); ?>">
<?php echo esc_html($type_label); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
<div class="aksrt-dl-sidebar-card">
<h3 class="aksrt-dl-sidebar-card__title">
<i class="fas fa-lightbulb"></i>
<?php esc_html_e('下载须知', 'aksrt'); ?>
</h3>
<div class="aksrt-dl-sidebar-card__tips">
<p><i class="fas fa-book-open" aria-hidden="true"></i> <?php esc_html_e('优先从普通文章内容页进入主付费链路', 'aksrt'); ?></p>
<p><i class="fas fa-clock" aria-hidden="true"></i> <?php esc_html_e('下载链接 10 分钟内有效', 'aksrt'); ?></p>
<p><i class="fas fa-sync-alt" aria-hidden="true"></i> <?php esc_html_e('下载中心作为统一内容付费的补充入口', 'aksrt'); ?></p>
</div>
</div>
</div>
</div>
</div>
</main>
<?php
get_footer();