Merge pull request 'feat(pay): alone download page, free-login gate, list pay badges' (#115) from worktree-hero-banner-chain into main

Reviewed-on: CYL/wordpress-theme-aksrt#115
This commit is contained in:
kate522 committed 2026-07-14 00:44:27 +08:00
commit 0f855e9209
8 files changed
+275 -13

No files matched your search

@@ -15,6 +15,8 @@ export const paidSchema = {
pay_show_paycount: true, pay_show_paycount: true,
pay_box_position: 'top', pay_box_position: 'top',
payment_download_enable: false, payment_download_enable: false,
payment_down_alone_page: false,
pay_free_logged_show: false,
payment_download_remote_s: true, payment_download_remote_s: true,
payment_download_verify_nonce: true, payment_download_verify_nonce: true,
payment_download_user_log: 50, payment_download_user_log: 50,
@@ -52,6 +54,7 @@ export const paidSchema = {
{ key: 'pay_show_user', label: '显示购买用户', type: 'switch', default: true }, { key: 'pay_show_user', label: '显示购买用户', type: 'switch', default: true },
{ key: 'pay_show_paycount', label: '显示购买次数', type: 'switch', default: true }, { key: 'pay_show_paycount', label: '显示购买次数', type: 'switch', default: true },
{ key: 'pay_box_position', label: '付费框位置', type: 'radio', default: 'top', options: [{ label: '文章框顶部(封面后)', value: 'box_top' }, { label: '正文顶部', value: 'top' }, { label: '正文底部', value: 'bottom' }, { label: '文章框底部(相关前)', value: 'box_bottom' }] }, { key: 'pay_box_position', label: '付费框位置', type: 'radio', default: 'top', options: [{ label: '文章框顶部(封面后)', value: 'box_top' }, { label: '正文顶部', value: 'top' }, { label: '正文底部', value: 'bottom' }, { label: '文章框底部(相关前)', value: 'box_bottom' }] },
{ key: 'pay_free_logged_show', label: '免费资源需登录后下载', type: 'switch', default: false, help: '开启后,价格为 0 的下载资源也要求登录才可下载(对齐 zibll pay_free_logged_show)。' },
], ],
}, },
{ {
@@ -60,6 +63,7 @@ export const paidSchema = {
icon: 'fas fa-cloud-download-alt', icon: 'fas fa-cloud-download-alt',
fields: [ fields: [
{ key: 'payment_download_enable', label: '启用下载功能', type: 'switch', default: false }, { key: 'payment_download_enable', label: '启用下载功能', type: 'switch', default: false },
{ key: 'payment_down_alone_page', label: '独立下载页面', type: 'switch', default: false, help: '开启后,已获权限的下载入口跳转到独立下载页(模板:单篇资源下载),而不是在正文内联显示全部下载按钮。', dependsOn: { key: 'payment_download_enable', value: true } },
{ key: 'payment_download_remote_s', label: '远程文件下载', type: 'switch', default: true, dependsOn: { key: 'payment_download_enable', value: true } }, { key: 'payment_download_remote_s', label: '远程文件下载', type: 'switch', default: true, dependsOn: { key: 'payment_download_enable', value: true } },
{ key: 'payment_download_verify_nonce', label: '下载鉴权', type: 'switch', default: true, dependsOn: { key: 'payment_download_enable', value: true } }, { key: 'payment_download_verify_nonce', label: '下载鉴权', type: 'switch', default: true, dependsOn: { key: 'payment_download_enable', value: true } },
{ key: 'payment_download_user_log', label: '用户下载记录条数', type: 'number', default: 50, min: 0, max: 9999, help: '0 为不保存', dependsOn: { key: 'payment_download_enable', value: true } }, { key: 'payment_download_user_log', label: '用户下载记录条数', type: 'number', default: 50, min: 0, max: 9999, help: '0 为不保存', dependsOn: { key: 'payment_download_enable', value: true } },
@@ -40,9 +40,11 @@ class AKSRT_Admin_Schema_Payment {
['label' => '正文底部', 'value' => 'bottom'], ['label' => '正文底部', 'value' => 'bottom'],
['label' => '文章框底部', 'value' => 'box_bottom'], ['label' => '文章框底部', 'value' => 'box_bottom'],
]], ]],
['key' => 'pay_free_logged_show', 'label' => '免费资源需登录后下载', 'type' => 'switch', 'default' => false],
]], ]],
['key' => 'download', 'title' => '下载能力', 'fields' => [ ['key' => 'download', 'title' => '下载能力', 'fields' => [
['key' => 'payment_download_enable', 'label' => '启用下载能力', 'type' => 'switch', 'default' => false], ['key' => 'payment_download_enable', 'label' => '启用下载能力', 'type' => 'switch', 'default' => false],
['key' => 'payment_down_alone_page', 'label' => '独立下载页面', 'type' => 'switch', 'default' => false],
['key' => 'payment_download_remote_s', 'label' => '远程文件下载', 'type' => 'switch', 'default' => true], ['key' => 'payment_download_remote_s', 'label' => '远程文件下载', 'type' => 'switch', 'default' => true],
['key' => 'payment_download_verify_nonce', 'label' => '下载鉴权', 'type' => 'switch', 'default' => true], ['key' => 'payment_download_verify_nonce', 'label' => '下载鉴权', 'type' => 'switch', 'default' => true],
['key' => 'payment_download_user_log', 'label' => '用户下载记录条数', 'type' => 'number', 'default' => 50, 'min' => 0, 'max' => 9999], ['key' => 'payment_download_user_log', 'label' => '用户下载记录条数', 'type' => 'number', 'default' => 50, 'min' => 0, 'max' => 9999],
@@ -53,6 +53,8 @@ class AKSRT_Settings_Payment_Runtime {
'catalog_note' => $catalog_note, 'catalog_note' => $catalog_note,
'manual_delivery_note' => $manual_note !== '' ? $manual_note : __('付费或人工确认内容请在订单备注中记录交付方式。', 'aksrt'), 'manual_delivery_note' => $manual_note !== '' ? $manual_note : __('付费或人工确认内容请在订单备注中记录交付方式。', 'aksrt'),
'no_logged_in' => !isset($settings['pay_no_logged_in']) || !empty($settings['pay_no_logged_in']), 'no_logged_in' => !isset($settings['pay_no_logged_in']) || !empty($settings['pay_no_logged_in']),
'free_logged_show' => !empty($settings['pay_free_logged_show']),
'down_alone_page' => !empty($settings['payment_down_alone_page']),
'display' => [ 'display' => [
'mark' => sanitize_text_field((string) ($settings['pay_mark'] ?? '付费')), 'mark' => sanitize_text_field((string) ($settings['pay_mark'] ?? '付费')),
'currency_symbol' => sanitize_text_field((string) ($settings['payment_currency_symbol'] ?? '¥')), 'currency_symbol' => sanitize_text_field((string) ($settings['payment_currency_symbol'] ?? '¥')),
@@ -68,6 +70,7 @@ class AKSRT_Settings_Payment_Runtime {
'post_log' => max(0, min(9999, (int) ($settings['payment_download_post_log'] ?? 50))), 'post_log' => max(0, min(9999, (int) ($settings['payment_download_post_log'] ?? 50))),
'remote_size' => max(1, (int) ($settings['payment_download_remote_size'] ?? 2048)), 'remote_size' => max(1, (int) ($settings['payment_download_remote_size'] ?? 2048)),
'remote_ext' => sanitize_text_field((string) ($settings['payment_download_remote_ext'] ?? 'zip,rar,7z')), 'remote_ext' => sanitize_text_field((string) ($settings['payment_download_remote_ext'] ?? 'zip,rar,7z')),
'alone_page' => !empty($settings['payment_down_alone_page']),
], ],
]; ];
} }
+39
View File
@@ -328,6 +328,45 @@ if (!function_exists('aksrt_get_download_cost')) {
} }
} }
/**
* URL of the Zibll-style single-post download page (page template + ?post=ID).
*/
if (!function_exists('aksrt_get_single_download_page_url')) {
function aksrt_get_single_download_page_url($post = null): string {
$p = get_post($post);
if (!($p instanceof WP_Post)) {
return '';
}
$page_url = '';
if (function_exists('aksrt_find_template_page')) {
$page = aksrt_find_template_page('templates/pages/page-download-file.php');
if ($page instanceof WP_Post) {
$page_url = get_permalink($page);
}
}
if ($page_url === '') {
// Fallback: look for any page using the template via slug convention.
$page_url = home_url('/download-file/');
}
return add_query_arg('post', (int) $p->ID, $page_url);
}
}
/**
* Whether independent download page mode is enabled (Zibll down_alone_page).
*/
if (!function_exists('aksrt_is_download_alone_page_enabled')) {
function aksrt_is_download_alone_page_enabled(): bool {
if (!class_exists('AKSRT_Settings')) {
return false;
}
$paid = AKSRT_Settings::get_paid_content_settings();
return !empty($paid['down_alone_page']) || !empty($paid['download']['alone_page']);
}
}
// ============================================================ // ============================================================
// 价格显示 // 价格显示
// ============================================================ // ============================================================
+35 -9
View File
@@ -145,28 +145,54 @@ if (!function_exists('aksrt_resource_price_amount')) {
if (!function_exists('aksrt_resource_card_badge_text')) { if (!function_exists('aksrt_resource_card_badge_text')) {
/** /**
* Resource badge text used in mixed post cards. * List-card pay badge (Zibll zib_get_posts_list_pay_tags equivalent).
* *
* Only resource-type posts should render this badge. * Renders for any paid post type, not only download resources.
* Returns plain text; card template wraps with link + class.
* *
* @param int|WP_Post|null $post * @param int|WP_Post|null $post
* @return string * @return string
*/ */
function aksrt_resource_card_badge_text($post = null): string { function aksrt_resource_card_badge_text($post = null): string {
if (!function_exists('aksrt_is_resource_post') || !aksrt_is_resource_post($post)) { $p = get_post($post);
if (!($p instanceof WP_Post)) {
return ''; return '';
} }
$meta = aksrt_get_resource_meta($post); $meta = function_exists('aksrt_get_pay_meta') ? aksrt_get_pay_meta($p) : null;
$price = (float) $meta['price']; if (!is_array($meta)) {
if ($price <= 0) {
// 免费资源不在卡片上显示价格 chip。
return ''; return '';
} }
$pay_type = (string) ($meta['pay_type'] ?? 'no');
if ($pay_type === '' || $pay_type === 'no') {
return '';
}
$price = (float) ($meta['price'] ?? 0);
$type_labels = function_exists('aksrt_get_pay_types') ? aksrt_get_pay_types() : [];
$type_name = $type_labels[$pay_type] ?? __('付费内容', 'aksrt');
// VIP-only posts.
if ($pay_type === 'vip') {
return __('会员专属', 'aksrt');
}
// Free paid-type (price 0): Zibll shows "免费资源" / free type name.
if ($price <= 0) {
if ($pay_type === 'download') {
return __('免费资源', 'aksrt');
}
// e.g. 付费阅读 → 免费阅读
return str_replace(__('付费', 'aksrt'), __('免费', 'aksrt'), (string) $type_name);
}
$currency = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_currency_name() : __('积分', 'aksrt'); $currency = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_currency_name() : __('积分', 'aksrt');
return sprintf(__('付费 %s %s', 'aksrt'), aksrt_resource_price_amount($price), $currency); $amount = function_exists('aksrt_resource_price_amount')
? aksrt_resource_price_amount($price)
: (string) $price;
return sprintf('%s %s%s', $type_name, $amount, $currency);
} }
} }
+154
View File
@@ -0,0 +1,154 @@
<?php
/**
* Template Name: AKSRT - 单篇资源下载
* Template Post Type: page
*
* Zibll pages/download.php equivalent.
* URL: {page}?post={post_id}
* Only for pay_type=download posts. Shows download buttons when allowed,
* or a no-permission state with a back link to the article.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
$post_id = isset($_GET['post']) ? absint($_GET['post']) : 0;
$post = $post_id > 0 ? get_post($post_id) : null;
if (!$post instanceof WP_Post || $post->post_status !== 'publish') {
get_header();
echo '<main class="container"><div class="content-wrap"><div class="content-layout">';
echo '<div class="alert jb-red em12" style="margin:2em;"><b>' . esc_html__('无效的下载请求', 'aksrt') . '</b></div>';
echo '</div></div></main>';
get_footer();
exit;
}
$pay_meta = function_exists('aksrt_get_pay_meta') ? aksrt_get_pay_meta($post) : ['pay_type' => 'no', 'downloads' => []];
$pay_type = (string) ($pay_meta['pay_type'] ?? 'no');
$is_download = $pay_type === 'download' || (function_exists('aksrt_is_downloadable_content') && aksrt_is_downloadable_content($post));
if (!$is_download) {
get_header();
echo '<main class="container"><div class="content-wrap"><div class="content-layout">';
echo '<div class="alert jb-red em12" style="margin:2em;"><b>' . esc_html__('该内容不是可下载资源', 'aksrt') . '</b></div>';
echo '<p><a class="but jb-yellow padding-lg" href="' . esc_url(get_permalink($post)) . '#posts-pay"><i class="fa fa-long-arrow-left" aria-hidden="true"></i><span class="ml10">' . esc_html__('返回文章', 'aksrt') . '</span></a></p>';
echo '</div></div></main>';
get_footer();
exit;
}
$article_url = get_permalink($post) . '#posts-pay';
$pay_title = get_the_title($post);
$subtitle = '';
if (function_exists('get_the_subtitle')) {
// noop — AKSRT may not have zibll subtitle helper
}
$has_access = function_exists('aksrt_has_paid_access') ? aksrt_has_paid_access($post) : false;
$gate = function_exists('aksrt_can_download') ? aksrt_can_download($post) : true;
$can_dl = $gate === true;
$need_login = is_wp_error($gate) && $gate->get_error_code() === 'aksrt_need_login';
// Free download + login required (Zibll pay_free_logged_show).
$price = (float) ($pay_meta['price'] ?? 0);
$order_settings = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_order_settings() : [];
$free_logged_show = !empty($order_settings['free_logged_show']);
if ($price <= 0 && $free_logged_show && !is_user_logged_in()) {
$can_dl = false;
$need_login = true;
$has_access = true; // free "access" but must login to download
}
$paid_name = '';
if ($has_access || $can_dl) {
if ($price <= 0) {
$paid_name = __('免费资源', 'aksrt');
} else {
$paid_name = __('已获得下载权限', 'aksrt');
}
}
get_header();
?>
<style>
.aksrt-single-download .but-download > .but,
.aksrt-single-download .but-download > a,
.aksrt-single-download .but-download > button,
.aksrt-single-download .resource-download-box__btn {
min-width: 200px;
padding: .5em;
margin-top: 10px;
}
.aksrt-single-download .pay-extra-hide {
background: var(--muted-border-color, #f0f0f0);
display: block;
margin: 10px 0;
padding: 20px;
color: var(--muted-color, #888);
border-radius: 4px;
}
</style>
<main class="container aksrt-single-download">
<div class="content-wrap">
<div class="content-layout">
<article class="article page-article main-bg theme-box box-body radius8 main-shadow">
<div class="pay-box">
<div class="article-header theme-box">
<div class="article-title">
<a href="<?php echo esc_url($article_url); ?>"><?php echo esc_html($pay_title); ?></a>
</div>
<?php if ($paid_name !== '') : ?>
<b class="badg jb-red mr6" style="font-size:12px;padding:2px 10px;line-height:1.4;">
<i class="fa fa-check mr6" aria-hidden="true"></i><?php echo esc_html($paid_name); ?>
</b>
<?php endif; ?>
</div>
<?php if ($can_dl) : ?>
<div style="margin-bottom:2em;" class="pay-box">
<?php
// Reuse single download box UI for the allowed state.
global $post;
$GLOBALS['post'] = $post;
setup_postdata($post);
$GLOBALS['aksrt_on_download_file_page'] = true;
get_template_part('templates/parts/resource-download-box');
unset($GLOBALS['aksrt_on_download_file_page']);
wp_reset_postdata();
?>
</div>
<?php elseif ($need_login) : ?>
<div class="alert jb-yellow em12" style="margin:2em;">
<b><?php esc_html_e('免费资源,请登录后下载', 'aksrt'); ?></b>
</div>
<div class="pay-extra-hide">
<?php
$login_url = wp_login_url(add_query_arg('post', $post_id, get_permalink()));
printf(
/* translators: %s: login url */
wp_kses_post(__('Hi!请先 <a href="%s">登录</a> 后再下载。', 'aksrt')),
esc_url($login_url)
);
?>
</div>
<a style="margin-bottom:2em;" href="<?php echo esc_url($article_url); ?>" class="but jb-yellow padding-lg">
<i class="fa fa-long-arrow-left" aria-hidden="true"></i>
<span class="ml10"><?php esc_html_e('返回文章', 'aksrt'); ?></span>
</a>
<?php else : ?>
<div class="alert jb-red em12" style="margin:2em;">
<b><?php esc_html_e('暂无下载权限', 'aksrt'); ?></b>
</div>
<a style="margin-bottom:2em;" href="<?php echo esc_url($article_url); ?>" class="but jb-yellow padding-lg">
<i class="fa fa-long-arrow-left" aria-hidden="true"></i>
<span class="ml10"><?php esc_html_e('返回文章', 'aksrt'); ?></span>
</a>
<?php endif; ?>
</div>
</article>
</div>
</div>
</main>
<?php
get_footer();
+1 -1
View File
@@ -95,7 +95,7 @@ ob_start();
?>␍ ?>␍
<div class="item-tags scroll-x no-scrollbar">␍ <div class="item-tags scroll-x no-scrollbar">␍
<?php if ($resource_badge !== '') : ?>␍ <?php if ($resource_badge !== '') : ?>␍
<badge class="meta-pay but jb-yellow"><?php echo esc_html($resource_badge); ?></badge> <a rel="nofollow" href="<?php echo esc_url(get_permalink($post_id) . '#posts-pay'); ?>" class="meta-pay but jb-yellow"><?php echo esc_html($resource_badge); ?></a>␍
<?php endif; ?>␍ <?php endif; ?>␍
<?php foreach (array_slice($categories, 0, $category_limit) as $category) : ?>␍ <?php foreach (array_slice($categories, 0, $category_limit) as $category) : ?>␍
<a href="<?php echo esc_url(get_category_link($category->term_id)); ?>" class="but"><i class="far fa-folder-open" aria-hidden="true"></i> <?php echo esc_html($category->name); ?></a>␍ <a href="<?php echo esc_url(get_category_link($category->term_id)); ?>" class="but"><i class="far fa-folder-open" aria-hidden="true"></i> <?php echo esc_html($category->name); ?></a>␍
+37 -3
View File
@@ -55,7 +55,26 @@ $balance = (int) ($gate_data['balance'] ?? 0);
$login_url = (string) ($gate_data['login_url'] ?? wp_login_url(get_permalink($post_id))); $login_url = (string) ($gate_data['login_url'] ?? wp_login_url(get_permalink($post_id)));
$is_need_login = $gate_blocked && $gate_code === 'aksrt_need_login'; $is_need_login = $gate_blocked && $gate_code === 'aksrt_need_login';
$is_low_credit = $gate_blocked && $gate_code === 'aksrt_credits_insufficient'; $is_low_credit = $gate_blocked && $gate_code === 'aksrt_credits_insufficient';
// Zibll pay_free_logged_show: free downloads still require login.
$free_logged_show = !empty($paid_settings['free_logged_show']);
$price_amount = (float) ($meta['price'] ?? 0);
if ($price_amount <= 0 && $free_logged_show && !is_user_logged_in()) {
$is_need_login = true;
$gate_blocked = true;
}
// Zibll down_alone_page: single entry to independent download page.
$alone_page = !empty($paid_settings['down_alone_page']) || !empty($paid_settings['download']['alone_page']);
$alone_url = '';
if ($alone_page && function_exists('aksrt_get_single_download_page_url')) {
$alone_url = aksrt_get_single_download_page_url($post_id);
}
$use_alone_entry = $alone_page && $alone_url !== '' && !$is_need_login && !$is_low_credit;
if (!empty($GLOBALS['aksrt_on_download_file_page'])) {
$use_alone_entry = false;
}
// 缩略图 // 缩略图
$thumbnail = get_the_post_thumbnail_url($post_id, 'medium') ?: ''; $thumbnail = get_the_post_thumbnail_url($post_id, 'medium') ?: '';
@@ -160,7 +179,21 @@ $currency = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_currency_name()
<p class="resource-download-box__catalog-note"><?php echo esc_html((string) $paid_settings['catalog_note']); ?></p> <p class="resource-download-box__catalog-note"><?php echo esc_html((string) $paid_settings['catalog_note']); ?></p>
<?php endif; ?> <?php endif; ?>
<ul class="resource-download-box__list"> <?php if (!empty($use_alone_entry)) : ?>
<div class="mt10 resource-download-box__alone">
<a target="_blank" rel="nofollow" href="<?php echo esc_url($alone_url); ?>" class="resource-download-box__btn btn-primary resource-download-box__btn--alone">
<i class="fas fa-download" aria-hidden="true"></i>
<span><?php esc_html_e('资源下载', 'aksrt'); ?></span>
</a>
<?php if (!empty($meta['demo_url'])) : ?>
<a target="_blank" rel="nofollow" href="<?php echo esc_url((string) $meta['demo_url']); ?>" class="resource-download-box__btn btn-outline resource-download-box__btn--demo">
<i class="fas fa-external-link-alt" aria-hidden="true"></i>
<span><?php esc_html_e('在线演示', 'aksrt'); ?></span>
</a>
<?php endif; ?>
</div>
<?php else : ?>
<ul class="resource-download-box__list">
<?php foreach ($downloads as $idx => $row) : <?php foreach ($downloads as $idx => $row) :
$label = isset($row['label']) ? (string) $row['label'] : ''; $label = isset($row['label']) ? (string) $row['label'] : '';
if ($label === '') { if ($label === '') {
@@ -241,6 +274,7 @@ $currency = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_currency_name()
</li> </li>
<?php endforeach; ?> <?php endforeach; ?>
</ul> </ul>
<?php endif; ?>
<div class="resource-download-box__guarantees"> <div class="resource-download-box__guarantees">
<span class="resource-download-box__guarantee"> <span class="resource-download-box__guarantee">
@@ -262,7 +296,7 @@ $currency = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_currency_name()
<?php if ($is_need_login) : ?> <?php if ($is_need_login) : ?>
<p class="resource-download-box__hint resource-download-box__hint--login"> <p class="resource-download-box__hint resource-download-box__hint--login">
<i class="fas fa-info-circle" aria-hidden="true"></i> <i class="fas fa-info-circle" aria-hidden="true"></i>
<?php esc_html_e('登录后可解锁并下载该内容。', 'aksrt'); ?> <?php echo (isset($price_amount) && $price_amount <= 0) ? esc_html__('免费资源,请登录后下载。', 'aksrt') : esc_html__('登录后可解锁并下载该内容。', 'aksrt'); ?>
</p> </p>
<?php elseif ($is_low_credit) : ?> <?php elseif ($is_low_credit) : ?>
<p class="resource-download-box__hint resource-download-box__hint--credit"> <p class="resource-download-box__hint resource-download-box__hint--credit">