PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 2.2.0
Visualizer – Tables & Charts Manager with Built-in AI Generator v2.2.0
4.0.8 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 All 149 releases
← All changes | classes/Visualizer/Module/Chart.php +109 -139 2.1.92.2.0 View file →
@@ -72,14 +72,16 @@
72 72 public function getCharts() {
73 73 $query_args = array(
74 74 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
75 75 'posts_per_page' => 9,
76 - 'paged' => filter_input( INPUT_GET, 'page', FILTER_VALIDATE_INT, array(
77 - 'options' => array(
78 - 'min_range' => 1,
79 - 'default' => 1,
80 - ),
81 - ) ),
76 + 'paged' => filter_input(
77 + INPUT_GET, 'page', FILTER_VALIDATE_INT, array(
78 + 'options' => array(
79 + 'min_range' => 1,
80 + 'default' => 1,
81 + ),
82 + )
83 + ),
82 84 );
83 85 $filter = filter_input( INPUT_GET, 's', FILTER_SANITIZE_STRING );
84 86 if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes() ) ) {
85 87 $query_args['meta_query'] = array(
@@ -97,13 +99,15 @@
97 99 $chart_data = $this->_getChartArray( $chart );
98 100 $chart_data['id'] = $chart->ID;
99 101 $charts[] = $chart_data;
100 102 }
101 - self::_sendResponse( array(
102 - 'success' => true,
103 - 'data' => $charts,
104 - 'total' => $query->max_num_pages,
105 - ) );
103 + self::_sendResponse(
104 + array(
105 + 'success' => true,
106 + 'data' => $charts,
107 + 'total' => $query->max_num_pages,
108 + )
109 + );
106 110 }
107 111
108 112 /**
109 113 * Returns chart data required for rendering.
@@ -162,13 +166,15 @@
162 166 $chart_id = $success = false;
163 167 $nonce = wp_verify_nonce( filter_input( $input_method, 'nonce' ) );
164 168 $capable = current_user_can( 'delete_posts' );
165 169 if ( $nonce && $capable ) {
166 - $chart_id = filter_input( $input_method, 'chart', FILTER_VALIDATE_INT, array(
167 - 'options' => array(
168 - 'min_range' => 1,
169 - ),
170 - ) );
170 + $chart_id = filter_input(
171 + $input_method, 'chart', FILTER_VALIDATE_INT, array(
172 + 'options' => array(
173 + 'min_range' => 1,
174 + ),
175 + )
176 + );
171 177 if ( $chart_id ) {
172 178 $chart = get_post( $chart_id );
173 179 $success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
174 180 }
@@ -176,11 +182,13 @@
176 182 if ( $success ) {
177 183 wp_delete_post( $chart_id, true );
178 184 }
179 185 if ( $is_post ) {
180 - self::_sendResponse( array(
181 - 'success' => $success,
182 - ) );
186 + self::_sendResponse(
187 + array(
188 + 'success' => $success,
189 + )
190 + );
183 191 }
184 192 wp_redirect( wp_get_referer() );
185 193 exit;
186 194 }
@@ -200,23 +208,27 @@
200 208 if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
201 209 $default_type = 'line';
202 210 $source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $default_type . '.csv' );
203 211 $source->fetch();
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 - ) );
212 + $chart_id = wp_insert_post(
213 + array(
214 + 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
215 + 'post_title' => 'Visualization',
216 + 'post_author' => get_current_user_id(),
217 + 'post_status' => 'auto-draft',
218 + 'post_content' => $source->getData(),
219 + )
220 + );
211 221 if ( $chart_id && ! is_wp_error( $chart_id ) ) {
212 222 add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, $default_type );
213 223 add_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 1 );
214 224 add_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
215 225 add_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
216 - add_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, array(
217 - 'focusTarget' => 'datum',
218 - ) );
226 + add_post_meta(
227 + $chart_id, Visualizer_Plugin::CF_SETTINGS, array(
228 + 'focusTarget' => 'datum',
229 + )
230 + );
219 231 }
220 232 wp_redirect( add_query_arg( 'chart', (int) $chart_id ) );
221 233 defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
222 234 }
@@ -224,17 +236,21 @@
224 236 wp_register_style( 'visualizer-frame', VISUALIZER_ABSURL . 'css/frame.css', array(), Visualizer_Plugin::VERSION );
225 237 wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'jquery' ), Visualizer_Plugin::VERSION, true );
226 238 wp_register_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true );
227 239 wp_register_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true );
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 );
240 + wp_register_script(
241 + 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array(
242 + 'google-jsapi-old',
243 + 'google-jsapi-new',
244 + 'visualizer-frame',
245 + ), Visualizer_Plugin::VERSION, true
246 + );
247 + wp_register_script(
248 + 'visualizer-preview', VISUALIZER_ABSURL . 'js/preview.js', array(
249 + 'wp-color-picker',
250 + 'visualizer-render',
251 + ), Visualizer_Plugin::VERSION, true
252 + );
237 253 // added by Ash/Upwork
238 254 if ( VISUALIZER_PRO ) {
239 255 global $Visualizer_Pro;
240 256 $Visualizer_Pro->_addScriptsAndStyles();
@@ -292,17 +308,19 @@
292 308 wp_enqueue_style( 'wp-color-picker' );
293 309 wp_enqueue_style( 'visualizer-frame' );
294 310 wp_enqueue_script( 'visualizer-preview' );
295 311 wp_enqueue_script( 'visualizer-render' );
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 - ) );
312 + wp_localize_script(
313 + 'visualizer-render', 'visualizer', array(
314 + 'l10n' => array(
315 + 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ),
316 + ),
317 + 'charts' => array(
318 + 'canvas' => $data,
319 + ),
320 + 'map_api_key' => get_option( 'visualizer-map-api-key' ),
321 + )
322 + );
305 323 $render = new Visualizer_Render_Page_Data();
306 324 $render->chart = $this->_chart;
307 325 $render->type = $data['type'];
308 326 $render->sidebar = $sidebar;
@@ -440,13 +458,15 @@
440 458 $chart_id = $success = false;
441 459 $nonce = wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ), Visualizer_Plugin::ACTION_CLONE_CHART );
442 460 $capable = current_user_can( 'edit_posts' );
443 461 if ( $nonce && $capable ) {
444 - $chart_id = filter_input( INPUT_GET, 'chart', FILTER_VALIDATE_INT, array(
445 - 'options' => array(
446 - 'min_range' => 1,
447 - ),
448 - ) );
462 + $chart_id = filter_input(
463 + INPUT_GET, 'chart', FILTER_VALIDATE_INT, array(
464 + 'options' => array(
465 + 'min_range' => 1,
466 + ),
467 + )
468 + );
449 469 if ( $chart_id ) {
450 470 $chart = get_post( $chart_id );
451 471 $success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
452 472 }
@@ -452,15 +472,17 @@
452 472 }
453 473 }
454 474 $redirect = wp_get_referer();
455 475 if ( $success ) {
456 - $new_chart_id = wp_insert_post( array(
457 - 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
458 - 'post_title' => 'Visualization',
459 - 'post_author' => get_current_user_id(),
460 - 'post_status' => $chart->post_status,
461 - 'post_content' => $chart->post_content,
462 - ) );
476 + $new_chart_id = wp_insert_post(
477 + array(
478 + 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
479 + 'post_title' => 'Visualization',
480 + 'post_author' => get_current_user_id(),
481 + 'post_status' => $chart->post_status,
482 + 'post_content' => $chart->post_content,
483 + )
484 + );
463 485 if ( $new_chart_id && ! is_wp_error( $new_chart_id ) ) {
464 486 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_CHART_TYPE, get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true ) );
465 487 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, get_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, true ) );
466 488 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SOURCE, get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) );
@@ -465,12 +487,14 @@
465 487 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, get_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, true ) );
466 488 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SOURCE, get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) );
467 489 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SERIES, get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true ) );
468 490 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SETTINGS, get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true ) );
469 - $redirect = add_query_arg( array(
470 - 'page' => 'visualizer',
471 - 'type' => filter_input( INPUT_GET, 'type' ),
472 - ), admin_url( 'upload.php' ) );
491 + $redirect = add_query_arg(
492 + array(
493 + 'page' => 'visualizer',
494 + 'type' => filter_input( INPUT_GET, 'type' ),
495 + ), admin_url( 'upload.php' )
496 + );
473 497 }
474 498 }
475 499 wp_redirect( $redirect );
476 500 exit;
@@ -484,81 +508,25 @@
484 508 * @access public
485 509 */
486 510 public function exportData() {
487 511 check_ajax_referer( Visualizer_Plugin::ACTION_EXPORT_DATA . Visualizer_Plugin::VERSION, 'security' );
488 - $chart_id = $success = false;
489 512 $capable = current_user_can( 'edit_posts' );
490 513 if ( $capable ) {
491 - $chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT, array(
492 - 'options' => array(
493 - 'min_range' => 1,
494 - ),
495 - ) ) : '';
514 + $chart_id = isset( $_GET['chart'] ) ? filter_var(
515 + $_GET['chart'], FILTER_VALIDATE_INT, array(
516 + 'options' => array(
517 + 'min_range' => 1,
518 + ),
519 + )
520 + ) : '';
496 521 if ( $chart_id ) {
497 - $chart = get_post( $chart_id );
498 - $success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
522 + $data = $this->_getDataAs( $chart_id, 'csv' );
523 + if ( $data ) {
524 + echo wp_send_json_success( $data );
525 + }
499 526 }
500 527 }
501 - if ( $success ) {
502 - $settings = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true );
503 - $filename = isset( $settings['title'] ) ? $settings['title'] : '';
504 - if ( empty( $filename ) ) {
505 - $filename = 'export.csv';
506 - } else {
507 - $filename .= '.csv';
508 - }
509 - $rows = array();
510 - $series = get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true );
511 - $data = unserialize( $chart->post_content );
512 - if ( ! empty( $series ) ) {
513 - $row = array();
514 - foreach ( $series as $array ) {
515 - $row[] = $array['label'];
516 - }
517 - $rows[] = $row;
518 - $row = array();
519 - foreach ( $series as $array ) {
520 - $row[] = $array['type'];
521 - }
522 - $rows[] = $row;
523 - }
524 - if ( ! empty( $data ) ) {
525 - foreach ( $data as $array ) {
526 - // ignore strings
527 - if ( ! is_array( $array ) ) {
528 - continue;
529 - }
530 - // if this is an array of arrays...
531 - if ( is_array( $array[0] ) ) {
532 - foreach ( $array as $arr ) {
533 - $rows[] = $arr;
534 - }
535 - } else {
536 - // just an array
537 - $rows[] = $array;
538 - }
539 - }
540 - }
541 - $fp = tmpfile();
542 - // support for MS Excel
543 - fprintf( $fp, $bom = ( chr( 0xEF ) . chr( 0xBB ) . chr( 0xBF ) ) );
544 - foreach ( $rows as $row ) {
545 - fputcsv( $fp, $row );
546 - }
547 - rewind( $fp );
548 - $csv = '';
549 - while ( ( $array = fgetcsv( $fp ) ) !== false ) {
550 - if ( strlen( $csv ) > 0 ) {
551 - $csv .= PHP_EOL;
552 - }
553 - $csv .= implode( ',', $array );
554 - }
555 - fclose( $fp );
556 - echo wp_send_json_success( array(
557 - 'csv' => $csv,
558 - 'name' => $filename,
559 - ) );
560 - }// End if().
528 +
561 529 defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
562 530 }
563 531
564 532 /**
@@ -575,16 +543,18 @@
575 543 $render->type = $data['type'];
576 544 unset( $data['settings']['width'], $data['settings']['height'] );
577 545 wp_enqueue_style( 'visualizer-frame' );
578 546 wp_enqueue_script( 'visualizer-render' );
579 - wp_localize_script( 'visualizer-render', 'visualizer', array(
580 - 'l10n' => array(
581 - 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ),
582 - ),
583 - 'charts' => array(
584 - 'canvas' => $data,
585 - ),
586 - ) );
547 + wp_localize_script(
548 + 'visualizer-render', 'visualizer', array(
549 + 'l10n' => array(
550 + 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ),
551 + ),
552 + 'charts' => array(
553 + 'canvas' => $data,
554 + ),
555 + )
556 + );
587 557 // Added by Ash/Upwork
588 558 if ( VISUALIZER_PRO ) {
589 559 global $Visualizer_Pro;
590 560 $Visualizer_Pro->_enqueueScriptsAndStyles( $data );