PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.84
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.84
5.5.84 5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 5.5.42 All 160 releases
← All changes | admin/class-wp-data-access-admin.php +39 -201 5.5.775.5.84 View file →
@@ -5,13 +5,15 @@
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 13 use WPDataAccess\Data_Apps\WPDA_App_Builder;
13 14 use WPDataAccess\Data_Apps\WPDA_Data_Explorer;
15 +use WPDataAccess\Data_Apps\WPDA_Table_Container;
14 16 use WPDataAccess\Global_Search\WPDA_Global_Search;
15 17 use WPDataAccess\List_Table\WPDA_List_View;
16 18 use WPDataAccess\Plugin_Table_Models\WPDA_App_Model;
17 19 use WPDataAccess\Plugin_Table_Models\WPDA_Design_Table_Model;
@@ -88,8 +90,10 @@
88 90 * Plugin main page slug
89 91 */
90 92 const MAIN_PAGE_SLUG = self::PAGE_NAVI;
91 93
94 + const PAGE_TABLE = 'wpda_table';
95 +
92 96 /**
93 97 * Menu slug for my tables page
94 98 */
95 99 const PAGE_MY_TABLES = 'wpda_my_tables';
@@ -100,8 +104,10 @@
100 104 * @var string|false
101 105 */
102 106 protected $wpda_data_explorer_menu;
103 107
108 + protected $wpda_table;
109 +
104 110 /**
105 111 * Page hook suffix to Data Designer page or false
106 112 *
107 113 * @var string|false
@@ -299,9 +305,9 @@
299 305 plugins_url( '../assets/css/responsive.dataTables.min.css', __FILE__ ),
300 306 array(),
301 307 WPDA::get_option( WPDA::OPTION_WPDA_VERSION )
302 308 );
303 - 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 ) {
304 310 // Load UI smoothness theme.
305 311 wp_enqueue_style(
306 312 'wpda_ui_smoothness',
307 313 plugins_url( '../assets/css/jquery-ui.smoothness.min.css', __FILE__ ),
@@ -347,23 +353,8 @@
347 353 WPDA::get_option( WPDA::OPTION_WPDA_VERSION ),
348 354 false
349 355 );
350 356 }
351 - if ( self::PAGE_QUERY_BUILDER === $this->page ) {
352 - // Add Query Builder resources.
353 - wp_enqueue_style(
354 - 'wpda_query_builder',
355 - plugins_url( '../assets/css/wpda_query_builder.css', __FILE__ ),
356 - array(),
357 - WPDA::get_option( WPDA::OPTION_WPDA_VERSION )
358 - );
359 - wp_enqueue_style(
360 - 'wpda_jquery_json_viewer',
361 - plugins_url( '../assets/css/jquery.json-viewer.css', __FILE__ ),
362 - array(),
363 - WPDA::get_option( WPDA::OPTION_WPDA_VERSION )
364 - );
365 - }
366 357 if ( !WPDA::current_user_is_admin() ) {
367 358 wp_enqueue_style(
368 359 'wpda_non_admin',
369 360 plugins_url( '../assets/css/wpda_non_admin.css', __FILE__ ),
@@ -524,46 +515,8 @@
524 515 }
525 516 if ( self::PAGE_CHARTS === $this->page ) {
526 517 $this->load_google_charts();
527 518 }
528 - if ( self::PAGE_QUERY_BUILDER === $this->page ) {
529 - // Add Query Builder resources.
530 - wp_enqueue_script(
531 - 'wpda_query_builder',
532 - plugins_url( '../assets/js/wpda_query_builder.js', __FILE__ ),
533 - array(),
534 - WPDA::get_option( WPDA::OPTION_WPDA_VERSION ),
535 - false
536 - );
537 - wp_enqueue_script(
538 - 'wpda_jquery_xml2json',
539 - plugins_url( '../assets/js/jquery.xml2json.js', __FILE__ ),
540 - array(),
541 - WPDA::get_option( WPDA::OPTION_WPDA_VERSION ),
542 - false
543 - );
544 - wp_enqueue_script(
545 - 'wpda_jquery_json_viewer',
546 - plugins_url( '../assets/js/jquery.json-viewer.js', __FILE__ ),
547 - array(),
548 - WPDA::get_option( WPDA::OPTION_WPDA_VERSION ),
549 - false
550 - );
551 - // Add codeEditor to query builder.
552 - $cm_settings['codeEditor'] = wp_enqueue_code_editor( array(
553 - 'type' => 'text/x-sql',
554 - 'codemirror' => array(
555 - 'mode' => 'sql',
556 - 'lineNumbers' => true,
557 - 'autoRefresh' => true,
558 - 'lineWrapping' => true,
559 - 'styleActiveLine' => true,
560 - ),
561 - ) );
562 - wp_enqueue_script( 'wp-theme-plugin-editor' );
563 - wp_localize_script( 'wp-theme-plugin-editor', 'cm_settings', $cm_settings );
564 - wp_enqueue_style( 'wp-codemirror' );
565 - }
566 519 if ( self::PAGE_DASHBOARD === $this->page ) {
567 520 $this->load_google_charts();
568 521 // Load DBMS panels.
569 522 wp_enqueue_script(
@@ -641,24 +594,8 @@
641 594 $this->add_data_projects();
642 595 // Hide admin menu.
643 596 return;
644 597 }
645 - if ( self::PAGE_MAIN === $this->page && isset( $_REQUEST['de'] ) ) {
646 - if ( 'new' === $_REQUEST['de'] ) {
647 - update_user_meta( WPDA::get_current_user_id(), 'wpda_data_explorer', 'new' );
648 - } elseif ( 'old' === $_REQUEST['de'] ) {
649 - update_user_meta( WPDA::get_current_user_id(), 'wpda_data_explorer', 'old' );
650 - }
651 - }
652 - if ( self::PAGE_QUERY_BUILDER === $this->page && isset( $_REQUEST['qb'] ) ) {
653 - if ( 'new' === $_REQUEST['qb'] ) {
654 - update_user_meta( WPDA::get_current_user_id(), 'wpda_query_builder_version', 'new' );
655 - } elseif ( 'old' === $_REQUEST['qb'] ) {
656 - update_user_meta( WPDA::get_current_user_id(), 'wpda_query_builder_version', 'old' );
657 - }
658 - }
659 - // Specific list tables (and forms) can be made available for specific capabilities:
660 - // managed in method add_menu_my_tables.
661 598 // Main menu and items are only available to admin users (set capability to 'manage_options').
662 599 add_menu_page(
663 600 'WP Data Access',
664 601 'WP Data Access',
@@ -686,12 +623,8 @@
686 623 self::PAGE_APPS,
687 624 array($this, 'data_apps')
688 625 );
689 626 // Add data explorer to WPDA menu.
690 - $current_data_explorer_version = get_user_meta( WPDA::get_current_user_id(), 'wpda_data_explorer', true );
691 - if ( isset( $_POST['explorer'] ) && 'OLD' === $_POST['explorer'] ) {
692 - $current_data_explorer_version = true;
693 - }
694 627 $this->wpda_data_explorer_menu = add_submenu_page(
695 628 self::MAIN_PAGE_SLUG,
696 629 'WP Data Access',
697 630 'Data Explorer',
@@ -696,20 +629,20 @@
696 629 'WP Data Access',
697 630 'Data Explorer',
698 631 'manage_options',
699 632 self::PAGE_MAIN,
700 - array($this, ( 'new' !== $current_data_explorer_version && '' !== $current_data_explorer_version ? 'data_explorer_page' : 'data_explorer_page_new' ))
633 + array($this, 'data_explorer_page')
701 634 );
702 - if ( self::PAGE_MAIN === $this->page ) {
703 - if ( 'new' !== $current_data_explorer_version && '' !== $current_data_explorer_version ) {
704 - $args = array(
705 - 'page_hook_suffix' => $this->wpda_data_explorer_menu,
706 - );
707 - $this->wpda_data_explorer_view = new WPDA_List_View($args);
708 - }
709 - }
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',
640 + 'manage_options',
641 + self::PAGE_TABLE,
642 + array($this, 'data_explorer_table_page')
643 + );
710 644 // Add submenu for Query Builder.
711 - $current_query_builder_version = get_user_meta( WPDA::get_current_user_id(), 'wpda_query_builder_version', true );
712 645 $this->wpda_data_publisher_menu = add_submenu_page(
713 646 self::MAIN_PAGE_SLUG,
714 647 'WP Data Access',
715 648 'SQL Query Builder',
@@ -714,9 +647,9 @@
714 647 'WP Data Access',
715 648 'SQL Query Builder',
716 649 'manage_options',
717 650 self::PAGE_QUERY_BUILDER,
718 - array($this, ( $current_query_builder_version === 'old' ? 'query_builder_old' : 'query_builder' ))
651 + array($this, 'query_builder')
719 652 );
720 653 // Add submenu for Data Tables.
721 654 $this->wpda_data_publisher_menu = add_submenu_page(
722 655 self::MAIN_PAGE_SLUG,
@@ -910,19 +843,8 @@
910 843 public function data_dashboard_page() {
911 844 WPDA_Dashboard::add_dashboard( true );
912 845 }
913 846
914 - /**
915 - * Show data explorer main page
916 - *
917 - * Initialization of $this->wpda_data_explorer_view is done earlier in
918 - * {@see WP_Data_Access_Admin::add_menu_items()} to support screen options. This method just shows the page
919 - * containing the list table.
920 - *
921 - * @since 1.0.0
922 - *
923 - * @see WP_Data_Access_Admin::add_menu_items()
924 - */
925 847 public function data_explorer_page() {
926 848 WPDA_Dashboard::add_dashboard();
927 849 if ( isset( $_REQUEST['page_action'] ) && 'wpda_backup' === $_REQUEST['page_action'] ) {
928 850 $this->backup_page();
@@ -930,24 +852,34 @@
930 852 $this->import_csv();
931 853 } elseif ( isset( $_REQUEST['page_action'] ) && 'wpda_global_search' === $_REQUEST['page_action'] ) {
932 854 $this->advanced_search();
933 855 } else {
934 - $this->wpda_data_explorer_view->show();
856 + $explorer = new WPDA_Data_Explorer();
857 + $explorer->show();
935 858 }
936 859 }
937 860
938 - public function data_explorer_page_new() {
861 + public function data_explorer_table_page() {
939 862 WPDA_Dashboard::add_dashboard();
940 - if ( isset( $_REQUEST['page_action'] ) && 'wpda_backup' === $_REQUEST['page_action'] ) {
941 - $this->backup_page();
942 - } elseif ( isset( $_REQUEST['page_action'] ) && 'wpda_import_csv' === $_REQUEST['page_action'] ) {
943 - $this->import_csv();
944 - } elseif ( isset( $_REQUEST['page_action'] ) && 'wpda_global_search' === $_REQUEST['page_action'] ) {
945 - $this->advanced_search();
946 - } else {
947 - $explorer = new WPDA_Data_Explorer();
948 - $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' ) );
949 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();
950 882 }
951 883
952 884 public function data_navi() {
953 885 if ( isset( $_POST['wpda-legacy-tool-status'] ) ) {
@@ -1002,14 +934,8 @@
1002 934 $query_builder = new \WPDataAccess\Data_Apps\WPDA_Query_Builder();
1003 935 $query_builder->show();
1004 936 }
1005 937
1006 - public function query_builder_old() {
1007 - WPDA_Dashboard::add_dashboard();
1008 - $query_builder = new \WPDataAccess\Query_Builder\WPDA_Query_Builder();
1009 - $query_builder->show();
1010 - }
1011 -
1012 938 /**
1013 939 * Add CSV page
1014 940 *
1015 941 * @return void
@@ -1147,96 +1073,8 @@
1147 1073 $wpda_backup->wpda_update_cron_job();
1148 1074 }
1149 1075 } else {
1150 1076 $wpda_backup->show_wp_cron();
1151 - }
1152 - }
1153 -
1154 - /**
1155 - * Add user defined sub menu
1156 - *
1157 - * WPDA allows users to create sub menu for table lists and simple forms. Sub menus can be added to the WPDA
1158 - * menu or any other (external) menu. A sub menu is added to an external menu via the menu slug. Sub menus are
1159 - * taken from {@see WPDA_User_Menus_Model}.
1160 - *
1161 - * This method is called from the admin_menu action with a lower priority to make sure other menus are available.
1162 - * User defined menu items are added to available menus in this method. These can be WPDA menus or external menus
1163 - * as mentioned in the according list table and edit form. WPDA menus are added to menu WP Data Tables. External
1164 - * menus are added to the menu having the menu slug defined by the user.
1165 - *
1166 - * This method does not actually show the list tables! It just creates the menu items. When the user clicks on such
1167 - * a dynamically defined menu item, method {@see WP_Data_Access_Admin::my_tables_page()} is called, which takes
1168 - * care of showing the list table.
1169 - *
1170 - * @since 1.0.0
1171 - *
1172 - * @see WP_Data_Access_Admin::my_tables_page()
1173 - * @see WPDA_User_Menus_Model
1174 - */
1175 - public function add_menu_my_tables() {
1176 - $menus_shown_to_current_user = array();
1177 - // Add list tables to external menus.
1178 - foreach ( WPDA_User_Menus_Model::list_external_menus() as $menu ) {
1179 - $user_roles = WPDA::get_current_user_roles();
1180 - $user_has_role = false;
1181 - if ( '' === $menu->menu_role || null === $menu->menu_role ) {
1182 - $user_has_role = in_array( 'administrator', $user_roles, true );
1183 - } else {
1184 - $user_role_array = explode( ',', (string) $menu->menu_role );
1185 - // phpcs:ignore -- 8.1 proof
1186 - foreach ( $user_role_array as $user_role_array_item ) {
1187 - $user_has_role = in_array( $user_role_array_item, $user_roles, true );
1188 - // phpcs:ignore -- 8.1 proof
1189 - if ( $user_has_role ) {
1190 - break;
1191 - }
1192 - }
1193 - }
1194 - if ( $user_has_role ) {
1195 - if ( !isset( $menus_shown_to_current_user[$menu->menu_slug . '/' . $menu->menu_name . '/' . $menu->menu_table_name . '/' . $menu->menu_schema_name] ) ) {
1196 - $menu_slug = self::PAGE_EXPLORER . '_' . $menu->menu_table_name;
1197 - $menu_index = $menu->menu_table_name;
1198 - $this->create_non_admin_menu( $menu_slug );
1199 - $this->wpda_my_table_list_menu[$menu_index] = add_submenu_page(
1200 - $this->first_page,
1201 - 'WP Data Access : ' . strtoupper( $menu->menu_table_name ),
1202 - $menu->menu_name,
1203 - WPDA::get_current_user_capability(),
1204 - $menu_slug,
1205 - array($this, 'my_tables_page')
1206 - );
1207 - $this->wpda_my_table_list_view[$menu_index] = new WPDA_List_View(array(
1208 - 'page_hook_suffix' => $this->wpda_my_table_list_menu[$menu_index],
1209 - 'wpdaschema_name' => $menu->menu_schema_name,
1210 - 'table_name' => $menu->menu_table_name,
1211 - ));
1212 - $menus_shown_to_current_user[$menu->menu_slug . '/' . $menu->menu_name . '/' . $menu_index . '/' . $menu->menu_schema_name] = true;
1213 - }
1214 - }
1215 - }
1216 - }
1217 -
1218 - /**
1219 - * Show user defined menus
1220 - *
1221 - * A user defined menu that are added to the plugin menu in {@see WP_Data_Access_Admin::add_menu_my_tables()} is
1222 - * shown here. This method is called when the user clicks on the menu item generated in
1223 - * {@see WP_Data_Access_Admin::add_menu_my_tables()}.
1224 - *
1225 - * @since 1.0.0
1226 - *
1227 - * @see WP_Data_Access_Admin::add_menu_my_tables()
1228 - */
1229 - public function my_tables_page() {
1230 - // Grab table name from menu slug.
1231 - if ( null !== $this->page ) {
1232 - if ( strpos( $this->page, self::PAGE_EXPLORER ) !== false ) {
1233 - $table = substr( $this->page, strlen( self::PAGE_EXPLORER . '_' ) );
1234 - } else {
1235 - $table = substr( $this->page, strlen( self::PAGE_MY_TABLES . '_' ) );
1236 - }
1237 - // Show list table.
1238 - $this->wpda_my_table_list_view[$table]->show();
1239 1077 }
1240 1078 }
1241 1079
1242 1080 /**