PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.3.0
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.3.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 +109 -465 3.10.13.3.0 View file →
@@ -68,39 +68,11 @@
68 68 $this->_addAjaxAction( Visualizer_Plugin::ACTION_JSON_SET_SCHEDULE, 'setJsonSchedule' );
69 69
70 70 $this->_addAjaxAction( Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY, 'saveFilter' );
71 71
72 - $this->_addFilter( 'visualizer_get_sidebar', 'getSidebar', 10, 2 );
73 -
74 72 }
75 73
76 74 /**
77 - * Generates the HTML of the sidebar for the chart.
78 - *
79 - * @since ?
80 - *
81 - * @access public
82 - */
83 - public function getSidebar( $sidebar, $chart_id ) {
84 - $chart = get_post( $chart_id );
85 - $data = $this->_getChartArray( $chart );
86 - $sidebar = '';
87 - $sidebar_class = $this->load_chart_class_name( $chart_id );
88 - if ( class_exists( $sidebar_class, true ) ) {
89 - $sidebar = new $sidebar_class( $data['settings'] );
90 - $sidebar->__series = $data['series'];
91 - $sidebar->__data = $data['data'];
92 - } else {
93 - $sidebar = apply_filters( 'visualizer_pro_chart_type_sidebar', '', $data );
94 - if ( $sidebar !== '' ) {
95 - $sidebar->__series = $data['series'];
96 - $sidebar->__data = $data['data'];
97 - }
98 - }
99 - return str_replace( "'", '"', $sidebar->__toString() );
100 - }
101 -
102 - /**
103 75 * Sets the schedule for how JSON-endpoint charts should be updated.
104 76 *
105 77 * @since ?
106 78 *
@@ -134,30 +106,12 @@
134 106 ),
135 107 )
136 108 );
137 109
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 110 delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE );
153 111
154 112 if ( -1 < $time ) {
155 113 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 114 }
161 115 wp_send_json_success();
162 116 }
163 117
@@ -201,11 +155,10 @@
201 155 wp_die();
202 156 }
203 157
204 158 $source = new Visualizer_Source_Json( $params );
205 - $source->fetch();
206 - $data = $source->getRawData();
207 159
160 + $data = $source->parse();
208 161 if ( empty( $data ) ) {
209 162 wp_send_json_error( array( 'msg' => esc_html__( 'Unable to fetch data from the endpoint. Please try again.', 'visualizer' ) ) );
210 163 }
211 164
@@ -232,12 +185,11 @@
232 185
233 186 $chart = get_post( $chart_id );
234 187
235 188 $source = new Visualizer_Source_Json( $params );
236 - update_post_meta( $chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true );
237 - $source->fetchFromEditableTable();
189 + $source->fetch();
238 190
239 - $content = $source->getData( get_post_meta( $chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) );
191 + $content = $source->getData();
240 192 $chart->post_content = $content;
241 193 wp_update_post( $chart->to_array() );
242 194 update_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
243 195 update_post_meta( $chart->ID, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
@@ -243,58 +195,16 @@
243 195 update_post_meta( $chart->ID, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
244 196 update_post_meta( $chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, 0 );
245 197 update_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_URL, $params['url'] );
246 198 update_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_ROOT, $params['root'] );
247 -
248 - delete_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_HEADERS );
249 - $headers = array( 'method' => $params['method'] );
250 - if ( ! empty( $params['auth'] ) ) {
251 - $headers['auth'] = $params['auth'];
252 - } elseif ( ! empty( $params['username'] ) && ! empty( $params['password'] ) ) {
253 - $headers['auth'] = array( 'username' => $params['username'], 'password' => $params['password'] );
254 - }
255 -
256 - add_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_HEADERS, $headers );
257 -
258 199 delete_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_PAGING );
259 200 if ( ! empty( $params['paging'] ) ) {
260 201 add_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_PAGING, $params['paging'] );
261 202 }
262 203
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 - $time = filter_input(
272 - INPUT_POST,
273 - 'time',
274 - FILTER_VALIDATE_INT,
275 - array(
276 - 'options' => array(
277 - 'min_range' => -1,
278 - ),
279 - )
280 - );
281 -
282 - delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE );
283 -
284 - if ( -1 < $time ) {
285 - add_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, $time );
286 - }
287 -
288 - // delete other source specific parameters.
289 - delete_post_meta( $chart_id, Visualizer_Plugin::CF_DB_QUERY );
290 - delete_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE );
291 - delete_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_URL );
292 - delete_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_SCHEDULE );
293 -
294 204 $render = new Visualizer_Render_Page_Update();
295 205 $render->id = $chart->ID;
296 - $render->data = json_encode( $source->getRawData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) );
206 + $render->data = json_encode( $source->getRawData() );
297 207 $render->series = json_encode( $source->getSeries() );
298 208 $render->render();
299 209
300 210 defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
@@ -384,9 +294,9 @@
384 294 $chart = $this->_chart;
385 295 }
386 296 $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
387 297 $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 );
298 + $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( $chart->post_content ), $chart->ID, $type );
389 299 $library = $this->load_chart_type( $chart->ID );
390 300
391 301 $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
392 302 $settings = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SETTINGS, $settings, $chart->ID, $type );
@@ -460,22 +370,9 @@
460 370 $success = $chart && $chart->post_type === Visualizer_Plugin::CPT_VISUALIZER;
461 371 }
462 372 }
463 373 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 - }
374 + wp_delete_post( $chart_id, true );
478 375 }
479 376 if ( $is_post ) {
480 377 self::_sendResponse(
481 378 array(
@@ -524,104 +421,42 @@
524 421 * @access public
525 422 */
526 423 public function renderChartPages() {
527 424 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 425 // check chart, if chart not exists, will create new one and redirects to the same page with proper chart id
534 426 $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 427 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(
428 + $this->deleteOldCharts();
429 + $default_type = isset( $_GET['type'] ) && ! empty( $_GET['type'] ) ? $_GET['type'] : 'line';
430 + $source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $default_type . '.csv' );
431 + $source->fetch();
432 + $chart_id = wp_insert_post(
433 + array(
434 + 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
435 + 'post_title' => 'Visualization',
436 + 'post_author' => get_current_user_id(),
437 + 'post_status' => 'auto-draft',
438 + 'post_content' => $source->getData(),
439 + )
440 + );
441 + if ( $chart_id && ! is_wp_error( $chart_id ) ) {
442 + add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, $default_type );
443 + add_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 1 );
444 + add_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
445 + add_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
446 + add_post_meta(
447 + $chart_id,
448 + Visualizer_Plugin::CF_SETTINGS,
549 449 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 ) ),
450 + 'focusTarget' => 'datum',
555 451 )
556 452 );
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 453 do_action( 'visualizer_pro_new_chart_defaults', $chart_id );
606 454 }
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();
455 + wp_redirect( add_query_arg( 'chart', (int) $chart_id ) );
456 + defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
613 457 }
614 458
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 459 $lib = $this->load_chart_type( $chart_id );
625 460
626 461 // the alpha color picker (RGBA) is not supported by google.
627 462 $color_picker_dep = 'wp-color-picker';
@@ -634,9 +469,9 @@
634 469 wp_register_script( 'visualizer-chosen', VISUALIZER_ABSURL . 'js/lib/chosen.jquery.min.js', array( 'jquery' ), Visualizer_Plugin::VERSION );
635 470 wp_register_style( 'visualizer-chosen', VISUALIZER_ABSURL . 'css/lib/chosen.min.css', array(), Visualizer_Plugin::VERSION );
636 471
637 472 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 );
473 + wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'visualizer-chosen', 'jquery-ui-accordion' ), Visualizer_Plugin::VERSION, true );
639 474 wp_register_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true );
640 475 wp_register_script(
641 476 'visualizer-render',
642 477 VISUALIZER_ABSURL . 'js/render-facade.js',
@@ -675,9 +510,8 @@
675 510 if ( isset( $_POST['cancel'] ) && 1 === intval( $_POST['cancel'] ) ) {
676 511 // if the cancel button is clicked.
677 512 $this->undoRevisions( $chart_id, true );
678 513 } elseif ( isset( $_POST['save'] ) && 1 === intval( $_POST['save'] ) ) {
679 - $this->handlePermissions();
680 514 // if the save button is clicked.
681 515 $this->undoRevisions( $chart_id, false );
682 516 } else {
683 517 // if the edit button is clicked.
@@ -683,16 +517,8 @@
683 517 // if the edit button is clicked.
684 518 $this->_chart = $this->handleExistingRevisions( $chart_id, $this->_chart );
685 519 }
686 520
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 521 switch ( $tab ) {
696 522 case 'settings':
697 523 $this->_handleDataAndSettingsPage();
698 524 break;
@@ -700,9 +526,9 @@
700 526 case 'visualizer': // fall through.
701 527 $this->_handleTypesPage();
702 528 break;
703 529 default:
704 - // this should never happen.
530 + do_action( 'visualizer_pro_handle_tab', $tab, $this->_chart );
705 531 break;
706 532 }
707 533 defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
708 534 }
@@ -709,9 +535,9 @@
709 535
710 536 /**
711 537 * Load code editor assets.
712 538 */
713 - private function loadCodeEditorAssets( $chart_id ) {
539 + private function loadCodeEditorAssets() {
714 540 global $wp_version;
715 541
716 542 $wp_scripts = wp_scripts();
717 543
@@ -717,9 +543,9 @@
717 543
718 544 // data tables assets.
719 545 wp_register_script( 'visualizer-datatables', VISUALIZER_ABSURL . 'js/lib/datatables.min.js', array( 'jquery-ui-core' ), Visualizer_Plugin::VERSION );
720 546 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 );
547 + 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 548 wp_enqueue_script( 'visualizer-datatables' );
723 549 wp_enqueue_style( 'visualizer-jquery-ui' );
724 550
725 551 if ( ! Visualizer_Module::is_pro() ) {
@@ -725,9 +551,9 @@
725 551 if ( ! Visualizer_Module::is_pro() ) {
726 552 return;
727 553 }
728 554
729 - $table_col_mapping = Visualizer_Source_Query_Params::get_all_db_tables_column_mapping( $chart_id );
555 + $table_col_mapping = Visualizer_Source_Query_Params::get_all_db_tables_column_mapping();
730 556
731 557 if ( version_compare( $wp_version, '4.9.0', '<' ) ) {
732 558 // code mirror assets.
733 559 wp_register_script( 'visualizer-codemirror-core', '//codemirror.net/lib/codemirror.js', array( 'jquery' ), Visualizer_Plugin::VERSION );
@@ -762,25 +588,8 @@
762 588 return $table_col_mapping;
763 589 }
764 590
765 591 /**
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 592 * Handle data and settings page
784 593 */
785 594 private function _handleDataAndSettingsPage() {
786 595 if ( isset( $_POST['map_api_key'] ) ) {
@@ -785,9 +594,8 @@
785 594 private function _handleDataAndSettingsPage() {
786 595 if ( isset( $_POST['map_api_key'] ) ) {
787 596 update_option( 'visualizer-map-api-key', $_POST['map_api_key'] );
788 597 }
789 -
790 598 if ( $_SERVER['REQUEST_METHOD'] === 'POST' && isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'] ) ) {
791 599 if ( $this->_chart->post_status === 'auto-draft' ) {
792 600 $this->_chart->post_status = 'publish';
793 601
@@ -792,10 +600,9 @@
792 600 $this->_chart->post_status = 'publish';
793 601
794 602 // 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 603 // we do not want any difference in data so disable revisions temporarily.
796 - $this->disableRevisionsTemporarily();
797 -
604 + add_filter( 'wp_revisions_to_keep', '__return_false' );
798 605 wp_update_post( $this->_chart->to_array() );
799 606 }
800 607 // save meta data only when it is NOT being canceled.
801 608 if ( ! ( isset( $_POST['cancel'] ) && 1 === intval( $_POST['cancel'] ) ) ) {
@@ -814,19 +621,14 @@
814 621 if ( empty( $title ) ) {
815 622 $title = $this->_chart->ID;
816 623 }
817 624 $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 625 update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, $settings );
825 626 }
826 627 $render = new Visualizer_Render_Page_Send();
827 628 $render->text = sprintf( '[visualizer id="%d"]', $this->_chart->ID );
828 629 wp_iframe( array( $render, 'render' ) );
630 +
829 631 return;
830 632 }
831 633 $data = $this->_getChartArray();
832 634 $sidebar = '';
@@ -848,9 +650,9 @@
848 650 wp_enqueue_script( 'visualizer-preview' );
849 651 wp_enqueue_script( 'visualizer-chosen' );
850 652 wp_enqueue_script( 'visualizer-render' );
851 653
852 - if ( Visualizer_Module::can_show_feature( 'simple-editor' ) ) {
654 + if ( ! Visualizer_Module::is_pro() ) {
853 655 wp_enqueue_script( 'visualizer-editor-simple' );
854 656 wp_localize_script(
855 657 'visualizer-editor-simple',
856 658 'visualizer1',
@@ -865,9 +667,9 @@
865 667 )
866 668 );
867 669 }
868 670
869 - $table_col_mapping = $this->loadCodeEditorAssets( $this->_chart->ID );
671 + $table_col_mapping = $this->loadCodeEditorAssets();
870 672
871 673 wp_localize_script(
872 674 'visualizer-render',
873 675 'visualizer',
@@ -872,13 +674,11 @@
872 674 'visualizer-render',
873 675 'visualizer',
874 676 array(
875 677 'l10n' => array(
876 - 'invalid_source' => esc_html__( 'You have entered an invalid URL. Please provide a valid URL.', 'visualizer' ),
678 + 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ),
877 679 'loading' => esc_html__( 'Loading...', 'visualizer' ),
878 680 'json_error' => esc_html__( 'An error occured in fetching data.', 'visualizer' ),
879 - '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 681 ),
882 682 'charts' => array(
883 683 'canvas' => $data,
884 684 'id' => $this->_chart->ID,
@@ -909,9 +709,8 @@
909 709 'page_type' => 'chart',
910 710 'json_tag_separator' => Visualizer_Source_Json::TAG_SEPARATOR,
911 711 'json_tag_separator_view' => Visualizer_Source_Json::TAG_SEPARATOR_VIEW,
912 712 'is_front' => false,
913 - 'rest_base' => get_rest_url( null, 'wc/v3/reports/' ),
914 713 )
915 714 );
916 715
917 716 $render = new Visualizer_Render_Page_Data();
@@ -929,13 +728,13 @@
929 728 } else {
930 729 $render->button = esc_attr__( 'Insert Chart', 'visualizer' );
931 730 }
932 731
933 - do_action( 'visualizer_enqueue_scripts_and_styles', $data, $this->_chart->ID );
732 + do_action( 'visualizer_enqueue_scripts_and_styles', $data );
934 733
935 734 if ( Visualizer_Module::is_pro() && Visualizer_Module::is_pro_older_than( '1.9.0' ) ) {
936 735 global $Visualizer_Pro;
937 - $Visualizer_Pro->_enqueueScriptsAndStyles( $data, $this->_chart->ID );
736 + $Visualizer_Pro->_enqueueScriptsAndStyles( $data );
938 737 }
939 738
940 739 $this->_addAction( 'admin_head', 'renderFlattrScript' );
941 740 wp_iframe( array( $render, 'render' ) );
@@ -952,9 +751,9 @@
952 751 // process post request
953 752 if ( $_SERVER['REQUEST_METHOD'] === 'POST' && wp_verify_nonce( filter_input( INPUT_POST, 'nonce' ) ) ) {
954 753 $type = filter_input( INPUT_POST, 'type' );
955 754 $library = filter_input( INPUT_POST, 'chart-library' );
956 - if ( Visualizer_Module_Admin::checkChartStatus( $type ) ) {
755 + if ( in_array( $type, Visualizer_Plugin::getChartTypes(), true ) ) {
957 756 if ( empty( $library ) ) {
958 757 // library cannot be empty.
959 758 do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'Chart library empty while creating the chart! Aborting...', 'error', __FILE__, __LINE__ );
960 759 return;
@@ -966,9 +765,9 @@
966 765 // if the chart has default data, update it with appropriate default data for new type
967 766 if ( filter_var( get_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, true ), FILTER_VALIDATE_BOOLEAN ) ) {
968 767 $source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $type . '.csv' );
969 768 $source->fetch();
970 - $this->_chart->post_content = $source->getData( get_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) );
769 + $this->_chart->post_content = $source->getData();
971 770 wp_update_post( $this->_chart->to_array() );
972 771 update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
973 772 }
974 773
@@ -975,9 +774,9 @@
975 774 Visualizer_Module_Utility::set_defaults( $this->_chart );
976 775
977 776 // redirect to next tab
978 777 // changed by Ash/Upwork
979 - wp_redirect( esc_url_raw( add_query_arg( 'tab', 'settings' ) ) );
778 + wp_redirect( add_query_arg( 'tab', 'settings' ) );
980 779
981 780 return;
982 781 }
983 782 }
@@ -1006,51 +805,30 @@
1006 805 * Processes the CSV that is sent in the request as a string.
1007 806 *
1008 807 * @since 3.2.0
1009 808 */
1010 - private function handleCSVasString( $data, $editor_type ) {
809 + private function handleCSVasString( $data ) {
1011 810 $source = null;
1012 811
1013 - switch ( $editor_type ) {
1014 - case 'text':
1015 - // data coming in from the text editor.
1016 - $tmpfile = tempnam( get_temp_dir(), Visualizer_Plugin::NAME );
1017 - $handle = fopen( $tmpfile, 'w' );
1018 - $values = preg_split( '/[\n\r]+/', stripslashes( trim( $data ) ) );
1019 - if ( $values ) {
1020 - foreach ( $values as $row ) {
1021 - if ( empty( $row ) ) {
1022 - continue;
1023 - }
1024 - $row = explode( ',', $row );
1025 - $row = array_map(
1026 - function( $r ) {
1027 - return '' === $r ? ' ' : $r;
1028 - },
1029 - $row
1030 - );
1031 - $row = implode( ',', $row );
1032 - // don't use fpucsv here because we need to just dump the data
1033 - // minus the empty rows
1034 - // 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
1039 - fwrite( $handle, $row );
1040 - fwrite( $handle, PHP_EOL );
812 + // @issue https://github.com/Codeinwp/visualizer/issues/412
813 + if ( has_filter( 'visualizer_pro_handle_chart_data' ) ) {
814 + $source = apply_filters( 'visualizer_pro_handle_chart_data', $data, '' );
815 + } else {
816 + // data coming in from the text editor.
817 + $tmpfile = tempnam( get_temp_dir(), Visualizer_Plugin::NAME );
818 + $handle = fopen( $tmpfile, 'w' );
819 + $values = preg_split( '/[\n\r]+/', stripslashes( trim( $data ) ) );
820 + if ( $values ) {
821 + foreach ( $values as $row ) {
822 + if ( empty( $row ) ) {
823 + continue;
1041 824 }
825 + $columns = explode( ',', $row );
826 + fputcsv( $handle, $columns );
1042 827 }
1043 - $source = new Visualizer_Source_Csv( $tmpfile );
1044 - fclose( $handle );
1045 - break;
1046 - case 'table':
1047 - // Import from Chart
1048 - // fall-through.
1049 - case 'excel':
1050 - // data coming in from the excel editor.
1051 - $source = apply_filters( 'visualizer_pro_handle_chart_data', $data, '' );
1052 - break;
828 + }
829 + $source = new Visualizer_Source_Csv( $tmpfile );
830 + fclose( $handle );
1053 831 }
1054 832 return $source;
1055 833 }
1056 834
@@ -1099,9 +877,9 @@
1099 877 $csv[] = $types;
1100 878 for ( $j = 0; $j < count( $columns[0] ); $j++ ) {
1101 879 $row = array();
1102 880 for ( $i = 0; $i < count( $headers ); $i++ ) {
1103 - $row[] = sanitize_text_field( $columns[ $i ][ $j ] );
881 + $row[] = $columns[ $i ][ $j ];
1104 882 }
1105 883 $csv[] = $row;
1106 884 }
1107 885
@@ -1154,10 +932,8 @@
1154 932 status_header( 400 );
1155 933 exit;
1156 934 }
1157 935
1158 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Uploading data for chart %d with POST = %s and GET = %s', $chart_id, print_r( $_POST, true ), print_r( $_GET, true ) ), 'debug', __FILE__, __LINE__ );
1159 -
1160 936 if ( ! isset( $_POST['vz-import-time'] ) ) {
1161 937 apply_filters( 'visualizer_pro_remove_schedule', $chart_id );
1162 938 }
1163 939
@@ -1169,9 +945,8 @@
1169 945
1170 946 // delete "import from db" specific parameters.
1171 947 delete_post_meta( $chart_id, Visualizer_Plugin::CF_DB_QUERY );
1172 948 delete_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE );
1173 - delete_post_meta( $chart_id, Visualizer_Plugin::CF_REMOTE_DB_PARAMS );
1174 949 }
1175 950
1176 951 // delete json related data.
1177 952 delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_URL );
@@ -1176,51 +951,29 @@
1176 951 // delete json related data.
1177 952 delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_URL );
1178 953 delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_ROOT );
1179 954 delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_PAGING );
1180 - delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_HEADERS );
1181 955
1182 - // delete last error
1183 - delete_post_meta( $chart_id, Visualizer_Plugin::CF_ERROR );
1184 -
1185 - // delete editor related data.
1186 - delete_post_meta( $chart_id, Visualizer_Plugin::CF_EDITOR );
1187 -
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 956 $source = null;
1192 957 $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 );
958 + if ( isset( $_POST['remote_data'] ) && filter_var( $_POST['remote_data'], FILTER_VALIDATE_URL ) ) {
959 + $source = new Visualizer_Source_Csv_Remote( $_POST['remote_data'] );
1200 960 if ( isset( $_POST['vz-import-time'] ) ) {
1201 - apply_filters( 'visualizer_pro_chart_schedule', $chart_id, $remote_data, $_POST['vz-import-time'] );
961 + apply_filters( 'visualizer_pro_chart_schedule', $chart_id, $_POST['remote_data'], $_POST['vz-import-time'] );
1202 962 }
1203 963 // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1204 964 } elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) {
1205 965 $source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] );
1206 966 } elseif ( isset( $_POST['chart_data'] ) && strlen( $_POST['chart_data'] ) > 0 ) {
1207 - $source = $this->handleCSVasString( $_POST['chart_data'], $_POST['editor-type'] );
1208 - update_post_meta( $chart_id, Visualizer_Plugin::CF_EDITOR, $_POST['editor-type'] );
967 + $source = $this->handleCSVasString( $_POST['chart_data'] );
1209 968 } elseif ( isset( $_POST['table_data'] ) && 'yes' === $_POST['table_data'] ) {
1210 969 $source = $this->handleTabularData();
1211 - update_post_meta( $chart_id, Visualizer_Plugin::CF_EDITOR, $_POST['editor-type'] );
1212 970 } else {
1213 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'CSV file with chart data was not uploaded for chart %d.', $chart_id ), 'error', __FILE__, __LINE__ );
1214 971 $render->message = esc_html__( 'CSV file with chart data was not uploaded. Please try again.', 'visualizer' );
1215 - update_post_meta( $chart_id, Visualizer_Plugin::CF_ERROR, esc_html__( 'CSV file with chart data was not uploaded. Please try again.', 'visualizer' ) );
1216 972 }
1217 -
1218 - 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 -
1220 973 if ( $source ) {
1221 974 if ( $source->fetch() ) {
1222 - $content = $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) );
975 + $content = $source->getData();
1223 976 $populate = true;
1224 977 if ( is_string( $content ) && is_array( unserialize( $content ) ) ) {
1225 978 $json = unserialize( $content );
1226 979 // if source exists, so should data. if source exists but data is blank, do not populate the chart.
@@ -1226,9 +979,8 @@
1226 979 // if source exists, so should data. if source exists but data is blank, do not populate the chart.
1227 980 // if we populate the data even if it is empty, the chart will show "Table has no columns".
1228 981 if ( array_key_exists( 'source', $json ) && ! empty( $json['source'] ) && ( ! array_key_exists( 'data', $json ) || empty( $json['data'] ) ) ) {
1229 982 do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Not populating chart data as source exists (%s) but data is empty!', $json['source'] ), 'warn', __FILE__, __LINE__ );
1230 - update_post_meta( $chart_id, Visualizer_Plugin::CF_ERROR, sprintf( 'Not populating chart data as source exists (%s) but data is empty!', $json['source'] ) );
1231 983 $populate = false;
1232 984 }
1233 985 }
1234 986 if ( $populate ) {
@@ -1234,43 +986,26 @@
1234 986 if ( $populate ) {
1235 987 $chart->post_content = $content;
1236 988 }
1237 989 wp_update_post( $chart->to_array() );
1238 -
1239 990 update_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
1240 991 update_post_meta( $chart->ID, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
1241 992 update_post_meta( $chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, 0 );
1242 993
1243 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Updated post for chart %d', $chart_id ), 'debug', __FILE__, __LINE__ );
1244 -
1245 994 Visualizer_Module_Utility::set_defaults( $chart, null );
1246 995
1247 996 $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 997
1258 998 $render->id = $chart->ID;
1259 - $render->data = json_encode( $source->getRawData( get_post_meta( $chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) );
999 + $render->data = json_encode( $source->getRawData() );
1260 1000 $render->series = json_encode( $source->getSeries() );
1261 1001 $render->settings = json_encode( $settings );
1262 1002 } else {
1263 - $error = $source->get_error();
1264 - if ( empty( $error ) ) {
1265 - $error = esc_html__( 'CSV file is broken or invalid. Please try again.', 'visualizer' );
1003 + $render->message = $source->get_error();
1004 + if ( empty( $render->message ) ) {
1005 + $render->message = esc_html__( 'CSV file is broken or invalid. Please try again.', 'visualizer' );
1266 1006 }
1267 - $render->message = $error;
1268 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( '%s for chart %d.', $error, $chart_id ), 'error', __FILE__, __LINE__ );
1269 - update_post_meta( $chart_id, Visualizer_Plugin::CF_ERROR, $error );
1270 1007 }
1271 - } else {
1272 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unknown internal error for chart %d.', $chart_id ), 'error', __FILE__, __LINE__ );
1273 1008 }
1274 1009 $render->render();
1275 1010 if ( ! $can_die ) {
1276 1011 return;
@@ -1286,12 +1021,21 @@
1286 1021 * @access public
1287 1022 */
1288 1023 public function cloneChart() {
1289 1024 $chart_id = $success = false;
1290 - $nonce = isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'], Visualizer_Plugin::ACTION_CLONE_CHART );
1025 + $nonce = wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ), Visualizer_Plugin::ACTION_CLONE_CHART );
1291 1026 $capable = current_user_can( 'edit_posts' );
1292 1027 if ( $nonce && $capable ) {
1293 - $chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : '';
1028 + $chart_id = filter_input(
1029 + INPUT_GET,
1030 + 'chart',
1031 + FILTER_VALIDATE_INT,
1032 + array(
1033 + 'options' => array(
1034 + 'min_range' => 1,
1035 + ),
1036 + )
1037 + );
1294 1038 if ( $chart_id ) {
1295 1039 $chart = get_post( $chart_id );
1296 1040 $success = $chart && $chart->post_type === Visualizer_Plugin::CPT_VISUALIZER;
1297 1041 }
@@ -1306,35 +1050,24 @@
1306 1050 'post_status' => $chart->post_status,
1307 1051 'post_content' => $chart->post_content,
1308 1052 )
1309 1053 );
1310 - if ( is_wp_error( $new_chart_id ) ) {
1311 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Error while cloning chart %d = %s', $chart_id, print_r( $new_chart_id, true ) ), 'error', __FILE__, __LINE__ );
1312 - } else {
1313 - $post_meta = get_post_meta( $chart_id );
1314 - foreach ( $post_meta as $key => $value ) {
1315 - if ( strpos( $key, 'visualizer-' ) !== false ) {
1316 - add_post_meta( $new_chart_id, $key, maybe_unserialize( $value[0] ) );
1317 - }
1318 - }
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' )
1054 + if ( $new_chart_id && ! is_wp_error( $new_chart_id ) ) {
1055 + add_post_meta( $new_chart_id, Visualizer_Plugin::CF_CHART_TYPE, get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true ) );
1056 + add_post_meta( $new_chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, get_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, true ) );
1057 + add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SOURCE, get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) );
1058 + add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SERIES, get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true ) );
1059 + add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SETTINGS, get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true ) );
1060 + $redirect = add_query_arg(
1061 + array(
1062 + 'page' => 'visualizer',
1063 + 'type' => filter_input( INPUT_GET, 'type' ),
1064 + 'vaction' => false,
1327 1065 ),
1328 - null,
1329 - 'db'
1066 + admin_url( 'admin.php' )
1330 1067 );
1331 1068 }
1332 1069 }
1333 -
1334 - if ( defined( 'WP_TESTS_DOMAIN' ) ) {
1335 - wp_die();
1336 - }
1337 1070 wp_redirect( $redirect );
1338 1071 exit;
1339 1072 }
1340 1073
@@ -1380,12 +1113,9 @@
1380 1113 $data = $this->_getChartArray();
1381 1114 $render = new Visualizer_Render_Page_Data();
1382 1115 $render->chart = $this->_chart;
1383 1116 $render->type = $data['type'];
1384 -
1385 - if ( $data && $data['settings'] ) {
1386 - unset( $data['settings']['width'], $data['settings']['height'], $data['settings']['chartArea'] );
1387 - }
1117 + unset( $data['settings']['width'], $data['settings']['height'], $data['settings']['chartArea'] );
1388 1118 wp_enqueue_style( 'visualizer-frame' );
1389 1119 wp_enqueue_script( 'visualizer-render' );
1390 1120 wp_localize_script(
1391 1121 'visualizer-render',
@@ -1391,9 +1121,9 @@
1391 1121 'visualizer-render',
1392 1122 'visualizer',
1393 1123 array(
1394 1124 'l10n' => array(
1395 - 'invalid_source' => esc_html__( 'You have entered an invalid URL. Please provide a valid URL.', 'visualizer' ),
1125 + 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ),
1396 1126 'loading' => esc_html__( 'Loading...', 'visualizer' ),
1397 1127 ),
1398 1128 'charts' => array(
1399 1129 'canvas' => $data,
@@ -1400,13 +1130,13 @@
1400 1130 ),
1401 1131 )
1402 1132 );
1403 1133
1404 - do_action( 'visualizer_enqueue_scripts_and_styles', $data, $this->_chart->ID );
1134 + do_action( 'visualizer_enqueue_scripts_and_styles', $data );
1405 1135
1406 1136 if ( Visualizer_Module::is_pro() && Visualizer_Module::is_pro_older_than( '1.9.0' ) ) {
1407 1137 global $Visualizer_Pro;
1408 - $Visualizer_Pro->_enqueueScriptsAndStyles( $data, $this->_chart->ID );
1138 + $Visualizer_Pro->_enqueueScriptsAndStyles( $data );
1409 1139 }
1410 1140
1411 1141 // Added by Ash/Upwork
1412 1142 $this->_addAction( 'admin_head', 'renderFlattrScript' );
@@ -1421,14 +1151,13 @@
1421 1151 public function getQueryData() {
1422 1152 check_ajax_referer( Visualizer_Plugin::ACTION_FETCH_DB_DATA . Visualizer_Plugin::VERSION, 'security' );
1423 1153
1424 1154 $params = wp_parse_args( $_POST['params'] );
1425 - $chart_id = filter_var( $params['chart_id'], FILTER_VALIDATE_INT );
1426 -
1427 - $source = new Visualizer_Source_Query( stripslashes( $params['query'] ), $chart_id, $params );
1155 + $source = new Visualizer_Source_Query( stripslashes( $params['query'] ) );
1428 1156 $html = $source->fetch( true );
1429 - $error = $source->get_error();
1430 - if ( ! empty( $error ) ) {
1157 + $error = '';
1158 + if ( empty( $html ) ) {
1159 + $error = $source->get_error();
1431 1160 wp_send_json_error( array( 'msg' => $error ) );
1432 1161 }
1433 1162 wp_send_json_success( array( 'table' => $html ) );
1434 1163 }
@@ -1451,42 +1180,21 @@
1451 1180 ),
1452 1181 )
1453 1182 );
1454 1183
1455 - $hours = filter_input(
1456 - INPUT_POST,
1457 - 'refresh',
1458 - FILTER_VALIDATE_FLOAT,
1459 - array(
1460 - 'options' => array(
1461 - 'min_range' => -1,
1462 - 'max_range' => apply_filters( 'visualizer_is_business', false ) ? PHP_INT_MAX : -1,
1463 - ),
1464 - )
1465 - );
1466 -
1467 - if ( ! is_numeric( $hours ) ) {
1468 - $hours = -1;
1469 - }
1470 -
1471 1184 $render = new Visualizer_Render_Page_Update();
1472 1185 if ( $chart_id ) {
1473 1186 $params = wp_parse_args( $_POST['params'] );
1474 - $source = new Visualizer_Source_Query( stripslashes( $params['query'] ), $chart_id, $params );
1187 + $source = new Visualizer_Source_Query( stripslashes( $params['query'] ) );
1475 1188 $source->fetch( false );
1476 1189 $error = $source->get_error();
1477 1190 if ( empty( $error ) ) {
1191 + $hours = $_POST['refresh'];
1478 1192 update_post_meta( $chart_id, Visualizer_Plugin::CF_DB_QUERY, stripslashes( $params['query'] ) );
1479 1193 update_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
1480 1194 update_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
1481 1195 update_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, $hours );
1482 1196 update_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 0 );
1483 - if ( isset( $params['db_type'] ) && $params['db_type'] !== Visualizer_Plugin::WP_DB_NAME ) {
1484 - $remote_db_params = $params;
1485 - unset( $remote_db_params['query'] );
1486 - unset( $remote_db_params['chart_id'] );
1487 - update_post_meta( $chart_id, Visualizer_Plugin::CF_REMOTE_DB_PARAMS, $remote_db_params );
1488 - }
1489 1197
1490 1198 $schedules = get_option( Visualizer_Plugin::CF_DB_SCHEDULE, array() );
1491 1199 $schedules[ $chart_id ] = time() + $hours * HOUR_IN_SECONDS;
1492 1200 update_option( Visualizer_Plugin::CF_DB_SCHEDULE, $schedules );
@@ -1493,14 +1201,13 @@
1493 1201
1494 1202 wp_update_post(
1495 1203 array(
1496 1204 'ID' => $chart_id,
1497 - 'post_content' => $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ),
1205 + 'post_content' => $source->getData(),
1498 1206 )
1499 1207 );
1500 - $render->data = json_encode( $source->getRawData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) );
1208 + $render->data = json_encode( $source->getRawData() );
1501 1209 $render->series = json_encode( $source->getSeries() );
1502 - $render->id = $chart_id;
1503 1210 } else {
1504 1211 $render->message = $error;
1505 1212 }
1506 1213 }
@@ -1529,76 +1236,13 @@
1529 1236 ),
1530 1237 )
1531 1238 );
1532 1239
1533 - $hours = filter_input(
1534 - INPUT_POST,
1535 - 'refresh',
1536 - FILTER_VALIDATE_INT,
1537 - array(
1538 - 'options' => array(
1539 - 'min_range' => -1,
1540 - 'max_range' => apply_filters( 'visualizer_is_business', false ) ? PHP_INT_MAX : -1,
1541 - ),
1542 - )
1543 - );
1240 + $hours = $_POST['refresh'];
1544 1241
1545 - if ( 0 !== $hours && empty( $hours ) ) {
1546 - $hours = -1;
1547 - }
1548 -
1549 1242 do_action( 'visualizer_save_filter', $chart_id, $hours );
1550 1243
1551 1244 if ( ! ( defined( 'VISUALIZER_DO_NOT_DIE' ) && VISUALIZER_DO_NOT_DIE ) ) {
1552 1245 defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
1553 1246 }
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 1247 }
1604 1248 }