进行了一些小修复

This commit is contained in:
2026-08-26 15:11:25 +08:00
parent d37c34f71c
commit ae10b3d3fd
16 changed files with 278 additions and 417 deletions
+144 -244
View File
@@ -157,25 +157,6 @@ if (!function_exists('aksrt_get_pay_meta')) {
if (!function_exists('aksrt_default_pay_meta')) {
function aksrt_default_pay_meta(): array {
return \AKSRT\Core\DomainModel::default_pay_meta();
return [
'pay_type' => AKSRT_PAY_TYPE_NO,
'price' => 0.0,
'original_price' => 0.0,
'vip1_price' => 0.0,
'vip2_price' => 0.0,
'version' => '',
'size' => '',
'license' => '',
'compat' => '',
'demo_url' => '',
'downloads' => [],
'require_login' => false,
'require_captcha' => false,
'attributes' => [],
'gallery' => [],
'video_url' => '',
];
}
}
@@ -1195,101 +1176,127 @@ if (!function_exists('aksrt_get_pay_attributes_html')) {
// ============================================================
if (!function_exists('aksrt_get_paywall_html')) {
function aksrt_get_paywall_html(WP_Post $post, bool $is_fragment = false): string {
function aksrt_get_paywall_html(WP_Post $post, array $args = []): string {
$is_widget = ($args['layout'] ?? 'article') === 'widget';
$theme = sanitize_html_class((string) ($args['theme'] ?? 'jb-red')) ?: 'jb-red';
$meta = aksrt_get_pay_meta($post);
$pay_type = $meta['pay_type'];
$priced = function_exists('aksrt_get_user_pay_price') ? aksrt_get_user_pay_price($post) : null;
$pay_modo = is_array($priced) ? ((($priced['modo'] ?? '0') === 'points') ? 'points' : '0') : ((($meta['pay_modo'] ?? '0') === 'points') ? 'points' : '0');
$price = is_array($priced)
? ($priced['amount'] ?? ($pay_modo === 'points' ? 0 : '0.00'))
: ($pay_modo === 'points' ? (int) ($meta['points_price'] ?? 0) : (string) ($meta['price'] ?? '0.00'));
$price_minor = aksrt_asset_price_minor($price, $pay_modo);
$vip_level = is_array($priced) ? (int) ($priced['vip_level'] ?? 0) : 0;
$currency = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_currency_name() : __('积分', 'aksrt');
$cash_symbol = '¥';
if (class_exists('\AKSRT\Settings\Settings')) {
$paid = \AKSRT\Settings\Settings::get_paid_content_settings();
$cash_symbol = (string) ($paid['display']['currency_symbol'] ?? '¥');
}
$price_text = $pay_modo === 'points'
? (aksrt_format_price($price) . ' ' . $currency)
: ($cash_symbol . aksrt_format_price($price));
$pay_type = (string) ($meta['pay_type'] ?? AKSRT_PAY_TYPE_NO);
if ($pay_type === AKSRT_PAY_TYPE_NO) return '';
$type_labels = [
AKSRT_PAY_TYPE_READING => ['icon' => 'fa-lock', 'label' => __('付费阅读', 'aksrt'), 'desc' => __('付费后即可查看完整内容', 'aksrt')],
AKSRT_PAY_TYPE_GALLERY => ['icon' => 'fa-image', 'label' => __('付费图库', 'aksrt'), 'desc' => __('付费后即可查看全部图片', 'aksrt')],
AKSRT_PAY_TYPE_VIDEO => ['icon' => 'fa-play-circle', 'label' => __('付费视频', 'aksrt'), 'desc' => __('付费后即可观看完整视频', 'aksrt')],
];
$type_info = $type_labels[$pay_type] ?? $type_labels[AKSRT_PAY_TYPE_READING];
if ($is_fragment && $pay_type === AKSRT_PAY_TYPE_READING) {
$type_info['desc'] = __('付费后即可查看此片段内容', 'aksrt');
}
$login_url = function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url(get_permalink($post));
$is_logged_in = is_user_logged_in();
$original_price = $pay_modo === 'points'
? max(0, (int) ($meta['original_price'] ?? 0))
: (string) ($meta['original_price'] ?? '0.00');
$original_minor = aksrt_asset_price_minor($original_price, $pay_modo);
$has_original = $original_minor > 0 && $original_minor > $price_minor;
$pay_limit = (int) ($meta['pay_limit'] ?? 0);
$priced = aksrt_get_user_pay_price($post);
$modo = (string) ($priced['modo'] ?? '0');
$amount = $priced['amount'] ?? 0;
$amount_minor = aksrt_asset_price_minor($amount, $modo);
$price_label = aksrt_get_pay_price_label($post);
$price_text = (string) ($price_label['text'] ?? __('免费', 'aksrt'));
$pay_limit = (int) ($priced['pay_limit'] ?? ($meta['pay_limit'] ?? 0));
$vip_level = (int) ($priced['vip_level'] ?? 0);
$member_blocked = $pay_limit > 0 && $vip_level < $pay_limit;
$vip_url = function_exists('aksrt_get_user_center_tab_url')
? aksrt_get_user_center_tab_url('credits')
: (function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url() : home_url('/'));
$type_labels = [
AKSRT_PAY_TYPE_READING => __('付费阅读', 'aksrt'),
AKSRT_PAY_TYPE_DOWNLOAD => __('付费下载', 'aksrt'),
AKSRT_PAY_TYPE_GALLERY => __('付费图库', 'aksrt'),
AKSRT_PAY_TYPE_VIDEO => __('付费视频', 'aksrt'),
AKSRT_PAY_TYPE_VIP => __('VIP 专属', 'aksrt'),
];
$type_label = $type_labels[$pay_type] ?? __('付费内容', 'aksrt');
$order_types = [
AKSRT_PAY_TYPE_READING => 1,
AKSRT_PAY_TYPE_DOWNLOAD => 2,
AKSRT_PAY_TYPE_GALLERY => 5,
AKSRT_PAY_TYPE_VIDEO => 6,
AKSRT_PAY_TYPE_VIP => 4,
];
$order_type = (int) ($order_types[$pay_type] ?? 1);
$title = get_the_title($post);
$doc = trim((string) ($args['message'] ?? ''));
if ($doc === '') {
$doc = sprintf(__('此内容为%s,请付费后查看', 'aksrt'), $type_label);
}
$sales = max(0, (int) ($meta['virtual_sales'] ?? 0));
$sales += max(0, (int) get_post_meta($post->ID, \AKSRT\Core\DomainModel::RESOURCE_SALES_VOLUME_KEY, true));
$tag = $is_widget
? '<badge class="pay-tag abs-center">' . esc_html($type_label) . '</badge>'
: '<div class="pay-tag abs-center">' . esc_html($type_label) . '</div>';
$block_class = $is_widget ? ' btn-block' : '';
$button = '';
if (!is_user_logged_in()) {
if ($pay_limit <= 0 && $amount_minor > 0 && $modo === '0' && aksrt_allow_guest_content_pay($post)) {
$button = '<button type="button" class="but jb-red padding-lg cashier-link' . $block_class . '" data-aksrt-pay-content="' . esc_attr((string) $post->ID) . '"><i class="fa fa-shopping-cart" aria-hidden="true"></i> ' . esc_html__('立即购买', 'aksrt') . '</button>';
} else {
$button = '<a href="' . esc_url(wp_login_url(get_permalink($post))) . '" class="but jb-blue padding-lg' . $block_class . '"><i class="fa fa-sign-in" aria-hidden="true"></i> ' . esc_html__('登录购买', 'aksrt') . '</a>';
}
} elseif ($member_blocked) {
$vip_url = aksrt_get_user_center_tab_url('vip');
$button = '<a href="' . esc_url($vip_url) . '" class="but jb-vip' . max(1, min(2, $pay_limit)) . ' padding-lg' . $block_class . '"><i class="fa fa-certificate" aria-hidden="true"></i> ' . esc_html__('开通会员后可查看', 'aksrt') . '</a>';
} elseif ($amount_minor > 0) {
$button = '<button type="button" class="but ' . ($modo === 'points' ? 'jb-yellow' : 'jb-red') . ' padding-lg cashier-link' . $block_class . '" data-aksrt-pay-content="' . esc_attr((string) $post->ID) . '"><i class="fa fa-shopping-cart" aria-hidden="true"></i> ' . esc_html__('立即购买', 'aksrt') . '</button>';
} else {
$button = '<button type="button" class="but jb-blue padding-lg cashier-link' . $block_class . '" data-aksrt-pay-content="' . esc_attr((string) $post->ID) . '"><i class="fa fa-eye" aria-hidden="true"></i> ' . esc_html__('查看内容', 'aksrt') . '</button>';
}
$price_color = ($price_label['free'] ?? false) ? 'c-green' : ($modo === 'points' ? 'c-yellow' : 'c-red');
$price = '<div class="price-box"><div class="' . esc_attr($price_color) . '"><b class="em3x">' . esc_html($price_text) . '</b></div></div>';
$vip_items = [];
$base_minor = aksrt_asset_price_minor($priced['base'] ?? $amount, $modo);
foreach ([1, 2] as $level) {
$key = $modo === 'points' ? 'vip' . $level . '_points' : 'vip' . $level . '_price';
$value = $meta[$key] ?? 0;
$vip_minor = aksrt_asset_price_minor($value, $modo);
if ($vip_minor > 0 && ($base_minor <= 0 || $vip_minor < $base_minor)) {
$vip_items[] = '<span class="but vip-price"><span class="vip-price-text">' . esc_html(sprintf(__('VIP%d', 'aksrt'), $level)) . '</span><span class="em12 ml3">' . esc_html(aksrt_format_price($value)) . '</span></span>';
}
}
$vip = implode('', $vip_items);
if (count($vip_items) > 1) {
$vip = '<span class="vip-price-buts but-average inline">' . $vip . '</span>';
}
$attrs = aksrt_get_pay_attributes_html($post, 'pay-attr');
$count = $sales > 0 ? '<badge class="img-badge hot jb-blue px12">' . esc_html(sprintf(__('已售 %s', 'aksrt'), $sales)) . '</badge>' : '';
$service = aksrt_get_pay_service_html('muted-2-color');
$demo = aksrt_get_demo_link_html($post, 'but jb-yellow padding-lg');
$demo_row = $demo !== '' ? '<div class="mt10">' . $demo . '</div>' : '';
$discount = $modo === '0' ? aksrt_get_post_rebate_discount($post) : '0.00';
$discount_text = aksrt_asset_price_minor($discount, '0') > 0
? sprintf(__('推广优惠 %s', 'aksrt'), (string) ($priced['currency'] ?? '¥') . aksrt_format_price($discount))
: '';
$discount_banner = $discount_text !== '' ? '<div class="text-center padding-6 jb-yellow px12">' . esc_html($discount_text) . '</div>' : '';
ob_start();
?>
<div class="aksrt-paywall<?php echo $is_fragment ? ' aksrt-paywall--fragment' : ''; ?>" data-post-id="<?php echo esc_attr((string) $post->ID); ?>" data-pay-type="<?php echo esc_attr($pay_type); ?>" data-pay-modo="<?php echo esc_attr($pay_modo); ?>">
<div class="aksrt-paywall__card" role="group" aria-label="<?php esc_attr_e('付费内容购买', 'aksrt'); ?>">
<div class="aksrt-paywall__icon">
<i class="fa <?php echo esc_attr($type_info['icon']); ?>" aria-hidden="true"></i>
</div>
<div class="aksrt-paywall__body">
<h3 class="aksrt-paywall__title"><?php echo esc_html($type_info['label']); ?></h3>
<p class="aksrt-paywall__desc"><?php echo esc_html($type_info['desc']); ?></p>
<div class="aksrt-paywall__price">
<?php if ($member_blocked) : ?>
<span class="aksrt-paywall__price-member"><?php esc_html_e('会员专属', 'aksrt'); ?></span>
<?php elseif ($price > 0) : ?>
<span class="aksrt-paywall__price-amount"><?php echo esc_html($price_text); ?></span>
<?php if ($has_original) : ?>
<span class="aksrt-paywall__price-original"><?php echo esc_html(($pay_modo === 'points' ? aksrt_format_price($original_price) . ' ' . $currency : $cash_symbol . aksrt_format_price($original_price))); ?></span>
<?php endif; ?>
<?php else : ?>
<span class="aksrt-paywall__price-free"><?php esc_html_e('免费', 'aksrt'); ?></span>
<?php endif; ?>
</div>
</div>
<div class="aksrt-paywall__actions">
<?php if (!$is_logged_in) : ?>
<?php if ($pay_limit <= 0 && $price > 0 && $pay_modo !== 'points' && function_exists('aksrt_allow_guest_content_pay') && aksrt_allow_guest_content_pay($post)) : ?>
<button type="button" class="but <?php echo $pay_modo === 'points' ? 'jb-yellow' : 'jb-red'; ?> padding-lg cashier-link aksrt-paywall__btn" data-aksrt-pay-content="<?php echo esc_attr((string) $post->ID); ?>">
<i class="fa fas fa-shopping-cart" aria-hidden="true"></i> <?php printf(esc_html__('游客购买(%s)', 'aksrt'), $price_text); ?>
</button>
<a href="<?php echo esc_url($login_url); ?>" class="aksrt-paywall__login-link"><?php esc_html_e('已有账号?登录后购买', 'aksrt'); ?></a>
<?php else : ?>
<a href="<?php echo esc_url($login_url); ?>" class="but jb-red padding-lg aksrt-paywall__btn">
<i class="fa fas fa-sign-in-alt" aria-hidden="true"></i> <?php esc_html_e('登录后购买', 'aksrt'); ?>
</a>
<?php endif; ?>
<?php elseif ($member_blocked) : ?>
<a href="<?php echo esc_url($vip_url); ?>" class="but jb-vip padding-lg aksrt-paywall__btn">
<i class="fa fas fa-certificate" aria-hidden="true"></i> <?php esc_html_e('开通会员后可查看', 'aksrt'); ?>
</a>
<?php elseif ($price > 0) : ?>
<button type="button" class="but <?php echo $pay_modo === 'points' ? 'jb-yellow' : 'jb-red'; ?> padding-lg cashier-link aksrt-paywall__btn" data-aksrt-pay-content="<?php echo esc_attr((string) $post->ID); ?>">
<i class="fa fas fa-shopping-cart" aria-hidden="true"></i> <?php printf(esc_html__('立即购买(%s)', 'aksrt'), $price_text); ?>
</button>
<?php endif; ?>
<p class="aksrt-paywall__hint">
<i class="fa fas fa-shield-alt" aria-hidden="true"></i> <?php esc_html_e('购买后永久有效,支持重复查看', 'aksrt'); ?>
</p>
</div>
</div>
</div>
<?php
return ob_get_clean();
if ($is_widget && aksrt_has_paid_access($post)) {
$view_labels = [
AKSRT_PAY_TYPE_DOWNLOAD => '<i class="fa fa-download fa-fw" aria-hidden="true"></i>' . esc_html__('获取下载地址', 'aksrt'),
AKSRT_PAY_TYPE_GALLERY => '<i class="fa fa-file-image-o fa-fw" aria-hidden="true"></i>' . esc_html__('查看图片', 'aksrt'),
AKSRT_PAY_TYPE_VIDEO => '<i class="fa fa-play-circle fa-fw" aria-hidden="true"></i>' . esc_html__('查看视频', 'aksrt'),
];
$view_label = $view_labels[$pay_type] ?? '<i class="fa fa-dot-circle-o fa-fw" aria-hidden="true"></i>' . esc_html__('查看内容', 'aksrt');
return '<div class="zib-widget pay-box pay-widget paid-box order-type-' . $order_type . '" style="padding:0">' . $tag . '<div class="relative-h ' . esc_attr($theme) . '" style="background-size:120%"><div class="pay-widget__orb pay-widget__orb--right ' . esc_attr($theme) . '"></div><div class="pay-widget__orb pay-widget__orb--left ' . esc_attr($theme) . '"></div><div class="relative box-body"><div class="text-center mt10 box-body"><p><i class="fa fa-shopping-bag fa-3x" aria-hidden="true"></i></p><b class="em14">' . esc_html__('已购买', 'aksrt') . '</b></div></div></div><div class="box-body"><div class="px12 muted-2-color">' . $service . '</div><div class="mt10"><a href="#posts-pay" class="but padding-lg btn-block ' . esc_attr($theme) . '">' . $view_label . '</a></div>' . $demo_row . $attrs . '</div>' . $count . '</div>';
}
if ($is_widget) {
return '<div class="zib-widget pay-box pay-widget order-type-' . $order_type . '" style="padding:0">' . $tag . '<div class="relative-h ' . esc_attr($theme) . '" style="background-size:120%"><div class="pay-widget__orb pay-widget__orb--right ' . esc_attr($theme) . '"></div><div class="pay-widget__orb pay-widget__orb--left ' . esc_attr($theme) . '"></div><div class="relative box-body"><div class="text-center mt10">' . $price . '</div></div><div class="relative">' . $vip . '</div></div>' . $discount_banner . '<div class="box-body"><div class="px12 muted-2-color">' . $service . '</div><div class="mt10">' . $button . '</div>' . $demo_row . $attrs . '</div>' . $count . '</div>';
}
$thumb = get_the_post_thumbnail($post, 'medium', ['class' => 'fit-cover', 'alt' => '']);
if ($thumb === '') {
$thumb = '<div class="pay-thumb-placeholder"><i class="fa fa-lock" aria-hidden="true"></i></div>';
}
$graphic_actions = '';
if ($demo !== '' || $discount_text !== '') {
$graphic_actions = '<div class="abs-center text-center left-bottom">';
$graphic_actions .= $demo !== '' ? '<div>' . $demo . '</div>' : '';
$graphic_actions .= $discount_text !== '' ? '<div class="padding-6 jb-red px12 hidden-xs">' . esc_html($discount_text) . '</div>' : '';
$graphic_actions .= '</div>';
}
$discount_mobile = $discount_text !== '' ? '<div class="visible-xs-block badg c-red px12 mb6">' . esc_html($discount_text) . '</div>' : '';
if ($pay_type === AKSRT_PAY_TYPE_GALLERY) {
$gallery_count = count((array) ($meta['gallery'] ?? []));
$graphic = '<div class="flex0 relative mr20 hide-sm pay-thumb"><div class="graphic"><div class="blur-10 absolute">' . $thumb . '</div><div class="absolute graphic-mask" style="opacity:.3"></div><div class="abs-center text-center">' . esc_html(sprintf(__('共%s张图片', 'aksrt'), $gallery_count)) . '<br>' . esc_html__('请付费后查看', 'aksrt') . '</div>' . $graphic_actions . '</div></div>';
} elseif ($pay_type === AKSRT_PAY_TYPE_VIDEO) {
$graphic = '<div class="flex0 relative mr20 hide-sm pay-thumb"><div class="graphic">' . $thumb . '<div class="absolute graphic-mask" style="opacity:.2"></div><div class="abs-center text-center"><i class="fa fa-play-circle-o fa-4x opacity8" aria-hidden="true"></i></div>' . $graphic_actions . '</div></div>';
} else {
$graphic = '<div class="flex0 relative mr20 hide-sm pay-thumb"><div class="graphic">' . $thumb . $graphic_actions . '</div></div>';
}
$demo_mobile = $demo !== '' ? '<div class="mt10 visible-xs-block">' . $demo . '</div>' : '';
return '<div class="zib-widget pay-box order-type-' . $order_type . '" id="posts-pay"><div class="flex pay-flexbox">' . $graphic . '<div class="flex-auto-h flex xx jsb"><dt class="text-ellipsis pay-title">' . esc_html($title) . '</dt><div class="mt6 em09 muted-2-color">' . wp_kses_post($doc) . '</div><div>' . $price . '</div>' . $discount_mobile . ($vip !== '' ? '<div>' . $vip . '</div>' : '') . '<div class="text-right mt10">' . $button . '</div></div></div><div class="px12 muted-2-color mt10 text-right">' . $service . '</div>' . $demo_mobile . $attrs . $tag . $count . '</div>';
}
}
@@ -1305,51 +1312,23 @@ if (!function_exists('aksrt_render_paid_gallery')) {
$images = $meta['gallery'] ?? [];
if (empty($images)) return '';
$has_access = aksrt_has_paid_access($post);
$base_uri = get_template_directory_uri();
if (!aksrt_has_paid_access($post)) return '';
ob_start();
?>
<div class="aksrt-paid-gallery" data-post-id="<?php echo esc_attr((string) $post->ID); ?>">
<?php if ($has_access) : ?>
<!-- 已付费:Swiper 轮播 -->
<div class="new-swiper aksrt-paid-gallery__swiper" data-loop="true">
<div class="swiper-wrapper">
<?php foreach ($images as $img_url) : ?>
<div class="swiper-slide">
<img<?php echo aksrt_get_lazy_attr('lazy_other', (string) $img_url, '', aksrt_get_lazy_thumb('lg')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="">
</div>
<?php endforeach; ?>
</div>
<div class="swiper-pagination"></div>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<div class="new-swiper aksrt-paid-gallery__swiper" data-loop="true">
<div class="swiper-wrapper">
<?php foreach ($images as $img_url) : ?>
<div class="swiper-slide">
<img<?php echo aksrt_get_lazy_attr('lazy_other', (string) $img_url, '', aksrt_get_lazy_thumb('lg')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="">
</div>
<?php endforeach; ?>
</div>
<?php else : ?>
<!-- 未付费:仅首图模糊预览,不输出完整图库 URL 列表 -->
<div class="aksrt-paid-gallery__locked">
<div class="aksrt-paid-gallery__preview">
<img<?php echo aksrt_get_lazy_attr('lazy_other', (string) $images[0], 'aksrt-gallery-locked', aksrt_get_lazy_thumb('lg')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="">
</div>
<div class="aksrt-paid-gallery__overlay">
<i class="fa fas fa-image" aria-hidden="true"></i>
<p><?php
printf(
/* translators: %d: image count */
esc_html__('共 %d 张图片,付费后可查看', 'aksrt'),
count($images)
);
?></p>
<?php $price_label = function_exists('aksrt_get_pay_price_label') ? aksrt_get_pay_price_label($post) : ['text' => '']; ?>
<?php if (!empty($price_label['text'])) : ?>
<span class="aksrt-paid-gallery__price"><?php echo esc_html((string) $price_label['text']); ?></span>
<?php endif; ?>
<button type="button" class="but jb-red padding-lg cashier-link" data-aksrt-pay-content="<?php echo esc_attr((string) $post->ID); ?>">
<i class="fa fas fa-shopping-cart" aria-hidden="true"></i> <?php esc_html_e('立即购买', 'aksrt'); ?>
</button>
</div>
</div>
<?php endif; ?>
<div class="swiper-pagination"></div>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
</div>
<?php
@@ -1369,42 +1348,22 @@ if (!function_exists('aksrt_render_paid_video')) {
$video_url = $meta['video_url'] ?? '';
if (empty($video_url)) return '';
$has_access = aksrt_has_paid_access($post);
if (!aksrt_has_paid_access($post)) return '';
ob_start();
?>
<div class="aksrt-paid-video" data-post-id="<?php echo esc_attr((string) $post->ID); ?>">
<?php if ($has_access) : ?>
<!-- 已付费:视频播放器 -->
<div class="aksrt-paid-video__player">
<?php if (preg_match('/\.(mp4|webm|ogg)$/i', $video_url)) : ?>
<video controls preload="metadata"<?php echo aksrt_is_lazy('lazy_posts_content') ? ' class="lazyload" src="" data-src="' . esc_url($video_url) . '"' : ' src="' . esc_url($video_url) . '"'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> style="width:100%;border-radius:var(--radius-lg);">
<?php esc_html_e('您的浏览器不支持视频播放。', 'aksrt'); ?>
</video>
<?php else : ?>
<div class="aksrt-paid-video__embed">
<iframe<?php echo aksrt_is_lazy('lazy_posts_content') ? ' class="lazyload" src="" data-src="' . esc_url($video_url) . '"' : ' src="' . esc_url($video_url) . '"'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> frameborder="0" allowfullscreen></iframe>
</div>
<?php endif; ?>
</div>
<?php else : ?>
<!-- 未付费:锁定预览(不输出真实视频地址) -->
<div class="aksrt-paid-video__locked">
<div class="aksrt-paid-video__placeholder">
<i class="fa fas fa-play-circle" aria-hidden="true"></i>
<p><?php esc_html_e('付费后即可观看完整视频', 'aksrt'); ?></p>
<?php $price_label = function_exists('aksrt_get_pay_price_label') ? aksrt_get_pay_price_label($post) : ['text' => '']; ?>
<?php if (!empty($price_label['text'])) : ?>
<span class="aksrt-paid-video__price"><?php echo esc_html((string) $price_label['text']); ?></span>
<?php endif; ?>
<p style="margin-top:14px;">
<button type="button" class="but jb-red padding-lg cashier-link" data-aksrt-pay-content="<?php echo esc_attr((string) $post->ID); ?>">
<i class="fa fas fa-shopping-cart" aria-hidden="true"></i> <?php esc_html_e('立即购买', 'aksrt'); ?>
</button>
</p>
</div>
</div>
<?php endif; ?>
<div class="aksrt-paid-video__player">
<?php if (preg_match('/\.(mp4|webm|ogg)$/i', $video_url)) : ?>
<video controls preload="metadata"<?php echo aksrt_is_lazy('lazy_posts_content') ? ' class="lazyload" src="" data-src="' . esc_url($video_url) . '"' : ' src="' . esc_url($video_url) . '"'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> style="width:100%;border-radius:var(--radius-lg);">
<?php esc_html_e('您的浏览器不支持视频播放。', 'aksrt'); ?>
</video>
<?php else : ?>
<div class="aksrt-paid-video__embed">
<iframe<?php echo aksrt_is_lazy('lazy_posts_content') ? ' class="lazyload" src="" data-src="' . esc_url($video_url) . '"' : ' src="' . esc_url($video_url) . '"'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> frameborder="0" allowfullscreen></iframe>
</div>
<?php endif; ?>
</div>
</div>
<?php
return ob_get_clean();
@@ -1439,59 +1398,10 @@ if (!function_exists('aksrt_paid_content_filter')) {
return $content;
}
// free_preview teaser + paywall. Never render full gallery/video media when unpaid.
// Only the configured teaser remains in the article body. The single
// template owns the one canonical purchase card for gallery/video.
$preview = trim((string) ($meta['free_preview'] ?? ''));
$out = '';
if ($preview !== '') {
$out .= '<div class="aksrt-paywall-preview">' . wp_kses_post($preview) . '</div>';
}
$out .= aksrt_get_paywall_html($post);
if ($pay_type === AKSRT_PAY_TYPE_GALLERY) {
$out .= aksrt_render_paid_gallery($post);
} elseif ($pay_type === AKSRT_PAY_TYPE_VIDEO) {
$out .= aksrt_render_paid_video($post);
}
return $out;
}
}
// 已付费的内容增强
if (!function_exists('aksrt_paid_content_enhance')) {
function aksrt_paid_content_enhance(string $content): string {
if (is_admin() || !is_singular() || !in_the_loop() || !is_main_query()) {
return $content;
}
global $post;
if (!($post instanceof WP_Post)) {
return $content;
}
$meta = aksrt_get_pay_meta($post);
$pay_type = (string) ($meta['pay_type'] ?? AKSRT_PAY_TYPE_NO);
if ($pay_type === AKSRT_PAY_TYPE_NO) {
return $content;
}
if (!aksrt_has_paid_access($post)) {
return $content;
}
if ($pay_type === AKSRT_PAY_TYPE_GALLERY && strpos($content, 'aksrt-paid-gallery') === false) {
$gallery_html = aksrt_render_paid_gallery($post);
if ($gallery_html) {
$content .= $gallery_html;
}
}
if ($pay_type === AKSRT_PAY_TYPE_VIDEO && strpos($content, 'aksrt-paid-video') === false) {
$video_html = aksrt_render_paid_video($post);
if ($video_html) {
$content .= $video_html;
}
}
return $content;
return $preview !== '' ? '<div class="aksrt-paywall-preview">' . wp_kses_post($preview) . '</div>' : '';
}
}
@@ -1511,20 +1421,10 @@ add_action('wp_head', function (): void {
.aksrt-paid-gallery{margin:24px 0}
.aksrt-paid-gallery__swiper{border-radius:var(--radius-lg);overflow:hidden}
.aksrt-paid-gallery__swiper img{width:100%;height:auto;display:block}
.aksrt-paid-gallery__locked{position:relative;border-radius:var(--radius-lg);overflow:hidden}
.aksrt-paid-gallery__preview img{width:100%;display:block}
.aksrt-paid-gallery__overlay{position:absolute;inset:0;background:rgba(0,0,0,.5);display:flex;flex-direction:column;align-items:center;justify-content:center;color:#fff;gap:12px}
.aksrt-paid-gallery__overlay i{font-size:48px;opacity:.8}
.aksrt-paid-gallery__overlay p{font-size:16px;margin:0}
.aksrt-paid-gallery__price{font-size:20px;font-weight:700;background:rgba(255,255,255,.2);padding:6px 16px;border-radius:20px}
.aksrt-paid-video{margin:24px 0}
.aksrt-paid-video__embed{position:relative;padding-bottom:56.25%;height:0;overflow:hidden;border-radius:var(--radius-lg)}
.aksrt-paid-video__embed iframe{position:absolute;top:0;left:0;width:100%;height:100%;border:none}
.aksrt-paid-video__locked{background:var(--surface-2);border-radius:var(--radius-lg);padding:60px 20px;text-align:center}
.aksrt-paid-video__placeholder i{font-size:64px;color:var(--color-ink-4);margin-bottom:16px}
.aksrt-paid-video__placeholder p{font-size:16px;color:var(--color-ink-3);margin:0 0 12px}
.aksrt-paid-video__price{font-size:20px;font-weight:700;color:var(--color-error)}
</style>
<?php
});