PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.9.2
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.9.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/Module/Frontend.php +36 -117 4.0.33.9.2 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(
@@ -305,13 +304,8 @@
305 304 ),
306 305 $atts
307 306 );
308 307
309 - $atts['id'] = (int) $atts['id'];
310 - $atts['class'] = esc_attr( $atts['class'] );
311 - $atts['lazy'] = esc_attr( $atts['lazy'] );
312 - $atts['use_image'] = esc_attr( $atts['use_image'] );
313 -
314 308 global $sitepress;
315 309 if ( Visualizer_Module::is_pro() && ( function_exists( 'icl_get_languages' ) && $sitepress instanceof \SitePress ) ) {
316 310 global $sitepress;
317 311 $locale = icl_get_current_language();
@@ -340,15 +334,12 @@
340 334 if ( ! is_admin() && ! empty( $chart_data['is_woocommerce_report'] ) ) {
341 335 return '';
342 336 }
343 337
344 - // in case revisions exist (skip D3 charts to avoid reverting AI data).
345 - $chart_library = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_LIBRARY, true );
346 - if ( 'd3' !== $chart_library ) {
347 - $revisions = $this->undoRevisions( $chart->ID, true );
348 - if ( true === $revisions ) {
349 - $chart = get_post( $chart->ID );
350 - }
338 + // in case revisions exist.
339 + // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
340 + if ( true === ( $revisions = $this->undoRevisions( $chart->ID, true ) ) ) {
341 + $chart = get_post( $chart->ID );
351 342 }
352 343
353 344 $id = 'visualizer-' . $atts['id'];
354 345 $defaultClass = 'visualizer-front';
@@ -371,9 +362,8 @@
371 362 $chart = apply_filters( 'visualizer_schedule_refresh_chart', $chart, $chart->ID, false );
372 363
373 364 // Get and update settings.
374 365 $settings = $chart_data['settings'];
375 - $settings = ! empty( $settings ) ? $settings : array();
376 366 if ( empty( $settings['height'] ) ) {
377 367 $settings['height'] = '400';
378 368 }
379 369
@@ -385,11 +375,10 @@
385 375
386 376 $lazy_load = isset( $settings['lazy_load_chart'] ) ? $settings['lazy_load_chart'] : false;
387 377 $lazy_load = apply_filters( 'visualizer_lazy_load_chart', $lazy_load, $chart->ID );
388 378 $container_class = 'visualizer-front-container';
389 - if ( ! $lazy_load ) {
390 - $this->lazy_render_script = false;
391 - } else {
379 + if ( $lazy_load ) {
380 + $this->lazy_render_script = true;
392 381 $container_class .= ' visualizer-lazy-render';
393 382 }
394 383
395 384 // handle data filter hooks
@@ -435,9 +424,9 @@
435 424 unset( $settings['controls'] );
436 425 }
437 426
438 427 // add chart to the array
439 - $chart_entry = array(
428 + $this->_charts[ $id ] = array(
440 429 'type' => $type,
441 430 'series' => $series,
442 431 'settings' => $settings,
443 432 'data' => $data,
@@ -443,15 +432,8 @@
443 432 'data' => $data,
444 433 'library' => $library,
445 434 );
446 435
447 - // For D3 charts, include the stored code so the renderer can execute it.
448 - if ( 'd3' === $library ) {
449 - $chart_entry['code'] = get_post_meta( $chart->ID, Visualizer_Module_AIBuilder::CF_D3_CODE, true );
450 - }
451 -
452 - $this->_charts[ $id ] = $chart_entry;
453 -
454 436 $actions_div = '';
455 437 $actions_visible = apply_filters( 'visualizer_pro_add_actions', isset( $settings['actions'] ) ? $settings['actions'] : array(), $atts['id'] );
456 438 if ( ! empty( $actions_visible ) ) {
457 439 $actions = $this->get_actions();
@@ -485,104 +467,42 @@
485 467
486 468 $_charts = array();
487 469 $_charts_type = '';
488 470 $count = 0;
489 - static $visualizer_localized = false;
490 - static $visualizer_charts = array();
491 - static $d3_localized = false;
492 - $facade_handle = 'visualizer-render-facade';
493 471 foreach ( $this->_charts as $id => $array ) {
494 472 $_charts = $this->_charts;
495 473 $library = $array['library'];
496 474 $_charts_type = $library;
497 - $facade_deps = apply_filters( 'visualizer_assets_render', array( 'jquery', 'visualizer-customization' ), true );
498 - if ( ! wp_script_is( $facade_handle, 'registered' ) ) {
475 + if ( ! wp_script_is( "visualizer-render-$library", 'registered' ) ) {
499 476 wp_register_script(
500 - $facade_handle,
477 + "visualizer-render-$library",
501 478 VISUALIZER_ABSURL . 'js/render-facade.js',
502 - $facade_deps,
479 + apply_filters( 'visualizer_assets_render', array( 'jquery', 'visualizer-customization' ), true ),
503 480 Visualizer_Plugin::VERSION,
504 481 true
505 482 );
506 - wp_enqueue_script( $facade_handle );
507 - } else {
508 - // Ensure newly discovered dependencies are attached to the facade.
509 - global $wp_scripts;
510 - if ( isset( $wp_scripts->registered[ $facade_handle ] ) ) {
511 - $wp_scripts->registered[ $facade_handle ]->deps = array_unique(
512 - array_merge( $wp_scripts->registered[ $facade_handle ]->deps, $facade_deps )
513 - );
514 - }
515 - foreach ( $facade_deps as $dep_handle ) {
516 - wp_enqueue_script( $dep_handle );
517 - }
483 + wp_enqueue_script( "visualizer-render-$library" );
518 484 }
519 485
520 - // For D3 charts, also enqueue the dedicated renderer bundle.
521 - if ( 'd3' === $library ) {
522 - $d3_renderer_asset = VISUALIZER_ABSPATH . '/classes/Visualizer/D3Renderer/build/index.asset.php';
523 - if ( file_exists( $d3_renderer_asset ) && ! wp_script_is( 'visualizer-d3-renderer', 'registered' ) ) {
524 - /**
525 - * Ignore missing build asset in source checkout.
526 - *
527 - * @phpstan-ignore-next-line
528 - */
529 - $d3_asset = include $d3_renderer_asset;
530 - wp_register_script(
531 - 'visualizer-d3-renderer',
532 - VISUALIZER_ABSURL . 'classes/Visualizer/D3Renderer/build/index.js',
533 - array_merge( $d3_asset['dependencies'], array( 'jquery' ) ),
534 - $d3_asset['version'],
535 - true
536 - );
537 - wp_enqueue_script( 'visualizer-d3-renderer' );
538 - }
539 - if ( ! $d3_localized ) {
540 - wp_localize_script(
541 - 'visualizer-d3-renderer',
542 - 'vizD3Renderer',
543 - array(
544 - 'iframeJsUrl' => VISUALIZER_ABSURL . 'classes/Visualizer/D3Renderer/build/iframe.js',
545 - )
546 - );
547 - $d3_localized = true;
548 - }
486 + if ( wp_script_is( "visualizer-render-$_charts_type" ) && 0 === $count ) {
487 + wp_localize_script(
488 + "visualizer-render-$_charts_type",
489 + 'visualizer',
490 + array(
491 + 'charts' => $this->_charts,
492 + 'language' => $this->get_language(),
493 + 'map_api_key' => get_option( 'visualizer-map-api-key' ),
494 + 'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '',
495 + 'wp_nonce' => wp_create_nonce( 'wp_rest' ),
496 + 'i10n' => array(
497 + 'copied' => __( 'The data has been copied to your clipboard. Hit Ctrl-V/Cmd-V in your spreadsheet editor to paste the data.', 'visualizer' ),
498 + ),
499 + 'page_type' => 'frontend',
500 + 'is_front' => true,
501 + )
502 + );
549 503 }
550 -
551 - if ( wp_script_is( $facade_handle ) && 0 === $count ) {
552 - if ( ! $visualizer_localized ) {
553 - $visualizer_charts = $this->_charts;
554 - wp_localize_script(
555 - $facade_handle,
556 - 'visualizer',
557 - array(
558 - 'charts' => $this->_charts,
559 - 'language' => $this->get_language(),
560 - 'map_api_key' => get_option( 'visualizer-map-api-key' ),
561 - 'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '',
562 - 'wp_nonce' => wp_create_nonce( 'wp_rest' ),
563 - 'i10n' => array(
564 - 'copied' => __( 'The data has been copied to your clipboard. Hit Ctrl-V/Cmd-V in your spreadsheet editor to paste the data.', 'visualizer' ),
565 - ),
566 - 'page_type' => 'frontend',
567 - 'is_front' => true,
568 - )
569 - );
570 - $visualizer_localized = true;
571 - } else {
572 - $new_charts = array_diff_key( $this->_charts, $visualizer_charts );
573 - if ( ! empty( $new_charts ) ) {
574 - wp_add_inline_script(
575 - $facade_handle,
576 - 'window.visualizer = window.visualizer || {};' .
577 - 'window.visualizer.charts = Object.assign(window.visualizer.charts || {}, ' . wp_json_encode( $new_charts ) . ');',
578 - 'before'
579 - );
580 - $visualizer_charts = array_merge( $visualizer_charts, $new_charts );
581 - }
582 - }
583 - }
584 - ++$count;
504 + $count++;
585 505 }
586 506 $prefix = 'C' . 'h' . 'a' . 'rt';
587 507 if ( $type === 'tabular' ) {
588 508 $prefix = 'T' . 'a' . 'bl' . 'e';
@@ -590,9 +510,9 @@
590 510 if ( Visualizer_Module::is_pro() && $enable_controls ) {
591 511 $actions_div .= '<div id="control_wrapper_' . $id . '"></div>';
592 512 }
593 513 // return placeholder div
594 - return '<div class="' . $container_class . '" id="chart_wrapper_' . $id . '">' . $actions_div . '<div id="' . $id . '"' . $this->getHtmlAttributes( $attributes ) . '></div>' . $this->addSchema( $chart->ID ) . '</div>';
514 + return '<div class="' . $container_class . '" id="chart_wrapper_' . $id . '">' . $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>';
595 515 }
596 516
597 517 /**
598 518 * Converts the array of attributes to a string of HTML attributes.
@@ -771,9 +691,8 @@
771 691 if ( $this->lazy_render_script ) {
772 692 ?>
773 693 <script type="text/javascript">
774 694 var visualizerUserInteractionEvents = [
775 - "scroll",
776 695 "mouseover",
777 696 "keydown",
778 697 "touchmove",
779 698 "touchstart"