PluginProbe
Echo Knowledge Base – Documentation, FAQs, Chat & Smart Search / 17.0.4
Echo Knowledge Base – Documentation, FAQs, Chat & Smart Search v17.0.4
17.214.0 17.213.1 17.212.0 17.211.0 17.210.0 17.200.0 11.0.0 12.0.0 13.10.0 14.0.0 15.0.0 16.011.0 16.20.0 17.0.1 17.0.4 17.1.0 17.1.2 17.111.0 17.3.0 17.4.0 trunk
echo-knowledge-base / echo-knowledge-base.php

echo-knowledge-base.php in Echo Knowledge Base – Documentation, FAQs, Chat & Smart Search 17.0.4, at echo-knowledge-base.php

422 lines 13.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Knowledge Base for Documents and FAQs
4 * Plugin URI: https://www.echoknowledgebase.com
5 * Description: Create Echo Knowledge Base articles, docs and FAQs.
6 * Version: 17.0.4
7 * Author: Echo Plugins
8 * Author URI: https://www.echoknowledgebase.com
9 * Text Domain: echo-knowledge-base
10 * Domain Path: /languages
11 * License: GPLv2 or later
12 * License URI: http://www.gnu.org/licenses/gpl-2.0.html
13 *
14 * Knowledge Base for Documents and FAQs is distributed under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 2 of the License, or
16 * any later version.
17 *
18 * Knowledge Base for Documents and FAQs is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with Knowledge Base for Documents and FAQs. If not, see <http://www.gnu.org/licenses/>.
25 *
26 */
27
28 if ( ! defined( 'ABSPATH' ) ) exit;
29
30 if ( ! defined( 'EPKB_PLUGIN_NAME' ) ) {
31 define( 'EPKB_PLUGIN_NAME', 'Echo Knowledge Base' );
32 }
33
34 if ( ! class_exists( 'Echo_Knowledge_Base' ) ) :
35
36 /**
37 * Main class to load the plugin.
38 *
39 * Singleton
40 */
41 final class Echo_Knowledge_Base {
42
43 /* @var Echo_Knowledge_Base */
44 private static $instance;
45
46 public static $version = '17.0.4';
47 public static $plugin_dir;
48 public static $plugin_url;
49 public static $plugin_file = __FILE__;
50 public static $needs_min_add_on_version = array( 'LAY' => '1.2.1', 'MKB' => '1.10.0', 'RTD' => '1.0.0', 'IDG' => '1.0.0', 'BLK' => '1.0.0',
51 'SEA' => '1.0.0', 'PRF' => '1.0.0', 'PIE' => '1.0.0', 'ART' => '1.0.0' );
52
53 /* @var EPKB_KB_Config_DB */
54 public $kb_config_obj;
55 /* @var EPKB_AI_Security */
56 public $security_obj;
57
58 /**
59 * Initialise the plugin
60 */
61 private function __construct() {
62 self::$plugin_dir = plugin_dir_path( __FILE__ );
63 self::$plugin_url = plugin_dir_url( __FILE__ );
64 }
65
66 /**
67 * Retrieve or create a new instance of this main class (avoid global vars)
68 *
69 * @static
70 * @return Echo_Knowledge_Base
71 */
72 public static function instance() {
73
74 if ( ! empty( self::$instance ) && ( self::$instance instanceof Echo_Knowledge_Base ) ) {
75 return self::$instance;
76 }
77
78 self::$instance = new Echo_Knowledge_Base();
79 self::$instance->setup_system();
80 self::$instance->setup_plugin();
81
82 add_action( 'plugins_loaded', array( self::$instance, 'load_text_domain' ), 11 );
83
84 return self::$instance;
85 }
86
87 /**
88 * Setup class autoloading and other support functions. Setup custom core features.
89 */
90 private function setup_system() {
91
92 // autoload classes ONLY when needed by executed code rather than on every page request
93 require_once self::$plugin_dir . 'includes/system/class-epkb-autoloader.php';
94
95 // register settings
96 self::$instance->kb_config_obj = new EPKB_KB_Config_DB();
97
98 // load non-classes
99 require_once self::$plugin_dir . 'includes/system/plugin-setup.php';
100 require_once self::$plugin_dir . 'includes/system/scripts-registration-public.php';
101 require_once self::$plugin_dir . 'includes/system/scripts-registration-admin.php';
102 require_once self::$plugin_dir . 'includes/system/plugin-links.php';
103 require_once self::$plugin_dir . 'includes/admin/blocks/blocks-json.php';
104
105 new EPKB_Upgrades();
106
107 // setup custom core features
108 new EPKB_Articles_CPT_Setup();
109 new EPKB_Articles_Admin();
110 new EPKB_FAQs_CPT_Setup();
111 new EPKB_Glossary_Taxonomy_Setup();
112 new EPKB_Glossary_Frontend();
113 new EPKB_Blocks_Setup();
114
115 new EPKB_Categories_Admin();
116 new EPKB_Template_Sync();
117 new EPKB_KB_Demo_Data();
118
119 $this->security_obj = new EPKB_AI_Security();
120 new EPKB_AI_REST_Search_Controller();
121 new EPKB_AI_REST_Chat_Controller();
122
123 // Setup Steps and Pointers for Help Resources page
124 new EPKB_Setup_Steps();
125 new EPKB_Setup_Pointers();
126 }
127
128 /**
129 * Setup plugin before it runs. Include functions and instantiate classes based on user action
130 */
131 private function setup_plugin() {
132
133 $action = EPKB_Utilities::get( 'action' );
134
135 // process action request if any
136 if ( ! empty( $action ) ) {
137 $this->handle_action_request( $action );
138 }
139
140 // handle AJAX front & back-end requests (no admin, no admin bar)
141 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
142 $this->handle_ajax_requests( $action );
143 return;
144 }
145
146 /** @disregard P1011 */
147 if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
148 if ( $this->is_kb_plugin_active_for_network( 'echo-knowledge-base/echo-knowledge-base.php' ) ) {
149 add_action( 'plugins_loaded', array( self::$instance, 'setup_backend_classes' ), 11 );
150 } else {
151 $this->setup_backend_classes();
152 }
153 new EPKB_Article_Count_Handler();
154 return;
155 }
156
157 // catch saving and creating of Post in Gutenberg
158 $server_referrer = isset( $_SERVER['HTTP_REFERER'] ) ? wp_unslash( $_SERVER['HTTP_REFERER'] ) : '';
159 if ( ! empty( $server_referrer ) && ( strpos( $server_referrer, '/wp-admin/post.php' ) !== false || strpos( $server_referrer, '/wp-admin/post-new.php' ) !== false ) ) {
160 require_once self::$plugin_dir . 'includes/admin/admin-functions.php';
161 }
162
163 // FRONT-END (no ajax, possibly admin bar)
164 new EPKB_Layouts_Setup(); // KB Main page shortcode, list of themes
165 new EPKB_Articles_Setup();
166 new EPKB_Templates();
167 new EPKB_Shortcodes();
168 new EPKB_AI_Chat_Frontend();
169
170 // REST API controllers
171 new EPKB_AI_REST_Admin_Controller();
172 new EPKB_AI_REST_Training_Data_Controller();
173 new EPKB_AI_REST_Sync_Controller();
174 new EPKB_AI_REST_Content_Analysis_Controller();
175 new EPKB_AI_REST_Search_Results_Controller();
176
177 EPKB_AI_Sync_Cron_Handler::init();
178 EPKB_AI_Search_Results_Display::init();
179 }
180
181 /**
182 * Handle plugin actions here such as saving settings
183 * @param $action
184 */
185 private function handle_action_request( $action ) {
186
187 if ( $action == 'epkb_download_debug_info' ) {
188 new EPKB_Debug_Controller();
189 return;
190 }
191 }
192
193 /**
194 * Handle AJAX requests coming from front-end and back-end
195 * @param $action
196 */
197 private function handle_ajax_requests( $action ) {
198
199 if ( empty( $action ) ) {
200 return;
201 }
202
203 if ( $action == 'epkb-search-kb' ) { // user searching KB
204 new EPKB_KB_Search();
205 return;
206 } else if ( in_array( $action, array( 'epkb_toggle_debug', 'epkb_enable_advanced_search_debug', 'epkb_show_logs', 'epkb_reset_logs' ) ) ) {
207 new EPKB_Debug_Controller();
208 return;
209 } else if ( in_array( $action, array( 'epkb_get_wizard_template', 'epkb_apply_wizard_changes', 'epkb_wizard_update_order_view', 'epkb_apply_setup_wizard_changes', 'epkb_get_wizard_preset_preview' ) ) ) {
210 new EPKB_KB_Wizard_Cntrl();
211 return;
212 } else if ( in_array( $action, array( 'epkb_wpml_enable', 'eckb_update_category_slug_parameter', 'eckb_update_tag_slug_parameter', 'epkb_preload_fonts',
213 'epkb_load_resource_links_icons', 'epkb_load_general_typography', 'epkb_save_access_control', 'epkb_apply_settings_changes', 'epkb_save_kb_name',
214 'epkb_save_sidebar_intro_text', 'epkb_switch_kb_template' ) ) ) {
215 new EPKB_KB_Config_Controller();
216 return;
217 } else if ( in_array( $action, array( 'epkb_reset_sequence', 'epkb_show_sequence' ) ) ) {
218 new EPKB_Reset();
219 return;
220 } else if ( in_array( $action, array( 'epkb_create_kb_demo_data' ) ) ) {
221 new EPKB_Controller();
222 return;
223 } else if ( in_array( $action, array( 'epkb_save_faq', 'epkb_get_faq', 'epkb_delete_faq', 'epkb_save_faq_group', 'epkb_delete_faq_group' ) ) ) {
224 new EPKB_FAQs_Ctrl();
225 return;
226 } else if ( in_array( $action, array( 'epkb_glossary_save_term', 'epkb_glossary_delete_term', 'epkb_glossary_get_term', 'epkb_glossary_bulk_publish' ) ) ) {
227 new EPKB_Glossary_Ctrl();
228 return;
229 } else if ( in_array( $action, array( 'epkb_faq_get_shortcode' ) ) ) {
230 new EPKB_FAQs_AJAX();
231 return;
232 } else if ( in_array( $action, array( 'epkb_editor_error', 'eckb_hide_fe_toggle_button' ) ) ) {
233 new EPKB_Frontend_Editor();
234 return;
235 } else if ( in_array( $action, array( 'epkb_ai_beta_signup' ) ) ) {
236 new EPKB_AI_Admin_Page;
237 return;
238 } else if ( in_array( $action, array( 'epkb_ai_get_php_error_logs', 'epkb_ai_get_wp_error_logs', 'epkb_ai_get_ai_logs', 'epkb_ai_clear_ai_logs' ) ) ) {
239 new EPKB_AI_Tools_Debug_Tab();
240 return;
241 } else if ( $action == 'epkb_ai_toggle_debug_mode' ) {
242 new EPKB_AI_Tools_Tab();
243 return;
244 } else if ( in_array( $action, array( 'epkb_get_ai_status', 'epkb_vote_for_features' ) ) ) {
245 new EPKB_AI_Dashboard_Tab();
246 return;
247 } else if ( $action == 'epkb_kb_vote_for_features' ) {
248 new EPKB_Dashboard_Page();
249 return;
250 } else if ( $action == 'epkb_check_training_data_sync' ) {
251 new EPKB_AI_Dashboard_Tab();
252 return;
253 }
254
255 if ( $action == 'add-tag' ) {
256 new EPKB_KB_Config_Category();
257 return;
258 }
259
260 if ( $action == 'epkb_dismiss_ongoing_notice' ) {
261 new EPKB_Admin_Notices( true );
262 return;
263 }
264
265 if ( $action == 'epkb_deactivate_feedback' ) {
266 new EPKB_Deactivate_Feedback();
267 return;
268 }
269
270 if ( in_array( $action, array( 'epkb_load_articles_list', 'epkb_convert_kb_content' ) ) ) {
271 new EPKB_Convert_Ctrl();
272 return;
273 }
274
275 if ( $action == 'epkb_update_the_content_flag' ) {
276 new EPKB_Articles_Setup();
277 return;
278 }
279
280 if ( $action == 'epkb_delete_all_kb_data' ) {
281 new EPKB_Delete_KB();
282 return;
283 }
284
285 if ( $action == 'epkb_count_article_view' ) {
286 new EPKB_Article_Count_Cntrl();
287 return;
288 }
289
290 if ( in_array( $action, array( 'epkb_toggle_article_views_counter', 'epkb_get_filtered_analytics' ) ) ) {
291 new EPKB_Analytics_Page();
292 return;
293 }
294
295 if ( in_array( $action, array( 'eckb_apply_fe_settings', 'eckb_save_fe_settings', 'eckb_save_fe_article_settings', 'eckb_save_fe_archive_settings', 'eckb_closed_fe_editor' ) ) ) {
296 new EPKB_Frontend_Editor();
297 return;
298 }
299
300 // Elementor AJAX save - register hooks to convert text-editor widgets with KB shortcode to shortcode widgets
301 if ( $action == 'elementor_ajax' ) {
302 new EPKB_Site_Builders();
303 return;
304 }
305 }
306
307 /**
308 * Setup up classes when on ADMIN pages
309 */
310 public function setup_backend_classes() {
311 global $pagenow;
312
313 $is_kb_request = EPKB_KB_Handler::is_kb_request();
314 $request_page = empty( $_REQUEST['page'] ) ? '' : EPKB_Utilities::request_key( 'page' );
315 $admin_pages = [ 'post.php', 'edit.php', 'post-new.php', 'edit-tags.php', 'term.php' ];
316
317 // show KB notice and AI Help Sidebar on our pages or when potential KB Main Page is being edited
318 if ( $is_kb_request && in_array( $pagenow, $admin_pages ) ) {
319 new EPKB_Admin_Notices();
320 }
321
322 // article new page
323 if ( $is_kb_request && $pagenow == 'post-new.php' ) {
324 add_action( 'admin_enqueue_scripts', 'epkb_load_admin_article_page_styles' );
325 }
326
327 // article edit page - include scripts to show categories box
328 // phpcs:disable WordPress.Security.NonceVerification.Recommended
329 if ( $pagenow == 'post.php' && ! empty( $_REQUEST['post'] ) && ! empty( $_REQUEST['action'] ) && $_REQUEST['action'] == 'edit' ) {
330 $kb_post_type = get_post_type( sanitize_text_field( wp_unslash( $_REQUEST['post'] ) ) );
331 if ( EPKB_KB_Handler::is_kb_post_type( $kb_post_type ) ) {
332 add_action( 'admin_enqueue_scripts', 'epkb_load_admin_article_page_styles' );
333 }
334 }
335
336 // include our admin scripts on our admin pages (submenus of KB menu) but not on Edit/Add page due to blocks etc.
337 if ( $is_kb_request && $pagenow != 'post-new.php' && $pagenow != 'post.php' ) {
338
339 // KB Configuration Page
340 if ( $request_page == 'epkb-kb-configuration' ) {
341
342 // Setup Wizard
343 if ( isset( $_GET['setup-wizard-on'] ) ) {
344 add_action( 'admin_enqueue_scripts', 'epkb_load_admin_kb_setup_wizard_script' );
345
346 // Usual KB Configuration page
347 } else {
348 add_action( 'admin_enqueue_scripts', 'epkb_load_admin_kb_wizards_script' );
349 add_action( 'admin_enqueue_scripts', 'epkb_load_admin_plugin_pages_resources' );
350 }
351
352 // KB Admin Pages (not config)
353 } else {
354 add_action( 'admin_enqueue_scripts', 'epkb_load_admin_plugin_pages_resources' );
355 }
356 }
357
358 // on Category page show category icon selection feature
359 if ( $is_kb_request && ( $pagenow == 'term.php' || $pagenow == 'edit-tags.php' ) ) {
360 new EPKB_KB_Config_Category();
361 }
362
363 // admin core classes
364 require_once self::$plugin_dir . 'includes/admin/admin-menu.php';
365 require_once self::$plugin_dir . 'includes/admin/admin-functions.php';
366
367 if ( ! empty( $pagenow ) && in_array( $pagenow, [ 'plugins.php', 'plugins-network.php' ] ) ) {
368 new EPKB_Deactivate_Feedback();
369 }
370
371 new EPKB_AI_Admin_Page();
372 // TODO new EPKB_AI_Sync_Hooks();
373
374 // Initialize Analytics Page to register AJAX handlers
375 new EPKB_Analytics_Page();
376 }
377
378 public function load_text_domain() {
379
380 EPKB_KB_Config_Specs::reset_cache_specs();
381
382 /** Check for a translation file in includes/languages/plugins/echo-knowledge-base-LOCALE.mo or .php.
383 If it does not find one, it will try the default path you specify (the /languages directory in your plugin). */
384 load_plugin_textdomain( 'echo-knowledge-base', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
385 }
386
387 // Don't allow this singleton to be cloned.
388 public function __clone() {
389 _doing_it_wrong( __FUNCTION__, 'Invalid (#1)', '4.0' );
390 }
391
392 // Don't allow un-serializing of the class except when testing
393 public function __wakeup() {
394 _doing_it_wrong( __FUNCTION__, 'Invalid (#1)', '4.0' );
395 }
396
397 private function is_kb_plugin_active_for_network( $plugin ) {
398 if ( ! is_multisite() ) {
399 return false;
400 }
401
402 $plugins = get_site_option( 'active_sitewide_plugins' );
403 if ( isset( $plugins[ $plugin ] ) ) {
404 return true;
405 }
406
407 return false;
408 }
409 }
410
411 /**
412 * Returns the single instance of this class
413 * @return Echo_Knowledge_Base - this class instance
414 */
415 function epkb_get_instance() {
416 return Echo_Knowledge_Base::instance();
417 }
418 epkb_get_instance();
419
420 endif; // end class_exists() check
421
422