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

384 lines 12.3 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: 13.10.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 = '13.10.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
115 /**
116 * Setup plugin before it runs. Include functions and instantiate classes based on user action
117 */
118 private function setup_plugin() {
119
120 $action = EPKB_Utilities::get( 'action' );
121
122 // process action request if any
123 if ( ! empty( $action ) ) {
124 $this->handle_action_request( $action );
125 }
126
127 // handle AJAX front & back-end requests (no admin, no admin bar)
128 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
129 $this->handle_ajax_requests( $action );
130 return;
131 }
132
133 // ADMIN or CLI
134 if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
135 if ( $this->is_kb_plugin_active_for_network( 'echo-knowledge-base/echo-knowledge-base.php' ) ) {
136 add_action( 'plugins_loaded', array( self::$instance, 'setup_backend_classes' ), 11 );
137 } else {
138 $this->setup_backend_classes();
139 }
140 return;
141 }
142
143 // catch saving and creating of Post in Gutenberg
144 $server_referrer = isset( $_SERVER['HTTP_REFERER'] ) ? wp_unslash( $_SERVER['HTTP_REFERER'] ) : '';
145 if ( ! empty( $server_referrer ) && ( strpos( $server_referrer, '/wp-admin/post.php' ) !== false || strpos( $server_referrer, '/wp-admin/post-new.php' ) !== false ) ) {
146 require_once self::$plugin_dir . 'includes/admin/admin-functions.php';
147 }
148
149 // FRONT-END (no ajax, possibly admin bar)
150 new EPKB_Layouts_Setup(); // KB Main page shortcode, list of themes
151 new EPKB_Articles_Setup();
152 new EPKB_Templates();
153 new EPKB_Shortcodes();
154 new EPKB_Main_Page_Visual_Helper();
155 new EPKB_Article_Page_Visual_Helper();
156 new EPKB_Category_Page_Visual_Helper();
157 }
158
159 /**
160 * Handle plugin actions here such as saving settings
161 * @param $action
162 */
163 private function handle_action_request( $action ) {
164
165 if ( $action == 'eckb_apply_editor_changes' ) {
166 new EPKB_Editor_Controller();
167 return;
168 }
169
170 if ( $action == 'epkb_load_editor' ) {
171 new EPKB_Editor_View();
172 return;
173 }
174
175 if ( $action == 'epkb_download_debug_info' ) {
176 new EPKB_Debug_Controller();
177 return;
178 }
179
180 if ( empty( $action ) || ! EPKB_KB_Handler::is_kb_request() ) {
181 return;
182 }
183 }
184
185 /**
186 * Handle AJAX requests coming from front-end and back-end
187 * @param $action
188 */
189 private function handle_ajax_requests( $action ) {
190
191 if ( empty( $action ) ) {
192 return;
193 }
194
195 if ( $action == 'epkb-search-kb' ) { // user searching KB
196 new EPKB_KB_Search();
197 return;
198 } else if ( in_array( $action, array( 'epkb_toggle_debug', 'epkb_enable_advanced_search_debug', 'epkb_show_logs', 'epkb_reset_logs' ) ) ) {
199 new EPKB_Debug_Controller();
200 return;
201 } 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' ) ) ) {
202 new EPKB_KB_Wizard_Cntrl();
203 return;
204 } else if ( in_array( $action, array( EPKB_Need_Help_Features::FEATURES_TAB_VISITED_ACTION ) ) ) {
205 new EPKB_Need_Help_Features();
206 return;
207 } else if ( in_array( $action, array( 'epkb_wpml_enable', 'epkb_preload_fonts','epkb_disable_openai', 'epkb_load_resource_links_icons', 'epkb_load_general_typography', 'epkb_save_access_control', 'epkb_apply_settings_changes' ) ) ) {
208 new EPKB_KB_Config_Controller();
209 return;
210 } else if ( in_array( $action, array( 'epkb_reset_sequence', 'epkb_show_sequence' ) ) ) {
211 new EPKB_Reset();
212 return;
213 } else if ( in_array( $action, array( 'epkb_create_kb_demo_data' ) ) ) {
214 new EPKB_Controller();
215 return;
216 } else if ( in_array( $action, array( 'epkb_save_faq', 'epkb_get_faq', 'epkb_delete_faq', 'epkb_save_faq_group', 'epkb_delete_faq_group' ) ) ) {
217 new EPKB_FAQs_Ctrl();
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_editor_error' ) {
232 new EPKB_Editor_Controller();
233 return;
234 }
235
236 if ( $action == 'epkb_deactivate_feedback' ) {
237 new EPKB_Deactivate_Feedback();
238 return;
239 }
240
241 if ( in_array( $action, array( 'epkb_load_articles_list', 'epkb_convert_kb_content' ) ) ) {
242 new EPKB_Convert_Ctrl();
243 return;
244 }
245
246 if ( $action == 'epkb_update_the_content_flag' ) {
247 new EPKB_Articles_Setup();
248 return;
249 }
250
251 if ( $action == 'epkb_delete_all_kb_data' ) {
252 new EPKB_Delete_KB();
253 return;
254 }
255
256 if ( in_array( $action, [ 'epkb_ai_request', 'epkb_ai_feedback' ] ) ) {
257 new EPKB_AI_Help_Sidebar_Ctrl();
258 return;
259 }
260
261 if ( $action == 'epkb_count_article_view' ) {
262 new EPKB_Article_Count_Cntrl();
263 return;
264 }
265
266 if ( in_array( $action, array('epkb_visual_helper_update_switch_settings', 'epkb_visual_helper_switch_template') ) ) {
267 new EPKB_Visual_Helper();
268 return;
269 }
270 }
271
272 /**
273 * Setup up classes when on ADMIN pages
274 */
275 public function setup_backend_classes() {
276 global $pagenow;
277
278 $is_kb_request = EPKB_KB_Handler::is_kb_request();
279 $request_page = empty( $_REQUEST['page'] ) ? '' : EPKB_Utilities::request_key( 'page' );
280 $admin_pages = [ 'post.php', 'edit.php', 'post-new.php', 'edit-tags.php', 'term.php' ];
281
282 // show KB notice and AI Help Sidebar on our pages or when potential KB Main Page is being edited
283 if ( $is_kb_request && in_array( $pagenow, $admin_pages ) ) {
284 new EPKB_Admin_Notices();
285 new EPKB_AI_Help_Sidebar();
286 }
287
288 // article new page
289 if ( $is_kb_request && $pagenow == 'post-new.php' ) {
290 add_action( 'admin_enqueue_scripts', 'epkb_load_admin_article_page_styles' );
291 }
292
293 // article edit page - include scripts to show categories box
294 // phpcs:disable WordPress.Security.NonceVerification.Recommended
295 if ( $pagenow == 'post.php' && ! empty( $_REQUEST['post'] ) && ! empty( $_REQUEST['action'] ) && $_REQUEST['action'] == 'edit' ) {
296 $kb_post_type = get_post_type( sanitize_text_field( wp_unslash( $_REQUEST['post'] ) ) );
297 if ( EPKB_KB_Handler::is_kb_post_type( $kb_post_type ) ) {
298 new EPKB_AI_Help_Sidebar();
299 add_action( 'admin_enqueue_scripts', 'epkb_load_admin_article_page_styles' );
300 }
301 }
302
303 // include our admin scripts on our admin pages (submenus of KB menu) but not on Edit/Add page due to blocks etc.
304 if ( $is_kb_request && $pagenow != 'post-new.php' && $pagenow != 'post.php' ) {
305
306 // KB Configuration Page
307 if ( $request_page == 'epkb-kb-configuration' ) {
308
309 // Setup Wizard
310 if ( isset( $_GET['setup-wizard-on'] ) ) {
311 add_action( 'admin_enqueue_scripts', 'epkb_load_admin_kb_setup_wizard_script' );
312
313 // Usual KB Configuration page
314 } else {
315 add_action( 'admin_enqueue_scripts', 'epkb_load_admin_kb_wizards_script' );
316 add_action( 'admin_enqueue_scripts', 'epkb_load_admin_plugin_pages_resources' );
317 }
318
319 // KB Admin Pages (not config)
320 } else {
321 add_action( 'admin_enqueue_scripts', 'epkb_load_admin_plugin_pages_resources' );
322 }
323 }
324
325 // on Category page show category icon selection feature
326 if ( $is_kb_request && ( $pagenow == 'term.php' || $pagenow == 'edit-tags.php' ) ) {
327 new EPKB_KB_Config_Category();
328 }
329
330 // admin core classes
331 require_once self::$plugin_dir . 'includes/admin/admin-menu.php';
332 require_once self::$plugin_dir . 'includes/admin/admin-functions.php';
333
334 if ( ! empty( $pagenow ) && in_array( $pagenow, [ 'plugins.php', 'plugins-network.php' ] ) ) {
335 new EPKB_Deactivate_Feedback();
336 }
337
338 // setup article views counter hooks
339 new EPKB_Article_Count_Handler();
340 }
341
342 /**
343 /**
344 * Loads the plugin language files from ./languages directory.
345 */
346 public function load_text_domain() {
347 load_plugin_textdomain( 'echo-knowledge-base', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
348 }
349
350 // Don't allow this singleton to be cloned.
351 public function __clone() {
352 _doing_it_wrong( __FUNCTION__, 'Invalid (#1)', '4.0' );
353 }
354
355 // Don't allow un-serializing of the class except when testing
356 public function __wakeup() {
357 _doing_it_wrong( __FUNCTION__, 'Invalid (#1)', '4.0' );
358 }
359
360 private function is_kb_plugin_active_for_network( $plugin ) {
361 if ( ! is_multisite() ) {
362 return false;
363 }
364
365 $plugins = get_site_option( 'active_sitewide_plugins' );
366 if ( isset( $plugins[ $plugin ] ) ) {
367 return true;
368 }
369
370 return false;
371 }
372 }
373
374 /**
375 * Returns the single instance of this class
376 * @return Echo_Knowledge_Base - this class instance
377 */
378 function epkb_get_instance() {
379 return Echo_Knowledge_Base::instance();
380 }
381 epkb_get_instance();
382
383 endif; // end class_exists() check
384