| @@ -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( |
| @@ -230,19 +227,15 @@ | ||
| 230 | 227 | $chart_id, Visualizer_Plugin::CF_SETTINGS, array( |
| 231 | 228 | 'focusTarget' => 'datum', |
| 232 | 229 | ) |
| 233 | 230 | ); |
| 234 | - do_action( 'visualizer_pro_new_chart_defaults', $chart_id ); | |
| 235 | 231 | } |
| 236 | 232 | wp_redirect( add_query_arg( 'chart', (int) $chart_id ) ); |
| 237 | 233 | defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit(); |
| 238 | 234 | } |
| 239 | 235 | // enqueue and register scripts and styles |
| 240 | - wp_register_script( 'visualizer-chosen', VISUALIZER_ABSURL . 'js/lib/chosen.jquery.min.js', array( 'jquery' ), Visualizer_Plugin::VERSION ); | |
| 241 | - wp_register_style( 'visualizer-chosen', VISUALIZER_ABSURL . 'css/lib/chosen.min.css', array(), Visualizer_Plugin::VERSION ); | |
| 242 | - | |
| 243 | - wp_register_style( 'visualizer-frame', VISUALIZER_ABSURL . 'css/frame.css', array( 'visualizer-chosen' ), Visualizer_Plugin::VERSION ); | |
| 244 | - wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'visualizer-chosen' ), Visualizer_Plugin::VERSION, true ); | |
| 236 | + wp_register_style( 'visualizer-frame', VISUALIZER_ABSURL . 'css/frame.css', array(), Visualizer_Plugin::VERSION ); | |
| 237 | + wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'jquery' ), Visualizer_Plugin::VERSION, true ); | |
| 245 | 238 | wp_register_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true ); |
| 246 | 239 | wp_register_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true ); |
| 247 | 240 | wp_register_script( |
| 248 | 241 | 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( |
| @@ -263,37 +256,17 @@ | ||
| 263 | 256 | $Visualizer_Pro->_addScriptsAndStyles(); |
| 264 | 257 | } |
| 265 | 258 | // dispatch pages |
| 266 | 259 | $this->_chart = get_post( $chart_id ); |
| 267 | - $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 | - switch ( $tab ) { | |
| 260 | + switch ( isset( $_GET['tab'] ) ? $_GET['tab'] : '' ) { | |
| 286 | 261 | case 'settings': |
| 262 | + // changed by Ash/Upwork | |
| 287 | 263 | $this->_handleDataAndSettingsPage(); |
| 288 | 264 | break; |
| 289 | - case 'type': // fall through. | |
| 290 | - case 'visualizer': // fall through. | |
| 265 | + case 'type': | |
| 266 | + default: | |
| 291 | 267 | $this->_handleTypesPage(); |
| 292 | 268 | break; |
| 293 | - default: | |
| 294 | - do_action( 'visualizer_pro_handle_tab', $tab, $this->_chart ); | |
| 295 | - break; | |
| 296 | 269 | } |
| 297 | 270 | defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit(); |
| 298 | 271 | } |
| 299 | 272 | |
| @@ -339,24 +312,13 @@ | ||
| 339 | 312 | wp_localize_script( |
| 340 | 313 | 'visualizer-render', 'visualizer', array( |
| 341 | 314 | 'l10n' => array( |
| 342 | 315 | 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ), |
| 343 | - 'loading' => esc_html__( 'Loading...', 'visualizer' ), | |
| 344 | 316 | ), |
| 345 | 317 | 'charts' => array( |
| 346 | 318 | 'canvas' => $data, |
| 347 | 319 | ), |
| 348 | - 'language' => $this->get_language(), | |
| 349 | 320 | 'map_api_key' => get_option( 'visualizer-map-api-key' ), |
| 350 | - 'ajax' => array( | |
| 351 | - 'url' => admin_url( 'admin-ajax.php' ), | |
| 352 | - 'nonces' => array( | |
| 353 | - 'permissions' => wp_create_nonce( Visualizer_Plugin::ACTION_FETCH_PERMISSIONS_DATA ), | |
| 354 | - ), | |
| 355 | - 'actions' => array( | |
| 356 | - 'permissions' => Visualizer_Plugin::ACTION_FETCH_PERMISSIONS_DATA, | |
| 357 | - ), | |
| 358 | - ), | |
| 359 | 321 | ) |
| 360 | 322 | ); |
| 361 | 323 | $render = new Visualizer_Render_Page_Data(); |
| 362 | 324 | $render->chart = $this->_chart; |
| @@ -365,11 +327,8 @@ | ||
| 365 | 327 | if ( filter_input( INPUT_GET, 'library', FILTER_VALIDATE_BOOLEAN ) ) { |
| 366 | 328 | $render->button = filter_input( INPUT_GET, 'action' ) == Visualizer_Plugin::ACTION_EDIT_CHART |
| 367 | 329 | ? esc_html__( 'Save Chart', 'visualizer' ) |
| 368 | 330 | : 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 | 331 | } else { |
| 373 | 332 | $render->button = esc_attr__( 'Insert Chart', 'visualizer' ); |
| 374 | 333 | } |
| 375 | 334 | if ( VISUALIZER_PRO ) { |
| @@ -437,41 +396,23 @@ | ||
| 437 | 396 | * |
| 438 | 397 | * @access public |
| 439 | 398 | */ |
| 440 | 399 | 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 | 400 | // validate nonce |
| 401 | + // do not use filter_input as it does not work for phpunit test cases, use filter_var instead | |
| 446 | 402 | if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'] ) ) { |
| 447 | - if ( ! $can_die ) { | |
| 448 | - return; | |
| 449 | - } | |
| 450 | 403 | status_header( 403 ); |
| 451 | 404 | exit; |
| 452 | 405 | } |
| 453 | - | |
| 454 | 406 | // 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 | 407 | $chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : ''; |
| 457 | 408 | if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) { |
| 458 | - if ( ! $can_die ) { | |
| 459 | - return; | |
| 460 | - } | |
| 461 | 409 | status_header( 400 ); |
| 462 | 410 | exit; |
| 463 | 411 | } |
| 464 | - | |
| 465 | 412 | if ( ! isset( $_POST['vz-import-time'] ) ) { |
| 466 | 413 | apply_filters( 'visualizer_pro_remove_schedule', $chart_id ); |
| 467 | 414 | } |
| 468 | - | |
| 469 | - if ( ! isset( $_POST['chart_data_src'] ) || Visualizer_Plugin::CF_SOURCE_FILTER !== $_POST['chart_data_src'] ) { | |
| 470 | - // delete the filters in case this chart is being uploaded from other data sources | |
| 471 | - delete_post_meta( $chart_id, 'visualizer-filter-config' ); | |
| 472 | - } | |
| 473 | - | |
| 474 | 415 | $source = null; |
| 475 | 416 | $render = new Visualizer_Render_Page_Update(); |
| 476 | 417 | if ( isset( $_POST['remote_data'] ) && filter_var( $_POST['remote_data'], FILTER_VALIDATE_URL ) ) { |
| 477 | 418 | $source = new Visualizer_Source_Csv_Remote( $_POST['remote_data'] ); |
| @@ -479,10 +420,12 @@ | ||
| 479 | 420 | apply_filters( 'visualizer_pro_chart_schedule', $chart_id, $_POST['remote_data'], $_POST['vz-import-time'] ); |
| 480 | 421 | } |
| 481 | 422 | } elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) { |
| 482 | 423 | $source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] ); |
| 424 | + // Added by Ash/Upwork | |
| 483 | 425 | } elseif ( isset( $_POST['chart_data'] ) && strlen( $_POST['chart_data'] ) > 0 ) { |
| 484 | 426 | $source = apply_filters( 'visualizer_pro_handle_chart_data', $_POST['chart_data'], '' ); |
| 427 | + // Added by Ash/Upwork | |
| 485 | 428 | } else { |
| 486 | 429 | $render->message = esc_html__( 'CSV file with chart data was not uploaded. Please, try again.', 'visualizer' ); |
| 487 | 430 | } |
| 488 | 431 | if ( $source ) { |
| @@ -498,12 +441,11 @@ | ||
| 498 | 441 | $render->message = esc_html__( 'CSV file is broken or invalid. Please, try again.', 'visualizer' ); |
| 499 | 442 | } |
| 500 | 443 | } |
| 501 | 444 | $render->render(); |
| 502 | - if ( ! $can_die ) { | |
| 503 | - return; | |
| 445 | + if ( ! ( defined( 'VISUALIZER_DO_NOT_DIE' ) && VISUALIZER_DO_NOT_DIE ) ) { | |
| 446 | + defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit(); | |
| 504 | 447 | } |
| 505 | - defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit(); | |
| 506 | 448 | } |
| 507 | 449 | |
| 508 | 450 | /** |
| 509 | 451 | * Clones the chart. |
| @@ -605,9 +547,8 @@ | ||
| 605 | 547 | wp_localize_script( |
| 606 | 548 | 'visualizer-render', 'visualizer', array( |
| 607 | 549 | 'l10n' => array( |
| 608 | 550 | 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ), |
| 609 | - 'loading' => esc_html__( 'Loading...', 'visualizer' ), | |
| 610 | 551 | ), |
| 611 | 552 | 'charts' => array( |
| 612 | 553 | 'canvas' => $data, |
| 613 | 554 | ), |
| @@ -621,6 +562,5 @@ | ||
| 621 | 562 | // Added by Ash/Upwork |
| 622 | 563 | $this->_addAction( 'admin_head', 'renderFlattrScript' ); |
| 623 | 564 | wp_iframe( array( $render, 'render' ) ); |
| 624 | 565 | } |
| 625 | - | |
| 626 | 566 | } |