| @@ -66,9 +66,9 @@ | ||
| 66 | 66 | /** |
| 67 | 67 | * Enqueue front end and editor JavaScript and CSS |
| 68 | 68 | */ |
| 69 | 69 | public function enqueue_gutenberg_scripts() { |
| 70 | - global $wp_version, $pagenow; | |
| 70 | + global $wp_version; | |
| 71 | 71 | |
| 72 | 72 | $blockPath = VISUALIZER_ABSURL . 'classes/Visualizer/Gutenberg/build/block.js'; |
| 73 | 73 | $handsontableJS = VISUALIZER_ABSURL . 'classes/Visualizer/Gutenberg/build/handsontable.js'; |
| 74 | 74 | $stylePath = VISUALIZER_ABSURL . 'classes/Visualizer/Gutenberg/build/block.css'; |
| @@ -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,16 +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 | - 'isFullSiteEditor' => 'site-editor.php' === $pagenow, | |
| 116 | 106 | ); |
| 117 | 107 | wp_localize_script( 'visualizer-gutenberg-block', 'visualizerLocalize', $translation_array ); |
| 118 | 108 | |
| 119 | 109 | // Enqueue frontend and editor block styles |
| @@ -351,11 +341,9 @@ | ||
| 351 | 341 | $data['visualizer-default-data'] = get_post_meta( $post_id, Visualizer_Plugin::CF_DEFAULT_DATA, true ); |
| 352 | 342 | |
| 353 | 343 | // faetch and update settings |
| 354 | 344 | $data['visualizer-settings'] = get_post_meta( $post_id, Visualizer_Plugin::CF_SETTINGS, true ); |
| 355 | - if ( empty( $data['visualizer-settings']['pagination'] ) ) { | |
| 356 | - $data['visualizer-settings']['pageSize'] = ''; | |
| 357 | - } | |
| 345 | + | |
| 358 | 346 | // handle series filter hooks |
| 359 | 347 | $data['visualizer-series'] = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $post_id, Visualizer_Plugin::CF_SERIES, true ), $post_id, $data['visualizer-chart-type'] ); |
| 360 | 348 | |
| 361 | 349 | // handle settings filter hooks |
| @@ -363,18 +351,8 @@ | ||
| 363 | 351 | |
| 364 | 352 | // handle data filter hooks |
| 365 | 353 | $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'] ); |
| 366 | 354 | |
| 367 | - // we are going to format only for tabular charts, because we are not sure of the effect on others. | |
| 368 | - // this is to solve the case where boolean data shows up as all-ticks on gutenberg. | |
| 369 | - if ( in_array( $data['visualizer-chart-type'], array( 'tabular' ), true ) ) { | |
| 370 | - $data['visualizer-data'] = $this->format_chart_data( $data['visualizer-data'], $data['visualizer-series'] ); | |
| 371 | - } | |
| 372 | - | |
| 373 | - if ( ! isset( $data['visualizer-settings']['hAxis']['format'] ) ) { | |
| 374 | - $data['visualizer-settings']['hAxis']['format'] = ''; | |
| 375 | - } | |
| 376 | - | |
| 377 | 355 | $data['visualizer-data-exploded'] = ''; |
| 378 | 356 | // handle annotations for google charts |
| 379 | 357 | if ( 'GoogleCharts' === $library ) { |
| 380 | 358 | // this will contain the data of both axis. |
| @@ -391,12 +369,8 @@ | ||
| 391 | 369 | if ( ! empty( $serie['role'] ) ) { |
| 392 | 370 | // this series is some kind of annotation, so let's collect its index. |
| 393 | 371 | // the index will be +1 because the X axis value is index 0, which is being ignored. |
| 394 | 372 | $annotations[ 'role' . ( intval( $index ) + 1 ) ] = $serie['role']; |
| 395 | - | |
| 396 | - if ( isset( $data['visualizer-series'][ intval( $index ) + 1 ] ) ) { | |
| 397 | - $data['visualizer-series'][ intval( $index ) + 1 ]['role'] = $serie['role']; | |
| 398 | - } | |
| 399 | 373 | } |
| 400 | 374 | } |
| 401 | 375 | } |
| 402 | 376 | if ( ! empty( $annotations ) ) { |
| @@ -465,18 +439,11 @@ | ||
| 465 | 439 | |
| 466 | 440 | if ( Visualizer_Module::is_pro() ) { |
| 467 | 441 | $permissions = get_post_meta( $post_id, Visualizer_PRO::CF_PERMISSIONS, true ); |
| 468 | 442 | |
| 469 | - if ( empty( $permissions ) ) { | |
| 470 | - $permissions = array( 'permissions' => array( | |
| 471 | - 'read' => 'all', | |
| 472 | - 'edit' => 'roles', | |
| 473 | - 'edit-specific' => array( 'administrator' ), | |
| 474 | - ), | |
| 475 | - ); | |
| 443 | + if ( ! empty( $permissions ) ) { | |
| 444 | + $data['visualizer-permissions'] = $permissions; | |
| 476 | 445 | } |
| 477 | - | |
| 478 | - $data['visualizer-permissions'] = $permissions; | |
| 479 | 446 | } |
| 480 | 447 | |
| 481 | 448 | return $data; |
| 482 | 449 | } |
| @@ -607,21 +574,16 @@ | ||
| 607 | 574 | delete_post_meta( $data['id'], Visualizer_Plugin::CF_CHART_URL ); |
| 608 | 575 | apply_filters( 'visualizer_pro_remove_schedule', $data['id'] ); |
| 609 | 576 | } |
| 610 | 577 | |
| 611 | - // let's check if this is not an external db chart | |
| 612 | - // as there is no support for that in the block editor interface | |
| 613 | - $external_params = get_post_meta( $data['id'], Visualizer_Plugin::CF_REMOTE_DB_PARAMS, true ); | |
| 614 | - if ( empty( $external_params ) ) { | |
| 615 | - if ( $source_type === 'Visualizer_Source_Query' ) { | |
| 616 | - $db_schedule = intval( $data['visualizer-db-schedule'] ); | |
| 617 | - $db_query = $data['visualizer-db-query']; | |
| 618 | - update_post_meta( $data['id'], Visualizer_Plugin::CF_DB_SCHEDULE, $db_schedule ); | |
| 619 | - update_post_meta( $data['id'], Visualizer_Plugin::CF_DB_QUERY, stripslashes( $db_query ) ); | |
| 620 | - } else { | |
| 621 | - delete_post_meta( $data['id'], Visualizer_Plugin::CF_DB_SCHEDULE ); | |
| 622 | - delete_post_meta( $data['id'], Visualizer_Plugin::CF_DB_QUERY ); | |
| 623 | - } | |
| 578 | + if ( $source_type === 'Visualizer_Source_Query' ) { | |
| 579 | + $db_schedule = intval( $data['visualizer-db-schedule'] ); | |
| 580 | + $db_query = $data['visualizer-db-query']; | |
| 581 | + update_post_meta( $data['id'], Visualizer_Plugin::CF_DB_SCHEDULE, $db_schedule ); | |
| 582 | + update_post_meta( $data['id'], Visualizer_Plugin::CF_DB_QUERY, stripslashes( $db_query ) ); | |
| 583 | + } else { | |
| 584 | + delete_post_meta( $data['id'], Visualizer_Plugin::CF_DB_SCHEDULE ); | |
| 585 | + delete_post_meta( $data['id'], Visualizer_Plugin::CF_DB_QUERY ); | |
| 624 | 586 | } |
| 625 | 587 | |
| 626 | 588 | if ( $source_type === 'Visualizer_Source_Json' ) { |
| 627 | 589 | $json_schedule = intval( $data['visualizer-json-schedule'] ); |
| @@ -666,14 +628,8 @@ | ||
| 666 | 628 | ); |
| 667 | 629 | |
| 668 | 630 | wp_update_post( $chart ); |
| 669 | 631 | |
| 670 | - // Clear existing chart cache. | |
| 671 | - $cache_key = Visualizer_Plugin::CF_CHART_CACHE . '_' . $data['id']; | |
| 672 | - if ( get_transient( $cache_key ) ) { | |
| 673 | - delete_transient( $cache_key ); | |
| 674 | - } | |
| 675 | - | |
| 676 | 632 | $revisions = wp_get_post_revisions( $data['id'], array( 'order' => 'ASC' ) ); |
| 677 | 633 | |
| 678 | 634 | if ( count( $revisions ) > 1 ) { |
| 679 | 635 | $revision_ids = array_keys( $revisions ); |
| @@ -689,10 +645,8 @@ | ||
| 689 | 645 | } |
| 690 | 646 | |
| 691 | 647 | /** |
| 692 | 648 | * Format chart data. |
| 693 | - * | |
| 694 | - * Note: No matter how tempted, don't use the similar method from Visualizer_Source. That works on a different structure. | |
| 695 | 649 | */ |
| 696 | 650 | public function format_chart_data( $data, $series ) { |
| 697 | 651 | foreach ( $series as $i => $row ) { |
| 698 | 652 | // if no value exists for the seires, then add null |
| @@ -703,38 +657,39 @@ | ||
| 703 | 657 | if ( is_null( $series[ $i ] ) ) { |
| 704 | 658 | continue; |
| 705 | 659 | } |
| 706 | 660 | |
| 707 | - switch ( $row['type'] ) { | |
| 708 | - case 'number': | |
| 709 | - foreach ( $data as $o => $col ) { | |
| 710 | - $data[ $o ][ $i ] = ( is_numeric( $col[ $i ] ) ) ? floatval( $col[ $i ] ) : ( is_numeric( str_replace( ',', '', $col[ $i ] ) ) ? floatval( str_replace( ',', '', $col[ $i ] ) ) : null ); | |
| 661 | + if ( $row['type'] === 'number' ) { | |
| 662 | + foreach ( $data as $o => $col ) { | |
| 663 | + $data[ $o ][ $i ] = ( is_numeric( $col[ $i ] ) ) ? floatval( $col[ $i ] ) : ( is_numeric( str_replace( ',', '', $col[ $i ] ) ) ? floatval( str_replace( ',', '', $col[ $i ] ) ) : null ); | |
| 664 | + } | |
| 665 | + } | |
| 666 | + | |
| 667 | + if ( $row['type'] === 'boolean' ) { | |
| 668 | + foreach ( $data as $o => $col ) { | |
| 669 | + $data[ $o ][ $i ] = ! empty( $col[ $i ] ) ? filter_var( $col[ $i ], FILTER_VALIDATE_BOOLEAN ) : null; | |
| 670 | + } | |
| 671 | + } | |
| 672 | + | |
| 673 | + if ( $row['type'] === 'timeofday' ) { | |
| 674 | + foreach ( $data as $o => $col ) { | |
| 675 | + $date = new DateTime( '1984-03-16T' . $col[ $i ] ); | |
| 676 | + if ( $date ) { | |
| 677 | + $data[ $o ][ $i ] = array( | |
| 678 | + intval( $date->format( 'H' ) ), | |
| 679 | + intval( $date->format( 'i' ) ), | |
| 680 | + intval( $date->format( 's' ) ), | |
| 681 | + 0, | |
| 682 | + ); | |
| 711 | 683 | } |
| 712 | - break; | |
| 713 | - case 'boolean': | |
| 714 | - foreach ( $data as $o => $col ) { | |
| 715 | - $data[ $o ][ $i ] = ! empty( $col[ $i ] ) ? filter_var( $col[ $i ], FILTER_VALIDATE_BOOLEAN ) : false; | |
| 716 | - } | |
| 717 | - break; | |
| 718 | - case 'timeofday': | |
| 719 | - foreach ( $data as $o => $col ) { | |
| 720 | - $date = new DateTime( '1984-03-16T' . $col[ $i ] ); | |
| 721 | - if ( $date ) { | |
| 722 | - $data[ $o ][ $i ] = array( | |
| 723 | - intval( $date->format( 'H' ) ), | |
| 724 | - intval( $date->format( 'i' ) ), | |
| 725 | - intval( $date->format( 's' ) ), | |
| 726 | - 0, | |
| 727 | - ); | |
| 728 | - } | |
| 729 | - } | |
| 730 | - break; | |
| 731 | - case 'string': | |
| 732 | - foreach ( $data as $o => $col ) { | |
| 733 | - $data[ $o ][ $i ] = $this->toUTF8( $col[ $i ] ); | |
| 734 | - } | |
| 735 | - break; | |
| 684 | + } | |
| 736 | 685 | } |
| 686 | + | |
| 687 | + if ( $row['type'] === 'string' ) { | |
| 688 | + foreach ( $data as $o => $col ) { | |
| 689 | + $data[ $o ][ $i ] = $this->toUTF8( $col[ $i ] ); | |
| 690 | + } | |
| 691 | + } | |
| 737 | 692 | } |
| 738 | 693 | |
| 739 | 694 | return $data; |
| 740 | 695 | } |
| @@ -756,14 +711,10 @@ | ||
| 756 | 711 | if ( ! current_user_can( 'edit_posts' ) ) { |
| 757 | 712 | return false; |
| 758 | 713 | } |
| 759 | 714 | |
| 760 | - $remote_data = false; | |
| 761 | - if ( isset( $data['url'] ) && function_exists( 'wp_http_validate_url' ) ) { | |
| 762 | - $remote_data = wp_http_validate_url( $data['url'] ); | |
| 763 | - } | |
| 764 | - if ( false !== $remote_data && ! is_wp_error( $remote_data ) ) { | |
| 765 | - $source = new Visualizer_Source_Csv_Remote( $remote_data ); | |
| 715 | + if ( $data['url'] && ! is_wp_error( $data['url'] ) && filter_var( $data['url'], FILTER_VALIDATE_URL ) ) { | |
| 716 | + $source = new Visualizer_Source_Csv_Remote( $data['url'] ); | |
| 766 | 717 | if ( $source->fetch() ) { |
| 767 | 718 | $temp = $source->getData(); |
| 768 | 719 | if ( is_string( $temp ) && is_array( unserialize( $temp ) ) ) { |
| 769 | 720 | $content['series'] = $source->getSeries(); |