PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.1.3
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.1.3
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 +66 -2 3.1.23.1.3 View file →
@@ -60,8 +60,9 @@
60 60 $this->_addAjaxAction( Visualizer_Plugin::ACTION_EXPORT_DATA, 'exportData' );
61 61
62 62 $this->_addAjaxAction( Visualizer_Plugin::ACTION_FETCH_DB_DATA, 'getQueryData' );
63 63 $this->_addAjaxAction( Visualizer_Plugin::ACTION_SAVE_DB_QUERY, 'saveQuery' );
64 + $this->_addAjaxAction( Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY, 'saveFilter' );
64 65 }
65 66
66 67 /**
67 68 * Fetches charts from database.
@@ -162,8 +163,10 @@
162 163 $css = $arguments[0];
163 164 $settings = $arguments[1];
164 165 }
165 166
167 + $date_formats = Visualizer_Source::get_date_formats_if_exists( $series, $data );
168 +
166 169 return array(
167 170 'type' => $type,
168 171 'series' => $series,
169 172 'settings' => $settings,
@@ -169,8 +172,9 @@
169 172 'settings' => $settings,
170 173 'data' => $data,
171 174 'library' => $library,
172 175 'css' => $css,
176 + 'date_formats' => $date_formats,
173 177 );
174 178 }
175 179
176 180 /**
@@ -233,8 +237,36 @@
233 237 exit;
234 238 }
235 239
236 240 /**
241 + * Delete charts that are still in auto-draft mode.
242 + */
243 + private function deleteOldCharts() {
244 + $query = new WP_Query(
245 + array(
246 + 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
247 + 'post_status' => 'auto-draft',
248 + 'fields' => 'ids',
249 + 'update_post_meta_cache' => false,
250 + 'update_post_term_cache' => false,
251 + 'posts_per_page' => 50,
252 + 'date_query' => array(
253 + array(
254 + 'before' => 'today',
255 + ),
256 + ),
257 + )
258 + );
259 +
260 + if ( $query->have_posts() ) {
261 + $ids = array();
262 + while ( $query->have_posts() ) {
263 + wp_delete_post( $query->next_post(), true );
264 + }
265 + }
266 + }
267 +
268 + /**
237 269 * Renders appropriate page for chart builder. Creates new auto draft chart
238 270 * if no chart has been specified.
239 271 *
240 272 * @since 1.0.0
@@ -245,8 +277,9 @@
245 277 defined( 'IFRAME_REQUEST' ) || define( 'IFRAME_REQUEST', 1 );
246 278 // check chart, if chart not exists, will create new one and redirects to the same page with proper chart id
247 279 $chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : '';
248 280 if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
281 + $this->deleteOldCharts();
249 282 $default_type = isset( $_GET['type'] ) && ! empty( $_GET['type'] ) ? $_GET['type'] : 'line';
250 283 $source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $default_type . '.csv' );
251 284 $source->fetch();
252 285 $chart_id = wp_insert_post(
@@ -588,9 +621,11 @@
588 621 }
589 622
590 623 if ( ! isset( $_POST['chart_data_src'] ) || Visualizer_Plugin::CF_SOURCE_FILTER !== $_POST['chart_data_src'] ) {
591 624 // delete the filters in case this chart is being uploaded from other data sources
592 - delete_post_meta( $chart_id, 'visualizer-filter-config' );
625 + delete_post_meta( $chart_id, Visualizer_Plugin::CF_FILTER_CONFIG );
626 + delete_post_meta( $chart_id, '__transient-' . Visualizer_Plugin::CF_FILTER_CONFIG );
627 + delete_post_meta( $chart_id, '__transient-' . Visualizer_Plugin::CF_DB_QUERY );
593 628
594 629 // delete "import from db" specific parameters.
595 630 delete_post_meta( $chart_id, Visualizer_Plugin::CF_DB_QUERY );
596 631 delete_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE );
@@ -605,9 +640,9 @@
605 640 }
606 641 } elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) {
607 642 $source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] );
608 643 } elseif ( isset( $_POST['chart_data'] ) && strlen( $_POST['chart_data'] ) > 0 ) {
609 - $source = apply_filters( 'visualizer_pro_handle_chart_data', $_POST['chart_data'], '' );
644 + $source = apply_filters( 'visualizer_pro_handle_chart_data', $_POST['chart_data'], '', $chart_id, $_POST );
610 645 } else {
611 646 $render->message = esc_html__( 'CSV file with chart data was not uploaded. Please, try again.', 'visualizer' );
612 647 }
613 648 if ( $source ) {
@@ -838,8 +873,37 @@
838 873 $render->message = $error;
839 874 }
840 875 }
841 876 $render->render();
877 + if ( ! ( defined( 'VISUALIZER_DO_NOT_DIE' ) && VISUALIZER_DO_NOT_DIE ) ) {
878 + defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
879 + }
880 + }
881 +
882 +
883 + /**
884 + * Saves the filter query and the schedule.
885 + *
886 + * @access public
887 + */
888 + public function saveFilter() {
889 + check_ajax_referer( Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY . Visualizer_Plugin::VERSION, 'security' );
890 +
891 + $chart_id = filter_input(
892 + INPUT_GET,
893 + 'chart',
894 + FILTER_VALIDATE_INT,
895 + array(
896 + 'options' => array(
897 + 'min_range' => 1,
898 + ),
899 + )
900 + );
901 +
902 + $hours = $_POST['refresh'];
903 +
904 + do_action( 'visualizer_save_filter', $chart_id, $hours );
905 +
842 906 if ( ! ( defined( 'VISUALIZER_DO_NOT_DIE' ) && VISUALIZER_DO_NOT_DIE ) ) {
843 907 defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
844 908 }
845 909 }