进行了一些小修复

This commit is contained in:
2026-08-26 13:54:49 +08:00
parent ed1a47cf4e
commit d4b7ec1deb
9 changed files with 1763 additions and 80 deletions
+137 -12
View File
@@ -16,10 +16,136 @@ defined('ABSPATH') || exit;
*/
trait ScriptsPart1c {
/**
* Resolve the assets required by the current singular response.
*
* @return array<string,bool>
*/
private function resolve_singular_asset_requirements(bool $is_single_post, bool $is_single_resource, bool $is_paid_content_single): array {
$requirements = [
'is_article' => false,
'has_code' => false,
'has_toc' => false,
'has_video' => false,
'has_hidden_content' => false,
'needs_cover' => false,
'needs_navigation' => false,
'needs_related_toc' => false,
'needs_post_card' => false,
'needs_sidebar' => false,
'needs_breadcrumb' => false,
'needs_comments' => false,
'needs_comment_tools' => false,
'needs_page_template' => false,
'needs_reward' => false,
'needs_yiyan' => false,
'needs_share' => false,
'needs_print' => false,
];
if (!is_singular()) {
return $requirements;
}
$post_id = (int) get_queried_object_id();
$post = $post_id > 0 ? get_post($post_id) : null;
if (!$post instanceof \WP_Post) {
return $requirements;
}
$is_docs_article = $is_single_post
&& function_exists('aksrt_single_is_docs_page')
&& aksrt_single_is_docs_page($post_id);
$is_article = ($is_single_post || $is_single_resource) && !$is_docs_article;
$settings = function_exists('aksrt_resolve_single_post_display_settings')
? aksrt_resolve_single_post_display_settings($post_id)
: [];
$content = (string) $post->post_content;
$display_content = $content
. (string) ($settings['front_content'] ?? '')
. (string) ($settings['after_content'] ?? '');
$has_code = (bool) preg_match(
'/(?:<!--\s*wp:(?:code|preformatted|aksrt\/enlighter)\b|<pre\b|data-enlighter-language)/i',
$display_content
);
$heading_count = preg_match_all('/<h[1-4]\b/i', $display_content);
$has_hidden_content = $is_paid_content_single || (bool) preg_match(
'/(?:<!--\s*wp:aksrt\/paid-fragment\b|\[(?:aksrt_hide|hide|reply|vip|payshow|hidecontent|content)\b|aksrt-(?:hidden-content|paywall))/i',
$content
);
$comment_settings = class_exists('\\AKSRT\\Settings\\Settings')
? \AKSRT\Settings\Settings::get_comment_display_settings()
: [];
$comments_disabled = $is_docs_article
|| post_password_required($post_id)
|| !empty($comment_settings['close_comments']);
$comments_are_open = !$comments_disabled && comments_open($post_id);
$has_comments = !$comments_disabled && (
$comments_are_open
|| (int) get_comments_number($post_id) > 0
);
$can_use_comment_form = $comments_are_open && (
empty($comment_settings['require_login'])
|| is_user_logged_in()
);
$show_cover = !empty($settings['show_cover']) && (string) ($settings['cover_url'] ?? '') !== '';
$has_video = $is_article && (
($show_cover && (string) ($settings['cover_type'] ?? '') === 'video')
|| str_contains($content, 'data-aksrt-video')
);
$has_yiyan = $is_article && (
!empty($settings['yiyan_header'])
|| !empty($settings['yiyan_footer'])
|| !empty($settings['yiyan_box'])
);
$has_inserted_content = trim((string) ($settings['front_content'] ?? '')) !== ''
|| trim((string) ($settings['after_content'] ?? '')) !== '';
$has_page_break = (bool) preg_match('/<!--\s*nextpage\s*-->/i', $content);
$has_related = $is_article && !empty($settings['related_enabled']);
$layout = function_exists('aksrt_get_post_show_layout')
? (string) aksrt_get_post_show_layout($post_id)
: '';
$requirements['is_article'] = $is_article;
$requirements['has_code'] = $has_code;
$requirements['has_toc'] = $is_article && $heading_count >= 2;
$requirements['has_video'] = $has_video;
$requirements['has_hidden_content'] = $has_hidden_content || $has_yiyan || $has_inserted_content;
$requirements['needs_cover'] = $is_article && (
$show_cover
|| !empty($settings['breadcrumbs'])
|| $is_paid_content_single
);
$requirements['needs_navigation'] = $is_article && $has_page_break;
$requirements['needs_related_toc'] = $is_article && (
!empty($settings['reading_progress'])
|| !empty($settings['maxheight_enabled'])
|| !empty($settings['prevnext'])
|| $has_related
);
$requirements['needs_post_card'] = $has_related;
$requirements['needs_sidebar'] = $is_article
&& get_post_type($post_id) === 'post'
&& $layout !== 'no_sidebar'
&& function_exists('aksrt_is_show_sidebar')
&& aksrt_is_show_sidebar();
$requirements['needs_breadcrumb'] = $is_article && !empty($settings['breadcrumbs']);
$requirements['needs_comments'] = $has_comments;
$requirements['needs_comment_tools'] = $can_use_comment_form;
$requirements['needs_page_template'] = !empty($settings['lightbox']) || !empty($settings['maxheight_enabled']);
$requirements['needs_reward'] = $is_article && !empty($settings['rewards_enabled']);
$requirements['needs_yiyan'] = $has_yiyan;
$requirements['needs_share'] = $is_article && !empty($settings['share_enabled']);
$requirements['needs_print'] = !empty($settings['print_enabled']);
return $requirements;
}
/**
* Fonts / FA / global JS stack / aksrtData (split from enqueue_public).
*/
private function enqueue_public_fonts_js_and_data($base_uri, $core_dep, $deps, $is_fixed_homepage, $is_home_or_archive, $is_single_post, $is_single_resource, $version): void {
private function enqueue_public_fonts_js_and_data($base_uri, $core_dep, $deps, $is_fixed_homepage, $is_home_or_archive, $is_single_post, $is_single_resource, $version, array $singular_assets): void {
$runtime_uri = $base_uri . '/assets';
$runtime_main_path = get_template_directory() . '/assets/js/runtime/main.min.js';
$runtime_version = file_exists($runtime_main_path) ? (string) filemtime($runtime_main_path) : $version;
@@ -96,7 +222,7 @@ trait ScriptsPart1c {
// Code block enhancements (copy button + language label)
$precode_js = get_template_directory() . '/assets/js/precode.js';
if (is_singular() && file_exists($precode_js)) {
if (!empty($singular_assets['has_code']) && file_exists($precode_js)) {
wp_enqueue_script(
'aksrt-precode',
$base_uri . '/assets/js/precode.js',
@@ -108,8 +234,7 @@ trait ScriptsPart1c {
// Input field enhancements (auto-resize, counter, validation)
$input_expand_js = get_template_directory() . '/assets/js/input-expand.js';
$needs_input_enhancements = is_singular()
|| (bool) get_query_var('aksrt_sign')
$needs_input_enhancements = (bool) get_query_var('aksrt_sign')
|| (bool) get_query_var('aksrt_user_center')
|| (bool) get_query_var('aksrt_author_identifier');
if ($needs_input_enhancements && file_exists($input_expand_js)) {
@@ -124,7 +249,7 @@ trait ScriptsPart1c {
// Section navs: article TOC / scrollspy
$section_navs_js = get_template_directory() . '/assets/js/section-navs.js';
if (is_singular() && file_exists($section_navs_js)) {
if (!empty($singular_assets['has_toc']) && file_exists($section_navs_js)) {
wp_enqueue_script(
'aksrt-section-navs',
$base_uri . '/assets/js/section-navs.js',
@@ -136,7 +261,7 @@ trait ScriptsPart1c {
// Video player (MP4/HLS/FLV)
$video_player_js = get_template_directory() . '/assets/js/video-player.js';
if (is_singular() && file_exists($video_player_js)) {
if (!empty($singular_assets['has_video']) && file_exists($video_player_js)) {
wp_enqueue_script(
'aksrt-video-player',
$base_uri . '/assets/js/video-player.js',
@@ -148,7 +273,7 @@ trait ScriptsPart1c {
// Reward (打赏)
$reward_js = get_template_directory() . '/assets/js/reward.js';
if (($is_single_post || $is_single_resource) && file_exists($reward_js)) {
if (!empty($singular_assets['needs_reward']) && file_exists($reward_js)) {
wp_enqueue_script(
'aksrt-reward',
$base_uri . '/assets/js/reward.js',
@@ -160,7 +285,7 @@ trait ScriptsPart1c {
// Yiyan (一言轮播)
$yiyan_js = get_template_directory() . '/assets/js/yiyan.js';
if (($is_single_post || $is_single_resource) && file_exists($yiyan_js)) {
if (!empty($singular_assets['needs_yiyan']) && file_exists($yiyan_js)) {
wp_enqueue_script(
'aksrt-yiyan',
$base_uri . '/assets/js/yiyan.js',
@@ -242,7 +367,7 @@ trait ScriptsPart1c {
// Comment toolbar (smilie/code/image/quick shortcodes) — post form.
$load_comment_tools = (is_singular() && comments_open());
$load_comment_tools = !empty($singular_assets['needs_comment_tools']);
if ($load_comment_tools) {
$comment_tools_path = get_template_directory() . '/assets/js/comment-tools.js';
wp_enqueue_script(
@@ -265,7 +390,7 @@ trait ScriptsPart1c {
// Comment actions client (like / edit / delete / moderate / pin).
// Submit path lives in assets/js/core/comments.js (REST).
if (is_singular() && (comments_open() || (int) get_comments_number() > 0)) {
if (!empty($singular_assets['needs_comments'])) {
$comment_ajax_path = get_template_directory() . '/assets/js/comment-ajax.js';
if (file_exists($comment_ajax_path)) {
wp_enqueue_script(
@@ -278,7 +403,7 @@ trait ScriptsPart1c {
}
}
if (is_singular()) {
if (!empty($singular_assets['needs_page_template'])) {
$page_template_path = get_template_directory() . '/assets/js/page-template.js';
if (file_exists($page_template_path)) {
wp_enqueue_script(
@@ -292,7 +417,7 @@ trait ScriptsPart1c {
}
// Post/resource share functionality
if ($is_single_post || $is_single_resource) {
if (!empty($singular_assets['needs_share'])) {
$weixin_share_path = get_template_directory() . '/assets/js/weixin-share.js';
if (file_exists($weixin_share_path)) {
wp_enqueue_script(