feat(frontend): single pay-box positions + Zibll cover episodes/slides

Wire pay_box_position to box_top/top/bottom/box_bottom, render download or
paywall modules at those slots, and resolve featured_slide/attachment IDs
plus video episode chrome for single covers.
This commit is contained in:
2026-07-11 22:08:50 +08:00
parent 9c443c808b
commit 619d2bc170
7 changed files with 221 additions and 75 deletions
+149 -61
View File
@@ -74,19 +74,20 @@ if (!function_exists('aksrt_single_build_context')) :
$paid_settings = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_paid_content_settings() : [];
$paid_display = is_array($paid_settings['display'] ?? null) ? $paid_settings['display'] : [];
$paid_box_position = (string) ($paid_display['box_position'] ?? 'top');
if ($paid_box_position === 'box_top') {
$paid_box_position = 'top';
} elseif ($paid_box_position === 'box_bottom') {
$paid_box_position = 'bottom';
}
if (!in_array($paid_box_position, ['top', 'bottom'], true)) {
$paid_box_position = sanitize_key((string) ($paid_display['box_position'] ?? 'top'));
// Zibll positions: box_top | top | bottom | box_bottom (do not collapse).
if (!in_array($paid_box_position, ['box_top', 'top', 'bottom', 'box_bottom'], true)) {
$paid_box_position = 'top';
}
$show_cover = !empty($settings['show_cover']) && (string) ($settings['cover_url'] ?? '') !== '';
$show_toc = !empty($settings['toc_enabled']);
$has_download = function_exists('aksrt_is_downloadable_content') && aksrt_is_downloadable_content($post_id);
$pay_meta = function_exists('aksrt_get_pay_meta') ? aksrt_get_pay_meta($post_id) : ['pay_type' => 'no'];
$pay_type = (string) ($pay_meta['pay_type'] ?? 'no');
$is_paid_post = function_exists('aksrt_is_paid_post') && aksrt_is_paid_post($post_id);
// Pay module: download box OR non-download paid types (reading/gallery/video/vip).
$show_pay_box = $has_download || ($is_paid_post && $pay_type !== 'no' && $pay_type !== 'download');
$breadcrumbs_html = '';
if (!empty($settings['breadcrumbs']) && function_exists('aksrt_breadcrumbs')) {
@@ -124,7 +125,8 @@ if (!function_exists('aksrt_single_build_context')) :
'img_scale' => (int) ($settings['article_image_cover_scale'] ?? 35),
'video_scale' => (int) ($settings['article_video_cover_scale'] ?? 56),
'slide_images' => array_values(array_filter((array) ($settings['slide_images'] ?? []))),
'episode_count' => max(0, (int) get_post_meta($post_id, '_aksrt_featured_video_episode', true)),
'episode_count' => max(0, (int) ($settings['episode_count'] ?? 0)),
'video_poster' => (string) ($settings['video_poster'] ?? ''),
'meta_items' => $meta_items,
'views' => $views,
'comment_count' => $comment_count,
@@ -137,10 +139,13 @@ if (!function_exists('aksrt_single_build_context')) :
'after_content' => (string) ($settings['after_content'] ?? ''),
'content_maxheight' => !empty($settings['maxheight_enabled']) ? max(0, (int) ($settings['maxheight'] ?? 0)) : 0,
'has_download' => $has_download,
'show_pay_box' => $show_pay_box,
'pay_type' => $pay_type,
'is_paid_post' => $is_paid_post,
'paid_box_position' => $paid_box_position,
'breadcrumbs_html' => $breadcrumbs_html,
'status_badge' => $status_badge,
'show_aside' => $aside_widgets || $show_toc || $has_download,
'show_aside' => $aside_widgets || $show_toc || $has_download || $show_pay_box,
'toc_title' => __('文章目录', 'aksrt'),
];
}
@@ -177,7 +182,7 @@ endif;
if (!function_exists('aksrt_single_render_cover')) :
/**
* Cover / slide / video header.
* Cover / slide / video header (Zibll single-head-cover).
*
* @param array<string,mixed> $ctx Single context.
*/
@@ -190,29 +195,44 @@ if (!function_exists('aksrt_single_render_cover')) :
$badge = (string) $ctx['status_badge'];
$crumbs = (string) $ctx['breadcrumbs_html'];
$meta_items = is_array($ctx['meta_items'] ?? null) ? $ctx['meta_items'] : [];
$img_scale = (int) $ctx['img_scale'];
$video_scale = (int) $ctx['video_scale'];
$img_scale = max(10, min(100, (int) $ctx['img_scale']));
$video_scale = max(20, min(100, (int) $ctx['video_scale']));
$episode = (int) $ctx['episode_count'];
$slides = is_array($ctx['slide_images'] ?? null) ? $ctx['slide_images'] : [];
$poster = (string) ($ctx['video_poster'] ?? '');
$title = get_the_title();
if ($type === 'video') :
?>
<div class="single-head-cover single-cover single-cover--video graphic imgbox-container" style="padding-bottom:<?php echo esc_attr((string) $video_scale); ?>%;">
<video src="<?php echo esc_url($ctx['cover_url']); ?>" autoplay muted loop playsinline class="single-cover__video"></video>
<div class="single-cover__overlay"></div>
<div class="single-cover__content">
<?php if ($crumbs !== '') : ?>
<div class="post-breadcrumbs"><?php echo $crumbs; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
<?php endif; ?>
<h1 class="article-title title-h-left"><?php the_title(); ?></h1>
<?php echo $badge; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<div class="cover-meta abs-right">
<?php foreach ($meta_items as $item) : ?>
<item class="meta-view"><?php echo esc_html((string) ($item['text'] ?? '')); ?></item>
<?php endforeach; ?>
<div class="single-head-cover">
<div class="single-video single-cover single-cover--video graphic imgbox-container" style="padding-bottom:<?php echo esc_attr((string) $video_scale); ?>%;">
<video src="<?php echo esc_url($ctx['cover_url']); ?>"<?php echo $poster !== '' ? ' poster="' . esc_url($poster) . '"' : ''; ?> autoplay muted loop playsinline controls class="single-cover__video fit-cover"></video>
<div class="single-cover__overlay"></div>
</div>
<div class="single-video-footer dplayer-featured">
<div class="flex jsb at">
<?php if ($crumbs !== '') : ?>
<div class="post-breadcrumbs"><?php echo $crumbs; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
<?php endif; ?>
<div class="cover-meta single-metabox">
<?php foreach ($meta_items as $item) : ?>
<item class="meta-view"><?php echo esc_html((string) ($item['text'] ?? '')); ?></item>
<?php endforeach; ?>
</div>
</div>
<h1 class="article-title">
<?php if ($episode > 1) : ?>
<span class="badg badg-sm b-theme mr6"><i class="fa fa-play-circle mr3" aria-hidden="true"></i><?php printf(esc_html__('共%d集', 'aksrt'), $episode); ?></span>
<?php else : ?>
<i class="fa fa-play-circle-o mr6 opacity8" aria-hidden="true"></i>
<?php endif; ?>
<?php echo esc_html($title); ?>
</h1>
<?php echo $badge; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php if ($episode > 0) : ?>
<div class="featured-video-episode single-video"><?php printf(esc_html__('第 %d 集', 'aksrt'), $episode); ?></div>
<div class="featured-video-episode mt10">
<span class="switch-video text-ellipsis active"><span class="mr6 badg badg-sm">1</span><i class="episode-active-icon"></i><?php printf(esc_html__('第%d集', 'aksrt'), 1); ?></span>
</div>
<?php endif; ?>
</div>
</div>
@@ -222,27 +242,29 @@ if (!function_exists('aksrt_single_render_cover')) :
if ($type === 'slide' && !empty($slides)) :
?>
<div class="single-head-cover single-cover single-cover--slide graphic imgbox-container" style="padding-bottom:<?php echo esc_attr((string) $img_scale); ?>%;">
<div class="single-cover__slides">
<?php foreach ($slides as $idx => $slide_url) : ?>
<div class="single-cover__slide<?php echo $idx === 0 ? ' is-active' : ''; ?>">
<img src="<?php echo esc_url($slide_url); ?>" alt="<?php echo esc_attr(get_the_title()); ?>" class="fit-cover" loading="<?php echo $idx === 0 ? 'eager' : 'lazy'; ?>">
</div>
<?php endforeach; ?>
</div>
<div class="single-cover__overlay"></div>
<div class="single-cover__content">
<?php if ($crumbs !== '') : ?>
<div class="post-breadcrumbs"><?php echo $crumbs; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
<?php endif; ?>
<h1 class="article-title title-h-left"><?php the_title(); ?></h1>
<?php echo $badge; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<div class="single-head-cover">
<div class="single-cover single-cover--slide graphic imgbox-container mb20 single-cover-slide" style="padding-bottom:<?php echo esc_attr((string) $img_scale); ?>%;">
<div class="single-cover__slides">
<?php foreach ($slides as $idx => $slide_url) : ?>
<div class="single-cover__slide<?php echo $idx === 0 ? ' is-active' : ''; ?>">
<img src="<?php echo esc_url($slide_url); ?>" alt="<?php echo esc_attr($title); ?>" class="fit-cover" loading="<?php echo $idx === 0 ? 'eager' : 'lazy'; ?>">
</div>
<?php endforeach; ?>
</div>
<div class="single-cover__overlay"></div>
<div class="abs-center left-bottom single-cover-con single-cover__content">
<?php if ($crumbs !== '') : ?>
<div class="post-breadcrumbs"><?php echo $crumbs; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
<?php endif; ?>
<h1 class="article-title title-h-left"><?php echo esc_html($title); ?></h1>
<?php echo $badge; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</div>
<div class="cover-meta abs-right">
<?php foreach ($meta_items as $item) : ?>
<item class="meta-view"><?php echo esc_html((string) ($item['text'] ?? '')); ?></item>
<?php endforeach; ?>
</div>
<div class="single-cover__dots single-cover-slide" aria-hidden="true">
<div class="single-cover__dots" aria-hidden="true">
<?php foreach ($slides as $idx => $_slide) : ?>
<span class="single-cover__dot<?php echo $idx === 0 ? ' is-active' : ''; ?>"></span>
<?php endforeach; ?>
@@ -253,15 +275,17 @@ if (!function_exists('aksrt_single_render_cover')) :
return;
endif;
?>
<div class="single-head-cover single-cover graphic imgbox-container" style="padding-bottom:<?php echo esc_attr((string) $img_scale); ?>%;">
<img src="<?php echo esc_url($ctx['cover_url']); ?>" alt="<?php echo esc_attr(get_the_title()); ?>" class="fit-cover" loading="eager">
<div class="single-cover__overlay"></div>
<div class="single-cover__content">
<?php if ($crumbs !== '') : ?>
<div class="post-breadcrumbs"><?php echo $crumbs; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
<?php endif; ?>
<h1 class="article-title title-h-left"><?php the_title(); ?></h1>
<?php echo $badge; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<div class="single-head-cover">
<div class="graphic mb20 single-cover imgbox-container" style="padding-bottom:<?php echo esc_attr((string) $img_scale); ?>%;">
<img src="<?php echo esc_url($ctx['cover_url']); ?>" alt="<?php echo esc_attr($title); ?>" class="fit-cover" loading="eager">
<div class="single-cover__overlay"></div>
<div class="abs-center left-bottom single-cover-con single-cover__content">
<?php if ($crumbs !== '') : ?>
<div class="post-breadcrumbs"><?php echo $crumbs; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
<?php endif; ?>
<h1 class="article-title title-h-left"><?php echo esc_html($title); ?></h1>
<?php echo $badge; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</div>
<div class="cover-meta abs-right">
<?php foreach ($meta_items as $item) : ?>
<item class="meta-view"><?php echo esc_html((string) ($item['text'] ?? '')); ?></item>
@@ -689,6 +713,68 @@ if (!function_exists('aksrt_single_render_related')) :
}
endif;
if (!function_exists('aksrt_single_render_pay_box')) :
/**
* Unified single pay module (Zibll zibpay_posts_pay_content equivalent).
*
* @param array<string,mixed> $ctx Single context.
*/
function aksrt_single_render_pay_box(array $ctx = []): void {
if ($ctx === []) {
$ctx = function_exists('aksrt_single_build_context') ? aksrt_single_build_context() : [];
}
if (empty($ctx['show_pay_box'])) {
return;
}
$post_id = (int) ($ctx['post_id'] ?? get_the_ID());
$post = get_post($post_id);
if (!($post instanceof WP_Post)) {
return;
}
$pay_type = (string) ($ctx['pay_type'] ?? 'no');
if (!empty($ctx['has_download']) || $pay_type === 'download') {
echo '<div class="aksrt-single-pay-box aksrt-single-pay-box--download" id="posts-pay">';
get_template_part('templates/parts/resource-download-box');
echo '</div>';
return;
}
if (!function_exists('aksrt_get_pay_meta')) {
return;
}
$has_access = function_exists('aksrt_has_paid_access') ? aksrt_has_paid_access($post) : false;
echo '<div class="aksrt-single-pay-box aksrt-single-pay-box--' . esc_attr($pay_type) . '" id="posts-pay">';
if ($has_access) {
if ($pay_type === 'gallery' && function_exists('aksrt_render_paid_gallery')) {
echo aksrt_render_paid_gallery($post); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
} elseif ($pay_type === 'video' && function_exists('aksrt_render_paid_video')) {
echo aksrt_render_paid_video($post); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
} else {
echo '<div class="zib-widget pay-box paid-box"><div class="box-body"><span class="badg c-green hollow badg-sm mr6">' . esc_html__('已解锁', 'aksrt') . '</span><b>' . esc_html(get_the_title($post)) . '</b></div></div>';
}
} elseif (function_exists('aksrt_get_paywall_html')) {
echo aksrt_get_paywall_html($post); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
echo '</div>';
}
endif;
if (!function_exists('aksrt_single_pay_box_matches')) :
/**
* @param array<string,mixed> $ctx
*/
function aksrt_single_pay_box_matches(array $ctx, string $slot): bool {
if (empty($ctx['show_pay_box'])) {
return false;
}
return (string) ($ctx['paid_box_position'] ?? 'top') === $slot;
}
endif;
if (!function_exists('aksrt_single_render_article')) :
/**
* Main article box.
@@ -708,11 +794,9 @@ if (!function_exists('aksrt_single_render_article')) :
<?php do_action('aksrt_single_content_before', get_post()); ?>
<?php if (!empty($ctx['has_download']) && $ctx['paid_box_position'] === 'top') : ?>
<div class="aksrt-single-download-box aksrt-single-download-box--before">
<?php get_template_part('templates/parts/resource-download-box'); ?>
</div>
<?php endif; ?>
<?php if (function_exists('aksrt_single_pay_box_matches') && aksrt_single_pay_box_matches($ctx, 'top')) : ?>
<?php aksrt_single_render_pay_box($ctx); ?>
<?php endif; ?>
<?php if ($ctx['front_content'] !== '') : ?>
<div class="post_front_content theme-box box-body"><?php echo wp_kses_post((string) $ctx['front_content']); ?></div>
@@ -738,11 +822,9 @@ if (!function_exists('aksrt_single_render_article')) :
<div class="post_after_content theme-box box-body"><?php echo wp_kses_post((string) $ctx['after_content']); ?></div>
<?php endif; ?>
<?php if (!empty($ctx['has_download']) && $ctx['paid_box_position'] === 'bottom') : ?>
<div class="aksrt-single-download-box aksrt-single-download-box--after">
<?php get_template_part('templates/parts/resource-download-box'); ?>
</div>
<?php endif; ?>
<?php if (function_exists('aksrt_single_pay_box_matches') && aksrt_single_pay_box_matches($ctx, 'bottom')) : ?>
<?php aksrt_single_render_pay_box($ctx); ?>
<?php endif; ?>
<?php aksrt_single_render_actions($ctx); ?>
<?php aksrt_single_render_content_footer($ctx); ?>
@@ -839,9 +921,15 @@ if (!function_exists('aksrt_single')) :
}
do_action('aksrt_single_before', get_post());
if (function_exists('aksrt_single_pay_box_matches') && aksrt_single_pay_box_matches($ctx, 'box_top')) {
aksrt_single_render_pay_box($ctx);
}
aksrt_single_render_article($ctx);
do_action('aksrt_single_article_after', get_post());
aksrt_single_render_after_box($ctx);
if (function_exists('aksrt_single_pay_box_matches') && aksrt_single_pay_box_matches($ctx, 'box_bottom')) {
aksrt_single_render_pay_box($ctx);
}
do_action('aksrt_single_after', get_post());
}
endif;