| @@ -5,9 +5,9 @@ | ||
| 5 | 5 | |
| 6 | 6 | class FrmXMLHelper { |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | - * @var bool $installing_template true if importing an XML from API, false if importing an XML file manually. | |
| 9 | + * @var bool true if importing an XML from API, false if importing an XML file manually. | |
| 10 | 10 | */ |
| 11 | 11 | private static $installing_template = false; |
| 12 | 12 | |
| 13 | 13 | public static function get_xml_values( $opt, $padding ) { |
| @@ -91,9 +91,9 @@ | ||
| 91 | 91 | '', |
| 92 | 92 | $content_before_channel_tag, |
| 93 | 93 | 1 |
| 94 | 94 | ); |
| 95 | - $xml_string = $content_before_channel_tag . substr( $xml_string, $channel_start_position ); | |
| 95 | + $xml_string = $content_before_channel_tag . substr( $xml_string, $channel_start_position ); | |
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
| @@ -123,9 +123,9 @@ | ||
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | $imported = apply_filters( 'frm_importing_xml', $imported, $xml ); |
| 126 | 126 | |
| 127 | - if ( ! isset( $imported['form_status'] ) || empty( $imported['form_status'] ) ) { | |
| 127 | + if ( empty( $imported['form_status'] ) ) { | |
| 128 | 128 | // Check for an error message in the XML. |
| 129 | 129 | if ( isset( $xml->Code ) && isset( $xml->Message ) ) { // phpcs:ignore WordPress.NamingConventions |
| 130 | 130 | $imported['error'] = (string) $xml->Message; // phpcs:ignore WordPress.NamingConventions |
| 131 | 131 | } |
| @@ -175,14 +175,14 @@ | ||
| 175 | 175 | ) |
| 176 | 176 | ); |
| 177 | 177 | |
| 178 | 178 | if ( $term && is_array( $term ) ) { |
| 179 | - $imported['imported']['terms'] ++; | |
| 179 | + ++$imported['imported']['terms']; | |
| 180 | 180 | $imported['terms'][ (int) $t->term_id ] = $term['term_id']; |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | unset( $term, $t ); |
| 184 | - } | |
| 184 | + }//end foreach | |
| 185 | 185 | |
| 186 | 186 | return $imported; |
| 187 | 187 | } |
| 188 | 188 | |
| @@ -228,9 +228,9 @@ | ||
| 228 | 228 | $form_id = FrmForm::create( $form ); |
| 229 | 229 | if ( $form_id ) { |
| 230 | 230 | if ( empty( $form['parent_form_id'] ) ) { |
| 231 | 231 | // Don't include the repeater form in the imported count. |
| 232 | - $imported['imported']['forms'] ++; | |
| 232 | + ++$imported['imported']['forms']; | |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | // Keep track of whether this specific form was updated or not. |
| 236 | 236 | $imported['form_status'][ $form_id ] = 'imported'; |
| @@ -255,9 +255,9 @@ | ||
| 255 | 255 | |
| 256 | 256 | do_action( 'frm_after_import_form', $form_id, $form ); |
| 257 | 257 | |
| 258 | 258 | unset( $form, $item ); |
| 259 | - } | |
| 259 | + }//end foreach | |
| 260 | 260 | |
| 261 | 261 | self::maybe_update_child_form_parent_id( $imported['forms'], $child_forms ); |
| 262 | 262 | |
| 263 | 263 | return $imported; |
| @@ -303,9 +303,15 @@ | ||
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | $edit_query = apply_filters( 'frm_match_xml_form', $edit_query, $form ); |
| 306 | 306 | |
| 307 | - return FrmForm::getAll( $edit_query, '', 1 ); | |
| 307 | + $form = FrmForm::getAll( $edit_query, '', 1 ); | |
| 308 | + if ( is_object( $form ) && $form->status === 'trash' ) { | |
| 309 | + FrmForm::destroy( $form->id ); | |
| 310 | + return false; | |
| 311 | + } | |
| 312 | + | |
| 313 | + return $form; | |
| 308 | 314 | } |
| 309 | 315 | |
| 310 | 316 | private static function update_form( $this_form, $form, &$imported ) { |
| 311 | 317 | $form_id = $this_form->id; |
| @@ -311,9 +317,9 @@ | ||
| 311 | 317 | $form_id = $this_form->id; |
| 312 | 318 | FrmForm::update( $form_id, $form ); |
| 313 | 319 | if ( empty( $form['parent_form_id'] ) ) { |
| 314 | 320 | // Don't include the repeater form in the updated count. |
| 315 | - $imported['updated']['forms'] ++; | |
| 321 | + ++$imported['updated']['forms']; | |
| 316 | 322 | } |
| 317 | 323 | |
| 318 | 324 | // Keep track of whether this specific form was updated or not |
| 319 | 325 | $imported['form_status'][ $form_id ] = 'updated'; |
| @@ -374,10 +380,10 @@ | ||
| 374 | 380 | * Keep track of all imported child forms |
| 375 | 381 | * |
| 376 | 382 | * @since 2.0.16 |
| 377 | 383 | * |
| 378 | - * @param int $form_id | |
| 379 | - * @param int $parent_form_id | |
| 384 | + * @param int $form_id | |
| 385 | + * @param int $parent_form_id | |
| 380 | 386 | * @param array $child_forms |
| 381 | 387 | */ |
| 382 | 388 | private static function track_imported_child_forms( $form_id, $parent_form_id, &$child_forms ) { |
| 383 | 389 | if ( $parent_form_id ) { |
| @@ -429,13 +435,13 @@ | ||
| 429 | 435 | if ( ! empty( $this_form ) ) { |
| 430 | 436 | // check for field to edit by field id |
| 431 | 437 | if ( isset( $form_fields[ $f['id'] ] ) ) { |
| 432 | 438 | FrmField::update( $f['id'], $f ); |
| 433 | - $imported['updated']['fields'] ++; | |
| 439 | + ++$imported['updated']['fields']; | |
| 434 | 440 | |
| 435 | 441 | unset( $form_fields[ $f['id'] ] ); |
| 436 | 442 | |
| 437 | - //unset old field key | |
| 443 | + // Unset old field key. | |
| 438 | 444 | if ( isset( $form_fields[ $f['field_key'] ] ) ) { |
| 439 | 445 | unset( $form_fields[ $f['field_key'] ] ); |
| 440 | 446 | } |
| 441 | 447 | } elseif ( isset( $form_fields[ $f['field_key'] ] ) ) { |
| @@ -440,25 +446,32 @@ | ||
| 440 | 446 | } |
| 441 | 447 | } elseif ( isset( $form_fields[ $f['field_key'] ] ) ) { |
| 442 | 448 | $keys_by_original_field_id[ $f['id'] ] = $f['field_key']; |
| 443 | 449 | |
| 450 | + $old_field_id = $f['id']; | |
| 451 | + | |
| 444 | 452 | // check for field to edit by field key |
| 445 | 453 | unset( $f['id'] ); |
| 446 | 454 | |
| 447 | 455 | FrmField::update( $form_fields[ $f['field_key'] ], $f ); |
| 448 | - $imported['updated']['fields'] ++; | |
| 456 | + ++$imported['updated']['fields']; | |
| 449 | 457 | |
| 450 | - unset( $form_fields[ $form_fields[ $f['field_key'] ] ] ); //unset old field id | |
| 451 | - unset( $form_fields[ $f['field_key'] ] ); //unset old field key | |
| 458 | + self::do_after_field_imported_action( $f, $form_fields, $old_field_id ); | |
| 459 | + | |
| 460 | + // Unset old field id. | |
| 461 | + unset( $form_fields[ $form_fields[ $f['field_key'] ] ] ); | |
| 462 | + | |
| 463 | + // Unset old field key. | |
| 464 | + unset( $form_fields[ $f['field_key'] ] ); | |
| 452 | 465 | } else { |
| 453 | - // if no matching field id or key in this form, create the field | |
| 466 | + // If no matching field id or key in this form, create the field. | |
| 454 | 467 | self::create_imported_field( $f, $imported ); |
| 455 | - } | |
| 468 | + }//end if | |
| 456 | 469 | } else { |
| 457 | 470 | |
| 458 | 471 | self::create_imported_field( $f, $imported ); |
| 459 | - } | |
| 460 | - } | |
| 472 | + }//end if | |
| 473 | + }//end foreach | |
| 461 | 474 | |
| 462 | 475 | if ( $keys_by_original_field_id ) { |
| 463 | 476 | self::maybe_update_field_ids( $form_id, $keys_by_original_field_id ); |
| 464 | 477 | } |
| @@ -463,8 +476,46 @@ | ||
| 463 | 476 | self::maybe_update_field_ids( $form_id, $keys_by_original_field_id ); |
| 464 | 477 | } |
| 465 | 478 | } |
| 466 | 479 | |
| 480 | + /** | |
| 481 | + * @since 6.8.4 | |
| 482 | + * | |
| 483 | + * @param array $field_array | |
| 484 | + * @return array | |
| 485 | + */ | |
| 486 | + private static function update_field_options_with_defaults( $field_array ) { | |
| 487 | + $defaults = self::default_field_options( $field_array['type'] ); | |
| 488 | + $field_array['field_options'] = array_merge( $defaults, $field_array['field_options'] ); | |
| 489 | + | |
| 490 | + return $field_array; | |
| 491 | + } | |
| 492 | + | |
| 493 | + /** | |
| 494 | + * @since 6.8.4 | |
| 495 | + * | |
| 496 | + * @param array $field_array | |
| 497 | + * @param array $form_fields | |
| 498 | + * @param int $old_field_id | |
| 499 | + * | |
| 500 | + * @return void | |
| 501 | + */ | |
| 502 | + private static function do_after_field_imported_action( $field_array, $form_fields, $old_field_id ) { | |
| 503 | + // Assign field array the update field's ID. | |
| 504 | + $field_array['id'] = $form_fields[ $field_array['field_key'] ]; | |
| 505 | + | |
| 506 | + /** | |
| 507 | + * Fires when an existing field is imported. | |
| 508 | + * | |
| 509 | + * @since 6.8.4 | |
| 510 | + * | |
| 511 | + * @param array $field_array | |
| 512 | + * @param int $field_id | |
| 513 | + * @param int $old_field_id | |
| 514 | + */ | |
| 515 | + do_action( 'frm_after_existing_field_is_imported', $field_array, $form_fields[ $field_array['field_key'] ], $old_field_id ); | |
| 516 | + } | |
| 517 | + | |
| 467 | 518 | private static function fill_field( $field, $form_id ) { |
| 468 | 519 | return array( |
| 469 | 520 | 'id' => (int) $field->id, |
| 470 | 521 | 'field_key' => (string) $field->field_key, |
| @@ -520,9 +571,9 @@ | ||
| 520 | 571 | /** |
| 521 | 572 | * Update the current in_section value at the beginning of the field loop |
| 522 | 573 | * |
| 523 | 574 | * @since 2.0.25 |
| 524 | - * @param int $in_section | |
| 575 | + * @param int $in_section | |
| 525 | 576 | * @param array $f |
| 526 | 577 | */ |
| 527 | 578 | private static function maybe_update_in_section_variable( &$in_section, &$f ) { |
| 528 | 579 | // If we're at the end of a section, switch $in_section is 0 |
| @@ -535,9 +586,9 @@ | ||
| 535 | 586 | $f['field_options']['in_section'] = $in_section; |
| 536 | 587 | } |
| 537 | 588 | |
| 538 | 589 | // If we're starting a new section, switch $in_section to ID of divider |
| 539 | - if ( $f['type'] == 'divider' ) { | |
| 590 | + if ( $f['type'] === 'divider' ) { | |
| 540 | 591 | $in_section = $f['id']; |
| 541 | 592 | } |
| 542 | 593 | } |
| 543 | 594 | |
| @@ -553,9 +604,9 @@ | ||
| 553 | 604 | if ( ! isset( $imported['forms'] ) ) { |
| 554 | 605 | return; |
| 555 | 606 | } |
| 556 | 607 | |
| 557 | - if ( $f['type'] == 'form' || ( $f['type'] == 'divider' && FrmField::is_option_true( $f['field_options'], 'repeat' ) ) ) { | |
| 608 | + if ( $f['type'] === 'form' || ( $f['type'] === 'divider' && FrmField::is_option_true( $f['field_options'], 'repeat' ) ) ) { | |
| 558 | 609 | if ( FrmField::is_option_true( $f['field_options'], 'form_select' ) ) { |
| 559 | 610 | $form_select = (int) $f['field_options']['form_select']; |
| 560 | 611 | if ( isset( $imported['forms'][ $form_select ] ) ) { |
| 561 | 612 | $f['field_options']['form_select'] = $imported['forms'][ $form_select ]; |
| @@ -617,9 +668,9 @@ | ||
| 617 | 668 | * @since 4.0 |
| 618 | 669 | * @return array |
| 619 | 670 | */ |
| 620 | 671 | public static function migrate_field_placeholder( $field, $type ) { |
| 621 | - $field = (array) $field; | |
| 672 | + $field = (array) $field; | |
| 622 | 673 | $field_options = $field['field_options']; |
| 623 | 674 | if ( empty( $field_options[ $type ] ) || empty( $field['default_value'] ) ) { |
| 624 | 675 | return array(); |
| 625 | 676 | } |
| @@ -664,10 +715,9 @@ | ||
| 664 | 715 | * @param array $f |
| 665 | 716 | * @param array $imported |
| 666 | 717 | */ |
| 667 | 718 | private static function create_imported_field( $f, &$imported ) { |
| 668 | - $defaults = self::default_field_options( $f['type'] ); | |
| 669 | - $f['field_options'] = array_merge( $defaults, $f['field_options'] ); | |
| 719 | + $f = self::update_field_options_with_defaults( $f ); | |
| 670 | 720 | |
| 671 | 721 | if ( is_callable( 'FrmProFileImport::import_attachment' ) ) { |
| 672 | 722 | $f = self::maybe_import_images_for_options( $f ); |
| 673 | 723 | } |
| @@ -673,9 +723,9 @@ | ||
| 673 | 723 | } |
| 674 | 724 | |
| 675 | 725 | $new_id = FrmField::create( $f ); |
| 676 | 726 | if ( $new_id != false ) { |
| 677 | - $imported['imported']['fields'] ++; | |
| 727 | + ++$imported['imported']['fields']; | |
| 678 | 728 | do_action( 'frm_after_field_is_imported', $f, $new_id ); |
| 679 | 729 | } |
| 680 | 730 | } |
| 681 | 731 | |
| @@ -696,13 +746,15 @@ | ||
| 696 | 746 | if ( ! is_array( $option ) || empty( $option['src'] ) ) { |
| 697 | 747 | continue; |
| 698 | 748 | } |
| 699 | 749 | |
| 700 | - $field_object = (object) $field; | |
| 701 | - $field_object->type = 'file'; // Fake the file type as FrmProImport::import_attachment checks for file type. | |
| 750 | + $field_object = (object) $field; | |
| 751 | + // Fake the file type as FrmProImport::import_attachment checks for file type. | |
| 752 | + $field_object->type = 'file'; | |
| 702 | 753 | |
| 703 | 754 | $image_id = FrmProFileImport::import_attachment( $option['src'], $field_object ); |
| 704 | - unset( $field['options'][ $key ]['src'] ); // Remove the src from options as it isn't required after import. | |
| 755 | + // Remove the src from options as it isn't required after import. | |
| 756 | + unset( $field['options'][ $key ]['src'] ); | |
| 705 | 757 | |
| 706 | 758 | if ( is_numeric( $image_id ) ) { |
| 707 | 759 | $field['options'][ $key ]['image'] = $image_id; |
| 708 | 760 | } |
| @@ -714,9 +766,9 @@ | ||
| 714 | 766 | /** |
| 715 | 767 | * Fix field ids for fields that already exist prior to import. |
| 716 | 768 | * |
| 717 | 769 | * @since 4.07 |
| 718 | - * @param int $form_id | |
| 770 | + * @param int $form_id | |
| 719 | 771 | * @param array $keys_by_original_field_id |
| 720 | 772 | */ |
| 721 | 773 | protected static function maybe_update_field_ids( $form_id, $keys_by_original_field_id ) { |
| 722 | 774 | global $frm_duplicate_ids; |
| @@ -786,9 +838,9 @@ | ||
| 786 | 838 | |
| 787 | 839 | // Set to default |
| 788 | 840 | $form['options']['custom_style'] = 1; |
| 789 | 841 | } |
| 790 | - } | |
| 842 | + }//end if | |
| 791 | 843 | } |
| 792 | 844 | |
| 793 | 845 | /** |
| 794 | 846 | * After styles are imported, check for any forms that were linked |
| @@ -876,9 +928,9 @@ | ||
| 876 | 928 | $post['post_parent'] = $imported['posts'][ $post['post_parent'] ]; |
| 877 | 929 | } |
| 878 | 930 | // Create/update post now |
| 879 | 931 | $post_id = wp_insert_post( $post ); |
| 880 | - } | |
| 932 | + }//end if | |
| 881 | 933 | |
| 882 | 934 | if ( ! is_numeric( $post_id ) ) { |
| 883 | 935 | continue; |
| 884 | 936 | } |
| @@ -895,23 +947,23 @@ | ||
| 895 | 947 | $this_type = $post_types[ $post['post_type'] ]; |
| 896 | 948 | } |
| 897 | 949 | |
| 898 | 950 | if ( isset( $post['ID'] ) && $post_id == $post['ID'] ) { |
| 899 | - $imported['updated'][ $this_type ] ++; | |
| 951 | + ++$imported['updated'][ $this_type ]; | |
| 900 | 952 | } else { |
| 901 | - $imported['imported'][ $this_type ] ++; | |
| 953 | + ++$imported['imported'][ $this_type ]; | |
| 902 | 954 | } |
| 903 | 955 | |
| 904 | - $imported['posts'][ (int) $old_id ] = $post_id; | |
| 956 | + $imported['posts'][ $old_id ] = $post_id; | |
| 905 | 957 | |
| 906 | 958 | if ( $post['post_type'] === 'frm_display' ) { |
| 907 | - $view_ids[ (int) $old_id ] = $post_id; | |
| 959 | + $view_ids[ $old_id ] = $post_id; | |
| 908 | 960 | } |
| 909 | 961 | |
| 910 | 962 | do_action( 'frm_after_import_view', $post_id, $post ); |
| 911 | 963 | |
| 912 | 964 | unset( $post ); |
| 913 | - } | |
| 965 | + }//end foreach | |
| 914 | 966 | |
| 915 | 967 | if ( $posts_with_shortcodes && $view_ids ) { |
| 916 | 968 | self::maybe_switch_view_ids_after_importing_posts( $posts_with_shortcodes, $view_ids ); |
| 917 | 969 | } |
| @@ -935,9 +987,9 @@ | ||
| 935 | 987 | * @param array $imported_forms |
| 936 | 988 | */ |
| 937 | 989 | private static function clear_forms_style_caches( $imported_forms ) { |
| 938 | 990 | $where = array( |
| 939 | - 'id' => $imported_forms, | |
| 991 | + 'id' => $imported_forms, | |
| 940 | 992 | 'options LIKE' => '"old_style"', |
| 941 | 993 | ); |
| 942 | 994 | $forms = FrmDb::get_results( 'frm_forms', $where ); |
| 943 | 995 | |
| @@ -1102,9 +1154,9 @@ | ||
| 1102 | 1154 | 'key' => (string) $meta->meta_key, |
| 1103 | 1155 | 'value' => (string) $meta->meta_value, |
| 1104 | 1156 | ); |
| 1105 | 1157 | |
| 1106 | - //switch old form and field ids to new ones | |
| 1158 | + // Switch old form and field ids to new ones. | |
| 1107 | 1159 | if ( 'frm_form_id' === $m['key'] && isset( $imported['forms'][ (int) $m['value'] ] ) ) { |
| 1108 | 1160 | $m['value'] = $imported['forms'][ (int) $m['value'] ]; |
| 1109 | 1161 | } else { |
| 1110 | 1162 | $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] ); |
| @@ -1120,10 +1172,26 @@ | ||
| 1120 | 1172 | $m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ]; |
| 1121 | 1173 | } |
| 1122 | 1174 | } |
| 1123 | 1175 | |
| 1176 | + if ( ! empty( $m['value']['map_address_fields'] ) ) { | |
| 1177 | + foreach ( $m['value']['map_address_fields'] as $address_field_key => $address_field_id ) { | |
| 1178 | + if ( isset( $frm_duplicate_ids[ $address_field_id ] ) ) { | |
| 1179 | + $m['value']['map_address_fields'][ $address_field_key ] = $frm_duplicate_ids[ $address_field_id ]; | |
| 1180 | + } | |
| 1181 | + } | |
| 1182 | + } | |
| 1183 | + | |
| 1184 | + if ( ! empty( $m['value']['calendar_options'] ) ) { | |
| 1185 | + foreach ( $m['value']['calendar_options'] as $calendar_option_group_key => $calendar_option ) { | |
| 1186 | + if ( isset( $frm_duplicate_ids[ $calendar_option['value'] ] ) ) { | |
| 1187 | + $m['value']['calendar_options'][ $calendar_option_group_key ]['value'] = $frm_duplicate_ids[ $calendar_option['value'] ]; | |
| 1188 | + } | |
| 1189 | + } | |
| 1190 | + } | |
| 1191 | + | |
| 1124 | 1192 | $check_dup_array = array(); |
| 1125 | - if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) { | |
| 1193 | + if ( ! empty( $m['value']['order_by'] ) ) { | |
| 1126 | 1194 | if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) { |
| 1127 | 1195 | $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ]; |
| 1128 | 1196 | } elseif ( is_array( $m['value']['order_by'] ) ) { |
| 1129 | 1197 | $check_dup_array[] = 'order_by'; |
| @@ -1129,9 +1197,9 @@ | ||
| 1129 | 1197 | $check_dup_array[] = 'order_by'; |
| 1130 | 1198 | } |
| 1131 | 1199 | } |
| 1132 | 1200 | |
| 1133 | - if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) { | |
| 1201 | + if ( ! empty( $m['value']['where'] ) ) { | |
| 1134 | 1202 | $check_dup_array[] = 'where'; |
| 1135 | 1203 | } |
| 1136 | 1204 | |
| 1137 | 1205 | foreach ( $check_dup_array as $check_k ) { |
| @@ -1141,11 +1209,11 @@ | ||
| 1141 | 1209 | } |
| 1142 | 1210 | unset( $mk, $mv ); |
| 1143 | 1211 | } |
| 1144 | 1212 | } |
| 1145 | - } | |
| 1146 | - } | |
| 1147 | - } | |
| 1213 | + }//end if | |
| 1214 | + }//end if | |
| 1215 | + }//end if | |
| 1148 | 1216 | |
| 1149 | 1217 | if ( ! is_array( $m['value'] ) ) { |
| 1150 | 1218 | $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] ); |
| 1151 | 1219 | } |
| @@ -1159,10 +1227,10 @@ | ||
| 1159 | 1227 | |
| 1160 | 1228 | /** |
| 1161 | 1229 | * Add terms to post |
| 1162 | 1230 | * |
| 1163 | - * @param array $post by reference | |
| 1164 | - * @param object $item The XML object data | |
| 1231 | + * @param array $post By reference. | |
| 1232 | + * @param object $item The XML object data. | |
| 1165 | 1233 | */ |
| 1166 | 1234 | private static function populate_taxonomies( &$post, $item ) { |
| 1167 | 1235 | foreach ( $item->category as $c ) { |
| 1168 | 1236 | $att = $c->attributes(); |
| @@ -1187,9 +1255,9 @@ | ||
| 1187 | 1255 | } |
| 1188 | 1256 | |
| 1189 | 1257 | $post['tax_input'][ $taxonomy ][] = $name; |
| 1190 | 1258 | unset( $name ); |
| 1191 | - } | |
| 1259 | + }//end foreach | |
| 1192 | 1260 | } |
| 1193 | 1261 | |
| 1194 | 1262 | /** |
| 1195 | 1263 | * Edit post if the key and created time match |
| @@ -1243,13 +1311,13 @@ | ||
| 1243 | 1311 | |
| 1244 | 1312 | case 'frm_param': |
| 1245 | 1313 | add_rewrite_endpoint( $v, EP_PERMALINK | EP_PAGES ); |
| 1246 | 1314 | break; |
| 1247 | - } | |
| 1315 | + }//end switch | |
| 1248 | 1316 | |
| 1249 | 1317 | update_post_meta( $post_id, $k, $v ); |
| 1250 | 1318 | unset( $k, $v ); |
| 1251 | - } | |
| 1319 | + }//end foreach | |
| 1252 | 1320 | } |
| 1253 | 1321 | |
| 1254 | 1322 | /** |
| 1255 | 1323 | * @param array $post |
| @@ -1265,10 +1333,10 @@ | ||
| 1265 | 1333 | } |
| 1266 | 1334 | } |
| 1267 | 1335 | |
| 1268 | 1336 | private static function maybe_update_stylesheet( $imported ) { |
| 1269 | - $new_styles = isset( $imported['imported']['styles'] ) && ! empty( $imported['imported']['styles'] ); | |
| 1270 | - $updated_styles = isset( $imported['updated']['styles'] ) && ! empty( $imported['updated']['styles'] ); | |
| 1337 | + $new_styles = ! empty( $imported['imported']['styles'] ); | |
| 1338 | + $updated_styles = ! empty( $imported['updated']['styles'] ); | |
| 1271 | 1339 | if ( $new_styles || $updated_styles ) { |
| 1272 | 1340 | if ( is_admin() && function_exists( 'get_filesystem_method' ) ) { |
| 1273 | 1341 | $frm_style = new FrmStyle(); |
| 1274 | 1342 | $frm_style->update( 'default' ); |
| @@ -1279,9 +1347,11 @@ | ||
| 1279 | 1347 | } |
| 1280 | 1348 | } |
| 1281 | 1349 | |
| 1282 | 1350 | /** |
| 1351 | + * @param mixed $result | |
| 1283 | 1352 | * @param string $message |
| 1353 | + * @param array $errors | |
| 1284 | 1354 | */ |
| 1285 | 1355 | public static function parse_message( $result, &$message, &$errors ) { |
| 1286 | 1356 | if ( is_wp_error( $result ) ) { |
| 1287 | 1357 | $errors[] = $result->get_error_message(); |
| @@ -1287,9 +1357,9 @@ | ||
| 1287 | 1357 | $errors[] = $result->get_error_message(); |
| 1288 | 1358 | |
| 1289 | 1359 | // Remove the SimpleXML_parse_error from the WP_Error object to avoid |
| 1290 | 1360 | // displaying duplicate error messages from $result->get_error_message() |
| 1291 | - $error_codes = $result->get_error_codes(); | |
| 1361 | + $error_codes = $result->get_error_codes(); | |
| 1292 | 1362 | $error_details = array(); |
| 1293 | 1363 | foreach ( $error_codes as $error_code ) { |
| 1294 | 1364 | // Clone WP_Error data because WP_Error removes all error messages and data |
| 1295 | 1365 | // associated with the specified error code when an item is removed. |
| @@ -1305,15 +1375,16 @@ | ||
| 1305 | 1375 | $errors[] = '<br />' . esc_html_x( 'Error details:', 'import xml message', 'formidable' ) . '<br />' . esc_html( print_r( $error_details, 1 ) ); |
| 1306 | 1376 | } |
| 1307 | 1377 | |
| 1308 | 1378 | return; |
| 1309 | - } elseif ( ! $result ) { | |
| 1379 | + }//end if | |
| 1380 | + | |
| 1381 | + if ( ! $result ) { | |
| 1310 | 1382 | return; |
| 1311 | 1383 | } |
| 1312 | 1384 | |
| 1313 | 1385 | if ( ! is_array( $result ) ) { |
| 1314 | 1386 | $message = is_string( $result ) ? $result : htmlentities( print_r( $result, 1 ) ); |
| 1315 | - | |
| 1316 | 1387 | return; |
| 1317 | 1388 | } |
| 1318 | 1389 | |
| 1319 | 1390 | $t_strings = array( |
| @@ -1340,9 +1411,9 @@ | ||
| 1340 | 1411 | $message .= '</li>'; |
| 1341 | 1412 | } |
| 1342 | 1413 | } |
| 1343 | 1414 | |
| 1344 | - if ( $message == '<ul>' ) { | |
| 1415 | + if ( $message === '<ul>' ) { | |
| 1345 | 1416 | $message = ''; |
| 1346 | 1417 | $errors[] = __( 'Nothing was imported or updated', 'formidable' ); |
| 1347 | 1418 | } else { |
| 1348 | 1419 | self::add_form_link_to_message( $result, $message ); |
| @@ -1646,9 +1717,13 @@ | ||
| 1646 | 1717 | |
| 1647 | 1718 | /** |
| 1648 | 1719 | * Migrate post settings to form action |
| 1649 | 1720 | * |
| 1721 | + * @param array $form_options | |
| 1722 | + * @param int $form_id | |
| 1650 | 1723 | * @param string $post_type |
| 1724 | + * @param array $imported | |
| 1725 | + * @param bool $switch | |
| 1651 | 1726 | */ |
| 1652 | 1727 | private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) { |
| 1653 | 1728 | if ( ! isset( $form_options['create_post'] ) || ! $form_options['create_post'] ) { |
| 1654 | 1729 | return; |
| @@ -1717,9 +1792,9 @@ | ||
| 1717 | 1792 | |
| 1718 | 1793 | if ( ! $exists ) { |
| 1719 | 1794 | // this isn't an email, but we need to use a class that will always be included |
| 1720 | 1795 | FrmDb::save_json_post( $new_action ); |
| 1721 | - $imported['imported']['actions'] ++; | |
| 1796 | + ++$imported['imported']['actions']; | |
| 1722 | 1797 | } |
| 1723 | 1798 | } |
| 1724 | 1799 | |
| 1725 | 1800 | /** |
| @@ -1726,11 +1801,11 @@ | ||
| 1726 | 1801 | * Switch old field IDs for new field IDs in emails and post |
| 1727 | 1802 | * |
| 1728 | 1803 | * @since 2.0 |
| 1729 | 1804 | * |
| 1730 | - * @param array $post_content - check for old field IDs | |
| 1731 | - * @param array $basic_fields - fields with string or int saved | |
| 1732 | - * @param array $array_fields - fields with arrays saved | |
| 1805 | + * @param array $post_content Check for old field IDs. | |
| 1806 | + * @param array $basic_fields Fields with string or int saved. | |
| 1807 | + * @param array $array_fields Fields with arrays saved. | |
| 1733 | 1808 | * |
| 1734 | 1809 | * @return string $post_content - new field IDs |
| 1735 | 1810 | */ |
| 1736 | 1811 | private static function switch_action_field_ids( $post_content, $basic_fields, $array_fields = array() ) { |
| @@ -1811,12 +1886,12 @@ | ||
| 1811 | 1886 | ); |
| 1812 | 1887 | |
| 1813 | 1888 | if ( empty( $exists ) ) { |
| 1814 | 1889 | FrmDb::save_json_post( $new_notification ); |
| 1815 | - $imported['imported']['actions'] ++; | |
| 1890 | + ++$imported['imported']['actions']; | |
| 1816 | 1891 | } |
| 1817 | 1892 | unset( $new_notification ); |
| 1818 | - } | |
| 1893 | + }//end foreach | |
| 1819 | 1894 | |
| 1820 | 1895 | self::remove_deprecated_notification_settings( $form_id, $form_options ); |
| 1821 | 1896 | } |
| 1822 | 1897 | |
| @@ -1825,9 +1900,9 @@ | ||
| 1825 | 1900 | * |
| 1826 | 1901 | * @since 2.05 |
| 1827 | 1902 | * |
| 1828 | 1903 | * @param int|string $form_id |
| 1829 | - * @param array $form_options | |
| 1904 | + * @param array $form_options | |
| 1830 | 1905 | */ |
| 1831 | 1906 | private static function remove_deprecated_notification_settings( $form_id, $form_options ) { |
| 1832 | 1907 | $delete_settings = array( 'notification', 'autoresponder', 'email_to' ); |
| 1833 | 1908 | foreach ( $delete_settings as $index ) { |
| @@ -1838,9 +1913,9 @@ | ||
| 1838 | 1913 | FrmForm::update( $form_id, array( 'options' => $form_options ) ); |
| 1839 | 1914 | } |
| 1840 | 1915 | |
| 1841 | 1916 | private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) { |
| 1842 | - if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) { | |
| 1917 | + if ( ! isset( $form_options['notification'] ) && ! empty( $form_options['email_to'] ) ) { | |
| 1843 | 1918 | // add old settings into notification array |
| 1844 | 1919 | $form_options['notification'] = array( 0 => $form_options ); |
| 1845 | 1920 | } elseif ( isset( $form_options['notification']['email_to'] ) ) { |
| 1846 | 1921 | // make sure it's in the correct format |
| @@ -1870,10 +1945,10 @@ | ||
| 1870 | 1945 | $new_notification = array(); |
| 1871 | 1946 | self::setup_new_notification( $new_notification, $notification, $atts ); |
| 1872 | 1947 | |
| 1873 | 1948 | $notifications[] = $new_notification; |
| 1874 | - } | |
| 1875 | - } | |
| 1949 | + }//end foreach | |
| 1950 | + }//end if | |
| 1876 | 1951 | } |
| 1877 | 1952 | |
| 1878 | 1953 | private static function format_email_data( &$atts, $notification ) { |
| 1879 | 1954 | // Format email_to |
| @@ -1969,9 +2044,9 @@ | ||
| 1969 | 2044 | |
| 1970 | 2045 | /** |
| 1971 | 2046 | * Switch field IDs in pre-2.0 email conditional logic |
| 1972 | 2047 | * |
| 1973 | - * @param $post_content array, pass by reference | |
| 2048 | + * @param array $post_content Pass by reference. | |
| 1974 | 2049 | */ |
| 1975 | 2050 | private static function switch_email_condition_field_ids( &$post_content ) { |
| 1976 | 2051 | // Switch field IDs in conditional logic |
| 1977 | 2052 | if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) { |
| @@ -2024,17 +2099,17 @@ | ||
| 2024 | 2099 | } |
| 2025 | 2100 | |
| 2026 | 2101 | $notifications[] = $new_notification2; |
| 2027 | 2102 | unset( $new_notification2 ); |
| 2028 | - } | |
| 2103 | + }//end if | |
| 2029 | 2104 | } |
| 2030 | 2105 | |
| 2031 | 2106 | /** |
| 2032 | 2107 | * PHP 8 backward compatibility for the libxml_disable_entity_loader function |
| 2033 | 2108 | * |
| 2034 | - * @param boolean $disable | |
| 2109 | + * @param bool $loader | |
| 2035 | 2110 | * |
| 2036 | - * @return boolean | |
| 2111 | + * @return bool | |
| 2037 | 2112 | */ |
| 2038 | 2113 | public static function maybe_libxml_disable_entity_loader( $loader ) { |
| 2039 | 2114 | if ( version_compare( phpversion(), '8.0', '<' ) && function_exists( 'libxml_disable_entity_loader' ) ) { |
| 2040 | 2115 | $loader = libxml_disable_entity_loader( $loader ); // phpcs:disable Generic.PHP.DeprecatedFunctions.Deprecated |
| @@ -2045,6 +2120,22 @@ | ||
| 2045 | 2120 | |
| 2046 | 2121 | public static function check_if_libxml_disable_entity_loader_exists() { |
| 2047 | 2122 | return version_compare( phpversion(), '8.0', '<' ) && ! function_exists( 'libxml_disable_entity_loader' ); |
| 2048 | 2123 | } |
| 2124 | + | |
| 2125 | + /** | |
| 2126 | + * Get the file types allowed for importing. | |
| 2127 | + * This is used in the "accept" attribute for the file upload input on the XML import page. | |
| 2128 | + * | |
| 2129 | + * @since 6.8.3 | |
| 2130 | + * | |
| 2131 | + * @return array | |
| 2132 | + */ | |
| 2133 | + public static function get_supported_upload_file_types() { | |
| 2134 | + $file_types = array( '.xml' ); | |
| 2135 | + if ( FrmAppHelper::pro_is_installed() ) { | |
| 2136 | + // CSV Importing is only available in Pro. | |
| 2137 | + $file_types[] = '.csv'; | |
| 2138 | + } | |
| 2139 | + return $file_types; | |
| 2140 | + } | |
| 2049 | 2141 | } |
| 2050 | - | |