@@ -66,6 +66,7 @@ public function __construct( Visualizer_Plugin $plugin ) {
66
66
67
67
$ this ->_addFilter ( Visualizer_Plugin::FILTER_UNDO_REVISIONS , 'undoRevisions ' , 10 , 2 );
68
68
$ this ->_addFilter ( Visualizer_Plugin::FILTER_HANDLE_REVISIONS , 'handleExistingRevisions ' , 10 , 2 );
69
+ $ this ->_addFilter ( Visualizer_Plugin::FILTER_GET_CHART_DATA_AS , 'getDataAs ' , 10 , 3 );
69
70
70
71
}
71
72
@@ -147,6 +148,15 @@ protected function _addShortcode( $tag, $method ) {
147
148
return $ this ;
148
149
}
149
150
151
+ /**
152
+ * A wrapper around the actual function _getDataAs. This function is invoked as a filter.
153
+ *
154
+ * @since 3.2.0
155
+ */
156
+ public function getDataAs ( $ final , $ chart_id , $ type ) {
157
+ return $ this ->_getDataAs ( $ chart_id , $ type );
158
+ }
159
+
150
160
/**
151
161
* Extracts the data for a chart and prepares it for the given type.
152
162
*
@@ -223,14 +233,16 @@ public function _getDataAs( $chart_id, $type ) {
223
233
private function _getCSV ( $ rows , $ filename ) {
224
234
$ filename .= '.csv ' ;
225
235
236
+ $ bom = chr ( 0xEF ) . chr ( 0xBB ) . chr ( 0xBF );
226
237
$ fp = tmpfile ();
227
238
// support for MS Excel
228
- fprintf ( $ fp , $ bom = ( chr ( 0xEF ) . chr ( 0xBB ) . chr ( 0xBF ) ) );
239
+ fprintf ( $ fp , $ bom );
229
240
foreach ( $ rows as $ row ) {
230
241
fputcsv ( $ fp , $ row );
231
242
}
232
243
rewind ( $ fp );
233
244
$ csv = '' ;
245
+ // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
234
246
while ( ( $ array = fgetcsv ( $ fp ) ) !== false ) {
235
247
if ( strlen ( $ csv ) > 0 ) {
236
248
$ csv .= PHP_EOL ;
@@ -242,6 +254,7 @@ private function _getCSV( $rows, $filename ) {
242
254
return array (
243
255
'csv ' => $ csv ,
244
256
'name ' => $ filename ,
257
+ 'string ' => str_replace ( $ bom , '' , $ csv ),
245
258
);
246
259
}
247
260
@@ -280,6 +293,7 @@ private function _getExcel( $rows, $filename ) {
280
293
return array (
281
294
'csv ' => 'data:application/vnd.ms-excel;base64, ' . base64_encode ( $ xlsData ),
282
295
'name ' => $ filename ,
296
+ 'raw ' => base64_encode ( $ xlsData ),
283
297
);
284
298
}
285
299
@@ -311,6 +325,12 @@ private function _getHTML( $rows ) {
311
325
$ table = '<table class="visualizer-print"> ' ;
312
326
$ index = 0 ;
313
327
foreach ( $ rows as $ row ) {
328
+ // skip the data type row.
329
+ if ( 1 === $ index ) {
330
+ $ index ++;
331
+ continue ;
332
+ }
333
+
314
334
$ table .= '<tr> ' ;
315
335
foreach ( $ row as $ col ) {
316
336
if ( $ index === 0 ) {
@@ -432,6 +452,7 @@ protected function get_user_customization_js() {
432
452
}
433
453
434
454
if ( ! $ wp_filesystem ->exists ( $ dir ) ) {
455
+ // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
435
456
if ( ( $ done = $ wp_filesystem ->mkdir ( $ dir ) ) === false ) {
436
457
do_action ( 'themeisle_log_event ' , Visualizer_Plugin::NAME , sprintf ( 'Unable to create directory %s ' , $ dir ), 'error ' , __FILE__ , __LINE__ );
437
458
return $ default ;
@@ -441,6 +462,7 @@ protected function get_user_customization_js() {
441
462
// if file does not exist, copy.
442
463
if ( ! $ wp_filesystem ->exists ( $ file ) ) {
443
464
$ src = str_replace ( ABSPATH , $ wp_filesystem ->abspath (), VISUALIZER_ABSPATH . '/js/customization.js ' );
465
+ // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
444
466
if ( ( $ done = $ wp_filesystem ->copy ( $ src , $ file ) ) === false ) {
445
467
do_action ( 'themeisle_log_event ' , Visualizer_Plugin::NAME , sprintf ( 'Unable to copy file %s to %s ' , $ src , $ file ), 'error ' , __FILE__ , __LINE__ );
446
468
return $ default ;
0 commit comments