PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.3.4
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.3.4
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 +47 -432 3.10.03.3.4 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;
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,21 +72,13 @@
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 83 wp_enqueue_script( 'visualizer-gutenberg-block', $blockPath, array( 'wp-api', 'handsontable', 'visualizer-datatables', 'moment' ), $version, true );
94 84
@@ -100,19 +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 100 );
116 101 wp_localize_script( 'visualizer-gutenberg-block', 'visualizerLocalize', $translation_array );
117 102
118 103 // Enqueue frontend and editor block styles
@@ -117,26 +102,8 @@
117 102
118 103 // Enqueue frontend and editor block styles
119 104 wp_enqueue_style( 'handsontable', $handsontableCSS );
120 105 wp_enqueue_style( 'visualizer-gutenberg-block', $stylePath, array( 'visualizer-datatables' ), $version );
121 -
122 - if ( version_compare( $wp_version, '4.9.0', '>' ) ) {
123 -
124 - wp_enqueue_code_editor(
125 - array(
126 - 'type' => 'sql',
127 - 'codemirror' => array(
128 - 'autofocus' => true,
129 - 'lineWrapping' => true,
130 - 'dragDrop' => false,
131 - 'matchBrackets' => true,
132 - 'autoCloseBrackets' => true,
133 - 'extraKeys' => array( 'Ctrl-Space' => 'autocomplete' ),
134 - 'hintOptions' => array( 'tables' => $table_col_mapping ),
135 - ),
136 - )
137 - );
138 - }
139 106 }
140 107 /**
141 108 * Hook server side rendering into render callback
142 109 */
@@ -147,11 +114,8 @@
147 114 'attributes' => array(
148 115 'id' => array(
149 116 'type' => 'number',
150 117 ),
151 - 'lazy' => array(
152 - 'type' => 'string',
153 - ),
154 118 ),
155 119 )
156 120 );
157 121 }
@@ -158,46 +122,16 @@
158 122
159 123 /**
160 124 * Gutenberg Block Callback Function
161 125 */
162 - public function gutenberg_block_callback( $atts ) {
163 - // no id, no fun.
164 - if ( ! isset( $atts['id'] ) ) {
165 - 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 . '"]';
166 133 }
167 -
168 - $atts = shortcode_atts(
169 - array(
170 - 'id' => false,
171 - 'lazy' => apply_filters( 'visualizer_lazy_by_default', false, $atts['id'] ),
172 - // we are deliberating excluding the class attribute from here
173 - // as this will be handled by the custom class in Gutenberg
174 - ),
175 - $atts
176 - );
177 -
178 - // no id, no fun.
179 - if ( ! $atts['id'] ) {
180 - return '';
181 - }
182 -
183 - // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
184 - if ( $atts['lazy'] == -1 || $atts['lazy'] == false ) {
185 - $atts['lazy'] = 'no';
186 - }
187 -
188 - // we don't want the chart in the editor lazy-loading.
189 - if ( is_admin() ) {
190 - unset( $atts['lazy'] );
191 - }
192 -
193 - $shortcode = '[visualizer';
194 - foreach ( $atts as $name => $value ) {
195 - $shortcode .= sprintf( ' %s="%s"', $name, $value );
196 - }
197 - $shortcode .= ']';
198 -
199 - return $shortcode;
200 134 }
201 135
202 136 /**
203 137 * Hook server side rendering into render callback
@@ -212,74 +146,8 @@
212 146 );
213 147
214 148 register_rest_route(
215 149 'visualizer/v' . VISUALIZER_REST_VERSION,
216 - '/get-query-data',
217 - array(
218 - 'methods' => 'GET',
219 - 'callback' => array( $this, 'get_query_data' ),
220 - 'permission_callback' => function () {
221 - return current_user_can( 'edit_posts' );
222 - },
223 - )
224 - );
225 -
226 - register_rest_route(
227 - 'visualizer/v' . VISUALIZER_REST_VERSION,
228 - '/get-json-root',
229 - array(
230 - 'methods' => 'GET',
231 - 'callback' => array( $this, 'get_json_root_data' ),
232 - 'args' => array(
233 - 'url' => array(
234 - 'sanitize_callback' => 'esc_url_raw',
235 - ),
236 - ),
237 - 'permission_callback' => function () {
238 - return current_user_can( 'edit_posts' );
239 - },
240 - )
241 - );
242 -
243 - register_rest_route(
244 - 'visualizer/v' . VISUALIZER_REST_VERSION,
245 - '/get-json-data',
246 - array(
247 - 'methods' => 'GET',
248 - 'callback' => array( $this, 'get_json_data' ),
249 - 'args' => array(
250 - 'url' => array(
251 - 'sanitize_callback' => 'esc_url_raw',
252 - ),
253 - 'chart' => array(
254 - 'sanitize_callback' => 'absint',
255 - ),
256 - ),
257 - 'permission_callback' => function () {
258 - return current_user_can( 'edit_posts' );
259 - },
260 - )
261 - );
262 -
263 - register_rest_route(
264 - 'visualizer/v' . VISUALIZER_REST_VERSION,
265 - '/set-json-data',
266 - array(
267 - 'methods' => 'GET',
268 - 'callback' => array( $this, 'set_json_data' ),
269 - 'args' => array(
270 - 'url' => array(
271 - 'sanitize_callback' => 'esc_url_raw',
272 - ),
273 - ),
274 - 'permission_callback' => function () {
275 - return current_user_can( 'edit_posts' );
276 - },
277 - )
278 - );
279 -
280 - register_rest_route(
281 - 'visualizer/v' . VISUALIZER_REST_VERSION,
282 150 '/update-chart',
283 151 array(
284 152 'methods' => 'POST',
285 153 'callback' => array( $this, 'update_chart_data' ),
@@ -341,10 +209,9 @@
341 209 $post_id = $post['id'];
342 210
343 211 $data['visualizer-chart-type'] = get_post_meta( $post_id, Visualizer_Plugin::CF_CHART_TYPE, true );
344 212
345 - $library = get_post_meta( $post_id, Visualizer_Plugin::CF_CHART_LIBRARY, true );
346 - $data['visualizer-chart-library'] = $library;
213 + $data['visualizer-chart-library'] = get_post_meta( $post_id, Visualizer_Plugin::CF_CHART_LIBRARY, true );
347 214
348 215 $data['visualizer-source'] = get_post_meta( $post_id, Visualizer_Plugin::CF_SOURCE, true );
349 216
350 217 $data['visualizer-default-data'] = get_post_meta( $post_id, Visualizer_Plugin::CF_DEFAULT_DATA, true );
@@ -360,116 +227,23 @@
360 227
361 228 // handle data filter hooks
362 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'] );
363 230
364 - // we are going to format only for tabular charts, because we are not sure of the effect on others.
365 - // this is to solve the case where boolean data shows up as all-ticks on gutenberg.
366 - if ( in_array( $data['visualizer-chart-type'], array( 'tabular' ), true ) ) {
367 - $data['visualizer-data'] = $this->format_chart_data( $data['visualizer-data'], $data['visualizer-series'] );
368 - }
369 -
370 - $data['visualizer-data-exploded'] = '';
371 - // handle annotations for google charts
372 - if ( 'GoogleCharts' === $library ) {
373 - // this will contain the data of both axis.
374 - $settings = $data['visualizer-settings'];
375 - // this will contain data only of Y axis.
376 - $series = $data['visualizer-series'];
377 - $annotations = array();
378 - if ( isset( $settings['series'] ) ) {
379 - foreach ( $settings['series'] as $index => $serie ) {
380 - // skip X axis data.
381 - if ( $index === 0 ) {
382 - continue;
383 - }
384 - if ( ! empty( $serie['role'] ) ) {
385 - // this series is some kind of annotation, so let's collect its index.
386 - // the index will be +1 because the X axis value is index 0, which is being ignored.
387 - $annotations[ 'role' . ( intval( $index ) + 1 ) ] = $serie['role'];
388 -
389 - if ( isset( $data['visualizer-series'][ intval( $index ) + 1 ] ) ) {
390 - $data['visualizer-series'][ intval( $index ) + 1 ]['role'] = $serie['role'];
391 - }
392 - }
393 - }
394 - }
395 - if ( ! empty( $annotations ) ) {
396 - $exploded_data = array();
397 - $series_names = array();
398 - foreach ( $series as $index => $serie ) {
399 - // skip X axis data.
400 - if ( $index === 0 ) {
401 - continue;
402 - }
403 - if ( array_key_exists( 'role' . $index, $annotations ) ) {
404 - $series_names[] = (object) array( 'role' => $annotations[ 'role' . $index ], 'type' => $serie['type'] );
405 - } else {
406 - $series_names[] = $serie['label'];
407 - }
408 - }
409 - $exploded_data[] = $series_names;
410 -
411 - foreach ( $data['visualizer-data'] as $datum ) {
412 - // skip X axis data.
413 - unset( $datum[0] );
414 - $exploded_data[] = $datum;
415 - }
416 - $data['visualizer-data-exploded'] = array( $exploded_data );
417 - }
418 - }
419 -
420 231 $import = get_post_meta( $post_id, Visualizer_Plugin::CF_CHART_URL, true );
421 232
422 233 $schedule = get_post_meta( $post_id, Visualizer_Plugin::CF_CHART_SCHEDULE, true );
423 234
424 - $db_schedule = get_post_meta( $post_id, Visualizer_Plugin::CF_DB_SCHEDULE, true );
425 -
426 - $db_query = get_post_meta( $post_id, Visualizer_Plugin::CF_DB_QUERY, true );
427 -
428 - $json_url = get_post_meta( $post_id, Visualizer_Plugin::CF_JSON_URL, true );
429 -
430 - $json_headers = get_post_meta( $post_id, Visualizer_Plugin::CF_JSON_HEADERS, true );
431 -
432 - $json_schedule = get_post_meta( $post_id, Visualizer_Plugin::CF_JSON_SCHEDULE, true );
433 -
434 - $json_root = get_post_meta( $post_id, Visualizer_Plugin::CF_JSON_ROOT, true );
435 -
436 - $json_paging = get_post_meta( $post_id, Visualizer_Plugin::CF_JSON_PAGING, true );
437 -
438 235 if ( ! empty( $import ) && ! empty( $schedule ) ) {
439 236 $data['visualizer-chart-url'] = $import;
440 237 $data['visualizer-chart-schedule'] = $schedule;
441 238 }
442 239
443 - if ( ! empty( $db_schedule ) && ! empty( $db_query ) ) {
444 - $data['visualizer-db-schedule'] = $db_schedule;
445 - $data['visualizer-db-query'] = $db_query;
446 - }
447 -
448 - if ( ! empty( $json_url ) ) {
449 - $data['visualizer-json-schedule'] = $json_schedule;
450 - $data['visualizer-json-url'] = $json_url;
451 - $data['visualizer-json-headers'] = $json_headers;
452 - $data['visualizer-json-root'] = $json_root;
453 -
454 - if ( Visualizer_Module::is_pro() && ! empty( $json_paging ) ) {
455 - $data['visualizer-json-paging'] = $json_paging;
456 - }
457 - }
458 -
459 240 if ( Visualizer_Module::is_pro() ) {
460 241 $permissions = get_post_meta( $post_id, Visualizer_PRO::CF_PERMISSIONS, true );
461 242
462 - if ( empty( $permissions ) ) {
463 - $permissions = array( 'permissions' => array(
464 - 'read' => 'all',
465 - 'edit' => 'roles',
466 - 'edit-specific' => array( 'administrator' ),
467 - ),
468 - );
243 + if ( ! empty( $permissions ) ) {
244 + $data['visualizer-permissions'] = $permissions;
469 245 }
470 -
471 - $data['visualizer-permissions'] = $permissions;
472 246 }
473 247
474 248 return $data;
475 249 }
@@ -474,104 +248,8 @@
474 248 return $data;
475 249 }
476 250
477 251 /**
478 - * Returns the data for the query.
479 - *
480 - * @access public
481 - */
482 - public function get_query_data( $data ) {
483 - if ( ! current_user_can( 'edit_posts' ) ) {
484 - return false;
485 - }
486 -
487 - $source = new Visualizer_Source_Query( stripslashes( $data['query'] ) );
488 - $html = $source->fetch( true );
489 - $source->fetch( false );
490 - $name = $source->getSourceName();
491 - $series = $source->getSeries();
492 - $data = $source->getRawData();
493 - $error = '';
494 - if ( empty( $html ) ) {
495 - $error = $source->get_error();
496 - wp_send_json_error( array( 'msg' => $error ) );
497 - }
498 - wp_send_json_success( array( 'table' => $html, 'name' => $name, 'series' => $series, 'data' => $data ) );
499 - }
500 -
501 - /**
502 - * Returns the JSON root.
503 - *
504 - * @access public
505 - */
506 - public function get_json_root_data( $data ) {
507 - if ( ! current_user_can( 'edit_posts' ) ) {
508 - return false;
509 - }
510 -
511 - $source = new Visualizer_Source_Json( $data );
512 -
513 - $roots = $source->fetchRoots();
514 - if ( empty( $roots ) ) {
515 - wp_send_json_error( array( 'msg' => $source->get_error() ) );
516 - }
517 -
518 - wp_send_json_success( array( 'url' => $data['url'], 'roots' => $roots ) );
519 - }
520 -
521 - /**
522 - * Returns the JSON data.
523 - *
524 - * @access public
525 - */
526 - public function get_json_data( $data ) {
527 - if ( ! current_user_can( 'edit_posts' ) ) {
528 - return false;
529 - }
530 -
531 - $chart_id = $data['chart'];
532 -
533 - if ( empty( $chart_id ) ) {
534 - wp_die();
535 - }
536 -
537 - $source = new Visualizer_Source_Json( $data );
538 - $source->fetch();
539 - $table = $source->getRawData();
540 -
541 - if ( empty( $table ) ) {
542 - wp_send_json_error( array( 'msg' => esc_html__( 'Unable to fetch data from the endpoint. Please try again.', 'visualizer' ) ) );
543 - }
544 -
545 - $table = Visualizer_Render_Layout::show( 'editor-table', $table, $chart_id, 'viz-json-table', false, false );
546 - wp_send_json_success( array( 'table' => $table, 'root' => $data['root'], 'url' => $data['url'], 'paging' => $source->getPaginationElements() ) );
547 - }
548 -
549 - /**
550 - * Set the JSON data.
551 - *
552 - * @access public
553 - */
554 - public function set_json_data( $data ) {
555 - if ( ! current_user_can( 'edit_posts' ) ) {
556 - return false;
557 - }
558 -
559 - $source = new Visualizer_Source_Json( $data );
560 -
561 - $table = $source->fetch();
562 - if ( empty( $table ) ) {
563 - wp_send_json_error( array( 'msg' => esc_html__( 'Unable to fetch data from the endpoint. Please try again.', 'visualizer' ) ) );
564 - }
565 -
566 - $source->fetchFromEditableTable();
567 - $name = $source->getSourceName();
568 - $series = json_encode( $source->getSeries() );
569 - $data = json_encode( $source->getRawData() );
570 - wp_send_json_success( array( 'name' => $name, 'series' => $series, 'data' => $data ) );
571 - }
572 -
573 - /**
574 252 * Rest Callback Method
575 253 */
576 254 public function update_chart_data( $data ) {
577 255 if ( ! current_user_can( 'edit_posts' ) ) {
@@ -578,11 +256,9 @@
578 256 return false;
579 257 }
580 258
581 259 if ( $data['id'] && ! is_wp_error( $data['id'] ) ) {
582 - if ( get_post_type( $data['id'] ) !== Visualizer_Plugin::CPT_VISUALIZER ) {
583 - return new WP_Error( 'invalid_post_type', 'Invalid post type.' );
584 - }
260 +
585 261 $chart_type = sanitize_text_field( $data['visualizer-chart-type'] );
586 262 $source_type = sanitize_text_field( $data['visualizer-source'] );
587 263
588 264 update_post_meta( $data['id'], Visualizer_Plugin::CF_CHART_TYPE, $chart_type );
@@ -600,48 +276,8 @@
600 276 delete_post_meta( $data['id'], Visualizer_Plugin::CF_CHART_URL );
601 277 apply_filters( 'visualizer_pro_remove_schedule', $data['id'] );
602 278 }
603 279
604 - // let's check if this is not an external db chart
605 - // as there is no support for that in the block editor interface
606 - $external_params = get_post_meta( $data['id'], Visualizer_Plugin::CF_REMOTE_DB_PARAMS, true );
607 - if ( empty( $external_params ) ) {
608 - if ( $source_type === 'Visualizer_Source_Query' ) {
609 - $db_schedule = intval( $data['visualizer-db-schedule'] );
610 - $db_query = $data['visualizer-db-query'];
611 - update_post_meta( $data['id'], Visualizer_Plugin::CF_DB_SCHEDULE, $db_schedule );
612 - update_post_meta( $data['id'], Visualizer_Plugin::CF_DB_QUERY, stripslashes( $db_query ) );
613 - } else {
614 - delete_post_meta( $data['id'], Visualizer_Plugin::CF_DB_SCHEDULE );
615 - delete_post_meta( $data['id'], Visualizer_Plugin::CF_DB_QUERY );
616 - }
617 - }
618 -
619 - if ( $source_type === 'Visualizer_Source_Json' ) {
620 - $json_schedule = intval( $data['visualizer-json-schedule'] );
621 - $json_url = esc_url_raw( $data['visualizer-json-url'] );
622 - $json_headers = esc_url_raw( $data['visualizer-json-headers'] );
623 - $json_root = $data['visualizer-json-root'];
624 - $json_paging = $data['visualizer-json-paging'];
625 -
626 - update_post_meta( $data['id'], Visualizer_Plugin::CF_JSON_SCHEDULE, $json_schedule );
627 - update_post_meta( $data['id'], Visualizer_Plugin::CF_JSON_URL, $json_url );
628 - update_post_meta( $data['id'], Visualizer_Plugin::CF_JSON_HEADERS, $json_headers );
629 - update_post_meta( $data['id'], Visualizer_Plugin::CF_JSON_ROOT, $json_root );
630 -
631 - if ( ! empty( $json_paging ) ) {
632 - update_post_meta( $data['id'], Visualizer_Plugin::CF_JSON_PAGING, $json_paging );
633 - } else {
634 - delete_post_meta( $data['id'], Visualizer_Plugin::CF_JSON_PAGING );
635 - }
636 - } else {
637 - delete_post_meta( $data['id'], Visualizer_Plugin::CF_JSON_SCHEDULE );
638 - delete_post_meta( $data['id'], Visualizer_Plugin::CF_JSON_URL );
639 - delete_post_meta( $data['id'], Visualizer_Plugin::CF_JSON_HEADERS );
640 - delete_post_meta( $data['id'], Visualizer_Plugin::CF_JSON_ROOT );
641 - delete_post_meta( $data['id'], Visualizer_Plugin::CF_JSON_PAGING );
642 - }
643 -
644 280 if ( Visualizer_Module::is_pro() ) {
645 281 update_post_meta( $data['id'], Visualizer_PRO::CF_PERMISSIONS, $data['visualizer-permissions'] );
646 282 }
647 283
@@ -659,14 +295,8 @@
659 295 );
660 296
661 297 wp_update_post( $chart );
662 298
663 - // Clear existing chart cache.
664 - $cache_key = Visualizer_Plugin::CF_CHART_CACHE . '_' . $data['id'];
665 - if ( get_transient( $cache_key ) ) {
666 - delete_transient( $cache_key );
667 - }
668 -
669 299 $revisions = wp_get_post_revisions( $data['id'], array( 'order' => 'ASC' ) );
670 300
671 301 if ( count( $revisions ) > 1 ) {
672 302 $revision_ids = array_keys( $revisions );
@@ -682,10 +312,8 @@
682 312 }
683 313
684 314 /**
685 315 * Format chart data.
686 - *
687 - * Note: No matter how tempted, don't use the similar method from Visualizer_Source. That works on a different structure.
688 316 */
689 317 public function format_chart_data( $data, $series ) {
690 318 foreach ( $series as $i => $row ) {
691 319 // if no value exists for the seires, then add null
@@ -696,38 +324,39 @@
696 324 if ( is_null( $series[ $i ] ) ) {
697 325 continue;
698 326 }
699 327
700 - switch ( $row['type'] ) {
701 - case 'number':
702 - foreach ( $data as $o => $col ) {
703 - $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 + );
704 350 }
705 - break;
706 - case 'boolean':
707 - foreach ( $data as $o => $col ) {
708 - $data[ $o ][ $i ] = ! empty( $col[ $i ] ) ? filter_var( $col[ $i ], FILTER_VALIDATE_BOOLEAN ) : false;
709 - }
710 - break;
711 - case 'timeofday':
712 - foreach ( $data as $o => $col ) {
713 - $date = new DateTime( '1984-03-16T' . $col[ $i ] );
714 - if ( $date ) {
715 - $data[ $o ][ $i ] = array(
716 - intval( $date->format( 'H' ) ),
717 - intval( $date->format( 'i' ) ),
718 - intval( $date->format( 's' ) ),
719 - 0,
720 - );
721 - }
722 - }
723 - break;
724 - case 'string':
725 - foreach ( $data as $o => $col ) {
726 - $data[ $o ][ $i ] = $this->toUTF8( $col[ $i ] );
727 - }
728 - break;
351 + }
729 352 }
353 +
354 + if ( $row['type'] === 'string' ) {
355 + foreach ( $data as $o => $col ) {
356 + $data[ $o ][ $i ] = $this->toUTF8( $col[ $i ] );
357 + }
358 + }
730 359 }
731 360
732 361 return $data;
733 362 }
@@ -749,14 +378,10 @@
749 378 if ( ! current_user_can( 'edit_posts' ) ) {
750 379 return false;
751 380 }
752 381
753 - $remote_data = false;
754 - if ( isset( $data['url'] ) && function_exists( 'wp_http_validate_url' ) ) {
755 - $remote_data = wp_http_validate_url( $data['url'] );
756 - }
757 - if ( false !== $remote_data && ! is_wp_error( $remote_data ) ) {
758 - $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'] );
759 384 if ( $source->fetch() ) {
760 385 $temp = $source->getData();
761 386 if ( is_string( $temp ) && is_array( unserialize( $temp ) ) ) {
762 387 $content['series'] = $source->getSeries();
@@ -824,21 +449,11 @@
824 449 * Filter Rest Query
825 450 */
826 451 public function add_rest_query_vars( $args, \WP_REST_Request $request ) {
827 452 if ( isset( $request['meta_key'] ) && isset( $request['meta_value'] ) ) {
828 - $args['meta_query'] = array(
829 - 'relation' => 'OR',
830 - array(
831 - 'key' => $request->get_param( 'meta_key' ),
832 - 'value' => $request->get_param( 'meta_value' ),
833 - 'compare' => '!=',
834 - ),
835 - array(
836 - 'key' => $request->get_param( 'meta_key' ),
837 - 'value' => $request->get_param( 'meta_value' ),
838 - 'compare' => 'NOT EXISTS',
839 - ),
840 - );
453 + $args['meta_key'] = $request->get_param( 'meta_key' );
454 + $args['meta_value'] = $request->get_param( 'meta_value' );
455 + $args['meta_compare'] = '!=';
841 456 }
842 457 return $args;
843 458 }
844 459 }