PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 2.0.3
Visualizer – Tables & Charts Manager with Built-in AI Generator v2.0.3
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 +148 -186 3.0.82.0.3 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
@@ -300,11 +257,8 @@
300 257 /**
301 258 * Handle data and settings page
302 259 */
303 260 private function _handleDataAndSettingsPage() {
304 - if ( isset( $_POST['map_api_key'] ) ) {
305 - update_option( 'visualizer-map-api-key', $_POST['map_api_key'] );
306 - }
307 261 if ( $_SERVER['REQUEST_METHOD'] == 'POST' && isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'] ) ) {
308 262 if ( $this->_chart->post_status == 'auto-draft' ) {
309 263 $this->_chart->post_status = 'publish';
310 264 wp_update_post( $this->_chart->to_array() );
@@ -335,30 +289,16 @@
335 289 wp_enqueue_style( 'wp-color-picker' );
336 290 wp_enqueue_style( 'visualizer-frame' );
337 291 wp_enqueue_script( 'visualizer-preview' );
338 292 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 - );
293 + wp_localize_script( 'visualizer-render', 'visualizer', array(
294 + 'l10n' => array(
295 + 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ),
296 + ),
297 + 'charts' => array(
298 + 'canvas' => $data,
299 + ),
300 + ) );
361 301 $render = new Visualizer_Render_Page_Data();
362 302 $render->chart = $this->_chart;
363 303 $render->type = $data['type'];
364 304 $render->sidebar = $sidebar;
@@ -365,11 +305,8 @@
365 305 if ( filter_input( INPUT_GET, 'library', FILTER_VALIDATE_BOOLEAN ) ) {
366 306 $render->button = filter_input( INPUT_GET, 'action' ) == Visualizer_Plugin::ACTION_EDIT_CHART
367 307 ? esc_html__( 'Save Chart', 'visualizer' )
368 308 : 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 309 } else {
373 310 $render->button = esc_attr__( 'Insert Chart', 'visualizer' );
374 311 }
375 312 if ( VISUALIZER_PRO ) {
@@ -437,41 +374,23 @@
437 374 *
438 375 * @access public
439 376 */
440 377 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 -
445 378 // validate nonce
379 + // do not use filter_input as it does not work for phpunit test cases, use filter_var instead
446 380 if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'] ) ) {
447 - if ( ! $can_die ) {
448 - return;
449 - }
450 381 status_header( 403 );
451 382 exit;
452 383 }
453 -
454 384 // 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 385 $chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : '';
457 386 if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
458 - if ( ! $can_die ) {
459 - return;
460 - }
461 387 status_header( 400 );
462 388 exit;
463 389 }
464 -
465 390 if ( ! isset( $_POST['vz-import-time'] ) ) {
466 391 apply_filters( 'visualizer_pro_remove_schedule', $chart_id );
467 392 }
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 393 $source = null;
475 394 $render = new Visualizer_Render_Page_Update();
476 395 if ( isset( $_POST['remote_data'] ) && filter_var( $_POST['remote_data'], FILTER_VALIDATE_URL ) ) {
477 396 $source = new Visualizer_Source_Csv_Remote( $_POST['remote_data'] );
@@ -479,10 +398,12 @@
479 398 apply_filters( 'visualizer_pro_chart_schedule', $chart_id, $_POST['remote_data'], $_POST['vz-import-time'] );
480 399 }
481 400 } elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) {
482 401 $source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] );
402 + // Added by Ash/Upwork
483 403 } elseif ( isset( $_POST['chart_data'] ) && strlen( $_POST['chart_data'] ) > 0 ) {
484 404 $source = apply_filters( 'visualizer_pro_handle_chart_data', $_POST['chart_data'], '' );
405 + // Added by Ash/Upwork
485 406 } else {
486 407 $render->message = esc_html__( 'CSV file with chart data was not uploaded. Please, try again.', 'visualizer' );
487 408 }
488 409 if ( $source ) {
@@ -498,11 +419,8 @@
498 419 $render->message = esc_html__( 'CSV file is broken or invalid. Please, try again.', 'visualizer' );
499 420 }
500 421 }
501 422 $render->render();
502 - if ( ! $can_die ) {
503 - return;
504 - }
505 423 defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
506 424 }
507 425
508 426 /**
@@ -516,15 +434,13 @@
516 434 $chart_id = $success = false;
517 435 $nonce = wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ), Visualizer_Plugin::ACTION_CLONE_CHART );
518 436 $capable = current_user_can( 'edit_posts' );
519 437 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 - );
438 + $chart_id = filter_input( INPUT_GET, 'chart', FILTER_VALIDATE_INT, array(
439 + 'options' => array(
440 + 'min_range' => 1,
441 + ),
442 + ) );
527 443 if ( $chart_id ) {
528 444 $chart = get_post( $chart_id );
529 445 $success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
530 446 }
@@ -530,17 +446,15 @@
530 446 }
531 447 }
532 448 $redirect = wp_get_referer();
533 449 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 - );
450 + $new_chart_id = wp_insert_post( array(
451 + 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
452 + 'post_title' => 'Visualization',
453 + 'post_author' => get_current_user_id(),
454 + 'post_status' => $chart->post_status,
455 + 'post_content' => $chart->post_content,
456 + ) );
543 457 if ( $new_chart_id && ! is_wp_error( $new_chart_id ) ) {
544 458 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_CHART_TYPE, get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true ) );
545 459 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, get_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, true ) );
546 460 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SOURCE, get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) );
@@ -545,14 +459,12 @@
545 459 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, get_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, true ) );
546 460 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SOURCE, get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) );
547 461 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SERIES, get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true ) );
548 462 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 - );
463 + $redirect = add_query_arg( array(
464 + 'page' => 'visualizer',
465 + 'type' => filter_input( INPUT_GET, 'type' ),
466 + ), admin_url( 'upload.php' ) );
555 467 }
556 468 }
557 469 wp_redirect( $redirect );
558 470 exit;
@@ -566,25 +478,79 @@
566 478 * @access public
567 479 */
568 480 public function exportData() {
569 481 check_ajax_referer( Visualizer_Plugin::ACTION_EXPORT_DATA . Visualizer_Plugin::VERSION, 'security' );
482 + $chart_id = $success = false;
570 483 $capable = current_user_can( 'edit_posts' );
571 484 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 - ) : '';
485 + $chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT, array(
486 + 'options' => array(
487 + 'min_range' => 1,
488 + ),
489 + ) ) : '';
579 490 if ( $chart_id ) {
580 - $data = $this->_getDataAs( $chart_id, 'csv' );
581 - if ( $data ) {
582 - echo wp_send_json_success( $data );
491 + $chart = get_post( $chart_id );
492 + $success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
493 + }
494 + }
495 + if ( $success ) {
496 + $settings = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true );
497 + $filename = isset( $settings['title'] ) ? $settings['title'] : '';
498 + if ( empty( $filename ) ) {
499 + $filename = 'export.csv';
500 + } else {
501 + $filename .= '.csv';
502 + }
503 + $rows = array();
504 + $series = get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true );
505 + $data = unserialize( $chart->post_content );
506 + if ( ! empty( $series ) ) {
507 + $row = array();
508 + foreach ( $series as $array ) {
509 + $row[] = $array['label'];
583 510 }
511 + $rows[] = $row;
512 + $row = array();
513 + foreach ( $series as $array ) {
514 + $row[] = $array['type'];
515 + }
516 + $rows[] = $row;
584 517 }
585 - }
586 -
518 + if ( ! empty( $data ) ) {
519 + foreach ( $data as $array ) {
520 + // ignore strings
521 + if ( ! is_array( $array ) ) {
522 + continue;
523 + }
524 + // if this is an array of arrays...
525 + if ( is_array( $array[0] ) ) {
526 + foreach ( $array as $arr ) {
527 + $rows[] = $arr;
528 + }
529 + } else {
530 + // just an array
531 + $rows[] = $array;
532 + }
533 + }
534 + }
535 + $fp = tmpfile();
536 + foreach ( $rows as $row ) {
537 + fputcsv( $fp, $row );
538 + }
539 + rewind( $fp );
540 + $csv = '';
541 + while ( ( $array = fgetcsv( $fp ) ) !== false ) {
542 + if ( strlen( $csv ) > 0 ) {
543 + $csv .= PHP_EOL;
544 + }
545 + $csv .= implode( ',', $array );
546 + }
547 + fclose( $fp );
548 + echo wp_send_json_success( array(
549 + 'csv' => $csv,
550 + 'name' => $filename,
551 + ) );
552 + }// End if().
587 553 defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
588 554 }
589 555
590 556 /**
@@ -601,19 +567,16 @@
601 567 $render->type = $data['type'];
602 568 unset( $data['settings']['width'], $data['settings']['height'] );
603 569 wp_enqueue_style( 'visualizer-frame' );
604 570 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 - );
571 + wp_localize_script( 'visualizer-render', 'visualizer', array(
572 + 'l10n' => array(
573 + 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ),
574 + ),
575 + 'charts' => array(
576 + 'canvas' => $data,
577 + ),
578 + ) );
616 579 // Added by Ash/Upwork
617 580 if ( VISUALIZER_PRO ) {
618 581 global $Visualizer_Pro;
619 582 $Visualizer_Pro->_enqueueScriptsAndStyles( $data );
@@ -621,6 +584,5 @@
621 584 // Added by Ash/Upwork
622 585 $this->_addAction( 'admin_head', 'renderFlattrScript' );
623 586 wp_iframe( array( $render, 'render' ) );
624 587 }
625 -
626 588 }