| 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.214.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 = '17.214.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 |
/* @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 |
EPKB_AI_Utilities::register_ai_pro_version_guard(); |
| 81 |
self::$instance->setup_plugin(); |
| 82 |
|
| 83 |
add_action( 'plugins_loaded', array( self::$instance, 'load_text_domain' ), 11 ); |
| 84 |
|
| 85 |
return self::$instance; |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Setup class autoloading and other support functions. Setup custom core features. |
| 90 |
*/ |
| 91 |
private function setup_system() { |
| 92 |
|
| 93 |
// autoload classes ONLY when needed by executed code rather than on every page request |
| 94 |
require_once self::$plugin_dir . 'includes/system/class-epkb-autoloader.php'; |
| 95 |
|
| 96 |
// register settings |
| 97 |
self::$instance->kb_config_obj = new EPKB_KB_Config_DB(); |
| 98 |
|
| 99 |
// load non-classes |
| 100 |
require_once self::$plugin_dir . 'includes/system/plugin-setup.php'; |
| 101 |
require_once self::$plugin_dir . 'includes/system/scripts-registration-public.php'; |
| 102 |
require_once self::$plugin_dir . 'includes/system/scripts-registration-admin.php'; |
| 103 |
require_once self::$plugin_dir . 'includes/system/plugin-links.php'; |
| 104 |
require_once self::$plugin_dir . 'includes/admin/blocks/blocks-json.php'; |
| 105 |
|
| 106 |
new EPKB_Upgrades(); |
| 107 |
|
| 108 |
// setup custom core features |
| 109 |
new EPKB_Articles_CPT_Setup(); |
| 110 |
new EPKB_Articles_Admin(); |
| 111 |
new EPKB_FAQs_CPT_Setup(); |
| 112 |
new EPKB_Quizzes_CPT_Setup(); |
| 113 |
new EPKB_Quizzes_Setup(); |
| 114 |
new EPKB_Glossary_Taxonomy_Setup(); |
| 115 |
new EPKB_Glossary_Frontend(); |
| 116 |
new EPKB_Blocks_Setup(); |
| 117 |
|
| 118 |
new EPKB_Categories_Admin(); |
| 119 |
new EPKB_Template_Sync(); |
| 120 |
new EPKB_KB_Demo_Data(); |
| 121 |
|
| 122 |
$this->security_obj = new EPKB_AI_Security(); |
| 123 |
new EPKB_AI_REST_Search_Controller(); |
| 124 |
new EPKB_AI_REST_Chat_Controller(); |
| 125 |
|
| 126 |
// Setup Steps and Pointers for Help Resources page |
| 127 |
new EPKB_Setup_Steps(); |
| 128 |
new EPKB_Setup_Pointers(); |
| 129 |
} |
| 130 |
|
| 131 |
/** |
| 132 |
* Setup plugin before it runs. Include functions and instantiate classes based on user action |
| 133 |
*/ |
| 134 |
private function setup_plugin() { |
| 135 |
|
| 136 |
$action = EPKB_Utilities::get( 'action' ); |
| 137 |
|
| 138 |
// process action request if any |
| 139 |
if ( ! empty( $action ) ) { |
| 140 |
$this->handle_action_request( $action ); |
| 141 |
} |
| 142 |
|
| 143 |
// handle AJAX front & back-end requests (no admin, no admin bar) |
| 144 |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
| 145 |
$this->handle_ajax_requests( $action ); |
| 146 |
return; |
| 147 |
} |
| 148 |
|
| 149 |
/** @disregard P1011 */ |
| 150 |
if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
| 151 |
if ( $this->is_kb_plugin_active_for_network( 'echo-knowledge-base/echo-knowledge-base.php' ) ) { |
| 152 |
add_action( 'plugins_loaded', array( self::$instance, 'setup_backend_classes' ), 11 ); |
| 153 |
} else { |
| 154 |
$this->setup_backend_classes(); |
| 155 |
} |
| 156 |
new EPKB_Article_Count_Handler(); |
| 157 |
return; |
| 158 |
} |
| 159 |
|
| 160 |
// catch saving and creating of Post in Gutenberg |
| 161 |
$server_referrer = isset( $_SERVER['HTTP_REFERER'] ) ? wp_unslash( $_SERVER['HTTP_REFERER'] ) : ''; |
| 162 |
if ( ! empty( $server_referrer ) && ( strpos( $server_referrer, '/wp-admin/post.php' ) !== false || strpos( $server_referrer, '/wp-admin/post-new.php' ) !== false ) ) { |
| 163 |
require_once self::$plugin_dir . 'includes/admin/admin-functions.php'; |
| 164 |
} |
| 165 |
|
| 166 |
// FRONT-END (no ajax, possibly admin bar) |
| 167 |
new EPKB_Layouts_Setup(); // KB Main page shortcode, list of themes |
| 168 |
new EPKB_Articles_Setup(); |
| 169 |
new EPKB_Templates(); |
| 170 |
new EPKB_Shortcodes(); |
| 171 |
new EPKB_AI_Chat_Frontend(); |
| 172 |
|
| 173 |
// REST API controllers |
| 174 |
new EPKB_AI_REST_Admin_Controller(); |
| 175 |
new EPKB_AI_REST_Training_Data_Controller(); |
| 176 |
new EPKB_AI_REST_Sync_Controller(); |
| 177 |
new EPKB_AI_REST_Content_Analysis_Controller(); |
| 178 |
new EPKB_AI_REST_Search_Results_Controller(); |
| 179 |
new EPKB_AI_REST_PDF_Extract_Controller(); |
| 180 |
|
| 181 |
EPKB_AI_Sync_Cron_Handler::init(); |
| 182 |
EPKB_AI_Search_Results_Display::init(); |
| 183 |
} |
| 184 |
|
| 185 |
/** |
| 186 |
* Handle plugin actions here such as saving settings |
| 187 |
* @param $action |
| 188 |
*/ |
| 189 |
private function handle_action_request( $action ) { |
| 190 |
|
| 191 |
if ( in_array( $action, array( 'epkb_download_debug_info', 'epkb_download_ai_config' ), true ) ) { |
| 192 |
new EPKB_Debug_Controller(); |
| 193 |
return; |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
/** |
| 198 |
* Handle AJAX requests coming from front-end and back-end |
| 199 |
* @param $action |
| 200 |
*/ |
| 201 |
private function handle_ajax_requests( $action ) { |
| 202 |
|
| 203 |
if ( empty( $action ) ) { |
| 204 |
return; |
| 205 |
} |
| 206 |
|
| 207 |
if ( $action == 'epkb-search-kb' ) { // user searching KB |
| 208 |
new EPKB_KB_Search(); |
| 209 |
return; |
| 210 |
} else if ( in_array( $action, array( 'epkb_toggle_debug', 'epkb_enable_advanced_search_debug', 'epkb_show_logs', 'epkb_reset_logs' ) ) ) { |
| 211 |
new EPKB_Debug_Controller(); |
| 212 |
return; |
| 213 |
} 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' ) ) ) { |
| 214 |
new EPKB_KB_Wizard_Cntrl(); |
| 215 |
return; |
| 216 |
} else if ( in_array( $action, array( 'epkb_wpml_enable', 'eckb_update_category_slug_parameter', 'eckb_update_tag_slug_parameter', 'epkb_preload_fonts', |
| 217 |
'epkb_load_resource_links_icons', 'epkb_load_general_typography', 'epkb_save_access_control', 'epkb_apply_settings_changes', 'epkb_save_kb_name', |
| 218 |
'epkb_save_sidebar_intro_text', 'epkb_switch_kb_template' ) ) ) { |
| 219 |
new EPKB_KB_Config_Controller(); |
| 220 |
return; |
| 221 |
} else if ( in_array( $action, array( 'epkb_reset_sequence', 'epkb_show_sequence' ) ) ) { |
| 222 |
new EPKB_Reset(); |
| 223 |
return; |
| 224 |
} else if ( in_array( $action, array( 'epkb_create_kb_demo_data' ) ) ) { |
| 225 |
new EPKB_Controller(); |
| 226 |
return; |
| 227 |
} else if ( in_array( $action, array( 'epkb_save_faq', 'epkb_get_faq', 'epkb_delete_faq', 'epkb_save_faq_group', 'epkb_delete_faq_group' ) ) ) { |
| 228 |
new EPKB_FAQs_Ctrl(); |
| 229 |
return; |
| 230 |
} else if ( in_array( $action, array( 'epkb_save_quiz', 'epkb_get_quiz', 'epkb_get_quiz_by_article', 'epkb_delete_quiz', 'epkb_generate_quiz', 'epkb_submit_quiz_attempt' ) ) ) { |
| 231 |
new EPKB_Quizzes_Ctrl(); |
| 232 |
return; |
| 233 |
} else if ( in_array( $action, array( 'epkb_glossary_save_term', 'epkb_glossary_delete_term', 'epkb_glossary_get_term', 'epkb_glossary_bulk_publish', 'epkb_glossary_bulk_delete' ) ) ) { |
| 234 |
new EPKB_Glossary_Ctrl(); |
| 235 |
return; |
| 236 |
} else if ( in_array( $action, array( 'epkb_faq_get_shortcode' ) ) ) { |
| 237 |
new EPKB_FAQs_AJAX(); |
| 238 |
return; |
| 239 |
} else if ( in_array( $action, array( 'epkb_editor_error', 'eckb_hide_fe_toggle_button' ) ) ) { |
| 240 |
new EPKB_Frontend_Editor(); |
| 241 |
return; |
| 242 |
} else if ( in_array( $action, array( 'epkb_ai_beta_signup' ) ) ) { |
| 243 |
new EPKB_AI_Admin_Page; |
| 244 |
return; |
| 245 |
} 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' ) ) ) { |
| 246 |
new EPKB_AI_Tools_Debug_Tab(); |
| 247 |
return; |
| 248 |
} else if ( $action == 'epkb_ai_toggle_debug_mode' ) { |
| 249 |
new EPKB_AI_Tools_Tab(); |
| 250 |
return; |
| 251 |
} else if ( in_array( $action, array( 'epkb_get_ai_status', 'epkb_vote_for_features', 'epkb_submit_empty_content_report' ) ) ) { |
| 252 |
new EPKB_AI_Dashboard_Tab(); |
| 253 |
return; |
| 254 |
} else if ( in_array( $action, array( 'epkb_kb_vote_for_features', 'epkb_enable_glossary', 'epkb_enable_quizzes' ) ) ) { |
| 255 |
new EPKB_Dashboard_Page(); |
| 256 |
return; |
| 257 |
} else if ( $action == 'epkb_check_training_data_sync' ) { |
| 258 |
new EPKB_AI_Dashboard_Tab(); |
| 259 |
return; |
| 260 |
} |
| 261 |
|
| 262 |
if ( $action == 'add-tag' ) { |
| 263 |
new EPKB_KB_Config_Category(); |
| 264 |
return; |
| 265 |
} |
| 266 |
|
| 267 |
if ( $action == 'epkb_dismiss_ongoing_notice' ) { |
| 268 |
new EPKB_Admin_Notices( true ); |
| 269 |
return; |
| 270 |
} |
| 271 |
|
| 272 |
if ( $action == 'epkb_deactivate_feedback' ) { |
| 273 |
new EPKB_Deactivate_Feedback(); |
| 274 |
return; |
| 275 |
} |
| 276 |
|
| 277 |
if ( in_array( $action, array( 'epkb_load_articles_list', 'epkb_convert_kb_content' ) ) ) { |
| 278 |
new EPKB_Convert_Ctrl(); |
| 279 |
return; |
| 280 |
} |
| 281 |
|
| 282 |
if ( in_array( $action, array( 'epkb_import_pdf_article', 'epkb_ai_extract_pdf_text', 'epkb_prepare_pdf_content' ) ) ) { |
| 283 |
new EPKB_PDF_Import_Ctrl(); |
| 284 |
return; |
| 285 |
} |
| 286 |
|
| 287 |
if ( $action == 'epkb_update_the_content_flag' ) { |
| 288 |
new EPKB_Articles_Setup(); |
| 289 |
return; |
| 290 |
} |
| 291 |
|
| 292 |
if ( $action == 'epkb_delete_all_kb_data' ) { |
| 293 |
new EPKB_Delete_KB(); |
| 294 |
return; |
| 295 |
} |
| 296 |
|
| 297 |
if ( $action == 'epkb_count_article_view' ) { |
| 298 |
new EPKB_Article_Count_Cntrl(); |
| 299 |
return; |
| 300 |
} |
| 301 |
|
| 302 |
if ( in_array( $action, array( 'epkb_toggle_article_views_counter', 'epkb_get_filtered_analytics' ) ) ) { |
| 303 |
new EPKB_Analytics_Page(); |
| 304 |
return; |
| 305 |
} |
| 306 |
|
| 307 |
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' ) ) ) { |
| 308 |
new EPKB_Frontend_Editor(); |
| 309 |
return; |
| 310 |
} |
| 311 |
|
| 312 |
// Elementor AJAX save - register hooks to convert text-editor widgets with KB shortcode to shortcode widgets |
| 313 |
if ( $action == 'elementor_ajax' ) { |
| 314 |
new EPKB_Site_Builders(); |
| 315 |
return; |
| 316 |
} |
| 317 |
} |
| 318 |
|
| 319 |
/** |
| 320 |
* Setup up classes when on ADMIN pages |
| 321 |
*/ |
| 322 |
public function setup_backend_classes() { |
| 323 |
global $pagenow; |
| 324 |
|
| 325 |
$is_kb_request = EPKB_KB_Handler::is_kb_request(); |
| 326 |
$request_page = empty( $_REQUEST['page'] ) ? '' : EPKB_Utilities::request_key( 'page' ); |
| 327 |
$admin_pages = [ 'post.php', 'edit.php', 'post-new.php', 'edit-tags.php', 'term.php' ]; |
| 328 |
|
| 329 |
// show KB notice and AI Help Sidebar on our pages or when potential KB Main Page is being edited |
| 330 |
if ( $is_kb_request && in_array( $pagenow, $admin_pages ) ) { |
| 331 |
new EPKB_Admin_Notices(); |
| 332 |
} |
| 333 |
|
| 334 |
// article new page |
| 335 |
if ( $is_kb_request && $pagenow == 'post-new.php' ) { |
| 336 |
add_action( 'admin_enqueue_scripts', 'epkb_load_admin_article_page_styles' ); |
| 337 |
} |
| 338 |
|
| 339 |
// article edit page - include scripts to show categories box |
| 340 |
// phpcs:disable WordPress.Security.NonceVerification.Recommended |
| 341 |
if ( $pagenow == 'post.php' && ! empty( $_REQUEST['post'] ) && ! empty( $_REQUEST['action'] ) && $_REQUEST['action'] == 'edit' ) { |
| 342 |
$kb_post_type = get_post_type( sanitize_text_field( wp_unslash( $_REQUEST['post'] ) ) ); |
| 343 |
if ( EPKB_KB_Handler::is_kb_post_type( $kb_post_type ) ) { |
| 344 |
add_action( 'admin_enqueue_scripts', 'epkb_load_admin_article_page_styles' ); |
| 345 |
} |
| 346 |
} |
| 347 |
|
| 348 |
// include our admin scripts on our admin pages (submenus of KB menu) but not on Edit/Add page due to blocks etc. |
| 349 |
if ( $is_kb_request && $pagenow != 'post-new.php' && $pagenow != 'post.php' ) { |
| 350 |
|
| 351 |
// KB Configuration Page |
| 352 |
if ( $request_page == 'epkb-kb-configuration' ) { |
| 353 |
|
| 354 |
// Setup Wizard |
| 355 |
if ( isset( $_GET['setup-wizard-on'] ) ) { |
| 356 |
add_action( 'admin_enqueue_scripts', 'epkb_load_admin_kb_setup_wizard_script' ); |
| 357 |
|
| 358 |
// Usual KB Configuration page |
| 359 |
} else { |
| 360 |
add_action( 'admin_enqueue_scripts', 'epkb_load_admin_kb_wizards_script' ); |
| 361 |
add_action( 'admin_enqueue_scripts', 'epkb_load_admin_plugin_pages_resources' ); |
| 362 |
} |
| 363 |
|
| 364 |
// KB Admin Pages (not config) |
| 365 |
} else { |
| 366 |
add_action( 'admin_enqueue_scripts', 'epkb_load_admin_plugin_pages_resources' ); |
| 367 |
} |
| 368 |
} |
| 369 |
|
| 370 |
// on Category page show category icon selection feature |
| 371 |
if ( $is_kb_request && ( $pagenow == 'term.php' || $pagenow == 'edit-tags.php' ) ) { |
| 372 |
new EPKB_KB_Config_Category(); |
| 373 |
} |
| 374 |
|
| 375 |
// admin core classes |
| 376 |
require_once self::$plugin_dir . 'includes/admin/admin-menu.php'; |
| 377 |
require_once self::$plugin_dir . 'includes/admin/admin-functions.php'; |
| 378 |
|
| 379 |
if ( ! empty( $pagenow ) && in_array( $pagenow, [ 'plugins.php', 'plugins-network.php' ] ) ) { |
| 380 |
new EPKB_Deactivate_Feedback(); |
| 381 |
} |
| 382 |
|
| 383 |
new EPKB_AI_Admin_Page(); |
| 384 |
// TODO new EPKB_AI_Sync_Hooks(); |
| 385 |
|
| 386 |
// Initialize Analytics Page to register AJAX handlers |
| 387 |
new EPKB_Analytics_Page(); |
| 388 |
} |
| 389 |
|
| 390 |
public function load_text_domain() { |
| 391 |
|
| 392 |
EPKB_KB_Config_Specs::reset_cache_specs(); |
| 393 |
|
| 394 |
/** Check for a translation file in includes/languages/plugins/echo-knowledge-base-LOCALE.mo or .php. |
| 395 |
If it does not find one, it will try the default path you specify (the /languages directory in your plugin). */ |
| 396 |
load_plugin_textdomain( 'echo-knowledge-base', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); |
| 397 |
} |
| 398 |
|
| 399 |
// Don't allow this singleton to be cloned. |
| 400 |
public function __clone() { |
| 401 |
_doing_it_wrong( __FUNCTION__, 'Invalid (#1)', '4.0' ); |
| 402 |
} |
| 403 |
|
| 404 |
// Don't allow un-serializing of the class except when testing |
| 405 |
public function __wakeup() { |
| 406 |
_doing_it_wrong( __FUNCTION__, 'Invalid (#1)', '4.0' ); |
| 407 |
} |
| 408 |
|
| 409 |
private function is_kb_plugin_active_for_network( $plugin ) { |
| 410 |
if ( ! is_multisite() ) { |
| 411 |
return false; |
| 412 |
} |
| 413 |
|
| 414 |
$plugins = get_site_option( 'active_sitewide_plugins' ); |
| 415 |
if ( isset( $plugins[ $plugin ] ) ) { |
| 416 |
return true; |
| 417 |
} |
| 418 |
|
| 419 |
return false; |
| 420 |
} |
| 421 |
} |
| 422 |
|
| 423 |
/** |
| 424 |
* Returns the single instance of this class |
| 425 |
* @return Echo_Knowledge_Base - this class instance |
| 426 |
*/ |
| 427 |
function epkb_get_instance() { |
| 428 |
return Echo_Knowledge_Base::instance(); |
| 429 |
} |
| 430 |
epkb_get_instance(); |
| 431 |
|
| 432 |
endif; // end class_exists() check |
| 433 |
|