PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 2.0.3
Visualizer – Tables & Charts Manager with Built-in AI Generator v2.0.3
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
visualizer / classes / Visualizer / Module / Chart.php

Chart.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 2.0.3, at classes/Visualizer/Module/Chart.php

589 lines 20.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // +----------------------------------------------------------------------+
3 // | Copyright 2013 Madpixels (email : visualizer@madpixels.net) |
4 // +----------------------------------------------------------------------+
5 // | This program is free software; you can redistribute it and/or modify |
6 // | it under the terms of the GNU General Public License, version 2, as |
7 // | published by the Free Software Foundation. |
8 // | |
9 // | This program is distributed in the hope that it will be useful, |
10 // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 // | GNU General Public License for more details. |
13 // | |
14 // | You should have received a copy of the GNU General Public License |
15 // | along with this program; if not, write to the Free Software |
16 // | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
17 // | MA 02110-1301 USA |
18 // +----------------------------------------------------------------------+
19 // | Author: Eugene Manuilov <eugene@manuilov.org> |
20 // +----------------------------------------------------------------------+
21 /**
22 * The module for all stuff related to getting, editing, creating and deleting charts.
23 *
24 * @category Visualizer
25 * @package Module
26 *
27 * @since 1.0.0
28 */
29 class Visualizer_Module_Chart extends Visualizer_Module {
30
31 const NAME = __CLASS__;
32
33 /**
34 * The chart object.
35 *
36 * @since 1.0.0
37 *
38 * @access private
39 * @var WP_Post
40 */
41 private $_chart;
42
43 /**
44 * Constructor.
45 *
46 * @since 1.0.0
47 *
48 * @access public
49 *
50 * @param Visualizer_Plugin $plugin The instance of the plugin.
51 */
52 public function __construct( Visualizer_Plugin $plugin ) {
53 parent::__construct( $plugin );
54 $this->_addAjaxAction( Visualizer_Plugin::ACTION_GET_CHARTS, 'getCharts' );
55 $this->_addAjaxAction( Visualizer_Plugin::ACTION_DELETE_CHART, 'deleteChart' );
56 $this->_addAjaxAction( Visualizer_Plugin::ACTION_CREATE_CHART, 'renderChartPages' );
57 $this->_addAjaxAction( Visualizer_Plugin::ACTION_EDIT_CHART, 'renderChartPages' );
58 $this->_addAjaxAction( Visualizer_Plugin::ACTION_UPLOAD_DATA, 'uploadData' );
59 $this->_addAjaxAction( Visualizer_Plugin::ACTION_CLONE_CHART, 'cloneChart' );
60 // Added by Ash/Upwork
61 $this->_addAjaxAction( Visualizer_Plugin::ACTION_EXPORT_DATA, 'exportData' );
62 // Added by Ash/Upwork
63 }
64
65 /**
66 * Fetches charts from database.
67 *
68 * @since 1.0.0
69 *
70 * @access public
71 */
72 public function getCharts() {
73 $query_args = array(
74 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
75 'posts_per_page' => 9,
76 'paged' => filter_input( INPUT_GET, 'page', FILTER_VALIDATE_INT, array(
77 'options' => array(
78 'min_range' => 1,
79 'default' => 1,
80 ),
81 ) ),
82 );
83 $filter = filter_input( INPUT_GET, 's', FILTER_SANITIZE_STRING );
84 if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes() ) ) {
85 $query_args['meta_query'] = array(
86 array(
87 'key' => Visualizer_Plugin::CF_CHART_TYPE,
88 'value' => $filter,
89 'compare' => '=',
90 ),
91 );
92 }
93 $query = new WP_Query( $query_args );
94 $charts = array();
95 while ( $query->have_posts() ) {
96 $chart = $query->next_post();
97 $chart_data = $this->_getChartArray( $chart );
98 $chart_data['id'] = $chart->ID;
99 $charts[] = $chart_data;
100 }
101 self::_sendResponse( array(
102 'success' => true,
103 'data' => $charts,
104 'total' => $query->max_num_pages,
105 ) );
106 }
107
108 /**
109 * Returns chart data required for rendering.
110 *
111 * @since 1.0.0
112 *
113 * @access private
114 *
115 * @param WP_Post $chart The chart object.
116 *
117 * @return array The array of chart data.
118 */
119 private function _getChartArray( WP_Post $chart = null ) {
120 if ( is_null( $chart ) ) {
121 $chart = $this->_chart;
122 }
123 $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
124 $series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type );
125 $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( $chart->post_content ), $chart->ID, $type );
126
127 return array(
128 'type' => $type,
129 'series' => $series,
130 'settings' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true ),
131 'data' => $data,
132 );
133 }
134
135 /**
136 * Sends json response.
137 *
138 * @since 1.0.0
139 *
140 * @access private
141 *
142 * @param array $results The response array.
143 */
144 public static function _sendResponse( $results ) {
145 header( 'Content-type: application/json' );
146 nocache_headers();
147 echo json_encode( $results );
148 defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
149 }
150
151 /**
152 * Deletes a chart from database.
153 *
154 * @since 1.0.0
155 * @uses wp_delete_post() To delete a chart.
156 *
157 * @access public
158 */
159 public function deleteChart() {
160 $is_post = $_SERVER['REQUEST_METHOD'] == 'POST';
161 $input_method = $is_post ? INPUT_POST : INPUT_GET;
162 $chart_id = $success = false;
163 $nonce = wp_verify_nonce( filter_input( $input_method, 'nonce' ) );
164 $capable = current_user_can( 'delete_posts' );
165 if ( $nonce && $capable ) {
166 $chart_id = filter_input( $input_method, 'chart', FILTER_VALIDATE_INT, array(
167 'options' => array(
168 'min_range' => 1,
169 ),
170 ) );
171 if ( $chart_id ) {
172 $chart = get_post( $chart_id );
173 $success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
174 }
175 }
176 if ( $success ) {
177 wp_delete_post( $chart_id, true );
178 }
179 if ( $is_post ) {
180 self::_sendResponse( array(
181 'success' => $success,
182 ) );
183 }
184 wp_redirect( wp_get_referer() );
185 exit;
186 }
187
188 /**
189 * Renders appropriate page for chart builder. Creates new auto draft chart
190 * if no chart has been specified.
191 *
192 * @since 1.0.0
193 *
194 * @access public
195 */
196 public function renderChartPages() {
197 defined( 'IFRAME_REQUEST' ) || define( 'IFRAME_REQUEST', 1 );
198 // check chart, if chart not exists, will create new one and redirects to the same page with proper chart id
199 $chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : '';
200 if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
201 $default_type = 'line';
202 $source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $default_type . '.csv' );
203 $source->fetch();
204 $chart_id = wp_insert_post( array(
205 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
206 'post_title' => 'Visualization',
207 'post_author' => get_current_user_id(),
208 'post_status' => 'auto-draft',
209 'post_content' => $source->getData(),
210 ) );
211 if ( $chart_id && ! is_wp_error( $chart_id ) ) {
212 add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, $default_type );
213 add_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 1 );
214 add_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
215 add_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
216 add_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, array(
217 'focusTarget' => 'datum',
218 ) );
219 }
220 wp_redirect( add_query_arg( 'chart', (int) $chart_id ) );
221 defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
222 }
223 // enqueue and register scripts and styles
224 wp_register_style( 'visualizer-frame', VISUALIZER_ABSURL . 'css/frame.css', array(), Visualizer_Plugin::VERSION );
225 wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'jquery' ), Visualizer_Plugin::VERSION, true );
226 wp_register_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true );
227 wp_register_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true );
228 wp_register_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array(
229 'google-jsapi-old',
230 'google-jsapi-new',
231 'visualizer-frame',
232 ), Visualizer_Plugin::VERSION, true );
233 wp_register_script( 'visualizer-preview', VISUALIZER_ABSURL . 'js/preview.js', array(
234 'wp-color-picker',
235 'visualizer-render',
236 ), Visualizer_Plugin::VERSION, true );
237 // added by Ash/Upwork
238 if ( VISUALIZER_PRO ) {
239 global $Visualizer_Pro;
240 $Visualizer_Pro->_addScriptsAndStyles();
241 }
242 // dispatch pages
243 $this->_chart = get_post( $chart_id );
244 switch ( isset( $_GET['tab'] ) ? $_GET['tab'] : '' ) {
245 case 'settings':
246 // changed by Ash/Upwork
247 $this->_handleDataAndSettingsPage();
248 break;
249 case 'type':
250 default:
251 $this->_handleTypesPage();
252 break;
253 }
254 defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
255 }
256
257 /**
258 * Handle data and settings page
259 */
260 private function _handleDataAndSettingsPage() {
261 if ( $_SERVER['REQUEST_METHOD'] == 'POST' && isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'] ) ) {
262 if ( $this->_chart->post_status == 'auto-draft' ) {
263 $this->_chart->post_status = 'publish';
264 wp_update_post( $this->_chart->to_array() );
265 }
266 update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, $_POST );
267 $render = new Visualizer_Render_Page_Send();
268 $render->text = sprintf( '[visualizer id="%d"]', $this->_chart->ID );
269 wp_iframe( array( $render, 'render' ) );
270
271 return;
272 }
273 $data = $this->_getChartArray();
274 $sidebar = '';
275 $sidebar_class = 'Visualizer_Render_Sidebar_Type_' . ucfirst( $data['type'] );
276 if ( class_exists( $sidebar_class, true ) ) {
277 $sidebar = new $sidebar_class( $data['settings'] );
278 $sidebar->__series = $data['series'];
279 $sidebar->__data = $data['data'];
280 } else {
281 $sidebar = apply_filters( 'visualizer_pro_chart_type_sidebar', '', $data );
282 if ( $sidebar != '' ) {
283 $sidebar->__series = $data['series'];
284 $sidebar->__data = $data['data'];
285 }
286 }
287 unset( $data['settings']['width'], $data['settings']['height'] );
288 wp_enqueue_style( 'visualizer-frame' );
289 wp_enqueue_style( 'wp-color-picker' );
290 wp_enqueue_style( 'visualizer-frame' );
291 wp_enqueue_script( 'visualizer-preview' );
292 wp_enqueue_script( 'visualizer-render' );
293 wp_localize_script( 'visualizer-render', 'visualizer', array(
294 'l10n' => array(
295 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ),
296 ),
297 'charts' => array(
298 'canvas' => $data,
299 ),
300 ) );
301 $render = new Visualizer_Render_Page_Data();
302 $render->chart = $this->_chart;
303 $render->type = $data['type'];
304 $render->sidebar = $sidebar;
305 if ( filter_input( INPUT_GET, 'library', FILTER_VALIDATE_BOOLEAN ) ) {
306 $render->button = filter_input( INPUT_GET, 'action' ) == Visualizer_Plugin::ACTION_EDIT_CHART
307 ? esc_html__( 'Save Chart', 'visualizer' )
308 : esc_html__( 'Create Chart', 'visualizer' );
309 } else {
310 $render->button = esc_attr__( 'Insert Chart', 'visualizer' );
311 }
312 if ( VISUALIZER_PRO ) {
313 global $Visualizer_Pro;
314 $Visualizer_Pro->_enqueueScriptsAndStyles( $data );
315 }
316 $this->_addAction( 'admin_head', 'renderFlattrScript' );
317 wp_iframe( array( $render, 'render' ) );
318 }
319
320 /**
321 * Handles chart type selection page.
322 *
323 * @since 1.0.0
324 *
325 * @access private
326 */
327 private function _handleTypesPage() {
328 // process post request
329 if ( $_SERVER['REQUEST_METHOD'] == 'POST' && wp_verify_nonce( filter_input( INPUT_POST, 'nonce' ) ) ) {
330 $type = filter_input( INPUT_POST, 'type' );
331 if ( in_array( $type, Visualizer_Plugin::getChartTypes() ) ) {
332 // save new chart type
333 update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_CHART_TYPE, $type );
334 // if the chart has default data, update it with appropriate default data for new type
335 if ( filter_var( get_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, true ), FILTER_VALIDATE_BOOLEAN ) ) {
336 $source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $type . '.csv' );
337 $source->fetch();
338 $this->_chart->post_content = $source->getData();
339 wp_update_post( $this->_chart->to_array() );
340 update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
341 }
342 // redirect to next tab
343 // changed by Ash/Upwork
344 wp_redirect( add_query_arg( 'tab', 'settings' ) );
345
346 return;
347 }
348 }
349 $render = new Visualizer_Render_Page_Types();
350 $render->type = get_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
351 $render->types = Visualizer_Module_Admin::_getChartTypesLocalized();
352 $render->chart = $this->_chart;
353 wp_enqueue_style( 'visualizer-frame' );
354 wp_enqueue_script( 'visualizer-frame' );
355 wp_iframe( array( $render, 'render' ) );
356 }
357
358 /**
359 * Renders flattr script in the iframe <head>
360 *
361 * @since 1.4.2
362 * @action admin_head
363 *
364 * @access public
365 */
366 public function renderFlattrScript() {
367 echo '';
368 }
369 // changed by Ash/Upwork
370 /**
371 * Parses uploaded CSV file and saves new data for the chart.
372 *
373 * @since 1.0.0
374 *
375 * @access public
376 */
377 public function uploadData() {
378 // validate nonce
379 // do not use filter_input as it does not work for phpunit test cases, use filter_var instead
380 if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'] ) ) {
381 status_header( 403 );
382 exit;
383 }
384 // check chart, if chart exists
385 $chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : '';
386 if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
387 status_header( 400 );
388 exit;
389 }
390 if ( ! isset( $_POST['vz-import-time'] ) ) {
391 apply_filters( 'visualizer_pro_remove_schedule', $chart_id );
392 }
393 $source = null;
394 $render = new Visualizer_Render_Page_Update();
395 if ( isset( $_POST['remote_data'] ) && filter_var( $_POST['remote_data'], FILTER_VALIDATE_URL ) ) {
396 $source = new Visualizer_Source_Csv_Remote( $_POST['remote_data'] );
397 if ( isset( $_POST['vz-import-time'] ) ) {
398 apply_filters( 'visualizer_pro_chart_schedule', $chart_id, $_POST['remote_data'], $_POST['vz-import-time'] );
399 }
400 } elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) {
401 $source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] );
402 // Added by Ash/Upwork
403 } elseif ( isset( $_POST['chart_data'] ) && strlen( $_POST['chart_data'] ) > 0 ) {
404 $source = apply_filters( 'visualizer_pro_handle_chart_data', $_POST['chart_data'], '' );
405 // Added by Ash/Upwork
406 } else {
407 $render->message = esc_html__( 'CSV file with chart data was not uploaded. Please, try again.', 'visualizer' );
408 }
409 if ( $source ) {
410 if ( $source->fetch() ) {
411 $chart->post_content = $source->getData();
412 wp_update_post( $chart->to_array() );
413 update_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
414 update_post_meta( $chart->ID, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
415 update_post_meta( $chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, 0 );
416 $render->data = json_encode( $source->getRawData() );
417 $render->series = json_encode( $source->getSeries() );
418 } else {
419 $render->message = esc_html__( 'CSV file is broken or invalid. Please, try again.', 'visualizer' );
420 }
421 }
422 $render->render();
423 defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
424 }
425
426 /**
427 * Clones the chart.
428 *
429 * @since 1.0.0
430 *
431 * @access public
432 */
433 public function cloneChart() {
434 $chart_id = $success = false;
435 $nonce = wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ), Visualizer_Plugin::ACTION_CLONE_CHART );
436 $capable = current_user_can( 'edit_posts' );
437 if ( $nonce && $capable ) {
438 $chart_id = filter_input( INPUT_GET, 'chart', FILTER_VALIDATE_INT, array(
439 'options' => array(
440 'min_range' => 1,
441 ),
442 ) );
443 if ( $chart_id ) {
444 $chart = get_post( $chart_id );
445 $success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
446 }
447 }
448 $redirect = wp_get_referer();
449 if ( $success ) {
450 $new_chart_id = wp_insert_post( array(
451 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
452 'post_title' => 'Visualization',
453 'post_author' => get_current_user_id(),
454 'post_status' => $chart->post_status,
455 'post_content' => $chart->post_content,
456 ) );
457 if ( $new_chart_id && ! is_wp_error( $new_chart_id ) ) {
458 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_CHART_TYPE, get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true ) );
459 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, get_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, true ) );
460 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SOURCE, get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) );
461 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SERIES, get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true ) );
462 add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SETTINGS, get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true ) );
463 $redirect = add_query_arg( array(
464 'page' => 'visualizer',
465 'type' => filter_input( INPUT_GET, 'type' ),
466 ), admin_url( 'upload.php' ) );
467 }
468 }
469 wp_redirect( $redirect );
470 exit;
471 }
472
473 /**
474 * Exports the chart data
475 *
476 * @since 1.0.0
477 *
478 * @access public
479 */
480 public function exportData() {
481 check_ajax_referer( Visualizer_Plugin::ACTION_EXPORT_DATA . Visualizer_Plugin::VERSION, 'security' );
482 $chart_id = $success = false;
483 $capable = current_user_can( 'edit_posts' );
484 if ( $capable ) {
485 $chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT, array(
486 'options' => array(
487 'min_range' => 1,
488 ),
489 ) ) : '';
490 if ( $chart_id ) {
491 $chart = get_post( $chart_id );
492 $success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
493 }
494 }
495 if ( $success ) {
496 $settings = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true );
497 $filename = isset( $settings['title'] ) ? $settings['title'] : '';
498 if ( empty( $filename ) ) {
499 $filename = 'export.csv';
500 } else {
501 $filename .= '.csv';
502 }
503 $rows = array();
504 $series = get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true );
505 $data = unserialize( $chart->post_content );
506 if ( ! empty( $series ) ) {
507 $row = array();
508 foreach ( $series as $array ) {
509 $row[] = $array['label'];
510 }
511 $rows[] = $row;
512 $row = array();
513 foreach ( $series as $array ) {
514 $row[] = $array['type'];
515 }
516 $rows[] = $row;
517 }
518 if ( ! empty( $data ) ) {
519 foreach ( $data as $array ) {
520 // ignore strings
521 if ( ! is_array( $array ) ) {
522 continue;
523 }
524 // if this is an array of arrays...
525 if ( is_array( $array[0] ) ) {
526 foreach ( $array as $arr ) {
527 $rows[] = $arr;
528 }
529 } else {
530 // just an array
531 $rows[] = $array;
532 }
533 }
534 }
535 $fp = tmpfile();
536 foreach ( $rows as $row ) {
537 fputcsv( $fp, $row );
538 }
539 rewind( $fp );
540 $csv = '';
541 while ( ( $array = fgetcsv( $fp ) ) !== false ) {
542 if ( strlen( $csv ) > 0 ) {
543 $csv .= PHP_EOL;
544 }
545 $csv .= implode( ',', $array );
546 }
547 fclose( $fp );
548 echo wp_send_json_success( array(
549 'csv' => $csv,
550 'name' => $filename,
551 ) );
552 }// End if().
553 defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
554 }
555
556 /**
557 * Handles chart data page.
558 *
559 * @since 1.0.0
560 *
561 * @access private
562 */
563 private function _handleDataPage() {
564 $data = $this->_getChartArray();
565 $render = new Visualizer_Render_Page_Data();
566 $render->chart = $this->_chart;
567 $render->type = $data['type'];
568 unset( $data['settings']['width'], $data['settings']['height'] );
569 wp_enqueue_style( 'visualizer-frame' );
570 wp_enqueue_script( 'visualizer-render' );
571 wp_localize_script( 'visualizer-render', 'visualizer', array(
572 'l10n' => array(
573 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ),
574 ),
575 'charts' => array(
576 'canvas' => $data,
577 ),
578 ) );
579 // Added by Ash/Upwork
580 if ( VISUALIZER_PRO ) {
581 global $Visualizer_Pro;
582 $Visualizer_Pro->_enqueueScriptsAndStyles( $data );
583 }
584 // Added by Ash/Upwork
585 $this->_addAction( 'admin_head', 'renderFlattrScript' );
586 wp_iframe( array( $render, 'render' ) );
587 }
588 }
589