| @@ -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 ) { |
| @@ -26,8 +26,12 @@ | ||
| 26 | 26 | echo self::cdata( $opt ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 27 | 27 | } |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | + /** | |
| 31 | + * @param string $file | |
| 32 | + * @return array|WP_Error The items imported | |
| 33 | + */ | |
| 30 | 34 | public static function import_xml( $file ) { |
| 31 | 35 | if ( ! defined( 'WP_IMPORTING' ) ) { |
| 32 | 36 | define( 'WP_IMPORTING', true ); |
| 33 | 37 | } |
| @@ -91,9 +95,9 @@ | ||
| 91 | 95 | '', |
| 92 | 96 | $content_before_channel_tag, |
| 93 | 97 | 1 |
| 94 | 98 | ); |
| 95 | - $xml_string = $content_before_channel_tag . substr( $xml_string, $channel_start_position ); | |
| 99 | + $xml_string = $content_before_channel_tag . substr( $xml_string, $channel_start_position ); | |
| 96 | 100 | } |
| 97 | 101 | } |
| 98 | 102 | |
| 99 | 103 | /** |
| @@ -123,9 +127,9 @@ | ||
| 123 | 127 | } |
| 124 | 128 | |
| 125 | 129 | $imported = apply_filters( 'frm_importing_xml', $imported, $xml ); |
| 126 | 130 | |
| 127 | - if ( ! isset( $imported['form_status'] ) || empty( $imported['form_status'] ) ) { | |
| 131 | + if ( empty( $imported['form_status'] ) ) { | |
| 128 | 132 | // Check for an error message in the XML. |
| 129 | 133 | if ( isset( $xml->Code ) && isset( $xml->Message ) ) { // phpcs:ignore WordPress.NamingConventions |
| 130 | 134 | $imported['error'] = (string) $xml->Message; // phpcs:ignore WordPress.NamingConventions |
| 131 | 135 | } |
| @@ -156,8 +160,13 @@ | ||
| 156 | 160 | 'terms' => array(), |
| 157 | 161 | ); |
| 158 | 162 | } |
| 159 | 163 | |
| 164 | + /** | |
| 165 | + * @param SimpleXMLElement $terms | |
| 166 | + * @param array $imported | |
| 167 | + * @return array | |
| 168 | + */ | |
| 160 | 169 | public static function import_xml_terms( $terms, $imported ) { |
| 161 | 170 | foreach ( $terms as $t ) { |
| 162 | 171 | if ( term_exists( (string) $t->term_slug, (string) $t->term_taxonomy ) ) { |
| 163 | 172 | continue; |
| @@ -175,14 +184,14 @@ | ||
| 175 | 184 | ) |
| 176 | 185 | ); |
| 177 | 186 | |
| 178 | 187 | if ( $term && is_array( $term ) ) { |
| 179 | - $imported['imported']['terms'] ++; | |
| 188 | + ++$imported['imported']['terms']; | |
| 180 | 189 | $imported['terms'][ (int) $t->term_id ] = $term['term_id']; |
| 181 | 190 | } |
| 182 | 191 | |
| 183 | 192 | unset( $term, $t ); |
| 184 | - } | |
| 193 | + }//end foreach | |
| 185 | 194 | |
| 186 | 195 | return $imported; |
| 187 | 196 | } |
| 188 | 197 | |
| @@ -187,8 +196,11 @@ | ||
| 187 | 196 | } |
| 188 | 197 | |
| 189 | 198 | /** |
| 190 | 199 | * @since 2.0.8 |
| 200 | + * | |
| 201 | + * @param object $t | |
| 202 | + * @return int|string | |
| 191 | 203 | */ |
| 192 | 204 | private static function get_term_parent_id( $t ) { |
| 193 | 205 | $parent = (string) $t->term_parent; |
| 194 | 206 | if ( ! empty( $parent ) ) { |
| @@ -202,8 +214,13 @@ | ||
| 202 | 214 | |
| 203 | 215 | return $parent; |
| 204 | 216 | } |
| 205 | 217 | |
| 218 | + /** | |
| 219 | + * @param SimpleXMLElement $forms | |
| 220 | + * @param array $imported | |
| 221 | + * @return array | |
| 222 | + */ | |
| 206 | 223 | public static function import_xml_forms( $forms, $imported ) { |
| 207 | 224 | $child_forms = array(); |
| 208 | 225 | |
| 209 | 226 | // Import child forms first |
| @@ -228,9 +245,9 @@ | ||
| 228 | 245 | $form_id = FrmForm::create( $form ); |
| 229 | 246 | if ( $form_id ) { |
| 230 | 247 | if ( empty( $form['parent_form_id'] ) ) { |
| 231 | 248 | // Don't include the repeater form in the imported count. |
| 232 | - $imported['imported']['forms'] ++; | |
| 249 | + ++$imported['imported']['forms']; | |
| 233 | 250 | } |
| 234 | 251 | |
| 235 | 252 | // Keep track of whether this specific form was updated or not. |
| 236 | 253 | $imported['form_status'][ $form_id ] = 'imported'; |
| @@ -255,9 +272,9 @@ | ||
| 255 | 272 | |
| 256 | 273 | do_action( 'frm_after_import_form', $form_id, $form ); |
| 257 | 274 | |
| 258 | 275 | unset( $form, $item ); |
| 259 | - } | |
| 276 | + }//end foreach | |
| 260 | 277 | |
| 261 | 278 | self::maybe_update_child_form_parent_id( $imported['forms'], $child_forms ); |
| 262 | 279 | |
| 263 | 280 | return $imported; |
| @@ -303,9 +320,15 @@ | ||
| 303 | 320 | } |
| 304 | 321 | |
| 305 | 322 | $edit_query = apply_filters( 'frm_match_xml_form', $edit_query, $form ); |
| 306 | 323 | |
| 307 | - return FrmForm::getAll( $edit_query, '', 1 ); | |
| 324 | + $form = FrmForm::getAll( $edit_query, '', 1 ); | |
| 325 | + if ( is_object( $form ) && $form->status === 'trash' ) { | |
| 326 | + FrmForm::destroy( $form->id ); | |
| 327 | + return false; | |
| 328 | + } | |
| 329 | + | |
| 330 | + return $form; | |
| 308 | 331 | } |
| 309 | 332 | |
| 310 | 333 | private static function update_form( $this_form, $form, &$imported ) { |
| 311 | 334 | $form_id = $this_form->id; |
| @@ -311,9 +334,9 @@ | ||
| 311 | 334 | $form_id = $this_form->id; |
| 312 | 335 | FrmForm::update( $form_id, $form ); |
| 313 | 336 | if ( empty( $form['parent_form_id'] ) ) { |
| 314 | 337 | // Don't include the repeater form in the updated count. |
| 315 | - $imported['updated']['forms'] ++; | |
| 338 | + ++$imported['updated']['forms']; | |
| 316 | 339 | } |
| 317 | 340 | |
| 318 | 341 | // Keep track of whether this specific form was updated or not |
| 319 | 342 | $imported['form_status'][ $form_id ] = 'updated'; |
| @@ -374,10 +397,10 @@ | ||
| 374 | 397 | * Keep track of all imported child forms |
| 375 | 398 | * |
| 376 | 399 | * @since 2.0.16 |
| 377 | 400 | * |
| 378 | - * @param int $form_id | |
| 379 | - * @param int $parent_form_id | |
| 401 | + * @param int $form_id | |
| 402 | + * @param int $parent_form_id | |
| 380 | 403 | * @param array $child_forms |
| 381 | 404 | */ |
| 382 | 405 | private static function track_imported_child_forms( $form_id, $parent_form_id, &$child_forms ) { |
| 383 | 406 | if ( $parent_form_id ) { |
| @@ -429,13 +452,13 @@ | ||
| 429 | 452 | if ( ! empty( $this_form ) ) { |
| 430 | 453 | // check for field to edit by field id |
| 431 | 454 | if ( isset( $form_fields[ $f['id'] ] ) ) { |
| 432 | 455 | FrmField::update( $f['id'], $f ); |
| 433 | - $imported['updated']['fields'] ++; | |
| 456 | + ++$imported['updated']['fields']; | |
| 434 | 457 | |
| 435 | 458 | unset( $form_fields[ $f['id'] ] ); |
| 436 | 459 | |
| 437 | - //unset old field key | |
| 460 | + // Unset old field key. | |
| 438 | 461 | if ( isset( $form_fields[ $f['field_key'] ] ) ) { |
| 439 | 462 | unset( $form_fields[ $f['field_key'] ] ); |
| 440 | 463 | } |
| 441 | 464 | } elseif ( isset( $form_fields[ $f['field_key'] ] ) ) { |
| @@ -440,25 +463,32 @@ | ||
| 440 | 463 | } |
| 441 | 464 | } elseif ( isset( $form_fields[ $f['field_key'] ] ) ) { |
| 442 | 465 | $keys_by_original_field_id[ $f['id'] ] = $f['field_key']; |
| 443 | 466 | |
| 467 | + $old_field_id = $f['id']; | |
| 468 | + | |
| 444 | 469 | // check for field to edit by field key |
| 445 | 470 | unset( $f['id'] ); |
| 446 | 471 | |
| 447 | 472 | FrmField::update( $form_fields[ $f['field_key'] ], $f ); |
| 448 | - $imported['updated']['fields'] ++; | |
| 473 | + ++$imported['updated']['fields']; | |
| 449 | 474 | |
| 450 | - unset( $form_fields[ $form_fields[ $f['field_key'] ] ] ); //unset old field id | |
| 451 | - unset( $form_fields[ $f['field_key'] ] ); //unset old field key | |
| 475 | + self::do_after_field_imported_action( $f, $form_fields, $old_field_id ); | |
| 476 | + | |
| 477 | + // Unset old field id. | |
| 478 | + unset( $form_fields[ $form_fields[ $f['field_key'] ] ] ); | |
| 479 | + | |
| 480 | + // Unset old field key. | |
| 481 | + unset( $form_fields[ $f['field_key'] ] ); | |
| 452 | 482 | } else { |
| 453 | - // if no matching field id or key in this form, create the field | |
| 483 | + // If no matching field id or key in this form, create the field. | |
| 454 | 484 | self::create_imported_field( $f, $imported ); |
| 455 | - } | |
| 485 | + }//end if | |
| 456 | 486 | } else { |
| 457 | 487 | |
| 458 | 488 | self::create_imported_field( $f, $imported ); |
| 459 | - } | |
| 460 | - } | |
| 489 | + }//end if | |
| 490 | + }//end foreach | |
| 461 | 491 | |
| 462 | 492 | if ( $keys_by_original_field_id ) { |
| 463 | 493 | self::maybe_update_field_ids( $form_id, $keys_by_original_field_id ); |
| 464 | 494 | } |
| @@ -463,8 +493,46 @@ | ||
| 463 | 493 | self::maybe_update_field_ids( $form_id, $keys_by_original_field_id ); |
| 464 | 494 | } |
| 465 | 495 | } |
| 466 | 496 | |
| 497 | + /** | |
| 498 | + * @since 6.8.4 | |
| 499 | + * | |
| 500 | + * @param array $field_array | |
| 501 | + * @return array | |
| 502 | + */ | |
| 503 | + private static function update_field_options_with_defaults( $field_array ) { | |
| 504 | + $defaults = self::default_field_options( $field_array['type'] ); | |
| 505 | + $field_array['field_options'] = array_merge( $defaults, $field_array['field_options'] ); | |
| 506 | + | |
| 507 | + return $field_array; | |
| 508 | + } | |
| 509 | + | |
| 510 | + /** | |
| 511 | + * @since 6.8.4 | |
| 512 | + * | |
| 513 | + * @param array $field_array | |
| 514 | + * @param array $form_fields | |
| 515 | + * @param int $old_field_id | |
| 516 | + * | |
| 517 | + * @return void | |
| 518 | + */ | |
| 519 | + private static function do_after_field_imported_action( $field_array, $form_fields, $old_field_id ) { | |
| 520 | + // Assign field array the update field's ID. | |
| 521 | + $field_array['id'] = $form_fields[ $field_array['field_key'] ]; | |
| 522 | + | |
| 523 | + /** | |
| 524 | + * Fires when an existing field is imported. | |
| 525 | + * | |
| 526 | + * @since 6.8.4 | |
| 527 | + * | |
| 528 | + * @param array $field_array | |
| 529 | + * @param int $field_id | |
| 530 | + * @param int $old_field_id | |
| 531 | + */ | |
| 532 | + do_action( 'frm_after_existing_field_is_imported', $field_array, $form_fields[ $field_array['field_key'] ], $old_field_id ); | |
| 533 | + } | |
| 534 | + | |
| 467 | 535 | private static function fill_field( $field, $form_id ) { |
| 468 | 536 | return array( |
| 469 | 537 | 'id' => (int) $field->id, |
| 470 | 538 | 'field_key' => (string) $field->field_key, |
| @@ -520,9 +588,9 @@ | ||
| 520 | 588 | /** |
| 521 | 589 | * Update the current in_section value at the beginning of the field loop |
| 522 | 590 | * |
| 523 | 591 | * @since 2.0.25 |
| 524 | - * @param int $in_section | |
| 592 | + * @param int $in_section | |
| 525 | 593 | * @param array $f |
| 526 | 594 | */ |
| 527 | 595 | private static function maybe_update_in_section_variable( &$in_section, &$f ) { |
| 528 | 596 | // If we're at the end of a section, switch $in_section is 0 |
| @@ -535,9 +603,9 @@ | ||
| 535 | 603 | $f['field_options']['in_section'] = $in_section; |
| 536 | 604 | } |
| 537 | 605 | |
| 538 | 606 | // If we're starting a new section, switch $in_section to ID of divider |
| 539 | - if ( $f['type'] == 'divider' ) { | |
| 607 | + if ( $f['type'] === 'divider' ) { | |
| 540 | 608 | $in_section = $f['id']; |
| 541 | 609 | } |
| 542 | 610 | } |
| 543 | 611 | |
| @@ -553,9 +621,9 @@ | ||
| 553 | 621 | if ( ! isset( $imported['forms'] ) ) { |
| 554 | 622 | return; |
| 555 | 623 | } |
| 556 | 624 | |
| 557 | - if ( $f['type'] == 'form' || ( $f['type'] == 'divider' && FrmField::is_option_true( $f['field_options'], 'repeat' ) ) ) { | |
| 625 | + if ( $f['type'] === 'form' || ( $f['type'] === 'divider' && FrmField::is_option_true( $f['field_options'], 'repeat' ) ) ) { | |
| 558 | 626 | if ( FrmField::is_option_true( $f['field_options'], 'form_select' ) ) { |
| 559 | 627 | $form_select = (int) $f['field_options']['form_select']; |
| 560 | 628 | if ( isset( $imported['forms'][ $form_select ] ) ) { |
| 561 | 629 | $f['field_options']['form_select'] = $imported['forms'][ $form_select ]; |
| @@ -617,9 +685,9 @@ | ||
| 617 | 685 | * @since 4.0 |
| 618 | 686 | * @return array |
| 619 | 687 | */ |
| 620 | 688 | public static function migrate_field_placeholder( $field, $type ) { |
| 621 | - $field = (array) $field; | |
| 689 | + $field = (array) $field; | |
| 622 | 690 | $field_options = $field['field_options']; |
| 623 | 691 | if ( empty( $field_options[ $type ] ) || empty( $field['default_value'] ) ) { |
| 624 | 692 | return array(); |
| 625 | 693 | } |
| @@ -664,10 +732,9 @@ | ||
| 664 | 732 | * @param array $f |
| 665 | 733 | * @param array $imported |
| 666 | 734 | */ |
| 667 | 735 | 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'] ); | |
| 736 | + $f = self::update_field_options_with_defaults( $f ); | |
| 670 | 737 | |
| 671 | 738 | if ( is_callable( 'FrmProFileImport::import_attachment' ) ) { |
| 672 | 739 | $f = self::maybe_import_images_for_options( $f ); |
| 673 | 740 | } |
| @@ -673,9 +740,9 @@ | ||
| 673 | 740 | } |
| 674 | 741 | |
| 675 | 742 | $new_id = FrmField::create( $f ); |
| 676 | 743 | if ( $new_id != false ) { |
| 677 | - $imported['imported']['fields'] ++; | |
| 744 | + ++$imported['imported']['fields']; | |
| 678 | 745 | do_action( 'frm_after_field_is_imported', $f, $new_id ); |
| 679 | 746 | } |
| 680 | 747 | } |
| 681 | 748 | |
| @@ -696,13 +763,15 @@ | ||
| 696 | 763 | if ( ! is_array( $option ) || empty( $option['src'] ) ) { |
| 697 | 764 | continue; |
| 698 | 765 | } |
| 699 | 766 | |
| 700 | - $field_object = (object) $field; | |
| 701 | - $field_object->type = 'file'; // Fake the file type as FrmProImport::import_attachment checks for file type. | |
| 767 | + $field_object = (object) $field; | |
| 768 | + // Fake the file type as FrmProImport::import_attachment checks for file type. | |
| 769 | + $field_object->type = 'file'; | |
| 702 | 770 | |
| 703 | 771 | $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. | |
| 772 | + // Remove the src from options as it isn't required after import. | |
| 773 | + unset( $field['options'][ $key ]['src'] ); | |
| 705 | 774 | |
| 706 | 775 | if ( is_numeric( $image_id ) ) { |
| 707 | 776 | $field['options'][ $key ]['image'] = $image_id; |
| 708 | 777 | } |
| @@ -714,9 +783,9 @@ | ||
| 714 | 783 | /** |
| 715 | 784 | * Fix field ids for fields that already exist prior to import. |
| 716 | 785 | * |
| 717 | 786 | * @since 4.07 |
| 718 | - * @param int $form_id | |
| 787 | + * @param int $form_id | |
| 719 | 788 | * @param array $keys_by_original_field_id |
| 720 | 789 | */ |
| 721 | 790 | protected static function maybe_update_field_ids( $form_id, $keys_by_original_field_id ) { |
| 722 | 791 | global $frm_duplicate_ids; |
| @@ -786,9 +855,9 @@ | ||
| 786 | 855 | |
| 787 | 856 | // Set to default |
| 788 | 857 | $form['options']['custom_style'] = 1; |
| 789 | 858 | } |
| 790 | - } | |
| 859 | + }//end if | |
| 791 | 860 | } |
| 792 | 861 | |
| 793 | 862 | /** |
| 794 | 863 | * After styles are imported, check for any forms that were linked |
| @@ -810,8 +879,15 @@ | ||
| 810 | 879 | } |
| 811 | 880 | } |
| 812 | 881 | } |
| 813 | 882 | |
| 883 | + /** | |
| 884 | + * Handle import for all posts. This includes views, styles, pages, and form actions. | |
| 885 | + * | |
| 886 | + * @param SimpleXMLElement $views | |
| 887 | + * @param array $imported | |
| 888 | + * @return array | |
| 889 | + */ | |
| 814 | 890 | public static function import_xml_views( $views, $imported ) { |
| 815 | 891 | $imported['posts'] = array(); |
| 816 | 892 | $form_action_type = FrmFormActionsController::$action_post_type; |
| 817 | 893 | |
| @@ -865,8 +941,10 @@ | ||
| 865 | 941 | } elseif ( $post['post_type'] === 'frm_styles' ) { |
| 866 | 942 | // Properly encode post content before inserting the post |
| 867 | 943 | $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] ); |
| 868 | 944 | $post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] ); |
| 945 | + // Store template data additionally to a postmeta that can be used to revert the style to default template style. | |
| 946 | + $post['postmeta']['frm_style_default'] = $post['post_content']; | |
| 869 | 947 | |
| 870 | 948 | // Create/update post now |
| 871 | 949 | $post_id = wp_insert_post( $post ); |
| 872 | 950 | } else { |
| @@ -876,9 +954,9 @@ | ||
| 876 | 954 | $post['post_parent'] = $imported['posts'][ $post['post_parent'] ]; |
| 877 | 955 | } |
| 878 | 956 | // Create/update post now |
| 879 | 957 | $post_id = wp_insert_post( $post ); |
| 880 | - } | |
| 958 | + }//end if | |
| 881 | 959 | |
| 882 | 960 | if ( ! is_numeric( $post_id ) ) { |
| 883 | 961 | continue; |
| 884 | 962 | } |
| @@ -895,23 +973,23 @@ | ||
| 895 | 973 | $this_type = $post_types[ $post['post_type'] ]; |
| 896 | 974 | } |
| 897 | 975 | |
| 898 | 976 | if ( isset( $post['ID'] ) && $post_id == $post['ID'] ) { |
| 899 | - $imported['updated'][ $this_type ] ++; | |
| 977 | + ++$imported['updated'][ $this_type ]; | |
| 900 | 978 | } else { |
| 901 | - $imported['imported'][ $this_type ] ++; | |
| 979 | + ++$imported['imported'][ $this_type ]; | |
| 902 | 980 | } |
| 903 | 981 | |
| 904 | - $imported['posts'][ (int) $old_id ] = $post_id; | |
| 982 | + $imported['posts'][ $old_id ] = $post_id; | |
| 905 | 983 | |
| 906 | 984 | if ( $post['post_type'] === 'frm_display' ) { |
| 907 | - $view_ids[ (int) $old_id ] = $post_id; | |
| 985 | + $view_ids[ $old_id ] = $post_id; | |
| 908 | 986 | } |
| 909 | 987 | |
| 910 | 988 | do_action( 'frm_after_import_view', $post_id, $post ); |
| 911 | 989 | |
| 912 | 990 | unset( $post ); |
| 913 | - } | |
| 991 | + }//end foreach | |
| 914 | 992 | |
| 915 | 993 | if ( $posts_with_shortcodes && $view_ids ) { |
| 916 | 994 | self::maybe_switch_view_ids_after_importing_posts( $posts_with_shortcodes, $view_ids ); |
| 917 | 995 | } |
| @@ -935,9 +1013,9 @@ | ||
| 935 | 1013 | * @param array $imported_forms |
| 936 | 1014 | */ |
| 937 | 1015 | private static function clear_forms_style_caches( $imported_forms ) { |
| 938 | 1016 | $where = array( |
| 939 | - 'id' => $imported_forms, | |
| 1017 | + 'id' => $imported_forms, | |
| 940 | 1018 | 'options LIKE' => '"old_style"', |
| 941 | 1019 | ); |
| 942 | 1020 | $forms = FrmDb::get_results( 'frm_forms', $where ); |
| 943 | 1021 | |
| @@ -1102,9 +1180,9 @@ | ||
| 1102 | 1180 | 'key' => (string) $meta->meta_key, |
| 1103 | 1181 | 'value' => (string) $meta->meta_value, |
| 1104 | 1182 | ); |
| 1105 | 1183 | |
| 1106 | - //switch old form and field ids to new ones | |
| 1184 | + // Switch old form and field ids to new ones. | |
| 1107 | 1185 | if ( 'frm_form_id' === $m['key'] && isset( $imported['forms'][ (int) $m['value'] ] ) ) { |
| 1108 | 1186 | $m['value'] = $imported['forms'][ (int) $m['value'] ]; |
| 1109 | 1187 | } else { |
| 1110 | 1188 | $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] ); |
| @@ -1120,10 +1198,26 @@ | ||
| 1120 | 1198 | $m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ]; |
| 1121 | 1199 | } |
| 1122 | 1200 | } |
| 1123 | 1201 | |
| 1202 | + if ( ! empty( $m['value']['map_address_fields'] ) ) { | |
| 1203 | + foreach ( $m['value']['map_address_fields'] as $address_field_key => $address_field_id ) { | |
| 1204 | + if ( isset( $frm_duplicate_ids[ $address_field_id ] ) ) { | |
| 1205 | + $m['value']['map_address_fields'][ $address_field_key ] = $frm_duplicate_ids[ $address_field_id ]; | |
| 1206 | + } | |
| 1207 | + } | |
| 1208 | + } | |
| 1209 | + | |
| 1210 | + if ( ! empty( $m['value']['calendar_options'] ) ) { | |
| 1211 | + foreach ( $m['value']['calendar_options'] as $calendar_option_group_key => $calendar_option ) { | |
| 1212 | + if ( isset( $frm_duplicate_ids[ $calendar_option['value'] ] ) ) { | |
| 1213 | + $m['value']['calendar_options'][ $calendar_option_group_key ]['value'] = $frm_duplicate_ids[ $calendar_option['value'] ]; | |
| 1214 | + } | |
| 1215 | + } | |
| 1216 | + } | |
| 1217 | + | |
| 1124 | 1218 | $check_dup_array = array(); |
| 1125 | - if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) { | |
| 1219 | + if ( ! empty( $m['value']['order_by'] ) ) { | |
| 1126 | 1220 | if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) { |
| 1127 | 1221 | $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ]; |
| 1128 | 1222 | } elseif ( is_array( $m['value']['order_by'] ) ) { |
| 1129 | 1223 | $check_dup_array[] = 'order_by'; |
| @@ -1129,9 +1223,9 @@ | ||
| 1129 | 1223 | $check_dup_array[] = 'order_by'; |
| 1130 | 1224 | } |
| 1131 | 1225 | } |
| 1132 | 1226 | |
| 1133 | - if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) { | |
| 1227 | + if ( ! empty( $m['value']['where'] ) ) { | |
| 1134 | 1228 | $check_dup_array[] = 'where'; |
| 1135 | 1229 | } |
| 1136 | 1230 | |
| 1137 | 1231 | foreach ( $check_dup_array as $check_k ) { |
| @@ -1141,11 +1235,11 @@ | ||
| 1141 | 1235 | } |
| 1142 | 1236 | unset( $mk, $mv ); |
| 1143 | 1237 | } |
| 1144 | 1238 | } |
| 1145 | - } | |
| 1146 | - } | |
| 1147 | - } | |
| 1239 | + }//end if | |
| 1240 | + }//end if | |
| 1241 | + }//end if | |
| 1148 | 1242 | |
| 1149 | 1243 | if ( ! is_array( $m['value'] ) ) { |
| 1150 | 1244 | $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] ); |
| 1151 | 1245 | } |
| @@ -1159,10 +1253,10 @@ | ||
| 1159 | 1253 | |
| 1160 | 1254 | /** |
| 1161 | 1255 | * Add terms to post |
| 1162 | 1256 | * |
| 1163 | - * @param array $post by reference | |
| 1164 | - * @param object $item The XML object data | |
| 1257 | + * @param array $post By reference. | |
| 1258 | + * @param object $item The XML object data. | |
| 1165 | 1259 | */ |
| 1166 | 1260 | private static function populate_taxonomies( &$post, $item ) { |
| 1167 | 1261 | foreach ( $item->category as $c ) { |
| 1168 | 1262 | $att = $c->attributes(); |
| @@ -1187,13 +1281,13 @@ | ||
| 1187 | 1281 | } |
| 1188 | 1282 | |
| 1189 | 1283 | $post['tax_input'][ $taxonomy ][] = $name; |
| 1190 | 1284 | unset( $name ); |
| 1191 | - } | |
| 1285 | + }//end foreach | |
| 1192 | 1286 | } |
| 1193 | 1287 | |
| 1194 | 1288 | /** |
| 1195 | - * Edit post if the key and created time match | |
| 1289 | + * Edit post if the key and created time match. | |
| 1196 | 1290 | */ |
| 1197 | 1291 | private static function maybe_editing_post( &$post ) { |
| 1198 | 1292 | $match_by = array( |
| 1199 | 1293 | 'post_type' => $post['post_type'], |
| @@ -1201,9 +1295,9 @@ | ||
| 1201 | 1295 | 'post_status' => $post['post_status'], |
| 1202 | 1296 | 'posts_per_page' => 1, |
| 1203 | 1297 | ); |
| 1204 | 1298 | |
| 1205 | - if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) { | |
| 1299 | + if ( in_array( $post['post_status'], array( 'trash', 'draft' ), true ) ) { | |
| 1206 | 1300 | $match_by['include'] = $post['post_id']; |
| 1207 | 1301 | unset( $match_by['name'] ); |
| 1208 | 1302 | } |
| 1209 | 1303 | |
| @@ -1243,13 +1337,13 @@ | ||
| 1243 | 1337 | |
| 1244 | 1338 | case 'frm_param': |
| 1245 | 1339 | add_rewrite_endpoint( $v, EP_PERMALINK | EP_PAGES ); |
| 1246 | 1340 | break; |
| 1247 | - } | |
| 1341 | + }//end switch | |
| 1248 | 1342 | |
| 1249 | 1343 | update_post_meta( $post_id, $k, $v ); |
| 1250 | 1344 | unset( $k, $v ); |
| 1251 | - } | |
| 1345 | + }//end foreach | |
| 1252 | 1346 | } |
| 1253 | 1347 | |
| 1254 | 1348 | /** |
| 1255 | 1349 | * @param array $post |
| @@ -1265,10 +1359,10 @@ | ||
| 1265 | 1359 | } |
| 1266 | 1360 | } |
| 1267 | 1361 | |
| 1268 | 1362 | 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'] ); | |
| 1363 | + $new_styles = ! empty( $imported['imported']['styles'] ); | |
| 1364 | + $updated_styles = ! empty( $imported['updated']['styles'] ); | |
| 1271 | 1365 | if ( $new_styles || $updated_styles ) { |
| 1272 | 1366 | if ( is_admin() && function_exists( 'get_filesystem_method' ) ) { |
| 1273 | 1367 | $frm_style = new FrmStyle(); |
| 1274 | 1368 | $frm_style->update( 'default' ); |
| @@ -1279,9 +1373,11 @@ | ||
| 1279 | 1373 | } |
| 1280 | 1374 | } |
| 1281 | 1375 | |
| 1282 | 1376 | /** |
| 1377 | + * @param mixed $result | |
| 1283 | 1378 | * @param string $message |
| 1379 | + * @param array $errors | |
| 1284 | 1380 | */ |
| 1285 | 1381 | public static function parse_message( $result, &$message, &$errors ) { |
| 1286 | 1382 | if ( is_wp_error( $result ) ) { |
| 1287 | 1383 | $errors[] = $result->get_error_message(); |
| @@ -1287,9 +1383,9 @@ | ||
| 1287 | 1383 | $errors[] = $result->get_error_message(); |
| 1288 | 1384 | |
| 1289 | 1385 | // Remove the SimpleXML_parse_error from the WP_Error object to avoid |
| 1290 | 1386 | // displaying duplicate error messages from $result->get_error_message() |
| 1291 | - $error_codes = $result->get_error_codes(); | |
| 1387 | + $error_codes = $result->get_error_codes(); | |
| 1292 | 1388 | $error_details = array(); |
| 1293 | 1389 | foreach ( $error_codes as $error_code ) { |
| 1294 | 1390 | // Clone WP_Error data because WP_Error removes all error messages and data |
| 1295 | 1391 | // associated with the specified error code when an item is removed. |
| @@ -1305,15 +1401,16 @@ | ||
| 1305 | 1401 | $errors[] = '<br />' . esc_html_x( 'Error details:', 'import xml message', 'formidable' ) . '<br />' . esc_html( print_r( $error_details, 1 ) ); |
| 1306 | 1402 | } |
| 1307 | 1403 | |
| 1308 | 1404 | return; |
| 1309 | - } elseif ( ! $result ) { | |
| 1405 | + }//end if | |
| 1406 | + | |
| 1407 | + if ( ! $result ) { | |
| 1310 | 1408 | return; |
| 1311 | 1409 | } |
| 1312 | 1410 | |
| 1313 | 1411 | if ( ! is_array( $result ) ) { |
| 1314 | 1412 | $message = is_string( $result ) ? $result : htmlentities( print_r( $result, 1 ) ); |
| 1315 | - | |
| 1316 | 1413 | return; |
| 1317 | 1414 | } |
| 1318 | 1415 | |
| 1319 | 1416 | $t_strings = array( |
| @@ -1340,9 +1437,9 @@ | ||
| 1340 | 1437 | $message .= '</li>'; |
| 1341 | 1438 | } |
| 1342 | 1439 | } |
| 1343 | 1440 | |
| 1344 | - if ( $message == '<ul>' ) { | |
| 1441 | + if ( $message === '<ul>' ) { | |
| 1345 | 1442 | $message = ''; |
| 1346 | 1443 | $errors[] = __( 'Nothing was imported or updated', 'formidable' ); |
| 1347 | 1444 | } else { |
| 1348 | 1445 | self::add_form_link_to_message( $result, $message ); |
| @@ -1646,9 +1743,13 @@ | ||
| 1646 | 1743 | |
| 1647 | 1744 | /** |
| 1648 | 1745 | * Migrate post settings to form action |
| 1649 | 1746 | * |
| 1747 | + * @param array $form_options | |
| 1748 | + * @param int $form_id | |
| 1650 | 1749 | * @param string $post_type |
| 1750 | + * @param array $imported | |
| 1751 | + * @param bool $switch | |
| 1651 | 1752 | */ |
| 1652 | 1753 | private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) { |
| 1653 | 1754 | if ( ! isset( $form_options['create_post'] ) || ! $form_options['create_post'] ) { |
| 1654 | 1755 | return; |
| @@ -1717,9 +1818,9 @@ | ||
| 1717 | 1818 | |
| 1718 | 1819 | if ( ! $exists ) { |
| 1719 | 1820 | // this isn't an email, but we need to use a class that will always be included |
| 1720 | 1821 | FrmDb::save_json_post( $new_action ); |
| 1721 | - $imported['imported']['actions'] ++; | |
| 1822 | + ++$imported['imported']['actions']; | |
| 1722 | 1823 | } |
| 1723 | 1824 | } |
| 1724 | 1825 | |
| 1725 | 1826 | /** |
| @@ -1726,11 +1827,11 @@ | ||
| 1726 | 1827 | * Switch old field IDs for new field IDs in emails and post |
| 1727 | 1828 | * |
| 1728 | 1829 | * @since 2.0 |
| 1729 | 1830 | * |
| 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 | |
| 1831 | + * @param array $post_content Check for old field IDs. | |
| 1832 | + * @param array $basic_fields Fields with string or int saved. | |
| 1833 | + * @param array $array_fields Fields with arrays saved. | |
| 1733 | 1834 | * |
| 1734 | 1835 | * @return string $post_content - new field IDs |
| 1735 | 1836 | */ |
| 1736 | 1837 | private static function switch_action_field_ids( $post_content, $basic_fields, $array_fields = array() ) { |
| @@ -1811,12 +1912,12 @@ | ||
| 1811 | 1912 | ); |
| 1812 | 1913 | |
| 1813 | 1914 | if ( empty( $exists ) ) { |
| 1814 | 1915 | FrmDb::save_json_post( $new_notification ); |
| 1815 | - $imported['imported']['actions'] ++; | |
| 1916 | + ++$imported['imported']['actions']; | |
| 1816 | 1917 | } |
| 1817 | 1918 | unset( $new_notification ); |
| 1818 | - } | |
| 1919 | + }//end foreach | |
| 1819 | 1920 | |
| 1820 | 1921 | self::remove_deprecated_notification_settings( $form_id, $form_options ); |
| 1821 | 1922 | } |
| 1822 | 1923 | |
| @@ -1825,9 +1926,9 @@ | ||
| 1825 | 1926 | * |
| 1826 | 1927 | * @since 2.05 |
| 1827 | 1928 | * |
| 1828 | 1929 | * @param int|string $form_id |
| 1829 | - * @param array $form_options | |
| 1930 | + * @param array $form_options | |
| 1830 | 1931 | */ |
| 1831 | 1932 | private static function remove_deprecated_notification_settings( $form_id, $form_options ) { |
| 1832 | 1933 | $delete_settings = array( 'notification', 'autoresponder', 'email_to' ); |
| 1833 | 1934 | foreach ( $delete_settings as $index ) { |
| @@ -1838,9 +1939,9 @@ | ||
| 1838 | 1939 | FrmForm::update( $form_id, array( 'options' => $form_options ) ); |
| 1839 | 1940 | } |
| 1840 | 1941 | |
| 1841 | 1942 | 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'] ) ) { | |
| 1943 | + if ( ! isset( $form_options['notification'] ) && ! empty( $form_options['email_to'] ) ) { | |
| 1843 | 1944 | // add old settings into notification array |
| 1844 | 1945 | $form_options['notification'] = array( 0 => $form_options ); |
| 1845 | 1946 | } elseif ( isset( $form_options['notification']['email_to'] ) ) { |
| 1846 | 1947 | // make sure it's in the correct format |
| @@ -1870,10 +1971,10 @@ | ||
| 1870 | 1971 | $new_notification = array(); |
| 1871 | 1972 | self::setup_new_notification( $new_notification, $notification, $atts ); |
| 1872 | 1973 | |
| 1873 | 1974 | $notifications[] = $new_notification; |
| 1874 | - } | |
| 1875 | - } | |
| 1975 | + }//end foreach | |
| 1976 | + }//end if | |
| 1876 | 1977 | } |
| 1877 | 1978 | |
| 1878 | 1979 | private static function format_email_data( &$atts, $notification ) { |
| 1879 | 1980 | // Format email_to |
| @@ -1969,9 +2070,9 @@ | ||
| 1969 | 2070 | |
| 1970 | 2071 | /** |
| 1971 | 2072 | * Switch field IDs in pre-2.0 email conditional logic |
| 1972 | 2073 | * |
| 1973 | - * @param $post_content array, pass by reference | |
| 2074 | + * @param array $post_content Pass by reference. | |
| 1974 | 2075 | */ |
| 1975 | 2076 | private static function switch_email_condition_field_ids( &$post_content ) { |
| 1976 | 2077 | // Switch field IDs in conditional logic |
| 1977 | 2078 | if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) { |
| @@ -2024,17 +2125,17 @@ | ||
| 2024 | 2125 | } |
| 2025 | 2126 | |
| 2026 | 2127 | $notifications[] = $new_notification2; |
| 2027 | 2128 | unset( $new_notification2 ); |
| 2028 | - } | |
| 2129 | + }//end if | |
| 2029 | 2130 | } |
| 2030 | 2131 | |
| 2031 | 2132 | /** |
| 2032 | 2133 | * PHP 8 backward compatibility for the libxml_disable_entity_loader function |
| 2033 | 2134 | * |
| 2034 | - * @param boolean $disable | |
| 2135 | + * @param bool $loader | |
| 2035 | 2136 | * |
| 2036 | - * @return boolean | |
| 2137 | + * @return bool | |
| 2037 | 2138 | */ |
| 2038 | 2139 | public static function maybe_libxml_disable_entity_loader( $loader ) { |
| 2039 | 2140 | if ( version_compare( phpversion(), '8.0', '<' ) && function_exists( 'libxml_disable_entity_loader' ) ) { |
| 2040 | 2141 | $loader = libxml_disable_entity_loader( $loader ); // phpcs:disable Generic.PHP.DeprecatedFunctions.Deprecated |
| @@ -2045,6 +2146,22 @@ | ||
| 2045 | 2146 | |
| 2046 | 2147 | public static function check_if_libxml_disable_entity_loader_exists() { |
| 2047 | 2148 | return version_compare( phpversion(), '8.0', '<' ) && ! function_exists( 'libxml_disable_entity_loader' ); |
| 2048 | 2149 | } |
| 2150 | + | |
| 2151 | + /** | |
| 2152 | + * Get the file types allowed for importing. | |
| 2153 | + * This is used in the "accept" attribute for the file upload input on the XML import page. | |
| 2154 | + * | |
| 2155 | + * @since 6.8.3 | |
| 2156 | + * | |
| 2157 | + * @return array | |
| 2158 | + */ | |
| 2159 | + public static function get_supported_upload_file_types() { | |
| 2160 | + $file_types = array( '.xml' ); | |
| 2161 | + if ( FrmAppHelper::pro_is_installed() ) { | |
| 2162 | + // CSV Importing is only available in Pro. | |
| 2163 | + $file_types[] = '.csv'; | |
| 2164 | + } | |
| 2165 | + return $file_types; | |
| 2166 | + } | |
| 2049 | 2167 | } |
| 2050 | - | |