export_formats = array( 'csv' => __( 'CSV - Character-Separated Values', 'tablepress' ), 'html' => __( 'HTML - Hypertext Markup Language', 'tablepress' ), 'json' => __( 'JSON - JavaScript Object Notation', 'tablepress' ), ); $this->csv_delimiters = array( ';' => __( '; (semicolon)', 'tablepress' ), ',' => __( ', (comma)', 'tablepress' ), 'tab' => __( '\t (tabulator)', 'tablepress' ), ); /** This filter is documented in the WordPress function unzip_file() in wp-admin/includes/file.php */ if ( class_exists( 'ZipArchive' ) && apply_filters( 'unzip_file_use_ziparchive', true ) ) { $this->zip_support_available = true; } } /** * Export a table. * * @since 1.0.0 * * @param array $table Table to be exported. * @param string $export_format Format for the export ('csv', 'html', 'json'). * @param string $csv_delimiter Delimiter for CSV export. * @return string Exported table (only data for CSV and HTML, full tables (including options) for JSON). */ public function export_table( array $table, $export_format, $csv_delimiter ) { switch ( $export_format ) { case 'csv': $output = ''; if ( 'tab' === $csv_delimiter ) { $csv_delimiter = "\t"; } foreach ( $table['data'] as $row_idx => $row ) { $csv_row = array(); foreach ( $row as $column_idx => $cell_content ) { $csv_row[] = $this->csv_wrap_and_escape( $cell_content, $csv_delimiter ); } $output .= implode( $csv_delimiter, $csv_row ); $output .= "\n"; } break; case 'html': $num_rows = count( $table['data'] ); $last_row_idx = $num_rows - 1; $thead = ''; $tfoot = ''; $tbody = array(); foreach ( $table['data'] as $row_idx => $row ) { // First row, need to check for head (but only if at least two rows). if ( 0 === $row_idx && $table['options']['table_head'] && $num_rows > 1 ) { $thead = $this->html_render_row( $row, 'th' ); continue; } // Last row, need to check for footer (but only if at least two rows). if ( $last_row_idx === $row_idx && $table['options']['table_foot'] && $num_rows > 1 ) { $tfoot = $this->html_render_row( $row, 'th' ); continue; } // Neither first nor last row (with respective head/foot enabled), so render as body row. $tbody[] = $this->html_render_row( $row, 'td' ); } // ,
, and tags. if ( ! empty( $thead ) ) { $thead = "\t\n{$thead}\t\n"; } if ( ! empty( $tfoot ) ) { $tfoot = "\t\n{$tfoot}\t\n"; } $tbody = "\t\n" . implode( '', $tbody ) . "\t\n"; $output = "