| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Suppress "error - 0 - No summary was found for this file" on phpdoc generation |
| 5 |
* |
| 6 |
* @package WPDataAccess\Utilities |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace WPDataAccess\Utilities { |
| 10 |
|
| 11 |
use WPDataAccess\WPDA; |
| 12 |
|
| 13 |
/** |
| 14 |
* Class WPDA_Export_Csv |
| 15 |
* |
| 16 |
* @author Peter Schulz |
| 17 |
* @since 2.0.13 |
| 18 |
*/ |
| 19 |
class WPDA_Export_Csv extends WPDA_Export_Formatted { |
| 20 |
|
| 21 |
/** |
| 22 |
* File header for CSV export |
| 23 |
* |
| 24 |
* @since 2.0.13 |
| 25 |
*/ |
| 26 |
protected function header() { |
| 27 |
WPDA::sent_header( 'text/csv', null, "{$this->table_names}.csv" ); |
| 28 |
|
| 29 |
$first_col = true; |
| 30 |
foreach ( $this->rows[0] as $column_name => $column_value ) { |
| 31 |
if ( $first_col ) { |
| 32 |
$first_col = false; |
| 33 |
} else { |
| 34 |
echo ','; |
| 35 |
} |
| 36 |
echo $this->wpda_list_columns->get_column_label( $column_name ); // phpcs:ignore WordPress.Security.EscapeOutput |
| 37 |
} |
| 38 |
echo "\n"; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Process one row to be export in CSV format |
| 43 |
* |
| 44 |
* @param array $row |
| 45 |
* |
| 46 |
* @since 2.0.13 |
| 47 |
*/ |
| 48 |
protected function row( $row ) { |
| 49 |
$first_col = true; |
| 50 |
foreach ( $row as $column_name => $column_value ) { |
| 51 |
if ( $first_col ) { |
| 52 |
$first_col = false; |
| 53 |
} else { |
| 54 |
echo ','; |
| 55 |
} |
| 56 |
$is_string = 'number' === WPDA::get_type( $this->data_types[ $column_name ] ) ? '' : '"'; |
| 57 |
echo $is_string . str_replace( '"', '""', (string) $column_value ) . $is_string; // phpcs:ignore WordPress.Security.EscapeOutput |
| 58 |
} |
| 59 |
echo "\n"; |
| 60 |
} |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
} |
| 65 |
|