| @@ -9,11 +9,9 @@ | ||
| 9 | 9 | use WPDataAccess\Cookies\WPDA_Cookies; |
| 10 | 10 | use WPDataAccess\Data_Dictionary\WPDA_Dictionary_Lists; |
| 11 | 11 | use WPDataAccess\Data_Tables\WPDA_Data_Tables; |
| 12 | 12 | use WPDataAccess\Plugin_Table_Models\WPDA_Table_Settings_Model; |
| 13 | -use WPDataAccess\Utilities\WPDA_Table_Actions; | |
| 14 | 13 | use WPDataAccess\Utilities\WPDA_Export; |
| 15 | -use WPDataAccess\Utilities\WPDA_Favourites; | |
| 16 | 14 | use WPDataAccess\WPDA; |
| 17 | 15 | use WPDataProjects\Utilities\WPDP_Export_Project; |
| 18 | 16 | use WPDataAccess\Backup\WPDA_Data_Export; |
| 19 | 17 | use WPDataAccess\Plugin_Table_Models\WPDA_CSV_Uploads_Model; |
| @@ -20,9 +18,8 @@ | ||
| 20 | 18 | use WPDataRoles\WPDA_Roles; |
| 21 | 19 | use WPDataAccess\Utilities\WPDA_Autocomplete; |
| 22 | 20 | use WPDataAccess\Premium\WPDAPRO_Geo_Location\WPDAPRO_Geo_Location_WS; |
| 23 | 21 | use WPDataAccess\Premium\WPDAPRO_Geo_Location\WPDAPRO_Geo_Location; |
| 24 | -use WPDataAccess\Query_Builder\WPDA_Query_Builder; | |
| 25 | 22 | use WPDataAccess\Dashboard\WPDA_Dashboard; |
| 26 | 23 | use WPDataAccess\Dashboard\WPDA_Widget_Code; |
| 27 | 24 | use WPDataAccess\Dashboard\WPDA_Widget_Publication; |
| 28 | 25 | use WPDataAccess\Dashboard\WPDA_Widget_Dbms; |
| @@ -44,8 +41,9 @@ | ||
| 44 | 41 | * @see WP_Data_Access_Public |
| 45 | 42 | * @see WP_Data_Access_I18n |
| 46 | 43 | * @see WP_Data_Access_Loader |
| 47 | 44 | */ |
| 45 | +// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing -- verified on page | |
| 48 | 46 | class WP_Data_Access { |
| 49 | 47 | /** |
| 50 | 48 | * Reference to plugin loader |
| 51 | 49 | * |
| @@ -81,11 +79,9 @@ | ||
| 81 | 79 | * @see WP_Data_Access::define_public_hooks() |
| 82 | 80 | */ |
| 83 | 81 | public function __construct() { |
| 84 | 82 | if ( isset( $_REQUEST['page'] ) ) { |
| 85 | - // phpcs:ignore WordPress.Security.NonceVerification | |
| 86 | 83 | $this->page = sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ); |
| 87 | - // phpcs:ignore WordPress.Security.NonceVerification | |
| 88 | 84 | } |
| 89 | 85 | $this->load_dependencies(); |
| 90 | 86 | $this->set_locale(); |
| 91 | 87 | $this->define_admin_hooks(); |
| @@ -153,14 +149,8 @@ | ||
| 153 | 149 | $this->loader->add_action( 'admin_init', $wpda_cookies, 'handle_plugin_cookies' ); |
| 154 | 150 | } |
| 155 | 151 | // Admin menu. |
| 156 | 152 | $this->loader->add_action( 'admin_menu', $plugin_admin, 'add_menu_items' ); |
| 157 | - $this->loader->add_action( | |
| 158 | - 'admin_menu', | |
| 159 | - $plugin_admin, | |
| 160 | - 'add_menu_my_tables', | |
| 161 | - 11 | |
| 162 | - ); | |
| 163 | 153 | $this->loader->add_filter( 'submenu_file', $plugin_admin, 'wpda_submenu_filter' ); |
| 164 | 154 | // Admin scripts. |
| 165 | 155 | $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
| 166 | 156 | $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
| @@ -167,17 +157,8 @@ | ||
| 167 | 157 | $this->loader->add_action( 'in_admin_header', $plugin_admin, 'user_admin_notices' ); |
| 168 | 158 | $this->loader->add_action( 'admin_head', $plugin_admin, 'remove_icons' ); |
| 169 | 159 | // Add settings page. |
| 170 | 160 | $this->loader->add_action( 'admin_menu', $this, 'wpdataaccess_register_settings_page' ); |
| 171 | - // Query Builder. | |
| 172 | - $query_builder = new WPDA_Query_Builder(); | |
| 173 | - $this->loader->add_action( 'admin_action_wpda_query_builder_execute_sql', $query_builder, 'execute' ); | |
| 174 | - $this->loader->add_action( 'admin_action_wpda_query_builder_save_sql', $query_builder, 'save' ); | |
| 175 | - $this->loader->add_action( 'admin_action_wpda_query_builder_open_sql', $query_builder, 'open' ); | |
| 176 | - $this->loader->add_action( 'admin_action_wpda_query_builder_delete_sql', $query_builder, 'delete' ); | |
| 177 | - $this->loader->add_action( 'admin_action_wpda_query_builder_get_db_hints', $query_builder, 'get_db_hints' ); | |
| 178 | - $this->loader->add_action( 'admin_action_wpda_query_builder_set_db_hints', $query_builder, 'set_db_hints' ); | |
| 179 | - $this->loader->add_action( 'admin_action_wpda_query_builder_get_vqb', $query_builder, 'get_visual_query_ajax' ); | |
| 180 | 161 | // Run unattended scheduled export |
| 181 | 162 | $this->loader->add_action( \WPDataAccess\Utilities\WPDA_Export_Scheduler::SCHEDULER_HOOK_NAME, \WPDataAccess\Utilities\WPDA_Export_Scheduler::class, 'run_scheduled_export' ); |
| 182 | 163 | // Mail service. |
| 183 | 164 | $wpda_mail_server = \WPDataAccess\Utilities\WPDA_Mail::get_option(); |
| @@ -235,15 +216,8 @@ | ||
| 235 | 216 | $this->loader->add_action( 'wp_ajax_wpda_remove_new_dashboard_message', WPDA_Dashboard::class, 'remove_new_dashboard_message' ); |
| 236 | 217 | $this->loader->add_action( 'wp_ajax_wpda_widget_pub_add', WPDA_Widget_Publication::class, 'ajax_widget' ); |
| 237 | 218 | $this->loader->add_action( 'wp_ajax_wpda_widget_chart_add', WPDA_Widget_Google_Chart::class, 'ajax_widget' ); |
| 238 | 219 | $this->loader->add_action( 'wp_ajax_wpda_widget_chart_refresh', WPDA_Widget_Google_Chart::class, 'ajax_refresh' ); |
| 239 | - // Add/remove favourites. | |
| 240 | - $plugin_favourites = new WPDA_Favourites(); | |
| 241 | - $this->loader->add_action( 'admin_action_wpda_add_favourite', $plugin_favourites, 'add' ); | |
| 242 | - $this->loader->add_action( 'admin_action_wpda_rem_favourite', $plugin_favourites, 'rem' ); | |
| 243 | - // Show tables actions. | |
| 244 | - $plugin_table_actions = new WPDA_Table_Actions(); | |
| 245 | - $this->loader->add_action( 'admin_action_wpda_show_table_actions', $plugin_table_actions, 'show' ); | |
| 246 | 220 | $plugin_dictionary_list = new WPDA_Dictionary_Lists(); |
| 247 | 221 | // Get tables for a specific database. |
| 248 | 222 | $this->loader->add_action( 'admin_action_wpda_get_tables', $plugin_dictionary_list, 'get_tables_ajax' ); |
| 249 | 223 | // Get columns for a specific table. |
| @@ -287,27 +261,24 @@ | ||
| 287 | 261 | 'wp_ajax_wpda_dbinit_admin', |
| 288 | 262 | function () { |
| 289 | 263 | if ( !isset( $_POST['wpnonce'], $_POST['wpdaschema_name'] ) ) { |
| 290 | 264 | WPDA::sent_header( 'application/json' ); |
| 291 | - echo WPDA::sent_msg( 'ERROR', 'Invalid arguments' ); | |
| 292 | - // phpcs:ignore WordPress.Security.EscapeOutput | |
| 265 | + WPDA::sent_msg( 'ERROR', 'Invalid arguments' ); | |
| 293 | 266 | wp_die(); |
| 294 | 267 | } |
| 268 | + // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotValidated | |
| 295 | 269 | $wpnonce = sanitize_text_field( wp_unslash( $_REQUEST['wpnonce'] ) ); |
| 296 | - // input var okay. | |
| 297 | 270 | if ( !WPDA::current_user_is_admin() || !wp_verify_nonce( $wpnonce, 'wpda_dbinit_admin_' . WPDA::get_current_user_login() ) ) { |
| 298 | 271 | WPDA::sent_header( 'application/json' ); |
| 299 | - echo WPDA::sent_msg( 'ERROR', 'Not authorized' ); | |
| 300 | - // phpcs:ignore WordPress.Security.EscapeOutput | |
| 272 | + WPDA::sent_msg( 'ERROR', 'Not authorized' ); | |
| 301 | 273 | wp_die(); |
| 302 | 274 | } |
| 303 | 275 | $wpdaschema_name = sanitize_text_field( wp_unslash( $_REQUEST['wpdaschema_name'] ) ); |
| 304 | - // input var okay. | |
| 276 | + // phpcs:enable WordPress.Security.ValidatedSanitizedInput.InputNotValidated | |
| 305 | 277 | $wpdadb = WPDADB::get_db_connection( $wpdaschema_name ); |
| 306 | 278 | if ( null === $wpdadb ) { |
| 307 | 279 | WPDA::sent_header( 'application/json' ); |
| 308 | - echo WPDA::sent_msg( 'ERROR', 'Cannot connect to database' ); | |
| 309 | - // phpcs:ignore WordPress.Security.EscapeOutput | |
| 280 | + WPDA::sent_msg( 'ERROR', 'Cannot connect to database' ); | |
| 310 | 281 | wp_die(); |
| 311 | 282 | } |
| 312 | 283 | $suppress_errors = $wpdadb->suppress_errors( true ); |
| 313 | 284 | $wpdadb->query( 'create function wpda_get_wp_user_id() returns integer deterministic no sql return @wpda_wp_user_id' ); |
| @@ -313,14 +284,12 @@ | ||
| 313 | 284 | $wpdadb->query( 'create function wpda_get_wp_user_id() returns integer deterministic no sql return @wpda_wp_user_id' ); |
| 314 | 285 | $error = $wpdadb->last_error; |
| 315 | 286 | $wpdadb->suppress_errors( $suppress_errors ); |
| 316 | 287 | if ( '' === $error ) { |
| 317 | - //phpcs:ignore - 8.1 proof | |
| 318 | - echo WPDA::sent_msg( 'OK', '' ); | |
| 319 | - // phpcs:ignore WordPress.Security.EscapeOutput | |
| 288 | + // phpcs:ignore -- 8.1 proof | |
| 289 | + WPDA::sent_msg( 'OK', '' ); | |
| 320 | 290 | } else { |
| 321 | - echo WPDA::sent_msg( 'ERROR', "Function not created [{$error}]" ); | |
| 322 | - // phpcs:ignore WordPress.Security.EscapeOutput | |
| 291 | + WPDA::sent_msg( 'ERROR', "Function not created [{$error}]" ); | |
| 323 | 292 | } |
| 324 | 293 | wp_die(); |
| 325 | 294 | }, |
| 326 | 295 | 10, |
| @@ -393,8 +362,78 @@ | ||
| 393 | 362 | }, |
| 394 | 363 | 10, |
| 395 | 364 | 2 |
| 396 | 365 | ); |
| 366 | + // Add WP Data Access dashboard to freemius pages | |
| 367 | + add_action( 'admin_enqueue_scripts', function () { | |
| 368 | + if ( 'wpda_navi-account' === $this->page || 'wpda_navi-pricing' === $this->page || 'wpda_navi-affiliation' === $this->page ) { | |
| 369 | + wp_enqueue_script( 'jquery-ui-sortable' ); | |
| 370 | + wp_enqueue_script( 'jquery-ui-tooltip' ); | |
| 371 | + wp_enqueue_style( | |
| 372 | + 'wpdataaccess_dashboard', | |
| 373 | + plugins_url( '../assets/css/wpda_dashboard.css', __FILE__ ), | |
| 374 | + array(), | |
| 375 | + WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) | |
| 376 | + ); | |
| 377 | + wp_enqueue_script( | |
| 378 | + 'wpdataaccess_dashboard', | |
| 379 | + plugins_url( '../assets/js/wpda_dashboard.js', __FILE__ ), | |
| 380 | + array(), | |
| 381 | + WPDA::get_option( WPDA::OPTION_WPDA_VERSION ), | |
| 382 | + false | |
| 383 | + ); | |
| 384 | + wp_localize_script( 'wpdataaccess_dashboard', 'wpda_dashboard_vars', array( | |
| 385 | + 'wpda_ajaxurl' => admin_url( 'admin-ajax.php' ), | |
| 386 | + ) ); | |
| 387 | + // SAVING SPACE - According to the plugin guidelines it is allowed to include external fonts: | |
| 388 | + // https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/#8-plugins-may-not-send-executable-code-via-third-party-systems . | |
| 389 | + // Load fontawesome icons. | |
| 390 | + // phpcs:disable WordPress.WP.EnqueuedResourceParameters.MissingVersion | |
| 391 | + wp_enqueue_style( | |
| 392 | + 'wpda_fontawesome_icons', | |
| 393 | + WPDA::CDN_FONTAWESOME . 'all.min.css', | |
| 394 | + array(), | |
| 395 | + null, | |
| 396 | + false | |
| 397 | + ); | |
| 398 | + // phpcs:enable WordPress.WP.EnqueuedResourceParameters.MissingVersion | |
| 399 | + // Add dashboards to freemius pages | |
| 400 | + wp_enqueue_style( | |
| 401 | + 'wpda_add_dashboard_freemius', | |
| 402 | + plugins_url( '../assets/css/wpda_freemius.css', __FILE__ ), | |
| 403 | + array(), | |
| 404 | + WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) | |
| 405 | + ); | |
| 406 | + wp_enqueue_script( | |
| 407 | + 'wpda_add_dashboard_freemius', | |
| 408 | + plugins_url( '../assets/js/wpda_freemius.js', __FILE__ ), | |
| 409 | + array(), | |
| 410 | + WPDA::get_option( WPDA::OPTION_WPDA_VERSION ), | |
| 411 | + false | |
| 412 | + ); | |
| 413 | + ob_start(); | |
| 414 | + WPDA_Dashboard::add_dashboard(); | |
| 415 | + $freemius_dashboard = ob_get_clean(); | |
| 416 | + $freemius_title = ''; | |
| 417 | + if ( 'wpda_navi-affiliation' === $this->page ) { | |
| 418 | + $freemius_title = '<h1 class="wp-heading-inline" style="padding-top: 10px">WP Data Access Affiliate Program</h1>'; | |
| 419 | + } else { | |
| 420 | + if ( 'wpda_navi-pricing' === $this->page ) { | |
| 421 | + $freemius_title = '<h1 class="wp-heading-inline" style="padding-top: 10px">WP Data Access Plans and Pricing</h1><h2>Choose your plan and upgrade in minutes!</h2>'; | |
| 422 | + } else { | |
| 423 | + if ( 'wpda_navi-account' === $this->page ) { | |
| 424 | + $freemius_title = '<h1 class="wp-heading-inline" style="padding-top: 10px">WP Data Access Account</h1>'; | |
| 425 | + } | |
| 426 | + } | |
| 427 | + } | |
| 428 | + wp_localize_script( 'wpda_add_dashboard_freemius', 'dashboard', array( | |
| 429 | + 'content' => $freemius_dashboard . $freemius_title, | |
| 430 | + ) ); | |
| 431 | + // Remove notices | |
| 432 | + remove_all_actions( 'admin_notices' ); | |
| 433 | + remove_all_actions( 'all_admin_notices' ); | |
| 434 | + } | |
| 435 | + }, 9 ); | |
| 397 | 436 | } |
| 398 | 437 | |
| 399 | 438 | /** |
| 400 | 439 | * Needed for JDT to support IE |
| @@ -405,10 +444,11 @@ | ||
| 405 | 444 | * @return mixed|string |
| 406 | 445 | */ |
| 407 | 446 | public function add_id_to_script( $tag, $handle, $src ) { |
| 408 | 447 | if ( 'wpda_datatables' === $handle ) { |
| 448 | + // phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript | |
| 409 | 449 | $tag = '<script id="wpda_datatables" src="' . $src . '"></script>'; |
| 410 | - // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript | |
| 450 | + // phpcs:enable WordPress.WP.EnqueuedResources.NonEnqueuedScript | |
| 411 | 451 | } |
| 412 | 452 | return $tag; |
| 413 | 453 | } |
| 414 | 454 | |
| @@ -470,11 +510,49 @@ | ||
| 470 | 510 | * |
| 471 | 511 | * @since 1.0.0 |
| 472 | 512 | */ |
| 473 | 513 | public function run() { |
| 514 | + $this->loader->add_action( 'init', $this, 'register_blocks' ); | |
| 515 | + $this->loader->add_action( 'enqueue_block_assets', $this, 'enqueue_block_assets' ); | |
| 474 | 516 | $this->loader->run(); |
| 475 | 517 | } |
| 476 | 518 | |
| 519 | + public function register_blocks() { | |
| 520 | + register_block_type( plugin_dir_path( dirname( __FILE__ ) ) . 'assets/gtb', array( | |
| 521 | + 'render_callback' => array($this, 'render_wp_data_access_app_block'), | |
| 522 | + ) ); | |
| 523 | + } | |
| 524 | + | |
| 525 | + public function enqueue_block_assets() { | |
| 526 | + wp_enqueue_style( 'dashicons' ); | |
| 527 | + } | |
| 528 | + | |
| 529 | + public function render_wp_data_access_app_block( $attributes ) { | |
| 530 | + $appid = ( isset( $attributes['appid'] ) ? sanitize_text_field( $attributes['appid'] ) : '' ); | |
| 531 | + $feedback = filter_var( $attributes['feedback'] ?? false, FILTER_VALIDATE_BOOLEAN ); | |
| 532 | + $builders = filter_var( $attributes['builders'] ?? false, FILTER_VALIDATE_BOOLEAN ); | |
| 533 | + $hidetitlebar = filter_var( $attributes['hidetitlebar'] ?? false, FILTER_VALIDATE_BOOLEAN ); | |
| 534 | + $fullscreen = filter_var( $attributes['fullscreen'] ?? false, FILTER_VALIDATE_BOOLEAN ); | |
| 535 | + if ( empty( $appid ) ) { | |
| 536 | + return null; | |
| 537 | + } | |
| 538 | + if ( !shortcode_exists( 'wpda_app' ) ) { | |
| 539 | + return 'Shortcode wpda_app is not registered.'; | |
| 540 | + } | |
| 541 | + $shortcode = sprintf( | |
| 542 | + '[wpda_app app_id="%s" builders="%s" feedback="%s" hidetitlebar="%s" fullscreen="%s"]', | |
| 543 | + esc_attr( $appid ), | |
| 544 | + ( $builders ? 'false' : 'true' ), | |
| 545 | + ( $feedback ? 'true' : 'false' ), | |
| 546 | + ( $hidetitlebar ? 'true' : 'false' ), | |
| 547 | + ( $fullscreen ? 'true' : 'false' ) | |
| 548 | + ); | |
| 549 | + $wrapper_attributes = get_block_wrapper_attributes( array( | |
| 550 | + 'class' => 'wpda-wp-data-access-app', | |
| 551 | + ) ); | |
| 552 | + return sprintf( '<div %s>%s</div>', $wrapper_attributes, do_shortcode( $shortcode ) ); | |
| 553 | + } | |
| 554 | + | |
| 477 | 555 | /** |
| 478 | 556 | * Add plugin settings page |
| 479 | 557 | */ |
| 480 | 558 | public function wpdataaccess_register_settings_page() { |
| @@ -492,9 +570,8 @@ | ||
| 492 | 570 | */ |
| 493 | 571 | public function wpdataaccess_settings_page() { |
| 494 | 572 | WPDA_Dashboard::add_dashboard(); |
| 495 | 573 | $current_tab = ( isset( $_REQUEST['tab'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tab'] ) ) : 'plugin' ); |
| 496 | - // phpcs:ignore WordPress.Security.NonceVerification | |
| 497 | 574 | switch ( $current_tab ) { |
| 498 | 575 | case 'apps': |
| 499 | 576 | $wpda_settings_class_name = 'WPDA_Settings_Apps'; |
| 500 | 577 | break; |
| @@ -533,4 +610,6 @@ | ||
| 533 | 610 | $wpda_settings->show(); |
| 534 | 611 | } |
| 535 | 612 | |
| 536 | 613 | } |
| 614 | + | |
| 615 | +// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing | |