PluginProbe
EazyDocs – AI Powered Knowledge Base, Wiki, Documentation & FAQ Builder / trunk
EazyDocs – AI Powered Knowledge Base, Wiki, Documentation & FAQ Builder vtrunk
2.14.0 2.13.1 2.13.0 2.12.0 2.11.3 2.11.2 trunk 2.10.0 2.10.1 2.10.2 2.11.0 2.11.1 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 All 34 releases
eazydocs / eazydocs.php

eazydocs.php in EazyDocs – AI Powered Knowledge Base, Wiki, Documentation & FAQ Builder trunk, at eazydocs.php

426 lines 13.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: EazyDocs
4 * Description: Powerful & beautiful documentation, knowledge base builder plugin.
5 * Plugin URI: https://eazydocs.spider-themes.net
6 * Author: Spider Themes
7 * Author URI: https://eazydocs.spider-themes.net
8 * Version: 2.14.0
9 * Requires at least: 5.0
10 * Requires PHP: 7.4
11 * Text Domain: eazydocs
12 * Domain Path: /languages
13 * License: GPLv2 or later
14 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
15 */
16
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit();
19 }
20
21 if ( function_exists( 'eaz_fs' ) ) {
22 eaz_fs()->set_basename( false, __FILE__ );
23 } else {
24 // Check setup wizard completion
25 $opt = get_option( 'eazydocs_settings', array() );
26 if ( get_option( 'ezd_get_setup_wizard' ) && ! empty( $opt['setup_wizard_completed'] ) ) {
27 delete_option( 'ezd_get_setup_wizard' );
28 }
29
30 // Create SDK helper function
31 function eaz_fs() {
32 global $eaz_fs;
33
34 if ( ! isset( $eaz_fs ) ) {
35 require_once __DIR__ . '/vendor/freemius/wordpress-sdk/start.php';
36
37 $eaz_fs = fs_dynamic_init(
38 array(
39 'id' => '10290',
40 'slug' => 'eazydocs',
41 'premium_slug' => 'eazydocs-pro',
42 'type' => 'plugin',
43 'public_key' => 'pk_8474e4208f0893a7b28c04faf5045',
44 'is_premium' => false,
45 'is_premium_only' => false,
46 'has_addons' => false,
47 'has_paid_plans' => true,
48 'trial' => array(
49 'days' => 14,
50 'is_require_payment' => true,
51 ),
52 'menu' => array(
53 'slug' => 'eazydocs',
54 'contact' => false,
55 'support' => false,
56 'first-path' => get_option( 'ezd_get_setup_wizard' ) ? 'admin.php?page=eazydocs-initial-setup' : 'admin.php?page=eazydocs',
57 ),
58 'parallel_activation' => array(
59 'enabled' => true,
60 'premium_version_basename' => 'eazydocs-pro/eazydocs.php',
61 ),
62 )
63 );
64 }
65
66 return $eaz_fs;
67 }
68
69 eaz_fs()->add_filter( 'hide_freemius_powered_by', '__return_true' );
70 do_action( 'eaz_fs_loaded' );
71 }
72
73
74 if ( ! class_exists( 'EazyDocs' ) ) {
75 require_once __DIR__ . '/vendor/autoload.php';
76
77 class EazyDocs {
78
79 // Default constants
80 const version = '2.14.0';
81 public $plugin_path;
82 public $theme_dir_path;
83
84 public function __construct() {
85 $this->define_constants();
86 $this->core_includes();
87
88 register_activation_hook( __FILE__, array( $this, 'activate' ) );
89 add_action( 'init', array( $this, 'init_hooked' ) );
90 add_action( 'plugins_loaded', array( $this, 'init_plugin' ) );
91 add_action( 'after_setup_theme', array( $this, 'load_csf_files' ), 20 );
92 add_action( 'admin_notices', array( $this, 'update_database' ) );
93 add_filter( 'plugin_row_meta', array( $this, 'eazydocs_row_meta' ), 10, 2 );
94
95 add_action(
96 'admin_head',
97 function () {
98 // Check if we're on any EazyDocs admin page, taxonomy page, or post type page
99 $is_ezd_page = ezd_admin_pages() || ezd_admin_taxonomy() || ezd_admin_post_types();
100
101 if ( $is_ezd_page ) {
102 remove_all_actions( 'admin_notices' );
103 remove_all_actions( 'all_admin_notices' );
104
105 // Allow the Antimanual integration notice on EazyDocs pages.
106 if ( class_exists( '\EazyDocs\Admin\AntimanualNotice' ) ) {
107 \EazyDocs\Admin\AntimanualNotice::init();
108 }
109
110 $is_dev_mode = defined( 'DEVELOPER_MODE' ) && DEVELOPER_MODE;
111 if ( $is_dev_mode || ( ! ezd_is_premium() && ezd_is_plugin_installed_for_days( 12 ) && ( ! isset( $_GET['page'] ) || 'eazydocs-initial-setup' !== $_GET['page'] ) ) ) {
112 add_action( 'admin_notices', 'ezd_offer_notice' );
113 }
114
115 if ( function_exists( 'ezd_gutenberg_info_notice' ) ) {
116 add_action( 'admin_notices', 'ezd_gutenberg_info_notice' );
117 }
118 }
119 }
120 );
121 }
122
123 public static function get_instance() {
124 static $instance = null;
125 return $instance ?: ( $instance = new self() );
126 }
127
128 public function core_includes() {
129 require_once __DIR__ . '/includes/functions.php';
130 require_once __DIR__ . '/includes/notices/_notices.php';
131 require_once __DIR__ . '/includes/notices/update-database.php';
132
133 $core_files = array(
134 '/includes/sidebars.php',
135 '/includes/Frontend/Ajax.php',
136 '/includes/Frontend/Mailer.php',
137 '/includes/Post_Types.php',
138 '/includes/One_Page_Docs.php',
139 '/includes/One_Page.php',
140 '/includes/Frontend/Shortcode.php',
141 '/includes/Frontend/post-views.php',
142 '/includes/Frontend/search-counts.php',
143 '/includes/Walker_Docs_Onepage.php',
144 '/includes/Walker_Docs_Onepage_Fullscreen.php',
145 '/includes/Admin/setup-wizard/Plugin_Installer.php',
146 );
147
148 foreach ( $core_files as $file ) {
149 require_once __DIR__ . $file;
150 }
151
152 if ( ezd_unlock_themes( 'docy', 'docly', 'ama' ) ) {
153 require_once __DIR__ . '/shortcodes/reference.php';
154 }
155
156 require_once __DIR__ . '/shortcodes/conditional_data.php';
157 require_once __DIR__ . '/shortcodes/ezd-view-docs.php';
158
159 if ( ezd_is_premium() ) {
160 $docs_url = ezd_get_opt( 'docs-url-structure', 'custom-slug' );
161 $permalink = get_option( 'permalink_structure' );
162
163 if ( 'post-name' === $docs_url && ! empty( $permalink ) && '/archives/%post_id%' !== $permalink ) {
164 require_once __DIR__ . '/includes/Root_Conversion.php';
165 }
166 }
167
168 require_once __DIR__ . '/blocks.php';
169 }
170
171 /**
172 * Include CSF files include
173 */
174 public function load_csf_files() {
175 // Load CSF framework (needed on both frontend and admin)
176 require __DIR__ . '/includes/csf/classes/setup.class.php';
177 require __DIR__ . '/includes/Admin/options/settings-options.php';
178 if ( ezd_is_premium() ) {
179 require_once __DIR__ . '/includes/Admin/options/taxonomy-options.php';
180 }
181 }
182
183 /**
184 * Define constants
185 */
186 public function define_constants() {
187 define( 'EZD_VERSION', self::version );
188 define( 'EZD_FILE', __FILE__ );
189 define( 'EZD_PATH', __DIR__ );
190 define( 'EAZYDOCS_PATH', __DIR__ );
191 define( 'EAZYDOCS_URL', plugins_url( '', EZD_FILE ) );
192 define( 'EZD_URL', plugins_url( '', EZD_FILE ) );
193 define( 'EZD_ASSETS', EZD_URL . '/assets/' );
194 define( 'EZD_STYLES', EZD_URL . '/build/styles/' );
195 define( 'EAZYDOCS_IMG', EZD_URL . '/assets/images/' );
196 define( 'EZD_IMG', EZD_URL . '/assets/images/' );
197 define( 'EZD_VEND', EZD_URL . '/assets/vendors/' );
198 }
199
200 public static function init() {
201 static $instance = false;
202 return $instance ?: ( $instance = new self() );
203 }
204
205 /**
206 * Initialize the plugin
207 */
208 public function init_plugin() {
209 load_plugin_textdomain( 'eazydocs', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
210 $this->theme_dir_path = apply_filters( 'eazydocs_theme_dir_path', 'eazydocs/' );
211 if ( is_admin() ) {
212 new EazyDocs\Admin\Admin();
213 new EazyDocs\Admin\Create_Post();
214 new EazyDocs\Admin\Delete_Post();
215 new EazyDocs\Admin\Assets();
216 new EazyDocs\Admin\Import_Export();
217 new EazyDocs\One_Page();
218 new EazyDocs\Edit_OnePage();
219 } elseif ( ! is_admin() ) {
220 new EazyDocs\Frontend\Frontend();
221 new EazyDocs\Frontend\Assets();
222 new EazyDocs\Frontend\Shortcode();
223 }
224 new EazyDocs\Elementor\Widgets();
225
226 if ( ezd_get_opt( 'is_google_login' ) ) {
227 // Load Google Login functionality
228 new EazyDocs\Google_Login();
229 }
230
231 // Register the Docs Builder REST API route.
232 add_action(
233 'rest_api_init',
234 function () {
235 require_once __DIR__ . '/includes/Admin/Api/DocsBuilderController.php';
236 $controller = new EazyDocs\Admin\Api\Docs_Builder_Controller();
237 $controller->register_routes();
238 }
239 );
240 }
241
242 /**
243 * Initialize hooked classes
244 */
245 public function init_hooked() {
246 load_plugin_textdomain( 'eazydocs', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
247 new EazyDocs\Frontend\Ajax();
248 }
249
250 /**
251 * Do stuff upon plugin activation
252 */
253 public function activate() {
254 // Insert the installation time into the database
255 $installed = get_option( 'eazyDocs_installed' );
256 if ( ! $installed ) {
257 update_option( 'eazyDocs_installed', time() );
258 }
259 update_option( 'EazyDocs_version', EZD_VERSION );
260
261 // Insert the documentation page into the database if not exists
262 if ( ! ezd_get_page_by_title( 'Documentation' ) ) {
263 // Create page object
264 $current_user_id = get_current_user_id();
265 if ( ! $current_user_id ) {
266 $current_user_id = 1; // fallback if no user is logged in
267 }
268 $docs_page = array(
269 'post_title' => wp_strip_all_tags( 'Documentation' ),
270 'post_content' => '<!-- wp:eazydocs-pro/eazy-docs {"docTypes":"multi-doc","docPreset":"box","docSinglePreset":"box","docId":"2484"} /-->',
271 'post_status' => 'publish',
272 'post_author' => $current_user_id,
273 'post_type' => 'page',
274 );
275 wp_insert_post( $docs_page );
276 }
277
278 $this->create_analytics_db_tables();
279
280 // Re-verify the table-existence flags on the next admin/front-end load.
281 delete_transient( 'ezd_analytics_tables_ready' );
282 delete_transient( 'ezd_view_log_table_ready' );
283
284 // Update the option when the setup wizard is activated
285 update_option( 'ezd_get_setup_wizard', true );
286
287 // Reconcile documentation role capabilities from the saved settings.
288 if ( function_exists( 'ezd_sync_docs_capabilities' ) ) {
289 ezd_sync_docs_capabilities( true );
290 }
291 }
292
293 /**
294 * Create database table if not exists
295 * Insert search keywords table and search key logs table into the database if not exists
296 */
297 public function create_analytics_db_tables() {
298 global $wpdb;
299
300 $charset_collate = $wpdb->get_charset_collate();
301 $search_keyword = $wpdb->prefix . 'eazydocs_search_keyword';
302 $search_logs = $wpdb->prefix . 'eazydocs_search_log';
303 $view_logs = $wpdb->prefix . 'eazydocs_view_log';
304
305 // SQL statements to create tables.
306 $sql = "CREATE TABLE {$search_keyword} (
307 id bigint(20) unsigned not null auto_increment,
308 keyword varchar(255) not null,
309 PRIMARY KEY (id)
310 ) {$charset_collate};";
311
312 $sql2 = "CREATE TABLE {$search_logs} (
313 id bigint(20) unsigned not null auto_increment,
314 keyword_id bigint(20) unsigned not null,
315 count mediumint(8) unsigned not null,
316 not_found_count mediumint(8) unsigned not null,
317 created_at datetime not null,
318 PRIMARY KEY (id),
319 FOREIGN KEY (keyword_id) REFERENCES {$search_keyword}(id) ON DELETE CASCADE
320 ) {$charset_collate};";
321
322 $sql3 = "CREATE TABLE {$view_logs} (
323 id bigint(20) unsigned not null auto_increment,
324 post_id bigint(20) unsigned not null,
325 count mediumint(8) unsigned not null,
326 created_at datetime not null,
327 PRIMARY KEY (id)
328 ) {$charset_collate};";
329
330 // Load the required upgrade file.
331 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
332
333 // Execute the table creation queries.
334 dbDelta( $sql );
335 dbDelta( $sql2 );
336 dbDelta( $sql3 );
337 }
338
339 /**
340 * Database not found
341 */
342 function update_database() {
343 // Once the analytics tables are confirmed present, skip the three
344 // SHOW TABLES probes that otherwise ran on every admin page load.
345 // The flag is cleared on plugin activation (and self-heals after a day).
346 if ( get_transient( 'ezd_analytics_tables_ready' ) ) {
347 return;
348 }
349
350 global $wpdb;
351 $table_name = $wpdb->prefix . 'eazydocs_search_keyword';
352 $table_name2 = $wpdb->prefix . 'eazydocs_search_log';
353 $table_name3 = $wpdb->prefix . 'eazydocs_view_log';
354
355 // Suppress direct query warnings since checking table existence requires direct queries
356 // @codingStandardsIgnoreLine WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
357 $keyword_exists = $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $table_name ) );
358 // @codingStandardsIgnoreLine WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
359 $logs_exists = $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $table_name2 ) );
360 // @codingStandardsIgnoreLine WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
361 $view_exists = $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $table_name3 ) );
362
363 if ( $table_name !== $keyword_exists || $table_name2 !== $logs_exists || $table_name3 !== $view_exists ) {
364 // Don't cache the negative result — keep prompting until it's fixed.
365 ?>
366 <div class="notice notice-error is-dismissible eazydocs_table_error">
367 <p><?php esc_html_e( 'EazyDocs database needs an update. Please click the Update button to update your database.', 'eazydocs' ); ?></p>
368 <form method="get">
369 <input type="hidden" name="eazydocs_table_create" value="1">
370 <input type="submit" class="button button-primary" value="<?php esc_html_e( 'Update Database', 'eazydocs' ); ?>">
371 </form>
372 </div>
373 <?php
374 } else {
375 // All tables present — remember it so we stop probing on every page.
376 set_transient( 'ezd_analytics_tables_ready', 1, DAY_IN_SECONDS );
377 }
378 }
379
380 /**
381 * Get the plugin URL.
382 *
383 * @return string
384 */
385 public function plugin_url() {
386 return $this->plugin_url ?: ( $this->plugin_url = untrailingslashit( plugins_url( '/', __FILE__ ) ) );
387 }
388
389 /**
390 * Get the plugin path.
391 *
392 * @return string
393 */
394 public function plugin_path() {
395 return $this->plugin_path ?: ( $this->plugin_path = untrailingslashit( plugin_dir_path( __FILE__ ) ) );
396 }
397
398 /**
399 * Get the template path.
400 *
401 * @return string
402 */
403 public function template_path() {
404 return $this->plugin_path() . '/templates/';
405 }
406
407 /**
408 * Documentation links to plugin row meta
409 */
410 public function eazydocs_row_meta( $links, $file ) {
411 if ( plugin_basename( __FILE__ ) === $file ) {
412 $links[] = '<a href="https://helpdesk.spider-themes.net/docs/eazydocs-wordpress-plugin/" target="_blank">Documentation</a>';
413 $links[] = '<a href="' . admin_url( 'admin.php?page=eazydocs' ) . '">Dashboard</a>';
414 }
415 return $links;
416 }
417 }
418 }
419
420 if ( ! function_exists( 'eazydocs' ) ) {
421 function eazydocs() {
422 return EazyDocs::init();
423 }
424
425 eazydocs();
426 }