diff --git a/inc/helpers/aksrt-pay.php b/inc/helpers/aksrt-pay.php index 4f5b73d9..c16ace6e 100644 --- a/inc/helpers/aksrt-pay.php +++ b/inc/helpers/aksrt-pay.php @@ -1113,6 +1113,9 @@ add_action('wp_head', function (): void { .aksrt-paywall__btn{display:inline-flex;align-items:center;gap:8px} .aksrt-paywall__hint{font-size:12px;color:var(--color-ink-4,#8A8F98);margin:16px 0 0} .aksrt-gallery-locked{filter:blur(8px);pointer-events:none;user-select:none} + .aksrt-paywall-preview{margin:0 0 16px;padding:14px 16px;border-left:3px solid var(--color-primary,#f04494);background:var(--surface-2,#f8fafc);border-radius:0 10px 10px 0;color:var(--color-ink-2,#374151);line-height:1.7} + .aksrt-paywall-preview p:last-child{margin-bottom:0} + .aksrt-paid-gallery__overlay .but,.aksrt-paid-video__placeholder .but{margin-top:10px} - + @@ -1221,13 +1230,20 @@ if (!function_exists('aksrt_render_paid_video')) { - +

- - + '']; ?> + + + +

+ +

@@ -1244,47 +1260,73 @@ if (!function_exists('aksrt_render_paid_video')) { // 这些函数供 core-hooks.php 中的 the_content 过滤器调用 if (!function_exists('aksrt_paid_content_filter')) { function aksrt_paid_content_filter(string $content): string { - if (is_admin() || !is_singular()) return $content; + if (is_admin() || !is_singular() || !in_the_loop() || !is_main_query()) { + return $content; + } global $post; - if (!($post instanceof WP_Post)) return $content; - if (aksrt_can_access_content($post)) return $content; + if (!($post instanceof WP_Post)) { + return $content; + } + if (aksrt_can_access_content($post)) { + return $content; + } - // 图库类型:在内容末尾追加图库轮播 $meta = aksrt_get_pay_meta($post); - if ($meta['pay_type'] === AKSRT_PAY_TYPE_GALLERY) { - return aksrt_get_paywall_html($post) . aksrt_render_paid_gallery($post); + $pay_type = (string) ($meta['pay_type'] ?? AKSRT_PAY_TYPE_NO); + if (!in_array($pay_type, [AKSRT_PAY_TYPE_READING, AKSRT_PAY_TYPE_GALLERY, AKSRT_PAY_TYPE_VIDEO], true)) { + return $content; } - // 视频类型:在内容末尾追加视频播放器 - if ($meta['pay_type'] === AKSRT_PAY_TYPE_VIDEO) { - return aksrt_get_paywall_html($post) . aksrt_render_paid_video($post); + // free_preview teaser + paywall. Never render full gallery/video media when unpaid. + $preview = trim((string) ($meta['free_preview'] ?? '')); + $out = ''; + if ($preview !== '') { + $out .= '
' . wp_kses_post($preview) . '
'; + } + $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 aksrt_get_paywall_html($post); + return $out; } } // 已付费的内容增强 if (!function_exists('aksrt_paid_content_enhance')) { function aksrt_paid_content_enhance(string $content): string { - if (is_admin() || !is_singular()) return $content; + 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); - if ($meta['pay_type'] === AKSRT_PAY_TYPE_NO) return $content; - if (!aksrt_has_paid_access($post)) return $content; - - // 已付费的图库:追加 Swiper 轮播 - if ($meta['pay_type'] === AKSRT_PAY_TYPE_GALLERY) { - $gallery_html = aksrt_render_paid_gallery($post); - if ($gallery_html) $content .= $gallery_html; + if (!($post instanceof WP_Post)) { + return $content; } - // 已付费的视频:追加播放器 - if ($meta['pay_type'] === AKSRT_PAY_TYPE_VIDEO) { + $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; + if ($video_html) { + $content .= $video_html; + } } return $content;