PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.7.9
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.7.9
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/Module/Frontend.php +50 -178 4.0.53.7.9 View file →
@@ -46,9 +46,9 @@
46 46 *
47 47 * @access private
48 48 * @var bool
49 49 */
50 - private $lazy_render_script = true;
50 + private $lazy_render_script = false;
51 51
52 52 /**
53 53 * Constructor.
54 54 *
@@ -63,9 +63,8 @@
63 63
64 64 $this->_addAction( 'wp_print_footer_scripts', 'printFooterScripts' );
65 65 $this->_addAction( 'wp_enqueue_scripts', 'enqueueScripts' );
66 66 $this->_addAction( 'load-index.php', 'enqueueScripts' );
67 - $this->_addAction( 'load-visualizer_page_visualizer-setup-wizard', 'enqueueScripts' );
68 67 $this->_addAction( 'visualizer_enqueue_scripts', 'enqueueScripts' );
69 68 $this->_addFilter( 'visualizer_get_language', 'getLanguage' );
70 69 $this->_addShortcode( 'visualizer', 'renderChart' );
71 70
@@ -86,9 +85,9 @@
86 85
87 86 /**
88 87 * Adds the async attribute to certain scripts.
89 88 */
90 - public function script_loader_tag( $tag, $handle, $src ) {
89 + function script_loader_tag( $tag, $handle, $src ) {
91 90 if ( is_admin() ) {
92 91 return $tag;
93 92 }
94 93 // Async scripts.
@@ -97,9 +96,9 @@
97 96 if ( $async === $handle ) {
98 97 $tag = str_replace( ' src', ' async src', $tag );
99 98 break;
100 99 }
101 - }
100 + };
102 101
103 102 // Async scripts.
104 103 $scripts = array( 'dom-to-image' );
105 104 foreach ( array( 'async', 'defer' ) as $attr ) {
@@ -123,9 +122,9 @@
123 122
124 123 /**
125 124 * Returns the language/locale.
126 125 */
127 - public function getLanguage( $dummy, $only_language ) {
126 + function getLanguage( $dummy, $only_language ) {
128 127 return $this->get_language();
129 128 }
130 129
131 130
@@ -131,9 +130,9 @@
131 130
132 131 /**
133 132 * Registers the endpoints
134 133 */
135 - public function endpoint_register() {
134 + function endpoint_register() {
136 135 register_rest_route(
137 136 'visualizer/v' . VISUALIZER_REST_VERSION,
138 137 '/action/(?P<chart>\d+)/(?P<type>.+)/',
139 138 array(
@@ -141,9 +140,9 @@
141 140 'methods' => array( 'POST', 'GET' ),
142 141 'args' => array(
143 142 'chart' => array(
144 143 'required' => true,
145 - 'sanitize_callback' => function ( $param ) {
144 + 'sanitize_callback' => function( $param ) {
146 145 return is_numeric( $param ) ? $param : null;
147 146 },
148 147 ),
149 148 'type' => array(
@@ -152,27 +151,16 @@
152 151 'enum' => array_merge( array( 'save', 'cancel' ), array_keys( $this->get_actions() ) ),
153 152 ),
154 153 ),
155 154 'permission_callback' => function ( WP_REST_Request $request ) {
156 - $chart_id = absint( $request->get_param( 'chart' ) );
157 - if ( ! $chart_id ) {
158 - return false;
155 + $chart_id = filter_var( sanitize_text_field( $request->get_param( 'chart' ), FILTER_VALIDATE_INT ) );
156 + if ( ! empty( $chart_id ) && in_array( $request->get_param( 'type' ), array( 'save', 'cancel' ), true ) ) {
157 + // let save and cancel go without any check as past version of pro
158 + // did not send the X-WP-Nonce
159 + // we can change this at a later date.
160 + return true;
159 161 }
160 -
161 - $chart = get_post( $chart_id );
162 - if ( ! $chart || Visualizer_Plugin::CPT_VISUALIZER !== $chart->post_type ) {
163 - return false;
164 - }
165 -
166 - if ( in_array( $request->get_param( 'type' ), array( 'save', 'cancel' ), true ) ) {
167 - return current_user_can( 'edit_post', $chart_id );
168 - }
169 -
170 - if ( 'publish' !== $chart->post_status ) {
171 - return current_user_can( 'edit_post', $chart_id );
172 - }
173 -
174 - return apply_filters( 'visualizer_pro_show_chart', true, $chart_id );
162 + return ! empty( $chart_id ) && apply_filters( 'visualizer_pro_show_chart', true, $chart_id );
175 163 },
176 164 'callback' => array( $this, 'perform_action' ),
177 165 )
178 166 );
@@ -316,25 +304,8 @@
316 304 ),
317 305 $atts
318 306 );
319 307
320 - $atts['id'] = (int) $atts['id'];
321 - $atts['class'] = esc_attr( $atts['class'] );
322 - $atts['lazy'] = esc_attr( $atts['lazy'] );
323 - $atts['use_image'] = esc_attr( $atts['use_image'] );
324 -
325 - global $sitepress;
326 - if ( Visualizer_Module::is_pro() && ( function_exists( 'icl_get_languages' ) && $sitepress instanceof \SitePress ) ) {
327 - global $sitepress;
328 - $locale = icl_get_current_language();
329 - $locale = strtolower( str_replace( '_', '-', $locale ) );
330 - $trid = $sitepress->get_element_trid( $atts['id'], 'post_' . Visualizer_Plugin::CPT_VISUALIZER );
331 - $translations = $sitepress->get_element_translations( $trid );
332 - if ( isset( $translations[ $locale ] ) && is_object( $translations[ $locale ] ) ) {
333 - $atts['id'] = $translations[ $locale ]->element_id;
334 - }
335 - }
336 -
337 308 $chart_data = $this->getChartData( Visualizer_Plugin::CF_CHART_CACHE, $atts['id'] );
338 309 // if empty chart does not exists, then return empty string.
339 310 if ( ! $chart_data ) {
340 311 return '';
@@ -347,21 +318,14 @@
347 318 if ( ! apply_filters( 'visualizer_pro_show_chart', true, $atts['id'] ) ) {
348 319 return '';
349 320 }
350 321
351 - if ( ! is_admin() && ! empty( $chart_data['is_woocommerce_report'] ) ) {
352 - return '';
322 + // in case revisions exist.
323 + // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
324 + if ( true === ( $revisions = $this->undoRevisions( $chart->ID, true ) ) ) {
325 + $chart = get_post( $chart->ID );
353 326 }
354 327
355 - // in case revisions exist (skip D3 charts to avoid reverting AI data).
356 - $chart_library = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_LIBRARY, true );
357 - if ( 'd3' !== $chart_library ) {
358 - $revisions = $this->undoRevisions( $chart->ID, true );
359 - if ( true === $revisions ) {
360 - $chart = get_post( $chart->ID );
361 - }
362 - }
363 -
364 328 $id = 'visualizer-' . $atts['id'];
365 329 $defaultClass = 'visualizer-front';
366 330 $class = apply_filters( Visualizer_Plugin::FILTER_CHART_WRAPPER_CLASS, $atts['class'], $atts['id'] );
367 331
@@ -376,15 +340,12 @@
376 340 if ( ctype_digit( $atts['lazy'] ) ) {
377 341 $attributes['data-lazy-limit'] = $atts['lazy'];
378 342 }
379 343
380 - $attributes = apply_filters( 'visualizer_container_attributes', $attributes, $chart->ID );
381 -
382 344 $chart = apply_filters( 'visualizer_schedule_refresh_chart', $chart, $chart->ID, false );
383 345
384 346 // Get and update settings.
385 347 $settings = $chart_data['settings'];
386 - $settings = ! empty( $settings ) ? $settings : array();
387 348 if ( empty( $settings['height'] ) ) {
388 349 $settings['height'] = '400';
389 350 }
390 351
@@ -396,11 +357,10 @@
396 357
397 358 $lazy_load = isset( $settings['lazy_load_chart'] ) ? $settings['lazy_load_chart'] : false;
398 359 $lazy_load = apply_filters( 'visualizer_lazy_load_chart', $lazy_load, $chart->ID );
399 360 $container_class = 'visualizer-front-container';
400 - if ( ! $lazy_load ) {
401 - $this->lazy_render_script = false;
402 - } else {
361 + if ( $lazy_load ) {
362 + $this->lazy_render_script = true;
403 363 $container_class .= ' visualizer-lazy-render';
404 364 }
405 365
406 366 // handle data filter hooks
@@ -432,23 +392,10 @@
432 392 if ( isset( $settings['chart-img'] ) ) {
433 393 unset( $settings['chart-img'] );
434 394 }
435 395
436 - $enable_controls = false;
437 - if ( isset( $settings['controls'] ) && ! empty( $settings['controls']['controlType'] ) ) {
438 - $column_index = $settings['controls']['filterColumnIndex'];
439 - $column_label = $settings['controls']['filterColumnLabel'];
440 - if ( 'false' !== $column_index || 'false' !== $column_label ) {
441 - $enable_controls = true;
442 - }
443 - }
444 -
445 - if ( ! $enable_controls ) {
446 - unset( $settings['controls'] );
447 - }
448 -
449 396 // add chart to the array
450 - $chart_entry = array(
397 + $this->_charts[ $id ] = array(
451 398 'type' => $type,
452 399 'series' => $series,
453 400 'settings' => $settings,
454 401 'data' => $data,
@@ -454,15 +401,8 @@
454 401 'data' => $data,
455 402 'library' => $library,
456 403 );
457 404
458 - // For D3 charts, include the stored code so the renderer can execute it.
459 - if ( 'd3' === $library ) {
460 - $chart_entry['code'] = get_post_meta( $chart->ID, Visualizer_Module_AIBuilder::CF_D3_CODE, true );
461 - }
462 -
463 - $this->_charts[ $id ] = $chart_entry;
464 -
465 405 $actions_div = '';
466 406 $actions_visible = apply_filters( 'visualizer_pro_add_actions', isset( $settings['actions'] ) ? $settings['actions'] : array(), $atts['id'] );
467 407 if ( ! empty( $actions_visible ) ) {
468 408 $actions = $this->get_actions();
@@ -496,114 +436,49 @@
496 436
497 437 $_charts = array();
498 438 $_charts_type = '';
499 439 $count = 0;
500 - static $visualizer_localized = false;
501 - static $visualizer_charts = array();
502 - static $d3_localized = false;
503 - $facade_handle = 'visualizer-render-facade';
504 440 foreach ( $this->_charts as $id => $array ) {
505 441 $_charts = $this->_charts;
506 442 $library = $array['library'];
507 443 $_charts_type = $library;
508 - $facade_deps = apply_filters( 'visualizer_assets_render', array( 'jquery', 'visualizer-customization' ), true );
509 - if ( ! wp_script_is( $facade_handle, 'registered' ) ) {
444 + if ( ! wp_script_is( "visualizer-render-$library", 'registered' ) ) {
510 445 wp_register_script(
511 - $facade_handle,
446 + "visualizer-render-$library",
512 447 VISUALIZER_ABSURL . 'js/render-facade.js',
513 - $facade_deps,
448 + apply_filters( 'visualizer_assets_render', array( 'jquery', 'visualizer-customization' ), true ),
514 449 Visualizer_Plugin::VERSION,
515 450 true
516 451 );
517 - wp_enqueue_script( $facade_handle );
518 - } else {
519 - // Ensure newly discovered dependencies are attached to the facade.
520 - global $wp_scripts;
521 - if ( isset( $wp_scripts->registered[ $facade_handle ] ) ) {
522 - $wp_scripts->registered[ $facade_handle ]->deps = array_unique(
523 - array_merge( $wp_scripts->registered[ $facade_handle ]->deps, $facade_deps )
524 - );
525 - }
526 - foreach ( $facade_deps as $dep_handle ) {
527 - wp_enqueue_script( $dep_handle );
528 - }
452 + wp_enqueue_script( "visualizer-render-$library" );
529 453 }
530 454
531 - // For D3 charts, also enqueue the dedicated renderer bundle.
532 - if ( 'd3' === $library ) {
533 - $d3_renderer_asset = VISUALIZER_ABSPATH . '/classes/Visualizer/D3Renderer/build/index.asset.php';
534 - if ( file_exists( $d3_renderer_asset ) && ! wp_script_is( 'visualizer-d3-renderer', 'registered' ) ) {
535 - /**
536 - * Ignore missing build asset in source checkout.
537 - *
538 - * @phpstan-ignore-next-line
539 - */
540 - $d3_asset = include $d3_renderer_asset;
541 - wp_register_script(
542 - 'visualizer-d3-renderer',
543 - VISUALIZER_ABSURL . 'classes/Visualizer/D3Renderer/build/index.js',
544 - array_merge( $d3_asset['dependencies'], array( 'jquery' ) ),
545 - $d3_asset['version'],
546 - true
547 - );
548 - wp_enqueue_script( 'visualizer-d3-renderer' );
549 - }
550 - if ( ! $d3_localized ) {
551 - wp_localize_script(
552 - 'visualizer-d3-renderer',
553 - 'vizD3Renderer',
554 - array(
555 - 'iframeJsUrl' => VISUALIZER_ABSURL . 'classes/Visualizer/D3Renderer/build/iframe.js',
556 - )
557 - );
558 - $d3_localized = true;
559 - }
455 + if ( wp_script_is( "visualizer-render-$_charts_type" ) && 0 === $count ) {
456 + wp_localize_script(
457 + "visualizer-render-$_charts_type",
458 + 'visualizer',
459 + array(
460 + 'charts' => $this->_charts,
461 + 'language' => $this->get_language(),
462 + 'map_api_key' => get_option( 'visualizer-map-api-key' ),
463 + 'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '',
464 + 'wp_nonce' => wp_create_nonce( 'wp_rest' ),
465 + 'i10n' => array(
466 + 'copied' => __( 'The data has been copied to your clipboard. Hit Ctrl-V/Cmd-V in your spreadsheet editor to paste the data.', 'visualizer' ),
467 + ),
468 + 'page_type' => 'frontend',
469 + 'is_front' => true,
470 + )
471 + );
560 472 }
561 -
562 - if ( wp_script_is( $facade_handle ) && 0 === $count ) {
563 - if ( ! $visualizer_localized ) {
564 - $visualizer_charts = $this->_charts;
565 - wp_localize_script(
566 - $facade_handle,
567 - 'visualizer',
568 - array(
569 - 'charts' => $this->_charts,
570 - 'language' => $this->get_language(),
571 - 'map_api_key' => get_option( 'visualizer-map-api-key' ),
572 - 'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '',
573 - 'wp_nonce' => wp_create_nonce( 'wp_rest' ),
574 - 'i10n' => array(
575 - 'copied' => __( 'The data has been copied to your clipboard. Hit Ctrl-V/Cmd-V in your spreadsheet editor to paste the data.', 'visualizer' ),
576 - ),
577 - 'page_type' => 'frontend',
578 - 'is_front' => true,
579 - )
580 - );
581 - $visualizer_localized = true;
582 - } else {
583 - $new_charts = array_diff_key( $this->_charts, $visualizer_charts );
584 - if ( ! empty( $new_charts ) ) {
585 - wp_add_inline_script(
586 - $facade_handle,
587 - 'window.visualizer = window.visualizer || {};' .
588 - 'window.visualizer.charts = Object.assign(window.visualizer.charts || {}, ' . wp_json_encode( $new_charts ) . ');',
589 - 'before'
590 - );
591 - $visualizer_charts = array_merge( $visualizer_charts, $new_charts );
592 - }
593 - }
594 - }
595 - ++$count;
473 + $count++;
596 474 }
597 475 $prefix = 'C' . 'h' . 'a' . 'rt';
598 476 if ( $type === 'tabular' ) {
599 477 $prefix = 'T' . 'a' . 'bl' . 'e';
600 478 }
601 - if ( Visualizer_Module::is_pro() && $enable_controls ) {
602 - $actions_div .= '<div id="control_wrapper_' . $id . '"></div>';
603 - }
604 479 // return placeholder div
605 - return '<div class="' . $container_class . '" id="chart_wrapper_' . $id . '">' . $actions_div . '<div id="' . $id . '"' . $this->getHtmlAttributes( $attributes ) . '></div>' . $this->addSchema( $chart->ID ) . '</div>';
480 + return '<div class="' . $container_class . '">' . $actions_div . '<div id="' . $id . '"' . $this->getHtmlAttributes( $attributes ) . '></div>' . $this->addSchema( $chart->ID ) . ( ! Visualizer_Module::is_pro() ? ( '<' . 'di' . 'v st' . 'yl' . 'e="' . 'op' . 'a' . 'ci' . 't' . 'y:' . '0' . '.' . '.7' . ';t' . 'ex' . 't-a' . 'li' . 'gn:' . 'ri' . 'gh' . 't;b' . 'o' . 'tto' . 'm: 1' . '0px; z-i' . 'nd' . 'ex:1' . '00' . '0; ' . 'le' . 'ft' . ':2' . '0px' . '; fo' . 'nt-si' . 'ze: 1' . '4px">' . $prefix . ' b' . 'y' . ' <a ' . 'h' . 're' . 'f="ht' . 'tp' . 's:/' . '/t' . 'he' . 'me' . 'i' . 'sl' . 'e' . '.c' . 'om' . '/p' . 'lu' . 'gi' . 'ns' . '/v' . 'i' . 'su' . 'al' . 'iz' . 'er' . '-c' . 'ha' . 'rts' . '-a' . 'nd' . '-gr' . 'ap' . 'hs' . '/" t' . 'arg' . 'et="' . '_bl' . 'an' . 'k" re' . 'l=' . '"no' . 'fol' . 'l' . 'ow"' . '>V' . 'is' . 'u' . 'a' . 'l' . 'i' . 'z' . 'e' . 'r' . '</' . 'a' . '>' . '<' . '/' . 'd' . 'i' . 'v' . '>' ) : '' ) . '</div>';
606 481 }
607 482
608 483 /**
609 484 * Converts the array of attributes to a string of HTML attributes.
@@ -745,11 +620,10 @@
745 620
746 621 // Get chart by ID.
747 622 $chart = get_post( $chart_id );
748 623 if ( $chart && Visualizer_Plugin::CPT_VISUALIZER === $chart->post_type ) {
749 - $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
750 - $series = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true );
751 - $is_woocommerce_report = get_post_meta( $chart->ID, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true );
624 + $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
625 + $series = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true );
752 626
753 627 if ( isset( $settings['series'] ) && ! ( count( $settings['series'] ) - count( $series ) > 1 ) ) {
754 628 $diff_total_series = abs( count( $settings['series'] ) - count( $series ) );
755 629 if ( $diff_total_series ) {
@@ -758,14 +632,13 @@
758 632 }
759 633 }
760 634 }
761 635 $chart_data = array(
762 - 'chart' => $chart,
763 - 'type' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ),
764 - 'settings' => $settings,
765 - 'series' => $series,
766 - 'chart_image' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_IMAGE, true ),
767 - 'is_woocommerce_report' => $is_woocommerce_report,
636 + 'chart' => $chart,
637 + 'type' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ),
638 + 'settings' => $settings,
639 + 'series' => $series,
640 + 'chart_image' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_IMAGE, true ),
768 641 );
769 642
770 643 // Put the results in a transient. Expire after 12 hours.
771 644 set_transient( $cache_key, $chart_data, apply_filters( Visualizer_Plugin::FILTER_HANDLE_CACHE_EXPIRATION_TIME, 12 * HOUR_IN_SECONDS ) );
@@ -782,9 +655,8 @@
782 655 if ( $this->lazy_render_script ) {
783 656 ?>
784 657 <script type="text/javascript">
785 658 var visualizerUserInteractionEvents = [
786 - "scroll",
787 659 "mouseover",
788 660 "keydown",
789 661 "touchmove",
790 662 "touchstart"