*/ 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_pay_box' => 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( '/(?:/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_pay_box'] = $is_paid_content_single || (bool) preg_match('/\[(?:payshow|hidecontent)\b|wp:aksrt\/paid-fragment/i', $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, 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; $loader_path = get_template_directory() . '/assets/js/runtime/loader.js'; $bootstrap_path = get_template_directory() . '/assets/js/runtime/libs/bootstrap.min.js'; $post_page_settings = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_post_page_settings() : []; $lightbox_on = !isset($post_page_settings['lightbox']) || !empty($post_page_settings['lightbox']); wp_enqueue_script( 'bootstrap', $base_uri . '/assets/js/runtime/libs/bootstrap.min.js', ['jquery'], '3.4.1', true ); wp_enqueue_script( 'loader_js', $base_uri . '/assets/js/runtime/loader.js', ['jquery', 'bootstrap'], file_exists($loader_path) ? (string) filemtime($loader_path) : $version, true ); wp_localize_script( 'loader_js', '_win', [ 'views' => '', 'www' => home_url('/'), 'uri' => $runtime_uri, 'ver' => $runtime_version, // 货币符号 / 单位来自「收款接口」页配置(pay_currency_mark / pay_currency_unit)。 'pay_mark' => class_exists('\AKSRT\Settings\Settings') && class_exists('\AKSRT\Settings\PaymentRuntime') ? \AKSRT\Settings\PaymentRuntime::get_paid_content_settings()['display']['currency_symbol'] : '¥', 'pay_currency_unit' => class_exists('\AKSRT\Settings\Settings') && class_exists('\AKSRT\Settings\PaymentRuntime') ? \AKSRT\Settings\PaymentRuntime::get_paid_content_settings()['display']['currency_unit'] : __('元', 'aksrt'), 'imgbox' => $lightbox_on, 'imgbox_type' => 'group', 'imgbox_thumbs' => $lightbox_on && (!isset($post_page_settings['lightbox_thumbs']) || !empty($post_page_settings['lightbox_thumbs'])), 'imgbox_zoom' => $lightbox_on && (!isset($post_page_settings['lightbox_zoom']) || !empty($post_page_settings['lightbox_zoom'])), 'imgbox_full' => $lightbox_on && (!isset($post_page_settings['lightbox_full']) || !empty($post_page_settings['lightbox_full'])), 'imgbox_play' => $lightbox_on && !empty($post_page_settings['lightbox_play']), 'imgbox_down' => $lightbox_on && !empty($post_page_settings['lightbox_down']), 'ajax_url' => admin_url('admin-ajax.php'), 'ajaxpager' => '', 'ajax_trigger' => __('加载更多', 'aksrt'), 'ajax_nomore' => __('没有更多了', 'aksrt'), 'qj_loading' => __('加载中...', 'aksrt'), 'highlight_kg' => false, 'highlight_hh' => false, 'highlight_btn' => false, 'highlight_zt' => 'enlighter', 'highlight_white_zt' => 'enlighter', 'highlight_dark_zt' => 'dracula', 'upload_img_size' => 3, 'img_upload_multiple' => 6, 'upload_video_size' => 30, 'upload_file_size' => 30, 'upload_ext' => implode('|', array_keys(get_allowed_mime_types())), 'user_upload_nonce' => wp_create_nonce('user_upload'), 'post_action_nonce' => wp_create_nonce('post_action'), 'is_split_upload' => false, 'split_minimum_size' => 10, 'translate_config' => [], 'i18n' => [ 'load_more' => __('加载更多', 'aksrt'), 'processing' => __('处理中...', 'aksrt'), 'please_wait' => __('请稍候', 'aksrt'), 'done' => __('操作完成', 'aksrt'), 'confirm_clear_search' => __('确认清空搜索记录?', 'aksrt'), 'search_loading' => __('搜索中...', 'aksrt'), 'search_min_chars' => __('至少输入 %s 个字符', 'aksrt'), ], ] ); // AJAX 调试(WP_DEBUG 或 ?aksrt_ajax_debug=1):记录所有失败的 // jQuery ajax / fetch 请求,用于定位 vendor main.min.js 的 400 "0" 来源。 if (function_exists('aksrt_ajax_debug_enabled') && aksrt_ajax_debug_enabled()) { $ajax_debug_path = get_template_directory() . '/assets/js/core/ajax-debug.js'; wp_enqueue_script( 'aksrt-ajax-debug', $base_uri . '/assets/js/core/ajax-debug.js', ['loader_js'], file_exists($ajax_debug_path) ? (string) filemtime($ajax_debug_path) : $version, true ); } // Code block enhancements (copy button + language label) $precode_js = get_template_directory() . '/assets/js/precode.js'; if (!empty($singular_assets['has_code']) && file_exists($precode_js)) { wp_enqueue_script( 'aksrt-precode', $base_uri . '/assets/js/precode.js', ['loader_js'], (string) filemtime($precode_js), true ); } // Input field enhancements (auto-resize, counter, validation) $input_expand_js = get_template_directory() . '/assets/js/input-expand.js'; $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)) { wp_enqueue_script( 'aksrt-input-expand', $base_uri . '/assets/js/input-expand.js', ['loader_js'], (string) filemtime($input_expand_js), true ); } // Section navs: article TOC / scrollspy $section_navs_js = get_template_directory() . '/assets/js/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', ['loader_js'], (string) filemtime($section_navs_js), true ); } // Video player (MP4/HLS/FLV) $video_player_js = get_template_directory() . '/assets/js/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', ['loader_js'], (string) filemtime($video_player_js), true ); } // Reward (打赏) $reward_js = get_template_directory() . '/assets/js/reward.js'; if (!empty($singular_assets['needs_reward']) && file_exists($reward_js)) { wp_enqueue_script( 'aksrt-reward', $base_uri . '/assets/js/reward.js', ['loader_js'], (string) filemtime($reward_js), true ); } // Yiyan (一言轮播) $yiyan_js = get_template_directory() . '/assets/js/yiyan.js'; if (!empty($singular_assets['needs_yiyan']) && file_exists($yiyan_js)) { wp_enqueue_script( 'aksrt-yiyan', $base_uri . '/assets/js/yiyan.js', ['loader_js'], (string) filemtime($yiyan_js), true ); } // Frontend translate (默认关) // Content protection (copy notice / right-click / F12) $content_protect = class_exists('\AKSRT\Settings\Settings') ? [ 'enabled' => (bool) \AKSRT\Settings\Settings::get_value('content_protect_enabled', false), 'copy' => (bool) \AKSRT\Settings\Settings::get_value('content_protect_copy_notice', false), 'right_click' => (bool) \AKSRT\Settings\Settings::get_value('content_protect_right_click', false), 'devtools' => (bool) \AKSRT\Settings\Settings::get_value('content_protect_f12', false), ] : []; $content_protect_js = get_template_directory() . '/assets/js/content-protect.js'; if (in_array(true, $content_protect, true) && file_exists($content_protect_js)) { wp_enqueue_script( 'aksrt-content-protect', $base_uri . '/assets/js/content-protect.js', [], (string) filemtime($content_protect_js), false // load in
for early binding ); } // Site notice popup (global, controlled by Settings) $site_notice_config = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_system_notice_config() : []; $site_notice_enabled = !empty($site_notice_config['enabled']) && trim((string) ($site_notice_config['content'] ?? '')) !== ''; $site_notice_css = get_template_directory() . '/assets/css/frontend/site-notice.css'; if ($site_notice_enabled && file_exists($site_notice_css)) { wp_enqueue_style( 'aksrt-site-notice', $base_uri . '/assets/css/frontend/site-notice.css', [$core_dep], (string) filemtime($site_notice_css) ); } $site_notice_js = get_template_directory() . '/assets/js/site-notice.js'; if ($site_notice_enabled && file_exists($site_notice_js)) { wp_enqueue_script( 'aksrt-site-notice', $base_uri . '/assets/js/site-notice.js', ['loader_js'], (string) filemtime($site_notice_js), true ); } // One state machine owns modal and /sign/ authentication. $auth_js = get_template_directory() . '/assets/js/auth.js'; if ((!is_user_logged_in() || (bool) get_query_var('aksrt_sign')) && file_exists($auth_js)) { wp_enqueue_script( 'aksrt-auth', $base_uri . '/assets/js/auth.js', ['loader_js'], (string) filemtime($auth_js), true ); } // Comment toolbar (code/image/link shortcodes) — post form. $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( 'aksrt-comment-tools', $base_uri . '/assets/js/comment-tools.js', ['loader_js'], file_exists($comment_tools_path) ? (string) filemtime($comment_tools_path) : $version, true ); $comment_tools_css = get_template_directory() . '/assets/css/frontend/comment-tools.css'; if (file_exists($comment_tools_css)) { wp_enqueue_style( 'aksrt-comment-tools', $base_uri . '/assets/css/frontend/comment-tools.css', ['aksrt-comments'], (string) filemtime($comment_tools_css) ); } } // Comment actions client (like / edit / delete / moderate / pin). // Submit path lives in assets/js/core/comments.js (REST). 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( 'aksrt-comment-ajax', $base_uri . '/assets/js/comment-ajax.js', ['loader_js'], (string) filemtime($comment_ajax_path), true ); } } 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( 'aksrt-page-template', $base_uri . '/assets/js/page-template.js', ['loader_js'], (string) filemtime($page_template_path), true ); } } // Post/resource share functionality 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( 'aksrt-weixin-share', $base_uri . '/assets/js/weixin-share.js', ['loader_js'], (string) filemtime($weixin_share_path), true ); } $post_share_path = get_template_directory() . '/assets/js/post-share.js'; if (file_exists($post_share_path)) { wp_enqueue_script( 'aksrt-post-share', $base_uri . '/assets/js/post-share.js', ['loader_js', 'aksrt-weixin-share', 'aksrt-share-data'], (string) filemtime($post_share_path), true ); } } // Page navigation (TOC highlight, smooth scroll, doc search) // 评论回复脚本:由 assets/js/core/comment-move-form.js 提供(legacy 同款机制), // 不加载 WP comment-reply,避免两套 moveForm 冲突。 $runtime_routes = $this->resolve_frontend_routes(); // 数据注入 - 全站统一消费 window.aksrtData // Attach to loader_js (bootstraps runtime/main) so ajaxUrl/nonce exist // before pagination/search/article handlers run. wp_localize_script('loader_js', 'aksrtData', [ 'ajaxUrl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('aksrt_public_nonce'), 'restNonce' => wp_create_nonce('wp_rest'), 'captchaSignin' => function_exists('aksrt_is_captcha_enabled_for') && aksrt_is_captcha_enabled_for('signin'), // 已签到详情弹窗(签到成功后就地替换入口按钮用)。 'signinDetailsUrl' => esc_url_raw(rest_url('aksrt/v1/signin/details')), 'visibilityNonce' => wp_create_nonce('aksrt_visibility'), 'siteUrl' => home_url('/'), 'themeUrl' => AKSRT_URI, 'themeMode' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::theme_mode_js_value() : 'auto', 'debug' => defined('WP_DEBUG') && WP_DEBUG, 'debugLog' => defined('WP_DEBUG') && WP_DEBUG && defined('WP_DEBUG_LOG') && WP_DEBUG_LOG, 'postPaginationMode' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_post_pagination_mode() : 'load_more', 'commentPaginationMode' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_comment_pagination_mode() : 'numbered', // AJAX 翻页文案 'ajaxTrigger' => (class_exists('\AKSRT\Settings\Settings') && ($t = \AKSRT\Settings\Settings::get_post_list_style_settings()['ajax_trigger'] ?? '') !== '') ? $t : '加载更多', 'ajaxNomore' => (class_exists('\AKSRT\Settings\Settings') && ($n = \AKSRT\Settings\Settings::get_post_list_style_settings()['ajax_nomore'] ?? '') !== '') ? $n : __('没有更多内容了', 'aksrt'), 'ajaxLoading' => __('正在加载...', 'aksrt'), 'iasMax' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_post_list_style_settings()['ias_max'] : 3, 'commentIasAuto' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_comment_display_settings()['paging_ajax_ias'] : true, 'commentUploadUrl' => esc_url_raw(rest_url('aksrt/v1/comment/upload-image')), 'commentUploadMaxSize' => (function () { $settings = class_exists('\\AKSRT\\Settings\\Settings') ? \AKSRT\Settings\Settings::get_all() : []; $max_size_mb = max(1, min(10, (int) ($settings['comment_image_max_size'] ?? 2))); return $max_size_mb * MB_IN_BYTES; })(), 'commentIasMax' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_comment_display_settings()['paging_ajax_ias_max'] : 3, 'restUrl' => esc_url_raw(rest_url('aksrt/v1')), // Alias used by modal-auth / follow / report (same value as restUrl). 'apiUrl' => esc_url_raw(rest_url('aksrt/v1')), // 举报弹窗预置原因(report.js 徽章选择数据源)。 'reportCategories' => (function () { if (!class_exists('\AKSRT\Settings\Settings')) { return []; } $report = \AKSRT\Settings\Settings::get_user_identity_settings()['report'] ?? []; return is_array($report['categories'] ?? null) ? array_values($report['categories']) : []; })(), 'stickyEnabled' => class_exists('\AKSRT\Settings\Settings') ? !empty(\AKSRT\Settings\Settings::get_post_list_style_settings()['sticky_s']) : true, 'stickyPages' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_post_list_style_settings()['sticky_s'] : ['home', 'cat'], 'badgeShow' => class_exists('\AKSRT\Settings\Settings') ? !empty(\AKSRT\Settings\Settings::get_post_list_style_settings()['list_badge_show']) : true, 'badgeTypes' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_post_list_style_settings()['list_badge_show'] : ['pay', 'tag', 'cat'], // 用户状态 'isLoggedIn' => is_user_logged_in(), 'userId' => get_current_user_id(), 'ordersUrl' => $runtime_routes['orders'], 'userCenterUrl' => function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url() : home_url('/'), 'routes' => [ 'home' => home_url('/'), 'login' => function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url(), 'register' => function_exists('aksrt_get_register_url') ? aksrt_get_register_url() : wp_registration_url(), 'resetPassword' => function_exists('aksrt_get_reset_password_url') ? aksrt_get_reset_password_url() : wp_lostpassword_url(), 'profile' => function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url() : home_url('/profile/'), 'orders' => $runtime_routes['orders'], 'resources' => $runtime_routes['resources'], ], 'shell' => [ 'wrapperId' => '', 'navId' => 'navbar-top', 'searchPanelId' => 'nav-search-panel', 'drawerId' => 'mobile-navbar', 'userMenuId' => 'sub-user-box', 'floatActionsId' => 'float-right-btns', 'tabbarId' => 'footer-tabbar', ], 'themeUri' => get_template_directory_uri(), 'lazyScopes' => [ 'lazy_posts_thumb' => aksrt_is_lazy('lazy_posts_thumb'), 'lazy_avatar' => aksrt_is_lazy('lazy_avatar'), 'lazy_posts_content' => aksrt_is_lazy('lazy_posts_content'), 'lazy_comment' => aksrt_is_lazy('lazy_comment'), 'lazy_sider' => aksrt_is_lazy('lazy_sider'), 'lazy_cover' => aksrt_is_lazy('lazy_cover'), 'lazy_other' => aksrt_is_lazy('lazy_other'), ], 'lazyThumbs' => [ 'default' => aksrt_get_lazy_thumb(), 'sm' => aksrt_get_lazy_thumb('sm'), 'lg' => aksrt_get_lazy_thumb('lg'), ], 'lazyAvatar' => aksrt_get_default_avatar_url(), 'codeHighlight' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_code_highlight_config() : ['enabled' => true, 'lightTheme' => 'enlighter', 'darkTheme' => 'monokai', 'lineNumbers' => false, 'showButtons' => true, 'maxHeight' => 500], 'systemNotice' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_system_notice_config() : ['enabled' => false], 'contentProtect' => [ 'enabled' => class_exists('\AKSRT\Settings\Settings') && (bool) \AKSRT\Settings\Settings::get_value('content_protect_enabled', false), 'copyNotice' => class_exists('\AKSRT\Settings\Settings') && (bool) \AKSRT\Settings\Settings::get_value('content_protect_copy_notice', false), 'copyNoticeText' => class_exists('\AKSRT\Settings\Settings') ? (string) \AKSRT\Settings\Settings::get_value('content_protect_copy_text', '来自本站,请尊重原创版权。') : '', 'disableRightClick'=> class_exists('\AKSRT\Settings\Settings') && (bool) \AKSRT\Settings\Settings::get_value('content_protect_right_click', false), 'detectDevTools' => class_exists('\AKSRT\Settings\Settings') && (bool) \AKSRT\Settings\Settings::get_value('content_protect_f12', false), ], 'translate' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_i18n_config() : ['enabled' => false, 'autoDetect' => true, 'defaultLang' => 'zh-CN'], ]); } }