PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 2.1.1
Visualizer – Tables & Charts Manager with Built-in AI Generator v2.1.1
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 3.10.4 All 148 releases
← All changes | classes/Visualizer/Module/Chart.php +152 -183 3.0.92.1.1 View file →
@@ -56,9 +56,11 @@
56 56 $this->_addAjaxAction( Visualizer_Plugin::ACTION_CREATE_CHART, 'renderChartPages' );
57 57 $this->_addAjaxAction( Visualizer_Plugin::ACTION_EDIT_CHART, 'renderChartPages' );
58 58 $this->_addAjaxAction( Visualizer_Plugin::ACTION_UPLOAD_DATA, 'uploadData' );
59 59 $this->_addAjaxAction( Visualizer_Plugin::ACTION_CLONE_CHART, 'cloneChart' );
60 + // Added by Ash/Upwork
60 61 $this->_addAjaxAction( Visualizer_Plugin::ACTION_EXPORT_DATA, 'exportData' );
62 + // Added by Ash/Upwork
61 63 }
62 64
63 65 /**
64 66 * Fetches charts from database.
@@ -70,23 +72,16 @@
70 72 public function getCharts() {
71 73 $query_args = array(
72 74 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
73 75 'posts_per_page' => 9,
74 - 'paged' => filter_input(
75 - INPUT_GET, 'page', FILTER_VALIDATE_INT, array(
76 - 'options' => array(
77 - 'min_range' => 1,
78 - 'default' => 1,
79 - ),
80 - )
81 - ),
76 + 'paged' => filter_input( INPUT_GET, 'page', FILTER_VALIDATE_INT, array(
77 + 'options' => array(
78 + 'min_range' => 1,
79 + 'default' => 1,
80 + ),
81 + ) ),
82 82 );
83 83 $filter = filter_input( INPUT_GET, 's', FILTER_SANITIZE_STRING );
84 - if ( empty( $filter ) ) {
85 - // 'filter' is from the modal from the add media button.
86 - $filter = filter_input( INPUT_GET, 'filter', FILTER_SANITIZE_STRING );
87 - }
88 -
89 84 if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes() ) ) {
90 85 $query_args['meta_query'] = array(
91 86 array(
92 87 'key' => Visualizer_Plugin::CF_CHART_TYPE,
@@ -102,15 +97,13 @@
102 97 $chart_data = $this->_getChartArray( $chart );
103 98 $chart_data['id'] = $chart->ID;
104 99 $charts[] = $chart_data;
105 100 }
106 - self::_sendResponse(
107 - array(
108 - 'success' => true,
109 - 'data' => $charts,
110 - 'total' => $query->max_num_pages,
111 - )
112 - );
101 + self::_sendResponse( array(
102 + 'success' => true,
103 + 'data' => $charts,
104 + 'total' => $query->max_num_pages,
105 + ) );
113 106 }
114 107
115 108 /**
116 109 * Returns chart data required for rendering.
@@ -169,15 +162,13 @@
169 162 $chart_id = $success = false;
170 163 $nonce = wp_verify_nonce( filter_input( $input_method, 'nonce' ) );
171 164 $capable = current_user_can( 'delete_posts' );
172 165 if ( $nonce && $capable ) {
173 - $chart_id = filter_input(
174 - $input_method, 'chart', FILTER_VALIDATE_INT, array(
175 - 'options' => array(
176 - 'min_range' => 1,
177 - ),
178 - )
179 - );
166 + $chart_id = filter_input( $input_method, 'chart', FILTER_VALIDATE_INT, array(
167 + 'options' => array(
168 + 'min_range' => 1,
169 + ),
170 + ) );
180 171 if ( $chart_id ) {
181 172 $chart = get_post( $chart_id );
182 173 $success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
183 174 }
@@ -185,13 +176,11 @@
185 176 if ( $success ) {
186 177 wp_delete_post( $chart_id, true );
187 178 }
188 179 if ( $is_post ) {
189 - self::_sendResponse(
190 - array(
191 - 'success' => $success,
192 - )
193 - );
180 + self::_sendResponse( array(
181 + 'success' => $success,
182 + ) );
194 183 }
195 184 wp_redirect( wp_get_referer() );
196 185 exit;
197 186 }
@@ -208,56 +197,44 @@
208 197 defined( 'IFRAME_REQUEST' ) || define( 'IFRAME_REQUEST', 1 );
209 198 // check chart, if chart not exists, will create new one and redirects to the same page with proper chart id
210 199 $chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : '';
211 200 if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
212 - $default_type = isset( $_GET['type'] ) && ! empty( $_GET['type'] ) ? $_GET['type'] : 'line';
201 + $default_type = 'line';
213 202 $source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $default_type . '.csv' );
214 203 $source->fetch();
215 - $chart_id = wp_insert_post(
216 - array(
217 - 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
218 - 'post_title' => 'Visualization',
219 - 'post_author' => get_current_user_id(),
220 - 'post_status' => 'auto-draft',
221 - 'post_content' => $source->getData(),
222 - )
223 - );
204 + $chart_id = wp_insert_post( array(
205 + 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
206 + 'post_title' => 'Visualization',
207 + 'post_author' => get_current_user_id(),
208 + 'post_status' => 'auto-draft',
209 + 'post_content' => $source->getData(),
210 + ) );
224 211 if ( $chart_id && ! is_wp_error( $chart_id ) ) {
225 212 add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, $default_type );
226 213 add_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 1 );
227 214 add_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
228 215 add_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
229 - add_post_meta(
230 - $chart_id, Visualizer_Plugin::CF_SETTINGS, array(
231 - 'focusTarget' => 'datum',
232 - )
233 - );
234 - do_action( 'visualizer_pro_new_chart_defaults', $chart_id );
216 + add_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, array(
217 + 'focusTarget' => 'datum',
218 + ) );
235 219 }
236 220 wp_redirect( add_query_arg( 'chart', (int) $chart_id ) );
237 221 defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
238 222 }
239 223 // enqueue and register scripts and styles
240 - wp_register_script( 'visualizer-chosen', VISUALIZER_ABSURL . 'js/lib/chosen.jquery.min.js', array( 'jquery' ), Visualizer_Plugin::VERSION );
241 - wp_register_style( 'visualizer-chosen', VISUALIZER_ABSURL . 'css/lib/chosen.min.css', array(), Visualizer_Plugin::VERSION );
242 -
243 - wp_register_style( 'visualizer-frame', VISUALIZER_ABSURL . 'css/frame.css', array( 'visualizer-chosen' ), Visualizer_Plugin::VERSION );
244 - wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'visualizer-chosen' ), Visualizer_Plugin::VERSION, true );
224 + wp_register_style( 'visualizer-frame', VISUALIZER_ABSURL . 'css/frame.css', array(), Visualizer_Plugin::VERSION );
225 + wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'jquery' ), Visualizer_Plugin::VERSION, true );
245 226 wp_register_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true );
246 227 wp_register_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true );
247 - wp_register_script(
248 - 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array(
249 - 'google-jsapi-old',
250 - 'google-jsapi-new',
251 - 'visualizer-frame',
252 - ), Visualizer_Plugin::VERSION, true
253 - );
254 - wp_register_script(
255 - 'visualizer-preview', VISUALIZER_ABSURL . 'js/preview.js', array(
256 - 'wp-color-picker',
257 - 'visualizer-render',
258 - ), Visualizer_Plugin::VERSION, true
259 - );
228 + wp_register_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array(
229 + 'google-jsapi-old',
230 + 'google-jsapi-new',
231 + 'visualizer-frame',
232 + ), Visualizer_Plugin::VERSION, true );
233 + wp_register_script( 'visualizer-preview', VISUALIZER_ABSURL . 'js/preview.js', array(
234 + 'wp-color-picker',
235 + 'visualizer-render',
236 + ), Visualizer_Plugin::VERSION, true );
260 237 // added by Ash/Upwork
261 238 if ( VISUALIZER_PRO ) {
262 239 global $Visualizer_Pro;
263 240 $Visualizer_Pro->_addScriptsAndStyles();
@@ -263,37 +240,17 @@
263 240 $Visualizer_Pro->_addScriptsAndStyles();
264 241 }
265 242 // dispatch pages
266 243 $this->_chart = get_post( $chart_id );
267 - $tab = isset( $_GET['tab'] ) && ! empty( $_GET['tab'] ) ? $_GET['tab'] : 'visualizer';
268 -
269 - // skip chart type pages only for existing charts.
270 - if ( VISUALIZER_SKIP_CHART_TYPE_PAGE && 'auto-draft' !== $this->_chart->post_status && ( ! empty( $_GET['tab'] ) && 'visualizer' === $_GET['tab'] ) ) {
271 - $tab = 'settings';
272 - }
273 -
274 - if ( isset( $_POST['cancel'] ) && 1 === intval( $_POST['cancel'] ) ) {
275 - // if the cancel button is clicked.
276 - $this->undoRevisions( $chart_id, true );
277 - } elseif ( isset( $_POST['save'] ) && 1 === intval( $_POST['save'] ) ) {
278 - // if the save button is clicked.
279 - $this->undoRevisions( $chart_id, false );
280 - } else {
281 - // if the edit button is clicked.
282 - $this->_chart = $this->handleExistingRevisions( $chart_id, $this->_chart );
283 - }
284 -
285 - switch ( $tab ) {
244 + switch ( isset( $_GET['tab'] ) ? $_GET['tab'] : '' ) {
286 245 case 'settings':
246 + // changed by Ash/Upwork
287 247 $this->_handleDataAndSettingsPage();
288 248 break;
289 - case 'type': // fall through.
290 - case 'visualizer': // fall through.
249 + case 'type':
250 + default:
291 251 $this->_handleTypesPage();
292 252 break;
293 - default:
294 - do_action( 'visualizer_pro_handle_tab', $tab, $this->_chart );
295 - break;
296 253 }
297 254 defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
298 255 }
299 256
@@ -335,30 +292,17 @@
335 292 wp_enqueue_style( 'wp-color-picker' );
336 293 wp_enqueue_style( 'visualizer-frame' );
337 294 wp_enqueue_script( 'visualizer-preview' );
338 295 wp_enqueue_script( 'visualizer-render' );
339 - wp_localize_script(
340 - 'visualizer-render', 'visualizer', array(
341 - 'l10n' => array(
342 - 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ),
343 - 'loading' => esc_html__( 'Loading...', 'visualizer' ),
344 - ),
345 - 'charts' => array(
346 - 'canvas' => $data,
347 - ),
348 - 'language' => $this->get_language(),
349 - 'map_api_key' => get_option( 'visualizer-map-api-key' ),
350 - 'ajax' => array(
351 - 'url' => admin_url( 'admin-ajax.php' ),
352 - 'nonces' => array(
353 - 'permissions' => wp_create_nonce( Visualizer_Plugin::ACTION_FETCH_PERMISSIONS_DATA ),
354 - ),
355 - 'actions' => array(
356 - 'permissions' => Visualizer_Plugin::ACTION_FETCH_PERMISSIONS_DATA,
357 - ),
358 - ),
359 - )
360 - );
296 + wp_localize_script( 'visualizer-render', 'visualizer', array(
297 + 'l10n' => array(
298 + 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ),
299 + ),
300 + 'charts' => array(
301 + 'canvas' => $data,
302 + ),
303 + 'map_api_key' => get_option( 'visualizer-map-api-key' ),
304 + ) );
361 305 $render = new Visualizer_Render_Page_Data();
362 306 $render->chart = $this->_chart;
363 307 $render->type = $data['type'];
364 308 $render->sidebar = $sidebar;
@@ -365,11 +309,8 @@
365 309 if ( filter_input( INPUT_GET, 'library', FILTER_VALIDATE_BOOLEAN ) ) {
366 310 $render->button = filter_input( INPUT_GET, 'action' ) == Visualizer_Plugin::ACTION_EDIT_CHART
367 311 ? esc_html__( 'Save Chart', 'visualizer' )
368 312 : esc_html__( 'Create Chart', 'visualizer' );
369 - if ( filter_input( INPUT_GET, 'action' ) == Visualizer_Plugin::ACTION_EDIT_CHART ) {
370 - $render->cancel_button = esc_html__( 'Cancel', 'visualizer' );
371 - }
372 313 } else {
373 314 $render->button = esc_attr__( 'Insert Chart', 'visualizer' );
374 315 }
375 316 if ( VISUALIZER_PRO ) {
@@ -437,41 +378,24 @@
437 378 *
438 379 * @access public
439 380 */
440 381 public function uploadData() {
441 - // if this is being called internally from pro and VISUALIZER_DO_NOT_DIE is set.
442 - // otherwise, assume this is a normal web request.
443 - $can_die = ! ( defined( 'VISUALIZER_DO_NOT_DIE' ) && VISUALIZER_DO_NOT_DIE );
444 -
382 + error_log( 'in uploadData ' . print_r( $_GET,true ) . print_r( $_POST,true ) );
445 383 // validate nonce
384 + // do not use filter_input as it does not work for phpunit test cases, use filter_var instead
446 385 if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'] ) ) {
447 - if ( ! $can_die ) {
448 - return;
449 - }
450 386 status_header( 403 );
451 387 exit;
452 388 }
453 -
454 389 // check chart, if chart exists
455 - // do not use filter_input as it does not work for phpunit test cases, use filter_var instead
456 390 $chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : '';
457 391 if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
458 - if ( ! $can_die ) {
459 - return;
460 - }
461 392 status_header( 400 );
462 393 exit;
463 394 }
464 -
465 395 if ( ! isset( $_POST['vz-import-time'] ) ) {
466 396 apply_filters( 'visualizer_pro_remove_schedule', $chart_id );
467 397 }
468 -
469 - if ( ! isset( $_POST['chart_data_src'] ) || Visualizer_Plugin::CF_SOURCE_FILTER !== $_POST['chart_data_src'] ) {
470 - // delete the filters in case this chart is being uploaded from other data sources
471 - delete_post_meta( $chart_id, 'visualizer-filter-config' );
472 - }
473 -
474 398 $source = null;
475 399 $render = new Visualizer_Render_Page_Update();
476 400 if ( isset( $_POST['remote_data'] ) && filter_var( $_POST['remote_data'], FILTER_VALIDATE_URL ) ) {
477 401 $source = new Visualizer_Source_Csv_Remote( $_POST['remote_data'] );
@@ -479,10 +403,12 @@
479 403 apply_filters( 'visualizer_pro_chart_schedule', $chart_id, $_POST['remote_data'], $_POST['vz-import-time'] );
480 404 }
481 405 } elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) {
482 406 $source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] );
407 + // Added by Ash/Upwork
483 408 } elseif ( isset( $_POST['chart_data'] ) && strlen( $_POST['chart_data'] ) > 0 ) {
484 409 $source = apply_filters( 'visualizer_pro_handle_chart_data', $_POST['chart_data'], '' );
410 + // Added by Ash/Upwork
485 411 } else {
486 412 $render->message = esc_html__( 'CSV file with chart data was not uploaded. Please, try again.', 'visualizer' );
487 413 }
488 414 if ( $source ) {
@@ -498,12 +424,11 @@
498 424 $render->message = esc_html__( 'CSV file is broken or invalid. Please, try again.', 'visualizer' );
499 425 }
500 426 }
501 427 $render->render();
502 - if ( ! $can_die ) {
503 - return;
428 + if ( ! ( defined( 'VISUALIZER_DO_NOT_DIE' ) && VISUALIZER_DO_NOT_DIE ) ) {
429 + defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
504 430 }
505 - defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
506 431 }
507 432
508 433 /**
509 434 * Clones the chart.
@@ -516,15 +441,13 @@
516 441 $chart_id = $success = false;
517 442 $nonce = wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ), Visualizer_Plugin::ACTION_CLONE_CHART );
518 443 $capable = current_user_can( 'edit_posts' );
519 444 if ( $nonce && $capable ) {
520 - $chart_id = filter_input(
521 - INPUT_GET, 'chart', FILTER_VALIDATE_INT, array(
522 - 'options' => array(
523 - 'min_range' => 1,
524 - ),
525 - )
526 - );
445 + $chart_id = filter_input( INPUT_GET, 'chart', FILTER_VALIDATE_INT, array(
446 + 'options' => array(
447 + 'min_range' => 1,
448 + ),
449 + ) );
527 450 if ( $chart_id ) {
528 451 $chart = get_post( $chart_id );
529 452 $success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
530 453 }
@@ -530,17 +453,15 @@
530 453 }
531 454 }
532 455 $redirect = wp_get_referer();
533 456 if ( $success ) {
534 - $new_chart_id = wp_insert_post(
535 - array(
536 - 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
537 - 'post_title' => 'Visualization',
538 - 'post_author' => get_current_user_id(),
539 - 'post_status' => $chart->post_status,
540 - 'post_content' => $chart->post_content,
541 - )
542 - );
457 + $new_chart_id = wp_insert_post( array(
458 + 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
459 + 'post_title' => 'Visualization',
460 + 'post_author' => get_current_user_id(),
461 + 'post_status' => $chart->post_status,
462 + 'post_content' => $chart->post_content,
463 + ) );
543 464 if ( $new_chart_id && ! is_wp_error( $new_chart_id ) ) {
544 465 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_CHART_TYPE, get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true ) );
545 466 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, get_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, true ) );
546 467 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SOURCE, get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) );
@@ -545,14 +466,12 @@
545 466 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, get_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, true ) );
546 467 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SOURCE, get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) );
547 468 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SERIES, get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true ) );
548 469 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SETTINGS, get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true ) );
549 - $redirect = add_query_arg(
550 - array(
551 - 'page' => 'visualizer',
552 - 'type' => filter_input( INPUT_GET, 'type' ),
553 - ), admin_url( 'upload.php' )
554 - );
470 + $redirect = add_query_arg( array(
471 + 'page' => 'visualizer',
472 + 'type' => filter_input( INPUT_GET, 'type' ),
473 + ), admin_url( 'upload.php' ) );
555 474 }
556 475 }
557 476 wp_redirect( $redirect );
558 477 exit;
@@ -566,25 +485,79 @@
566 485 * @access public
567 486 */
568 487 public function exportData() {
569 488 check_ajax_referer( Visualizer_Plugin::ACTION_EXPORT_DATA . Visualizer_Plugin::VERSION, 'security' );
489 + $chart_id = $success = false;
570 490 $capable = current_user_can( 'edit_posts' );
571 491 if ( $capable ) {
572 - $chart_id = isset( $_GET['chart'] ) ? filter_var(
573 - $_GET['chart'], FILTER_VALIDATE_INT, array(
574 - 'options' => array(
575 - 'min_range' => 1,
576 - ),
577 - )
578 - ) : '';
492 + $chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT, array(
493 + 'options' => array(
494 + 'min_range' => 1,
495 + ),
496 + ) ) : '';
579 497 if ( $chart_id ) {
580 - $data = $this->_getDataAs( $chart_id, 'csv' );
581 - if ( $data ) {
582 - echo wp_send_json_success( $data );
498 + $chart = get_post( $chart_id );
499 + $success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
500 + }
501 + }
502 + if ( $success ) {
503 + $settings = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true );
504 + $filename = isset( $settings['title'] ) ? $settings['title'] : '';
505 + if ( empty( $filename ) ) {
506 + $filename = 'export.csv';
507 + } else {
508 + $filename .= '.csv';
509 + }
510 + $rows = array();
511 + $series = get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true );
512 + $data = unserialize( $chart->post_content );
513 + if ( ! empty( $series ) ) {
514 + $row = array();
515 + foreach ( $series as $array ) {
516 + $row[] = $array['label'];
583 517 }
518 + $rows[] = $row;
519 + $row = array();
520 + foreach ( $series as $array ) {
521 + $row[] = $array['type'];
522 + }
523 + $rows[] = $row;
584 524 }
585 - }
586 -
525 + if ( ! empty( $data ) ) {
526 + foreach ( $data as $array ) {
527 + // ignore strings
528 + if ( ! is_array( $array ) ) {
529 + continue;
530 + }
531 + // if this is an array of arrays...
532 + if ( is_array( $array[0] ) ) {
533 + foreach ( $array as $arr ) {
534 + $rows[] = $arr;
535 + }
536 + } else {
537 + // just an array
538 + $rows[] = $array;
539 + }
540 + }
541 + }
542 + $fp = tmpfile();
543 + foreach ( $rows as $row ) {
544 + fputcsv( $fp, $row );
545 + }
546 + rewind( $fp );
547 + $csv = '';
548 + while ( ( $array = fgetcsv( $fp ) ) !== false ) {
549 + if ( strlen( $csv ) > 0 ) {
550 + $csv .= PHP_EOL;
551 + }
552 + $csv .= implode( ',', $array );
553 + }
554 + fclose( $fp );
555 + echo wp_send_json_success( array(
556 + 'csv' => $csv,
557 + 'name' => $filename,
558 + ) );
559 + }// End if().
587 560 defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
588 561 }
589 562
590 563 /**
@@ -601,19 +574,16 @@
601 574 $render->type = $data['type'];
602 575 unset( $data['settings']['width'], $data['settings']['height'] );
603 576 wp_enqueue_style( 'visualizer-frame' );
604 577 wp_enqueue_script( 'visualizer-render' );
605 - wp_localize_script(
606 - 'visualizer-render', 'visualizer', array(
607 - 'l10n' => array(
608 - 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ),
609 - 'loading' => esc_html__( 'Loading...', 'visualizer' ),
610 - ),
611 - 'charts' => array(
612 - 'canvas' => $data,
613 - ),
614 - )
615 - );
578 + wp_localize_script( 'visualizer-render', 'visualizer', array(
579 + 'l10n' => array(
580 + 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ),
581 + ),
582 + 'charts' => array(
583 + 'canvas' => $data,
584 + ),
585 + ) );
616 586 // Added by Ash/Upwork
617 587 if ( VISUALIZER_PRO ) {
618 588 global $Visualizer_Pro;
619 589 $Visualizer_Pro->_enqueueScriptsAndStyles( $data );
@@ -621,6 +591,5 @@
621 591 // Added by Ash/Upwork
622 592 $this->_addAction( 'admin_head', 'renderFlattrScript' );
623 593 wp_iframe( array( $render, 'render' ) );
624 594 }
625 -
626 595 }