| @@ -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\Data_Dictionary\WPDA_List_Columns_Cache; |
| @@ -119,9 +119,9 @@ | ||
| 119 | 119 | |
| 120 | 120 | // Add reload form to actions. |
| 121 | 121 | $wp_nonce_action = "wpda-reload-csv-{$item['csv_id']}"; |
| 122 | 122 | $wp_nonce = esc_attr( wp_create_nonce( $wp_nonce_action ) ); |
| 123 | - $reload_form = $this->create_post_form( 'reload', "reload_form{$form_id}", $item['csv_id'], $wp_nonce, $item['csv_name'] ); | |
| 123 | + $reload_form = $this->create_post_form( 'reload', "reload_form{$form_id}", $item['csv_id'], $wp_nonce, $item['csv_name'], $item['csv_encoding'] ); | |
| 124 | 124 | ?> |
| 125 | 125 | <script type='text/javascript'> |
| 126 | 126 | jQuery("#wpda_invisible_container").append("<?php echo $reload_form; // phpcs:ignore WordPress.Security.EscapeOutput ?>"); |
| 127 | 127 | </script> |
| @@ -138,9 +138,9 @@ | ||
| 138 | 138 | // Remove edit action. |
| 139 | 139 | unset( $actions['edit'] ); |
| 140 | 140 | |
| 141 | 141 | // Add new links to beginning of action list. |
| 142 | - //phpcs:ignore - 8.1 proof | |
| 142 | + // phpcs:ignore -- 8.1 proof | |
| 143 | 143 | $actions = |
| 144 | 144 | array_merge( |
| 145 | 145 | array( 'mapping' => $mapping ), |
| 146 | 146 | array( 'import' => $import ), |
| @@ -158,10 +158,17 @@ | ||
| 158 | 158 | * @param string $wpnonce Nonce. |
| 159 | 159 | * @param string $csv_name CSV internal name. |
| 160 | 160 | * @return array|string|string[] |
| 161 | 161 | */ |
| 162 | - private function create_post_form( $action, $form_id, $csv_id, $wpnonce, $csv_name = '' ) { | |
| 162 | + private function create_post_form( $action, $form_id, $csv_id, $wpnonce, $csv_name = '', $csv_encoding = '' ) { | |
| 163 | 163 | $esc_attr = 'esc_attr'; |
| 164 | + | |
| 165 | + $csv_encoding_field = ''; | |
| 166 | + if ( ! empty( $csv_encoding ) ) { | |
| 167 | + $csv_encoding_field = "<input type='hidden' name='csv_encoding' value='{$esc_attr( $csv_encoding )}' />"; | |
| 168 | + } | |
| 169 | + | |
| 170 | + // phpcs:ignore PluginCheck.CodeAnalysis.Heredoc.NotAllowed | |
| 164 | 171 | $form = <<< EOT |
| 165 | 172 | <form id='{$esc_attr( $form_id )}' method='post' |
| 166 | 173 | action='?page={$esc_attr( $this->page )}&page_action=wpda_import_csv' |
| 167 | 174 | > |
| @@ -167,8 +174,9 @@ | ||
| 167 | 174 | > |
| 168 | 175 | <input type='hidden' name='action' value='{$esc_attr( $action )}' /> |
| 169 | 176 | <input type='hidden' name='csv_id' value='{$esc_attr( $csv_id )}' /> |
| 170 | 177 | <input type='hidden' name='csv_name' value='{$esc_attr( $csv_name )}' /> |
| 178 | + {$csv_encoding_field} | |
| 171 | 179 | <input type='hidden' name='_wpnonce' value='{$esc_attr( $wpnonce )}'> |
| 172 | 180 | </form> |
| 173 | 181 | EOT; |
| 174 | 182 | return str_replace( array( "\n", "\r" ), '', $form ); |
| @@ -201,9 +209,9 @@ | ||
| 201 | 209 | public function process_bulk_action() { |
| 202 | 210 | if ( 'delete' === $this->current_action() ) { |
| 203 | 211 | // Check if key is available. |
| 204 | 212 | if ( ! isset( $_REQUEST['csv_id'] ) ) { // input var okay. |
| 205 | - wp_die( __( 'ERROR: Invalid URL [missing primary key values]', 'wp-data-access' ) ); // phpcs:ignore WordPress.Security.EscapeOutput | |
| 213 | + wp_die( esc_html__( 'ERROR: Invalid URL [missing primary key values]', 'wp-data-access' ) ); | |
| 206 | 214 | } |
| 207 | 215 | $csv_id = sanitize_text_field( wp_unslash( $_REQUEST['csv_id'] ) ); // input var okay. |
| 208 | 216 | |
| 209 | 217 | // Check if delete is allowed. |
| @@ -209,17 +217,17 @@ | ||
| 209 | 217 | // Check if delete is allowed. |
| 210 | 218 | $wp_nonce_action = "wpda-delete-{$this->table_name}-{$csv_id}"; |
| 211 | 219 | $wp_nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : ''; // input var okay. |
| 212 | 220 | if ( ! wp_verify_nonce( $wp_nonce, $wp_nonce_action ) ) { |
| 213 | - wp_die( __( 'ERROR: Not authorized', 'wp-data-access' ) ); // phpcs:ignore WordPress.Security.EscapeOutput | |
| 221 | + wp_die( esc_html__( 'ERROR: Not authorized', 'wp-data-access' ) ); | |
| 214 | 222 | } |
| 215 | 223 | |
| 216 | 224 | // Delete CSV file and data. |
| 217 | 225 | $row = WPDA_CSV_Uploads_Model::query( $csv_id ); |
| 218 | - if ( is_array( $row ) && 1 === count( $row ) ) {//phpcs:ignore - 8.1 proof | |
| 226 | + if ( is_array( $row ) && 1 === count( $row ) ) { // phpcs:ignore -- 8.1 proof | |
| 219 | 227 | // Silently delete file. |
| 220 | 228 | if ( isset( $row[0]->csv_real_file_name ) ) { |
| 221 | - unlink( WPDA::get_plugin_upload_dir() . $row[0]->csv_real_file_name ); | |
| 229 | + unlink( WPDA::get_plugin_upload_dir() . $row[0]->csv_real_file_name ); // phpcs:ignore | |
| 222 | 230 | } |
| 223 | 231 | |
| 224 | 232 | // Delete record. |
| 225 | 233 | $next_row_to_be_deleted['csv_id'] = $csv_id; |
| @@ -253,16 +261,16 @@ | ||
| 253 | 261 | return; |
| 254 | 262 | } |
| 255 | 263 | |
| 256 | 264 | // Check if delete is allowed. |
| 257 | - $wp_nonce_action = 'wpda-delete-{$this->table_name}'; | |
| 265 | + $wp_nonce_action = "wpda-delete-{$this->table_name}"; | |
| 258 | 266 | $wp_nonce = isset( $_REQUEST['_wpnonce2'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce2'] ) ) : ''; // input var okay. |
| 259 | 267 | if ( ! wp_verify_nonce( $wp_nonce, $wp_nonce_action ) ) { |
| 260 | - die( __( 'ERROR: Not authorized', 'wp-data-access' ) ); // phpcs:ignore WordPress.Security.EscapeOutput | |
| 268 | + die( esc_html__( 'ERROR: Not authorized', 'wp-data-access' ) ); | |
| 261 | 269 | } |
| 262 | 270 | |
| 263 | 271 | $bulk_rows = $_REQUEST['bulk-selected']; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput |
| 264 | - //phpcs:ignore - 8.1 proof | |
| 272 | + // phpcs:ignore -- 8.1 proof | |
| 265 | 273 | $no_rows = count( ( array ) $bulk_rows ); // # rows to be deleted. |
| 266 | 274 | |
| 267 | 275 | $rows_to_be_deleted = array(); // Gonna hold rows to be deleted. |
| 268 | 276 | for ( $i = 0; $i < $no_rows; $i ++ ) { |
| @@ -271,9 +279,9 @@ | ||
| 271 | 279 | $row_object = json_decode( stripslashes( stripslashes( $bulk_rows[ $i ] ) ), true ); |
| 272 | 280 | |
| 273 | 281 | // Check if key is available. |
| 274 | 282 | if ( ! isset( $row_object['csv_id'] ) ) { |
| 275 | - wp_die( __( 'ERROR: Invalid URL [missing primary key values]', 'wp-data-access' ) ); // phpcs:ignore WordPress.Security.EscapeOutput | |
| 283 | + wp_die( esc_html__( 'ERROR: Invalid URL [missing primary key values]', 'wp-data-access' ) ); | |
| 276 | 284 | } |
| 277 | 285 | |
| 278 | 286 | // Save key. |
| 279 | 287 | $rows_to_be_deleted[ $i ] = $row_object['csv_id']; |
| @@ -284,12 +292,12 @@ | ||
| 284 | 292 | $rows_with_errors = 0; // Number of rows that could not be deleted. |
| 285 | 293 | for ( $i = 0; $i < $no_rows; $i ++ ) { |
| 286 | 294 | // Delete CSV file and data. |
| 287 | 295 | $row = WPDA_CSV_Uploads_Model::query( $rows_to_be_deleted[ $i ] ); |
| 288 | - if ( is_array( $row ) && 1 === count( $row ) ) {//phpcs:ignore - 8.1 proof | |
| 296 | + if ( is_array( $row ) && 1 === count( $row ) ) { // phpcs:ignore -- 8.1 proof | |
| 289 | 297 | // Silently delete file. |
| 290 | 298 | if ( isset( $row[0]->csv_real_file_name ) ) { |
| 291 | - unlink( WPDA_CSV_Import::get_plugin_upload_dir() . $row[0]->csv_real_file_name ); | |
| 299 | + unlink( WPDA::get_plugin_upload_dir() . $row[0]->csv_real_file_name ); // phpcs:ignore | |
| 292 | 300 | } |
| 293 | 301 | |
| 294 | 302 | // Delete record. |
| 295 | 303 | $next_row_to_be_deleted['csv_id'] = $rows_to_be_deleted[ $i ]; |
| @@ -352,8 +360,9 @@ | ||
| 352 | 360 | 'csv_real_file_name' => __( 'Local file Name', 'wp-data-access' ), |
| 353 | 361 | 'csv_orig_file_name' => __( 'File Name', 'wp-data-access' ), |
| 354 | 362 | 'csv_timestamp' => __( 'Timestamp', 'wp-data-access' ), |
| 355 | 363 | 'csv_mapping' => __( 'Mapping', 'wp-data-access' ), |
| 364 | + 'csv_encoding' => __( 'Encoding', 'wp-data-access' ), | |
| 356 | 365 | ); |
| 357 | 366 | } |
| 358 | 367 | |
| 359 | 368 | } |