| @@ -14,9 +14,9 @@ | ||
| 14 | 14 | public $response = array(); |
| 15 | 15 | public $tracking = 'frm_forms_imported'; |
| 16 | 16 | |
| 17 | 17 | protected $fields_map = array(); |
| 18 | - protected $current_source_form; | |
| 18 | + protected $current_source_form = null; | |
| 19 | 19 | protected $current_section = array(); |
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * Define required properties. |
| @@ -26,9 +26,9 @@ | ||
| 26 | 26 | return; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | if ( ! function_exists( 'is_plugin_active' ) ) { |
| 30 | - require_once ABSPATH . '/wp-admin/includes/plugin.php'; | |
| 30 | + require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); | |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | $this->source_active = is_plugin_active( $this->path ); |
| 34 | 34 | if ( ! $this->source_active ) { |
| @@ -49,15 +49,14 @@ | ||
| 49 | 49 | add_action( 'wp_ajax_frm_import_' . $this->slug, array( $this, 'import_forms' ) ); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | public function import_page() { |
| 53 | - $forms = $this->get_forms(); | |
| 54 | 53 | ?> |
| 55 | 54 | <div class="wrap"> |
| 56 | 55 | <h2 class="frm-h2"><?php echo esc_html( $this->name ); ?> Importer</h2> |
| 57 | 56 | <p class="howto">Import forms and settings automatically from <?php echo esc_html( $this->name ); ?>.</p> |
| 58 | - <div id="welcome-panel"> | |
| 59 | - <div style="margin-bottom:10px;"> | |
| 57 | + <div class="welcome-panel" id="welcome-panel"> | |
| 58 | + <div class="welcome-panel-content" style="text-align:center;margin-bottom:10px;"> | |
| 60 | 59 | <p class="about-description"> |
| 61 | 60 | Select the forms to import. |
| 62 | 61 | </p> |
| 63 | 62 | <form class="frm_form_importer" method="post" |
| @@ -64,15 +63,15 @@ | ||
| 64 | 63 | action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>"> |
| 65 | 64 | <?php wp_nonce_field( 'nonce', 'frm_ajax' ); ?> |
| 66 | 65 | <input type="hidden" name="slug" value="<?php echo esc_attr( $this->slug ); ?>" /> |
| 67 | 66 | <input type="hidden" name="action" value="frm_import_<?php echo esc_attr( $this->slug ); ?>" /> |
| 68 | - <div style="max-width:400px;text-align:left;"> | |
| 67 | + <div style="margin:10px auto;max-width:400px;text-align:left;"> | |
| 69 | 68 | <?php |
| 70 | - if ( ! $forms ) { | |
| 69 | + if ( empty( $this->get_forms() ) ) { | |
| 71 | 70 | esc_html_e( 'No Forms Found.', 'formidable' ); |
| 72 | 71 | } |
| 73 | 72 | ?> |
| 74 | - <?php foreach ( $forms as $form_id => $name ) { ?> | |
| 73 | + <?php foreach ( $this->get_forms() as $form_id => $name ) { ?> | |
| 75 | 74 | <p> |
| 76 | 75 | <label> |
| 77 | 76 | <input type="checkbox" name="form_id[]" |
| 78 | 77 | value="<?php echo esc_attr( $form_id ); ?>" checked="checked" /> |
| @@ -86,22 +85,9 @@ | ||
| 86 | 85 | </label> |
| 87 | 86 | </p> |
| 88 | 87 | <?php } ?> |
| 89 | 88 | </div> |
| 90 | - <?php | |
| 91 | - $button_atts = array( | |
| 92 | - 'type' => 'submit', | |
| 93 | - 'class' => 'button button-primary frm-button-primary', | |
| 94 | - ); | |
| 95 | - if ( ! $forms ) { | |
| 96 | - $button_atts['disabled'] = 'disabled'; | |
| 97 | - } | |
| 98 | - ?> | |
| 99 | - <p class="submit"> | |
| 100 | - <button <?php FrmAppHelper::array_to_html_params( $button_atts, true ); ?>> | |
| 101 | - <?php esc_html_e( 'Start Import', 'formidable' ); ?> | |
| 102 | - </button> | |
| 103 | - </p> | |
| 89 | + <button type="submit" class="button button-primary button-hero">Start Import</button> | |
| 104 | 90 | </form> |
| 105 | 91 | <div id="frm-importer-process" class="frm-importer-process frm_hidden"> |
| 106 | 92 | |
| 107 | 93 | <p class="process-count"> |
| @@ -110,15 +96,10 @@ | ||
| 110 | 96 | from <?php echo esc_html( $this->name ); ?>. |
| 111 | 97 | </p> |
| 112 | 98 | |
| 113 | 99 | <p class="process-completed" class="frm_hidden"> |
| 114 | - <?php | |
| 115 | - printf( | |
| 116 | - // translators: %s is the number of forms that were imported. | |
| 117 | - esc_html__( 'The import process has finished! We have successfully imported %s forms. You can review the results below.', 'formidable' ), | |
| 118 | - '<span class="forms-completed"></span>' | |
| 119 | - ); | |
| 120 | - ?> | |
| 100 | + The import process has finished! We have successfully imported | |
| 101 | + <span class="forms-completed"></span> forms. You can review the results below. | |
| 121 | 102 | </p> |
| 122 | 103 | |
| 123 | 104 | <div class="status"></div> |
| 124 | 105 | |
| @@ -146,9 +127,9 @@ | ||
| 146 | 127 | ); |
| 147 | 128 | |
| 148 | 129 | if ( is_array( $forms ) ) { |
| 149 | 130 | $imported = array(); |
| 150 | - foreach ( $forms as $form_id ) { | |
| 131 | + foreach ( (array) $forms as $form_id ) { | |
| 151 | 132 | $imported[] = $this->import_form( $form_id ); |
| 152 | 133 | } |
| 153 | 134 | } else { |
| 154 | 135 | $imported = $this->import_form( $forms ); |
| @@ -250,20 +231,20 @@ | ||
| 250 | 231 | } elseif ( $new_type === 'break' || $new_type === 'end_divider' ) { |
| 251 | 232 | $this->current_section = array(); |
| 252 | 233 | } |
| 253 | 234 | |
| 254 | - // This may occasionally skip one level/order e.g. after adding a | |
| 235 | + // This may occassionally skip one level/order e.g. after adding a | |
| 255 | 236 | // list field, as field_order would already be prepared to be used. |
| 256 | - ++$field_order; | |
| 237 | + $field_order ++; | |
| 257 | 238 | |
| 258 | - if ( ! empty( $new_field['fields'] ) && is_array( $new_field['fields'] ) ) { | |
| 239 | + if ( isset( $new_field['fields'] ) && is_array( $new_field['fields'] ) && ! empty( $new_field['fields'] ) ) { | |
| 259 | 240 | // we have (inner) fields to merge |
| 260 | 241 | |
| 261 | 242 | $form['fields'] = array_merge( $form['fields'], $new_field['fields'] ); |
| 262 | 243 | // set the new field_order as it would have changed |
| 263 | - $field_order = $new_field['current_order']; | |
| 244 | + $field_order = $new_field['current_order']; | |
| 264 | 245 | } |
| 265 | - }//end foreach | |
| 246 | + } | |
| 266 | 247 | } |
| 267 | 248 | |
| 268 | 249 | protected function prepare_field( $field, &$new_field ) { |
| 269 | 250 | // customize this function |
| @@ -290,9 +271,9 @@ | ||
| 290 | 271 | $open = array(); |
| 291 | 272 | |
| 292 | 273 | $order = 0; |
| 293 | 274 | foreach ( $fields as $field ) { |
| 294 | - ++$order; | |
| 275 | + $order ++; | |
| 295 | 276 | $type = $this->get_field_type( $field ); |
| 296 | 277 | $new_type = $this->convert_field_type( $type, $field ); |
| 297 | 278 | if ( ! in_array( $new_type, $with_end ) && $new_type !== 'break' ) { |
| 298 | 279 | continue; |
| @@ -320,9 +301,9 @@ | ||
| 320 | 301 | $sub = FrmFieldsHelper::setup_new_vars( 'end_divider' ); |
| 321 | 302 | $sub['name'] = __( 'Section Buttons', 'formidable' ); |
| 322 | 303 | $subs = array( $sub ); |
| 323 | 304 | $this->insert_fields_in_array( $subs, $order, 0, $fields ); |
| 324 | - ++$order; | |
| 305 | + $order ++; | |
| 325 | 306 | } |
| 326 | 307 | |
| 327 | 308 | /** |
| 328 | 309 | * Replace the original combo field with a group. |
| @@ -344,9 +325,9 @@ | ||
| 344 | 325 | * array at usage locations. |
| 345 | 326 | */ |
| 346 | 327 | protected function convert_field_type( $type, $field = array(), $use = '' ) { |
| 347 | 328 | if ( empty( $field ) ) { |
| 348 | - // For reverse compatibility. | |
| 329 | + // For reverse compatability. | |
| 349 | 330 | return $type; |
| 350 | 331 | } |
| 351 | 332 | |
| 352 | 333 | return $use ? $use : $field['type']; |
| @@ -355,9 +336,9 @@ | ||
| 355 | 336 | /** |
| 356 | 337 | * Add the new form to the database and return AJAX data.å |
| 357 | 338 | * |
| 358 | 339 | * @param array $form Form to import. |
| 359 | - * @param array $upgrade_omit No field alternative. | |
| 340 | + * @param array $upgrade_omit No field alternative | |
| 360 | 341 | */ |
| 361 | 342 | protected function add_form( $form, $upgrade_omit = array() ) { |
| 362 | 343 | |
| 363 | 344 | // Create empty form so we have an ID to work with. |
| @@ -388,9 +369,9 @@ | ||
| 388 | 369 | * @param array $form parameters for the new form to be created. Only |
| 389 | 370 | * the name key is a must. The keys are the column |
| 390 | 371 | * names of the forms table in the DB. |
| 391 | 372 | * |
| 392 | - * @return bool|int The ID of the newly created form or false on failure. | |
| 373 | + * @return int The ID of the newly created form. | |
| 393 | 374 | */ |
| 394 | 375 | protected function create_form( $form ) { |
| 395 | 376 | $form['form_key'] = $form['name']; |
| 396 | 377 | $form['status'] = 'published'; |
| @@ -411,9 +392,9 @@ | ||
| 411 | 392 | |
| 412 | 393 | /** |
| 413 | 394 | * @since 4.04.03 |
| 414 | 395 | * |
| 415 | - * @param int $form_id | |
| 396 | + * @param int $form_id | |
| 416 | 397 | * @param array $form |
| 417 | 398 | */ |
| 418 | 399 | protected function create_fields( $form_id, &$form ) { |
| 419 | 400 | foreach ( $form['fields'] as $key => $new_field ) { |
| @@ -435,16 +416,11 @@ | ||
| 435 | 416 | |
| 436 | 417 | /** |
| 437 | 418 | * @since 4.04.03 |
| 438 | 419 | * |
| 439 | - * @param array $action | |
| 440 | 420 | * @param array $form |
| 441 | - * @param int $form_id | |
| 442 | 421 | */ |
| 443 | 422 | protected function save_action( $action, $form, $form_id ) { |
| 444 | - /** | |
| 445 | - * @var FrmFormAction | |
| 446 | - */ | |
| 447 | 423 | $action_control = FrmFormActionsController::get_form_actions( $action['type'] ); |
| 448 | 424 | unset( $action['type'] ); |
| 449 | 425 | $new_action = $action_control->prepare_new( $form_id ); |
| 450 | 426 | foreach ( $action as $key => $value ) { |
| @@ -468,10 +444,10 @@ | ||
| 468 | 444 | * After a form has been successfully imported we track it, so that in the |
| 469 | 445 | * future we can alert users if they try to import a form that has already |
| 470 | 446 | * been imported. |
| 471 | 447 | * |
| 472 | - * @param int $source_id Imported plugin form ID. | |
| 473 | - * @param int $new_form_id Formidable form ID. | |
| 448 | + * @param int $source_id Imported plugin form ID | |
| 449 | + * @param int $new_form_id Formidable form ID | |
| 474 | 450 | */ |
| 475 | 451 | protected function track_import( $source_id, $new_form_id ) { |
| 476 | 452 | |
| 477 | 453 | $imported = $this->get_tracked_import(); |
| @@ -488,9 +464,9 @@ | ||
| 488 | 464 | return get_option( $this->tracking, array() ); |
| 489 | 465 | } |
| 490 | 466 | |
| 491 | 467 | /** |
| 492 | - * @param int $source_id Imported plugin form ID. | |
| 468 | + * @param int $source_id Imported plugin form ID | |
| 493 | 469 | * |
| 494 | 470 | * @return int the ID of the created form or 0 |
| 495 | 471 | */ |
| 496 | 472 | private function is_imported( $source_id ) { |
| @@ -542,9 +518,9 @@ | ||
| 542 | 518 | /** |
| 543 | 519 | * Replace 3rd-party form provider tags/shortcodes with our own Tags. |
| 544 | 520 | * |
| 545 | 521 | * @param string $string String to process the smart tag in. |
| 546 | - * @param array $fields List of fields for the form. | |
| 522 | + * @param array $fields List of fields for the form. | |
| 547 | 523 | * |
| 548 | 524 | * @return string |
| 549 | 525 | */ |
| 550 | 526 | protected function replace_smart_tags( $string, $fields ) { |
| @@ -564,9 +540,9 @@ | ||
| 564 | 540 | return array(); |
| 565 | 541 | } |
| 566 | 542 | |
| 567 | 543 | /** |
| 568 | - * @param array|object $source_form | |
| 544 | + * @param object|array $source_form | |
| 569 | 545 | * |
| 570 | 546 | * @return string |
| 571 | 547 | */ |
| 572 | 548 | protected function get_form_name( $source_form ) { |
| @@ -573,9 +549,9 @@ | ||
| 573 | 549 | return __( 'Default Form', 'formidable' ); |
| 574 | 550 | } |
| 575 | 551 | |
| 576 | 552 | /** |
| 577 | - * @param array|object $source_form | |
| 553 | + * @param object|array $source_form | |
| 578 | 554 | * |
| 579 | 555 | * @return array |
| 580 | 556 | */ |
| 581 | 557 | protected function get_form_fields( $source_form ) { |
| @@ -596,9 +572,9 @@ | ||
| 596 | 572 | * |
| 597 | 573 | * @return string |
| 598 | 574 | */ |
| 599 | 575 | protected function get_field_label( $field ) { |
| 600 | - $label = $field['label'] ?? ''; | |
| 576 | + $label = isset( $field['label'] ) ? $field['label'] : ''; | |
| 601 | 577 | if ( ! empty( $label ) ) { |
| 602 | 578 | return $label; |
| 603 | 579 | } |
| 604 | 580 | |