| @@ -1,5 +1,5 @@ | ||
| 1 | -<?php // phpcs:ignore Standard.Category.SniffName.ErrorCode | |
| 1 | +<?php | |
| 2 | 2 | |
| 3 | 3 | namespace WPDataAccess\CSV_Files { |
| 4 | 4 | |
| 5 | 5 | use WPDataAccess\Connection\WPDADB; |
| @@ -70,9 +70,9 @@ | ||
| 70 | 70 | ></a> |
| 71 | 71 | <?php |
| 72 | 72 | } |
| 73 | 73 | ?> |
| 74 | - <?php echo __( 'Import CSV ' ); // phpcs:ignore WordPress.Security.EscapeOutput ?> | |
| 74 | + <?php esc_html_e( 'Import CSV', 'wp-data-access' ); ?> | |
| 75 | 75 | </h1> |
| 76 | 76 | <?php $this->show_body(); ?> |
| 77 | 77 | </div> |
| 78 | 78 | <?php |
| @@ -149,9 +149,9 @@ | ||
| 149 | 149 | ?> |
| 150 | 150 | <br/><br/> |
| 151 | 151 | <fieldset class="wpda_fieldset"> |
| 152 | 152 | <legend> |
| 153 | - <?php echo __( 'Select a file and click upload', 'wp-data-access' ); // phpcs:ignore WordPress.Security.EscapeOutput ?> | |
| 153 | + <?php esc_html_e( 'Select a file and click upload', 'wp-data-access' ); ?> | |
| 154 | 154 | </legend> |
| 155 | 155 | |
| 156 | 156 | <form id="form_import_table" |
| 157 | 157 | method="post" |
| @@ -209,9 +209,9 @@ | ||
| 209 | 209 | class="button button-primary" |
| 210 | 210 | onclick="if (jQuery('#csv_name').val()===''||jQuery('#filename').val()==='') { alert('Please enter an import name and select a file'); return false; }" |
| 211 | 211 | > |
| 212 | 212 | <i class="fas fa-check wpda_icon_on_button"></i> |
| 213 | - <?php echo __( 'Upload', 'wp-data-access' ); // phpcs:ignore WordPress.Security.EscapeOutput ?> | |
| 213 | + <?php esc_html_e( 'Upload', 'wp-data-access' ); ?> | |
| 214 | 214 | </button> |
| 215 | 215 | <button type="button" |
| 216 | 216 | onclick="window.location.href='?page=wpda&page_action=wpda_import_csv'" |
| 217 | 217 | class="button button-secondary" |
| @@ -216,9 +216,9 @@ | ||
| 216 | 216 | onclick="window.location.href='?page=wpda&page_action=wpda_import_csv'" |
| 217 | 217 | class="button button-secondary" |
| 218 | 218 | > |
| 219 | 219 | <i class="fas fa-times-circle wpda_icon_on_button"></i> |
| 220 | - <?php echo __( 'Cancel', 'wp-data-access' ); // phpcs:ignore WordPress.Security.EscapeOutput ?> | |
| 220 | + <?php esc_html_e( 'Cancel', 'wp-data-access' ); ?> | |
| 221 | 221 | </button> |
| 222 | 222 | </td> |
| 223 | 223 | </tr> |
| 224 | 224 | </table> |
| @@ -312,9 +312,9 @@ | ||
| 312 | 312 | |
| 313 | 313 | // Security check. |
| 314 | 314 | $wp_nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '?'; // phpcs:ignore WordPress.Security.NonceVerification |
| 315 | 315 | if ( ! wp_verify_nonce( $wp_nonce, "wpda-import-csv-{$csv_id}" ) ) { |
| 316 | - wp_die( __( 'ERROR: Not authorized', 'wp-data-access' ) ); // phpcs:ignore WordPress.Security.EscapeOutput | |
| 316 | + wp_die( esc_html__( 'ERROR: Not authorized', 'wp-data-access' ) ); | |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | $truncate_table = |
| 320 | 320 | isset( $_REQUEST['truncate_table'] ) ? // phpcs:ignore WordPress.Security.NonceVerification |
| @@ -388,9 +388,9 @@ | ||
| 388 | 388 | $data_type_after[ $column['column_name'] ] = "'"; |
| 389 | 389 | } |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - // phpcs:disable | |
| 392 | + // phpcs:disable Squiz.PHP.DiscouragedFunctions.Discouraged, PluginCheck.CodeAnalysis.PHPErrorReporting.IniDirectiveDisplay_errors | |
| 393 | 393 | echo '<p>Enabling buffering...</p>'; |
| 394 | 394 | set_time_limit( 0 ); |
| 395 | 395 | @ini_set( 'zlib.output_compression', false ); |
| 396 | 396 | @ini_set( 'implicit_flush', true ); |
| @@ -398,9 +398,9 @@ | ||
| 398 | 398 | @ini_set( 'display_errors', false ); |
| 399 | 399 | ob_implicit_flush( true ); |
| 400 | 400 | echo '<p>Reading CSV file...</p>'; |
| 401 | 401 | @ini_set( 'auto_detect_line_endings', true ); |
| 402 | - // phpcs:enable | |
| 402 | + // phpcs:enable Squiz.PHP.DiscouragedFunctions.Discouraged, PluginCheck.CodeAnalysis.PHPErrorReporting.IniDirectiveDisplay_errors | |
| 403 | 403 | |
| 404 | 404 | if ( false !== ( $fp = fopen( $file_name, 'rb' ) ) ) { // phpcs:ignore |
| 405 | 405 | $wpdadb = WPDADB::get_db_connection( $schema_name ); |
| 406 | 406 | if ( null !== $wpdadb ) { |
| @@ -434,9 +434,9 @@ | ||
| 434 | 434 | $date_value = substr( $data[ $column ], 0, 10 ); |
| 435 | 435 | $convert_date = \DateTime::createFromFormat( str_replace( '%', '', $date_format ), $date_value ); |
| 436 | 436 | if ( false === $convert_date ) { |
| 437 | 437 | $error_msg = 'Cannot convert ' . esc_attr( $date_value ) . ' to date (using format ' . esc_attr( $date_format ) . ')'; |
| 438 | - echo "<div>ERROR: {$error_msg}</div>"; | |
| 438 | + echo '<div>ERROR: ' . esc_attr( $error_msg ) . '</div>'; | |
| 439 | 439 | $row_values_valid = false; |
| 440 | 440 | |
| 441 | 441 | // Write error to log file |
| 442 | 442 | WPDA::wpda_log_wp_error( $error_msg ); |
| @@ -444,9 +444,9 @@ | ||
| 444 | 444 | $wpda_insert_column_values[ $table_columns[ $column ] ] = $convert_date->format( 'Y-m-d' ); |
| 445 | 445 | } |
| 446 | 446 | } catch ( \Exception $e ) { |
| 447 | 447 | echo '<div>Cannot convert ' . esc_attr( $date_value ) . ' to date (using format ' . esc_attr( $date_format ) . ')</div>'; |
| 448 | - echo "<div>ERROR: {$error_msg}</div>"; | |
| 448 | + echo '<div>ERROR: ' . esc_attr( $error_msg ) . '</div>'; | |
| 449 | 449 | $row_values_valid = false; |
| 450 | 450 | |
| 451 | 451 | // Write error to log file |
| 452 | 452 | WPDA::wpda_log_wp_error( $error_msg ); |
| @@ -517,9 +517,9 @@ | ||
| 517 | 517 | $row++; |
| 518 | 518 | } |
| 519 | 519 | $wpdadb->suppress_errors( $suppress_errors ); |
| 520 | 520 | } |
| 521 | - fclose( $fp ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose | |
| 521 | + fclose( $fp ); // phpcs:ignore | |
| 522 | 522 | |
| 523 | 523 | $row--; |
| 524 | 524 | echo "<p style='font-weight: bold'>Import ready!</p>"; |
| 525 | 525 | echo esc_attr( $row ) . ' rows processed<br/>'; |
| @@ -543,9 +543,9 @@ | ||
| 543 | 543 | |
| 544 | 544 | // Security check. |
| 545 | 545 | $wp_nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '?'; // input var okay. |
| 546 | 546 | if ( ! wp_verify_nonce( $wp_nonce, "wpda-reload-csv-{$csv_id}" ) ) { |
| 547 | - wp_die( __( 'ERROR: Not authorized', 'wp-data-access' ) ); // phpcs:ignore WordPress.Security.EscapeOutput | |
| 547 | + wp_die( esc_html__( 'ERROR: Not authorized', 'wp-data-access' ) ); | |
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | $this->show_body_upload(); |
| 551 | 551 | } |
| @@ -558,15 +558,15 @@ | ||
| 558 | 558 | protected function upload_file() { |
| 559 | 559 | // Security check. |
| 560 | 560 | $wp_nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '?'; // input var okay. |
| 561 | 561 | if ( ! wp_verify_nonce( $wp_nonce, "wpda-import-csv-{$this->schema_name}" ) ) { |
| 562 | - wp_die( __( 'ERROR: Not authorized', 'wp-data-access' ) ); // phpcs:ignore WordPress.Security.EscapeOutput | |
| 562 | + wp_die( esc_html__( 'ERROR: Not authorized', 'wp-data-access' ) ); | |
| 563 | 563 | } |
| 564 | 564 | |
| 565 | - // phpcs:disable | |
| 565 | + // phpcs:disable Squiz.PHP.DiscouragedFunctions.Discouraged | |
| 566 | 566 | $temp_file_name = isset( $_FILES['filename']['tmp_name'] ) ? |
| 567 | 567 | sanitize_text_field( $_FILES['filename']['tmp_name'] ) : ''; // For Windows: do NOT unslash! |
| 568 | - // phpcs:enable | |
| 568 | + // phpcs:enable Squiz.PHP.DiscouragedFunctions.Discouraged | |
| 569 | 569 | $orig_file_name = isset( $_FILES['filename']['name'] ) ? |
| 570 | 570 | sanitize_text_field( wp_unslash( $_FILES['filename']['name'] ) ) : ''; |
| 571 | 571 | |
| 572 | 572 | if ( isset( $_FILES['filename'] ) && isset( $_REQUEST['csv_name'] ) ) { |
| @@ -576,9 +576,9 @@ | ||
| 576 | 576 | UPLOAD_ERR_OK === $_FILES['filename']['error'] && |
| 577 | 577 | is_uploaded_file( $temp_file_name ) |
| 578 | 578 | ) { |
| 579 | 579 | echo '<br/>'; |
| 580 | - echo __( 'Uploading file', 'wp-data-access' ) . ' <strong>' . esc_attr( $orig_file_name ) . '</strong>...'; // phpcs:ignore WordPress.Security.EscapeOutput | |
| 580 | + esc_html_e( 'Uploading file', 'wp-data-access' ) . ' <strong>' . esc_attr( $orig_file_name ) . '</strong>...'; | |
| 581 | 581 | echo '<br/><br/>'; |
| 582 | 582 | |
| 583 | 583 | $upload_dir = WPDA::get_plugin_upload_dir(); |
| 584 | 584 | $real_file_name = 'wpda_csv_upload_' . gmdate( 'YmdHis' ) . '.csv'; |
| @@ -594,25 +594,25 @@ | ||
| 594 | 594 | if ( ! is_dir( $upload_dir ) ) { |
| 595 | 595 | WPDA::wpda_create_content_folder(); |
| 596 | 596 | } |
| 597 | 597 | |
| 598 | - $fw = fopen( $upload_dir . "{$real_file_name}", 'w' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fopen | |
| 598 | + $fw = fopen( $upload_dir . "{$real_file_name}", 'w' ); // phpcs:ignore | |
| 599 | 599 | while ( ! feof( $this->file_pointer ) ) { |
| 600 | - $file_content = fread( $this->file_pointer, 1024 ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fread | |
| 600 | + $file_content = fread( $this->file_pointer, 1024 ); // phpcs:ignore | |
| 601 | 601 | |
| 602 | 602 | if ( 'UTF-8' === $csv_encoding ) { |
| 603 | 603 | // UTF-8 encoding |
| 604 | - fwrite( $fw, mb_convert_encoding( $file_content, 'UTF-8', 'ISO-8859-1' ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fwrite | |
| 604 | + fwrite( $fw, mb_convert_encoding( $file_content, 'UTF-8', 'ISO-8859-1' ) ); // phpcs:ignore | |
| 605 | 605 | } else { |
| 606 | 606 | // No encoding |
| 607 | - fwrite( $fw, $file_content ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fwrite | |
| 607 | + fwrite( $fw, $file_content ); // phpcs:ignore | |
| 608 | 608 | } |
| 609 | 609 | } |
| 610 | 610 | } |
| 611 | - fclose( $fp ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose | |
| 612 | - fclose( $fw ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose | |
| 611 | + fclose( $fp ); // phpcs:ignore | |
| 612 | + fclose( $fw ); // phpcs:ignore | |
| 613 | 613 | |
| 614 | - echo __( 'Saving file info...', 'wp-data-access' ); // phpcs:ignore WordPress.Security.EscapeOutput | |
| 614 | + esc_html_e( 'Saving file info...', 'wp-data-access' ); | |
| 615 | 615 | echo '<br/><br/>'; |
| 616 | 616 | |
| 617 | 617 | if ( '' === $csv_id ) { |
| 618 | 618 | // New CSV import. |
| @@ -623,9 +623,9 @@ | ||
| 623 | 623 | $result = WPDA_CSV_Uploads_Model::update( $csv_id, $real_file_name, $orig_file_name, $csv_encoding ); |
| 624 | 624 | if ( $result ) { |
| 625 | 625 | // Remove old file. |
| 626 | 626 | if ( isset( $oldrow[0]->csv_real_file_name ) ) { |
| 627 | - unlink( WPDA::get_plugin_upload_dir() . $oldrow[0]->csv_real_file_name ); | |
| 627 | + unlink( WPDA::get_plugin_upload_dir() . $oldrow[0]->csv_real_file_name ); // phpcs:ignore | |
| 628 | 628 | } |
| 629 | 629 | } |
| 630 | 630 | } |
| 631 | 631 | if ( false === $result ) { |
| @@ -630,9 +630,9 @@ | ||
| 630 | 630 | } |
| 631 | 631 | if ( false === $result ) { |
| 632 | 632 | $msg = new WPDA_Message_Box( |
| 633 | 633 | array( |
| 634 | - 'message_text' => __( 'Processing CSV file failed', 'wp-data-access' ), | |
| 634 | + 'message_text' => esc_html__( 'Processing CSV file failed', 'wp-data-access' ), | |
| 635 | 635 | 'message_type' => 'error', |
| 636 | 636 | 'message_is_dismissible' => false, |
| 637 | 637 | ) |
| 638 | 638 | ); |
| @@ -657,9 +657,9 @@ | ||
| 657 | 657 | > |
| 658 | 658 | <input type="submit" |
| 659 | 659 | class="page-title-action" |
| 660 | 660 | style="margin-left: 0;" |
| 661 | - value="<?php echo __( 'Column mapping' ); // phpcs:ignore WordPress.Security.EscapeOutput ?>" | |
| 661 | + value="<?php esc_html_e( 'Column mapping', 'wp-data-access' ); ?>" | |
| 662 | 662 | /> |
| 663 | 663 | <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( $wp_nonce ); ?>" /> |
| 664 | 664 | </form> |
| 665 | 665 | <form method="post" |
| @@ -667,9 +667,9 @@ | ||
| 667 | 667 | style="display: inline-block; vertical-align: baseline;"> |
| 668 | 668 | <input type="submit" |
| 669 | 669 | class="page-title-action" |
| 670 | 670 | style="margin-left: 0;" |
| 671 | - value="<?php echo __( 'CSV file list' ); // phpcs:ignore WordPress.Security.EscapeOutput ?>" | |
| 671 | + value="<?php esc_html_e( 'CSV file list', 'wp-data-access' ); ?>" | |
| 672 | 672 | /> |
| 673 | 673 | </form> |
| 674 | 674 | <?php |
| 675 | 675 | } |
| @@ -677,9 +677,9 @@ | ||
| 677 | 677 | } else { |
| 678 | 678 | // File upload failed: inform user. |
| 679 | 679 | $msg = new WPDA_Message_Box( |
| 680 | 680 | array( |
| 681 | - 'message_text' => __( 'File upload failed', 'wp-data-access' ), | |
| 681 | + 'message_text' => esc_html__( 'File upload failed', 'wp-data-access' ), | |
| 682 | 682 | 'message_type' => 'error', |
| 683 | 683 | 'message_is_dismissible' => false, |
| 684 | 684 | ) |
| 685 | 685 | ); |