PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.82
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.82
5.5.84 5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 5.5.42 All 160 releases
wp-data-access / WPDataAccess / Utilities / WPDA_Export_Csv.php

WPDA_Export_Csv.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 5.5.82, at WPDataAccess/Utilities/WPDA_Export_Csv.php

65 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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