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