563 lines
28 KiB
PHP
563 lines
28 KiB
PHP
<?php
|
||
/**
|
||
* @package AKSRT
|
||
*/
|
||
|
||
namespace AKSRT\Core;
|
||
|
||
defined('ABSPATH') || exit;
|
||
|
||
|
||
|
||
/**
|
||
* Scripts public enqueue continuation: fonts, icons, global JS, localize.
|
||
*
|
||
* @package AKSRT
|
||
*/
|
||
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_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,
|
||
];
|
||
|
||
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_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']);
|
||
|
||
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']);
|
||
$lightbox_type = sanitize_key((string) ($post_page_settings['lightbox_type'] ?? 'group'));
|
||
if (!in_array($lightbox_type, ['group', 'alone'], true)) {
|
||
$lightbox_type = 'group';
|
||
}
|
||
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' => $lightbox_on ? $lightbox_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'),
|
||
'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 <head> 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
|
||
);
|
||
}
|
||
}
|
||
|
||
// Reference-theme share runtime: direct platform links need no JS;
|
||
// only poster generation is loaded when a share surface can render.
|
||
if (!empty($singular_assets['needs_share']) || is_page_template('templates/pages/page-posts-navs.php')) {
|
||
$poster_share_path = get_template_directory() . '/assets/js/poster-share.js';
|
||
if (file_exists($poster_share_path)) {
|
||
wp_enqueue_script(
|
||
'aksrt-poster-share',
|
||
$base_uri . '/assets/js/poster-share.js',
|
||
['loader_js'],
|
||
(string) filemtime($poster_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'),
|
||
'smsNumberLimitCh' => class_exists('\\AKSRT\\Settings\\Settings') ? !empty(\AKSRT\Settings\Settings::get_sms_settings()['sms_number_limit_ch']) : true,
|
||
'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 翻页文案(参考主题 zib__('load_more') / 'ajax_nomore')
|
||
'ajaxTrigger' => (class_exists('\AKSRT\Settings\Settings') && ($t = \AKSRT\Settings\Settings::get_post_list_style_settings()['ajax_trigger'] ?? '') !== '') ? $t : '<i class="fa fas fa-angle-right"></i>' . __('加载更多', 'aksrt'),
|
||
'ajaxNomore' => (class_exists('\AKSRT\Settings\Settings') && ($n = \AKSRT\Settings\Settings::get_post_list_style_settings()['ajax_nomore'] ?? '') !== '') ? $n : __('没有更多内容了', 'aksrt'),
|
||
// 骨架兜底文案,仅在没有 post_ajax_loader 时使用(参考主题 zib__('loading'))。
|
||
'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 () {
|
||
return class_exists('\AKSRT\Attachment\UploadLimits')
|
||
? \AKSRT\Attachment\UploadLimits::limit_bytes('image')
|
||
: (int) wp_max_upload_size();
|
||
})(),
|
||
'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):预置原因读取后台“禁封/举报”的 ban_preset_reason
|
||
// (UserRuntime::ban_settings,参考主题 _pz('ban_preset_reason') 同源),
|
||
// 图片举证开关与举报说明读取 user_report_img_s / user_report_desc。
|
||
'reportCategories' => (function () {
|
||
if (!class_exists('\AKSRT\Settings\UserRuntime')) {
|
||
return [];
|
||
}
|
||
return \AKSRT\Settings\UserRuntime::ban_settings()['reasons'] ?? [];
|
||
})(),
|
||
'report' => (function () {
|
||
if (!class_exists('\AKSRT\Settings\UserRuntime')) {
|
||
return ['imgEnabled' => false, 'desc' => ''];
|
||
}
|
||
$report = \AKSRT\Settings\UserRuntime::report_settings();
|
||
return [
|
||
'imgEnabled' => !empty($report['img_enabled']),
|
||
'desc' => (string) ($report['desc'] ?? ''),
|
||
];
|
||
})(),
|
||
'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',
|
||
'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'],
|
||
]);
|
||
}
|
||
|
||
}
|