PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.0
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.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/Gutenberg/Block.php +50 -128 3.10.03.4.0 View file →
@@ -79,16 +79,8 @@
79 79 } else {
80 80 $version = $this->version;
81 81 }
82 82
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 83 // Enqueue the bundled block JS file
92 84 wp_enqueue_script( 'handsontable', $handsontableJS );
93 85 wp_enqueue_script( 'visualizer-gutenberg-block', $blockPath, array( 'wp-api', 'handsontable', 'visualizer-datatables', 'moment' ), $version, true );
94 86
@@ -104,15 +96,13 @@
104 96 $table_col_mapping = Visualizer_Source_Query_Params::get_all_db_tables_column_mapping( null, false );
105 97
106 98 $translation_array = array(
107 99 'isPro' => $type,
108 - 'proTeaser' => tsdk_utmify( Visualizer_Plugin::PRO_TEASER_URL, 'blockupsell'),
100 + 'proTeaser' => Visualizer_Plugin::PRO_TEASER_URL,
109 101 'absurl' => VISUALIZER_ABSURL,
110 102 'charts' => Visualizer_Module_Admin::_getChartTypesLocalized(),
111 103 'adminPage' => menu_page_url( 'visualizer', false ),
112 104 'sqlTable' => $table_col_mapping,
113 - 'chartsPerPage' => defined( 'TI_CYPRESS_TESTING' ) ? 20 : 6,
114 - 'proFeaturesLocked' => Visualizer_Module_Admin::proFeaturesLocked(),
115 105 );
116 106 wp_localize_script( 'visualizer-gutenberg-block', 'visualizerLocalize', $translation_array );
117 107
118 108 // Enqueue frontend and editor block styles
@@ -147,11 +137,8 @@
147 137 'attributes' => array(
148 138 'id' => array(
149 139 'type' => 'number',
150 140 ),
151 - 'lazy' => array(
152 - 'type' => 'string',
153 - ),
154 141 ),
155 142 )
156 143 );
157 144 }
@@ -158,46 +145,16 @@
158 145
159 146 /**
160 147 * Gutenberg Block Callback Function
161 148 */
162 - public function gutenberg_block_callback( $atts ) {
163 - // no id, no fun.
164 - if ( ! isset( $atts['id'] ) ) {
165 - return '';
149 + public function gutenberg_block_callback( $attr ) {
150 + if ( isset( $attr['id'] ) ) {
151 + $id = $attr['id'];
152 + if ( empty( $id ) || $id === 'none' ) {
153 + return ''; // no id = no fun
154 + }
155 + return '[visualizer id="' . $id . '"]';
166 156 }
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 157 }
201 158
202 159 /**
203 160 * Hook server side rendering into render callback
@@ -360,14 +317,8 @@
360 317
361 318 // handle data filter hooks
362 319 $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 320
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 321 $data['visualizer-data-exploded'] = '';
371 322 // handle annotations for google charts
372 323 if ( 'GoogleCharts' === $library ) {
373 324 // this will contain the data of both axis.
@@ -384,12 +335,8 @@
384 335 if ( ! empty( $serie['role'] ) ) {
385 336 // this series is some kind of annotation, so let's collect its index.
386 337 // the index will be +1 because the X axis value is index 0, which is being ignored.
387 338 $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 339 }
393 340 }
394 341 }
395 342 if ( ! empty( $annotations ) ) {
@@ -458,18 +405,11 @@
458 405
459 406 if ( Visualizer_Module::is_pro() ) {
460 407 $permissions = get_post_meta( $post_id, Visualizer_PRO::CF_PERMISSIONS, true );
461 408
462 - if ( empty( $permissions ) ) {
463 - $permissions = array( 'permissions' => array(
464 - 'read' => 'all',
465 - 'edit' => 'roles',
466 - 'edit-specific' => array( 'administrator' ),
467 - ),
468 - );
409 + if ( ! empty( $permissions ) ) {
410 + $data['visualizer-permissions'] = $permissions;
469 411 }
470 -
471 - $data['visualizer-permissions'] = $permissions;
472 412 }
473 413
474 414 return $data;
475 415 }
@@ -578,11 +518,9 @@
578 518 return false;
579 519 }
580 520
581 521 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 - }
522 +
585 523 $chart_type = sanitize_text_field( $data['visualizer-chart-type'] );
586 524 $source_type = sanitize_text_field( $data['visualizer-source'] );
587 525
588 526 update_post_meta( $data['id'], Visualizer_Plugin::CF_CHART_TYPE, $chart_type );
@@ -600,21 +538,16 @@
600 538 delete_post_meta( $data['id'], Visualizer_Plugin::CF_CHART_URL );
601 539 apply_filters( 'visualizer_pro_remove_schedule', $data['id'] );
602 540 }
603 541
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 - }
542 + if ( $source_type === 'Visualizer_Source_Query' ) {
543 + $db_schedule = intval( $data['visualizer-db-schedule'] );
544 + $db_query = $data['visualizer-db-query'];
545 + update_post_meta( $data['id'], Visualizer_Plugin::CF_DB_SCHEDULE, $db_schedule );
546 + update_post_meta( $data['id'], Visualizer_Plugin::CF_DB_QUERY, stripslashes( $db_query ) );
547 + } else {
548 + delete_post_meta( $data['id'], Visualizer_Plugin::CF_DB_SCHEDULE );
549 + delete_post_meta( $data['id'], Visualizer_Plugin::CF_DB_QUERY );
617 550 }
618 551
619 552 if ( $source_type === 'Visualizer_Source_Json' ) {
620 553 $json_schedule = intval( $data['visualizer-json-schedule'] );
@@ -659,14 +592,8 @@
659 592 );
660 593
661 594 wp_update_post( $chart );
662 595
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 596 $revisions = wp_get_post_revisions( $data['id'], array( 'order' => 'ASC' ) );
670 597
671 598 if ( count( $revisions ) > 1 ) {
672 599 $revision_ids = array_keys( $revisions );
@@ -682,10 +609,8 @@
682 609 }
683 610
684 611 /**
685 612 * 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 613 */
689 614 public function format_chart_data( $data, $series ) {
690 615 foreach ( $series as $i => $row ) {
691 616 // if no value exists for the seires, then add null
@@ -696,38 +621,39 @@
696 621 if ( is_null( $series[ $i ] ) ) {
697 622 continue;
698 623 }
699 624
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 );
625 + if ( $row['type'] === 'number' ) {
626 + foreach ( $data as $o => $col ) {
627 + $data[ $o ][ $i ] = ( is_numeric( $col[ $i ] ) ) ? floatval( $col[ $i ] ) : ( is_numeric( str_replace( ',', '', $col[ $i ] ) ) ? floatval( str_replace( ',', '', $col[ $i ] ) ) : null );
628 + }
629 + }
630 +
631 + if ( $row['type'] === 'boolean' ) {
632 + foreach ( $data as $o => $col ) {
633 + $data[ $o ][ $i ] = ! empty( $col[ $i ] ) ? filter_validate( $col[ $i ], FILTER_VALIDATE_BOOLEAN ) : null;
634 + }
635 + }
636 +
637 + if ( $row['type'] === 'timeofday' ) {
638 + foreach ( $data as $o => $col ) {
639 + $date = new DateTime( '1984-03-16T' . $col[ $i ] );
640 + if ( $date ) {
641 + $data[ $o ][ $i ] = array(
642 + intval( $date->format( 'H' ) ),
643 + intval( $date->format( 'i' ) ),
644 + intval( $date->format( 's' ) ),
645 + 0,
646 + );
704 647 }
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;
648 + }
729 649 }
650 +
651 + if ( $row['type'] === 'string' ) {
652 + foreach ( $data as $o => $col ) {
653 + $data[ $o ][ $i ] = $this->toUTF8( $col[ $i ] );
654 + }
655 + }
730 656 }
731 657
732 658 return $data;
733 659 }
@@ -749,14 +675,10 @@
749 675 if ( ! current_user_can( 'edit_posts' ) ) {
750 676 return false;
751 677 }
752 678
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 );
679 + if ( $data['url'] && ! is_wp_error( $data['url'] ) && filter_var( $data['url'], FILTER_VALIDATE_URL ) ) {
680 + $source = new Visualizer_Source_Csv_Remote( $data['url'] );
759 681 if ( $source->fetch() ) {
760 682 $temp = $source->getData();
761 683 if ( is_string( $temp ) && is_array( unserialize( $temp ) ) ) {
762 684 $content['series'] = $source->getSeries();