PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.0
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.0
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/Chart.php +57 -275 3.10.33.4.0 View file →
@@ -134,30 +134,12 @@
134 134 ),
135 135 )
136 136 );
137 137
138 - if ( Visualizer_Module::is_pro() ) {
139 - $is_woocommerce_report = filter_input(
140 - INPUT_POST,
141 - 'is_woocommerce_report',
142 - FILTER_VALIDATE_BOOLEAN
143 - );
144 -
145 - if ( $is_woocommerce_report ) {
146 - update_post_meta( $chart_id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true );
147 - } else {
148 - delete_post_meta( $chart_id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE );
149 - }
150 - }
151 -
152 138 delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE );
153 139
154 140 if ( -1 < $time ) {
155 141 add_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, $time );
156 - // Update schedules.
157 - $schedules = get_option( Visualizer_Plugin::CF_JSON_SCHEDULE, array() );
158 - $schedules[ $chart_id ] = time() + $time * HOUR_IN_SECONDS;
159 - update_option( Visualizer_Plugin::CF_JSON_SCHEDULE, $schedules );
160 142 }
161 143 wp_send_json_success();
162 144 }
163 145
@@ -232,12 +214,11 @@
232 214
233 215 $chart = get_post( $chart_id );
234 216
235 217 $source = new Visualizer_Source_Json( $params );
236 - update_post_meta( $chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true );
237 218 $source->fetchFromEditableTable();
238 219
239 - $content = $source->getData( get_post_meta( $chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) );
220 + $content = $source->getData();
240 221 $chart->post_content = $content;
241 222 wp_update_post( $chart->to_array() );
242 223 update_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
243 224 update_post_meta( $chart->ID, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
@@ -259,16 +240,8 @@
259 240 if ( ! empty( $params['paging'] ) ) {
260 241 add_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_PAGING, $params['paging'] );
261 242 }
262 243
263 - if ( Visualizer_Module::is_pro() ) {
264 - if ( ! empty( $params['vz_woo_source'] ) ) {
265 - update_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_WOOCOMMERCE_SOURCE, $params['vz_woo_source'] );
266 - } else {
267 - delete_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_WOOCOMMERCE_SOURCE );
268 - }
269 - }
270 -
271 244 $time = filter_input(
272 245 INPUT_POST,
273 246 'time',
274 247 FILTER_VALIDATE_INT,
@@ -292,9 +265,9 @@
292 265 delete_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_SCHEDULE );
293 266
294 267 $render = new Visualizer_Render_Page_Update();
295 268 $render->id = $chart->ID;
296 - $render->data = json_encode( $source->getRawData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) );
269 + $render->data = json_encode( $source->getRawData() );
297 270 $render->series = json_encode( $source->getSeries() );
298 271 $render->render();
299 272
300 273 defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
@@ -384,9 +357,9 @@
384 357 $chart = $this->_chart;
385 358 }
386 359 $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
387 360 $series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type );
388 - $data = self::get_chart_data( $chart, $type );
361 + $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( $chart->post_content ), $chart->ID, $type );
389 362 $library = $this->load_chart_type( $chart->ID );
390 363
391 364 $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
392 365 $settings = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SETTINGS, $settings, $chart->ID, $type );
@@ -460,22 +433,9 @@
460 433 $success = $chart && $chart->post_type === Visualizer_Plugin::CPT_VISUALIZER;
461 434 }
462 435 }
463 436 if ( $success ) {
464 - global $sitepress;
465 - if ( Visualizer_Module::is_pro() && ( function_exists( 'icl_get_languages' ) && $sitepress instanceof \SitePress ) ) {
466 - $trid = $sitepress->get_element_trid( $chart_id, 'post_' . Visualizer_Plugin::CPT_VISUALIZER );
467 - $translations = $sitepress->get_element_translations( $trid );
468 - if ( ! empty( $translations ) ) {
469 - foreach ( $translations as $translated_post ) {
470 - wp_delete_post( $translated_post->element_id, true );
471 - }
472 - } else {
473 - wp_delete_post( $chart_id, true );
474 - }
475 - } else {
476 - wp_delete_post( $chart_id, true );
477 - }
437 + wp_delete_post( $chart_id, true );
478 438 }
479 439 if ( $is_post ) {
480 440 self::_sendResponse(
481 441 array(
@@ -524,104 +484,43 @@
524 484 * @access public
525 485 */
526 486 public function renderChartPages() {
527 487 defined( 'IFRAME_REQUEST' ) || define( 'IFRAME_REQUEST', 1 );
528 - if ( ! defined( 'ET_BUILDER_PRODUCT_VERSION' ) && function_exists( 'et_get_theme_version' ) ) {
529 - define( 'ET_BUILDER_PRODUCT_VERSION', et_get_theme_version() );
530 - }
531 - // Set current screen for the render chart.
532 - set_current_screen( 'visualizer_render_chart' );
533 488 // check chart, if chart not exists, will create new one and redirects to the same page with proper chart id
534 489 $chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : '';
535 - if ( ! empty( $_POST ) ) {
536 - $_POST = map_deep( $_POST, 'wp_strip_all_tags' );
537 - }
538 490 if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type !== Visualizer_Plugin::CPT_VISUALIZER ) {
539 - if ( empty( $_GET['lang'] ) || empty( $_GET['parent_chart_id'] ) ) {
540 - $this->deleteOldCharts();
541 - $default_type = isset( $_GET['type'] ) && ! empty( $_GET['type'] ) ? $_GET['type'] : 'line';
542 - $chart_status = Visualizer_Module_Admin::checkChartStatus( $default_type );
543 - if ( ! $chart_status ) {
544 - $default_type = 'line';
545 - }
546 - $source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $default_type . '.csv' );
547 - $source->fetch();
548 - $chart_id = wp_insert_post(
491 + $this->deleteOldCharts();
492 + $default_type = isset( $_GET['type'] ) && ! empty( $_GET['type'] ) ? $_GET['type'] : 'line';
493 + $source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $default_type . '.csv' );
494 + $source->fetch();
495 + $chart_id = wp_insert_post(
496 + array(
497 + 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
498 + 'post_title' => 'Visualization',
499 + 'post_author' => get_current_user_id(),
500 + 'post_status' => 'auto-draft',
501 + 'post_content' => $source->getData(),
502 + )
503 + );
504 + if ( $chart_id && ! is_wp_error( $chart_id ) ) {
505 + add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, $default_type );
506 + add_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 1 );
507 + add_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
508 + add_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
509 + add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, '' );
510 + add_post_meta(
511 + $chart_id,
512 + Visualizer_Plugin::CF_SETTINGS,
549 513 array(
550 - 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
551 - 'post_title' => 'Visualization',
552 - 'post_author' => get_current_user_id(),
553 - 'post_status' => 'auto-draft',
554 - 'post_content' => $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ),
514 + 'focusTarget' => 'datum',
555 515 )
556 516 );
557 - if ( $chart_id && ! is_wp_error( $chart_id ) ) {
558 - add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, $default_type );
559 - add_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 1 );
560 - add_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
561 - add_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
562 - add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, '' );
563 - add_post_meta(
564 - $chart_id,
565 - Visualizer_Plugin::CF_SETTINGS,
566 - array(
567 - 'focusTarget' => 'datum',
568 - )
569 - );
570 -
571 - do_action( 'visualizer_pro_new_chart_defaults', $chart_id );
572 - }
573 - } else {
574 - if ( current_user_can( 'edit_posts' ) ) {
575 - $parent_chart_id = isset( $_GET['parent_chart_id'] ) ? filter_var( $_GET['parent_chart_id'], FILTER_VALIDATE_INT ) : '';
576 - $success = false;
577 - if ( $parent_chart_id ) {
578 - $parent_chart = get_post( $parent_chart_id );
579 - $success = $parent_chart && $parent_chart->post_type === Visualizer_Plugin::CPT_VISUALIZER;
580 - }
581 - if ( $success ) {
582 - $new_chart_id = wp_insert_post(
583 - array(
584 - 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
585 - 'post_title' => 'Visualization',
586 - 'post_author' => get_current_user_id(),
587 - 'post_status' => $parent_chart->post_status,
588 - 'post_content' => $parent_chart->post_content,
589 - )
590 - );
591 -
592 - if ( is_wp_error( $new_chart_id ) ) {
593 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Error while cloning chart %d = %s', $parent_chart_id, print_r( $new_chart_id, true ) ), 'error', __FILE__, __LINE__ );
594 - } else {
595 - $post_meta = get_post_meta( $parent_chart_id );
596 - $chart_id = $new_chart_id;
597 - foreach ( $post_meta as $key => $value ) {
598 - if ( strpos( $key, 'visualizer-' ) !== false ) {
599 - add_post_meta( $new_chart_id, $key, maybe_unserialize( $value[0] ) );
600 - }
601 - }
602 - }
603 - }
604 - }
605 517 do_action( 'visualizer_pro_new_chart_defaults', $chart_id );
606 518 }
607 - wp_redirect( esc_url_raw( add_query_arg( 'chart', (int) $chart_id ) ) );
608 -
609 - if ( defined( 'WP_TESTS_DOMAIN' ) ) {
610 - wp_die();
611 - }
612 - exit();
519 + wp_redirect( add_query_arg( 'chart', (int) $chart_id ) );
520 + defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
613 521 }
614 522
615 - $_POST['save_chart_image'] = isset( $_POST['save_chart_image'] ) && 'yes' === $_POST['save_chart_image'] ? true : false;
616 - $_POST['lazy_load_chart'] = isset( $_POST['lazy_load_chart'] ) && 'yes' === $_POST['lazy_load_chart'] ? true : false;
617 -
618 - if ( isset( $_POST['chart-img'] ) && ! empty( $_POST['chart-img'] ) ) {
619 - $attachment_id = $this->save_chart_image( $_POST['chart-img'], $chart_id, $_POST['save_chart_image'] );
620 - if ( $attachment_id ) {
621 - update_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_IMAGE, $attachment_id );
622 - }
623 - }
624 523 $lib = $this->load_chart_type( $chart_id );
625 524
626 525 // the alpha color picker (RGBA) is not supported by google.
627 526 $color_picker_dep = 'wp-color-picker';
@@ -634,9 +533,9 @@
634 533 wp_register_script( 'visualizer-chosen', VISUALIZER_ABSURL . 'js/lib/chosen.jquery.min.js', array( 'jquery' ), Visualizer_Plugin::VERSION );
635 534 wp_register_style( 'visualizer-chosen', VISUALIZER_ABSURL . 'css/lib/chosen.min.css', array(), Visualizer_Plugin::VERSION );
636 535
637 536 wp_register_style( 'visualizer-frame', VISUALIZER_ABSURL . 'css/frame.css', array( 'visualizer-chosen' ), Visualizer_Plugin::VERSION );
638 - wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'visualizer-chosen', 'jquery-ui-accordion', 'jquery-ui-tabs' ), Visualizer_Plugin::VERSION, true );
537 + wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'visualizer-chosen', 'jquery-ui-accordion' ), Visualizer_Plugin::VERSION, true );
639 538 wp_register_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true );
640 539 wp_register_script(
641 540 'visualizer-render',
642 541 VISUALIZER_ABSURL . 'js/render-facade.js',
@@ -675,9 +574,8 @@
675 574 if ( isset( $_POST['cancel'] ) && 1 === intval( $_POST['cancel'] ) ) {
676 575 // if the cancel button is clicked.
677 576 $this->undoRevisions( $chart_id, true );
678 577 } elseif ( isset( $_POST['save'] ) && 1 === intval( $_POST['save'] ) ) {
679 - $this->handlePermissions();
680 578 // if the save button is clicked.
681 579 $this->undoRevisions( $chart_id, false );
682 580 } else {
683 581 // if the edit button is clicked.
@@ -683,16 +581,8 @@
683 581 // if the edit button is clicked.
684 582 $this->_chart = $this->handleExistingRevisions( $chart_id, $this->_chart );
685 583 }
686 584
687 - // Clear existing chart cache.
688 - if ( isset( $_POST['save'] ) && 1 === intval( $_POST['save'] ) ) {
689 - $cache_key = Visualizer_Plugin::CF_CHART_CACHE . '_' . $chart_id;
690 - if ( get_transient( $cache_key ) ) {
691 - delete_transient( $cache_key );
692 - }
693 - }
694 -
695 585 switch ( $tab ) {
696 586 case 'settings':
697 587 $this->_handleDataAndSettingsPage();
698 588 break;
@@ -700,9 +590,9 @@
700 590 case 'visualizer': // fall through.
701 591 $this->_handleTypesPage();
702 592 break;
703 593 default:
704 - // this should never happen.
594 + do_action( 'visualizer_pro_handle_tab', $tab, $this->_chart );
705 595 break;
706 596 }
707 597 defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
708 598 }
@@ -717,9 +607,9 @@
717 607
718 608 // data tables assets.
719 609 wp_register_script( 'visualizer-datatables', VISUALIZER_ABSURL . 'js/lib/datatables.min.js', array( 'jquery-ui-core' ), Visualizer_Plugin::VERSION );
720 610 wp_register_style( 'visualizer-datatables', VISUALIZER_ABSURL . 'css/lib/datatables.min.css', array(), Visualizer_Plugin::VERSION );
721 - wp_register_style( 'visualizer-jquery-ui', sprintf( '//code.jquery.com/ui/%s/themes/smoothness/jquery-ui.css', $wp_scripts->registered['jquery-ui-core']->ver ), array( 'visualizer-datatables' ), Visualizer_Plugin::VERSION );
611 + wp_register_style( 'visualizer-jquery-ui', sprintf( '//ajax.googleapis.com/ajax/libs/jqueryui/%s/themes/smoothness/jquery-ui.css', $wp_scripts->registered['jquery-ui-core']->ver ), array( 'visualizer-datatables' ), Visualizer_Plugin::VERSION );
722 612 wp_enqueue_script( 'visualizer-datatables' );
723 613 wp_enqueue_style( 'visualizer-jquery-ui' );
724 614
725 615 if ( ! Visualizer_Module::is_pro() ) {
@@ -762,25 +652,8 @@
762 652 return $table_col_mapping;
763 653 }
764 654
765 655 /**
766 - * Handle permissions from the new conslidated settings sidebar.
767 - */
768 - private function handlePermissions() {
769 - if ( ! Visualizer_Module::is_pro() ) {
770 - return;
771 - }
772 -
773 - // we will not support old free and new pro.
774 - // handling new free and old pro.
775 - if ( has_action( 'visualizer_pro_handle_tab' ) ) {
776 - do_action( 'visualizer_pro_handle_tab', 'permissions', $this->_chart );
777 - } else {
778 - do_action( 'visualizer_handle_permissions', $this->_chart );
779 - }
780 - }
781 -
782 - /**
783 656 * Handle data and settings page
784 657 */
785 658 private function _handleDataAndSettingsPage() {
786 659 if ( isset( $_POST['map_api_key'] ) ) {
@@ -785,9 +658,8 @@
785 658 private function _handleDataAndSettingsPage() {
786 659 if ( isset( $_POST['map_api_key'] ) ) {
787 660 update_option( 'visualizer-map-api-key', $_POST['map_api_key'] );
788 661 }
789 -
790 662 if ( $_SERVER['REQUEST_METHOD'] === 'POST' && isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'] ) ) {
791 663 if ( $this->_chart->post_status === 'auto-draft' ) {
792 664 $this->_chart->post_status = 'publish';
793 665
@@ -792,10 +664,9 @@
792 664 $this->_chart->post_status = 'publish';
793 665
794 666 // ensure that a revision is not created. If a revision is created it will have the proper data and the parent of the revision will have default data.
795 667 // we do not want any difference in data so disable revisions temporarily.
796 - $this->disableRevisionsTemporarily();
797 -
668 + add_filter( 'wp_revisions_to_keep', '__return_false' );
798 669 wp_update_post( $this->_chart->to_array() );
799 670 }
800 671 // save meta data only when it is NOT being canceled.
801 672 if ( ! ( isset( $_POST['cancel'] ) && 1 === intval( $_POST['cancel'] ) ) ) {
@@ -814,19 +685,14 @@
814 685 if ( empty( $title ) ) {
815 686 $title = $this->_chart->ID;
816 687 }
817 688 $settings['internal_title'] = $title;
818 - $settings_label = isset( $settings['pieResidueSliceLabel'] ) ? $settings['pieResidueSliceLabel'] : '';
819 - if ( empty( $settings_label ) ) {
820 - $settings['pieResidueSliceLabel'] = esc_html__( 'Other', 'visualizer' );
821 - } else {
822 - $settings['pieResidueSliceLabel'] = $settings_label;
823 - }
824 689 update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, $settings );
825 690 }
826 691 $render = new Visualizer_Render_Page_Send();
827 692 $render->text = sprintf( '[visualizer id="%d"]', $this->_chart->ID );
828 693 wp_iframe( array( $render, 'render' ) );
694 +
829 695 return;
830 696 }
831 697 $data = $this->_getChartArray();
832 698 $sidebar = '';
@@ -876,9 +742,8 @@
876 742 'invalid_source' => esc_html__( 'You have entered an invalid URL. Please provide a valid URL.', 'visualizer' ),
877 743 'loading' => esc_html__( 'Loading...', 'visualizer' ),
878 744 'json_error' => esc_html__( 'An error occured in fetching data.', 'visualizer' ),
879 745 'select_columns' => esc_html__( 'Please select a few columns to include in the chart.', 'visualizer' ),
880 - 'save_settings' => __( 'You have modified the chart\'s settings. To modify the source/data again, you must save this chart and reopen it for editing. If you continue without saving the chart, you may lose your changes.', 'visualizer' ),
881 746 ),
882 747 'charts' => array(
883 748 'canvas' => $data,
884 749 'id' => $this->_chart->ID,
@@ -909,9 +774,8 @@
909 774 'page_type' => 'chart',
910 775 'json_tag_separator' => Visualizer_Source_Json::TAG_SEPARATOR,
911 776 'json_tag_separator_view' => Visualizer_Source_Json::TAG_SEPARATOR_VIEW,
912 777 'is_front' => false,
913 - 'rest_base' => get_rest_url( null, 'wc/v3/reports/' ),
914 778 )
915 779 );
916 780
917 781 $render = new Visualizer_Render_Page_Data();
@@ -952,9 +816,9 @@
952 816 // process post request
953 817 if ( $_SERVER['REQUEST_METHOD'] === 'POST' && wp_verify_nonce( filter_input( INPUT_POST, 'nonce' ) ) ) {
954 818 $type = filter_input( INPUT_POST, 'type' );
955 819 $library = filter_input( INPUT_POST, 'chart-library' );
956 - if ( Visualizer_Module_Admin::checkChartStatus( $type ) ) {
820 + if ( in_array( $type, Visualizer_Plugin::getChartTypes(), true ) ) {
957 821 if ( empty( $library ) ) {
958 822 // library cannot be empty.
959 823 do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'Chart library empty while creating the chart! Aborting...', 'error', __FILE__, __LINE__ );
960 824 return;
@@ -966,9 +830,9 @@
966 830 // if the chart has default data, update it with appropriate default data for new type
967 831 if ( filter_var( get_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, true ), FILTER_VALIDATE_BOOLEAN ) ) {
968 832 $source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $type . '.csv' );
969 833 $source->fetch();
970 - $this->_chart->post_content = $source->getData( get_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) );
834 + $this->_chart->post_content = $source->getData();
971 835 wp_update_post( $this->_chart->to_array() );
972 836 update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
973 837 }
974 838
@@ -975,9 +839,9 @@
975 839 Visualizer_Module_Utility::set_defaults( $this->_chart );
976 840
977 841 // redirect to next tab
978 842 // changed by Ash/Upwork
979 - wp_redirect( esc_url_raw( add_query_arg( 'tab', 'settings' ) ) );
843 + wp_redirect( add_query_arg( 'tab', 'settings' ) );
980 844
981 845 return;
982 846 }
983 847 }
@@ -1020,23 +884,14 @@
1020 884 foreach ( $values as $row ) {
1021 885 if ( empty( $row ) ) {
1022 886 continue;
1023 887 }
1024 - $row = explode( ',', $row );
1025 - $row = array_map(
1026 - function( $r ) {
1027 - return '' === $r ? ' ' : $r;
1028 - },
1029 - $row
1030 - );
1031 - $row = implode( ',', $row );
1032 888 // don't use fpucsv here because we need to just dump the data
1033 889 // minus the empty rows
890 + // and if any row contains ' or ", fputcsv will mess it up
1034 891 // because fputcsv needs to tokenize
1035 - // we can standardize the CSV enclosure here and replace all ' with "
1036 - // we can assume that if there are an even number of ' they should be changed to "
1037 - // but that will screw up words like fo'c'sle
1038 - // so here let's just assume ' will NOT be used for enclosures
892 + // and let's standardize the CSV enclosure
893 + $row = str_replace( "'", VISUALIZER_CSV_ENCLOSURE, $row );
1039 894 fwrite( $handle, $row );
1040 895 fwrite( $handle, PHP_EOL );
1041 896 }
1042 897 }
@@ -1042,11 +897,8 @@
1042 897 }
1043 898 $source = new Visualizer_Source_Csv( $tmpfile );
1044 899 fclose( $handle );
1045 900 break;
1046 - case 'table':
1047 - // Import from Chart
1048 - // fall-through.
1049 901 case 'excel':
1050 902 // data coming in from the excel editor.
1051 903 $source = apply_filters( 'visualizer_pro_handle_chart_data', $data, '' );
1052 904 break;
@@ -1184,22 +1036,14 @@
1184 1036
1185 1037 // delete editor related data.
1186 1038 delete_post_meta( $chart_id, Visualizer_Plugin::CF_EDITOR );
1187 1039
1188 - // delete this so that a JSON import can be later edited manually without a problem.
1189 - delete_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE );
1190 -
1191 1040 $source = null;
1192 1041 $render = new Visualizer_Render_Page_Update();
1193 -
1194 - $remote_data = false;
1195 - if ( isset( $_POST['remote_data'] ) && function_exists( 'wp_http_validate_url' ) ) {
1196 - $remote_data = wp_http_validate_url( $_POST['remote_data'] );
1197 - }
1198 - if ( false !== $remote_data ) {
1199 - $source = new Visualizer_Source_Csv_Remote( $remote_data );
1042 + if ( isset( $_POST['remote_data'] ) && filter_var( $_POST['remote_data'], FILTER_VALIDATE_URL ) ) {
1043 + $source = new Visualizer_Source_Csv_Remote( $_POST['remote_data'] );
1200 1044 if ( isset( $_POST['vz-import-time'] ) ) {
1201 - apply_filters( 'visualizer_pro_chart_schedule', $chart_id, $remote_data, $_POST['vz-import-time'] );
1045 + apply_filters( 'visualizer_pro_chart_schedule', $chart_id, $_POST['remote_data'], $_POST['vz-import-time'] );
1202 1046 }
1203 1047 // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1204 1048 } elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) {
1205 1049 $source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] );
@@ -1218,9 +1062,9 @@
1218 1062 do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Uploaded data for chart %d with source %s', $chart_id, print_r( $source, true ) ), 'debug', __FILE__, __LINE__ );
1219 1063
1220 1064 if ( $source ) {
1221 1065 if ( $source->fetch() ) {
1222 - $content = $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) );
1066 + $content = $source->getData();
1223 1067 $populate = true;
1224 1068 if ( is_string( $content ) && is_array( unserialize( $content ) ) ) {
1225 1069 $json = unserialize( $content );
1226 1070 // if source exists, so should data. if source exists but data is blank, do not populate the chart.
@@ -1234,9 +1078,8 @@
1234 1078 if ( $populate ) {
1235 1079 $chart->post_content = $content;
1236 1080 }
1237 1081 wp_update_post( $chart->to_array() );
1238 -
1239 1082 update_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
1240 1083 update_post_meta( $chart->ID, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
1241 1084 update_post_meta( $chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, 0 );
1242 1085
@@ -1244,20 +1087,11 @@
1244 1087
1245 1088 Visualizer_Module_Utility::set_defaults( $chart, null );
1246 1089
1247 1090 $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
1248 - if ( isset( $settings['series'] ) && ! ( count( $settings['series'] ) - count( $source->getSeries() ) > 1 ) ) {
1249 - $diff_total_series = abs( count( $settings['series'] ) - count( $source->getSeries() ) );
1250 - if ( $diff_total_series ) {
1251 - foreach ( range( 1, $diff_total_series ) as $k => $diff_series ) {
1252 - $settings['series'][] = end( $settings['series'] );
1253 - }
1254 - update_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, $settings );
1255 - }
1256 - }
1257 1091
1258 1092 $render->id = $chart->ID;
1259 - $render->data = json_encode( $source->getRawData( get_post_meta( $chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) );
1093 + $render->data = json_encode( $source->getRawData() );
1260 1094 $render->series = json_encode( $source->getSeries() );
1261 1095 $render->settings = json_encode( $settings );
1262 1096 } else {
1263 1097 $error = $source->get_error();
@@ -1315,19 +1149,15 @@
1315 1149 if ( strpos( $key, 'visualizer-' ) !== false ) {
1316 1150 add_post_meta( $new_chart_id, $key, maybe_unserialize( $value[0] ) );
1317 1151 }
1318 1152 }
1319 - $redirect = esc_url(
1320 - add_query_arg(
1321 - array(
1322 - 'page' => 'visualizer',
1323 - 'type' => filter_input( INPUT_GET, 'type' ),
1324 - 'vaction' => false,
1325 - ),
1326 - admin_url( 'admin.php' )
1153 + $redirect = add_query_arg(
1154 + array(
1155 + 'page' => 'visualizer',
1156 + 'type' => filter_input( INPUT_GET, 'type' ),
1157 + 'vaction' => false,
1327 1158 ),
1328 - null,
1329 - 'db'
1159 + admin_url( 'admin.php' )
1330 1160 );
1331 1161 }
1332 1162 }
1333 1163
@@ -1333,8 +1163,9 @@
1333 1163
1334 1164 if ( defined( 'WP_TESTS_DOMAIN' ) ) {
1335 1165 wp_die();
1336 1166 }
1167 +
1337 1168 wp_redirect( $redirect );
1338 1169 exit;
1339 1170 }
1340 1171
@@ -1454,9 +1285,9 @@
1454 1285
1455 1286 $hours = filter_input(
1456 1287 INPUT_POST,
1457 1288 'refresh',
1458 - FILTER_VALIDATE_FLOAT,
1289 + FILTER_VALIDATE_INT,
1459 1290 array(
1460 1291 'options' => array(
1461 1292 'min_range' => -1,
1462 1293 'max_range' => apply_filters( 'visualizer_is_business', false ) ? PHP_INT_MAX : -1,
@@ -1463,9 +1294,9 @@
1463 1294 ),
1464 1295 )
1465 1296 );
1466 1297
1467 - if ( ! is_numeric( $hours ) ) {
1298 + if ( ! is_int( $hours ) ) {
1468 1299 $hours = -1;
1469 1300 }
1470 1301
1471 1302 $render = new Visualizer_Render_Page_Update();
@@ -1493,12 +1324,12 @@
1493 1324
1494 1325 wp_update_post(
1495 1326 array(
1496 1327 'ID' => $chart_id,
1497 - 'post_content' => $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ),
1328 + 'post_content' => $source->getData(),
1498 1329 )
1499 1330 );
1500 - $render->data = json_encode( $source->getRawData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) );
1331 + $render->data = json_encode( $source->getRawData() );
1501 1332 $render->series = json_encode( $source->getSeries() );
1502 1333 $render->id = $chart_id;
1503 1334 } else {
1504 1335 $render->message = $error;
@@ -1541,9 +1372,9 @@
1541 1372 ),
1542 1373 )
1543 1374 );
1544 1375
1545 - if ( 0 !== $hours && empty( $hours ) ) {
1376 + if ( ! $hours ) {
1546 1377 $hours = -1;
1547 1378 }
1548 1379
1549 1380 do_action( 'visualizer_save_filter', $chart_id, $hours );
@@ -1550,55 +1381,6 @@
1550 1381
1551 1382 if ( ! ( defined( 'VISUALIZER_DO_NOT_DIE' ) && VISUALIZER_DO_NOT_DIE ) ) {
1552 1383 defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
1553 1384 }
1554 - }
1555 -
1556 - /**
1557 - * Save chart image.
1558 - *
1559 - * @param string $base64_img Chart image.
1560 - * @param int $chart_id Chart ID.
1561 - * @param bool $save_attachment Save attachment.
1562 - * @return attachment ID
1563 - */
1564 - public function save_chart_image( $base64_img, $chart_id, $save_attachment = true ) {
1565 - // Delete old chart image.
1566 - $old_attachment_id = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_IMAGE, true );
1567 - if ( $old_attachment_id ) {
1568 - wp_delete_attachment( $old_attachment_id, true );
1569 - }
1570 -
1571 - if ( ! $save_attachment ) {
1572 - return 0;
1573 - }
1574 -
1575 - // Upload dir.
1576 - $upload_dir = wp_upload_dir();
1577 - $upload_path = str_replace( '/', DIRECTORY_SEPARATOR, $upload_dir['path'] ) . DIRECTORY_SEPARATOR;
1578 -
1579 - $img = str_replace( 'data:image/png;base64,', '', $base64_img );
1580 - $img = str_replace( ' ', '+', $img );
1581 - $decoded = base64_decode( $img );
1582 - $filename = 'visualization-' . $chart_id . '.png';
1583 - $file_type = 'image/png';
1584 - $hashed_filename = $filename;
1585 -
1586 - // Save the image in the uploads directory.
1587 - require_once ABSPATH . '/wp-admin/includes/file.php';
1588 - \WP_Filesystem();
1589 - global $wp_filesystem;
1590 - $upload_file = $wp_filesystem->put_contents( $upload_path . $hashed_filename, $decoded );
1591 -
1592 - // Insert new chart image.
1593 - $attachment = array(
1594 - 'post_mime_type' => $file_type,
1595 - 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $hashed_filename ) ),
1596 - 'post_content' => '',
1597 - 'post_status' => 'inherit',
1598 - 'guid' => $upload_dir['url'] . '/' . basename( $hashed_filename ),
1599 - );
1600 -
1601 - $attach_id = wp_insert_attachment( $attachment, $upload_dir['path'] . '/' . $hashed_filename );
1602 - return $attach_id;
1603 1385 }
1604 1386 }