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