| @@ -41,16 +41,8 @@ | ||
| 41 | 41 | */ |
| 42 | 42 | private $_charts = array(); |
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | - * Lazy render script. | |
| 46 | - * | |
| 47 | - * @access private | |
| 48 | - * @var bool | |
| 49 | - */ | |
| 50 | - private $lazy_render_script = true; | |
| 51 | - | |
| 52 | - /** | |
| 53 | 45 | * Constructor. |
| 54 | 46 | * |
| 55 | 47 | * @since 1.0.0 |
| 56 | 48 | * @uses add_filter() To add "do_shortcode" hook for "widget_text" and "term_description" filters. |
| @@ -60,12 +52,10 @@ | ||
| 60 | 52 | */ |
| 61 | 53 | public function __construct( Visualizer_Plugin $plugin ) { |
| 62 | 54 | parent::__construct( $plugin ); |
| 63 | 55 | |
| 64 | - $this->_addAction( 'wp_print_footer_scripts', 'printFooterScripts' ); | |
| 65 | 56 | $this->_addAction( 'wp_enqueue_scripts', 'enqueueScripts' ); |
| 66 | 57 | $this->_addAction( 'load-index.php', 'enqueueScripts' ); |
| 67 | - $this->_addAction( 'load-visualizer_page_visualizer-setup-wizard', 'enqueueScripts' ); | |
| 68 | 58 | $this->_addAction( 'visualizer_enqueue_scripts', 'enqueueScripts' ); |
| 69 | 59 | $this->_addFilter( 'visualizer_get_language', 'getLanguage' ); |
| 70 | 60 | $this->_addShortcode( 'visualizer', 'renderChart' ); |
| 71 | 61 | |
| @@ -86,39 +76,21 @@ | ||
| 86 | 76 | |
| 87 | 77 | /** |
| 88 | 78 | * Adds the async attribute to certain scripts. |
| 89 | 79 | */ |
| 90 | - public function script_loader_tag( $tag, $handle, $src ) { | |
| 80 | + function script_loader_tag( $tag, $handle, $src ) { | |
| 91 | 81 | if ( is_admin() ) { |
| 92 | 82 | return $tag; |
| 93 | 83 | } |
| 94 | - // Async scripts. | |
| 95 | - $async_scripts = array( 'google-jsapi', 'chartjs', 'visualizer-datatables' ); | |
| 96 | - foreach ( $async_scripts as $async ) { | |
| 84 | + | |
| 85 | + $scripts = array( 'google-jsapi', 'visualizer-render-google-lib', 'visualizer-render-google' ); | |
| 86 | + | |
| 87 | + foreach ( $scripts as $async ) { | |
| 97 | 88 | if ( $async === $handle ) { |
| 98 | - $tag = str_replace( ' src', ' async src', $tag ); | |
| 89 | + $tag = str_replace( ' src', ' defer="defer" src', $tag ); | |
| 99 | 90 | break; |
| 100 | 91 | } |
| 101 | 92 | } |
| 102 | - | |
| 103 | - // Async scripts. | |
| 104 | - $scripts = array( 'dom-to-image' ); | |
| 105 | - foreach ( array( 'async', 'defer' ) as $attr ) { | |
| 106 | - if ( wp_scripts()->get_data( $handle, $attr ) ) { | |
| 107 | - break; | |
| 108 | - } | |
| 109 | - if ( in_array( $handle, $async_scripts, true ) || false === strpos( $handle, 'visualizer-' ) ) { | |
| 110 | - break; | |
| 111 | - } | |
| 112 | - if ( ! preg_match( ":\s$attr(=|>|\s):", $tag ) ) { | |
| 113 | - $tag = preg_replace( ':(?=></script>):', " $attr", $tag, 1 ); | |
| 114 | - if ( $this->lazy_render_script ) { | |
| 115 | - $tag = str_replace( ' src', ' data-visualizer-script', $tag ); | |
| 116 | - } | |
| 117 | - } | |
| 118 | - // Only allow async or defer, not both. | |
| 119 | - break; | |
| 120 | - } | |
| 121 | 93 | return $tag; |
| 122 | 94 | } |
| 123 | 95 | |
| 124 | 96 | /** |
| @@ -123,9 +95,9 @@ | ||
| 123 | 95 | |
| 124 | 96 | /** |
| 125 | 97 | * Returns the language/locale. |
| 126 | 98 | */ |
| 127 | - public function getLanguage( $dummy, $only_language ) { | |
| 99 | + function getLanguage( $dummy, $only_language ) { | |
| 128 | 100 | return $this->get_language(); |
| 129 | 101 | } |
| 130 | 102 | |
| 131 | 103 | |
| @@ -131,9 +103,9 @@ | ||
| 131 | 103 | |
| 132 | 104 | /** |
| 133 | 105 | * Registers the endpoints |
| 134 | 106 | */ |
| 135 | - public function endpoint_register() { | |
| 107 | + function endpoint_register() { | |
| 136 | 108 | register_rest_route( |
| 137 | 109 | 'visualizer/v' . VISUALIZER_REST_VERSION, |
| 138 | 110 | '/action/(?P<chart>\d+)/(?P<type>.+)/', |
| 139 | 111 | array( |
| @@ -141,9 +113,9 @@ | ||
| 141 | 113 | 'methods' => array( 'POST', 'GET' ), |
| 142 | 114 | 'args' => array( |
| 143 | 115 | 'chart' => array( |
| 144 | 116 | 'required' => true, |
| 145 | - 'sanitize_callback' => function ( $param ) { | |
| 117 | + 'sanitize_callback' => function( $param ) { | |
| 146 | 118 | return is_numeric( $param ) ? $param : null; |
| 147 | 119 | }, |
| 148 | 120 | ), |
| 149 | 121 | 'type' => array( |
| @@ -152,27 +124,16 @@ | ||
| 152 | 124 | 'enum' => array_merge( array( 'save', 'cancel' ), array_keys( $this->get_actions() ) ), |
| 153 | 125 | ), |
| 154 | 126 | ), |
| 155 | 127 | 'permission_callback' => function ( WP_REST_Request $request ) { |
| 156 | - $chart_id = absint( $request->get_param( 'chart' ) ); | |
| 157 | - if ( ! $chart_id ) { | |
| 158 | - return false; | |
| 128 | + $chart_id = filter_var( sanitize_text_field( $request->get_param( 'chart' ), FILTER_VALIDATE_INT ) ); | |
| 129 | + if ( ! empty( $chart_id ) && in_array( $request->get_param( 'type' ), array( 'save', 'cancel' ), true ) ) { | |
| 130 | + // let save and cancel go without any check as past version of pro | |
| 131 | + // did not send the X-WP-Nonce | |
| 132 | + // we can change this at a later date. | |
| 133 | + return true; | |
| 159 | 134 | } |
| 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 ); | |
| 135 | + return ! empty( $chart_id ) && apply_filters( 'visualizer_pro_show_chart', true, $chart_id ); | |
| 175 | 136 | }, |
| 176 | 137 | 'callback' => array( $this, 'perform_action' ), |
| 177 | 138 | ) |
| 178 | 139 | ); |
| @@ -282,8 +243,9 @@ | ||
| 282 | 243 | * @access public |
| 283 | 244 | */ |
| 284 | 245 | public function enqueueScripts() { |
| 285 | 246 | wp_register_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true ); |
| 247 | + wp_register_style( 'visualizer-front', VISUALIZER_ABSURL . 'css/front.css', array(), Visualizer_Plugin::VERSION ); | |
| 286 | 248 | do_action( 'visualizer_pro_frontend_load_resources' ); |
| 287 | 249 | } |
| 288 | 250 | |
| 289 | 251 | /** |
| @@ -316,25 +278,8 @@ | ||
| 316 | 278 | ), |
| 317 | 279 | $atts |
| 318 | 280 | ); |
| 319 | 281 | |
| 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 | 282 | $chart_data = $this->getChartData( Visualizer_Plugin::CF_CHART_CACHE, $atts['id'] ); |
| 338 | 283 | // if empty chart does not exists, then return empty string. |
| 339 | 284 | if ( ! $chart_data ) { |
| 340 | 285 | return ''; |
| @@ -347,21 +292,14 @@ | ||
| 347 | 292 | if ( ! apply_filters( 'visualizer_pro_show_chart', true, $atts['id'] ) ) { |
| 348 | 293 | return ''; |
| 349 | 294 | } |
| 350 | 295 | |
| 351 | - if ( ! is_admin() && ! empty( $chart_data['is_woocommerce_report'] ) ) { | |
| 352 | - return ''; | |
| 296 | + // in case revisions exist. | |
| 297 | + // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found | |
| 298 | + if ( true === ( $revisions = $this->undoRevisions( $chart->ID, true ) ) ) { | |
| 299 | + $chart = get_post( $chart->ID ); | |
| 353 | 300 | } |
| 354 | 301 | |
| 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 | 302 | $id = 'visualizer-' . $atts['id']; |
| 365 | 303 | $defaultClass = 'visualizer-front'; |
| 366 | 304 | $class = apply_filters( Visualizer_Plugin::FILTER_CHART_WRAPPER_CLASS, $atts['class'], $atts['id'] ); |
| 367 | 305 | |
| @@ -376,15 +314,12 @@ | ||
| 376 | 314 | if ( ctype_digit( $atts['lazy'] ) ) { |
| 377 | 315 | $attributes['data-lazy-limit'] = $atts['lazy']; |
| 378 | 316 | } |
| 379 | 317 | |
| 380 | - $attributes = apply_filters( 'visualizer_container_attributes', $attributes, $chart->ID ); | |
| 381 | - | |
| 382 | 318 | $chart = apply_filters( 'visualizer_schedule_refresh_chart', $chart, $chart->ID, false ); |
| 383 | 319 | |
| 384 | 320 | // Get and update settings. |
| 385 | 321 | $settings = $chart_data['settings']; |
| 386 | - $settings = ! empty( $settings ) ? $settings : array(); | |
| 387 | 322 | if ( empty( $settings['height'] ) ) { |
| 388 | 323 | $settings['height'] = '400'; |
| 389 | 324 | } |
| 390 | 325 | |
| @@ -393,17 +328,8 @@ | ||
| 393 | 328 | |
| 394 | 329 | // handle settings filter hooks |
| 395 | 330 | $settings = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SETTINGS, $settings, $chart->ID, $type ); |
| 396 | 331 | |
| 397 | - $lazy_load = isset( $settings['lazy_load_chart'] ) ? $settings['lazy_load_chart'] : false; | |
| 398 | - $lazy_load = apply_filters( 'visualizer_lazy_load_chart', $lazy_load, $chart->ID ); | |
| 399 | - $container_class = 'visualizer-front-container'; | |
| 400 | - if ( ! $lazy_load ) { | |
| 401 | - $this->lazy_render_script = false; | |
| 402 | - } else { | |
| 403 | - $container_class .= ' visualizer-lazy-render'; | |
| 404 | - } | |
| 405 | - | |
| 406 | 332 | // handle data filter hooks |
| 407 | 333 | $data = self::get_chart_data( $chart, $type ); |
| 408 | 334 | |
| 409 | 335 | $css = ''; |
| @@ -432,23 +358,10 @@ | ||
| 432 | 358 | if ( isset( $settings['chart-img'] ) ) { |
| 433 | 359 | unset( $settings['chart-img'] ); |
| 434 | 360 | } |
| 435 | 361 | |
| 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 | 362 | // add chart to the array |
| 450 | - $chart_entry = array( | |
| 363 | + $this->_charts[ $id ] = array( | |
| 451 | 364 | 'type' => $type, |
| 452 | 365 | 'series' => $series, |
| 453 | 366 | 'settings' => $settings, |
| 454 | 367 | 'data' => $data, |
| @@ -454,15 +367,8 @@ | ||
| 454 | 367 | 'data' => $data, |
| 455 | 368 | 'library' => $library, |
| 456 | 369 | ); |
| 457 | 370 | |
| 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 | 371 | $actions_div = ''; |
| 466 | 372 | $actions_visible = apply_filters( 'visualizer_pro_add_actions', isset( $settings['actions'] ) ? $settings['actions'] : array(), $atts['id'] ); |
| 467 | 373 | if ( ! empty( $actions_visible ) ) { |
| 468 | 374 | $actions = $this->get_actions(); |
| @@ -495,115 +401,45 @@ | ||
| 495 | 401 | $actions_div .= $css; |
| 496 | 402 | |
| 497 | 403 | $_charts = array(); |
| 498 | 404 | $_charts_type = ''; |
| 499 | - $count = 0; | |
| 500 | - static $visualizer_localized = false; | |
| 501 | - static $visualizer_charts = array(); | |
| 502 | - static $d3_localized = false; | |
| 503 | - $facade_handle = 'visualizer-render-facade'; | |
| 504 | 405 | foreach ( $this->_charts as $id => $array ) { |
| 505 | 406 | $_charts = $this->_charts; |
| 506 | 407 | $library = $array['library']; |
| 507 | 408 | $_charts_type = $library; |
| 508 | - $facade_deps = apply_filters( 'visualizer_assets_render', array( 'jquery', 'visualizer-customization' ), true ); | |
| 509 | - if ( ! wp_script_is( $facade_handle, 'registered' ) ) { | |
| 409 | + if ( ! wp_script_is( "visualizer-render-$library", 'registered' ) ) { | |
| 510 | 410 | wp_register_script( |
| 511 | - $facade_handle, | |
| 411 | + "visualizer-render-$library", | |
| 512 | 412 | VISUALIZER_ABSURL . 'js/render-facade.js', |
| 513 | - $facade_deps, | |
| 413 | + apply_filters( 'visualizer_assets_render', array( 'jquery', 'visualizer-customization' ), true ), | |
| 514 | 414 | Visualizer_Plugin::VERSION, |
| 515 | 415 | true |
| 516 | 416 | ); |
| 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 | - } | |
| 417 | + wp_enqueue_script( "visualizer-render-$library" ); | |
| 529 | 418 | } |
| 530 | - | |
| 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 | - } | |
| 560 | - } | |
| 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; | |
| 596 | 419 | } |
| 597 | - $prefix = 'C' . 'h' . 'a' . 'rt'; | |
| 598 | - if ( $type === 'tabular' ) { | |
| 599 | - $prefix = 'T' . 'a' . 'bl' . 'e'; | |
| 420 | + if ( wp_script_is( "visualizer-render-$_charts_type" ) ) { | |
| 421 | + wp_localize_script( | |
| 422 | + "visualizer-render-$_charts_type", | |
| 423 | + 'visualizer', | |
| 424 | + array( | |
| 425 | + 'charts' => $_charts, | |
| 426 | + 'language' => $this->get_language(), | |
| 427 | + 'map_api_key' => get_option( 'visualizer-map-api-key' ), | |
| 428 | + 'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '', | |
| 429 | + 'wp_nonce' => wp_create_nonce( 'wp_rest' ), | |
| 430 | + 'i10n' => array( | |
| 431 | + 'copied' => __( 'The data has been copied to your clipboard. Hit Ctrl-V/Cmd-V in your spreadsheet editor to paste the data.', 'visualizer' ), | |
| 432 | + ), | |
| 433 | + 'page_type' => 'frontend', | |
| 434 | + 'is_front' => true, | |
| 435 | + ) | |
| 436 | + ); | |
| 600 | 437 | } |
| 601 | - if ( Visualizer_Module::is_pro() && $enable_controls ) { | |
| 602 | - $actions_div .= '<div id="control_wrapper_' . $id . '"></div>'; | |
| 603 | - } | |
| 438 | + wp_enqueue_style( 'visualizer-front' ); | |
| 439 | + | |
| 604 | 440 | // 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>'; | |
| 441 | + return $actions_div . '<div id="' . $id . '"' . $this->getHtmlAttributes( $attributes ) . '></div>' . $this->addSchema( $chart->ID ); | |
| 606 | 442 | } |
| 607 | 443 | |
| 608 | 444 | /** |
| 609 | 445 | * Converts the array of attributes to a string of HTML attributes. |
| @@ -618,9 +454,9 @@ | ||
| 618 | 454 | return $string; |
| 619 | 455 | } |
| 620 | 456 | |
| 621 | 457 | foreach ( $attributes as $name => $value ) { |
| 622 | - $string .= sprintf( ' %s="%s"', esc_attr( $name ), esc_attr( $value ) ); | |
| 458 | + $string .= sprintf( '%s="%s"', esc_attr( $name ), esc_attr( $value ) ); | |
| 623 | 459 | } |
| 624 | 460 | return $string; |
| 625 | 461 | } |
| 626 | 462 | |
| @@ -745,11 +581,10 @@ | ||
| 745 | 581 | |
| 746 | 582 | // Get chart by ID. |
| 747 | 583 | $chart = get_post( $chart_id ); |
| 748 | 584 | 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 ); | |
| 585 | + $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true ); | |
| 586 | + $series = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ); | |
| 752 | 587 | |
| 753 | 588 | if ( isset( $settings['series'] ) && ! ( count( $settings['series'] ) - count( $series ) > 1 ) ) { |
| 754 | 589 | $diff_total_series = abs( count( $settings['series'] ) - count( $series ) ); |
| 755 | 590 | if ( $diff_total_series ) { |
| @@ -758,14 +593,13 @@ | ||
| 758 | 593 | } |
| 759 | 594 | } |
| 760 | 595 | } |
| 761 | 596 | $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, | |
| 597 | + 'chart' => $chart, | |
| 598 | + 'type' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ), | |
| 599 | + 'settings' => $settings, | |
| 600 | + 'series' => $series, | |
| 601 | + 'chart_image' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_IMAGE, true ), | |
| 768 | 602 | ); |
| 769 | 603 | |
| 770 | 604 | // Put the results in a transient. Expire after 12 hours. |
| 771 | 605 | set_transient( $cache_key, $chart_data, apply_filters( Visualizer_Plugin::FILTER_HANDLE_CACHE_EXPIRATION_TIME, 12 * HOUR_IN_SECONDS ) ); |
| @@ -772,60 +606,6 @@ | ||
| 772 | 606 | return $chart_data; |
| 773 | 607 | } |
| 774 | 608 | |
| 775 | 609 | return false; |
| 776 | - } | |
| 777 | - | |
| 778 | - /** | |
| 779 | - * Print footer script. | |
| 780 | - */ | |
| 781 | - public function printFooterScripts() { | |
| 782 | - if ( $this->lazy_render_script ) { | |
| 783 | - ?> | |
| 784 | - <script type="text/javascript"> | |
| 785 | - var visualizerUserInteractionEvents = [ | |
| 786 | - "scroll", | |
| 787 | - "mouseover", | |
| 788 | - "keydown", | |
| 789 | - "touchmove", | |
| 790 | - "touchstart" | |
| 791 | - ]; | |
| 792 | - | |
| 793 | - visualizerUserInteractionEvents.forEach(function(event) { | |
| 794 | - window.addEventListener(event, visualizerTriggerScriptLoader, { passive: true }); | |
| 795 | - }); | |
| 796 | - | |
| 797 | - function visualizerTriggerScriptLoader() { | |
| 798 | - visualizerLoadScripts(); | |
| 799 | - visualizerUserInteractionEvents.forEach(function(event) { | |
| 800 | - window.removeEventListener(event, visualizerTriggerScriptLoader, { passive: true }); | |
| 801 | - }); | |
| 802 | - } | |
| 803 | - | |
| 804 | - function visualizerLoadScripts() { | |
| 805 | - document.querySelectorAll("script[data-visualizer-script]").forEach(function(elem) { | |
| 806 | - jQuery.getScript( elem.getAttribute("data-visualizer-script") ) | |
| 807 | - .done( function( script, textStatus ) { | |
| 808 | - elem.setAttribute("src", elem.getAttribute("data-visualizer-script")); | |
| 809 | - elem.removeAttribute("data-visualizer-script"); | |
| 810 | - setTimeout( function() { | |
| 811 | - visualizerRefreshChart(); | |
| 812 | - } ); | |
| 813 | - } ); | |
| 814 | - }); | |
| 815 | - } | |
| 816 | - | |
| 817 | - function visualizerRefreshChart() { | |
| 818 | - jQuery( '.visualizer-front:not(.visualizer-chart-loaded)' ).resize(); | |
| 819 | - if ( jQuery( 'div.viz-facade-loaded:not(.visualizer-lazy):empty' ).length > 0 ) { | |
| 820 | - visualizerUserInteractionEvents.forEach( function( event ) { | |
| 821 | - window.addEventListener( event, function() { | |
| 822 | - jQuery( '.visualizer-front:not(.visualizer-chart-loaded)' ).resize(); | |
| 823 | - }, { passive: true } ); | |
| 824 | - } ); | |
| 825 | - } | |
| 826 | - } | |
| 827 | - </script> | |
| 828 | - <?php | |
| 829 | - } | |
| 830 | 610 | } |
| 831 | 611 | } |