| @@ -9,9 +9,8 @@ | ||
| 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 | 14 | use WPDataAccess\Utilities\WPDA_Favourites; |
| 16 | 15 | use WPDataAccess\WPDA; |
| 17 | 16 | use WPDataProjects\Utilities\WPDP_Export_Project; |
| @@ -20,9 +19,8 @@ | ||
| 20 | 19 | use WPDataRoles\WPDA_Roles; |
| 21 | 20 | use WPDataAccess\Utilities\WPDA_Autocomplete; |
| 22 | 21 | use WPDataAccess\Premium\WPDAPRO_Geo_Location\WPDAPRO_Geo_Location_WS; |
| 23 | 22 | use WPDataAccess\Premium\WPDAPRO_Geo_Location\WPDAPRO_Geo_Location; |
| 24 | -use WPDataAccess\Query_Builder\WPDA_Query_Builder; | |
| 25 | 23 | use WPDataAccess\Dashboard\WPDA_Dashboard; |
| 26 | 24 | use WPDataAccess\Dashboard\WPDA_Widget_Code; |
| 27 | 25 | use WPDataAccess\Dashboard\WPDA_Widget_Publication; |
| 28 | 26 | use WPDataAccess\Dashboard\WPDA_Widget_Dbms; |
| @@ -44,8 +42,9 @@ | ||
| 44 | 42 | * @see WP_Data_Access_Public |
| 45 | 43 | * @see WP_Data_Access_I18n |
| 46 | 44 | * @see WP_Data_Access_Loader |
| 47 | 45 | */ |
| 46 | +// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing -- verified on page | |
| 48 | 47 | class WP_Data_Access { |
| 49 | 48 | /** |
| 50 | 49 | * Reference to plugin loader |
| 51 | 50 | * |
| @@ -81,11 +80,9 @@ | ||
| 81 | 80 | * @see WP_Data_Access::define_public_hooks() |
| 82 | 81 | */ |
| 83 | 82 | public function __construct() { |
| 84 | 83 | if ( isset( $_REQUEST['page'] ) ) { |
| 85 | - // phpcs:ignore WordPress.Security.NonceVerification | |
| 86 | 84 | $this->page = sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ); |
| 87 | - // phpcs:ignore WordPress.Security.NonceVerification | |
| 88 | 85 | } |
| 89 | 86 | $this->load_dependencies(); |
| 90 | 87 | $this->set_locale(); |
| 91 | 88 | $this->define_admin_hooks(); |
| @@ -153,14 +150,8 @@ | ||
| 153 | 150 | $this->loader->add_action( 'admin_init', $wpda_cookies, 'handle_plugin_cookies' ); |
| 154 | 151 | } |
| 155 | 152 | // Admin menu. |
| 156 | 153 | $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 | 154 | $this->loader->add_filter( 'submenu_file', $plugin_admin, 'wpda_submenu_filter' ); |
| 164 | 155 | // Admin scripts. |
| 165 | 156 | $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
| 166 | 157 | $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
| @@ -167,17 +158,8 @@ | ||
| 167 | 158 | $this->loader->add_action( 'in_admin_header', $plugin_admin, 'user_admin_notices' ); |
| 168 | 159 | $this->loader->add_action( 'admin_head', $plugin_admin, 'remove_icons' ); |
| 169 | 160 | // Add settings page. |
| 170 | 161 | $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 | 162 | // Run unattended scheduled export |
| 181 | 163 | $this->loader->add_action( \WPDataAccess\Utilities\WPDA_Export_Scheduler::SCHEDULER_HOOK_NAME, \WPDataAccess\Utilities\WPDA_Export_Scheduler::class, 'run_scheduled_export' ); |
| 182 | 164 | // Mail service. |
| 183 | 165 | $wpda_mail_server = \WPDataAccess\Utilities\WPDA_Mail::get_option(); |
| @@ -236,14 +218,12 @@ | ||
| 236 | 218 | $this->loader->add_action( 'wp_ajax_wpda_widget_pub_add', WPDA_Widget_Publication::class, 'ajax_widget' ); |
| 237 | 219 | $this->loader->add_action( 'wp_ajax_wpda_widget_chart_add', WPDA_Widget_Google_Chart::class, 'ajax_widget' ); |
| 238 | 220 | $this->loader->add_action( 'wp_ajax_wpda_widget_chart_refresh', WPDA_Widget_Google_Chart::class, 'ajax_refresh' ); |
| 239 | 221 | // Add/remove favourites. |
| 222 | + // ??? | |
| 240 | 223 | $plugin_favourites = new WPDA_Favourites(); |
| 241 | 224 | $this->loader->add_action( 'admin_action_wpda_add_favourite', $plugin_favourites, 'add' ); |
| 242 | 225 | $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 | 226 | $plugin_dictionary_list = new WPDA_Dictionary_Lists(); |
| 247 | 227 | // Get tables for a specific database. |
| 248 | 228 | $this->loader->add_action( 'admin_action_wpda_get_tables', $plugin_dictionary_list, 'get_tables_ajax' ); |
| 249 | 229 | // Get columns for a specific table. |
| @@ -287,27 +267,24 @@ | ||
| 287 | 267 | 'wp_ajax_wpda_dbinit_admin', |
| 288 | 268 | function () { |
| 289 | 269 | if ( !isset( $_POST['wpnonce'], $_POST['wpdaschema_name'] ) ) { |
| 290 | 270 | WPDA::sent_header( 'application/json' ); |
| 291 | - echo WPDA::sent_msg( 'ERROR', 'Invalid arguments' ); | |
| 292 | - // phpcs:ignore WordPress.Security.EscapeOutput | |
| 271 | + WPDA::sent_msg( 'ERROR', 'Invalid arguments' ); | |
| 293 | 272 | wp_die(); |
| 294 | 273 | } |
| 274 | + // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotValidated | |
| 295 | 275 | $wpnonce = sanitize_text_field( wp_unslash( $_REQUEST['wpnonce'] ) ); |
| 296 | - // input var okay. | |
| 297 | 276 | if ( !WPDA::current_user_is_admin() || !wp_verify_nonce( $wpnonce, 'wpda_dbinit_admin_' . WPDA::get_current_user_login() ) ) { |
| 298 | 277 | WPDA::sent_header( 'application/json' ); |
| 299 | - echo WPDA::sent_msg( 'ERROR', 'Not authorized' ); | |
| 300 | - // phpcs:ignore WordPress.Security.EscapeOutput | |
| 278 | + WPDA::sent_msg( 'ERROR', 'Not authorized' ); | |
| 301 | 279 | wp_die(); |
| 302 | 280 | } |
| 303 | 281 | $wpdaschema_name = sanitize_text_field( wp_unslash( $_REQUEST['wpdaschema_name'] ) ); |
| 304 | - // input var okay. | |
| 282 | + // phpcs:enable WordPress.Security.ValidatedSanitizedInput.InputNotValidated | |
| 305 | 283 | $wpdadb = WPDADB::get_db_connection( $wpdaschema_name ); |
| 306 | 284 | if ( null === $wpdadb ) { |
| 307 | 285 | WPDA::sent_header( 'application/json' ); |
| 308 | - echo WPDA::sent_msg( 'ERROR', 'Cannot connect to database' ); | |
| 309 | - // phpcs:ignore WordPress.Security.EscapeOutput | |
| 286 | + WPDA::sent_msg( 'ERROR', 'Cannot connect to database' ); | |
| 310 | 287 | wp_die(); |
| 311 | 288 | } |
| 312 | 289 | $suppress_errors = $wpdadb->suppress_errors( true ); |
| 313 | 290 | $wpdadb->query( 'create function wpda_get_wp_user_id() returns integer deterministic no sql return @wpda_wp_user_id' ); |
| @@ -313,14 +290,12 @@ | ||
| 313 | 290 | $wpdadb->query( 'create function wpda_get_wp_user_id() returns integer deterministic no sql return @wpda_wp_user_id' ); |
| 314 | 291 | $error = $wpdadb->last_error; |
| 315 | 292 | $wpdadb->suppress_errors( $suppress_errors ); |
| 316 | 293 | if ( '' === $error ) { |
| 317 | - //phpcs:ignore - 8.1 proof | |
| 318 | - echo WPDA::sent_msg( 'OK', '' ); | |
| 319 | - // phpcs:ignore WordPress.Security.EscapeOutput | |
| 294 | + // phpcs:ignore -- 8.1 proof | |
| 295 | + WPDA::sent_msg( 'OK', '' ); | |
| 320 | 296 | } else { |
| 321 | - echo WPDA::sent_msg( 'ERROR', "Function not created [{$error}]" ); | |
| 322 | - // phpcs:ignore WordPress.Security.EscapeOutput | |
| 297 | + WPDA::sent_msg( 'ERROR', "Function not created [{$error}]" ); | |
| 323 | 298 | } |
| 324 | 299 | wp_die(); |
| 325 | 300 | }, |
| 326 | 301 | 10, |
| @@ -405,10 +380,11 @@ | ||
| 405 | 380 | * @return mixed|string |
| 406 | 381 | */ |
| 407 | 382 | public function add_id_to_script( $tag, $handle, $src ) { |
| 408 | 383 | if ( 'wpda_datatables' === $handle ) { |
| 384 | + // phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript | |
| 409 | 385 | $tag = '<script id="wpda_datatables" src="' . $src . '"></script>'; |
| 410 | - // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript | |
| 386 | + // phpcs:enable WordPress.WP.EnqueuedResources.NonEnqueuedScript | |
| 411 | 387 | } |
| 412 | 388 | return $tag; |
| 413 | 389 | } |
| 414 | 390 | |
| @@ -470,11 +446,49 @@ | ||
| 470 | 446 | * |
| 471 | 447 | * @since 1.0.0 |
| 472 | 448 | */ |
| 473 | 449 | public function run() { |
| 450 | + $this->loader->add_action( 'init', $this, 'register_blocks' ); | |
| 451 | + $this->loader->add_action( 'enqueue_block_assets', $this, 'enqueue_block_assets' ); | |
| 474 | 452 | $this->loader->run(); |
| 475 | 453 | } |
| 476 | 454 | |
| 455 | + public function register_blocks() { | |
| 456 | + register_block_type( plugin_dir_path( dirname( __FILE__ ) ) . 'assets/gtb', array( | |
| 457 | + 'render_callback' => array($this, 'render_wp_data_access_app_block'), | |
| 458 | + ) ); | |
| 459 | + } | |
| 460 | + | |
| 461 | + public function enqueue_block_assets() { | |
| 462 | + wp_enqueue_style( 'dashicons' ); | |
| 463 | + } | |
| 464 | + | |
| 465 | + public function render_wp_data_access_app_block( $attributes ) { | |
| 466 | + $appid = ( isset( $attributes['appid'] ) ? sanitize_text_field( $attributes['appid'] ) : '' ); | |
| 467 | + $feedback = filter_var( $attributes['feedback'] ?? false, FILTER_VALIDATE_BOOLEAN ); | |
| 468 | + $builders = filter_var( $attributes['builders'] ?? false, FILTER_VALIDATE_BOOLEAN ); | |
| 469 | + $hidetitlebar = filter_var( $attributes['hidetitlebar'] ?? false, FILTER_VALIDATE_BOOLEAN ); | |
| 470 | + $fullscreen = filter_var( $attributes['fullscreen'] ?? false, FILTER_VALIDATE_BOOLEAN ); | |
| 471 | + if ( empty( $appid ) ) { | |
| 472 | + return null; | |
| 473 | + } | |
| 474 | + if ( !shortcode_exists( 'wpda_app' ) ) { | |
| 475 | + return 'Shortcode wpda_app is not registered.'; | |
| 476 | + } | |
| 477 | + $shortcode = sprintf( | |
| 478 | + '[wpda_app app_id="%s" builders="%s" feedback="%s" hidetitlebar="%s" fullscreen="%s"]', | |
| 479 | + esc_attr( $appid ), | |
| 480 | + ( $builders ? 'false' : 'true' ), | |
| 481 | + ( $feedback ? 'true' : 'false' ), | |
| 482 | + ( $hidetitlebar ? 'true' : 'false' ), | |
| 483 | + ( $fullscreen ? 'true' : 'false' ) | |
| 484 | + ); | |
| 485 | + $wrapper_attributes = get_block_wrapper_attributes( array( | |
| 486 | + 'class' => 'wpda-wp-data-access-app', | |
| 487 | + ) ); | |
| 488 | + return sprintf( '<div %s>%s</div>', $wrapper_attributes, do_shortcode( $shortcode ) ); | |
| 489 | + } | |
| 490 | + | |
| 477 | 491 | /** |
| 478 | 492 | * Add plugin settings page |
| 479 | 493 | */ |
| 480 | 494 | public function wpdataaccess_register_settings_page() { |
| @@ -492,9 +506,8 @@ | ||
| 492 | 506 | */ |
| 493 | 507 | public function wpdataaccess_settings_page() { |
| 494 | 508 | WPDA_Dashboard::add_dashboard(); |
| 495 | 509 | $current_tab = ( isset( $_REQUEST['tab'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tab'] ) ) : 'plugin' ); |
| 496 | - // phpcs:ignore WordPress.Security.NonceVerification | |
| 497 | 510 | switch ( $current_tab ) { |
| 498 | 511 | case 'apps': |
| 499 | 512 | $wpda_settings_class_name = 'WPDA_Settings_Apps'; |
| 500 | 513 | break; |
| @@ -533,4 +546,6 @@ | ||
| 533 | 546 | $wpda_settings->show(); |
| 534 | 547 | } |
| 535 | 548 | |
| 536 | 549 | } |
| 550 | + | |
| 551 | +// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing | |