PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.4
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.4
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 3.10.4 All 148 releases
← All changes | classes/Visualizer/Module/Chart.php +49 -243 3.10.03.4.4 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();
@@ -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';
@@ -683,16 +582,8 @@
683 582 // if the edit button is clicked.
684 583 $this->_chart = $this->handleExistingRevisions( $chart_id, $this->_chart );
685 584 }
686 585
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 586 switch ( $tab ) {
696 587 case 'settings':
697 588 $this->_handleDataAndSettingsPage();
698 589 break;
@@ -717,9 +608,9 @@
717 608
718 609 // data tables assets.
719 610 wp_register_script( 'visualizer-datatables', VISUALIZER_ABSURL . 'js/lib/datatables.min.js', array( 'jquery-ui-core' ), Visualizer_Plugin::VERSION );
720 611 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 );
612 + 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 613 wp_enqueue_script( 'visualizer-datatables' );
723 614 wp_enqueue_style( 'visualizer-jquery-ui' );
724 615
725 616 if ( ! Visualizer_Module::is_pro() ) {
@@ -814,14 +705,8 @@
814 705 if ( empty( $title ) ) {
815 706 $title = $this->_chart->ID;
816 707 }
817 708 $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 709 update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, $settings );
825 710 }
826 711 $render = new Visualizer_Render_Page_Send();
827 712 $render->text = sprintf( '[visualizer id="%d"]', $this->_chart->ID );
@@ -909,9 +794,8 @@
909 794 'page_type' => 'chart',
910 795 'json_tag_separator' => Visualizer_Source_Json::TAG_SEPARATOR,
911 796 'json_tag_separator_view' => Visualizer_Source_Json::TAG_SEPARATOR_VIEW,
912 797 'is_front' => false,
913 - 'rest_base' => get_rest_url( null, 'wc/v3/reports/' ),
914 798 )
915 799 );
916 800
917 801 $render = new Visualizer_Render_Page_Data();
@@ -952,9 +836,9 @@
952 836 // process post request
953 837 if ( $_SERVER['REQUEST_METHOD'] === 'POST' && wp_verify_nonce( filter_input( INPUT_POST, 'nonce' ) ) ) {
954 838 $type = filter_input( INPUT_POST, 'type' );
955 839 $library = filter_input( INPUT_POST, 'chart-library' );
956 - if ( Visualizer_Module_Admin::checkChartStatus( $type ) ) {
840 + if ( in_array( $type, Visualizer_Plugin::getChartTypes(), true ) ) {
957 841 if ( empty( $library ) ) {
958 842 // library cannot be empty.
959 843 do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'Chart library empty while creating the chart! Aborting...', 'error', __FILE__, __LINE__ );
960 844 return;
@@ -966,9 +850,9 @@
966 850 // if the chart has default data, update it with appropriate default data for new type
967 851 if ( filter_var( get_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, true ), FILTER_VALIDATE_BOOLEAN ) ) {
968 852 $source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $type . '.csv' );
969 853 $source->fetch();
970 - $this->_chart->post_content = $source->getData( get_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) );
854 + $this->_chart->post_content = $source->getData();
971 855 wp_update_post( $this->_chart->to_array() );
972 856 update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
973 857 }
974 858
@@ -975,9 +859,9 @@
975 859 Visualizer_Module_Utility::set_defaults( $this->_chart );
976 860
977 861 // redirect to next tab
978 862 // changed by Ash/Upwork
979 - wp_redirect( esc_url_raw( add_query_arg( 'tab', 'settings' ) ) );
863 + wp_redirect( add_query_arg( 'tab', 'settings' ) );
980 864
981 865 return;
982 866 }
983 867 }
@@ -1020,16 +904,8 @@
1020 904 foreach ( $values as $row ) {
1021 905 if ( empty( $row ) ) {
1022 906 continue;
1023 907 }
1024 - $row = explode( ',', $row );
1025 - $row = array_map(
1026 - function( $r ) {
1027 - return '' === $r ? ' ' : $r;
1028 - },
1029 - $row
1030 - );
1031 - $row = implode( ',', $row );
1032 908 // don't use fpucsv here because we need to just dump the data
1033 909 // minus the empty rows
1034 910 // because fputcsv needs to tokenize
1035 911 // we can standardize the CSV enclosure here and replace all ' with "
@@ -1184,22 +1060,14 @@
1184 1060
1185 1061 // delete editor related data.
1186 1062 delete_post_meta( $chart_id, Visualizer_Plugin::CF_EDITOR );
1187 1063
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 1064 $source = null;
1192 1065 $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 );
1066 + if ( isset( $_POST['remote_data'] ) && filter_var( $_POST['remote_data'], FILTER_VALIDATE_URL ) ) {
1067 + $source = new Visualizer_Source_Csv_Remote( $_POST['remote_data'] );
1200 1068 if ( isset( $_POST['vz-import-time'] ) ) {
1201 - apply_filters( 'visualizer_pro_chart_schedule', $chart_id, $remote_data, $_POST['vz-import-time'] );
1069 + apply_filters( 'visualizer_pro_chart_schedule', $chart_id, $_POST['remote_data'], $_POST['vz-import-time'] );
1202 1070 }
1203 1071 // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1204 1072 } elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) {
1205 1073 $source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] );
@@ -1218,9 +1086,9 @@
1218 1086 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 1087
1220 1088 if ( $source ) {
1221 1089 if ( $source->fetch() ) {
1222 - $content = $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) );
1090 + $content = $source->getData();
1223 1091 $populate = true;
1224 1092 if ( is_string( $content ) && is_array( unserialize( $content ) ) ) {
1225 1093 $json = unserialize( $content );
1226 1094 // if source exists, so should data. if source exists but data is blank, do not populate the chart.
@@ -1234,9 +1102,8 @@
1234 1102 if ( $populate ) {
1235 1103 $chart->post_content = $content;
1236 1104 }
1237 1105 wp_update_post( $chart->to_array() );
1238 -
1239 1106 update_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
1240 1107 update_post_meta( $chart->ID, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
1241 1108 update_post_meta( $chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, 0 );
1242 1109
@@ -1244,20 +1111,11 @@
1244 1111
1245 1112 Visualizer_Module_Utility::set_defaults( $chart, null );
1246 1113
1247 1114 $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 1115
1258 1116 $render->id = $chart->ID;
1259 - $render->data = json_encode( $source->getRawData( get_post_meta( $chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) );
1117 + $render->data = json_encode( $source->getRawData() );
1260 1118 $render->series = json_encode( $source->getSeries() );
1261 1119 $render->settings = json_encode( $settings );
1262 1120 } else {
1263 1121 $error = $source->get_error();
@@ -1315,19 +1173,15 @@
1315 1173 if ( strpos( $key, 'visualizer-' ) !== false ) {
1316 1174 add_post_meta( $new_chart_id, $key, maybe_unserialize( $value[0] ) );
1317 1175 }
1318 1176 }
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' )
1177 + $redirect = add_query_arg(
1178 + array(
1179 + 'page' => 'visualizer',
1180 + 'type' => filter_input( INPUT_GET, 'type' ),
1181 + 'vaction' => false,
1327 1182 ),
1328 - null,
1329 - 'db'
1183 + admin_url( 'admin.php' )
1330 1184 );
1331 1185 }
1332 1186 }
1333 1187
@@ -1333,8 +1187,9 @@
1333 1187
1334 1188 if ( defined( 'WP_TESTS_DOMAIN' ) ) {
1335 1189 wp_die();
1336 1190 }
1191 +
1337 1192 wp_redirect( $redirect );
1338 1193 exit;
1339 1194 }
1340 1195
@@ -1454,9 +1309,9 @@
1454 1309
1455 1310 $hours = filter_input(
1456 1311 INPUT_POST,
1457 1312 'refresh',
1458 - FILTER_VALIDATE_FLOAT,
1313 + FILTER_VALIDATE_INT,
1459 1314 array(
1460 1315 'options' => array(
1461 1316 'min_range' => -1,
1462 1317 'max_range' => apply_filters( 'visualizer_is_business', false ) ? PHP_INT_MAX : -1,
@@ -1463,9 +1318,9 @@
1463 1318 ),
1464 1319 )
1465 1320 );
1466 1321
1467 - if ( ! is_numeric( $hours ) ) {
1322 + if ( ! is_int( $hours ) ) {
1468 1323 $hours = -1;
1469 1324 }
1470 1325
1471 1326 $render = new Visualizer_Render_Page_Update();
@@ -1493,12 +1348,12 @@
1493 1348
1494 1349 wp_update_post(
1495 1350 array(
1496 1351 'ID' => $chart_id,
1497 - 'post_content' => $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ),
1352 + 'post_content' => $source->getData(),
1498 1353 )
1499 1354 );
1500 - $render->data = json_encode( $source->getRawData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) );
1355 + $render->data = json_encode( $source->getRawData() );
1501 1356 $render->series = json_encode( $source->getSeries() );
1502 1357 $render->id = $chart_id;
1503 1358 } else {
1504 1359 $render->message = $error;
@@ -1541,9 +1396,9 @@
1541 1396 ),
1542 1397 )
1543 1398 );
1544 1399
1545 - if ( 0 !== $hours && empty( $hours ) ) {
1400 + if ( ! $hours ) {
1546 1401 $hours = -1;
1547 1402 }
1548 1403
1549 1404 do_action( 'visualizer_save_filter', $chart_id, $hours );
@@ -1550,55 +1405,6 @@
1550 1405
1551 1406 if ( ! ( defined( 'VISUALIZER_DO_NOT_DIE' ) && VISUALIZER_DO_NOT_DIE ) ) {
1552 1407 defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
1553 1408 }
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 1409 }
1604 1410 }