PluginProbe
Echo Knowledge Base – Documentation, FAQs, Chat & Smart Search / 15.0.0
Echo Knowledge Base – Documentation, FAQs, Chat & Smart Search v15.0.0
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 15.0.0, at echo-knowledge-base.php

378 lines 12.6 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: 15.0.0
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 = '15.0.0';
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
56 /**
57 * Initialise the plugin
58 */
59 private function __construct() {
60 self::$plugin_dir = plugin_dir_path( __FILE__ );
61 self::$plugin_url = plugin_dir_url( __FILE__ );
62 }
63
64 /**
65 * Retrieve or create a new instance of this main class (avoid global vars)
66 *
67 * @static
68 * @return Echo_Knowledge_Base
69 */
70 public static function instance() {
71
72 if ( ! empty( self::$instance ) && ( self::$instance instanceof Echo_Knowledge_Base ) ) {
73 return self::$instance;
74 }
75
76 self::$instance = new Echo_Knowledge_Base();
77 self::$instance->setup_system();
78 self::$instance->setup_plugin();
79
80 add_action( 'plugins_loaded', array( self::$instance, 'load_text_domain' ), 11 );
81
82 return self::$instance;
83 }
84
85 /**
86 * Setup class autoloading and other support functions. Setup custom core features.
87 */
88 private function setup_system() {
89
90 // autoload classes ONLY when needed by executed code rather than on every page request
91 require_once self::$plugin_dir . 'includes/system/class-epkb-autoloader.php';
92
93 // register settings
94 self::$instance->kb_config_obj = new EPKB_KB_Config_DB();
95
96 // load non-classes
97 require_once self::$plugin_dir . 'includes/system/plugin-setup.php';
98 require_once self::$plugin_dir . 'includes/system/scripts-registration-public.php';
99 require_once self::$plugin_dir . 'includes/system/scripts-registration-admin.php';
100 require_once self::$plugin_dir . 'includes/system/plugin-links.php';
101 require_once self::$plugin_dir . 'includes/admin/blocks/blocks-json.php';
102
103 new EPKB_Upgrades();
104
105 // setup custom core features
106 new EPKB_Articles_CPT_Setup();
107 new EPKB_Articles_Admin();
108 new EPKB_FAQs_CPT_Setup();
109 new EPKB_Blocks_Setup();
110
111 // subscribe to category actions create/edit/delete including for REST requests in Gutenberg
112 new EPKB_Categories_Admin();
113
114 //new EPKB_AI_Cron();
115 //new EPKB_AI_REST_Chat_Controller();
116 //new EPKB_AI_REST_Search_Controller();
117 }
118
119 /**
120 * Setup plugin before it runs. Include functions and instantiate classes based on user action
121 */
122 private function setup_plugin() {
123
124 $action = EPKB_Utilities::get( 'action' );
125
126 // process action request if any
127 if ( ! empty( $action ) ) {
128 $this->handle_action_request( $action );
129 }
130
131 // handle AJAX front & back-end requests (no admin, no admin bar)
132 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
133 $this->handle_ajax_requests( $action );
134 return;
135 }
136
137 // ADMIN or CLI
138 if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
139 if ( $this->is_kb_plugin_active_for_network( 'echo-knowledge-base/echo-knowledge-base.php' ) ) {
140 add_action( 'plugins_loaded', array( self::$instance, 'setup_backend_classes' ), 11 );
141 } else {
142 $this->setup_backend_classes();
143 }
144 add_action( 'after_setup_theme', array( self::$instance, 'load_features' ), 11 );
145 return;
146 }
147
148 // catch saving and creating of Post in Gutenberg
149 $server_referrer = isset( $_SERVER['HTTP_REFERER'] ) ? wp_unslash( $_SERVER['HTTP_REFERER'] ) : '';
150 if ( ! empty( $server_referrer ) && ( strpos( $server_referrer, '/wp-admin/post.php' ) !== false || strpos( $server_referrer, '/wp-admin/post-new.php' ) !== false ) ) {
151 require_once self::$plugin_dir . 'includes/admin/admin-functions.php';
152 }
153
154 // FRONT-END (no ajax, possibly admin bar)
155 new EPKB_Layouts_Setup(); // KB Main page shortcode, list of themes
156 new EPKB_Articles_Setup();
157 new EPKB_Templates();
158 new EPKB_Shortcodes();
159 new EPKB_Frontend_Editor();
160 //new EPKB_AI_Chat_Frontend();
161 }
162
163 /**
164 * Handle plugin actions here such as saving settings
165 * @param $action
166 */
167 private function handle_action_request( $action ) {
168
169 if ( $action == 'epkb_download_debug_info' ) {
170 new EPKB_Debug_Controller();
171 return;
172 }
173 }
174
175 /**
176 * Handle AJAX requests coming from front-end and back-end
177 * @param $action
178 */
179 private function handle_ajax_requests( $action ) {
180
181 if ( empty( $action ) ) {
182 return;
183 }
184
185 if ( $action == 'epkb-search-kb' ) { // user searching KB
186 new EPKB_KB_Search();
187 return;
188 } else if ( in_array( $action, array( 'epkb_toggle_debug', 'epkb_enable_advanced_search_debug', 'epkb_show_logs', 'epkb_reset_logs' ) ) ) {
189 new EPKB_Debug_Controller();
190 return;
191 } 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_report_admin_error' ) ) ) {
192 new EPKB_KB_Wizard_Cntrl();
193 return;
194 } else if ( in_array( $action, array( EPKB_Need_Help_Features::FEATURES_TAB_VISITED_ACTION ) ) ) {
195 new EPKB_Need_Help_Features();
196 return;
197 } else if ( in_array( $action, array( 'epkb_wpml_enable', 'eckb_update_category_slug_parameter', 'eckb_update_tag_slug_parameter', 'epkb_preload_fonts','epkb_enable_legacy_open_ai',
198 'epkb_load_resource_links_icons', 'epkb_load_general_typography', 'epkb_save_access_control', 'epkb_apply_settings_changes' ) ) ) {
199 new EPKB_KB_Config_Controller();
200 return;
201 } else if ( in_array( $action, array( 'epkb_reset_sequence', 'epkb_show_sequence' ) ) ) {
202 new EPKB_Reset();
203 return;
204 } else if ( in_array( $action, array( 'epkb_create_kb_demo_data' ) ) ) {
205 new EPKB_Controller();
206 return;
207 } else if ( in_array( $action, array( 'epkb_save_faq', 'epkb_get_faq', 'epkb_delete_faq', 'epkb_save_faq_group', 'epkb_delete_faq_group' ) ) ) {
208 new EPKB_FAQs_Ctrl();
209 return;
210 } else if ( in_array( $action, array( 'epkb_faq_get_shortcode' ) ) ) {
211 new EPKB_FAQs_AJAX();
212 return;
213 } else if ( in_array( $action, array( 'epkb_editor_error' ) ) ) {
214 new EPKB_Frontend_Editor();
215 return;
216 } else if ( in_array( $action, array( 'epkb_ai_beta_signup' ) ) ) {
217 new EPKB_AI_Admin_Page();
218 return;
219 }
220
221 if ( $action == 'add-tag' ) {
222 new EPKB_KB_Config_Category();
223 return;
224 }
225
226 if ( $action == 'epkb_dismiss_ongoing_notice' ) {
227 new EPKB_Admin_Notices( true );
228 return;
229 }
230
231 if ( $action == 'epkb_deactivate_feedback' ) {
232 new EPKB_Deactivate_Feedback();
233 return;
234 }
235
236 if ( in_array( $action, array( 'epkb_load_articles_list', 'epkb_convert_kb_content' ) ) ) {
237 new EPKB_Convert_Ctrl();
238 return;
239 }
240
241 if ( $action == 'epkb_update_the_content_flag' ) {
242 new EPKB_Articles_Setup();
243 return;
244 }
245
246 if ( $action == 'epkb_delete_all_kb_data' ) {
247 new EPKB_Delete_KB();
248 return;
249 }
250
251 if ( $action == 'epkb_count_article_view' ) {
252 new EPKB_Article_Count_Cntrl();
253 return;
254 }
255
256 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' ) ) ) {
257 new EPKB_Frontend_Editor();
258 return;
259 }
260 }
261
262 /**
263 * Setup up classes when on ADMIN pages
264 */
265 public function setup_backend_classes() {
266 global $pagenow;
267
268 $is_kb_request = EPKB_KB_Handler::is_kb_request();
269 $request_page = empty( $_REQUEST['page'] ) ? '' : EPKB_Utilities::request_key( 'page' );
270 $admin_pages = [ 'post.php', 'edit.php', 'post-new.php', 'edit-tags.php', 'term.php' ];
271
272 // show KB notice on our pages or when potential KB Main Page is being edited
273 if ( $is_kb_request && in_array( $pagenow, $admin_pages ) ) {
274 new EPKB_Admin_Notices();
275 }
276
277 // article new page
278 if ( $is_kb_request && $pagenow == 'post-new.php' ) {
279 add_action( 'admin_enqueue_scripts', 'epkb_load_admin_article_page_styles' );
280 }
281
282 // article edit page - include scripts to show categories box
283 // phpcs:disable WordPress.Security.NonceVerification.Recommended
284 if ( $pagenow == 'post.php' && ! empty( $_REQUEST['post'] ) && ! empty( $_REQUEST['action'] ) && $_REQUEST['action'] == 'edit' ) {
285 $kb_post_type = get_post_type( sanitize_text_field( wp_unslash( $_REQUEST['post'] ) ) );
286 if ( EPKB_KB_Handler::is_kb_post_type( $kb_post_type ) ) {
287 add_action( 'admin_enqueue_scripts', 'epkb_load_admin_article_page_styles' );
288 }
289 }
290
291 // include our admin scripts on our admin pages (submenus of KB menu) but not on Edit/Add page due to blocks etc.
292 if ( $is_kb_request && $pagenow != 'post-new.php' && $pagenow != 'post.php' ) {
293
294 // KB Configuration Page
295 if ( $request_page == 'epkb-kb-configuration' ) {
296
297 // Setup Wizard
298 if ( isset( $_GET['setup-wizard-on'] ) ) {
299 add_action( 'admin_enqueue_scripts', 'epkb_load_admin_kb_setup_wizard_script' );
300
301 // Usual KB Configuration page
302 } else {
303 add_action( 'admin_enqueue_scripts', 'epkb_load_admin_kb_wizards_script' );
304 add_action( 'admin_enqueue_scripts', 'epkb_load_admin_plugin_pages_resources' );
305 }
306
307 // KB Admin Pages (not config)
308 } else {
309 add_action( 'admin_enqueue_scripts', 'epkb_load_admin_plugin_pages_resources' );
310 }
311 }
312
313 // on Category page show category icon selection feature
314 if ( $is_kb_request && ( $pagenow == 'term.php' || $pagenow == 'edit-tags.php' ) ) {
315 new EPKB_KB_Config_Category();
316 }
317
318 // admin core classes
319 require_once self::$plugin_dir . 'includes/admin/admin-menu.php';
320 require_once self::$plugin_dir . 'includes/admin/admin-functions.php';
321
322 if ( ! empty( $pagenow ) && in_array( $pagenow, [ 'plugins.php', 'plugins-network.php' ] ) ) {
323 new EPKB_Deactivate_Feedback();
324 }
325
326 // Instantiate AI admin page to register AJAX handlers (like deactivation form)
327 new EPKB_AI_Admin_Page();
328 }
329
330 public function load_text_domain() {
331
332 EPKB_KB_Config_Specs::reset_cache_specs();
333
334 /** Check for a translation file in includes/languages/plugins/echo-knowledge-base-LOCALE.mo or .php.
335 If it does not find one, it will try the default path you specify (the /languages directory in your plugin). */
336 load_plugin_textdomain( 'echo-knowledge-base', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
337 }
338
339 public function load_features() {
340 // setup article views counter hooks
341 new EPKB_Article_Count_Handler();
342 }
343
344 // Don't allow this singleton to be cloned.
345 public function __clone() {
346 _doing_it_wrong( __FUNCTION__, 'Invalid (#1)', '4.0' );
347 }
348
349 // Don't allow un-serializing of the class except when testing
350 public function __wakeup() {
351 _doing_it_wrong( __FUNCTION__, 'Invalid (#1)', '4.0' );
352 }
353
354 private function is_kb_plugin_active_for_network( $plugin ) {
355 if ( ! is_multisite() ) {
356 return false;
357 }
358
359 $plugins = get_site_option( 'active_sitewide_plugins' );
360 if ( isset( $plugins[ $plugin ] ) ) {
361 return true;
362 }
363
364 return false;
365 }
366 }
367
368 /**
369 * Returns the single instance of this class
370 * @return Echo_Knowledge_Base - this class instance
371 */
372 function epkb_get_instance() {
373 return Echo_Knowledge_Base::instance();
374 }
375 epkb_get_instance();
376
377 endif; // end class_exists() check
378