*/ function aksrt_single_build_context($post_id = null): array { $post_id = $post_id ? (int) $post_id : (int) get_the_ID(); $settings = function_exists('aksrt_resolve_single_post_display_settings') ? aksrt_resolve_single_post_display_settings($post_id) : []; $views = function_exists('aksrt_get_post_views') ? (int) aksrt_get_post_views($post_id) : 0; $comment_count = (int) get_comments_number($post_id); $like_count = function_exists('aksrt_get_post_likes') ? (int) aksrt_get_post_likes($post_id) : 0; $favorite_count = function_exists('aksrt_get_post_favorites') ? (int) aksrt_get_post_favorites($post_id) : 0; $word_count = function_exists('aksrt_post_word_count') && !empty($settings['word_count_enabled']) ? aksrt_post_word_count($post_id) : 0; $reading_minutes = function_exists('aksrt_reading_minutes') && !empty($settings['reading_time_enabled']) ? aksrt_reading_minutes($post_id) : 0; // Zibll primary meta = comment/views/likes via meta_box_html. $meta_items = []; $meta_box_html = function_exists('aksrt_get_single_meta_box') ? aksrt_get_single_meta_box('abs-right', 'down', $post_id) : ''; $meta_items_secondary = []; if ($word_count > 0) { $meta_items_secondary[] = [ 'icon' => 'far fa-file-word', 'text' => sprintf(__('约 %s 字', 'aksrt'), number_format_i18n($word_count)), ]; } if ($reading_minutes > 0) { $meta_items_secondary[] = [ 'icon' => 'far fa-hourglass', 'text' => sprintf(_n('约 %d 分钟', '约 %d 分钟', $reading_minutes, 'aksrt'), $reading_minutes), ]; } $copyright = trim((string) ($settings['copyright_text'] ?? '')); if ($copyright === '') { $copyright = sprintf( __('本文由 %s 原创发布,转载请注明出处。', 'aksrt'), get_the_author_meta('display_name', (int) get_post_field('post_author', $post_id)) ); } $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 = 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')) { ob_start(); aksrt_breadcrumbs( (string) ($settings['breadcrumbs_home'] ?? ($settings['breadcrumbs_home_text'] ?? '')), ['single_text' => !isset($settings['breadcrumbs_single_text']) || !empty($settings['breadcrumbs_single_text'])] ); $breadcrumbs_html = trim((string) ob_get_clean()); } $status_badge = function_exists('aksrt_get_post_status_badge') ? aksrt_get_post_status_badge($post_id) : ''; $allow_view = function_exists('aksrt_get_post_allow_view_data') ? aksrt_get_post_allow_view_data($post_id) : ['allow' => true]; if (empty($allow_view['allow'])) { // Zibll: pay box is skipped when allow_view denies. $show_pay_box = false; } $aside_widgets = is_active_sidebar('sidebar-article') || is_active_sidebar('all_sidebar_top') || is_active_sidebar('all_sidebar_bottom'); return [ 'post_id' => $post_id, 'settings' => $settings, 'show_cover' => $show_cover, 'show_toc' => $show_toc, 'cover_url' => (string) ($settings['cover_url'] ?? ''), 'cover_type' => (string) ($settings['cover_type'] ?? 'none'), '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) ($settings['episode_count'] ?? 0)), 'video_episodes' => is_array($settings['video_episodes'] ?? null) ? array_values($settings['video_episodes']) : [], 'video_poster' => (string) ($settings['video_poster'] ?? ''), 'meta_items' => $meta_items, 'meta_items_secondary' => $meta_items_secondary, 'meta_box_html' => $meta_box_html, 'title_html' => function_exists('aksrt_get_single_title_html') ? aksrt_get_single_title_html($post_id) : esc_html(get_the_title($post_id)), 'allow_view' => $allow_view, 'views' => $views, 'comment_count' => $comment_count, 'like_count' => $like_count, 'favorite_count' => $favorite_count, 'is_liked' => function_exists('aksrt_is_post_liked') ? aksrt_is_post_liked($post_id) : false, 'is_favorited' => function_exists('aksrt_is_post_favorited') ? aksrt_is_post_favorited($post_id) : false, 'copyright_text' => $copyright, 'front_content' => (string) ($settings['front_content'] ?? ''), '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_pay_box, 'toc_title' => __('文章目录', 'aksrt'), ]; } endif; if (!function_exists('aksrt_single_is_docs_page')) : /** * Docs fast-path: true when the current post should leave the unified single surface. */ function aksrt_single_is_docs_page(int $post_id): bool { if (!class_exists('AKSRT_Docs_Presenter')) { return false; } return (bool) AKSRT_Docs_Presenter::get_instance()->is_docs_page($post_id); } endif; if (!function_exists('aksrt_single_render_author_bar')) : /** * Render author bar from a real args array (no ambient query vars). * * @param array $args Partial args. */ function aksrt_single_render_author_bar(array $args = []): void { $args = wp_parse_args($args, [ 'extra_class' => '', 'show_actions' => false, 'show_bio' => false, 'meta_items' => [], ]); get_template_part('templates/parts/single-author-bar', null, $args); } endif; if (!function_exists('aksrt_single_render_cover')) : /** * Cover / slide / video header (Zibll single-head-cover). * * @param array $ctx Single context. */ function aksrt_single_render_cover(array $ctx): void { if (empty($ctx['show_cover']) || $ctx['cover_url'] === '') { return; } $type = (string) $ctx['cover_type']; $badge = (string) $ctx['status_badge']; $crumbs = (string) $ctx['breadcrumbs_html']; $meta_box = (string) ($ctx['meta_box_html'] ?? ''); $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_html = (string) ($ctx['title_html'] ?? esc_html(get_the_title())); if ($type === 'video') : ?>
style="position:absolute;inset:0;width:100%;height:100%;">
(string) $slide_url, 'alt' => wp_strip_all_tags(get_the_title()), ]; } $overlay = '
' . '

