Merge pull request 'feat(pay): free-login gate in access policy plus service/demo helpers' (#116) from worktree-hero-banner-chain into main

Reviewed-on: CYL/wordpress-theme-aksrt#116
This commit is contained in:
2026-07-14 00:55:09 +08:00
3 changed files with 115 additions and 19 deletions
+14 -2
View File
@@ -97,7 +97,11 @@ class AKSRT_Content_Visibility {
: (int) ceil($price);
$state['download_cost'] = max(0, $download_cost);
$state['need_login'] = !empty($paid_settings['download_login']) || !empty($pay_meta['require_login']);
// Zibll pay_free_logged_show: free download still requires login.
$free_logged_show = !empty($paid_settings['free_logged_show']);
$state['need_login'] = !empty($paid_settings['download_login'])
|| !empty($pay_meta['require_login'])
|| ($free_logged_show && $state['download_cost'] <= 0);
$state['require_captcha'] = !empty($paid_settings['download_captcha']) || !empty($pay_meta['require_captcha']);
$state['need_purchase'] = !$has_vip_access && $state['download_cost'] > 0;
$state['has_paid_access'] = $has_vip_access || $has_paid_order || !$state['need_purchase'];
@@ -154,10 +158,18 @@ class AKSRT_Content_Visibility {
]);
}
// Free download + pay_free_logged_show (belt-and-suspenders with state.need_login).
$cost = (int) ($state['download_cost'] ?? 0);
$paid_settings = class_exists('AKSRT_Settings')
? AKSRT_Settings::get_paid_content_settings()
: ['download_credit' => true];
: ['download_credit' => true, 'free_logged_show' => false];
if ($cost <= 0 && !empty($paid_settings['free_logged_show']) && $uid <= 0) {
return new WP_Error('aksrt_need_login', __('免费资源,请登录后下载。', 'aksrt'), [
'status' => 401,
'login_url' => wp_login_url(get_permalink($resource_post)),
]);
}
if (!empty($paid_settings['download_credit']) && $cost > 0) {
$balance = class_exists('AKSRT_Credits') ? AKSRT_Credits::balance($uid) : 0;
+79
View File
@@ -420,6 +420,85 @@ if (!function_exists('aksrt_get_pay_type_badge')) {
}
}
/**
* Zibll zibpay_get_service() — service bullets under pay/download box.
*
* @return string HTML list of service items.
*/
if (!function_exists('aksrt_get_pay_service_html')) {
function aksrt_get_pay_service_html(string $class = 'resource-download-box__guarantee'): string {
$service = [];
if (class_exists('AKSRT_Settings')) {
$order = AKSRT_Settings::get_order_settings();
$service = is_array($order['service'] ?? null) ? $order['service'] : [];
}
$items = [];
$text = trim((string) ($service['text'] ?? ''));
$value = trim((string) ($service['value'] ?? ''));
$icon = trim((string) ($service['icon'] ?? 'fas fa-check-circle'));
if ($icon === '') {
$icon = 'fas fa-check-circle';
}
// Support multi-line pay_service textarea (one bullet per line).
$lines = [];
if ($text !== '') {
$lines = preg_split('/\r\n|\r|\n/', $text) ?: [];
}
if ($value !== '') {
$lines[] = $value;
}
$lines = array_values(array_filter(array_map('trim', $lines)));
if ($lines === []) {
// Defaults aligned with previous hardcoded guarantees.
$lines = [
__('安全检测', 'aksrt'),
__('支持 VIP 权益', 'aksrt'),
__('支持积分结算', 'aksrt'),
];
}
$html = '';
foreach ($lines as $line) {
$html .= '<span class="' . esc_attr($class) . '">';
$html .= '<i class="' . esc_attr($icon) . '" aria-hidden="true"></i> ';
$html .= esc_html($line);
$html .= '</span>';
}
return $html;
}
}
/**
* Demo link button (Zibll zibpay_get_demo_link).
*/
if (!function_exists('aksrt_get_demo_link_html')) {
function aksrt_get_demo_link_html($post = null, string $class = 'resource-download-box__btn btn-outline resource-download-box__btn--demo'): string {
$p = get_post($post);
if (!($p instanceof WP_Post)) {
return '';
}
$meta = aksrt_get_pay_meta($p);
if (($meta['pay_type'] ?? '') !== AKSRT_PAY_TYPE_DOWNLOAD) {
return '';
}
$url = trim((string) ($meta['demo_url'] ?? ''));
if ($url === '') {
return '';
}
$text = __('查看演示', 'aksrt');
return sprintf(
'<a target="_blank" rel="nofollow noopener" href="%s" class="%s"><i class="fas fa-external-link-alt" aria-hidden="true"></i><span>%s</span></a>',
esc_url($url),
esc_attr($class),
esc_html($text)
);
}
}
// ============================================================
// 付费墙 HTML
// ============================================================
+22 -17
View File
@@ -185,12 +185,18 @@ $currency = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_currency_name()
<i class="fas fa-download" aria-hidden="true"></i>
<span><?php esc_html_e('资源下载', 'aksrt'); ?></span>
</a>
<?php if (!empty($meta['demo_url'])) : ?>
<?php
if (function_exists('aksrt_get_demo_link_html')) {
echo aksrt_get_demo_link_html($post_id); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
} elseif (!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>
<span><?php esc_html_e('查看演示', 'aksrt'); ?></span>
</a>
<?php endif; ?>
<?php
}
?>
</div>
<?php else : ?>
<ul class="resource-download-box__list">
@@ -276,22 +282,21 @@ $currency = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_currency_name()
</ul>
<?php endif; ?>
<div class="resource-download-box__guarantees">
<span class="resource-download-box__guarantee">
<i class="fas fa-shield-alt" aria-hidden="true"></i>
<?php esc_html_e('安全检测', 'aksrt'); ?>
</span>
<span class="resource-download-box__guarantee">
<i class="fas fa-crown" aria-hidden="true"></i>
<?php esc_html_e('支持 VIP 权益', 'aksrt'); ?>
</span>
<span class="resource-download-box__guarantee">
<i class="fas fa-coins" aria-hidden="true"></i>
<?php esc_html_e('支持积分结算', 'aksrt'); ?>
</span>
<div class="resource-download-box__guarantees">
<?php
if (function_exists('aksrt_get_pay_service_html')) {
echo aksrt_get_pay_service_html(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
} else {
?>
<span class="resource-download-box__guarantee"><i class="fas fa-shield-alt" aria-hidden="true"></i> <?php esc_html_e('安全检测', 'aksrt'); ?></span>
<span class="resource-download-box__guarantee"><i class="fas fa-crown" aria-hidden="true"></i> <?php esc_html_e('支持 VIP 权益', 'aksrt'); ?></span>
<span class="resource-download-box__guarantee"><i class="fas fa-coins" aria-hidden="true"></i> <?php esc_html_e('支持积分结算', 'aksrt'); ?></span>
<?php
}
?>
</div>
</div>
</div>
</div>
<?php if ($is_need_login) : ?>
<p class="resource-download-box__hint resource-download-box__hint--login">