PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.3.2
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.3.2
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/Gutenberg/Block.php +52 -454 3.10.133.3.2 View file →
@@ -66,10 +66,8 @@
66 66 /**
67 67 * Enqueue front end and editor JavaScript and CSS
68 68 */
69 69 public function enqueue_gutenberg_scripts() {
70 - global $wp_version, $pagenow;
71 -
72 70 $blockPath = VISUALIZER_ABSURL . 'classes/Visualizer/Gutenberg/build/block.js';
73 71 $handsontableJS = VISUALIZER_ABSURL . 'classes/Visualizer/Gutenberg/build/handsontable.js';
74 72 $stylePath = VISUALIZER_ABSURL . 'classes/Visualizer/Gutenberg/build/block.css';
75 73 $handsontableCSS = VISUALIZER_ABSURL . 'classes/Visualizer/Gutenberg/build/handsontable.css';
@@ -74,24 +72,16 @@
74 72 $stylePath = VISUALIZER_ABSURL . 'classes/Visualizer/Gutenberg/build/block.css';
75 73 $handsontableCSS = VISUALIZER_ABSURL . 'classes/Visualizer/Gutenberg/build/handsontable.css';
76 74
77 75 if ( VISUALIZER_TEST_JS_CUSTOMIZATION ) {
78 - $version = filemtime( VISUALIZER_ABSPATH . '/classes/Visualizer/Gutenberg/build/block.js' );
76 + $version = filemtime( VISUALIZER_ABSPATH . 'classes/Visualizer/Gutenberg/build/block.js' );
79 77 } else {
80 78 $version = $this->version;
81 79 }
82 80
83 - if ( ! wp_script_is( 'visualizer-datatables', 'registered' ) ) {
84 - wp_register_script( 'visualizer-datatables', VISUALIZER_ABSURL . 'js/lib/datatables.min.js', array( 'jquery-ui-core' ), Visualizer_Plugin::VERSION );
85 - }
86 -
87 - if ( ! wp_style_is( 'visualizer-datatables', 'registered' ) ) {
88 - wp_register_style( 'visualizer-datatables', VISUALIZER_ABSURL . 'css/lib/datatables.min.css', array(), Visualizer_Plugin::VERSION );
89 - }
90 -
91 81 // Enqueue the bundled block JS file
92 82 wp_enqueue_script( 'handsontable', $handsontableJS );
93 - wp_enqueue_script( 'visualizer-gutenberg-block', $blockPath, array( 'wp-api', 'handsontable', 'visualizer-datatables', 'moment', 'lodash' ), $version, true );
83 + wp_enqueue_script( 'visualizer-gutenberg-block', $blockPath, array( 'wp-api', 'handsontable', 'visualizer-datatables', 'moment' ), $version, true );
94 84
95 85 $type = 'community';
96 86
97 87 if ( Visualizer_Module::is_pro() ) {
@@ -100,20 +90,14 @@
100 90 $type = 'business';
101 91 }
102 92 }
103 93
104 - $table_col_mapping = Visualizer_Source_Query_Params::get_all_db_tables_column_mapping( null, false );
105 -
106 94 $translation_array = array(
107 95 'isPro' => $type,
108 - 'proTeaser' => tsdk_utmify( Visualizer_Plugin::PRO_TEASER_URL, 'blockupsell'),
96 + 'proTeaser' => Visualizer_Plugin::PRO_TEASER_URL,
109 97 'absurl' => VISUALIZER_ABSURL,
110 98 'charts' => Visualizer_Module_Admin::_getChartTypesLocalized(),
111 99 'adminPage' => menu_page_url( 'visualizer', false ),
112 - 'sqlTable' => $table_col_mapping,
113 - 'chartsPerPage' => defined( 'TI_CYPRESS_TESTING' ) ? 20 : 6,
114 - 'proFeaturesLocked' => Visualizer_Module_Admin::proFeaturesLocked(),
115 - 'isFullSiteEditor' => 'site-editor.php' === $pagenow,
116 100 );
117 101 wp_localize_script( 'visualizer-gutenberg-block', 'visualizerLocalize', $translation_array );
118 102
119 103 // Enqueue frontend and editor block styles
@@ -118,26 +102,8 @@
118 102
119 103 // Enqueue frontend and editor block styles
120 104 wp_enqueue_style( 'handsontable', $handsontableCSS );
121 105 wp_enqueue_style( 'visualizer-gutenberg-block', $stylePath, array( 'visualizer-datatables' ), $version );
122 -
123 - if ( version_compare( $wp_version, '4.9.0', '>' ) ) {
124 -
125 - wp_enqueue_code_editor(
126 - array(
127 - 'type' => 'sql',
128 - 'codemirror' => array(
129 - 'autofocus' => true,
130 - 'lineWrapping' => true,
131 - 'dragDrop' => false,
132 - 'matchBrackets' => true,
133 - 'autoCloseBrackets' => true,
134 - 'extraKeys' => array( 'Ctrl-Space' => 'autocomplete' ),
135 - 'hintOptions' => array( 'tables' => $table_col_mapping ),
136 - ),
137 - )
138 - );
139 - }
140 106 }
141 107 /**
142 108 * Hook server side rendering into render callback
143 109 */
@@ -148,11 +114,8 @@
148 114 'attributes' => array(
149 115 'id' => array(
150 116 'type' => 'number',
151 117 ),
152 - 'lazy' => array(
153 - 'type' => 'string',
154 - ),
155 118 ),
156 119 )
157 120 );
158 121 }
@@ -159,46 +122,16 @@
159 122
160 123 /**
161 124 * Gutenberg Block Callback Function
162 125 */
163 - public function gutenberg_block_callback( $atts ) {
164 - // no id, no fun.
165 - if ( ! isset( $atts['id'] ) ) {
166 - return '';
126 + public function gutenberg_block_callback( $attr ) {
127 + if ( isset( $attr['id'] ) ) {
128 + $id = $attr['id'];
129 + if ( empty( $id ) || $id === 'none' ) {
130 + return ''; // no id = no fun
131 + }
132 + return '[visualizer id="' . $id . '"]';
167 133 }
168 -
169 - $atts = shortcode_atts(
170 - array(
171 - 'id' => false,
172 - 'lazy' => apply_filters( 'visualizer_lazy_by_default', false, $atts['id'] ),
173 - // we are deliberating excluding the class attribute from here
174 - // as this will be handled by the custom class in Gutenberg
175 - ),
176 - $atts
177 - );
178 -
179 - // no id, no fun.
180 - if ( ! $atts['id'] ) {
181 - return '';
182 - }
183 -
184 - // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
185 - if ( $atts['lazy'] == -1 || $atts['lazy'] == false ) {
186 - $atts['lazy'] = 'no';
187 - }
188 -
189 - // we don't want the chart in the editor lazy-loading.
190 - if ( is_admin() ) {
191 - unset( $atts['lazy'] );
192 - }
193 -
194 - $shortcode = '[visualizer';
195 - foreach ( $atts as $name => $value ) {
196 - $shortcode .= sprintf( ' %s="%s"', $name, $value );
197 - }
198 - $shortcode .= ']';
199 -
200 - return $shortcode;
201 134 }
202 135
203 136 /**
204 137 * Hook server side rendering into render callback
@@ -213,74 +146,8 @@
213 146 );
214 147
215 148 register_rest_route(
216 149 'visualizer/v' . VISUALIZER_REST_VERSION,
217 - '/get-query-data',
218 - array(
219 - 'methods' => 'GET',
220 - 'callback' => array( $this, 'get_query_data' ),
221 - 'permission_callback' => function () {
222 - return current_user_can( 'edit_posts' );
223 - },
224 - )
225 - );
226 -
227 - register_rest_route(
228 - 'visualizer/v' . VISUALIZER_REST_VERSION,
229 - '/get-json-root',
230 - array(
231 - 'methods' => 'GET',
232 - 'callback' => array( $this, 'get_json_root_data' ),
233 - 'args' => array(
234 - 'url' => array(
235 - 'sanitize_callback' => 'esc_url_raw',
236 - ),
237 - ),
238 - 'permission_callback' => function () {
239 - return current_user_can( 'edit_posts' );
240 - },
241 - )
242 - );
243 -
244 - register_rest_route(
245 - 'visualizer/v' . VISUALIZER_REST_VERSION,
246 - '/get-json-data',
247 - array(
248 - 'methods' => 'GET',
249 - 'callback' => array( $this, 'get_json_data' ),
250 - 'args' => array(
251 - 'url' => array(
252 - 'sanitize_callback' => 'esc_url_raw',
253 - ),
254 - 'chart' => array(
255 - 'sanitize_callback' => 'absint',
256 - ),
257 - ),
258 - 'permission_callback' => function () {
259 - return current_user_can( 'edit_posts' );
260 - },
261 - )
262 - );
263 -
264 - register_rest_route(
265 - 'visualizer/v' . VISUALIZER_REST_VERSION,
266 - '/set-json-data',
267 - array(
268 - 'methods' => 'GET',
269 - 'callback' => array( $this, 'set_json_data' ),
270 - 'args' => array(
271 - 'url' => array(
272 - 'sanitize_callback' => 'esc_url_raw',
273 - ),
274 - ),
275 - 'permission_callback' => function () {
276 - return current_user_can( 'edit_posts' );
277 - },
278 - )
279 - );
280 -
281 - register_rest_route(
282 - 'visualizer/v' . VISUALIZER_REST_VERSION,
283 150 '/update-chart',
284 151 array(
285 152 'methods' => 'POST',
286 153 'callback' => array( $this, 'update_chart_data' ),
@@ -342,10 +209,9 @@
342 209 $post_id = $post['id'];
343 210
344 211 $data['visualizer-chart-type'] = get_post_meta( $post_id, Visualizer_Plugin::CF_CHART_TYPE, true );
345 212
346 - $library = get_post_meta( $post_id, Visualizer_Plugin::CF_CHART_LIBRARY, true );
347 - $data['visualizer-chart-library'] = $library;
213 + $data['visualizer-chart-library'] = get_post_meta( $post_id, Visualizer_Plugin::CF_CHART_LIBRARY, true );
348 214
349 215 $data['visualizer-source'] = get_post_meta( $post_id, Visualizer_Plugin::CF_SOURCE, true );
350 216
351 217 $data['visualizer-default-data'] = get_post_meta( $post_id, Visualizer_Plugin::CF_DEFAULT_DATA, true );
@@ -351,11 +217,9 @@
351 217 $data['visualizer-default-data'] = get_post_meta( $post_id, Visualizer_Plugin::CF_DEFAULT_DATA, true );
352 218
353 219 // faetch and update settings
354 220 $data['visualizer-settings'] = get_post_meta( $post_id, Visualizer_Plugin::CF_SETTINGS, true );
355 - if ( empty( $data['visualizer-settings']['pagination'] ) ) {
356 - $data['visualizer-settings']['pageSize'] = '';
357 - }
221 +
358 222 // handle series filter hooks
359 223 $data['visualizer-series'] = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $post_id, Visualizer_Plugin::CF_SERIES, true ), $post_id, $data['visualizer-chart-type'] );
360 224
361 225 // handle settings filter hooks
@@ -363,120 +227,23 @@
363 227
364 228 // handle data filter hooks
365 229 $data['visualizer-data'] = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( html_entity_decode( get_the_content( $post_id ) ) ), $post_id, $data['visualizer-chart-type'] );
366 230
367 - // we are going to format only for tabular charts, because we are not sure of the effect on others.
368 - // this is to solve the case where boolean data shows up as all-ticks on gutenberg.
369 - if ( in_array( $data['visualizer-chart-type'], array( 'tabular' ), true ) ) {
370 - $data['visualizer-data'] = $this->format_chart_data( $data['visualizer-data'], $data['visualizer-series'] );
371 - }
372 -
373 - if ( ! isset( $data['visualizer-settings']['hAxis']['format'] ) ) {
374 - $data['visualizer-settings']['hAxis']['format'] = '';
375 - }
376 -
377 - $data['visualizer-data-exploded'] = '';
378 - // handle annotations for google charts
379 - if ( 'GoogleCharts' === $library ) {
380 - // this will contain the data of both axis.
381 - $settings = $data['visualizer-settings'];
382 - // this will contain data only of Y axis.
383 - $series = $data['visualizer-series'];
384 - $annotations = array();
385 - if ( isset( $settings['series'] ) ) {
386 - foreach ( $settings['series'] as $index => $serie ) {
387 - // skip X axis data.
388 - if ( $index === 0 ) {
389 - continue;
390 - }
391 - if ( ! empty( $serie['role'] ) ) {
392 - // this series is some kind of annotation, so let's collect its index.
393 - // the index will be +1 because the X axis value is index 0, which is being ignored.
394 - $annotations[ 'role' . ( intval( $index ) + 1 ) ] = $serie['role'];
395 -
396 - if ( isset( $data['visualizer-series'][ intval( $index ) + 1 ] ) ) {
397 - $data['visualizer-series'][ intval( $index ) + 1 ]['role'] = $serie['role'];
398 - }
399 - }
400 - }
401 - }
402 - if ( ! empty( $annotations ) ) {
403 - $exploded_data = array();
404 - $series_names = array();
405 - foreach ( $series as $index => $serie ) {
406 - // skip X axis data.
407 - if ( $index === 0 ) {
408 - continue;
409 - }
410 - if ( array_key_exists( 'role' . $index, $annotations ) ) {
411 - $series_names[] = (object) array( 'role' => $annotations[ 'role' . $index ], 'type' => $serie['type'] );
412 - } else {
413 - $series_names[] = $serie['label'];
414 - }
415 - }
416 - $exploded_data[] = $series_names;
417 -
418 - foreach ( $data['visualizer-data'] as $datum ) {
419 - // skip X axis data.
420 - unset( $datum[0] );
421 - $exploded_data[] = $datum;
422 - }
423 - $data['visualizer-data-exploded'] = array( $exploded_data );
424 - }
425 - }
426 -
427 231 $import = get_post_meta( $post_id, Visualizer_Plugin::CF_CHART_URL, true );
428 232
429 233 $schedule = get_post_meta( $post_id, Visualizer_Plugin::CF_CHART_SCHEDULE, true );
430 234
431 - $db_schedule = get_post_meta( $post_id, Visualizer_Plugin::CF_DB_SCHEDULE, true );
432 -
433 - $db_query = get_post_meta( $post_id, Visualizer_Plugin::CF_DB_QUERY, true );
434 -
435 - $json_url = get_post_meta( $post_id, Visualizer_Plugin::CF_JSON_URL, true );
436 -
437 - $json_headers = get_post_meta( $post_id, Visualizer_Plugin::CF_JSON_HEADERS, true );
438 -
439 - $json_schedule = get_post_meta( $post_id, Visualizer_Plugin::CF_JSON_SCHEDULE, true );
440 -
441 - $json_root = get_post_meta( $post_id, Visualizer_Plugin::CF_JSON_ROOT, true );
442 -
443 - $json_paging = get_post_meta( $post_id, Visualizer_Plugin::CF_JSON_PAGING, true );
444 -
445 - if ( ! empty( $import ) && $schedule >= 0 ) {
446 - $data['visualizer-chart-url'] = $import;
235 + if ( ! empty( $import ) && ! empty( $schedule ) ) {
236 + $data['visualizer-chart-url'] = $import;
447 237 $data['visualizer-chart-schedule'] = $schedule;
448 238 }
449 239
450 - if ( ! empty( $db_schedule ) && ! empty( $db_query ) ) {
451 - $data['visualizer-db-schedule'] = $db_schedule;
452 - $data['visualizer-db-query'] = $db_query;
453 - }
454 -
455 - if ( ! empty( $json_url ) ) {
456 - $data['visualizer-json-schedule'] = $json_schedule;
457 - $data['visualizer-json-url'] = $json_url;
458 - $data['visualizer-json-headers'] = $json_headers;
459 - $data['visualizer-json-root'] = $json_root;
460 -
461 - if ( Visualizer_Module::is_pro() && ! empty( $json_paging ) ) {
462 - $data['visualizer-json-paging'] = $json_paging;
463 - }
464 - }
465 -
466 240 if ( Visualizer_Module::is_pro() ) {
467 241 $permissions = get_post_meta( $post_id, Visualizer_PRO::CF_PERMISSIONS, true );
468 242
469 - if ( empty( $permissions ) ) {
470 - $permissions = array( 'permissions' => array(
471 - 'read' => 'all',
472 - 'edit' => 'roles',
473 - 'edit-specific' => array( 'administrator' ),
474 - ),
475 - );
243 + if ( ! empty( $permissions ) ) {
244 + $data['visualizer-permissions'] = $permissions;
476 245 }
477 -
478 - $data['visualizer-permissions'] = $permissions;
479 246 }
480 247
481 248 return $data;
482 249 }
@@ -481,104 +248,8 @@
481 248 return $data;
482 249 }
483 250
484 251 /**
485 - * Returns the data for the query.
486 - *
487 - * @access public
488 - */
489 - public function get_query_data( $data ) {
490 - if ( ! current_user_can( 'edit_posts' ) ) {
491 - return false;
492 - }
493 -
494 - $source = new Visualizer_Source_Query( stripslashes( $data['query'] ) );
495 - $html = $source->fetch( true );
496 - $source->fetch( false );
497 - $name = $source->getSourceName();
498 - $series = $source->getSeries();
499 - $data = $source->getRawData();
500 - $error = '';
501 - if ( empty( $html ) ) {
502 - $error = $source->get_error();
503 - wp_send_json_error( array( 'msg' => $error ) );
504 - }
505 - wp_send_json_success( array( 'table' => $html, 'name' => $name, 'series' => $series, 'data' => $data ) );
506 - }
507 -
508 - /**
509 - * Returns the JSON root.
510 - *
511 - * @access public
512 - */
513 - public function get_json_root_data( $data ) {
514 - if ( ! current_user_can( 'edit_posts' ) ) {
515 - return false;
516 - }
517 -
518 - $source = new Visualizer_Source_Json( $data );
519 -
520 - $roots = $source->fetchRoots();
521 - if ( empty( $roots ) ) {
522 - wp_send_json_error( array( 'msg' => $source->get_error() ) );
523 - }
524 -
525 - wp_send_json_success( array( 'url' => $data['url'], 'roots' => $roots ) );
526 - }
527 -
528 - /**
529 - * Returns the JSON data.
530 - *
531 - * @access public
532 - */
533 - public function get_json_data( $data ) {
534 - if ( ! current_user_can( 'edit_posts' ) ) {
535 - return false;
536 - }
537 -
538 - $chart_id = $data['chart'];
539 -
540 - if ( empty( $chart_id ) ) {
541 - wp_die();
542 - }
543 -
544 - $source = new Visualizer_Source_Json( $data );
545 - $source->fetch();
546 - $table = $source->getRawData();
547 -
548 - if ( empty( $table ) ) {
549 - wp_send_json_error( array( 'msg' => esc_html__( 'Unable to fetch data from the endpoint. Please try again.', 'visualizer' ) ) );
550 - }
551 -
552 - $table = Visualizer_Render_Layout::show( 'editor-table', $table, $chart_id, 'viz-json-table', false, false );
553 - wp_send_json_success( array( 'table' => $table, 'root' => $data['root'], 'url' => $data['url'], 'paging' => $source->getPaginationElements() ) );
554 - }
555 -
556 - /**
557 - * Set the JSON data.
558 - *
559 - * @access public
560 - */
561 - public function set_json_data( $data ) {
562 - if ( ! current_user_can( 'edit_posts' ) ) {
563 - return false;
564 - }
565 -
566 - $source = new Visualizer_Source_Json( $data );
567 -
568 - $table = $source->fetch();
569 - if ( empty( $table ) ) {
570 - wp_send_json_error( array( 'msg' => esc_html__( 'Unable to fetch data from the endpoint. Please try again.', 'visualizer' ) ) );
571 - }
572 -
573 - $source->fetchFromEditableTable();
574 - $name = $source->getSourceName();
575 - $series = json_encode( $source->getSeries() );
576 - $data = json_encode( $source->getRawData() );
577 - wp_send_json_success( array( 'name' => $name, 'series' => $series, 'data' => $data ) );
578 - }
579 -
580 - /**
581 252 * Rest Callback Method
582 253 */
583 254 public function update_chart_data( $data ) {
584 255 if ( ! current_user_can( 'edit_posts' ) ) {
@@ -585,11 +256,9 @@
585 256 return false;
586 257 }
587 258
588 259 if ( $data['id'] && ! is_wp_error( $data['id'] ) ) {
589 - if ( get_post_type( $data['id'] ) !== Visualizer_Plugin::CPT_VISUALIZER ) {
590 - return new WP_Error( 'invalid_post_type', 'Invalid post type.' );
591 - }
260 +
592 261 $chart_type = sanitize_text_field( $data['visualizer-chart-type'] );
593 262 $source_type = sanitize_text_field( $data['visualizer-source'] );
594 263
595 264 update_post_meta( $data['id'], Visualizer_Plugin::CF_CHART_TYPE, $chart_type );
@@ -597,9 +266,9 @@
597 266 update_post_meta( $data['id'], Visualizer_Plugin::CF_DEFAULT_DATA, $data['visualizer-default-data'] );
598 267 update_post_meta( $data['id'], Visualizer_Plugin::CF_SERIES, $data['visualizer-series'] );
599 268 update_post_meta( $data['id'], Visualizer_Plugin::CF_SETTINGS, $data['visualizer-settings'] );
600 269
601 - if ( $data['visualizer-chart-url'] && $data['visualizer-chart-schedule'] >= 0 ) {
270 + if ( $data['visualizer-chart-url'] && $data['visualizer-chart-schedule'] ) {
602 271 $chart_url = esc_url_raw( $data['visualizer-chart-url'] );
603 272 $chart_schedule = intval( $data['visualizer-chart-schedule'] );
604 273 update_post_meta( $data['id'], Visualizer_Plugin::CF_CHART_URL, $chart_url );
605 274 apply_filters( 'visualizer_pro_chart_schedule', $data['id'], $chart_url, $chart_schedule );
@@ -607,58 +276,8 @@
607 276 delete_post_meta( $data['id'], Visualizer_Plugin::CF_CHART_URL );
608 277 apply_filters( 'visualizer_pro_remove_schedule', $data['id'] );
609 278 }
610 279
611 - // let's check if this is not an external db chart
612 - // as there is no support for that in the block editor interface
613 - $external_params = get_post_meta( $data['id'], Visualizer_Plugin::CF_REMOTE_DB_PARAMS, true );
614 - if ( empty( $external_params ) ) {
615 - if ( $source_type === 'Visualizer_Source_Query' ) {
616 - $db_schedule = intval( $data['visualizer-db-schedule'] );
617 - $db_query = $data['visualizer-db-query'];
618 - update_post_meta( $data['id'], Visualizer_Plugin::CF_DB_SCHEDULE, $db_schedule );
619 - update_post_meta( $data['id'], Visualizer_Plugin::CF_DB_QUERY, stripslashes( $db_query ) );
620 - } else {
621 - delete_post_meta( $data['id'], Visualizer_Plugin::CF_DB_SCHEDULE );
622 - delete_post_meta( $data['id'], Visualizer_Plugin::CF_DB_QUERY );
623 - }
624 -
625 - if ( 'Visualizer_Source_Csv_Remote' === $source_type ) {
626 - $schedule_url = $data['visualizer-chart-url'];
627 - $schedule_id = $data['visualizer-chart-schedule'];
628 - update_post_meta( $data['id'], Visualizer_Plugin::CF_CHART_URL, $schedule_url );
629 - update_post_meta( $data['id'], Visualizer_Plugin::CF_CHART_SCHEDULE, $schedule_id );
630 - } else {
631 - delete_post_meta( $data['id'], Visualizer_Plugin::CF_CHART_URL );
632 - delete_post_meta( $data['id'], Visualizer_Plugin::CF_CHART_SCHEDULE );
633 - }
634 - }
635 -
636 - if ( $source_type === 'Visualizer_Source_Json' ) {
637 - $json_schedule = intval( $data['visualizer-json-schedule'] );
638 - $json_url = esc_url_raw( $data['visualizer-json-url'] );
639 - $json_headers = esc_url_raw( $data['visualizer-json-headers'] );
640 - $json_root = $data['visualizer-json-root'];
641 - $json_paging = $data['visualizer-json-paging'];
642 -
643 - update_post_meta( $data['id'], Visualizer_Plugin::CF_JSON_SCHEDULE, $json_schedule );
644 - update_post_meta( $data['id'], Visualizer_Plugin::CF_JSON_URL, $json_url );
645 - update_post_meta( $data['id'], Visualizer_Plugin::CF_JSON_HEADERS, $json_headers );
646 - update_post_meta( $data['id'], Visualizer_Plugin::CF_JSON_ROOT, $json_root );
647 -
648 - if ( ! empty( $json_paging ) ) {
649 - update_post_meta( $data['id'], Visualizer_Plugin::CF_JSON_PAGING, $json_paging );
650 - } else {
651 - delete_post_meta( $data['id'], Visualizer_Plugin::CF_JSON_PAGING );
652 - }
653 - } else {
654 - delete_post_meta( $data['id'], Visualizer_Plugin::CF_JSON_SCHEDULE );
655 - delete_post_meta( $data['id'], Visualizer_Plugin::CF_JSON_URL );
656 - delete_post_meta( $data['id'], Visualizer_Plugin::CF_JSON_HEADERS );
657 - delete_post_meta( $data['id'], Visualizer_Plugin::CF_JSON_ROOT );
658 - delete_post_meta( $data['id'], Visualizer_Plugin::CF_JSON_PAGING );
659 - }
660 -
661 280 if ( Visualizer_Module::is_pro() ) {
662 281 update_post_meta( $data['id'], Visualizer_PRO::CF_PERMISSIONS, $data['visualizer-permissions'] );
663 282 }
664 283
@@ -676,14 +295,8 @@
676 295 );
677 296
678 297 wp_update_post( $chart );
679 298
680 - // Clear existing chart cache.
681 - $cache_key = Visualizer_Plugin::CF_CHART_CACHE . '_' . $data['id'];
682 - if ( get_transient( $cache_key ) ) {
683 - delete_transient( $cache_key );
684 - }
685 -
686 299 $revisions = wp_get_post_revisions( $data['id'], array( 'order' => 'ASC' ) );
687 300
688 301 if ( count( $revisions ) > 1 ) {
689 302 $revision_ids = array_keys( $revisions );
@@ -699,10 +312,8 @@
699 312 }
700 313
701 314 /**
702 315 * Format chart data.
703 - *
704 - * Note: No matter how tempted, don't use the similar method from Visualizer_Source. That works on a different structure.
705 316 */
706 317 public function format_chart_data( $data, $series ) {
707 318 foreach ( $series as $i => $row ) {
708 319 // if no value exists for the seires, then add null
@@ -713,38 +324,39 @@
713 324 if ( is_null( $series[ $i ] ) ) {
714 325 continue;
715 326 }
716 327
717 - switch ( $row['type'] ) {
718 - case 'number':
719 - foreach ( $data as $o => $col ) {
720 - $data[ $o ][ $i ] = ( is_numeric( $col[ $i ] ) ) ? floatval( $col[ $i ] ) : ( is_numeric( str_replace( ',', '', $col[ $i ] ) ) ? floatval( str_replace( ',', '', $col[ $i ] ) ) : null );
328 + if ( $row['type'] === 'number' ) {
329 + foreach ( $data as $o => $col ) {
330 + $data[ $o ][ $i ] = ( is_numeric( $col[ $i ] ) ) ? floatval( $col[ $i ] ) : ( is_numeric( str_replace( ',', '', $col[ $i ] ) ) ? floatval( str_replace( ',', '', $col[ $i ] ) ) : null );
331 + }
332 + }
333 +
334 + if ( $row['type'] === 'boolean' ) {
335 + foreach ( $data as $o => $col ) {
336 + $data[ $o ][ $i ] = ! empty( $col[ $i ] ) ? filter_validate( $col[ $i ], FILTER_VALIDATE_BOOLEAN ) : null;
337 + }
338 + }
339 +
340 + if ( $row['type'] === 'timeofday' ) {
341 + foreach ( $data as $o => $col ) {
342 + $date = new DateTime( '1984-03-16T' . $col[ $i ] );
343 + if ( $date ) {
344 + $data[ $o ][ $i ] = array(
345 + intval( $date->format( 'H' ) ),
346 + intval( $date->format( 'i' ) ),
347 + intval( $date->format( 's' ) ),
348 + 0,
349 + );
721 350 }
722 - break;
723 - case 'boolean':
724 - foreach ( $data as $o => $col ) {
725 - $data[ $o ][ $i ] = ! empty( $col[ $i ] ) ? filter_var( $col[ $i ], FILTER_VALIDATE_BOOLEAN ) : false;
726 - }
727 - break;
728 - case 'timeofday':
729 - foreach ( $data as $o => $col ) {
730 - $date = new DateTime( '1984-03-16T' . $col[ $i ] );
731 - if ( $date ) {
732 - $data[ $o ][ $i ] = array(
733 - intval( $date->format( 'H' ) ),
734 - intval( $date->format( 'i' ) ),
735 - intval( $date->format( 's' ) ),
736 - 0,
737 - );
738 - }
739 - }
740 - break;
741 - case 'string':
742 - foreach ( $data as $o => $col ) {
743 - $data[ $o ][ $i ] = $this->toUTF8( $col[ $i ] );
744 - }
745 - break;
351 + }
746 352 }
353 +
354 + if ( $row['type'] === 'string' ) {
355 + foreach ( $data as $o => $col ) {
356 + $data[ $o ][ $i ] = $this->toUTF8( $col[ $i ] );
357 + }
358 + }
747 359 }
748 360
749 361 return $data;
750 362 }
@@ -766,14 +378,10 @@
766 378 if ( ! current_user_can( 'edit_posts' ) ) {
767 379 return false;
768 380 }
769 381
770 - $remote_data = false;
771 - if ( isset( $data['url'] ) && function_exists( 'wp_http_validate_url' ) ) {
772 - $remote_data = wp_http_validate_url( $data['url'] );
773 - }
774 - if ( false !== $remote_data && ! is_wp_error( $remote_data ) ) {
775 - $source = new Visualizer_Source_Csv_Remote( $remote_data );
382 + if ( $data['url'] && ! is_wp_error( $data['url'] ) && filter_var( $data['url'], FILTER_VALIDATE_URL ) ) {
383 + $source = new Visualizer_Source_Csv_Remote( $data['url'] );
776 384 if ( $source->fetch() ) {
777 385 $temp = $source->getData();
778 386 if ( is_string( $temp ) && is_array( unserialize( $temp ) ) ) {
779 387 $content['series'] = $source->getSeries();
@@ -841,21 +449,11 @@
841 449 * Filter Rest Query
842 450 */
843 451 public function add_rest_query_vars( $args, \WP_REST_Request $request ) {
844 452 if ( isset( $request['meta_key'] ) && isset( $request['meta_value'] ) ) {
845 - $args['meta_query'] = array(
846 - 'relation' => 'OR',
847 - array(
848 - 'key' => $request->get_param( 'meta_key' ),
849 - 'value' => $request->get_param( 'meta_value' ),
850 - 'compare' => '!=',
851 - ),
852 - array(
853 - 'key' => $request->get_param( 'meta_key' ),
854 - 'value' => $request->get_param( 'meta_value' ),
855 - 'compare' => 'NOT EXISTS',
856 - ),
857 - );
453 + $args['meta_key'] = $request->get_param( 'meta_key' );
454 + $args['meta_value'] = $request->get_param( 'meta_value' );
455 + $args['meta_compare'] = '!=';
858 456 }
859 457 return $args;
860 458 }
861 459 }