' . $title_html . '

' . ($crumbs !== '' ? $crumbs : '') . $badge . '
' . ($meta_box !== '' ? str_replace('abs-right', 'cover-meta abs-right', $meta_box) : ''); $slider_html = ''; if (function_exists('aksrt_render_slider')) { $slider_html = aksrt_render_slider([ 'slides' => $slide_items, 'scale_height' => true, 'scale_ratio' => $img_scale / 100, 'wrapper_class' => 'mb20 single-cover-slide imgbox-container', 'slider_class' => 'single-cover single-cover--slide', 'show_nav' => true, 'show_pagination' => true, 'loop' => count($slide_items) > 1, 'autoplay' => count($slide_items) > 1, 'overlay_html' => $overlay, ]); } ?>
$slide_url) : ?>
alt="">

$ctx Single context. */ function aksrt_single_render_box_header(array $ctx): void { $settings = is_array($ctx['settings'] ?? null) ? $ctx['settings'] : []; ?>

true, 'show_time' => empty($settings['hide_time']), 'meta_html' => empty($ctx['show_cover']) ? (string) ($ctx['meta_box_html'] ?? '') : '', ]); ?>
$ctx Single context. */ function aksrt_single_render_actions(array $ctx): void { $settings = is_array($ctx['settings'] ?? null) ? $ctx['settings'] : []; $post_id = (int) $ctx['post_id']; $like_count = (int) $ctx['like_count']; $favorite_count = (int) $ctx['favorite_count']; $is_liked = !empty($ctx['is_liked']); $is_favorited = !empty($ctx['is_favorited']); ?>
$ctx Single context. */ function aksrt_single_render_content_footer(array $ctx): void { $settings = is_array($ctx['settings'] ?? null) ? $ctx['settings'] : []; $post_id = (int) $ctx['post_id']; ?>
©
THE END
$ctx Single context. */ function aksrt_single_render_author_card(array $ctx): void { $author_id = (int) get_the_author_meta('ID'); if ($author_id <= 0) { return; } $author_url = get_author_posts_url($author_id); $author_name = get_the_author(); $bio = trim((string) get_the_author_meta('description')); $vip_badge = function_exists('aksrt_render_vip_badge') ? aksrt_render_vip_badge($author_id, 'sm') : ''; $signals = []; if (class_exists('AKSRT_User_Home')) { $signals = AKSRT_User_Home::get_instance()->get_profile_signals($author_id); } $avatar = function_exists('aksrt_get_avatar_html') ? aksrt_get_avatar_html($author_id, 80, ['class' => 'avatar avatar-lg']) : get_avatar($author_id, 80, '', esc_attr($author_name), ['class' => 'avatar avatar-lg']); $recent = get_posts([ 'author' => $author_id, 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => 6, 'orderby' => 'date', 'order' => 'DESC', 'no_found_rows' => true, ]); ?>
$ctx Single context. */ function aksrt_single_render_prevnext(array $ctx = []): void { $settings = is_array($ctx['settings'] ?? null) ? $ctx['settings'] : []; $enabled = array_key_exists('prevnext', $settings) ? !empty($settings['prevnext']) : (!array_key_exists('prevnext_s', $settings) || !empty($settings['prevnext_s'])); if (!$enabled) { return; } // Zibll: constrain to current category when available. $in_same_term = !empty(get_the_category()); $prev = get_previous_post($in_same_term, '', 'category'); $next = get_next_post($in_same_term, '', 'category'); if (!$prev && !$next) { // Fallback: any post. $prev = get_previous_post(); $next = get_next_post(); } if (!$prev && !$next) { return; } $prev_title = $prev ? get_the_title($prev) : __('无更多文章', 'aksrt'); $next_title = $next ? get_the_title($next) : __('无更多文章', 'aksrt'); $prev_href = $prev ? get_permalink($prev) : 'javascript:;'; $next_href = $next ? get_permalink($next) : 'javascript:;'; ?> $settings Single display settings. * @return array */ function aksrt_single_related_query_args(int $post_id, array $settings): array { $count = max(1, min(12, (int) ($settings['related_count'] ?? 6))); $type = sanitize_key((string) ($settings['related_source'] ?? ($settings['related_type'] ?? 'category'))); if (!in_array($type, ['category', 'tag', 'random'], true)) { $type = 'category'; } $orderby = sanitize_key((string) ($settings['related_orderby'] ?? 'views')); if (!in_array($orderby, ['rand', 'relevance', 'date', 'views', 'modified'], true)) { $orderby = 'views'; } $args = [ 'post_type' => get_post_type($post_id) ?: 'post', 'post_status' => 'publish', 'post__not_in' => [$post_id], 'posts_per_page' => $count, 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'order' => 'DESC', ]; if ($type === 'random') { $args['orderby'] = 'rand'; return $args; } $tax_query = ['relation' => 'OR']; if ($type === 'tag') { $tag_ids = wp_get_post_terms($post_id, 'post_tag', ['fields' => 'ids']); if (!empty($tag_ids) && !is_wp_error($tag_ids)) { $tax_query[] = [ 'taxonomy' => 'post_tag', 'field' => 'term_id', 'terms' => array_map('intval', $tag_ids), ]; } } else { // category (default): OR across category + tags + topics like Zibll. $cat_ids = wp_get_post_terms($post_id, 'category', ['fields' => 'ids']); if (!empty($cat_ids) && !is_wp_error($cat_ids)) { $tax_query[] = [ 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => array_map('intval', $cat_ids), ]; } $tag_ids = wp_get_post_terms($post_id, 'post_tag', ['fields' => 'ids']); if (!empty($tag_ids) && !is_wp_error($tag_ids)) { $tax_query[] = [ 'taxonomy' => 'post_tag', 'field' => 'term_id', 'terms' => array_map('intval', $tag_ids), ]; } if (taxonomy_exists('topics')) { $topic_ids = wp_get_post_terms($post_id, 'topics', ['fields' => 'ids']); if (!empty($topic_ids) && !is_wp_error($topic_ids)) { $tax_query[] = [ 'taxonomy' => 'topics', 'field' => 'term_id', 'terms' => array_map('intval', $topic_ids), ]; } } } if (count($tax_query) > 1) { $args['tax_query'] = $tax_query; } switch ($orderby) { case 'rand': $args['orderby'] = 'rand'; break; case 'date': $args['orderby'] = 'date'; break; case 'modified': $args['orderby'] = 'modified'; break; case 'views': $args['meta_key'] = 'aksrt_post_views'; $args['orderby'] = 'meta_value_num'; break; case 'relevance': default: // Prefer date when no search relevance context. $args['orderby'] = 'date'; break; } return $args; } endif; if (!function_exists('aksrt_single_render_related')) : /** * Related posts — Zibll-like list + optional shared mini renderer. * * @param array $ctx Single context. */ function aksrt_single_render_related(array $ctx): void { $settings = is_array($ctx['settings'] ?? null) ? $ctx['settings'] : []; if (empty($settings['related_enabled'])) { return; } $post_id = (int) $ctx['post_id']; $title = (string) ($settings['related_title'] ?? ''); if ($title === '') { $title = __('相关推荐', 'aksrt'); } $style = sanitize_key((string) ($settings['related_style'] ?? 'img')); if (!in_array($style, ['img', 'list', 'text'], true)) { $style = 'img'; } $args = function_exists('aksrt_single_related_query_args') ? aksrt_single_related_query_args($post_id, $settings) : [ 'post_type' => get_post_type($post_id) ?: 'post', 'post_status' => 'publish', 'post__not_in' => [$post_id], 'posts_per_page' => max(1, min(12, (int) ($settings['related_count'] ?? 6))), 'ignore_sticky_posts' => true, ]; $query = new WP_Query($args); if (!$query->have_posts()) { wp_reset_postdata(); return; } $wrap_class = 'theme-box relates' . ($style === 'img' ? ' relates-thumb' : ''); ?>
'related', 'mode' => 'mini', 'show_thumb' => true, 'show_meta' => true, 'show_number' => false, ]); ?> have_posts()) { $query->the_post(); $p = get_post(); if (!($p instanceof WP_Post)) { continue; } if ($style === 'img' && function_exists('aksrt_render_related_graphic_card')) { $posts_html .= aksrt_render_related_graphic_card($p); } else { $posts_html .= '
  • ' . esc_html(get_the_title($p)) . '
  • '; } } ?>
      ' . esc_html__('暂无相关文章', 'aksrt') . ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
    $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; } $allow = $ctx['allow_view'] ?? null; if (is_array($allow) && empty($allow['allow'])) { 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 '
    '; get_template_part('templates/parts/resource-download-box'); echo '
    '; return; } if (!function_exists('aksrt_get_pay_meta')) { return; } $has_access = function_exists('aksrt_has_paid_access') ? aksrt_has_paid_access($post) : false; $paid_class = $has_access ? 'paid-box' : 'pay-box'; echo '
    '; 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 '
    ' . esc_html__('已解锁', 'aksrt') . '' . esc_html(get_the_title($post)) . '
    '; } } elseif (function_exists('aksrt_get_paywall_html')) { echo aksrt_get_paywall_html($post); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } echo '
    '; } endif; if (!function_exists('aksrt_single_pay_box_matches')) : /** * @param array $ctx */ function aksrt_single_pay_box_matches(array $ctx, string $slot): bool { if (empty($ctx['show_pay_box'])) { return false; } $allow = $ctx['allow_view'] ?? null; if (is_array($allow) && empty($allow['allow'])) { return false; } return (string) ($ctx['paid_box_position'] ?? 'top') === $slot; } endif; if (!function_exists('aksrt_single_render_article')) : /** * Main article box (Zibll zib_single_content order). * * @param array $ctx Single context. */ function aksrt_single_render_article(array $ctx): void { $settings = is_array($ctx['settings'] ?? null) ? $ctx['settings'] : []; $maxheight = (int) $ctx['content_maxheight']; ?>
    >
    0 ? ' style="max-height:' . esc_attr((string) $maxheight) . 'px;"' : ''; ?> data-maxheight=" 0 ? max(0, $maxheight - 80) : 0)); ?>" data-aksrt-toc="" data-aksrt-toc-depth="" > '

    ', 'after' => '

    ', ]); ?>
    $ctx Single context. */ function aksrt_single_render_after_box(array $ctx): void { $settings = is_array($ctx['settings'] ?? null) ? $ctx['settings'] : []; if (!empty($settings['yiyan_box'])) { ?>
    $ctx Single context. */ function aksrt_single_render_aside(array $ctx): void { if (empty($ctx['show_aside']) || wp_is_mobile()) { return; } ?> |null $ctx Optional prebuilt context. */ function aksrt_single(?array $ctx = null): void { $ctx = is_array($ctx) ? $ctx : aksrt_single_build_context(); if (empty($ctx['show_cover'])) { if ($ctx['breadcrumbs_html'] !== '') { echo $ctx['breadcrumbs_html']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } elseif (function_exists('aksrt_breadcrumbs')) { $settings = is_array($ctx['settings'] ?? null) ? $ctx['settings'] : []; aksrt_breadcrumbs( (string) ($settings['breadcrumbs_home'] ?? ($settings['breadcrumbs_home_text'] ?? '')), ['single_text' => !isset($settings['breadcrumbs_single_text']) || !empty($settings['breadcrumbs_single_text'])] ); } } else { aksrt_single_render_cover($ctx); } 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;