feat(pay): alone download page, free-login gate, list pay badges
This commit is contained in:
1 parent
0ad41715e2
commit
5acf302e53
8 files changed
+448
-186
No files matched your search
@@ -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();
|
||||
Reference in new issue
Block a user