| @@ -72,8 +72,9 @@ | ||
| 72 | 72 | add_action( "load-$hook", array( $this, 'visualizer_load_setup_wizard_page' ) ); |
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | + | |
| 76 | 77 | /** |
| 77 | 78 | * Method to register the setup wizard page. |
| 78 | 79 | * |
| 79 | 80 | * @access public |
| @@ -167,9 +168,9 @@ | ||
| 167 | 168 | * Setup wizard process. |
| 168 | 169 | */ |
| 169 | 170 | public function visualizer_wizard_step_process() { |
| 170 | 171 | check_ajax_referer( VISUALIZER_ABSPATH, 'security' ); |
| 171 | - $step = ! empty( $_POST['step'] ) ? filter_input( INPUT_POST, 'step', FILTER_SANITIZE_STRING ) : 1; | |
| 172 | + $step = ! empty( $_POST['step'] ) ? sanitize_text_field( wp_unslash( $_POST['step'] ) ) : 1; | |
| 172 | 173 | switch ( $step ) { |
| 173 | 174 | case 'step_2': |
| 174 | 175 | $this->setup_wizard_import_chart(); |
| 175 | 176 | break; |
| @@ -192,9 +193,9 @@ | ||
| 192 | 193 | * Step: 2 import chart. |
| 193 | 194 | */ |
| 194 | 195 | private function setup_wizard_import_chart() { |
| 195 | 196 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 196 | - $chart_type = ! empty( $_POST['chart_type'] ) ? filter_input( INPUT_POST, 'chart_type', FILTER_SANITIZE_STRING ) : ''; | |
| 197 | + $chart_type = ! empty( $_POST['chart_type'] ) ? sanitize_text_field( wp_unslash( $_POST['chart_type'] ) ) : ''; | |
| 197 | 198 | $chart_status = Visualizer_Module_Admin::checkChartStatus( $chart_type ); |
| 198 | 199 | if ( ! $chart_status ) { |
| 199 | 200 | wp_send_json( |
| 200 | 201 | array( |
| @@ -211,14 +212,15 @@ | ||
| 211 | 212 | 'success' => 2, |
| 212 | 213 | 'message' => __( 'Something went wrong while importing the chart', 'visualizer' ), |
| 213 | 214 | ); |
| 214 | 215 | |
| 216 | + $data = $source->getData(); | |
| 215 | 217 | $args = array( |
| 216 | 218 | 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, |
| 217 | 219 | 'post_title' => 'Visualization', |
| 218 | 220 | 'post_author' => get_current_user_id(), |
| 219 | 221 | 'post_status' => 'publish', |
| 220 | - 'post_content' => $source->getData(), | |
| 222 | + 'post_content' => $data, | |
| 221 | 223 | ); |
| 222 | 224 | $chart_id = wp_insert_post( $args ); |
| 223 | 225 | |
| 224 | 226 | if ( $chart_id && ! is_wp_error( $chart_id ) ) { |
| @@ -231,10 +233,12 @@ | ||
| 231 | 233 | update_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); |
| 232 | 234 | update_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $series ); |
| 233 | 235 | update_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, '' ); |
| 234 | 236 | |
| 237 | + $data = maybe_unserialize( $data ); | |
| 235 | 238 | $setting_series = array(); |
| 236 | - foreach ( $series as $s ) { | |
| 239 | + $setting_slices = array(); | |
| 240 | + foreach ( $data as $s ) { | |
| 237 | 241 | $setting_series[] = array( |
| 238 | 242 | 'visibleInLegend' => '', |
| 239 | 243 | 'lineWidth' => '', |
| 240 | 244 | 'pointSize' => '', |
| @@ -242,8 +246,12 @@ | ||
| 242 | 246 | 'curveType' => '', |
| 243 | 247 | 'color' => '', |
| 244 | 248 | 'role' => '', |
| 245 | 249 | ); |
| 250 | + $setting_slices[] = array( | |
| 251 | + 'offset' => 0, | |
| 252 | + 'color' => '', | |
| 253 | + ); | |
| 246 | 254 | } |
| 247 | 255 | update_post_meta( |
| 248 | 256 | $chart_id, |
| 249 | 257 | Visualizer_Plugin::CF_SETTINGS, |
| @@ -288,9 +296,9 @@ | ||
| 288 | 296 | 'height' => '', |
| 289 | 297 | ), |
| 290 | 298 | 'focusTarget' => 'datum', |
| 291 | 299 | 'series' => $setting_series, |
| 292 | - 'slices' => array(), | |
| 300 | + 'slices' => $setting_slices, | |
| 293 | 301 | 'vAxis' => array( |
| 294 | 302 | 'title' => '', |
| 295 | 303 | 'textPosition' => '', |
| 296 | 304 | 'direction' => 1, |
| @@ -333,8 +341,45 @@ | ||
| 333 | 341 | 'max' => '', |
| 334 | 342 | 'min' => '', |
| 335 | 343 | ), |
| 336 | 344 | ), |
| 345 | + 'customcss' => array( | |
| 346 | + 'headerRow' => array( | |
| 347 | + 'background-color' => '', | |
| 348 | + 'color' => '', | |
| 349 | + 'transform' => '', | |
| 350 | + ), | |
| 351 | + 'tableRow' => array( | |
| 352 | + 'background-color' => '', | |
| 353 | + 'color' => '', | |
| 354 | + 'transform' => '', | |
| 355 | + ), | |
| 356 | + 'oddTableRow' => array( | |
| 357 | + 'background-color' => '', | |
| 358 | + 'color' => '', | |
| 359 | + 'transform' => '', | |
| 360 | + ), | |
| 361 | + 'selectedTableRow' => array( | |
| 362 | + 'background-color' => '', | |
| 363 | + 'color' => '', | |
| 364 | + 'transform' => '', | |
| 365 | + ), | |
| 366 | + 'hoverTableRow' => array( | |
| 367 | + 'background-color' => '', | |
| 368 | + 'color' => '', | |
| 369 | + 'transform' => '', | |
| 370 | + ), | |
| 371 | + 'headerCell' => array( | |
| 372 | + 'background-color' => '', | |
| 373 | + 'color' => '', | |
| 374 | + 'transform' => '', | |
| 375 | + ), | |
| 376 | + 'tableCell' => array( | |
| 377 | + 'background-color' => '', | |
| 378 | + 'color' => '', | |
| 379 | + 'transform' => '', | |
| 380 | + ), | |
| 381 | + ), | |
| 337 | 382 | ) |
| 338 | 383 | ); |
| 339 | 384 | $wizard_data = array( |
| 340 | 385 | 'chart_type' => $chart_type, |
| @@ -341,9 +386,10 @@ | ||
| 341 | 386 | 'chart_id' => $chart_id, |
| 342 | 387 | ); |
| 343 | 388 | $this->update_wizard_data( $wizard_data, false ); |
| 344 | 389 | $response = array( |
| 345 | - 'success' => 1, | |
| 390 | + 'success' => 1, | |
| 391 | + 'chart_id' => $chart_id, | |
| 346 | 392 | ); |
| 347 | 393 | } |
| 348 | 394 | wp_send_json( $response ); |
| 349 | 395 | exit; |
| @@ -371,9 +417,9 @@ | ||
| 371 | 417 | */ |
| 372 | 418 | private function setup_wizard_create_draft_page( $return_page_id = false ) { |
| 373 | 419 | $add_basic_shortcode = ! empty( $_POST['add_basic_shortcode'] ) ? sanitize_text_field( wp_unslash( $_POST['add_basic_shortcode'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 374 | 420 | $add_basic_shortcode = 'true' === $add_basic_shortcode ? true : false; |
| 375 | - $basic_shortcode = ! empty( $_POST['basic_shortcode'] ) ? filter_input( INPUT_POST, 'basic_shortcode', FILTER_SANITIZE_STRING ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 421 | + $basic_shortcode = ! empty( $_POST['basic_shortcode'] ) ? sanitize_text_field( wp_unslash( $_POST['basic_shortcode'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 376 | 422 | |
| 377 | 423 | if ( ! $add_basic_shortcode ) { |
| 378 | 424 | wp_send_json( |
| 379 | 425 | array( |
| @@ -431,9 +477,9 @@ | ||
| 431 | 477 | * Step: 3 Install plugin. |
| 432 | 478 | */ |
| 433 | 479 | private function setup_wizard_install_plugin() { |
| 434 | 480 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 435 | - $slug = ! empty( $_POST['slug'] ) ? filter_input( INPUT_POST, 'slug', FILTER_SANITIZE_STRING ) : ''; | |
| 481 | + $slug = ! empty( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : ''; | |
| 436 | 482 | if ( empty( $slug ) ) { |
| 437 | 483 | wp_send_json( |
| 438 | 484 | array( |
| 439 | 485 | 'status' => 0, |
| @@ -451,10 +497,12 @@ | ||
| 451 | 497 | ); |
| 452 | 498 | } |
| 453 | 499 | |
| 454 | 500 | if ( ! empty( $slug ) ) { |
| 501 | + $wizard_data = get_option( self::OPTION_NAME, array() ); | |
| 455 | 502 | require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 456 | 503 | include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; |
| 504 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 457 | 505 | |
| 458 | 506 | $api = plugins_api( |
| 459 | 507 | 'plugin_information', |
| 460 | 508 | array( |
| @@ -514,13 +562,38 @@ | ||
| 514 | 562 | |
| 515 | 563 | wp_send_json( $status ); |
| 516 | 564 | } |
| 517 | 565 | |
| 518 | - activate_plugin( 'optimole-wp/optimole-wp.php' ); | |
| 519 | - delete_transient( 'optml_fresh_install' ); | |
| 520 | - // Update wizard data. | |
| 521 | - $wizard_data['enable_perfomance'] = true; | |
| 522 | - $this->update_wizard_data( $wizard_data ); | |
| 566 | + $installed_plugins = get_plugins( '/' . sanitize_key( wp_unslash( $slug ) ) ); | |
| 567 | + if ( ! empty( $installed_plugins ) ) { | |
| 568 | + $plugin_files = array_keys( $installed_plugins ); | |
| 569 | + $plugin_file = sanitize_key( wp_unslash( $slug ) ) . '/' . $plugin_files[0]; | |
| 570 | + activate_plugin( $plugin_file ); | |
| 571 | + } | |
| 572 | + $wizard_data_updated = false; | |
| 573 | + if ( 'optimole-wp' === $slug ) { | |
| 574 | + delete_transient( 'optml_fresh_install' ); | |
| 575 | + // Update wizard data. | |
| 576 | + $wizard_data['enable_perfomance'] = true; | |
| 577 | + $wizard_data_updated = true; | |
| 578 | + } | |
| 579 | + if ( 'otter-blocks' === $slug ) { | |
| 580 | + // Update wizard data. | |
| 581 | + $wizard_data['enable_otter_blocks'] = true; | |
| 582 | + $wizard_data_updated = true; | |
| 583 | + // Suppress Otter's post-activation redirects so the user stays in Visualizer. | |
| 584 | + update_option( 'themeisle_blocks_settings_redirect', '0' ); | |
| 585 | + update_option( 'themeisle_blocks_settings_onboarding', '0' ); | |
| 586 | + } | |
| 587 | + if ( 'wp-cloudflare-page-cache' === $slug ) { | |
| 588 | + // Update wizard data. | |
| 589 | + $wizard_data['enable_page_cache'] = true; | |
| 590 | + $wizard_data_updated = true; | |
| 591 | + update_option( 'swcfpc_dashboard_redirect', false ); | |
| 592 | + } | |
| 593 | + if ( $wizard_data_updated ) { | |
| 594 | + $this->update_wizard_data( $wizard_data ); | |
| 595 | + } | |
| 523 | 596 | |
| 524 | 597 | wp_send_json( |
| 525 | 598 | array( |
| 526 | 599 | 'status' => 1, |
| @@ -569,18 +642,19 @@ | ||
| 569 | 642 | ); |
| 570 | 643 | } |
| 571 | 644 | |
| 572 | 645 | if ( $with_subscribe && is_email( $email ) ) { |
| 573 | - $request_res = wp_remote_post( | |
| 646 | + wp_remote_post( | |
| 574 | 647 | VISUALIZER_SUBSCRIBE_API, |
| 575 | 648 | array( |
| 576 | - 'timeout' => 100, | |
| 577 | - 'headers' => array( | |
| 649 | + 'timeout' => 5, | |
| 650 | + 'blocking' => false, | |
| 651 | + 'headers' => array( | |
| 578 | 652 | 'Content-Type' => 'application/json', |
| 579 | 653 | 'Cache-Control' => 'no-cache', |
| 580 | 654 | 'Accept' => 'application/json, */*;q=0.1', |
| 581 | 655 | ), |
| 582 | - 'body' => wp_json_encode( | |
| 656 | + 'body' => wp_json_encode( | |
| 583 | 657 | array( |
| 584 | 658 | 'slug' => 'visualizer', |
| 585 | 659 | 'site' => home_url(), |
| 586 | 660 | 'email' => $email, |
| @@ -590,26 +664,12 @@ | ||
| 590 | 664 | ) |
| 591 | 665 | ), |
| 592 | 666 | ) |
| 593 | 667 | ); |
| 594 | - if ( ! is_wp_error( $request_res ) ) { | |
| 595 | - $body = json_decode( wp_remote_retrieve_body( $request_res ) ); | |
| 596 | - if ( 'success' === $body->code ) { | |
| 597 | - $this->dismissWizard( false ); | |
| 598 | - wp_send_json( $response ); | |
| 599 | - } | |
| 600 | - } | |
| 601 | - wp_send_json( | |
| 602 | - array( | |
| 603 | - 'status' => 0, | |
| 604 | - 'redirect_to' => '', | |
| 605 | - 'message' => '', | |
| 606 | - ) | |
| 607 | - ); | |
| 608 | - } else { | |
| 609 | - $this->dismissWizard( false ); | |
| 610 | - wp_send_json( $response ); | |
| 611 | 668 | } |
| 669 | + | |
| 670 | + $this->dismissWizard( false ); | |
| 671 | + wp_send_json( $response ); | |
| 612 | 672 | } |
| 613 | 673 | |
| 614 | 674 | /** |
| 615 | 675 | * Filter chart setting. |