| @@ -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 | |
| @@ -305,25 +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 | - global $sitepress; | |
| 315 | - if ( Visualizer_Module::is_pro() && ( function_exists( 'icl_get_languages' ) && $sitepress instanceof \SitePress ) ) { | |
| 316 | - global $sitepress; | |
| 317 | - $locale = icl_get_current_language(); | |
| 318 | - $locale = strtolower( str_replace( '_', '-', $locale ) ); | |
| 319 | - $trid = $sitepress->get_element_trid( $atts['id'], 'post_' . Visualizer_Plugin::CPT_VISUALIZER ); | |
| 320 | - $translations = $sitepress->get_element_translations( $trid ); | |
| 321 | - if ( isset( $translations[ $locale ] ) && is_object( $translations[ $locale ] ) ) { | |
| 322 | - $atts['id'] = $translations[ $locale ]->element_id; | |
| 323 | - } | |
| 324 | - } | |
| 325 | - | |
| 326 | 308 | $chart_data = $this->getChartData( Visualizer_Plugin::CF_CHART_CACHE, $atts['id'] ); |
| 327 | 309 | // if empty chart does not exists, then return empty string. |
| 328 | 310 | if ( ! $chart_data ) { |
| 329 | 311 | return ''; |
| @@ -336,12 +318,8 @@ | ||
| 336 | 318 | if ( ! apply_filters( 'visualizer_pro_show_chart', true, $atts['id'] ) ) { |
| 337 | 319 | return ''; |
| 338 | 320 | } |
| 339 | 321 | |
| 340 | - if ( ! is_admin() && ! empty( $chart_data['is_woocommerce_report'] ) ) { | |
| 341 | - return ''; | |
| 342 | - } | |
| 343 | - | |
| 344 | 322 | // in case revisions exist. |
| 345 | 323 | // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found |
| 346 | 324 | if ( true === ( $revisions = $this->undoRevisions( $chart->ID, true ) ) ) { |
| 347 | 325 | $chart = get_post( $chart->ID ); |
| @@ -362,15 +340,12 @@ | ||
| 362 | 340 | if ( ctype_digit( $atts['lazy'] ) ) { |
| 363 | 341 | $attributes['data-lazy-limit'] = $atts['lazy']; |
| 364 | 342 | } |
| 365 | 343 | |
| 366 | - $attributes = apply_filters( 'visualizer_container_attributes', $attributes, $chart->ID ); | |
| 367 | - | |
| 368 | 344 | $chart = apply_filters( 'visualizer_schedule_refresh_chart', $chart, $chart->ID, false ); |
| 369 | 345 | |
| 370 | 346 | // Get and update settings. |
| 371 | 347 | $settings = $chart_data['settings']; |
| 372 | - $settings = ! empty( $settings ) ? $settings : array(); | |
| 373 | 348 | if ( empty( $settings['height'] ) ) { |
| 374 | 349 | $settings['height'] = '400'; |
| 375 | 350 | } |
| 376 | 351 | |
| @@ -417,21 +392,8 @@ | ||
| 417 | 392 | if ( isset( $settings['chart-img'] ) ) { |
| 418 | 393 | unset( $settings['chart-img'] ); |
| 419 | 394 | } |
| 420 | 395 | |
| 421 | - $enable_controls = false; | |
| 422 | - if ( isset( $settings['controls'] ) && ! empty( $settings['controls']['controlType'] ) ) { | |
| 423 | - $column_index = $settings['controls']['filterColumnIndex']; | |
| 424 | - $column_label = $settings['controls']['filterColumnLabel']; | |
| 425 | - if ( 'false' !== $column_index || 'false' !== $column_label ) { | |
| 426 | - $enable_controls = true; | |
| 427 | - } | |
| 428 | - } | |
| 429 | - | |
| 430 | - if ( ! $enable_controls ) { | |
| 431 | - unset( $settings['controls'] ); | |
| 432 | - } | |
| 433 | - | |
| 434 | 396 | // add chart to the array |
| 435 | 397 | $this->_charts[ $id ] = array( |
| 436 | 398 | 'type' => $type, |
| 437 | 399 | 'series' => $series, |
| @@ -473,9 +435,8 @@ | ||
| 473 | 435 | $actions_div .= $css; |
| 474 | 436 | |
| 475 | 437 | $_charts = array(); |
| 476 | 438 | $_charts_type = ''; |
| 477 | - $count = 0; | |
| 478 | 439 | foreach ( $this->_charts as $id => $array ) { |
| 479 | 440 | $_charts = $this->_charts; |
| 480 | 441 | $library = $array['library']; |
| 481 | 442 | $_charts_type = $library; |
| @@ -488,38 +449,30 @@ | ||
| 488 | 449 | true |
| 489 | 450 | ); |
| 490 | 451 | wp_enqueue_script( "visualizer-render-$library" ); |
| 491 | 452 | } |
| 492 | - | |
| 493 | - if ( wp_script_is( "visualizer-render-$_charts_type" ) && 0 === $count ) { | |
| 494 | - wp_localize_script( | |
| 495 | - "visualizer-render-$_charts_type", | |
| 496 | - 'visualizer', | |
| 497 | - array( | |
| 498 | - 'charts' => $this->_charts, | |
| 499 | - 'language' => $this->get_language(), | |
| 500 | - 'map_api_key' => get_option( 'visualizer-map-api-key' ), | |
| 501 | - 'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '', | |
| 502 | - 'wp_nonce' => wp_create_nonce( 'wp_rest' ), | |
| 503 | - 'i10n' => array( | |
| 504 | - 'copied' => __( 'The data has been copied to your clipboard. Hit Ctrl-V/Cmd-V in your spreadsheet editor to paste the data.', 'visualizer' ), | |
| 505 | - ), | |
| 506 | - 'page_type' => 'frontend', | |
| 507 | - 'is_front' => true, | |
| 508 | - ) | |
| 509 | - ); | |
| 510 | - } | |
| 511 | - $count++; | |
| 512 | 453 | } |
| 513 | - $prefix = 'C' . 'h' . 'a' . 'rt'; | |
| 514 | - if ( $type === 'tabular' ) { | |
| 515 | - $prefix = 'T' . 'a' . 'bl' . 'e'; | |
| 454 | + if ( wp_script_is( "visualizer-render-$_charts_type" ) ) { | |
| 455 | + wp_localize_script( | |
| 456 | + "visualizer-render-$_charts_type", | |
| 457 | + 'visualizer', | |
| 458 | + array( | |
| 459 | + 'charts' => $_charts, | |
| 460 | + 'language' => $this->get_language(), | |
| 461 | + 'map_api_key' => get_option( 'visualizer-map-api-key' ), | |
| 462 | + 'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '', | |
| 463 | + 'wp_nonce' => wp_create_nonce( 'wp_rest' ), | |
| 464 | + 'i10n' => array( | |
| 465 | + 'copied' => __( 'The data has been copied to your clipboard. Hit Ctrl-V/Cmd-V in your spreadsheet editor to paste the data.', 'visualizer' ), | |
| 466 | + ), | |
| 467 | + 'page_type' => 'frontend', | |
| 468 | + 'is_front' => true, | |
| 469 | + ) | |
| 470 | + ); | |
| 516 | 471 | } |
| 517 | - if ( Visualizer_Module::is_pro() && $enable_controls ) { | |
| 518 | - $actions_div .= '<div id="control_wrapper_' . $id . '"></div>'; | |
| 519 | - } | |
| 472 | + | |
| 520 | 473 | // return placeholder div |
| 521 | - 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>'; | |
| 474 | + return '<div class="' . $container_class . '">' . $actions_div . '<div id="' . $id . '"' . $this->getHtmlAttributes( $attributes ) . '></div>' . $this->addSchema( $chart->ID ) . '</div>'; | |
| 522 | 475 | } |
| 523 | 476 | |
| 524 | 477 | /** |
| 525 | 478 | * Converts the array of attributes to a string of HTML attributes. |
| @@ -534,9 +487,9 @@ | ||
| 534 | 487 | return $string; |
| 535 | 488 | } |
| 536 | 489 | |
| 537 | 490 | foreach ( $attributes as $name => $value ) { |
| 538 | - $string .= sprintf( ' %s="%s"', esc_attr( $name ), esc_attr( $value ) ); | |
| 491 | + $string .= sprintf( '%s="%s"', esc_attr( $name ), esc_attr( $value ) ); | |
| 539 | 492 | } |
| 540 | 493 | return $string; |
| 541 | 494 | } |
| 542 | 495 | |
| @@ -661,11 +614,10 @@ | ||
| 661 | 614 | |
| 662 | 615 | // Get chart by ID. |
| 663 | 616 | $chart = get_post( $chart_id ); |
| 664 | 617 | if ( $chart && Visualizer_Plugin::CPT_VISUALIZER === $chart->post_type ) { |
| 665 | - $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true ); | |
| 666 | - $series = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ); | |
| 667 | - $is_woocommerce_report = get_post_meta( $chart->ID, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true ); | |
| 618 | + $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true ); | |
| 619 | + $series = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ); | |
| 668 | 620 | |
| 669 | 621 | if ( isset( $settings['series'] ) && ! ( count( $settings['series'] ) - count( $series ) > 1 ) ) { |
| 670 | 622 | $diff_total_series = abs( count( $settings['series'] ) - count( $series ) ); |
| 671 | 623 | if ( $diff_total_series ) { |
| @@ -674,14 +626,13 @@ | ||
| 674 | 626 | } |
| 675 | 627 | } |
| 676 | 628 | } |
| 677 | 629 | $chart_data = array( |
| 678 | - 'chart' => $chart, | |
| 679 | - 'type' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ), | |
| 680 | - 'settings' => $settings, | |
| 681 | - 'series' => $series, | |
| 682 | - 'chart_image' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_IMAGE, true ), | |
| 683 | - 'is_woocommerce_report' => $is_woocommerce_report, | |
| 630 | + 'chart' => $chart, | |
| 631 | + 'type' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ), | |
| 632 | + 'settings' => $settings, | |
| 633 | + 'series' => $series, | |
| 634 | + 'chart_image' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_IMAGE, true ), | |
| 684 | 635 | ); |
| 685 | 636 | |
| 686 | 637 | // Put the results in a transient. Expire after 12 hours. |
| 687 | 638 | set_transient( $cache_key, $chart_data, apply_filters( Visualizer_Plugin::FILTER_HANDLE_CACHE_EXPIRATION_TIME, 12 * HOUR_IN_SECONDS ) ); |
| @@ -717,28 +668,13 @@ | ||
| 717 | 668 | } |
| 718 | 669 | |
| 719 | 670 | function visualizerLoadScripts() { |
| 720 | 671 | document.querySelectorAll("script[data-visualizer-script]").forEach(function(elem) { |
| 721 | - jQuery.getScript( elem.getAttribute("data-visualizer-script") ) | |
| 722 | - .done( function( script, textStatus ) { | |
| 672 | + jQuery.getScript( elem.getAttribute("data-visualizer-script"), function() { | |
| 723 | 673 | elem.setAttribute("src", elem.getAttribute("data-visualizer-script")); |
| 724 | 674 | elem.removeAttribute("data-visualizer-script"); |
| 725 | - setTimeout( function() { | |
| 726 | - visualizerRefreshChart(); | |
| 727 | - } ); | |
| 728 | 675 | } ); |
| 729 | 676 | }); |
| 730 | - } | |
| 731 | - | |
| 732 | - function visualizerRefreshChart() { | |
| 733 | - jQuery( '.visualizer-front:not(.visualizer-chart-loaded)' ).resize(); | |
| 734 | - if ( jQuery( 'div.viz-facade-loaded:not(.visualizer-lazy):empty' ).length > 0 ) { | |
| 735 | - visualizerUserInteractionEvents.forEach( function( event ) { | |
| 736 | - window.addEventListener( event, function() { | |
| 737 | - jQuery( '.visualizer-front:not(.visualizer-chart-loaded)' ).resize(); | |
| 738 | - }, { passive: true } ); | |
| 739 | - } ); | |
| 740 | - } | |
| 741 | 677 | } |
| 742 | 678 | </script> |
| 743 | 679 | <?php |
| 744 | 680 | } |