PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.4
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.4
4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 All 202 releases
betterdocs / includes / Core / Scripts.php

Scripts.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.9.4, at includes/Core/Scripts.php

204 lines 8.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WPDeveloper\BetterDocs\Core;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8
9 use WPDeveloper\BetterDocs\Utils\Base;
10 use WPDeveloper\BetterDocs\Utils\Helper;
11 use WPDeveloper\BetterDocs\FrontEnd\PrintTemplate;
12
13 class Scripts extends Base {
14 protected $settings;
15
16 public function __construct( Settings $settings ) {
17 $this->settings = $settings;
18
19 add_action( 'init', [ $this, 'init' ], 1 );
20 }
21
22 public function init() {
23 $assets = betterdocs()->assets;
24
25 // Vendor CSS
26 $assets->register( 'simplebar', 'vendor/css/simplebar.css' );
27
28 // Vendor JS
29 $assets->register( 'simplebar', 'vendor/js/simplebar.js' );
30
31 if ( ! wp_script_is( 'clipboard', 'registered' ) ) {
32 $assets->register( 'clipboard', 'vendor/js/clipboard.min.js' );
33 }
34
35 // Shortcodes Styles Registrations
36 $assets->register( 'betterdocs-search', 'public/css/search.css' );
37 $assets->register( 'betterdocs-search-modal', 'public/css/search-modal.css' );
38 $assets->register( 'betterdocs-social-share', 'public/css/social-share.css' );
39 $assets->register( 'betterdocs-feedback-form', 'public/css/feedback-form.css' );
40 $assets->register( 'betterdocs-reactions', 'public/css/reactions.css' );
41 $assets->register( 'betterdocs-toc', 'public/css/toc.css' );
42 $assets->register( 'betterdocs-faq', 'public/css/faq.css' );
43 $assets->register( 'betterdocs-category-tab-grid', 'public/css/category-tab-grid.css' );
44 $assets->register( 'reading-time', 'public/css/reading-time.css' );
45
46 // Template Parts
47 $assets->register( 'betterdocs-sidebar', 'public/css/sidebar.css' );
48 $assets->register( 'betterdocs-breadcrumb', 'public/css/breadcrumb.css' );
49 $assets->register( 'betterdocs-single', 'public/css/single.css' );
50 $assets->register( 'betterdocs-docs', 'public/css/docs.css' );
51 $assets->register( 'betterdocs-pagination', 'public/css/pagination.css' );
52 $assets->register( 'betterdocs-doc_category', 'public/css/tax-doc_category.css', [ 'betterdocs-breadcrumb', 'betterdocs-pagination' ] );
53 $assets->register( 'betterdocs-category-archive-header', 'public/css/archive-header.css' );
54 $assets->register( 'betterdocs-category-archive-doc-list', 'public/css/archive-doc-list.css' );
55 $assets->register( 'betterdocs-article-summary', 'public/css/article-summary.css' );
56 $assets->register( 'betterdocs-author', 'public/css/author.css' );
57 $assets->register( 'betterdocs-ai-actions', 'public/css/ai-actions.css' );
58 $assets->register( 'betterdocs-listen', 'public/css/listen.css' );
59
60 $assets->register( 'betterdocs-category-grid', 'public/css/category-grid.css', [ 'simplebar' ] );
61 $assets->register( 'betterdocs-category-box', 'public/css/category-box.css' );
62 $assets->register( 'betterdocs-category-grid-list', 'public/css/category-grid-list.css' );
63
64 // JS
65 $assets->register( 'betterdocs', 'public/js/betterdocs.js', [ 'jquery' ] );
66 // Shortcode JS
67 $assets->register( 'betterdocs-category-toggler', 'public/js/category-toggler.js', [ 'jquery' ] );
68 $assets->register(
69 'betterdocs-category-grid',
70 'public/js/category-grid.js',
71 [
72 'jquery',
73 'masonry',
74 'simplebar',
75 'betterdocs-category-toggler'
76 ]
77 );
78 $assets->register( 'betterdocs-faq', 'shortcodes/js/faq.js', [ 'jquery' ] );
79 $assets->register( 'betterdocs-reactions', 'shortcodes/js/reactions.js', [ 'jquery' ] );
80 $assets->register( 'betterdocs-search', 'shortcodes/js/search.js', [ 'jquery' ] );
81 $assets->register( 'betterdocs-search-modal', 'shortcodes/js/search-modal.js', [ 'jquery' ] );
82
83 /**
84 * Print template config for the single-doc Print / Save-as-PDF button.
85 *
86 * These values feed the print *popup* opened by the BetterDocs print
87 * icon. The browser's own Ctrl/Cmd+P route is handled separately by
88 * {@see PrintTemplate}, which resolves the same two values — see that
89 * class for why the two routes use different layout mechanisms.
90 *
91 * Both toggles live in `betterdocs_settings` (BetterDocs → Settings →
92 * Layout → Single Doc → General) rather than theme mods, so they stay
93 * reachable on block/FSE themes, which have no Customizer. Both default
94 * to OFF; while a toggle is off the value resolves empty and the print
95 * script renders nothing for it.
96 */
97 $print_logo = PrintTemplate::get_logo();
98 $print_footer = PrintTemplate::get_footer();
99
100 $assets->localize(
101 'betterdocs',
102 'betterdocsConfig',
103 [
104 'ajax_url' => admin_url( 'admin-ajax.php' ),
105 'copy_text' => __( 'Copied', 'betterdocs' ),
106 'sticky_toc_offset' => $this->settings->get( 'sticky_toc_offset' ),
107 'summary_nonce' => wp_create_nonce( 'betterdocs_article_summary_nonce' ),
108 'summary_error' => __( 'Failed to generate doc summary. Please try again.', 'betterdocs' ),
109 // Namespaced so the AI Actions strings do not collide as the feature
110 // grows. Nothing URL-shaped belongs here: init() runs with no $post,
111 // so every per-doc URL lives on the rendered data-bd-* attributes.
112 'ai_actions' => [
113 'i18n' => [
114 'copy' => __( 'Copy page', 'betterdocs' ),
115 'copying' => __( 'Copying…', 'betterdocs' ),
116 'copied' => __( 'Copied', 'betterdocs' ),
117 'copy_failed' => __( 'Copy failed', 'betterdocs' ),
118 'copy_error' => __( 'Could not copy this page. Please try again.', 'betterdocs' )
119 ]
120 ],
121 // Same shape and the same reasoning: namespaced, and with nothing
122 // per-doc in it. Core\Listen owns the contents, because the rates and
123 // the two content selectors are filterable and the filters have to
124 // reach the script.
125 //
126 // Guarded: this runs on `init` at 1 and Plugin::initialize() — which
127 // builds the property — is the `init` callback at 0, so the ordering
128 // holds today. It is one priority of slack, and a fatal if it ever
129 // changes.
130 'listen' => isset( betterdocs()->listen ) ? betterdocs()->listen->localize() : [],
131 'print' => [
132 'logo' => $print_logo ? esc_url( $print_logo ) : '',
133 'footer' => $print_footer ? wp_kses_post( $print_footer ) : ''
134 ]
135 ]
136 );
137
138 $assets->localize(
139 'betterdocs-search',
140 'betterdocsSearchConfig',
141 [
142 // Root-relative so live search stays same-origin when the KB is
143 // served on a different host than the Site Address (subdomain /
144 // domain alias / reverse proxy). See Helper::frontend_ajax_url().
145 'ajax_url' => Helper::frontend_ajax_url(),
146 'search_letter_limit' => $this->settings->get( 'search_letter_limit' )
147 ]
148 );
149
150 $assets->localize(
151 'betterdocs-search-modal',
152 'betterdocsSearchModalConfig',
153 [
154 // Same-origin (see betterdocsSearchConfig above).
155 'ajax_url' => Helper::frontend_ajax_url(),
156 'rest_url' => esc_url_raw(rest_url()),
157 'advance_search' => $this->settings->get( 'advance_search' ),
158 'child_category_exclude' => $this->settings->get( 'child_category_exclude' ),
159 'popular_keyword_limit' => $this->settings->get( 'popular_keyword_limit' ),
160 'search_letter_limit' => $this->settings->get( 'search_letter_limit' ),
161 'search_placeholder' => $this->settings->get( 'search_placeholder' ),
162 'search_button_text' => $this->settings->get( 'search_button_text' ),
163 'search_not_found_text' => $this->settings->get( 'search_not_found_text' ),
164 'kb_based_search' => $this->settings->get( 'kb_based_search' )
165 ]
166 );
167
168 /**
169 * Localize This In Order To Know If This Shortcode Is Arriving From Betterdocs Templates Or Not
170 */
171 betterdocs()->assets->localize(
172 'betterdocs-category-grid',
173 'betterdocsCategoryGridConfig',
174 [
175 'is_betterdocs_templates' => betterdocs()->helper->is_templates() ? true : false,
176 'ajax_url' => admin_url( 'admin-ajax.php' ),
177 'lazy_load_action' => 'betterdocs_lazy_category_body'
178 ]
179 );
180
181 $this->blocks( $assets );
182 $this->admin_assets( $assets );
183
184 return $assets;
185 }
186
187
188
189 public function blocks( $assets ) {
190 $assets->register( 'betterdocs-fontawesome', 'vendor/css/font-awesome5.css' );
191 $assets->register( 'betterdocs-blocks-category-box', 'blocks/categorybox/default.css' );
192 $assets->register( 'betterdocs-blocks-category-grid', 'blocks/categorygrid/default.css' );
193 $assets->register( 'betterdocs-blocks-category-tech-layout', 'blocks/category-tech-layout/default.css' );
194 $assets->register( 'betterdocs-blocks-category-slate-layout', 'blocks/category-slate-layout/default.css' );
195 $assets->register( 'betterdocs-feedback-form-editor', 'blocks/feedback-form/style-feedback-editor.css' );
196 $assets->register( 'betterdocs-doc-archive-list', 'blocks/doc-archive-list/default.css' );
197 }
198
199 public function admin_assets( $assets ) {
200 $assets->register( 'betterdocs-article-quality-score', 'admin/js/article-quality-score.js', [ 'jquery' ] );
201
202 }
203 }
204