| @@ -19,9 +19,9 @@ | ||
| 19 | 19 | * Class WPDA |
| 20 | 20 | * |
| 21 | 21 | * Plugin default values and settings are managed through this class. Every plugin option has a default value |
| 22 | 22 | * which is maintained in an array together with the option name. Options are only saved in $wpdb->options when |
| 23 | - * they are changed. Otherwise the default values are used. After reading option values from $wpdb->options the | |
| 23 | + * they are changed. Otherwise, the default values are used. After reading option values from $wpdb->options the | |
| 24 | 24 | * values are cached as many of them are used in multiple |
| 25 | 25 | * values are cached as many of them are used in multiple |
| 26 | 26 | * places during the processing of a request. |
| 27 | 27 | * |
| @@ -27,10 +27,12 @@ | ||
| 27 | 27 | * |
| 28 | 28 | * @author Peter Schulz |
| 29 | 29 | * @since 1.0.0 |
| 30 | 30 | */ |
| 31 | - class WPDA { | |
| 32 | 31 | |
| 32 | + // phpcs:disable PluginCheck.CodeAnalysis.Offloading.OffloadedContent | |
| 33 | + class WPDA { | |
| 34 | + | |
| 33 | 35 | // SAVING SPACE - According to the plugin guidelines it is allowed to include external fonts: |
| 34 | 36 | // https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/#8-plugins-may-not-send-executable-code-via-third-party-systems |
| 35 | 37 | const CDN_FONTAWESOME = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/'; |
| 36 | 38 | const GOOGLE_CHARTS = 'https://www.gstatic.com/charts/loader.js'; |
| @@ -50,10 +52,10 @@ | ||
| 50 | 52 | // Application options. |
| 51 | 53 | /** |
| 52 | 54 | * Option wpda_version and it's default value |
| 53 | 55 | */ |
| 54 | - const OPTION_WPDA_VERSION = array( 'wpda_version', '5.5.72' ); | |
| 55 | - const OPTION_WPDA_CLIENT_VERSION = array( 'wpda_client_version', '1.0.70' ); | |
| 56 | + const OPTION_WPDA_VERSION = array( 'wpda_version', '5.5.84' ); | |
| 57 | + const OPTION_WPDA_CLIENT_VERSION = array( 'wpda_client_version', '1.0.82' ); | |
| 56 | 58 | const OPTION_WPDA_UPGRADED = array( 'wpda_upgraded', false ); |
| 57 | 59 | /** |
| 58 | 60 | * Option wpda_setup_error and it's default value |
| 59 | 61 | */ |
| @@ -344,8 +346,9 @@ | ||
| 344 | 346 | WP_Data_Access_Admin::PAGE_PUBLISHER, |
| 345 | 347 | WP_Data_Access_Admin::PAGE_DESIGNER, |
| 346 | 348 | WP_Data_Access_Admin::PAGE_MY_TABLES, |
| 347 | 349 | WP_Data_Access_Admin::PAGE_CHARTS, |
| 350 | + WP_Data_Access_Admin::PAGE_TABLE, | |
| 348 | 351 | WPDP::PAGE_MAIN, |
| 349 | 352 | WPDP::PAGE_TEMPLATES, |
| 350 | 353 | ); |
| 351 | 354 | |
| @@ -354,9 +357,9 @@ | ||
| 354 | 357 | is_scalar( $page ) && |
| 355 | 358 | ( |
| 356 | 359 | 'wpda_wpdp_' === substr( $page, 0, 10 ) || |
| 357 | 360 | WP_Data_Access_Admin::PAGE_EXPLORER === substr( $page, 0, 13 ) || |
| 358 | - in_array( $page, self::$plugin_pages) //phpcs:ignore - 8.1 proof | |
| 361 | + in_array( $page, self::$plugin_pages) // phpcs:ignore -- 8.1 proof | |
| 359 | 362 | ) |
| 360 | 363 | ); |
| 361 | 364 | } |
| 362 | 365 | |
| @@ -429,9 +432,9 @@ | ||
| 429 | 432 | public static function clear_all_options() { |
| 430 | 433 | |
| 431 | 434 | global $wpdb; |
| 432 | 435 | |
| 433 | - $wpdb->query( | |
| 436 | + $wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 434 | 437 | " |
| 435 | 438 | DELETE FROM wp_options |
| 436 | 439 | WHERE option_name LIKE 'wpda_%' |
| 437 | 440 | " |
| @@ -447,9 +450,9 @@ | ||
| 447 | 450 | * @since 1.1.0 |
| 448 | 451 | */ |
| 449 | 452 | public static function load_wp_tables() { |
| 450 | 453 | |
| 451 | - if ( 0 === count( self::$wp_tables ) ) {//phpcs:ignore - 8.1 proof | |
| 454 | + if ( 0 === count( self::$wp_tables ) ) { // phpcs:ignore -- 8.1 proof | |
| 452 | 455 | try { |
| 453 | 456 | global $wpdb; |
| 454 | 457 | |
| 455 | 458 | if ( ! is_multisite() ) { |
| @@ -457,11 +460,11 @@ | ||
| 457 | 460 | self::$wp_tables[ $table ] = $table; |
| 458 | 461 | } |
| 459 | 462 | } else { |
| 460 | 463 | $query = "select blog_id from {$wpdb->blogs}"; |
| 461 | - $blogs = $wpdb->get_results( $query, 'ARRAY_N' ); | |
| 464 | + $blogs = $wpdb->get_results( $query, 'ARRAY_N' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 462 | 465 | foreach ( $blogs as $blog ) { |
| 463 | - foreach ( $wpdb->tables( $blog === reset( $blogs ) ? 'all' : 'blog', true, $blog[0] ) as $table ) {//phpcs:ignore - 8.1 proof | |
| 466 | + foreach ( $wpdb->tables( $blog === reset( $blogs ) ? 'all' : 'blog', true, $blog[0] ) as $table ) { // phpcs:ignore -- 8.1 proof | |
| 464 | 467 | self::$wp_tables[ $table ] = $table; |
| 465 | 468 | } |
| 466 | 469 | } |
| 467 | 470 | } |
| @@ -467,12 +470,14 @@ | ||
| 467 | 470 | } |
| 468 | 471 | |
| 469 | 472 | return true; |
| 470 | 473 | } catch ( \Exception $e ) { |
| 471 | - wp_die( 'ERROR: ' . $e->getMessage() ); | |
| 474 | + wp_die( esc_attr( 'ERROR: ' . $e->getMessage() ) ); | |
| 472 | 475 | } |
| 473 | 476 | } |
| 474 | 477 | |
| 478 | + return false; | |
| 479 | + | |
| 475 | 480 | } |
| 476 | 481 | |
| 477 | 482 | /** |
| 478 | 483 | * Checks if a table is a WordPress table |
| @@ -486,9 +491,9 @@ | ||
| 486 | 491 | public static function is_wp_table( $table_name ) { |
| 487 | 492 | |
| 488 | 493 | self::load_wp_tables(); |
| 489 | 494 | |
| 490 | - if ( 0 === count( self::$wp_tables ) ) {//phpcs:ignore - 8.1 proof | |
| 495 | + if ( 0 === count( self::$wp_tables ) ) { // phpcs:ignore -- 8.1 proof | |
| 491 | 496 | return false; |
| 492 | 497 | } |
| 493 | 498 | |
| 494 | 499 | return isset( self::$wp_tables[ $table_name ] ); |
| @@ -505,10 +510,10 @@ | ||
| 505 | 510 | public static function get_wp_tables() { |
| 506 | 511 | |
| 507 | 512 | self::load_wp_tables(); |
| 508 | 513 | |
| 509 | - if ( 0 === count( self::$wp_tables ) ) {//phpcs:ignore - 8.1 proof | |
| 510 | - wp_die( __( 'ERROR: No WordPress table found', 'wp-data-access' ) ); | |
| 514 | + if ( 0 === count( self::$wp_tables ) ) { // phpcs:ignore -- 8.1 proof | |
| 515 | + wp_die( esc_attr__( 'ERROR: No WordPress table found', 'wp-data-access' ) ); | |
| 511 | 516 | } |
| 512 | 517 | |
| 513 | 518 | return self::$wp_tables; |
| 514 | 519 | |
| @@ -542,9 +547,9 @@ | ||
| 542 | 547 | * |
| 543 | 548 | * @return bool |
| 544 | 549 | */ |
| 545 | 550 | public static function column_is_schema_name( $table_name, $column_name ) { |
| 546 | - if ( 0 === count( self::$wpda_tables ) ) {//phpcs:ignore - 8.1 proof | |
| 551 | + if ( 0 === count( self::$wpda_tables ) ) { // phpcs:ignore -- 8.1 proof | |
| 547 | 552 | // Cache schema names |
| 548 | 553 | global $wpdb; |
| 549 | 554 | self::$wpda_tables[$wpdb->prefix . 'wpda_media.media_schema_name' ] = true; |
| 550 | 555 | self::$wpda_tables[$wpdb->prefix . 'wpda_project_page.page_schema_name' ] = true; |
| @@ -722,13 +727,13 @@ | ||
| 722 | 727 | * |
| 723 | 728 | * @return array |
| 724 | 729 | */ |
| 725 | 730 | public static function array_insert_after( $array, $key, $new ) { |
| 726 | - $keys = array_keys( (array) $array ); //phpcs:ignore - 8.1 proof | |
| 727 | - $index = array_search( $key, $keys ); //phpcs:ignore - 8.1 proof | |
| 728 | - $pos = false === $index ? count( $array ) : $index + 1; //phpcs:ignore - 8.1 proof | |
| 731 | + $keys = array_keys( (array) $array ); // phpcs:ignore -- 8.1 proof | |
| 732 | + $index = array_search( $key, $keys ); // phpcs:ignore -- 8.1 proof | |
| 733 | + $pos = false === $index ? count( $array ) : $index + 1; // phpcs:ignore -- 8.1 proof | |
| 729 | 734 | |
| 730 | - return array_merge( array_slice( $array, 0, $pos ), $new, array_slice( $array, $pos ) ); //phpcs:ignore - 8.1 proof | |
| 735 | + return array_merge( array_slice( $array, 0, $pos ), $new, array_slice( $array, $pos ) ); // phpcs:ignore -- 8.1 proof | |
| 731 | 736 | } |
| 732 | 737 | |
| 733 | 738 | /** |
| 734 | 739 | * Log a message in the database |
| @@ -754,9 +759,9 @@ | ||
| 754 | 759 | , $log_id |
| 755 | 760 | , $log_type |
| 756 | 761 | , $log_msg |
| 757 | 762 | ); |
| 758 | - $wpdb->query( $sql ); | |
| 763 | + $wpdb->query( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 759 | 764 | |
| 760 | 765 | } |
| 761 | 766 | |
| 762 | 767 | /** |
| @@ -790,9 +795,9 @@ | ||
| 790 | 795 | if ( is_user_logged_in() ) { |
| 791 | 796 | $user = wp_get_current_user(); |
| 792 | 797 | $allcaps = array(); |
| 793 | 798 | foreach ( $user->allcaps as $key => $val ) { |
| 794 | - array_push( $allcaps, $key );//phpcs:ignore - 8.1 proof | |
| 799 | + array_push( $allcaps, $key ); // phpcs:ignore -- 8.1 proof | |
| 795 | 800 | } |
| 796 | 801 | |
| 797 | 802 | return $allcaps[0]; |
| 798 | 803 | } else { |
| @@ -818,8 +823,9 @@ | ||
| 818 | 823 | } else if ( $matches[2] == 'K' ) { |
| 819 | 824 | return $matches[1] * 1024; |
| 820 | 825 | } |
| 821 | 826 | } |
| 827 | + return ''; | |
| 822 | 828 | } |
| 823 | 829 | |
| 824 | 830 | public static function get_current_user_id() { |
| 825 | 831 | global $current_user; |
| @@ -925,9 +931,9 @@ | ||
| 925 | 931 | * $columns['column_default'] => information_schema.tables.column_default |
| 926 | 932 | * |
| 927 | 933 | * @param string $schema_name Schema name (optional) |
| 928 | 934 | * @param string $table_name Table name (optional) |
| 929 | - * @param string $columns Array containing table columns | |
| 935 | + * @param array $columns Array containing table columns | |
| 930 | 936 | * @param string $search Search string entered by user |
| 931 | 937 | * @param boolean $is_case_sensitive Case-sensitive search (default = false) |
| 932 | 938 | * @param boolean $is_dt_request Always skip filter for DataTable requests (default = false) |
| 933 | 939 | * |
| @@ -985,22 +991,22 @@ | ||
| 985 | 991 | $where_columns = array(); |
| 986 | 992 | |
| 987 | 993 | foreach ( $columns as $column ) { |
| 988 | 994 | if ( 'string' === WPDA::get_type( $column['data_type'] ) ) { |
| 989 | - $where_columns[] = $wpdb->prepare( "`" . str_replace( '`', '', $column['column_name'] ) . "` like {$case_sensitive} '%s'", '%' . esc_sql( $search ) . '%' ); // phpcs:ignore Standard.Category.SniffName.ErrorCode | |
| 995 | + $where_columns[] = $wpdb->prepare( "`" . str_replace( '`', '', $column['column_name'] ) . "` like {$case_sensitive} '%s'", '%' . esc_sql( $search ) . '%' ); // phpcs:ignore | |
| 990 | 996 | } |
| 991 | 997 | |
| 992 | 998 | if ( $is_dt_request ) { |
| 993 | 999 | // Handle numeric and date queries for DataTables. |
| 994 | 1000 | if ( 'number' === WPDA::get_type( $column['data_type'] ) && ( is_numeric( $search ) ) ) { |
| 995 | - $where_columns[] = $wpdb->prepare( "`" . str_replace( '`', '', $column['column_name'] ) . "` = '%s'", esc_sql( $search ) ); // phpcs:ignore Standard.Category.SniffName.ErrorCode | |
| 1001 | + $where_columns[] = $wpdb->prepare( "`" . str_replace( '`', '', $column['column_name'] ) . "` = '%s'", esc_sql( $search ) ); // phpcs:ignore | |
| 996 | 1002 | } elseif ( 'date' === WPDA::get_type( $column['data_type'] ) ) { |
| 997 | - $where_columns[] = $wpdb->prepare( "`" . str_replace( '`', '', $column['column_name'] ) . "` like '%s'", esc_sql( $search ) . '%' ); // phpcs:ignore Standard.Category.SniffName.ErrorCode | |
| 1003 | + $where_columns[] = $wpdb->prepare( "`" . str_replace( '`', '', $column['column_name'] ) . "` like '%s'", esc_sql( $search ) . '%' ); // phpcs:ignore | |
| 998 | 1004 | } |
| 999 | 1005 | } |
| 1000 | 1006 | } |
| 1001 | 1007 | |
| 1002 | - if ( 0 === count( $where_columns ) ) {//phpcs:ignore - 8.1 proof | |
| 1008 | + if ( 0 === count( $where_columns ) ) { // phpcs:ignore -- 8.1 proof | |
| 1003 | 1009 | return '' === $where_search_args ? ' (1=2) ' : $where_search_args; |
| 1004 | 1010 | } |
| 1005 | 1011 | |
| 1006 | 1012 | if ( '' === $where_search_args ) { |
| @@ -1014,11 +1020,11 @@ | ||
| 1014 | 1020 | $where_columns = array(); |
| 1015 | 1021 | |
| 1016 | 1022 | if ( is_array( $columns ) ) { |
| 1017 | 1023 | global $wpdb; |
| 1018 | - $request = array_change_key_case( $_REQUEST ); //phpcs:ignore - 8.1 proof | |
| 1024 | + $request = array_change_key_case( $_REQUEST ); // phpcs:ignore -- 8.1 proof | |
| 1019 | 1025 | foreach ( $columns as $column ) { |
| 1020 | - $column_name = str_replace( '`', '', $column['column_name'] ); | |
| 1026 | + $column_name = str_replace( '`', '', $column['column_name'] ?? '' ); | |
| 1021 | 1027 | $column_name_lwr = strtolower( $column_name ); |
| 1022 | 1028 | if ( isset( $request["wpda_search_column_{$column_name_lwr}"] ) ) { |
| 1023 | 1029 | if ( is_array( $request["wpda_search_column_{$column_name_lwr}"] ) ) { |
| 1024 | 1030 | // Handle multiple values for same column with OR |
| @@ -1027,16 +1033,16 @@ | ||
| 1027 | 1033 | $column_date_type = $column['data_type']; |
| 1028 | 1034 | $column_value = wp_strip_all_tags( wp_unslash( $value ) ); // input var okay. |
| 1029 | 1035 | if ( '' !== $column_value ) { |
| 1030 | 1036 | if ( 'string' === WPDA::get_type( $column_date_type ) ) { |
| 1031 | - $where_columns_arr[] = $wpdb->prepare( "`{$column_name}` like '%s'", esc_sql( $column_value ) ); // phpcs:ignore Standard.Category.SniffName.ErrorCode | |
| 1037 | + $where_columns_arr[] = $wpdb->prepare( "`{$column_name}` like '%s'", esc_sql( $column_value ) ); // phpcs:ignore | |
| 1032 | 1038 | } elseif ( 'number' === WPDA::get_type( $column_date_type ) ) { |
| 1033 | - $where_columns_arr[] = $wpdb->prepare( "`{$column_name}` = '%d'", esc_sql( $column_value ) ); // phpcs:ignore Standard.Category.SniffName.ErrorCode | |
| 1039 | + $where_columns_arr[] = $wpdb->prepare( "`{$column_name}` = '%d'", esc_sql( $column_value ) ); // phpcs:ignore | |
| 1034 | 1040 | } |
| 1035 | 1041 | } |
| 1036 | 1042 | } |
| 1037 | - if ( count( $where_columns_arr ) > 0 ) {//phpcs:ignore - 8.1 proof | |
| 1038 | - $where_columns[] = ' (' . implode( ' or ', $where_columns_arr ) . ') ';//phpcs:ignore - 8.1 proof | |
| 1043 | + if ( count( $where_columns_arr ) > 0 ) { // phpcs:ignore -- 8.1 proof | |
| 1044 | + $where_columns[] = ' (' . implode( ' or ', $where_columns_arr ) . ') '; // phpcs:ignore -- 8.1 proof | |
| 1039 | 1045 | } |
| 1040 | 1046 | } else { |
| 1041 | 1047 | // Handle single value |
| 1042 | 1048 | $column_date_type = $column['data_type']; |
| @@ -1042,11 +1048,11 @@ | ||
| 1042 | 1048 | $column_date_type = $column['data_type']; |
| 1043 | 1049 | $column_value = wp_strip_all_tags( wp_unslash( $request[ "wpda_search_column_{$column_name_lwr}" ] ) ); |
| 1044 | 1050 | if ( '' !== $column_value ) { |
| 1045 | 1051 | if ( 'string' === WPDA::get_type( $column_date_type ) ) { |
| 1046 | - $where_columns[] = $wpdb->prepare( "`{$column_name}` like '%s'", esc_sql( $column_value ) ); // phpcs:ignore Standard.Category.SniffName.ErrorCode | |
| 1052 | + $where_columns[] = $wpdb->prepare( "`{$column_name}` like '%s'", esc_sql( $column_value ) ); // phpcs:ignore | |
| 1047 | 1053 | } elseif ( 'number' === WPDA::get_type( $column_date_type ) ) { |
| 1048 | - $where_columns[] = $wpdb->prepare( "`{$column_name}` = '%d'", esc_sql( $column_value ) ); // phpcs:ignore Standard.Category.SniffName.ErrorCode | |
| 1054 | + $where_columns[] = $wpdb->prepare( "`{$column_name}` = '%d'", esc_sql( $column_value ) ); // phpcs:ignore | |
| 1049 | 1055 | } |
| 1050 | 1056 | } |
| 1051 | 1057 | } |
| 1052 | 1058 | } |
| @@ -1052,14 +1058,13 @@ | ||
| 1052 | 1058 | } |
| 1053 | 1059 | } |
| 1054 | 1060 | } |
| 1055 | 1061 | |
| 1056 | - if ( 0 === count( $where_columns ) ) {//phpcs:ignore - 8.1 proof | |
| 1062 | + if ( 0 === count( $where_columns ) ) { // phpcs:ignore -- 8.1 proof | |
| 1057 | 1063 | return ''; |
| 1058 | 1064 | } else { |
| 1059 | 1065 | $operator = |
| 1060 | - isset( $_REQUEST['wpda_search_column_operator'] ) && | |
| 1061 | - 'or' === strtolower( $_REQUEST['wpda_search_column_operator'] ) | |
| 1066 | + isset( $_REQUEST['wpda_search_column_operator'] ) && 'or' === strtolower( $_REQUEST['wpda_search_column_operator'] ) // phpcs:ignore | |
| 1062 | 1067 | ? 'or' : 'and'; |
| 1063 | 1068 | return ' (' . implode( " $operator ", $where_columns ) . ') '; |
| 1064 | 1069 | } |
| 1065 | 1070 | } |
| @@ -1092,15 +1097,18 @@ | ||
| 1092 | 1097 | return false; |
| 1093 | 1098 | } |
| 1094 | 1099 | if ( method_exists( $wpdadb, 'is_connected' ) ) { |
| 1095 | 1100 | if ( ! $wpdadb->is_connected() ) { |
| 1101 | + // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment | |
| 1096 | 1102 | $msg = new WPDA_Message_Box( |
| 1097 | 1103 | [ |
| 1098 | - 'message_text' => __( "Remote database '{$schema_name}' not available [check connection: Settings > WP Data Access]", 'wp-data-access' ), | |
| 1104 | + /* translators: %s = database name */ | |
| 1105 | + 'message_text' => sprintf( __( 'Remote database "%s" not available [check connection: Settings > WP Data Access]', 'wp-data-access' ), $schema_name ), | |
| 1099 | 1106 | 'message_type' => 'error', |
| 1100 | 1107 | 'message_is_dismissible' => false, |
| 1101 | 1108 | ] |
| 1102 | 1109 | ); |
| 1110 | + // phpcs:enable WordPress.WP.I18n.MissingTranslatorsComment | |
| 1103 | 1111 | $msg->box(); |
| 1104 | 1112 | |
| 1105 | 1113 | return false; |
| 1106 | 1114 | } |
| @@ -1114,9 +1122,9 @@ | ||
| 1114 | 1122 | $wpdadb->dbname, |
| 1115 | 1123 | ] |
| 1116 | 1124 | ) |
| 1117 | 1125 | ); // db call ok; no-cache ok. |
| 1118 | - $wpdadb->get_results(); // phpcs:ignore Standard.Category.SniffName.ErrorCode | |
| 1126 | + $wpdadb->get_results(); | |
| 1119 | 1127 | |
| 1120 | 1128 | return 1 === $wpdadb->num_rows; |
| 1121 | 1129 | } |
| 1122 | 1130 | |
| @@ -1143,23 +1151,28 @@ | ||
| 1143 | 1151 | jQuery(function() { |
| 1144 | 1152 | var clipboard = new ClipboardJS('.wpda_shortcode_clipboard'); |
| 1145 | 1153 | }); |
| 1146 | 1154 | </script> |
| 1147 | - <style type="text/css"> | |
| 1155 | + <style> | |
| 1156 | + /* noinspection CssUnusedSymbol */ | |
| 1148 | 1157 | .wpda_shortcode_content { |
| 1149 | 1158 | padding: 0 20px; |
| 1150 | 1159 | } |
| 1160 | + /* noinspection CssUnusedSymbol */ | |
| 1151 | 1161 | .wpda_shortcode_text { |
| 1152 | 1162 | text-align: center; |
| 1153 | 1163 | font-size: 105%; |
| 1154 | 1164 | white-space: nowrap; |
| 1155 | 1165 | } |
| 1166 | + /* noinspection CssUnusedSymbol */ | |
| 1156 | 1167 | .wpda_shortcode_buttons { |
| 1157 | 1168 | text-align: center; |
| 1158 | 1169 | } |
| 1170 | + /* noinspection CssUnusedSymbol */ | |
| 1159 | 1171 | .button.wpda_shortcode_button { |
| 1160 | 1172 | width: 100px !important; |
| 1161 | 1173 | } |
| 1174 | + /* noinspection CssUnusedSymbol */ | |
| 1162 | 1175 | .wpda_shortcode_link { |
| 1163 | 1176 | text-decoration: none; |
| 1164 | 1177 | font-weight: bold; |
| 1165 | 1178 | } |
| @@ -1188,9 +1201,9 @@ | ||
| 1188 | 1201 | * @return array |
| 1189 | 1202 | */ |
| 1190 | 1203 | public static function get_post_types() { |
| 1191 | 1204 | global $wpdb; |
| 1192 | - $rows = $wpdb->get_results( | |
| 1205 | + $rows = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 1193 | 1206 | "select distinct post_type from {$wpdb->posts}", |
| 1194 | 1207 | 'ARRAY_N' |
| 1195 | 1208 | ); |
| 1196 | 1209 | |
| @@ -1203,9 +1216,9 @@ | ||
| 1203 | 1216 | } |
| 1204 | 1217 | |
| 1205 | 1218 | public static function get_table_engine( $schema_name, $table_name ) { |
| 1206 | 1219 | $table_info = WPDA::get_table_values( $schema_name, $table_name ); |
| 1207 | - //phpcs:ignore - 8.1 proof | |
| 1220 | + // phpcs:ignore -- 8.1 proof | |
| 1208 | 1221 | return ( |
| 1209 | 1222 | 1 === count( $table_info ) && |
| 1210 | 1223 | 'connect' === strtolower( $table_info[0]['engine'] ) |
| 1211 | 1224 | ) ? 'connect' : ''; |
| @@ -1234,13 +1247,13 @@ | ||
| 1234 | 1247 | |
| 1235 | 1248 | /** |
| 1236 | 1249 | * Get estimated number of rows in a table |
| 1237 | 1250 | * |
| 1238 | - * @param $schema_name Schema name | |
| 1239 | - * @param $table_name Table name | |
| 1240 | - * @param $wpda_table_settings Table settings (query WPDA_Table_Settings_Model) | |
| 1251 | + * @param $schema_name string Schema name | |
| 1252 | + * @param $table_name string Table name | |
| 1253 | + * @param $wpda_table_settings string Table settings (query WPDA_Table_Settings_Model) | |
| 1241 | 1254 | * |
| 1242 | - * @return int row count estimate or -1 if no estimate available | |
| 1255 | + * @return array row count estimate or -1 if no estimate available | |
| 1243 | 1256 | */ |
| 1244 | 1257 | public static function get_row_count_estimate( $schema_name, $table_name, $wpda_table_settings ) { |
| 1245 | 1258 | $row_count = null; |
| 1246 | 1259 | $is_estimate = null; |
| @@ -1245,9 +1258,9 @@ | ||
| 1245 | 1258 | $row_count = null; |
| 1246 | 1259 | $is_estimate = null; |
| 1247 | 1260 | $do_real_count = null; |
| 1248 | 1261 | $table_info = self::get_table_values( $schema_name, $table_name ); |
| 1249 | - if ( 1 === count( $table_info ) ) {//phpcs:ignore - 8.1 proof | |
| 1262 | + if ( 1 === count( $table_info ) ) { // phpcs:ignore -- 8.1 proof | |
| 1250 | 1263 | $row_count = $table_info[0]['table_rows']; |
| 1251 | 1264 | |
| 1252 | 1265 | $system_row_count_estimate = null; |
| 1253 | 1266 | $row_count_estimate_value = null; |
| @@ -1302,9 +1315,9 @@ | ||
| 1302 | 1315 | } |
| 1303 | 1316 | } elseif ( 'connect' === strtolower( $table_info[0]['engine'] ) ) { |
| 1304 | 1317 | $getpk = WPDA_List_Columns_Cache::get_list_columns( $schema_name, $table_name ); |
| 1305 | 1318 | $pk = $getpk->get_table_primary_key(); |
| 1306 | - if ( is_array( $pk ) && count( $pk ) > 0 ) {//phpcs:ignore - 8.1 proof | |
| 1319 | + if ( is_array( $pk ) && count( $pk ) > 0 ) { // phpcs:ignore -- 8.1 proof | |
| 1307 | 1320 | $sql_rowcount_sql = |
| 1308 | 1321 | 'select count(*) from `' . str_replace( '`', '', $table_name ) . |
| 1309 | 1322 | '` where `' . $pk[0] . '` not in ' . |
| 1310 | 1323 | '(select null from `' . str_replace( '`', '', $table_name ) . '` where 1=2)'; |
| @@ -1309,9 +1322,9 @@ | ||
| 1309 | 1322 | '` where `' . $pk[0] . '` not in ' . |
| 1310 | 1323 | '(select null from `' . str_replace( '`', '', $table_name ) . '` where 1=2)'; |
| 1311 | 1324 | $wpdadb = WPDADB::get_db_connection( $schema_name ); |
| 1312 | 1325 | $sql_rowcount = $wpdadb->get_results( $sql_rowcount_sql, 'ARRAY_N' ); |
| 1313 | - if ( count( $sql_rowcount ) === 1 ) {//phpcs:ignore - 8.1 proof | |
| 1326 | + if ( count( $sql_rowcount ) === 1 ) { // phpcs:ignore -- 8.1 proof | |
| 1314 | 1327 | $row_count = $sql_rowcount[0][0]; |
| 1315 | 1328 | $is_estimate = false; |
| 1316 | 1329 | $do_real_count = false; |
| 1317 | 1330 | } else { |
| @@ -1358,11 +1371,11 @@ | ||
| 1358 | 1371 | } |
| 1359 | 1372 | |
| 1360 | 1373 | if ( null === $column_names ) { |
| 1361 | 1374 | $columns = WPDA_Dictionary_Lists::get_table_columns( $table_name, $schema_name ); |
| 1362 | - $column_names = array_column( $columns, 'column_name' ); //phpcs:ignore - 8.1 proof | |
| 1375 | + $column_names = array_column( $columns, 'column_name' ); // phpcs:ignore -- 8.1 proof | |
| 1363 | 1376 | } |
| 1364 | - if ( count( $column_names ) === 0 ) {//phpcs:ignore - 8.1 proof | |
| 1377 | + if ( count( $column_names ) === 0 ) { // phpcs:ignore -- 8.1 proof | |
| 1365 | 1378 | return self::validate_name_np(); |
| 1366 | 1379 | } |
| 1367 | 1380 | |
| 1368 | 1381 | $is_valid = true; |
| @@ -1463,9 +1476,22 @@ | ||
| 1463 | 1476 | $encrypt_method = 'AES-256-CBC'; |
| 1464 | 1477 | $key = hash( 'sha256', WPDA::get_option( WPDA::OPTION_PLUGIN_SECRET_KEY ) ); |
| 1465 | 1478 | $iv = substr( hash( 'sha256', WPDA::get_option( WPDA::OPTION_PLUGIN_SECRET_IV ) ), 0, 16 ); |
| 1466 | 1479 | |
| 1467 | - return base64_encode( openssl_encrypt( WPDA::get_option( WPDA::OPTION_PLUGIN_SONCE_SEED ) . $_SERVER['REMOTE_ADDR'], $encrypt_method, $key, 0, $iv ) ); | |
| 1480 | + return base64_encode( | |
| 1481 | + openssl_encrypt( WPDA::get_option( | |
| 1482 | + WPDA::OPTION_PLUGIN_SONCE_SEED ) . | |
| 1483 | + ( | |
| 1484 | + isset( $_SERVER['REMOTE_ADDR'] ) | |
| 1485 | + ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) | |
| 1486 | + : '' | |
| 1487 | + ), | |
| 1488 | + $encrypt_method, | |
| 1489 | + $key, | |
| 1490 | + 0, | |
| 1491 | + $iv | |
| 1492 | + ) | |
| 1493 | + ); | |
| 1468 | 1494 | } |
| 1469 | 1495 | |
| 1470 | 1496 | public static function wpda_create_sonce( $action = 'undefined' ) { |
| 1471 | 1497 | $token = self::get_sonce_token(); |
| @@ -1488,14 +1514,14 @@ | ||
| 1488 | 1514 | |
| 1489 | 1515 | public static function wpda_create_content_folder() { |
| 1490 | 1516 | $upload_dir = WPDA::get_plugin_upload_dir(); |
| 1491 | 1517 | if ( ! file_exists( $upload_dir ) ) { |
| 1492 | - mkdir( $upload_dir, 0755, true ); | |
| 1493 | - $fw = fopen( $upload_dir . ".htaccess", 'w' ); | |
| 1518 | + mkdir( $upload_dir, 0755, true ); // phpcs:ignore | |
| 1519 | + $fw = fopen( $upload_dir . ".htaccess", 'w' ); // phpcs:ignore | |
| 1494 | 1520 | if ( false !== $fw ) { |
| 1495 | - fwrite( $fw, "IndexIgnore *" ); | |
| 1521 | + fwrite( $fw, "IndexIgnore *" ); // phpcs:ignore | |
| 1496 | 1522 | } |
| 1497 | - fclose( $fw ); | |
| 1523 | + fclose( $fw ); // phpcs:ignore | |
| 1498 | 1524 | } |
| 1499 | 1525 | } |
| 1500 | 1526 | |
| 1501 | 1527 | public static function wpda_delete_content_folder() { |
| @@ -1502,13 +1528,12 @@ | ||
| 1502 | 1528 | $upload_dir = WPDA::get_plugin_upload_dir(); |
| 1503 | 1529 | if ( file_exists( $upload_dir ) ) { |
| 1504 | 1530 | $files = glob( $upload_dir . '*', GLOB_MARK ); |
| 1505 | 1531 | foreach ( $files as $file ) { |
| 1506 | - unlink( $file ); | |
| 1532 | + unlink( $file ); // phpcs:ignore | |
| 1507 | 1533 | } |
| 1508 | - unlink( $upload_dir . '.htaccess' ); | |
| 1509 | - | |
| 1510 | - rmdir( $upload_dir ); | |
| 1534 | + unlink( $upload_dir . '.htaccess' ); // phpcs:ignore | |
| 1535 | + rmdir( $upload_dir ); // phpcs:ignore | |
| 1511 | 1536 | } |
| 1512 | 1537 | } |
| 1513 | 1538 | |
| 1514 | 1539 | public static function sent_header( $content_type, $cors = null, $attachment = null ) { |
| @@ -1529,12 +1554,12 @@ | ||
| 1529 | 1554 | |
| 1530 | 1555 | public static function sent_msg( $status, $msg ) { |
| 1531 | 1556 | echo json_encode( |
| 1532 | 1557 | array( |
| 1533 | - 'status' => $status, | |
| 1534 | - 'msg' => $msg, | |
| 1558 | + 'status' => esc_attr( $status ), | |
| 1559 | + 'msg' => $msg, // phpcs:ignore | |
| 1535 | 1560 | ), true |
| 1536 | - ); // phpcs:ignore - 8.1 proof | |
| 1561 | + ); // phpcs:ignore | |
| 1537 | 1562 | } |
| 1538 | 1563 | |
| 1539 | 1564 | public static function is_post() { |
| 1540 | 1565 | global $post; |
| @@ -1550,9 +1575,9 @@ | ||
| 1550 | 1575 | $user_id = get_current_user_id(); |
| 1551 | 1576 | |
| 1552 | 1577 | $wpda_hide_manage_link = get_option( 'wpda_hide_manage_link' ); |
| 1553 | 1578 | if ( is_array( $wpda_hide_manage_link ) ) { |
| 1554 | - $wpda_hide_manage_list = array_flip( $wpda_hide_manage_link ); //phpcs:ignore - 8.1 proof | |
| 1579 | + $wpda_hide_manage_list = array_flip( $wpda_hide_manage_link ); // phpcs:ignore -- 8.1 proof | |
| 1555 | 1580 | } else { |
| 1556 | 1581 | $wpda_hide_manage_list = array(); |
| 1557 | 1582 | } |
| 1558 | 1583 | |
| @@ -1598,11 +1623,11 @@ | ||
| 1598 | 1623 | * @return mixed|string |
| 1599 | 1624 | */ |
| 1600 | 1625 | public static function get_server_address() { |
| 1601 | 1626 | if ( isset( $_SERVER['SERVER_ADDR'] ) ) { |
| 1602 | - return $_SERVER['SERVER_ADDR']; | |
| 1627 | + return sanitize_text_field( wp_unslash( $_SERVER['SERVER_ADDR'] ) ); | |
| 1603 | 1628 | } elseif ( isset( $_SERVER['LOCAL_ADDR'] ) ) { |
| 1604 | - return $_SERVER['LOCAL_ADDR']; | |
| 1629 | + return sanitize_text_field( wp_unslash( $_SERVER['LOCAL_ADDR'] ) ); | |
| 1605 | 1630 | } else { |
| 1606 | 1631 | return 'UNKNOWN'; |
| 1607 | 1632 | } |
| 1608 | 1633 | } |
| @@ -1617,9 +1642,9 @@ | ||
| 1617 | 1642 | return WPDA::get_current_user_email(); |
| 1618 | 1643 | case '$$NOW$$': |
| 1619 | 1644 | case '$$NOWDT$$': |
| 1620 | 1645 | global $wpdb; |
| 1621 | - $now_db = $wpdb->get_var( 'select now()' ); | |
| 1646 | + $now_db = $wpdb->get_var( 'select now()' ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 1622 | 1647 | $db_format = WPDA::DB_DATETIME_FORMAT; |
| 1623 | 1648 | $convert_date = \DateTime::createFromFormat( $db_format, $now_db ); |
| 1624 | 1649 | if ( false !== $convert_date ) { |
| 1625 | 1650 | $date_format = WPDA::get_option( WPDA::OPTION_PLUGIN_DATE_FORMAT ); |
| @@ -1643,20 +1668,22 @@ | ||
| 1643 | 1668 | * @param string $errmsg Error message |
| 1644 | 1669 | * @return void |
| 1645 | 1670 | */ |
| 1646 | 1671 | public static function wpda_log_wp_error( $errmsg ) { |
| 1647 | - $dbt = debug_backtrace(); | |
| 1648 | - $clr = array_shift( $dbt );//phpcs:ignore - 8.1 proof | |
| 1672 | + $dbt = debug_backtrace(); // phpcs:ignore | |
| 1673 | + $clr = array_shift( $dbt ); // phpcs:ignore -- 8.1 proof | |
| 1649 | 1674 | |
| 1675 | + // phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r | |
| 1650 | 1676 | error_log( "WP Data Access error in {$clr['file']}:{$clr['line']}" ); |
| 1651 | 1677 | error_log( print_r( $errmsg, true ) ); |
| 1678 | + // phpcs:enable WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r | |
| 1652 | 1679 | } |
| 1653 | 1680 | |
| 1654 | 1681 | /** |
| 1655 | 1682 | * Get the column data types from a custom query |
| 1656 | 1683 | * |
| 1657 | - * @param $database Database (schema) name | |
| 1658 | - * @param $query Custom query | |
| 1684 | + * @param $database string Database (schema) name | |
| 1685 | + * @param $query string Custom query | |
| 1659 | 1686 | * @return array|null Column data type array or null if the query does not return any columns |
| 1660 | 1687 | */ |
| 1661 | 1688 | public static function get_columns_from_query( $database, $query ) { |
| 1662 | 1689 | $wpdadb = WPDADB::get_db_connection( $database ); |
| @@ -1664,9 +1691,9 @@ | ||
| 1664 | 1691 | return null; |
| 1665 | 1692 | } |
| 1666 | 1693 | |
| 1667 | 1694 | $wpdadb->suppress_errors( true ); |
| 1668 | - $table_name = 'custom' . mt_rand(0, time()); | |
| 1695 | + $table_name = 'custom' . wp_rand(0, time()); | |
| 1669 | 1696 | |
| 1670 | 1697 | // Create temporary table. |
| 1671 | 1698 | $wpdadb->query( |
| 1672 | 1699 | "CREATE TEMPORARY TABLE `{$table_name}` AS (select * from (" . $query . ') as t limit 0)' |
| @@ -1686,9 +1713,18 @@ | ||
| 1686 | 1713 | return $rows; |
| 1687 | 1714 | } |
| 1688 | 1715 | |
| 1689 | 1716 | public static function current_user_is_admin() { |
| 1690 | - return current_user_can( 'manage_options' ) || is_super_admin(); | |
| 1717 | + if (current_user_can( 'manage_options' ) || is_super_admin()) { | |
| 1718 | + return true; | |
| 1719 | + } | |
| 1720 | + | |
| 1721 | + $user = wp_get_current_user(); | |
| 1722 | + if ( in_array( 'administrator', $user->roles ) ) { | |
| 1723 | + return true; | |
| 1724 | + } | |
| 1725 | + | |
| 1726 | + return false; | |
| 1691 | 1727 | } |
| 1692 | 1728 | |
| 1693 | 1729 | } |
| 1694 | 1730 | |