| @@ -56,9 +56,11 @@ | ||
| 56 | 56 | $this->_addAjaxAction( Visualizer_Plugin::ACTION_CREATE_CHART, 'renderChartPages' ); |
| 57 | 57 | $this->_addAjaxAction( Visualizer_Plugin::ACTION_EDIT_CHART, 'renderChartPages' ); |
| 58 | 58 | $this->_addAjaxAction( Visualizer_Plugin::ACTION_UPLOAD_DATA, 'uploadData' ); |
| 59 | 59 | $this->_addAjaxAction( Visualizer_Plugin::ACTION_CLONE_CHART, 'cloneChart' ); |
| 60 | + // Added by Ash/Upwork | |
| 60 | 61 | $this->_addAjaxAction( Visualizer_Plugin::ACTION_EXPORT_DATA, 'exportData' ); |
| 62 | + // Added by Ash/Upwork | |
| 61 | 63 | } |
| 62 | 64 | |
| 63 | 65 | /** |
| 64 | 66 | * Fetches charts from database. |
| @@ -80,13 +82,8 @@ | ||
| 80 | 82 | ) |
| 81 | 83 | ), |
| 82 | 84 | ); |
| 83 | 85 | $filter = filter_input( INPUT_GET, 's', FILTER_SANITIZE_STRING ); |
| 84 | - if ( empty( $filter ) ) { | |
| 85 | - // 'filter' is from the modal from the add media button. | |
| 86 | - $filter = filter_input( INPUT_GET, 'filter', FILTER_SANITIZE_STRING ); | |
| 87 | - } | |
| 88 | - | |
| 89 | 86 | if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes() ) ) { |
| 90 | 87 | $query_args['meta_query'] = array( |
| 91 | 88 | array( |
| 92 | 89 | 'key' => Visualizer_Plugin::CF_CHART_TYPE, |
| @@ -208,9 +205,9 @@ | ||
| 208 | 205 | defined( 'IFRAME_REQUEST' ) || define( 'IFRAME_REQUEST', 1 ); |
| 209 | 206 | // check chart, if chart not exists, will create new one and redirects to the same page with proper chart id |
| 210 | 207 | $chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : ''; |
| 211 | 208 | if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) { |
| 212 | - $default_type = isset( $_GET['type'] ) && ! empty( $_GET['type'] ) ? $_GET['type'] : 'line'; | |
| 209 | + $default_type = 'line'; | |
| 213 | 210 | $source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $default_type . '.csv' ); |
| 214 | 211 | $source->fetch(); |
| 215 | 212 | $chart_id = wp_insert_post( |
| 216 | 213 | array( |
| @@ -264,27 +261,11 @@ | ||
| 264 | 261 | } |
| 265 | 262 | // dispatch pages |
| 266 | 263 | $this->_chart = get_post( $chart_id ); |
| 267 | 264 | $tab = isset( $_GET['tab'] ) && ! empty( $_GET['tab'] ) ? $_GET['tab'] : 'visualizer'; |
| 268 | - | |
| 269 | - // skip chart type pages only for existing charts. | |
| 270 | - if ( VISUALIZER_SKIP_CHART_TYPE_PAGE && 'auto-draft' !== $this->_chart->post_status && ( ! empty( $_GET['tab'] ) && 'visualizer' === $_GET['tab'] ) ) { | |
| 271 | - $tab = 'settings'; | |
| 272 | - } | |
| 273 | - | |
| 274 | - if ( isset( $_POST['cancel'] ) && 1 === intval( $_POST['cancel'] ) ) { | |
| 275 | - // if the cancel button is clicked. | |
| 276 | - $this->undoRevisions( $chart_id, true ); | |
| 277 | - } elseif ( isset( $_POST['save'] ) && 1 === intval( $_POST['save'] ) ) { | |
| 278 | - // if the save button is clicked. | |
| 279 | - $this->undoRevisions( $chart_id, false ); | |
| 280 | - } else { | |
| 281 | - // if the edit button is clicked. | |
| 282 | - $this->_chart = $this->handleExistingRevisions( $chart_id, $this->_chart ); | |
| 283 | - } | |
| 284 | - | |
| 285 | 265 | switch ( $tab ) { |
| 286 | 266 | case 'settings': |
| 267 | + // changed by Ash/Upwork | |
| 287 | 268 | $this->_handleDataAndSettingsPage(); |
| 288 | 269 | break; |
| 289 | 270 | case 'type': // fall through. |
| 290 | 271 | case 'visualizer': // fall through. |
| @@ -344,9 +325,8 @@ | ||
| 344 | 325 | ), |
| 345 | 326 | 'charts' => array( |
| 346 | 327 | 'canvas' => $data, |
| 347 | 328 | ), |
| 348 | - 'language' => $this->get_language(), | |
| 349 | 329 | 'map_api_key' => get_option( 'visualizer-map-api-key' ), |
| 350 | 330 | 'ajax' => array( |
| 351 | 331 | 'url' => admin_url( 'admin-ajax.php' ), |
| 352 | 332 | 'nonces' => array( |
| @@ -365,11 +345,8 @@ | ||
| 365 | 345 | if ( filter_input( INPUT_GET, 'library', FILTER_VALIDATE_BOOLEAN ) ) { |
| 366 | 346 | $render->button = filter_input( INPUT_GET, 'action' ) == Visualizer_Plugin::ACTION_EDIT_CHART |
| 367 | 347 | ? esc_html__( 'Save Chart', 'visualizer' ) |
| 368 | 348 | : esc_html__( 'Create Chart', 'visualizer' ); |
| 369 | - if ( filter_input( INPUT_GET, 'action' ) == Visualizer_Plugin::ACTION_EDIT_CHART ) { | |
| 370 | - $render->cancel_button = esc_html__( 'Cancel', 'visualizer' ); | |
| 371 | - } | |
| 372 | 349 | } else { |
| 373 | 350 | $render->button = esc_attr__( 'Insert Chart', 'visualizer' ); |
| 374 | 351 | } |
| 375 | 352 | if ( VISUALIZER_PRO ) { |
| @@ -437,32 +414,20 @@ | ||
| 437 | 414 | * |
| 438 | 415 | * @access public |
| 439 | 416 | */ |
| 440 | 417 | public function uploadData() { |
| 441 | - // if this is being called internally from pro and VISUALIZER_DO_NOT_DIE is set. | |
| 442 | - // otherwise, assume this is a normal web request. | |
| 443 | - $can_die = ! ( defined( 'VISUALIZER_DO_NOT_DIE' ) && VISUALIZER_DO_NOT_DIE ); | |
| 444 | - | |
| 445 | 418 | // validate nonce |
| 419 | + // do not use filter_input as it does not work for phpunit test cases, use filter_var instead | |
| 446 | 420 | if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'] ) ) { |
| 447 | - if ( ! $can_die ) { | |
| 448 | - return; | |
| 449 | - } | |
| 450 | 421 | status_header( 403 ); |
| 451 | 422 | exit; |
| 452 | 423 | } |
| 453 | - | |
| 454 | 424 | // check chart, if chart exists |
| 455 | - // do not use filter_input as it does not work for phpunit test cases, use filter_var instead | |
| 456 | 425 | $chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : ''; |
| 457 | 426 | if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) { |
| 458 | - if ( ! $can_die ) { | |
| 459 | - return; | |
| 460 | - } | |
| 461 | 427 | status_header( 400 ); |
| 462 | 428 | exit; |
| 463 | 429 | } |
| 464 | - | |
| 465 | 430 | if ( ! isset( $_POST['vz-import-time'] ) ) { |
| 466 | 431 | apply_filters( 'visualizer_pro_remove_schedule', $chart_id ); |
| 467 | 432 | } |
| 468 | 433 | |
| @@ -479,10 +444,12 @@ | ||
| 479 | 444 | apply_filters( 'visualizer_pro_chart_schedule', $chart_id, $_POST['remote_data'], $_POST['vz-import-time'] ); |
| 480 | 445 | } |
| 481 | 446 | } elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) { |
| 482 | 447 | $source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] ); |
| 448 | + // Added by Ash/Upwork | |
| 483 | 449 | } elseif ( isset( $_POST['chart_data'] ) && strlen( $_POST['chart_data'] ) > 0 ) { |
| 484 | 450 | $source = apply_filters( 'visualizer_pro_handle_chart_data', $_POST['chart_data'], '' ); |
| 451 | + // Added by Ash/Upwork | |
| 485 | 452 | } else { |
| 486 | 453 | $render->message = esc_html__( 'CSV file with chart data was not uploaded. Please, try again.', 'visualizer' ); |
| 487 | 454 | } |
| 488 | 455 | if ( $source ) { |
| @@ -498,12 +465,11 @@ | ||
| 498 | 465 | $render->message = esc_html__( 'CSV file is broken or invalid. Please, try again.', 'visualizer' ); |
| 499 | 466 | } |
| 500 | 467 | } |
| 501 | 468 | $render->render(); |
| 502 | - if ( ! $can_die ) { | |
| 503 | - return; | |
| 469 | + if ( ! ( defined( 'VISUALIZER_DO_NOT_DIE' ) && VISUALIZER_DO_NOT_DIE ) ) { | |
| 470 | + defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit(); | |
| 504 | 471 | } |
| 505 | - defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit(); | |
| 506 | 472 | } |
| 507 | 473 | |
| 508 | 474 | /** |
| 509 | 475 | * Clones the chart. |
| @@ -621,6 +587,5 @@ | ||
| 621 | 587 | // Added by Ash/Upwork |
| 622 | 588 | $this->_addAction( 'admin_head', 'renderFlattrScript' ); |
| 623 | 589 | wp_iframe( array( $render, 'render' ) ); |
| 624 | 590 | } |
| 625 | - | |
| 626 | 591 | } |