| @@ -3,9 +3,8 @@ | ||
| 3 | 3 | * Handles the installation of a solution and any dependencies. |
| 4 | 4 | * This page is shown when a Formidable plugin is activated. |
| 5 | 5 | * |
| 6 | 6 | * @since 4.06.02 |
| 7 | - * | |
| 8 | 7 | * @package Formidable |
| 9 | 8 | */ |
| 10 | 9 | |
| 11 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -13,16 +12,10 @@ | ||
| 13 | 12 | } |
| 14 | 13 | |
| 15 | 14 | class FrmSolution { |
| 16 | 15 | |
| 17 | - /** | |
| 18 | - * @var string | |
| 19 | - */ | |
| 20 | 16 | protected $plugin_slug = ''; |
| 21 | 17 | |
| 22 | - /** | |
| 23 | - * @var string | |
| 24 | - */ | |
| 25 | 18 | protected $plugin_file = ''; |
| 26 | 19 | |
| 27 | 20 | /** |
| 28 | 21 | * Hidden welcome page slug. |
| @@ -27,21 +20,14 @@ | ||
| 27 | 20 | /** |
| 28 | 21 | * Hidden welcome page slug. |
| 29 | 22 | * |
| 30 | 23 | * @since 4.06.02 |
| 31 | - * | |
| 32 | 24 | * @var string |
| 33 | 25 | */ |
| 34 | 26 | protected $page = ''; |
| 35 | 27 | |
| 36 | - /** | |
| 37 | - * @var string | |
| 38 | - */ | |
| 39 | 28 | protected $icon = 'frm_icon_font frm_settings_icon'; |
| 40 | 29 | |
| 41 | - /** | |
| 42 | - * @param array $atts | |
| 43 | - */ | |
| 44 | 30 | public function __construct( $atts = array() ) { |
| 45 | 31 | if ( empty( $this->plugin_slug ) ) { |
| 46 | 32 | return; |
| 47 | 33 | } |
| @@ -82,13 +68,8 @@ | ||
| 82 | 68 | add_action( 'admin_menu', array( $this, 'register' ) ); |
| 83 | 69 | add_action( 'admin_head', array( $this, 'hide_menu' ) ); |
| 84 | 70 | } |
| 85 | 71 | |
| 86 | - /** | |
| 87 | - * @param array $links | |
| 88 | - * | |
| 89 | - * @return array | |
| 90 | - */ | |
| 91 | 72 | public function plugin_links( $links ) { |
| 92 | 73 | if ( ! $this->is_complete() ) { |
| 93 | 74 | $settings = '<a href="' . esc_url( $this->settings_link() ) . '">' . __( 'Setup', 'formidable' ) . '</a>'; |
| 94 | 75 | array_unshift( $links, $settings ); |
| @@ -167,9 +148,8 @@ | ||
| 167 | 148 | */ |
| 168 | 149 | public function redirect() { |
| 169 | 150 | |
| 170 | 151 | $current_page = FrmAppHelper::simple_get( 'page', 'sanitize_title' ); |
| 171 | - | |
| 172 | 152 | if ( $current_page === $this->page ) { |
| 173 | 153 | // Prevent endless loop. |
| 174 | 154 | return; |
| 175 | 155 | } |
| @@ -199,12 +179,8 @@ | ||
| 199 | 179 | } |
| 200 | 180 | |
| 201 | 181 | /** |
| 202 | 182 | * Add page to global settings. |
| 203 | - * | |
| 204 | - * @param array $sections Sections. | |
| 205 | - * | |
| 206 | - * @return array | |
| 207 | 183 | */ |
| 208 | 184 | public function add_settings( $sections ) { |
| 209 | 185 | wp_enqueue_style( 'formidable-pro-fields' ); |
| 210 | 186 | $sections[ $this->plugin_slug ] = array( |
| @@ -224,9 +200,8 @@ | ||
| 224 | 200 | * @return void |
| 225 | 201 | */ |
| 226 | 202 | public function settings_page() { |
| 227 | 203 | $steps = $this->get_steps_data(); |
| 228 | - | |
| 229 | 204 | if ( ! $steps['license']['complete'] || ( isset( $steps['plugin'] ) && ! $steps['plugin']['complete'] ) ) { |
| 230 | 205 | // Redirect to the welcome page if install hasn't been done. |
| 231 | 206 | $url = $this->settings_link(); |
| 232 | 207 | echo '<script>window.location.replace("' . esc_url_raw( $url ) . '");</script>'; |
| @@ -245,9 +220,8 @@ | ||
| 245 | 220 | |
| 246 | 221 | $new_class = $all_imported ? ' button frm_hidden' : ''; |
| 247 | 222 | $step['button_class'] = str_replace( 'frm_grey disabled', $new_class, $step['button_class'] ); |
| 248 | 223 | } |
| 249 | - | |
| 250 | 224 | if ( $all_imported ) { |
| 251 | 225 | $step['description'] = __( 'The following form(s) have been created.', 'formidable' ); |
| 252 | 226 | } |
| 253 | 227 | $this->show_app_install( $step ); |
| @@ -324,9 +298,8 @@ | ||
| 324 | 298 | */ |
| 325 | 299 | protected function main_content() { |
| 326 | 300 | $steps = $this->get_steps_data(); |
| 327 | 301 | $this->license_box( $steps['license'] ); |
| 328 | - | |
| 329 | 302 | if ( isset( $steps['plugin'] ) ) { |
| 330 | 303 | $this->show_plugin_install( $steps['plugin'] ); |
| 331 | 304 | } |
| 332 | 305 | $this->show_app_install( $steps['import'] ); |
| @@ -332,11 +305,8 @@ | ||
| 332 | 305 | $this->show_app_install( $steps['import'] ); |
| 333 | 306 | $this->show_page_links( $steps['complete'] ); |
| 334 | 307 | } |
| 335 | 308 | |
| 336 | - /** | |
| 337 | - * @return array | |
| 338 | - */ | |
| 339 | 309 | protected function get_steps_data() { |
| 340 | 310 | $pro_installed = FrmAppHelper::pro_is_connected(); |
| 341 | 311 | |
| 342 | 312 | $steps = array( |
| @@ -374,9 +344,8 @@ | ||
| 374 | 344 | |
| 375 | 345 | $this->adjust_plugin_install_step( $steps ); |
| 376 | 346 | |
| 377 | 347 | $has_current = false; |
| 378 | - | |
| 379 | 348 | foreach ( $steps as $k => $step ) { |
| 380 | 349 | // Set the current step. |
| 381 | 350 | if ( ! isset( $step['current'] ) ) { |
| 382 | 351 | if ( $step['complete'] ) { |
| @@ -389,11 +358,10 @@ | ||
| 389 | 358 | $has_current = true; |
| 390 | 359 | } |
| 391 | 360 | |
| 392 | 361 | // Set disabled buttons. |
| 393 | - $class = $step['button_class'] ?? ''; | |
| 362 | + $class = isset( $step['button_class'] ) ? $step['button_class'] : ''; | |
| 394 | 363 | $class .= ' button-primary frm-button-primary'; |
| 395 | - | |
| 396 | 364 | if ( ! $steps[ $k ]['current'] ) { |
| 397 | 365 | $class .= ' frm_grey disabled'; |
| 398 | 366 | } |
| 399 | 367 | $steps[ $k ]['button_class'] = $class; |
| @@ -408,9 +376,8 @@ | ||
| 408 | 376 | * @return void |
| 409 | 377 | */ |
| 410 | 378 | protected function adjust_plugin_install_step( &$steps ) { |
| 411 | 379 | $plugins = $this->required_plugins(); |
| 412 | - | |
| 413 | 380 | if ( empty( $plugins ) ) { |
| 414 | 381 | unset( $steps['plugin'] ); |
| 415 | 382 | $steps['import']['num'] = 2; |
| 416 | 383 | $steps['complete']['num'] = 3; |
| @@ -418,16 +385,13 @@ | ||
| 418 | 385 | } |
| 419 | 386 | |
| 420 | 387 | $missing = array(); |
| 421 | 388 | $rel = array(); |
| 422 | - | |
| 423 | 389 | foreach ( $plugins as $plugin_key ) { |
| 424 | 390 | $plugin = FrmAddonsController::install_link( $plugin_key ); |
| 425 | - | |
| 426 | 391 | if ( $plugin['status'] === 'active' ) { |
| 427 | 392 | continue; |
| 428 | 393 | } |
| 429 | - | |
| 430 | 394 | if ( isset( $plugin['url'] ) ) { |
| 431 | 395 | $rel[] = $plugin['url']; |
| 432 | 396 | } else { |
| 433 | 397 | // Add-on is required but not allowed. |
| @@ -433,9 +397,8 @@ | ||
| 433 | 397 | // Add-on is required but not allowed. |
| 434 | 398 | $missing[] = $plugin_key; |
| 435 | 399 | } |
| 436 | 400 | } |
| 437 | - | |
| 438 | 401 | if ( empty( $rel ) && empty( $missing ) ) { |
| 439 | 402 | $steps['plugin']['complete'] = true; |
| 440 | 403 | } elseif ( ! empty( $missing ) ) { |
| 441 | 404 | $steps['plugin']['error'] = sprintf( |
| @@ -453,10 +416,8 @@ | ||
| 453 | 416 | } |
| 454 | 417 | } |
| 455 | 418 | |
| 456 | 419 | /** |
| 457 | - * @param array $step Step. | |
| 458 | - * | |
| 459 | 420 | * @return void |
| 460 | 421 | */ |
| 461 | 422 | protected function step_top( $step ) { |
| 462 | 423 | $section_class = empty( $step['current'] ) ? 'frm_grey' : ''; |
| @@ -493,10 +454,8 @@ | ||
| 493 | 454 | <?php |
| 494 | 455 | } |
| 495 | 456 | |
| 496 | 457 | /** |
| 497 | - * @param array $step Step. | |
| 498 | - * | |
| 499 | 458 | * @return void |
| 500 | 459 | */ |
| 501 | 460 | protected function step_bottom( $step ) { |
| 502 | 461 | ?> |
| @@ -507,10 +466,8 @@ | ||
| 507 | 466 | |
| 508 | 467 | /** |
| 509 | 468 | * Generate and output Connect step section HTML. |
| 510 | 469 | * |
| 511 | - * @param array $step Step. | |
| 512 | - * | |
| 513 | 470 | * @return void |
| 514 | 471 | */ |
| 515 | 472 | protected function license_box( $step ) { |
| 516 | 473 | $this->step_top( $step ); |
| @@ -528,10 +485,8 @@ | ||
| 528 | 485 | $this->step_bottom( $step ); |
| 529 | 486 | } |
| 530 | 487 | |
| 531 | 488 | /** |
| 532 | - * @param array $step Step. | |
| 533 | - * | |
| 534 | 489 | * @return void |
| 535 | 490 | */ |
| 536 | 491 | protected function show_plugin_install( $step ) { |
| 537 | 492 | $this->step_top( $step ); |
| @@ -536,9 +491,9 @@ | ||
| 536 | 491 | protected function show_plugin_install( $step ) { |
| 537 | 492 | $this->step_top( $step ); |
| 538 | 493 | |
| 539 | 494 | if ( ! isset( $step['error'] ) ) { |
| 540 | - $rel = $step['links'] ?? array(); | |
| 495 | + $rel = isset( $step['links'] ) ? $step['links'] : array(); | |
| 541 | 496 | |
| 542 | 497 | ?> |
| 543 | 498 | <a rel="<?php echo esc_attr( implode( ',', $rel ) ); ?>" class="<?php echo esc_attr( $step['button_class'] ); ?>"> |
| 544 | 499 | <?php echo esc_html( $step['button_label'] ); ?> |
| @@ -549,15 +504,12 @@ | ||
| 549 | 504 | $this->step_bottom( $step ); |
| 550 | 505 | } |
| 551 | 506 | |
| 552 | 507 | /** |
| 553 | - * @param array $step Step. | |
| 554 | - * | |
| 555 | 508 | * @return void |
| 556 | 509 | */ |
| 557 | 510 | protected function show_app_install( $step ) { |
| 558 | 511 | $is_complete = $step['complete']; |
| 559 | - | |
| 560 | 512 | if ( ! empty( $this->form_options() ) && ! $is_complete ) { |
| 561 | 513 | $step['description'] = __( 'Select the form or view you would like to create.', 'formidable' ); |
| 562 | 514 | } |
| 563 | 515 | |
| @@ -585,9 +537,8 @@ | ||
| 585 | 537 | } elseif ( ! isset( $addons[ $id ]['beta']['package'] ) ) { |
| 586 | 538 | echo '<p class="frm_error_style">' . esc_html__( 'Looks like you may not have a current subscription for this solution. Please check your account.', 'formidable' ) . '</p>'; |
| 587 | 539 | } else { |
| 588 | 540 | $xml = $addons[ $id ]['beta']['package']; |
| 589 | - | |
| 590 | 541 | if ( is_array( $xml ) ) { |
| 591 | 542 | $xml = reset( $xml ); |
| 592 | 543 | } |
| 593 | 544 | |
| @@ -630,10 +581,8 @@ | ||
| 630 | 581 | $this->step_bottom( $step ); |
| 631 | 582 | } |
| 632 | 583 | |
| 633 | 584 | /** |
| 634 | - * @param string $xml | |
| 635 | - * | |
| 636 | 585 | * @return void |
| 637 | 586 | */ |
| 638 | 587 | protected function show_form_options( $xml ) { |
| 639 | 588 | $this->show_import_options( $this->form_options(), 'form', $xml ); |
| @@ -661,9 +610,8 @@ | ||
| 661 | 610 | } |
| 662 | 611 | |
| 663 | 612 | $imported = $this->previously_imported_forms(); |
| 664 | 613 | $count = count( $options ); |
| 665 | - | |
| 666 | 614 | foreach ( $options as $info ) { |
| 667 | 615 | // Count the number of options displayed for css. |
| 668 | 616 | if ( $count > 1 && ! isset( $info['img'] ) ) { |
| 669 | 617 | --$count; |
| @@ -668,9 +616,8 @@ | ||
| 668 | 616 | if ( $count > 1 && ! isset( $info['img'] ) ) { |
| 669 | 617 | --$count; |
| 670 | 618 | } |
| 671 | 619 | } |
| 672 | - | |
| 673 | 620 | $width = floor( ( 533 - ( ( $count - 1 ) * 20 ) ) / $count ); |
| 674 | 621 | unset( $count ); |
| 675 | 622 | |
| 676 | 623 | $selected = false; |
| @@ -682,15 +629,13 @@ | ||
| 682 | 629 | * @return void |
| 683 | 630 | */ |
| 684 | 631 | protected function show_page_options() { |
| 685 | 632 | $pages = $this->needed_pages(); |
| 686 | - | |
| 687 | 633 | if ( empty( $pages ) ) { |
| 688 | 634 | return; |
| 689 | 635 | } |
| 690 | 636 | |
| 691 | 637 | echo '<h3>Choose New Page Title</h3>'; |
| 692 | - | |
| 693 | 638 | foreach ( $pages as $page ) { |
| 694 | 639 | ?> |
| 695 | 640 | <p> |
| 696 | 641 | <label for="pages_<?php echo esc_html( $page['type'] ); ?>"> |
| @@ -702,10 +647,8 @@ | ||
| 702 | 647 | } |
| 703 | 648 | } |
| 704 | 649 | |
| 705 | 650 | /** |
| 706 | - * @param array $step | |
| 707 | - * | |
| 708 | 651 | * @return void |
| 709 | 652 | */ |
| 710 | 653 | protected function show_page_links( $step ) { |
| 711 | 654 | if ( $step['current'] ) { |
| @@ -743,9 +686,8 @@ | ||
| 743 | 686 | * @return bool |
| 744 | 687 | */ |
| 745 | 688 | protected function is_complete( $count = 1 ) { |
| 746 | 689 | $imported = $this->previously_imported_forms(); |
| 747 | - | |
| 748 | 690 | if ( $count === 'all' ) { |
| 749 | 691 | return count( $imported ) >= count( $this->form_options() ); |
| 750 | 692 | } |
| 751 | 693 | return ! empty( $imported ); |
| @@ -758,12 +700,10 @@ | ||
| 758 | 700 | */ |
| 759 | 701 | protected function previously_imported_forms() { |
| 760 | 702 | $imported = array(); |
| 761 | 703 | $forms = $this->form_options(); |
| 762 | - | |
| 763 | 704 | foreach ( $forms as $form ) { |
| 764 | 705 | $was_imported = isset( $form['form'] ) ? FrmForm::get_id_by_key( $form['form'] ) : false; |
| 765 | - | |
| 766 | 706 | if ( $was_imported ) { |
| 767 | 707 | $imported[ $form['form'] ] = $was_imported; |
| 768 | 708 | } |
| 769 | 709 | } |