| @@ -5,24 +5,27 @@ | ||
| 5 | 5 | * |
| 6 | 6 | * @package plugin\admin |
| 7 | 7 | */ |
| 8 | 8 | use WPDataAccess\API\WPDA_API; |
| 9 | +use WPDataAccess\API\WPDA_API_Core; | |
| 9 | 10 | use WPDataAccess\Backup\WPDA_Data_Export; |
| 10 | 11 | use WPDataAccess\CSV_Files\WPDA_CSV_Import; |
| 11 | 12 | use WPDataAccess\Dashboard\WPDA_Dashboard; |
| 12 | -use WPDataAccess\Data_Apps\WPDA_Apps; | |
| 13 | -use WPDataAccess\Data_Apps\WPDA_Explorer_Container; | |
| 14 | -use WPDataAccess\Data_Apps\WPDA_Apps_List; | |
| 13 | +use WPDataAccess\Data_Apps\WPDA_App_Builder; | |
| 14 | +use WPDataAccess\Data_Apps\WPDA_Data_Explorer; | |
| 15 | +use WPDataAccess\Data_Apps\WPDA_Table_Container; | |
| 15 | 16 | use WPDataAccess\Global_Search\WPDA_Global_Search; |
| 16 | 17 | use WPDataAccess\List_Table\WPDA_List_View; |
| 18 | +use WPDataAccess\Plugin_Table_Models\WPDA_App_Model; | |
| 17 | 19 | use WPDataAccess\Plugin_Table_Models\WPDA_Design_Table_Model; |
| 18 | 20 | use WPDataAccess\Plugin_Table_Models\WPDA_Publisher_Model; |
| 19 | 21 | use WPDataAccess\Plugin_Table_Models\WPDA_User_Menus_Model; |
| 20 | 22 | use WPDataAccess\Premium\WPDAPRO_Data_Publisher\WPDAPRO_Data_Publisher_Manage_Styles; |
| 21 | -use WPDataAccess\Query_Builder\WPDA_Query_Builder; | |
| 22 | 23 | use WPDataAccess\Settings\WPDA_Settings; |
| 24 | +use WPDataAccess\Utilities\WPDA_Add_App_To_Menu; | |
| 23 | 25 | use WPDataAccess\Utilities\WPDA_Repository; |
| 24 | 26 | use WPDataAccess\WPDA; |
| 27 | +use WPDataAccess\WPDA_Navi\WPDA_Navi; | |
| 25 | 28 | use WPDataProjects\WPDP; |
| 26 | 29 | /** |
| 27 | 30 | * Class WP_Data_Access_Admin |
| 28 | 31 | * |
| @@ -30,8 +33,9 @@ | ||
| 30 | 33 | * |
| 31 | 34 | * @author Peter Schulz |
| 32 | 35 | * @since 1.0.0 |
| 33 | 36 | */ |
| 37 | +// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing -- verified on page | |
| 34 | 38 | class WP_Data_Access_Admin { |
| 35 | 39 | /** |
| 36 | 40 | * Menu slug for main page |
| 37 | 41 | */ |
| @@ -37,8 +41,13 @@ | ||
| 37 | 41 | */ |
| 38 | 42 | const PAGE_MAIN = 'wpda'; |
| 39 | 43 | |
| 40 | 44 | /** |
| 45 | + * Menu slug for navigator page | |
| 46 | + */ | |
| 47 | + const PAGE_NAVI = 'wpda_navi'; | |
| 48 | + | |
| 49 | + /** | |
| 41 | 50 | * Menu slug for apps page |
| 42 | 51 | */ |
| 43 | 52 | const PAGE_APPS = 'wpda_apps'; |
| 44 | 53 | |
| @@ -77,8 +86,15 @@ | ||
| 77 | 86 | */ |
| 78 | 87 | const PAGE_DESIGNER = 'wpda_designer'; |
| 79 | 88 | |
| 80 | 89 | /** |
| 90 | + * Plugin main page slug | |
| 91 | + */ | |
| 92 | + const MAIN_PAGE_SLUG = self::PAGE_NAVI; | |
| 93 | + | |
| 94 | + const PAGE_TABLE = 'wpda_table'; | |
| 95 | + | |
| 96 | + /** | |
| 81 | 97 | * Menu slug for my tables page |
| 82 | 98 | */ |
| 83 | 99 | const PAGE_MY_TABLES = 'wpda_my_tables'; |
| 84 | 100 | |
| @@ -88,8 +104,10 @@ | ||
| 88 | 104 | * @var string|false |
| 89 | 105 | */ |
| 90 | 106 | protected $wpda_data_explorer_menu; |
| 91 | 107 | |
| 108 | + protected $wpda_table; | |
| 109 | + | |
| 92 | 110 | /** |
| 93 | 111 | * Page hook suffix to Data Designer page or false |
| 94 | 112 | * |
| 95 | 113 | * @var string|false |
| @@ -186,14 +204,22 @@ | ||
| 186 | 204 | * @since 1.0.0 |
| 187 | 205 | */ |
| 188 | 206 | public function __construct() { |
| 189 | 207 | if ( isset( $_REQUEST['page'] ) ) { |
| 190 | - // phpcs:ignore WordPress.Security.NonceVerification | |
| 191 | 208 | $this->page = sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ); |
| 192 | - // phpcs:ignore WordPress.Security.NonceVerification | |
| 193 | 209 | } |
| 194 | 210 | } |
| 195 | 211 | |
| 212 | + private function load_app_css() { | |
| 213 | + // WPDataAccess apps CSS. | |
| 214 | + wp_register_style( | |
| 215 | + 'wpda_apps', | |
| 216 | + plugins_url( '../assets/css/wpda_apps.css', __FILE__ ), | |
| 217 | + array(), | |
| 218 | + WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) | |
| 219 | + ); | |
| 220 | + } | |
| 221 | + | |
| 196 | 222 | /** |
| 197 | 223 | * Add stylesheets to back-end |
| 198 | 224 | * |
| 199 | 225 | * The following stylesheets are added: |
| @@ -211,21 +237,34 @@ | ||
| 211 | 237 | */ |
| 212 | 238 | public function enqueue_styles() { |
| 213 | 239 | if ( !WPDA::is_plugin_page( $this->page ) ) { |
| 214 | 240 | // Admin styles are only added to plugin admin pages. |
| 241 | + // App pages still require the apps.css file. | |
| 242 | + $apps = WPDA_App_Model::add_to_dashboard_menu(); | |
| 243 | + $css_added = false; | |
| 244 | + for ($i = 0; $i < count( $apps ) && !$css_added; $i++) { | |
| 245 | + $settings = json_decode( $apps[$i]['app_settings'], true ); | |
| 246 | + if ( isset( $settings['settings']['app_menu_title'] ) && $this->page === $settings['settings']['app_menu_title'] ) { | |
| 247 | + $this->load_app_css(); | |
| 248 | + $css_added = true; | |
| 249 | + } | |
| 250 | + } | |
| 215 | 251 | return; |
| 216 | 252 | } |
| 253 | + if ( self::PAGE_NAVI === $this->page ) { | |
| 254 | + // WPDataAccess CSS. | |
| 255 | + wp_enqueue_style( | |
| 256 | + 'wpdanavi', | |
| 257 | + plugins_url( '../assets/css/wpda_navi.css', __FILE__ ), | |
| 258 | + array(), | |
| 259 | + WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) | |
| 260 | + ); | |
| 261 | + } | |
| 217 | 262 | wp_enqueue_style( 'wp-jquery-ui-core' ); |
| 218 | 263 | wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
| 219 | 264 | wp_enqueue_style( 'wp-jquery-ui-sortable' ); |
| 220 | 265 | wp_enqueue_style( 'wp-jquery-ui-tabs' ); |
| 221 | - // WPDataAccess apps CSS. | |
| 222 | - wp_register_style( | |
| 223 | - 'wpda_apps', | |
| 224 | - plugins_url( '../assets/css/wpda_apps.css', __FILE__ ), | |
| 225 | - array(), | |
| 226 | - WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) | |
| 227 | - ); | |
| 266 | + $this->load_app_css(); | |
| 228 | 267 | // WPDataAccess CSS. |
| 229 | 268 | wp_enqueue_style( |
| 230 | 269 | 'wpdataaccess', |
| 231 | 270 | plugins_url( '../assets/css/wpda_style.css', __FILE__ ), |
| @@ -266,9 +305,9 @@ | ||
| 266 | 305 | plugins_url( '../assets/css/responsive.dataTables.min.css', __FILE__ ), |
| 267 | 306 | array(), |
| 268 | 307 | WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) |
| 269 | 308 | ); |
| 270 | - if ( self::PAGE_MAIN === $this->page || self::PAGE_APPS === $this->page || self::PAGE_DASHBOARD === $this->page || self::PAGE_QUERY_BUILDER === $this->page || self::PAGE_PUBLISHER === $this->page || self::PAGE_CHARTS === $this->page ) { | |
| 309 | + if ( self::PAGE_MAIN === $this->page || self::PAGE_APPS === $this->page || self::PAGE_DASHBOARD === $this->page || self::PAGE_PUBLISHER === $this->page || self::PAGE_CHARTS === $this->page ) { | |
| 271 | 310 | // Load UI smoothness theme. |
| 272 | 311 | wp_enqueue_style( |
| 273 | 312 | 'wpda_ui_smoothness', |
| 274 | 313 | plugins_url( '../assets/css/jquery-ui.smoothness.min.css', __FILE__ ), |
| @@ -288,10 +327,10 @@ | ||
| 288 | 327 | if ( false !== $hide_button_icons && 'on' !== $hide_button_icons ) { |
| 289 | 328 | // SAVING SPACE - According to the plugin guidelines it is allowed to include external fonts: |
| 290 | 329 | // https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/#8-plugins-may-not-send-executable-code-via-third-party-systems . |
| 291 | 330 | // Load fontawesome icons. |
| 331 | + // phpcs:disable WordPress.WP.EnqueuedResourceParameters.MissingVersion | |
| 292 | 332 | wp_enqueue_style( |
| 293 | - // phpcs:ignore WordPress.WP.EnqueuedResourceParameters | |
| 294 | 333 | 'wpda_fontawesome_icons', |
| 295 | 334 | WPDA::CDN_FONTAWESOME . 'all.min.css', |
| 296 | 335 | array(), |
| 297 | 336 | null, |
| @@ -296,8 +335,9 @@ | ||
| 296 | 335 | array(), |
| 297 | 336 | null, |
| 298 | 337 | false |
| 299 | 338 | ); |
| 339 | + // phpcs:enable WordPress.WP.EnqueuedResourceParameters.MissingVersion | |
| 300 | 340 | } |
| 301 | 341 | if ( self::PAGE_PUBLISHER === $this->page ) { |
| 302 | 342 | wp_register_style( |
| 303 | 343 | 'wpda_datatables_default', |
| @@ -313,25 +353,10 @@ | ||
| 313 | 353 | WPDA::get_option( WPDA::OPTION_WPDA_VERSION ), |
| 314 | 354 | false |
| 315 | 355 | ); |
| 316 | 356 | } |
| 317 | - if ( self::PAGE_QUERY_BUILDER === $this->page ) { | |
| 318 | - // Add Query Builder resources. | |
| 357 | + if ( !WPDA::current_user_is_admin() ) { | |
| 319 | 358 | wp_enqueue_style( |
| 320 | - 'wpda_query_builder', | |
| 321 | - plugins_url( '../assets/css/wpda_query_builder.css', __FILE__ ), | |
| 322 | - array(), | |
| 323 | - WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) | |
| 324 | - ); | |
| 325 | - wp_enqueue_style( | |
| 326 | - 'wpda_jquery_json_viewer', | |
| 327 | - plugins_url( '../assets/css/jquery.json-viewer.css', __FILE__ ), | |
| 328 | - array(), | |
| 329 | - WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) | |
| 330 | - ); | |
| 331 | - } | |
| 332 | - if ( !current_user_can( 'manage_options' ) ) { | |
| 333 | - wp_enqueue_style( | |
| 334 | 359 | 'wpda_non_admin', |
| 335 | 360 | plugins_url( '../assets/css/wpda_non_admin.css', __FILE__ ), |
| 336 | 361 | array(), |
| 337 | 362 | WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) |
| @@ -490,46 +515,8 @@ | ||
| 490 | 515 | } |
| 491 | 516 | if ( self::PAGE_CHARTS === $this->page ) { |
| 492 | 517 | $this->load_google_charts(); |
| 493 | 518 | } |
| 494 | - if ( self::PAGE_QUERY_BUILDER === $this->page ) { | |
| 495 | - // Add Query Builder resources. | |
| 496 | - wp_enqueue_script( | |
| 497 | - 'wpda_query_builder', | |
| 498 | - plugins_url( '../assets/js/wpda_query_builder.js', __FILE__ ), | |
| 499 | - array(), | |
| 500 | - WPDA::get_option( WPDA::OPTION_WPDA_VERSION ), | |
| 501 | - false | |
| 502 | - ); | |
| 503 | - wp_enqueue_script( | |
| 504 | - 'wpda_jquery_xml2json', | |
| 505 | - plugins_url( '../assets/js/jquery.xml2json.js', __FILE__ ), | |
| 506 | - array(), | |
| 507 | - WPDA::get_option( WPDA::OPTION_WPDA_VERSION ), | |
| 508 | - false | |
| 509 | - ); | |
| 510 | - wp_enqueue_script( | |
| 511 | - 'wpda_jquery_json_viewer', | |
| 512 | - plugins_url( '../assets/js/jquery.json-viewer.js', __FILE__ ), | |
| 513 | - array(), | |
| 514 | - WPDA::get_option( WPDA::OPTION_WPDA_VERSION ), | |
| 515 | - false | |
| 516 | - ); | |
| 517 | - // Add codeEditor to query builder. | |
| 518 | - $cm_settings['codeEditor'] = wp_enqueue_code_editor( array( | |
| 519 | - 'type' => 'text/x-sql', | |
| 520 | - 'codemirror' => array( | |
| 521 | - 'mode' => 'sql', | |
| 522 | - 'lineNumbers' => true, | |
| 523 | - 'autoRefresh' => true, | |
| 524 | - 'lineWrapping' => true, | |
| 525 | - 'styleActiveLine' => true, | |
| 526 | - ), | |
| 527 | - ) ); | |
| 528 | - wp_enqueue_script( 'wp-theme-plugin-editor' ); | |
| 529 | - wp_localize_script( 'wp-theme-plugin-editor', 'cm_settings', $cm_settings ); | |
| 530 | - wp_enqueue_style( 'wp-codemirror' ); | |
| 531 | - } | |
| 532 | 519 | if ( self::PAGE_DASHBOARD === $this->page ) { |
| 533 | 520 | $this->load_google_charts(); |
| 534 | 521 | // Load DBMS panels. |
| 535 | 522 | wp_enqueue_script( |
| @@ -552,8 +539,9 @@ | ||
| 552 | 539 | * @return void |
| 553 | 540 | */ |
| 554 | 541 | private function load_google_charts() { |
| 555 | 542 | // Load Google Charts. |
| 543 | + // phpcs:disable WordPress.WP.EnqueuedResourceParameters | |
| 556 | 544 | wp_enqueue_script( |
| 557 | 545 | 'wpda_google_charts', |
| 558 | 546 | WPDA::GOOGLE_CHARTS, |
| 559 | 547 | array(), |
| @@ -559,8 +547,9 @@ | ||
| 559 | 547 | array(), |
| 560 | 548 | null, |
| 561 | 549 | false |
| 562 | 550 | ); |
| 551 | + // phpcs:enable WordPress.WP.EnqueuedResourceParameters | |
| 563 | 552 | wp_enqueue_script( |
| 564 | 553 | 'wpda_google_charts_fnc', |
| 565 | 554 | plugins_url( '../assets/js/wpda_google_charts.js', __FILE__ ), |
| 566 | 555 | array(), |
| @@ -598,9 +587,9 @@ | ||
| 598 | 587 | * |
| 599 | 588 | * @since 1.0.0 |
| 600 | 589 | */ |
| 601 | 590 | public function add_menu_items() { |
| 602 | - if ( current_user_can( 'manage_options' ) ) { | |
| 591 | + if ( WPDA::current_user_is_admin() ) { | |
| 603 | 592 | if ( 'on' === WPDA::get_option( WPDA::OPTION_PLUGIN_HIDE_ADMIN_MENU ) ) { |
| 604 | 593 | // Show Data Projects. |
| 605 | 594 | $this->add_data_projects(); |
| 606 | 595 | // Hide admin menu. |
| @@ -605,67 +594,66 @@ | ||
| 605 | 594 | $this->add_data_projects(); |
| 606 | 595 | // Hide admin menu. |
| 607 | 596 | return; |
| 608 | 597 | } |
| 609 | - if ( self::PAGE_MAIN === $this->page && isset( $_REQUEST['de'] ) ) { | |
| 610 | - if ( 'new' === $_REQUEST['de'] ) { | |
| 611 | - update_user_meta( WPDA::get_current_user_id(), 'wpda_data_explorer', 'new' ); | |
| 612 | - } | |
| 613 | - if ( 'old' === $_REQUEST['de'] ) { | |
| 614 | - delete_user_meta( WPDA::get_current_user_id(), 'wpda_data_explorer' ); | |
| 615 | - } | |
| 616 | - } | |
| 617 | - // Specific list tables (and forms) can be made available for specific capabilities: | |
| 618 | - // managed in method add_menu_my_tables. | |
| 619 | 598 | // Main menu and items are only available to admin users (set capability to 'manage_options'). |
| 620 | 599 | add_menu_page( |
| 621 | 600 | 'WP Data Access', |
| 622 | 601 | 'WP Data Access', |
| 623 | 602 | 'manage_options', |
| 624 | - self::PAGE_MAIN, | |
| 603 | + self::MAIN_PAGE_SLUG, | |
| 625 | 604 | null, |
| 626 | 605 | 'dashicons-database', |
| 627 | 606 | 999999999 |
| 628 | 607 | ); |
| 629 | - // Add data explorer to WPDA menu. | |
| 630 | - $current_data_explorer_version = get_user_meta( WPDA::get_current_user_id(), 'wpda_data_explorer', true ); | |
| 631 | - $this->wpda_data_explorer_menu = add_submenu_page( | |
| 632 | - self::PAGE_MAIN, | |
| 608 | + // Add navigator page to WPDA menu. | |
| 609 | + add_submenu_page( | |
| 610 | + self::MAIN_PAGE_SLUG, | |
| 633 | 611 | 'WP Data Access', |
| 634 | - 'Data Explorer', | |
| 612 | + 'Tool Guide', | |
| 635 | 613 | 'manage_options', |
| 636 | - self::PAGE_MAIN, | |
| 637 | - array($this, ( 'new' !== $current_data_explorer_version ? 'data_explorer_page' : 'data_explorer_page_new' )) | |
| 614 | + self::PAGE_NAVI, | |
| 615 | + array($this, 'data_navi') | |
| 638 | 616 | ); |
| 639 | - if ( self::PAGE_MAIN === $this->page ) { | |
| 640 | - if ( 'new' !== $current_data_explorer_version ) { | |
| 641 | - $args = array( | |
| 642 | - 'page_hook_suffix' => $this->wpda_data_explorer_menu, | |
| 643 | - ); | |
| 644 | - $this->wpda_data_explorer_view = new WPDA_List_View($args); | |
| 645 | - } | |
| 646 | - } | |
| 647 | 617 | // Add apps to menu. |
| 648 | 618 | add_submenu_page( |
| 649 | - self::PAGE_MAIN, | |
| 619 | + self::MAIN_PAGE_SLUG, | |
| 620 | + 'WP Data Access', | |
| 650 | 621 | 'App Builder', |
| 651 | - 'App Builder', | |
| 652 | 622 | 'manage_options', |
| 653 | 623 | self::PAGE_APPS, |
| 654 | 624 | array($this, 'data_apps') |
| 655 | 625 | ); |
| 656 | - // Add dashboard to menu. | |
| 657 | - add_submenu_page( | |
| 626 | + // Add data explorer to WPDA menu. | |
| 627 | + $this->wpda_data_explorer_menu = add_submenu_page( | |
| 628 | + self::MAIN_PAGE_SLUG, | |
| 629 | + 'WP Data Access', | |
| 630 | + 'Data Explorer', | |
| 631 | + 'manage_options', | |
| 658 | 632 | self::PAGE_MAIN, |
| 659 | - 'Dashboards', | |
| 660 | - 'Dashboards', | |
| 633 | + array($this, 'data_explorer_page') | |
| 634 | + ); | |
| 635 | + // Add data explorer to WPDA menu. | |
| 636 | + $this->wpda_table = add_submenu_page( | |
| 637 | + self::PAGE_TABLE, | |
| 638 | + 'WP Data Access', | |
| 639 | + 'Data Explorer', | |
| 661 | 640 | 'manage_options', |
| 662 | - self::PAGE_DASHBOARD, | |
| 663 | - array($this, 'data_dashboard_page') | |
| 641 | + self::PAGE_TABLE, | |
| 642 | + array($this, 'data_explorer_table_page') | |
| 664 | 643 | ); |
| 644 | + // Add submenu for Query Builder. | |
| 645 | + $this->wpda_data_publisher_menu = add_submenu_page( | |
| 646 | + self::MAIN_PAGE_SLUG, | |
| 647 | + 'WP Data Access', | |
| 648 | + 'SQL Query Builder', | |
| 649 | + 'manage_options', | |
| 650 | + self::PAGE_QUERY_BUILDER, | |
| 651 | + array($this, 'query_builder') | |
| 652 | + ); | |
| 665 | 653 | // Add submenu for Data Tables. |
| 666 | 654 | $this->wpda_data_publisher_menu = add_submenu_page( |
| 667 | - self::PAGE_MAIN, | |
| 655 | + self::MAIN_PAGE_SLUG, | |
| 668 | 656 | 'WP Data Access', |
| 669 | 657 | 'Table Builder', |
| 670 | 658 | 'manage_options', |
| 671 | 659 | self::PAGE_PUBLISHER, |
| @@ -679,13 +667,13 @@ | ||
| 679 | 667 | 'edit_form_class' => 'WPDataAccess\\Data_Publisher\\WPDA_Publisher_Form', |
| 680 | 668 | )); |
| 681 | 669 | } |
| 682 | 670 | // Add Data Projects menu. |
| 683 | - $wpdp = new WPDP(self::PAGE_MAIN); | |
| 671 | + $wpdp = new WPDP(self::MAIN_PAGE_SLUG); | |
| 684 | 672 | $wpdp->add_menu_items(); |
| 685 | 673 | // Add data designer to WPDA menu. |
| 686 | 674 | $this->wpda_data_designer_menu = add_submenu_page( |
| 687 | - self::PAGE_MAIN, | |
| 675 | + self::MAIN_PAGE_SLUG, | |
| 688 | 676 | 'WP Data Access', |
| 689 | 677 | 'Data Designer', |
| 690 | 678 | 'manage_options', |
| 691 | 679 | self::PAGE_DESIGNER, |
| @@ -705,17 +693,8 @@ | ||
| 705 | 693 | $this->grant_access_to_data_publications(); |
| 706 | 694 | } |
| 707 | 695 | $this->add_data_projects(); |
| 708 | 696 | $this->add_apps(); |
| 709 | - // Add submenu for Query Builder. | |
| 710 | - $this->wpda_data_publisher_menu = add_submenu_page( | |
| 711 | - self::PAGE_MAIN, | |
| 712 | - 'WP Data Access', | |
| 713 | - 'Query Builder', | |
| 714 | - 'manage_options', | |
| 715 | - self::PAGE_QUERY_BUILDER, | |
| 716 | - array($this, 'query_builder') | |
| 717 | - ); | |
| 718 | 697 | } |
| 719 | 698 | |
| 720 | 699 | /** |
| 721 | 700 | * Remove plugin sub menu items (when in dashboard mode) |
| @@ -723,19 +702,21 @@ | ||
| 723 | 702 | * @param mixed $submenu_file Dashboard menu items. |
| 724 | 703 | * @return mixed |
| 725 | 704 | */ |
| 726 | 705 | public function wpda_submenu_filter( $submenu_file ) { |
| 727 | - if ( current_user_can( 'manage_options' ) ) { | |
| 706 | + if ( WPDA::current_user_is_admin() ) { | |
| 728 | 707 | $hidden_submenus = array( |
| 729 | - // self::PAGE_APPS, | |
| 730 | 708 | self::PAGE_DASHBOARD, |
| 709 | + self::PAGE_CHARTS, | |
| 710 | + self::PAGE_PUBLISHER, | |
| 711 | + WPDP::PAGE_MAIN, | |
| 731 | 712 | self::PAGE_DESIGNER, |
| 732 | 713 | WPDP::PAGE_TEMPLATES, |
| 733 | - 'wpda-account', | |
| 734 | - 'wpda-wp-support-forum', | |
| 714 | + self::MAIN_PAGE_SLUG . '-account', | |
| 715 | + self::MAIN_PAGE_SLUG . '-wp-support-forum' | |
| 735 | 716 | ); |
| 736 | 717 | foreach ( $hidden_submenus as $submenu ) { |
| 737 | - remove_submenu_page( self::PAGE_MAIN, $submenu ); | |
| 718 | + remove_submenu_page( self::MAIN_PAGE_SLUG, $submenu ); | |
| 738 | 719 | } |
| 739 | 720 | } else { |
| 740 | 721 | global $submenu; |
| 741 | 722 | $submenu[self::PAGE_MAIN][0][2] = self::PAGE_DASHBOARD; |
| @@ -750,9 +731,9 @@ | ||
| 750 | 731 | * @return void |
| 751 | 732 | */ |
| 752 | 733 | protected function add_apps() { |
| 753 | 734 | // Add apps to dashbaord menu |
| 754 | - $apps = new WPDA_Apps(); | |
| 735 | + $apps = new WPDA_Add_App_To_Menu(); | |
| 755 | 736 | $apps->add_apps_to_menu(); |
| 756 | 737 | } |
| 757 | 738 | |
| 758 | 739 | /** |
| @@ -778,9 +759,9 @@ | ||
| 778 | 759 | // Cannot determine the user roles (not able to show menus). |
| 779 | 760 | return; |
| 780 | 761 | } |
| 781 | 762 | // Check dashboard role access. |
| 782 | - $dashboard_roles = get_option( \WPDataAccess\Settings\WPDA_Settings_Dashboard::DASHBOARD_ROLES ); | |
| 763 | + $dashboard_roles = get_option( \WPDataAccess\Settings\WPDA_Settings_Legacy_Dashboard::DASHBOARD_ROLES ); | |
| 783 | 764 | $user_has_role = false; |
| 784 | 765 | foreach ( $user_roles as $user_role ) { |
| 785 | 766 | if ( false !== strpos( $dashboard_roles, $user_role ) ) { |
| 786 | 767 | $user_has_role = true; |
| @@ -787,9 +768,9 @@ | ||
| 787 | 768 | break; |
| 788 | 769 | } |
| 789 | 770 | } |
| 790 | 771 | // Check dashboard user access. |
| 791 | - $dashboard_users = get_option( \WPDataAccess\Settings\WPDA_Settings_Dashboard::DASHBOARD_USERS ); | |
| 772 | + $dashboard_users = get_option( \WPDataAccess\Settings\WPDA_Settings_Legacy_Dashboard::DASHBOARD_USERS ); | |
| 792 | 773 | $user_has_access = false !== strpos( $dashboard_users, WPDA::get_current_user_login() ); |
| 793 | 774 | if ( !$user_has_role && !$user_has_access ) { |
| 794 | 775 | return; |
| 795 | 776 | } |
| @@ -862,56 +843,81 @@ | ||
| 862 | 843 | public function data_dashboard_page() { |
| 863 | 844 | WPDA_Dashboard::add_dashboard( true ); |
| 864 | 845 | } |
| 865 | 846 | |
| 866 | - /** | |
| 867 | - * Show data explorer main page | |
| 868 | - * | |
| 869 | - * Initialization of $this->wpda_data_explorer_view is done earlier in | |
| 870 | - * {@see WP_Data_Access_Admin::add_menu_items()} to support screen options. This method just shows the page | |
| 871 | - * containing the list table. | |
| 872 | - * | |
| 873 | - * @since 1.0.0 | |
| 874 | - * | |
| 875 | - * @see WP_Data_Access_Admin::add_menu_items() | |
| 876 | - */ | |
| 877 | 847 | public function data_explorer_page() { |
| 878 | 848 | WPDA_Dashboard::add_dashboard(); |
| 879 | 849 | if ( isset( $_REQUEST['page_action'] ) && 'wpda_backup' === $_REQUEST['page_action'] ) { |
| 880 | - // phpcs:ignore WordPress.Security.NonceVerification | |
| 881 | 850 | $this->backup_page(); |
| 882 | 851 | } elseif ( isset( $_REQUEST['page_action'] ) && 'wpda_import_csv' === $_REQUEST['page_action'] ) { |
| 883 | - // phpcs:ignore WordPress.Security.NonceVerification | |
| 884 | 852 | $this->import_csv(); |
| 885 | 853 | } elseif ( isset( $_REQUEST['page_action'] ) && 'wpda_global_search' === $_REQUEST['page_action'] ) { |
| 886 | - // phpcs:ignore WordPress.Security.NonceVerification | |
| 887 | 854 | $this->advanced_search(); |
| 888 | 855 | } else { |
| 889 | - $this->wpda_data_explorer_view->show(); | |
| 856 | + $explorer = new WPDA_Data_Explorer(); | |
| 857 | + $explorer->show(); | |
| 890 | 858 | } |
| 891 | 859 | } |
| 892 | 860 | |
| 893 | - public function data_explorer_page_new() { | |
| 861 | + public function data_explorer_table_page() { | |
| 894 | 862 | WPDA_Dashboard::add_dashboard(); |
| 895 | - if ( isset( $_REQUEST['page_action'] ) && 'wpda_backup' === $_REQUEST['page_action'] ) { | |
| 896 | - // phpcs:ignore WordPress.Security.NonceVerification | |
| 897 | - $this->backup_page(); | |
| 898 | - } elseif ( isset( $_REQUEST['page_action'] ) && 'wpda_import_csv' === $_REQUEST['page_action'] ) { | |
| 899 | - // phpcs:ignore WordPress.Security.NonceVerification | |
| 900 | - $this->import_csv(); | |
| 901 | - } elseif ( isset( $_REQUEST['page_action'] ) && 'wpda_global_search' === $_REQUEST['page_action'] ) { | |
| 902 | - // phpcs:ignore WordPress.Security.NonceVerification | |
| 903 | - $this->advanced_search(); | |
| 904 | - } else { | |
| 905 | - $explorer = new WPDA_Explorer_Container(); | |
| 906 | - $explorer->show(); | |
| 863 | + if ( !isset( | |
| 864 | + $_POST['dbs'], | |
| 865 | + $_POST['tbl'], | |
| 866 | + $_POST['s'], | |
| 867 | + $_POST['c'] | |
| 868 | + ) ) { | |
| 869 | + wp_die( esc_attr__( 'ERROR: Invalid usage', 'wp-data-access' ) ); | |
| 907 | 870 | } |
| 871 | + $dbs = WPDA_API_Core::sanitize_db_identifier( sanitize_text_field( wp_unslash( $_POST['dbs'] ) ) ); | |
| 872 | + $tbl = WPDA_API_Core::sanitize_db_identifier( sanitize_text_field( wp_unslash( $_POST['tbl'] ) ) ); | |
| 873 | + $s = WPDA_API_Core::sanitize_db_identifier( sanitize_text_field( wp_unslash( $_POST['s'] ) ) ); | |
| 874 | + $c = WPDA_API_Core::sanitize_db_identifier( sanitize_text_field( wp_unslash( $_POST['c'] ) ) ); | |
| 875 | + $explorer = new WPDA_Table_Container(array( | |
| 876 | + 'dbs' => $dbs, | |
| 877 | + 'tbl' => $tbl, | |
| 878 | + 's' => $s, | |
| 879 | + 'c' => $c, | |
| 880 | + )); | |
| 881 | + $explorer->show(); | |
| 908 | 882 | } |
| 909 | 883 | |
| 884 | + public function data_navi() { | |
| 885 | + if ( isset( $_POST['wpda-legacy-tool-status'] ) ) { | |
| 886 | + // Legacy tools update | |
| 887 | + $update_status = json_decode( sanitize_text_field( wp_unslash( $_POST['wpda-legacy-tool-status'] ) ), true ); | |
| 888 | + if ( null !== $update_status ) { | |
| 889 | + if ( isset( | |
| 890 | + $update_status['tables'], | |
| 891 | + $update_status['forms'], | |
| 892 | + $update_status['templates'], | |
| 893 | + $update_status['designer'], | |
| 894 | + $update_status['dashboards'], | |
| 895 | + $update_status['charts'] | |
| 896 | + ) ) { | |
| 897 | + // Get current legacy tool settings | |
| 898 | + $option_legacy_tools = \WPDataAccess\Utilities\WPDA_Legacy_Tool_Visibility::get(); | |
| 899 | + // Update legacy tool settings | |
| 900 | + $option_legacy_tools['tables'][0] = $update_status['tables']; | |
| 901 | + $option_legacy_tools['forms'][0] = $update_status['forms']; | |
| 902 | + $option_legacy_tools['templates'][0] = $update_status['templates']; | |
| 903 | + $option_legacy_tools['designer'][0] = $update_status['designer']; | |
| 904 | + $option_legacy_tools['dashboards'][0] = $update_status['dashboards']; | |
| 905 | + $option_legacy_tools['charts'][0] = $update_status['charts']; | |
| 906 | + // Save legacy tool settings | |
| 907 | + WPDA::set_option( WPDA::OPTION_PLUGIN_LEGACY_TOOLS, $option_legacy_tools ); | |
| 908 | + } | |
| 909 | + } | |
| 910 | + } | |
| 911 | + WPDA_Dashboard::add_dashboard(); | |
| 912 | + $navi = new WPDA_Navi(); | |
| 913 | + $navi->show(); | |
| 914 | + } | |
| 915 | + | |
| 910 | 916 | public function data_apps() { |
| 911 | 917 | WPDA_Dashboard::add_dashboard(); |
| 912 | - $wpda_apps_list = new WPDA_Apps_List(); | |
| 913 | - $wpda_apps_list->show(); | |
| 918 | + $wpda_app_builder = new WPDA_App_Builder(); | |
| 919 | + $wpda_app_builder->show(); | |
| 914 | 920 | } |
| 915 | 921 | |
| 916 | 922 | public function advanced_search() { |
| 917 | 923 | $advanced_search = new WPDA_Global_Search(); |
| @@ -924,9 +930,9 @@ | ||
| 924 | 930 | * @return void |
| 925 | 931 | */ |
| 926 | 932 | public function query_builder() { |
| 927 | 933 | WPDA_Dashboard::add_dashboard(); |
| 928 | - $query_builder = new WPDA_Query_Builder(); | |
| 934 | + $query_builder = new \WPDataAccess\Data_Apps\WPDA_Query_Builder(); | |
| 929 | 935 | $query_builder->show(); |
| 930 | 936 | } |
| 931 | 937 | |
| 932 | 938 | /** |
| @@ -970,9 +976,9 @@ | ||
| 970 | 976 | ?> |
| 971 | 977 | <div class="wrap"> |
| 972 | 978 | <h1 class="wp-heading-inline"> |
| 973 | 979 | <span>Data Designer</span> |
| 974 | - <a href="https://wpdataaccess.com/docs/data-designer/data-designer-getting-started/" target="_blank" class="wpda_tooltip" title="Plugin Help - opens in a new tab or window"> | |
| 980 | + <a href="https://docs.legacy.wpdataaccess.com/docs/data-designer-getting-started/" target="_blank" class="wpda_tooltip" title="Plugin Help - opens in a new tab or window"> | |
| 975 | 981 | <span class="dashicons dashicons-editor-help" style="text-decoration:none;vertical-align:top;font-size:30px;"> |
| 976 | 982 | </span> |
| 977 | 983 | </a> |
| 978 | 984 | </h1> |
| @@ -977,10 +983,9 @@ | ||
| 977 | 983 | </a> |
| 978 | 984 | </h1> |
| 979 | 985 | <p> |
| 980 | 986 | <?php |
| 981 | - echo __( 'ERROR: Repository table not found!', 'wp-data-access' ); | |
| 982 | - // phpcs:ignore WordPress.Security.EscapeOutput | |
| 987 | + esc_html_e( 'ERROR: Repository table not found!', 'wp-data-access' ); | |
| 983 | 988 | ?> |
| 984 | 989 | </p> |
| 985 | 990 | </div> |
| 986 | 991 | <?php |
| @@ -989,9 +994,9 @@ | ||
| 989 | 994 | /** |
| 990 | 995 | * Show Data Tables main page |
| 991 | 996 | */ |
| 992 | 997 | public function data_publisher_page() { |
| 993 | - if ( current_user_can( 'manage_options' ) ) { | |
| 998 | + if ( WPDA::current_user_is_admin() ) { | |
| 994 | 999 | WPDA_Dashboard::add_dashboard(); |
| 995 | 1000 | } |
| 996 | 1001 | $data_publisher_table_found = WPDA_Publisher_Model::table_exists(); |
| 997 | 1002 | if ( $data_publisher_table_found ) { |
| @@ -1017,9 +1022,9 @@ | ||
| 1017 | 1022 | /** |
| 1018 | 1023 | * Data Tables repository table not found |
| 1019 | 1024 | */ |
| 1020 | 1025 | public function data_publisher_page_not_found() { |
| 1021 | - if ( current_user_can( 'manage_options' ) ) { | |
| 1026 | + if ( WPDA::current_user_is_admin() ) { | |
| 1022 | 1027 | WPDA_Dashboard::add_dashboard(); |
| 1023 | 1028 | } |
| 1024 | 1029 | $wpda_repository = new WPDA_Repository(); |
| 1025 | 1030 | $wpda_repository->inform_user(); |
| @@ -1026,9 +1031,9 @@ | ||
| 1026 | 1031 | ?> |
| 1027 | 1032 | <div class="wrap"> |
| 1028 | 1033 | <h1 class="wp-heading-inline"> |
| 1029 | 1034 | <span>Data Tables</span> |
| 1030 | - <a href="https://wpdataaccess.com/docs/data-tables/data-tables-getting-started/" target="_blank" class="wpda_tooltip" title="Plugin Help - opens in a new tab or window"> | |
| 1035 | + <a href="https://docs.legacy.wpdataaccess.com/docs/data-tables-getting-started/" target="_blank" class="wpda_tooltip" title="Plugin Help - opens in a new tab or window"> | |
| 1031 | 1036 | <span class="dashicons dashicons-editor-help" style="text-decoration:none;vertical-align:top;font-size:30px;"> |
| 1032 | 1037 | </span> |
| 1033 | 1038 | </a> |
| 1034 | 1039 | </h1> |
| @@ -1033,10 +1038,9 @@ | ||
| 1033 | 1038 | </a> |
| 1034 | 1039 | </h1> |
| 1035 | 1040 | <p> |
| 1036 | 1041 | <?php |
| 1037 | - echo __( 'ERROR: Repository table not found!', 'wp-data-access' ); | |
| 1038 | - // phpcs:ignore WordPress.Security.EscapeOutput | |
| 1042 | + esc_html_e( 'ERROR: Repository table not found!', 'wp-data-access' ); | |
| 1039 | 1043 | ?> |
| 1040 | 1044 | </p> |
| 1041 | 1045 | </div> |
| 1042 | 1046 | <?php |
| @@ -1053,12 +1057,11 @@ | ||
| 1053 | 1057 | * @see WPDA_Data_Export::show_wp_cron() |
| 1054 | 1058 | */ |
| 1055 | 1059 | public function backup_page() { |
| 1056 | 1060 | $wpda_backup = new WPDA_Data_Export(); |
| 1057 | - if ( isset( $_REQUEST['action'] ) ) { | |
| 1058 | - // phpcs:ignore WordPress.Security.NonceVerification | |
| 1061 | + $wp_nonce = ( isset( $_REQUEST['wp_nonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['wp_nonce'] ) ) : '?' ); | |
| 1062 | + if ( isset( $_REQUEST['action'] ) && wp_verify_nonce( $wp_nonce, 'wpda-backup-' . WPDA::get_current_user_login() ) ) { | |
| 1059 | 1063 | $action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ); |
| 1060 | - // phpcs:ignore WordPress.Security.NonceVerification | |
| 1061 | 1064 | if ( 'new' === $action ) { |
| 1062 | 1065 | $wpda_backup->create_export( 'add' ); |
| 1063 | 1066 | } elseif ( 'add' === $action ) { |
| 1064 | 1067 | $wpda_backup->wpda_add_cron_job(); |
| @@ -1074,96 +1077,8 @@ | ||
| 1074 | 1077 | } |
| 1075 | 1078 | } |
| 1076 | 1079 | |
| 1077 | 1080 | /** |
| 1078 | - * Add user defined sub menu | |
| 1079 | - * | |
| 1080 | - * WPDA allows users to create sub menu for table lists and simple forms. Sub menus can be added to the WPDA | |
| 1081 | - * menu or any other (external) menu. A sub menu is added to an external menu via the menu slug. Sub menus are | |
| 1082 | - * taken from {@see WPDA_User_Menus_Model}. | |
| 1083 | - * | |
| 1084 | - * This method is called from the admin_menu action with a lower priority to make sure other menus are available. | |
| 1085 | - * User defined menu items are added to available menus in this method. These can be WPDA menus or external menus | |
| 1086 | - * as mentioned in the according list table and edit form. WPDA menus are added to menu WP Data Tables. External | |
| 1087 | - * menus are added to the menu having the menu slug defined by the user. | |
| 1088 | - * | |
| 1089 | - * This method does not actually show the list tables! It just creates the menu items. When the user clicks on such | |
| 1090 | - * a dynamically defined menu item, method {@see WP_Data_Access_Admin::my_tables_page()} is called, which takes | |
| 1091 | - * care of showing the list table. | |
| 1092 | - * | |
| 1093 | - * @since 1.0.0 | |
| 1094 | - * | |
| 1095 | - * @see WP_Data_Access_Admin::my_tables_page() | |
| 1096 | - * @see WPDA_User_Menus_Model | |
| 1097 | - */ | |
| 1098 | - public function add_menu_my_tables() { | |
| 1099 | - $menus_shown_to_current_user = array(); | |
| 1100 | - // Add list tables to external menus. | |
| 1101 | - foreach ( WPDA_User_Menus_Model::list_external_menus() as $menu ) { | |
| 1102 | - $user_roles = WPDA::get_current_user_roles(); | |
| 1103 | - $user_has_role = false; | |
| 1104 | - if ( '' === $menu->menu_role || null === $menu->menu_role ) { | |
| 1105 | - $user_has_role = in_array( 'administrator', $user_roles, true ); | |
| 1106 | - } else { | |
| 1107 | - $user_role_array = explode( ',', (string) $menu->menu_role ); | |
| 1108 | - //phpcs:ignore - 8.1 proof | |
| 1109 | - foreach ( $user_role_array as $user_role_array_item ) { | |
| 1110 | - $user_has_role = in_array( $user_role_array_item, $user_roles, true ); | |
| 1111 | - //phpcs:ignore - 8.1 proof | |
| 1112 | - if ( $user_has_role ) { | |
| 1113 | - break; | |
| 1114 | - } | |
| 1115 | - } | |
| 1116 | - } | |
| 1117 | - if ( $user_has_role ) { | |
| 1118 | - if ( !isset( $menus_shown_to_current_user[$menu->menu_slug . '/' . $menu->menu_name . '/' . $menu->menu_table_name . '/' . $menu->menu_schema_name] ) ) { | |
| 1119 | - $menu_slug = self::PAGE_EXPLORER . '_' . $menu->menu_table_name; | |
| 1120 | - $menu_index = $menu->menu_table_name; | |
| 1121 | - $this->create_non_admin_menu( $menu_slug ); | |
| 1122 | - $this->wpda_my_table_list_menu[$menu_index] = add_submenu_page( | |
| 1123 | - $this->first_page, | |
| 1124 | - 'WP Data Access : ' . strtoupper( $menu->menu_table_name ), | |
| 1125 | - $menu->menu_name, | |
| 1126 | - WPDA::get_current_user_capability(), | |
| 1127 | - $menu_slug, | |
| 1128 | - array($this, 'my_tables_page') | |
| 1129 | - ); | |
| 1130 | - $this->wpda_my_table_list_view[$menu_index] = new WPDA_List_View(array( | |
| 1131 | - 'page_hook_suffix' => $this->wpda_my_table_list_menu[$menu_index], | |
| 1132 | - 'wpdaschema_name' => $menu->menu_schema_name, | |
| 1133 | - 'table_name' => $menu->menu_table_name, | |
| 1134 | - )); | |
| 1135 | - $menus_shown_to_current_user[$menu->menu_slug . '/' . $menu->menu_name . '/' . $menu_index . '/' . $menu->menu_schema_name] = true; | |
| 1136 | - } | |
| 1137 | - } | |
| 1138 | - } | |
| 1139 | - } | |
| 1140 | - | |
| 1141 | - /** | |
| 1142 | - * Show user defined menus | |
| 1143 | - * | |
| 1144 | - * A user defined menu that are added to the plugin menu in {@see WP_Data_Access_Admin::add_menu_my_tables()} is | |
| 1145 | - * shown here. This method is called when the user clicks on the menu item generated in | |
| 1146 | - * {@see WP_Data_Access_Admin::add_menu_my_tables()}. | |
| 1147 | - * | |
| 1148 | - * @since 1.0.0 | |
| 1149 | - * | |
| 1150 | - * @see WP_Data_Access_Admin::add_menu_my_tables() | |
| 1151 | - */ | |
| 1152 | - public function my_tables_page() { | |
| 1153 | - // Grab table name from menu slug. | |
| 1154 | - if ( null !== $this->page ) { | |
| 1155 | - if ( strpos( $this->page, self::PAGE_EXPLORER ) !== false ) { | |
| 1156 | - $table = substr( $this->page, strlen( self::PAGE_EXPLORER . '_' ) ); | |
| 1157 | - } else { | |
| 1158 | - $table = substr( $this->page, strlen( self::PAGE_MY_TABLES . '_' ) ); | |
| 1159 | - } | |
| 1160 | - // Show list table. | |
| 1161 | - $this->wpda_my_table_list_view[$table]->show(); | |
| 1162 | - } | |
| 1163 | - } | |
| 1164 | - | |
| 1165 | - /** | |
| 1166 | 1081 | * Add main menu for non admin user |
| 1167 | 1082 | * |
| 1168 | 1083 | * @param string $first_page First plugin page. |
| 1169 | 1084 | * @return void |
| @@ -1185,4 +1100,6 @@ | ||
| 1185 | 1100 | } |
| 1186 | 1101 | } |
| 1187 | 1102 | |
| 1188 | 1103 | } |
| 1104 | + | |
| 1105 | +// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing | |