',', 'semicolon' => ';', 'tab' => "\t", 'pipe' => '|', 'colon' => ':', ); /** * Mapping * * @var mixed|null */ protected $mapping = null; /** * Actual delimiter * * @var mixed|string */ protected $delimiter = ','; /** * Data format * * @var mixed|string */ protected $date_format = '%Y-%m-%d'; /** * Indicates if header columns are available * * @var bool */ protected $has_header_columns = true; /** * CSV ID * * @var string|null */ protected $csv_id = null; /** * CSV name * * @var string */ protected $csv_name = ''; /** * CSV upload * * @var null */ protected $csv_upload = null; /** * Nonce * * @var null */ protected $wpnonce = null; /** * Preview nonce * * @var null */ protected $wpnonce_preview = null; /** * Database schema name * * @var array */ protected $db_schema_name = array(); /** * Schema name mapping * * @var mixed|null */ protected $schema_name_mapping = null; /** * Constructor */ public function __construct() { $this->csv_id = isset( $_REQUEST['csv_id'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['csv_id'] ) ) : ''; // input var okay. if ( null === $this->csv_id ) { wp_die( __( 'ERROR: Missing argument', 'wp-data-access' ) ); // phpcs:ignore WordPress.Security.EscapeOutput } $wp_nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : ''; // input var okay. if ( ! wp_verify_nonce( $wp_nonce, "wpda-mapping-{$this->csv_id}" ) ) { wp_die( __( 'ERROR: Not authorized', 'wp-data-access' ) ); // phpcs:ignore WordPress.Security.EscapeOutput } $this->csv_upload = WPDA_CSV_Uploads_Model::query( $this->csv_id ); if ( isset( $this->csv_upload[0]->csv_name ) ) { $this->csv_name = $this->csv_upload[0]->csv_name; } if ( isset( $this->csv_upload[0]->csv_mapping ) ) { $this->mapping = json_decode( $this->csv_upload[0]->csv_mapping, true ); if ( isset( $this->mapping['settings']['delimiter'] ) ) { $this->delimiter = $this->mapping['settings']['delimiter']; if ( '\\t' === $this->delimiter ) { $this->delimiter = "\t"; } } if ( isset( $this->mapping['settings']['date_format'] ) ) { $this->date_format = $this->mapping['settings']['date_format']; } if ( isset( $this->mapping['settings']['has_header_columns'] ) && 'false' === $this->mapping['settings']['has_header_columns'] ) { $this->has_header_columns = false; } } $this->db_schema_name = WPDA_Dictionary_Lists::get_db_schemas(); if ( isset( $this->mapping['database']['wpdaschema_name'] ) ) { $this->schema_name_mapping = $this->mapping['database']['wpdaschema_name']; } else { $this->schema_name_mapping = WPDA::get_user_default_scheme(); } $this->wpnonce = wp_create_nonce( "wpda-csv-mapping-{$this->csv_id}" ); $this->wpnonce_preview = wp_create_nonce( "wpda-csv-preview-mapping-{$this->csv_id}" ); } /** * Show mapping page * * @return void */ public function show() { $upload_dir = WPDA::get_plugin_upload_dir(); if ( ! isset( $this->csv_upload[0]->csv_real_file_name ) ) { wp_die( __( 'ERROR: CSV file not found', 'wp-data-access' ) ); // phpcs:ignore WordPress.Security.EscapeOutput } $file_name = $upload_dir . $this->csv_upload[0]->csv_real_file_name; $table_list = WPDA_Dictionary_Lists::get_tables( false, $this->schema_name_mapping ); $wp_nonce = esc_attr( wp_create_nonce( "wpda-import-csv-{$this->csv_id}" ) ); $wp_nonce_mapping = esc_attr( wp_create_nonce( "wpda-mapping-{$this->csv_id}" ) ); ?>

           


delimiter ) ) ) { // phpcs:ignore for ( $column = 0; $column < count( $data ); $column ++ ) { // phpcs:ignore - 8.1 proof if ( $this->has_header_columns ) { array_push( $csv_columns, $data[ $column ] );//phpcs:ignore - 8.1 proof } else { array_push( $csv_columns, "column_{$index}" );//phpcs:ignore - 8.1 proof $index++; } } break; } fclose( $fp ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose } ?>
$csv_column_ ) { $csv_column = trim( $csv_column_ ); ?>
  Mapped   Table
    mapping['columns'][ $key ] ) ) { ?>
  • mapping['columns'][ $key ] ); ?>

Save mapping Import CSV file Preview CSV file preview(); } /** * Preview container * * @return void */ protected function preview() { ?>