PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.85
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.85
5.5.85 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 All 161 releases
← All changes | public/class-wp-data-access-public.php +109 -206 5.5.73 → 5.5.85 View file →
@@ -19,8 +19,9 @@
19 19 *
20 20 * @author Peter Schulz
21 21 * @since 1.0.0
22 22 */
23 +// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing -- verified on page
23 24 class WP_Data_Access_Public {
24 25 /**
25 26 * Add stylesheets to front-end
26 27 *
@@ -110,10 +111,10 @@
110 111 );
111 112 // SAVING SPACE - According to the plugin guidelines it is allowed to include external fonts:
112 113 // https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/#8-plugins-may-not-send-executable-code-via-third-party-systems .
113 114 // Load fontawesome icons.
115 + // phpcs:disable WordPress.WP.EnqueuedResourceParameters.MissingVersion
114 116 wp_register_style(
115 - // phpcs:ignore WordPress.WP.EnqueuedResourceParameters
116 117 'wpda_fontawesome_icons',
117 118 WPDA::CDN_FONTAWESOME . 'all.min.css',
118 119 array(),
119 120 null,
@@ -254,10 +255,10 @@
254 255 *
255 256 * @since 1.0.0
256 257 */
257 258 public function register_shortcodes() {
259 + add_shortcode( 'wpda_app', array($this, 'wpda_app') );
258 260 add_shortcode( 'wpda_app_builder', array($this, 'wpda_app_builder') );
259 - add_shortcode( 'wpda_app', array($this, 'wpda_app') );
260 261 add_shortcode( 'wpda_data_explorer', array($this, 'wpda_data_explorer') );
261 262 add_shortcode( 'wpda_query_builder', array($this, 'wpda_query_builder') );
262 263 add_shortcode( 'wpdataaccess', array($this, 'wpdataaccess') );
263 264 add_shortcode( 'wpdadiehard', array($this, 'wpdadiehard') );
@@ -306,9 +307,8 @@
306 307 'feedback' => false,
307 308 'builders' => true,
308 309 'hidetitlebar' => false,
309 310 'fullscreen' => false,
310 - 'pwa' => false,
311 311 'filter_field_name' => null,
312 312 'filter_field_value' => null,
313 313 ), $atts );
314 314 $shortcode_params = array();
@@ -316,8 +316,10 @@
316 316 if ( !key_exists( $key, $wp_atts ) ) {
317 317 $shortcode_params[$key] = $value;
318 318 }
319 319 }
320 + $shortcode_params['pwa'] = false;
321 + // Shortcode not allowed to use parameter pwa
320 322 ob_start();
321 323 $app = new WPDataAccess\Data_Apps\WPDA_App_Container($wp_atts, $shortcode_params);
322 324 $app->show();
323 325 return ob_get_clean();
@@ -450,26 +452,14 @@
450 452 global $wpdb;
451 453 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
452 454 //phpcs:ignore - 8.1 proof
453 455 $wp_atts = shortcode_atts( array(
454 - 'project_id' => '',
455 - 'page_id' => '',
456 - 'schema_name' => $wpdb->dbname,
457 - 'table_name' => '',
458 - 'title' => '',
459 - 'subtitle' => '',
460 - 'bulk_actions_enabled' => false,
461 - 'search_box_enabled' => false,
462 - 'bulk_export_enabled' => false,
463 - 'show_view_link' => 'on',
464 - 'allow_insert' => 'off',
465 - 'allow_update' => 'off',
466 - 'allow_delete' => 'off',
467 - 'allow_import' => 'off',
456 + 'project_id' => '',
457 + 'page_id' => '',
468 458 ), $atts );
469 - if ( '' === $wp_atts['project_id'] && '' === $wp_atts['page_id'] && '' === $wp_atts['table_name'] ) {
470 - // Either a Data Project page (project_id and page_id) or a table name must be provided.
471 - return __( 'ERROR: Missing argument(s) [(project_id and page_id) or table_name]', 'wp-data-access' );
459 + if ( '' === $wp_atts['project_id'] && '' === $wp_atts['page_id'] ) {
460 + // Dashboard menu feature was removed. Parameter table_name no longer valid.
461 + return __( 'ERROR: Missing argument(s) [project_id and page_id]', 'wp-data-access' );
472 462 }
473 463 // Sanitize database values.
474 464 $wp_atts['project_id'] = sanitize_text_field( wp_unslash( $wp_atts['project_id'] ) );
475 465 // input var okay.
@@ -474,46 +464,8 @@
474 464 $wp_atts['project_id'] = sanitize_text_field( wp_unslash( $wp_atts['project_id'] ) );
475 465 // input var okay.
476 466 $wp_atts['page_id'] = sanitize_text_field( wp_unslash( $wp_atts['page_id'] ) );
477 467 // input var okay.
478 - $wp_atts['schema_name'] = sanitize_text_field( wp_unslash( $wp_atts['schema_name'] ) );
479 - // input var okay.
480 - $wp_atts['table_name'] = sanitize_text_field( wp_unslash( $wp_atts['table_name'] ) );
481 - // input var okay.
482 - // Set default parameter values.
483 - $bulk_actions_enabled = false;
484 - $search_box_enabled = false;
485 - $bulk_export_enabled = false;
486 - $show_view_link = 'on';
487 - $allow_insert = 'off';
488 - $allow_update = 'off';
489 - $allow_delete = 'off';
490 - $allow_import = 'off';
491 - // Check arguments.
492 - if ( 'true' === $wp_atts['bulk_actions_enabled'] ) {
493 - $bulk_actions_enabled = true;
494 - }
495 - if ( 'true' === $wp_atts['search_box_enabled'] ) {
496 - $search_box_enabled = true;
497 - }
498 - if ( 'true' === $wp_atts['bulk_export_enabled'] ) {
499 - $bulk_export_enabled = true;
500 - }
501 - if ( 'false' === $wp_atts['show_view_link'] ) {
502 - $show_view_link = 'off';
503 - }
504 - if ( 'true' === $wp_atts['allow_insert'] ) {
505 - $allow_insert = 'on';
506 - }
507 - if ( 'true' === $wp_atts['allow_update'] ) {
508 - $allow_update = 'on';
509 - }
510 - if ( 'true' === $wp_atts['allow_delete'] ) {
511 - $allow_delete = 'on';
512 - }
513 - if ( 'true' === $wp_atts['allow_import'] ) {
514 - $allow_import = 'on';
515 - }
516 468 $default_where = '';
517 469 if ( isset( $atts['filter_field_name'] ) && isset( $atts['filter_field_value'] ) ) {
518 470 $filter_field_name = str_replace( '`', '', sanitize_text_field( wp_unslash( $atts['filter_field_name'] ) ) );
519 471 // input var okay.
@@ -525,41 +477,15 @@
525 477 //phpcs:ignore - 8.1 proof
526 478 if ( count( $filter_field_name_array ) === count( $filter_field_value_array ) ) {
527 479 //phpcs:ignore - 8.1 proof
528 480 // Add filter to where clause.
481 + // phpcs:disable Generic.CodeAnalysis.ForLoopWithTestFunctionCall, Squiz.PHP.DisallowSizeFunctionsInLoops, WordPress.DB.PreparedSQLPlaceholders
529 482 for ($i = 0; $i < count( $filter_field_name_array ); $i++) {
530 - // phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall, Squiz.PHP.DisallowSizeFunctionsInLoops
531 - $default_where .= (( '' === $default_where ? '' : ' and ' )) . $wpdb->prepare(
532 - ' `%1s` like %s ',
533 - // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders
534 - array(WPDA::remove_backticks( $filter_field_name_array[$i] ), $filter_field_value_array[$i])
535 - );
483 + $default_where .= (( '' === $default_where ? '' : ' and ' )) . $wpdb->prepare( ' `%1s` like %s ', array(WPDA::remove_backticks( $filter_field_name_array[$i] ), $filter_field_value_array[$i]) );
536 484 }
485 + // phpcs:enable Generic.CodeAnalysis.ForLoopWithTestFunctionCall, Squiz.PHP.DisallowSizeFunctionsInLoops, WordPress.DB.PreparedSQLPlaceholders
537 486 }
538 487 }
539 - // Is this a Data Projects page or a table administration page?
540 - if ( '' !== $wp_atts['project_id'] && '' !== $wp_atts['page_id'] ) {
541 - // phpcs:ignore Generic.CodeAnalysis.EmptyStatement
542 - // Request for Data Projects page (check is performed in WPDP_List_Page).
543 - } else {
544 - // Request for table administration page.
545 - // Check schema name.
546 - if ( 'sys' === $wp_atts['schema_name'] || 'mysql' === $wp_atts['schema_name'] || 'information_schema' === $wp_atts['schema_name'] ) {
547 - // No access to MySQL databases (meta data)!
548 - return __( 'ERROR: No access to MySQL meta data', 'wp-data-access' );
549 - }
550 - // Check database table name.
551 - if ( '' === $wp_atts['table_name'] ) {
552 - // Table name must be provided! No database administration in the public area!
553 - return __( 'ERROR: Missing argument [table_name]', 'wp-data-access' );
554 - }
555 - // Check if table exists (to prevent sql injection) and access is granted.
556 - $wpda_dictionary_checks = new WPDA_Dictionary_Exist($wp_atts['schema_name'], $wp_atts['table_name']);
557 - if ( !$wpda_dictionary_checks->table_exists( true, false ) ) {
558 - // Table not found.
559 - return '<p>' . __( 'ERROR: Invalid table name or not authorized', 'wp-data-access' ) . '</p>';
560 - }
561 - }
562 488 // Make sure user has access to necessary (fake) classes and functions in the frontend.
563 489 require_once plugin_dir_path( __DIR__ ) . 'wp-data-access-diehard.php';
564 490 // Make sure all style and JS is available.
565 491 wp_enqueue_script( 'wpda_admin_scripts' );
@@ -586,134 +512,109 @@
586 512 do_action( 'wpda_wpdadiehard_prepare' );
587 513 ob_start();
588 514 // Set page argument to allow public access.
589 515 $_REQUEST['page'] = 'diehard';
590 - if ( '' !== $wp_atts['project_id'] && '' !== $wp_atts['page_id'] ) {
591 - // Show Data Projects page (check is performed in WPDP_List_Page).
592 - // Get page values.
593 - $project_page = $wpdb->get_results( $wpdb->prepare( "\n select * from {$wpdb->prefix}wpda_project_page\n where project_id = %d\n and page_id = %d\n \t", array($wp_atts['project_id'], $wp_atts['page_id']) ), 'ARRAY_A' );
594 - // db call ok; no-cache ok.
595 - if ( 0 === $wpdb->num_rows ) {
596 - // This should never happen as it was already tested before.
597 - return __( 'ERROR: Data Project page not found [need a valid project_id and page_id]', 'wp-data-access' );
598 - }
599 - if ( 'off' !== WPDA::get_option( WPDA::OPTION_WPDA_USE_ROLES_IN_SHORTCODE ) ) {
600 - // Check if user has role.
601 - $user_roles = WPDA::get_current_user_roles();
602 - if ( false === $user_roles ) {
603 - // Cannot determine the user role(s). Not able to show project menus.
604 - return __( 'ERROR: No access [could not determine user role]', 'wp-data-access' );
516 + // Show Data Projects page (check is performed in WPDP_List_Page).
517 + // Get page values.
518 + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- plugin table
519 + $project_page = $wpdb->get_results( $wpdb->prepare( "\n select * from {$wpdb->prefix}wpda_project_page\n where project_id = %d\n and page_id = %d\n \t", array($wp_atts['project_id'], $wp_atts['page_id']) ), 'ARRAY_A' );
520 + // db call ok; no-cache ok.
521 + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
522 + if ( 0 === $wpdb->num_rows ) {
523 + // This should never happen as it was already tested before.
524 + return __( 'ERROR: Data Project page not found [need a valid project_id and page_id]', 'wp-data-access' );
525 + }
526 + // Check if user has role.
527 + $user_roles = WPDA::get_current_user_roles();
528 + if ( false === $user_roles ) {
529 + // Cannot determine the user role(s). Not able to show project menus.
530 + return __( 'ERROR: No access [could not determine user role]', 'wp-data-access' );
531 + }
532 + $user_has_role = in_array( 'administrator', $user_roles, true );
533 + if ( !$user_has_role && '' !== $project_page[0]['page_role'] && null !== $project_page[0]['page_role'] ) {
534 + $user_role_array = explode( ',', $project_page[0]['page_role'] );
535 + foreach ( $user_role_array as $user_role_array_item ) {
536 + $user_has_role = in_array( $user_role_array_item, $user_roles, true );
537 + if ( $user_has_role ) {
538 + break;
605 539 }
606 - $user_has_role = false;
607 - if ( '' === $project_page[0]['page_role'] || null === $project_page[0]['page_role'] ) {
608 - $user_has_role = in_array( 'administrator', $user_roles, true );
609 - //phpcs:ignore - 8.1 proof
610 - } else {
611 - $user_role_array = explode( ',', $project_page[0]['page_role'] );
612 - //phpcs:ignore - 8.1 proof
613 - foreach ( $user_role_array as $user_role_array_item ) {
614 - $user_has_role = in_array( $user_role_array_item, $user_roles, true );
615 - //phpcs:ignore - 8.1 proof
616 - if ( $user_has_role ) {
617 - break;
618 - }
619 - }
620 - }
621 - if ( !$user_has_role ) {
622 - return __( 'ERROR: No access [missing role]', 'wp-data-access' );
623 - }
624 540 }
625 - // Determine plugin classes to be used.
626 - if ( 'static' === $project_page[0]['page_type'] ) {
627 - return '';
628 - } elseif ( 'table' === $project_page[0]['page_type'] ) {
629 - $list_view_class = 'WPDataProjects\\List_Table\\WPDP_List_View';
630 - $list_table_class = 'WPDataProjects\\List_Table\\WPDP_List_Table';
631 - $edit_form_class = 'WPDataProjects\\Simple_Form\\WPDP_Simple_Form';
541 + }
542 + if ( !$user_has_role ) {
543 + return __( 'ERROR: No access [missing role]', 'wp-data-access' );
544 + }
545 + // Determine plugin classes to be used.
546 + if ( 'static' === $project_page[0]['page_type'] ) {
547 + return '';
548 + } elseif ( 'table' === $project_page[0]['page_type'] ) {
549 + $list_view_class = 'WPDataProjects\\List_Table\\WPDP_List_View';
550 + $list_table_class = 'WPDataProjects\\List_Table\\WPDP_List_Table';
551 + $edit_form_class = 'WPDataProjects\\Simple_Form\\WPDP_Simple_Form';
552 + } else {
553 + $list_view_class = 'WPDataProjects\\Parent_Child\\WPDP_Parent_List_View';
554 + $list_table_class = 'WPDataProjects\\Parent_Child\\WPDP_Parent_List_Table';
555 + $edit_form_class = 'WPDataProjects\\Parent_Child\\WPDP_Parent_Form';
556 + }
557 + if ( null !== $project_page[0]['page_where'] && '' !== $project_page[0]['page_where'] ) {
558 + if ( 'where' === substr( str_replace( ' ', '', $project_page[0]['page_where'] ), 0, 5 ) ) {
559 + $where_clause = " {$project_page[0]['page_where']}";
632 560 } else {
633 - $list_view_class = 'WPDataProjects\\Parent_Child\\WPDP_Parent_List_View';
634 - $list_table_class = 'WPDataProjects\\Parent_Child\\WPDP_Parent_List_Table';
635 - $edit_form_class = 'WPDataProjects\\Parent_Child\\WPDP_Parent_Form';
561 + $where_clause = " where {$project_page[0]['page_where']} ";
636 562 }
637 - if ( null !== $project_page[0]['page_where'] && '' !== $project_page[0]['page_where'] ) {
638 - if ( 'where' === substr( str_replace( ' ', '', $project_page[0]['page_where'] ), 0, 5 ) ) {
639 - $where_clause = " {$project_page[0]['page_where']}";
640 - } else {
641 - $where_clause = " where {$project_page[0]['page_where']} ";
642 - }
643 - $where_clause = WPDA::substitute_environment_vars( $where_clause );
563 + $where_clause = WPDA::substitute_environment_vars( $where_clause );
564 + } else {
565 + $where_clause = '';
566 + }
567 + if ( '' === $default_where ) {
568 + $default_where = $where_clause;
569 + } else {
570 + if ( '' === $where_clause ) {
571 + $default_where = " where {$default_where} ";
644 572 } else {
645 - $where_clause = '';
573 + $default_where = " {$where_clause} and {$default_where} ";
646 574 }
647 - if ( '' === $default_where ) {
648 - $default_where = $where_clause;
649 - } else {
650 - if ( '' === $where_clause ) {
651 - $default_where = " where {$default_where} ";
652 - } else {
653 - $default_where = " {$where_clause} and {$default_where} ";
654 - }
655 - }
656 - $default_orderby = $project_page[0]['page_orderby'];
657 - // Prepare arguments.
658 - $args = array(
659 - 'page_hook_suffix' => 'WPDA_WPDP',
660 - 'wpdaschema_name' => $project_page[0]['page_schema_name'],
661 - 'table_name' => $project_page[0]['page_table_name'],
662 - 'list_table_class' => $list_table_class,
663 - 'edit_form_class' => $edit_form_class,
664 - 'project_id' => $wp_atts['project_id'],
665 - 'page_id' => $wp_atts['page_id'],
666 - 'default_where' => $default_where,
667 - 'where_clause' => $default_where,
668 - 'orderby_clause' => $default_orderby,
669 - );
670 - if ( 'view' === $project_page[0]['page_mode'] ) {
671 - $args['allow_update'] = 'off';
672 - $args['allow_import'] = 'off';
673 - }
674 - if ( 'no' === $project_page[0]['page_allow_insert'] ) {
675 - $args['allow_insert'] = 'off';
676 - $args['allow_import'] = 'off';
677 - }
678 - if ( 'no' === $project_page[0]['page_allow_delete'] ) {
679 - $args['allow_delete'] = 'off';
680 - }
681 - if ( 'only' === $project_page[0]['page_allow_insert'] ) {
682 - $args['action'] = 'new';
683 - $args['allow_insert'] = 'only';
684 - $args['allow_update'] = 'off';
685 - $args['allow_import'] = 'off';
686 - $args['allow_delete'] = 'off';
687 - }
688 - if ( 'no' === $project_page[0]['page_allow_import'] ) {
689 - $args['allow_import'] = 'off';
690 - }
691 - if ( 'no' === $project_page[0]['page_allow_bulk'] ) {
692 - $args['bulk_actions_enabled'] = false;
693 - }
694 - // Show page.
695 - $project_page_view = new $list_view_class($args);
696 - $project_page_view->show();
697 - } else {
698 - // Show table administration page.
699 - $media_manager = new WPDA_List_View(array(
700 - 'wpdaschema_name' => $wp_atts['schema_name'],
701 - 'table_name' => $wp_atts['table_name'],
702 - 'title' => $wp_atts['title'],
703 - 'subtitle' => $wp_atts['subtitle'],
704 - 'bulk_actions_enabled' => $bulk_actions_enabled,
705 - 'search_box_enabled' => $search_box_enabled,
706 - 'bulk_export_enabled' => $bulk_export_enabled,
707 - 'show_view_link' => $show_view_link,
708 - 'allow_insert' => $allow_insert,
709 - 'allow_update' => $allow_update,
710 - 'allow_delete' => $allow_delete,
711 - 'allow_import' => $allow_import,
712 - 'default_where' => $default_where,
713 - ));
714 - $media_manager->show();
715 575 }
576 + $default_orderby = $project_page[0]['page_orderby'];
577 + // Prepare arguments.
578 + $args = array(
579 + 'page_hook_suffix' => 'WPDA_WPDP',
580 + 'wpdaschema_name' => $project_page[0]['page_schema_name'],
581 + 'table_name' => $project_page[0]['page_table_name'],
582 + 'list_table_class' => $list_table_class,
583 + 'edit_form_class' => $edit_form_class,
584 + 'project_id' => $wp_atts['project_id'],
585 + 'page_id' => $wp_atts['page_id'],
586 + 'default_where' => $default_where,
587 + 'where_clause' => $default_where,
588 + 'orderby_clause' => $default_orderby,
589 + );
590 + if ( 'view' === $project_page[0]['page_mode'] ) {
591 + $args['allow_update'] = 'off';
592 + $args['allow_import'] = 'off';
593 + }
594 + if ( 'no' === $project_page[0]['page_allow_insert'] ) {
595 + $args['allow_insert'] = 'off';
596 + $args['allow_import'] = 'off';
597 + }
598 + if ( 'no' === $project_page[0]['page_allow_delete'] ) {
599 + $args['allow_delete'] = 'off';
600 + }
601 + if ( 'only' === $project_page[0]['page_allow_insert'] ) {
602 + $args['action'] = 'new';
603 + $args['allow_insert'] = 'only';
604 + $args['allow_update'] = 'off';
605 + $args['allow_import'] = 'off';
606 + $args['allow_delete'] = 'off';
607 + }
608 + if ( 'no' === $project_page[0]['page_allow_import'] ) {
609 + $args['allow_import'] = 'off';
610 + }
611 + if ( 'no' === $project_page[0]['page_allow_bulk'] ) {
612 + $args['bulk_actions_enabled'] = false;
613 + }
614 + // Show page.
615 + $project_page_view = new $list_view_class($args);
616 + $project_page_view->show();
716 617 ?>
717 618 <script type='text/javascript'>
718 619 // JS variable commonL10n is used in loaded scripts, copied from wp_default_scripts for responsive support
719 620 /* <![CDATA[ */
@@ -753,4 +654,6 @@
753 654 return ob_get_clean();
754 655 }
755 656
756 657 }
658 +
659 +// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing