PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/helpers/FrmXMLHelper.php +114 -559 6.255.0 View file →
@@ -4,13 +4,8 @@
4 4 }
5 5
6 6 class FrmXMLHelper {
7 7
8 - /**
9 - * @var bool true if importing an XML from API, false if importing an XML file manually.
10 - */
11 - private static $installing_template = false;
12 -
13 8 public static function get_xml_values( $opt, $padding ) {
14 9 if ( is_array( $opt ) ) {
15 10 foreach ( $opt as $ok => $ov ) {
16 11 echo "\n" . esc_html( $padding );
@@ -22,16 +17,12 @@
22 17 }
23 18 echo '</' . esc_html( $tag ) . '>';
24 19 }
25 20 } else {
26 - echo self::cdata( $opt ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
21 + echo self::cdata( $opt ); // WPCS: XSS ok.
27 22 }
28 23 }
29 24
30 - /**
31 - * @param string $file
32 - * @return array|WP_Error The items imported
33 - */
34 25 public static function import_xml( $file ) {
35 26 if ( ! defined( 'WP_IMPORTING' ) ) {
36 27 define( 'WP_IMPORTING', true );
37 28 }
@@ -36,25 +27,13 @@
36 27 define( 'WP_IMPORTING', true );
37 28 }
38 29
39 30 if ( ! class_exists( 'DOMDocument' ) ) {
40 - $error_message = sprintf(
41 - /* translators: 1: Documentation link */
42 - __( 'In order to install XML, your server must have DOMDocument installed. Follow our documentation on %1$s to ensure DOMDocument is properly set up and XML support is enabled.', 'formidable' ),
43 - '<a href="https://formidableforms.com/knowledgebase/import-forms-entries-and-views/#kb-your-server-does-not-have-xml-enabled" target="_blank">Importing Forms, Entries, and Views</a>'
44 - );
45 -
46 - return new WP_Error( 'SimpleXML_parse_error', $error_message, libxml_get_errors() );
31 + return new WP_Error( 'SimpleXML_parse_error', __( 'Your server does not have XML enabled', 'formidable' ), libxml_get_errors() );
47 32 }
48 33
49 - $xml_string = file_get_contents( $file );
50 - self::maybe_fix_xml( $xml_string );
51 -
52 - $dom = new DOMDocument();
53 -
54 - // LIBXML_COMPACT activates small nodes allocation optimization.
55 - // Use LIBXML_PARSEHUGE to avoid "parser error : internal error: Huge input lookup" for large (300MB) files.
56 - $success = $dom->loadXML( $xml_string, LIBXML_COMPACT | LIBXML_PARSEHUGE );
34 + $dom = new DOMDocument();
35 + $success = $dom->loadXML( file_get_contents( $file ) );
57 36 if ( ! $success ) {
58 37 return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
59 38 }
60 39
@@ -73,50 +52,19 @@
73 52 return self::import_xml_now( $xml );
74 53 }
75 54
76 55 /**
77 - * @since 6.2.3
78 - *
79 - * @param string $xml_string
80 - * @return void
81 - */
82 - private static function maybe_fix_xml( &$xml_string ) {
83 - if ( '<?xml' !== substr( $xml_string, 0, 5 ) ) {
84 - // Some XML files have may have unexpected characters at the start.
85 - $xml_string = substr( $xml_string, strpos( $xml_string, '<?xml' ) );
86 - }
87 -
88 - // The Equity theme adds a <meta name="generator" content="Equity 1.7.13" /> tag using the "the_generator" filter.
89 - // Strip that out as it breaks the XML import.
90 - $channel_start_position = strpos( $xml_string, '<channel>' );
91 - $content_before_channel_tag = substr( $xml_string, 0, $channel_start_position );
92 - if ( 0 !== strpos( $content_before_channel_tag, '<meta name="generator" ' ) ) {
93 - $content_before_channel_tag = preg_replace(
94 - '/<meta\s+[^>]*name="generator"[^>]*\/>/i',
95 - '',
96 - $content_before_channel_tag,
97 - 1
98 - );
99 - $xml_string = $content_before_channel_tag . substr( $xml_string, $channel_start_position );
100 - }
101 - }
102 -
103 - /**
104 56 * Add terms, forms (form and field ids), posts (post ids), and entries to db, in that order
105 57 *
106 58 * @since 3.06
107 - *
108 - * @param object $xml
109 - * @param bool $installing_template
110 59 * @return array The number of items imported
111 60 */
112 - public static function import_xml_now( $xml, $installing_template = false ) {
61 + public static function import_xml_now( $xml ) {
113 62 if ( ! defined( 'WP_IMPORTING' ) ) {
114 63 define( 'WP_IMPORTING', true );
115 64 }
116 65
117 - self::$installing_template = $installing_template;
118 - $imported = self::pre_import_data();
66 + $imported = self::pre_import_data();
119 67
120 68 foreach ( array( 'term', 'form', 'view' ) as $item_type ) {
121 69 // Grab cats, tags, and terms, or forms or posts.
122 70 if ( isset( $xml->{$item_type} ) ) {
@@ -127,12 +75,12 @@
127 75 }
128 76
129 77 $imported = apply_filters( 'frm_importing_xml', $imported, $xml );
130 78
131 - if ( empty( $imported['form_status'] ) ) {
79 + if ( ! isset( $imported['form_status'] ) || empty( $imported['form_status'] ) ) {
132 80 // Check for an error message in the XML.
133 81 if ( isset( $xml->Code ) && isset( $xml->Message ) ) { // phpcs:ignore WordPress.NamingConventions
134 - $imported['error'] = (string) $xml->Message; // phpcs:ignore WordPress.NamingConventions
82 + $imported['error'] = reset( $xml->Message ); // phpcs:ignore WordPress.NamingConventions
135 83 }
136 84 }
137 85
138 86 return $imported;
@@ -160,13 +108,8 @@
160 108 'terms' => array(),
161 109 );
162 110 }
163 111
164 - /**
165 - * @param SimpleXMLElement $terms
166 - * @param array $imported
167 - * @return array
168 - */
169 112 public static function import_xml_terms( $terms, $imported ) {
170 113 foreach ( $terms as $t ) {
171 114 if ( term_exists( (string) $t->term_slug, (string) $t->term_taxonomy ) ) {
172 115 continue;
@@ -184,14 +127,14 @@
184 127 )
185 128 );
186 129
187 130 if ( $term && is_array( $term ) ) {
188 - ++$imported['imported']['terms'];
131 + $imported['imported']['terms'] ++;
189 132 $imported['terms'][ (int) $t->term_id ] = $term['term_id'];
190 133 }
191 134
192 135 unset( $term, $t );
193 - }//end foreach
136 + }
194 137
195 138 return $imported;
196 139 }
197 140
@@ -196,11 +139,8 @@
196 139 }
197 140
198 141 /**
199 142 * @since 2.0.8
200 - *
201 - * @param object $t
202 - * @return int|string
203 143 */
204 144 private static function get_term_parent_id( $t ) {
205 145 $parent = (string) $t->term_parent;
206 146 if ( ! empty( $parent ) ) {
@@ -214,13 +154,8 @@
214 154
215 155 return $parent;
216 156 }
217 157
218 - /**
219 - * @param SimpleXMLElement $forms
220 - * @param array $imported
221 - * @return array
222 - */
223 158 public static function import_xml_forms( $forms, $imported ) {
224 159 $child_forms = array();
225 160
226 161 // Import child forms first
@@ -245,9 +180,9 @@
245 180 $form_id = FrmForm::create( $form );
246 181 if ( $form_id ) {
247 182 if ( empty( $form['parent_form_id'] ) ) {
248 183 // Don't include the repeater form in the imported count.
249 - ++$imported['imported']['forms'];
184 + $imported['imported']['forms'] ++;
250 185 }
251 186
252 187 // Keep track of whether this specific form was updated or not.
253 188 $imported['form_status'][ $form_id ] = 'imported';
@@ -272,9 +207,9 @@
272 207
273 208 do_action( 'frm_after_import_form', $form_id, $form );
274 209
275 210 unset( $form, $item );
276 - }//end foreach
211 + }
277 212
278 213 self::maybe_update_child_form_parent_id( $imported['forms'], $child_forms );
279 214
280 215 return $imported;
@@ -300,13 +235,8 @@
300 235 }
301 236
302 237 $form['options'] = FrmAppHelper::maybe_json_decode( $form['options'] );
303 238
304 - if ( self::$installing_template ) {
305 - // Templates don't necessarily have antispam on, but we want our templates to all have antispam on by default.
306 - $form['options']['antispam'] = 1;
307 - }
308 -
309 239 return $form;
310 240 }
311 241
312 242 private static function maybe_get_form( $form ) {
@@ -320,15 +250,9 @@
320 250 }
321 251
322 252 $edit_query = apply_filters( 'frm_match_xml_form', $edit_query, $form );
323 253
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;
254 + return FrmForm::getAll( $edit_query, '', 1 );
331 255 }
332 256
333 257 private static function update_form( $this_form, $form, &$imported ) {
334 258 $form_id = $this_form->id;
@@ -334,9 +258,9 @@
334 258 $form_id = $this_form->id;
335 259 FrmForm::update( $form_id, $form );
336 260 if ( empty( $form['parent_form_id'] ) ) {
337 261 // Don't include the repeater form in the updated count.
338 - ++$imported['updated']['forms'];
262 + $imported['updated']['forms'] ++;
339 263 }
340 264
341 265 // Keep track of whether this specific form was updated or not
342 266 $imported['form_status'][ $form_id ] = 'updated';
@@ -397,10 +321,10 @@
397 321 * Keep track of all imported child forms
398 322 *
399 323 * @since 2.0.16
400 324 *
401 - * @param int $form_id
402 - * @param int $parent_form_id
325 + * @param int $form_id
326 + * @param int $parent_form_id
403 327 * @param array $child_forms
404 328 */
405 329 private static function track_imported_child_forms( $form_id, $parent_form_id, &$child_forms ) {
406 330 if ( $parent_form_id ) {
@@ -452,13 +376,13 @@
452 376 if ( ! empty( $this_form ) ) {
453 377 // check for field to edit by field id
454 378 if ( isset( $form_fields[ $f['id'] ] ) ) {
455 379 FrmField::update( $f['id'], $f );
456 - ++$imported['updated']['fields'];
380 + $imported['updated']['fields'] ++;
457 381
458 382 unset( $form_fields[ $f['id'] ] );
459 383
460 - // Unset old field key.
384 + //unset old field key
461 385 if ( isset( $form_fields[ $f['field_key'] ] ) ) {
462 386 unset( $form_fields[ $f['field_key'] ] );
463 387 }
464 388 } elseif ( isset( $form_fields[ $f['field_key'] ] ) ) {
@@ -463,32 +387,25 @@
463 387 }
464 388 } elseif ( isset( $form_fields[ $f['field_key'] ] ) ) {
465 389 $keys_by_original_field_id[ $f['id'] ] = $f['field_key'];
466 390
467 - $old_field_id = $f['id'];
468 -
469 391 // check for field to edit by field key
470 392 unset( $f['id'] );
471 393
472 394 FrmField::update( $form_fields[ $f['field_key'] ], $f );
473 - ++$imported['updated']['fields'];
395 + $imported['updated']['fields'] ++;
474 396
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'] ] );
397 + unset( $form_fields[ $form_fields[ $f['field_key'] ] ] ); //unset old field id
398 + unset( $form_fields[ $f['field_key'] ] ); //unset old field key
482 399 } else {
483 - // If no matching field id or key in this form, create the field.
400 + // if no matching field id or key in this form, create the field
484 401 self::create_imported_field( $f, $imported );
485 - }//end if
402 + }
486 403 } else {
487 404
488 405 self::create_imported_field( $f, $imported );
489 - }//end if
490 - }//end foreach
406 + }
407 + }
491 408
492 409 if ( $keys_by_original_field_id ) {
493 410 self::maybe_update_field_ids( $form_id, $keys_by_original_field_id );
494 411 }
@@ -493,46 +410,8 @@
493 410 self::maybe_update_field_ids( $form_id, $keys_by_original_field_id );
494 411 }
495 412 }
496 413
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 -
535 414 private static function fill_field( $field, $form_id ) {
536 415 return array(
537 416 'id' => (int) $field->id,
538 417 'field_key' => (string) $field->field_key,
@@ -588,9 +467,9 @@
588 467 /**
589 468 * Update the current in_section value at the beginning of the field loop
590 469 *
591 470 * @since 2.0.25
592 - * @param int $in_section
471 + * @param int $in_section
593 472 * @param array $f
594 473 */
595 474 private static function maybe_update_in_section_variable( &$in_section, &$f ) {
596 475 // If we're at the end of a section, switch $in_section is 0
@@ -603,9 +482,9 @@
603 482 $f['field_options']['in_section'] = $in_section;
604 483 }
605 484
606 485 // If we're starting a new section, switch $in_section to ID of divider
607 - if ( $f['type'] === 'divider' ) {
486 + if ( $f['type'] == 'divider' ) {
608 487 $in_section = $f['id'];
609 488 }
610 489 }
611 490
@@ -621,9 +500,9 @@
621 500 if ( ! isset( $imported['forms'] ) ) {
622 501 return;
623 502 }
624 503
625 - if ( $f['type'] === 'form' || ( $f['type'] === 'divider' && FrmField::is_option_true( $f['field_options'], 'repeat' ) ) ) {
504 + if ( $f['type'] == 'form' || ( $f['type'] == 'divider' && FrmField::is_option_true( $f['field_options'], 'repeat' ) ) ) {
626 505 if ( FrmField::is_option_true( $f['field_options'], 'form_select' ) ) {
627 506 $form_select = (int) $f['field_options']['form_select'];
628 507 if ( isset( $imported['forms'][ $form_select ] ) ) {
629 508 $f['field_options']['form_select'] = $imported['forms'][ $form_select ];
@@ -685,9 +564,9 @@
685 564 * @since 4.0
686 565 * @return array
687 566 */
688 567 public static function migrate_field_placeholder( $field, $type ) {
689 - $field = (array) $field;
568 + $field = (array) $field;
690 569 $field_options = $field['field_options'];
691 570 if ( empty( $field_options[ $type ] ) || empty( $field['default_value'] ) ) {
692 571 return array();
693 572 }
@@ -709,9 +588,9 @@
709 588 }
710 589
711 590 foreach ( $options as $opt_key => $opt ) {
712 591 if ( is_array( $opt ) ) {
713 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
592 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
714 593 }
715 594
716 595 if ( $opt == $default_value ) {
717 596 unset( $options[ $opt_key ] );
@@ -732,60 +611,23 @@
732 611 * @param array $f
733 612 * @param array $imported
734 613 */
735 614 private static function create_imported_field( $f, &$imported ) {
736 - $f = self::update_field_options_with_defaults( $f );
615 + $defaults = self::default_field_options( $f['type'] );
616 + $f['field_options'] = array_merge( $defaults, $f['field_options'] );
737 617
738 - if ( is_callable( 'FrmProFileImport::import_attachment' ) ) {
739 - $f = self::maybe_import_images_for_options( $f );
740 - }
741 -
742 618 $new_id = FrmField::create( $f );
743 619 if ( $new_id != false ) {
744 - ++$imported['imported']['fields'];
620 + $imported['imported']['fields'] ++;
745 621 do_action( 'frm_after_field_is_imported', $f, $new_id );
746 622 }
747 623 }
748 624
749 625 /**
750 - * Import images for radio buttons and checkboxes from image src if available.
751 - *
752 - * @since 5.5.1
753 - *
754 - * @param array $field
755 - * @return array
756 - */
757 - private static function maybe_import_images_for_options( $field ) {
758 - if ( empty( $field['options'] ) || ! is_array( $field['options'] ) ) {
759 - return $field;
760 - }
761 -
762 - foreach ( $field['options'] as $key => $option ) {
763 - if ( ! is_array( $option ) || empty( $option['src'] ) ) {
764 - continue;
765 - }
766 -
767 - $field_object = (object) $field;
768 - // Fake the file type as FrmProImport::import_attachment checks for file type.
769 - $field_object->type = 'file';
770 -
771 - $image_id = FrmProFileImport::import_attachment( $option['src'], $field_object );
772 - // Remove the src from options as it isn't required after import.
773 - unset( $field['options'][ $key ]['src'] );
774 -
775 - if ( is_numeric( $image_id ) ) {
776 - $field['options'][ $key ]['image'] = $image_id;
777 - }
778 - }
779 -
780 - return $field;
781 - }
782 -
783 - /**
784 626 * Fix field ids for fields that already exist prior to import.
785 627 *
786 628 * @since 4.07
787 - * @param int $form_id
629 + * @param int $form_id
788 630 * @param array $keys_by_original_field_id
789 631 */
790 632 protected static function maybe_update_field_ids( $form_id, $keys_by_original_field_id ) {
791 633 global $frm_duplicate_ids;
@@ -832,9 +674,9 @@
832 674 if ( ! isset( $form['options']['custom_style'] ) ) {
833 675 return;
834 676 }
835 677
836 - if ( is_numeric( $form['options']['custom_style'] ) && 1 === intval( $form['options']['custom_style'] ) ) {
678 + if ( is_numeric( $form['options']['custom_style'] ) ) {
837 679 // Set to default
838 680 $form['options']['custom_style'] = 1;
839 681 } else {
840 682 // Replace the style name with the style ID on import
@@ -855,9 +697,9 @@
855 697
856 698 // Set to default
857 699 $form['options']['custom_style'] = 1;
858 700 }
859 - }//end if
701 + }
860 702 }
861 703
862 704 /**
863 705 * After styles are imported, check for any forms that were linked
@@ -879,15 +721,8 @@
879 721 }
880 722 }
881 723 }
882 724
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 - */
890 725 public static function import_xml_views( $views, $imported ) {
891 726 $imported['posts'] = array();
892 727 $form_action_type = FrmFormActionsController::$action_post_type;
893 728
@@ -896,11 +731,8 @@
896 731 $form_action_type => 'actions',
897 732 'frm_styles' => 'styles',
898 733 );
899 734
900 - $view_ids = array();
901 - $posts_with_shortcodes = array();
902 -
903 735 foreach ( $views as $item ) {
904 736 $post = array(
905 737 'post_title' => (string) $item->title,
906 738 'post_name' => (string) $item->post_name,
@@ -923,15 +755,8 @@
923 755 'layout' => array(),
924 756 'tax_input' => array(),
925 757 );
926 758
927 - $post['post_content'] = self::switch_form_ids( $post['post_content'], $imported['forms'] );
928 -
929 - // Fix issue with line breaks appearing in descriptions as "rn".
930 - if ( $post['post_type'] === $form_action_type ) {
931 - $post['post_content'] = str_replace( '\\\\r\\\\n', '\\r\\n', $post['post_content'] );
932 - }
933 -
934 759 $old_id = $post['post_id'];
935 760 self::populate_post( $post, $item, $imported );
936 761
937 762 unset( $item );
@@ -936,41 +761,35 @@
936 761
937 762 unset( $item );
938 763
939 764 $post_id = false;
940 - if ( $post['post_type'] === $form_action_type ) {
765 + if ( $post['post_type'] == $form_action_type ) {
941 766 $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] );
942 - if ( $action_control && is_object( $action_control ) && isset( $imported['form_status'] ) ) {
767 + if ( $action_control && is_object( $action_control ) ) {
943 768 $post_id = $action_control->maybe_create_action( $post, $imported['form_status'] );
944 769 }
945 770 unset( $action_control );
946 - } elseif ( $post['post_type'] === 'frm_styles' ) {
771 + } elseif ( $post['post_type'] == 'frm_styles' ) {
947 772 // Properly encode post content before inserting the post
948 773 $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] );
774 + $custom_css = isset( $post['post_content']['custom_css'] ) ? $post['post_content']['custom_css'] : '';
949 775 $post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] );
950 - // Store template data additionally to a postmeta that can be used to revert the style to default template style.
951 - $post['postmeta']['frm_style_default'] = $post['post_content'];
952 776
953 777 // Create/update post now
954 778 $post_id = wp_insert_post( $post );
779 + self::maybe_update_custom_css( $custom_css );
955 780 } else {
956 781 if ( $post['post_type'] === 'frm_display' ) {
957 782 $post['post_content'] = self::maybe_prepare_json_view_content( $post['post_content'] );
958 - } elseif ( 'page' === $post['post_type'] && isset( $imported['posts'][ $post['post_parent'] ] ) ) {
959 - $post['post_parent'] = $imported['posts'][ $post['post_parent'] ];
960 783 }
961 784 // Create/update post now
962 785 $post_id = wp_insert_post( $post );
963 - }//end if
786 + }
964 787
965 788 if ( ! is_numeric( $post_id ) ) {
966 789 continue;
967 790 }
968 791
969 - if ( false !== strpos( $post['post_content'], '[display-frm-data' ) || false !== strpos( $post['post_content'], '[formidable' ) ) {
970 - $posts_with_shortcodes[ $post_id ] = $post;
971 - }
972 -
973 792 self::update_postmeta( $post, $post_id );
974 793 self::update_layout( $post, $post_id );
975 794
976 795 $this_type = 'posts';
@@ -978,161 +797,26 @@
978 797 $this_type = $post_types[ $post['post_type'] ];
979 798 }
980 799
981 800 if ( isset( $post['ID'] ) && $post_id == $post['ID'] ) {
982 - ++$imported['updated'][ $this_type ];
801 + $imported['updated'][ $this_type ] ++;
983 802 } else {
984 - ++$imported['imported'][ $this_type ];
803 + $imported['imported'][ $this_type ] ++;
985 804 }
986 805
987 - $imported['posts'][ $old_id ] = $post_id;
806 + $imported['posts'][ (int) $old_id ] = $post_id;
988 807
989 - if ( $post['post_type'] === 'frm_display' ) {
990 - $view_ids[ $old_id ] = $post_id;
991 - }
992 -
993 808 do_action( 'frm_after_import_view', $post_id, $post );
994 809
995 810 unset( $post );
996 - }//end foreach
997 -
998 - if ( $posts_with_shortcodes && $view_ids ) {
999 - self::maybe_switch_view_ids_after_importing_posts( $posts_with_shortcodes, $view_ids );
1000 811 }
1001 - unset( $posts_with_shortcodes, $view_ids );
1002 812
1003 - if ( ! empty( $imported['forms'] ) ) {
1004 - // clear imported forms style cache to make sure the new styles are applied to the forms
1005 - self::clear_forms_style_caches( $imported['forms'] );
1006 - }
1007 -
1008 813 self::maybe_update_stylesheet( $imported );
1009 814
1010 - flush_rewrite_rules();
1011 -
1012 815 return $imported;
1013 816 }
1014 817
1015 818 /**
1016 - * Clears styles from cache for imported forms
1017 - *
1018 - * @param array $imported_forms
1019 - */
1020 - private static function clear_forms_style_caches( $imported_forms ) {
1021 - $where = array(
1022 - 'id' => $imported_forms,
1023 - 'options LIKE' => '"old_style"',
1024 - );
1025 - $forms = FrmDb::get_results( 'frm_forms', $where );
1026 -
1027 - foreach ( $forms as $form ) {
1028 - FrmAppHelper::unserialize_or_decode( $form->options );
1029 - if ( ! $form->options ) {
1030 - continue;
1031 - }
1032 - $where = array(
1033 - 'post_name' => $form->options['old_style'],
1034 - 'post_type' => FrmStylesController::$post_type,
1035 - );
1036 -
1037 - $select = 'ID';
1038 -
1039 - $cache_key = FrmDb::generate_cache_key( $where, array( 'limit' => 1 ), $select, 'var' );
1040 - FrmDb::delete_cache_and_transient( $cache_key, 'post' );
1041 - }
1042 - }
1043 -
1044 - /**
1045 - * Replace old form ids with new ones in a string.
1046 - *
1047 - * @param string $string
1048 - * @param array<int> $form_ids new form ids indexed by old form id.
1049 - * @return string
1050 - */
1051 - private static function switch_form_ids( $string, $form_ids ) {
1052 - if ( false === strpos( $string, '[formidable' ) ) {
1053 - // Skip string replacing if there are no form shortcodes in string.
1054 - return $string;
1055 - }
1056 -
1057 - foreach ( $form_ids as $old_id => $new_id ) {
1058 - $string = str_replace(
1059 - array(
1060 - '[formidable id="' . $old_id . '"',
1061 - '[formidable id=' . $old_id . ']',
1062 - '[formidable id=' . $old_id . ' ',
1063 - '"formId":"' . $old_id . '"',
1064 - ),
1065 - array(
1066 - '[formidable id="' . $new_id . '"',
1067 - '[formidable id=' . $new_id . ']',
1068 - '[formidable id=' . $new_id . ' ',
1069 - '"formId":"' . $new_id . '"',
1070 - ),
1071 - $string
1072 - );
1073 - }
1074 -
1075 - return $string;
1076 - }
1077 -
1078 - /**
1079 - * @param array<array> $posts_with_shortcodes indexed by current post id.
1080 - * @param array<int> $view_ids new view ids indexed by old view id.
1081 - * @return void
1082 - */
1083 - private static function maybe_switch_view_ids_after_importing_posts( $posts_with_shortcodes, $view_ids ) {
1084 - foreach ( $posts_with_shortcodes as $imported_post_id => $post ) {
1085 - $post_content = self::switch_view_ids( $post['post_content'], $view_ids );
1086 - if ( $post_content === $post['post_content'] ) {
1087 - continue;
1088 - }
1089 -
1090 - wp_update_post(
1091 - array(
1092 - 'ID' => $imported_post_id,
1093 - 'post_content' => $post_content,
1094 - )
1095 - );
1096 - }
1097 - }
1098 -
1099 - /**
1100 - * Replace old view ids with new ones in a string.
1101 - *
1102 - * @param string $string
1103 - * @param array<int> $view_ids new view ids indexed by old view id.
1104 - * @return string
1105 - */
1106 - private static function switch_view_ids( $string, $view_ids ) {
1107 - if ( false === strpos( $string, '[display-frm-data' ) ) {
1108 - // Skip string replacing if there are no view shortcodes in string.
1109 - return $string;
1110 - }
1111 -
1112 - foreach ( $view_ids as $old_id => $new_id ) {
1113 - $string = str_replace(
1114 - array(
1115 - '[display-frm-data id="' . $old_id . '"',
1116 - '[display-frm-data id=' . $old_id . ']',
1117 - '[display-frm-data id=' . $old_id . ' ',
1118 - '"viewId":"' . $old_id . '"',
1119 - ),
1120 - array(
1121 - '[display-frm-data id="' . $new_id . '"',
1122 - '[display-frm-data id=' . $new_id . ']',
1123 - '[display-frm-data id=' . $new_id . ' ',
1124 - '"viewId":"' . $new_id . '"',
1125 - ),
1126 - $string
1127 - );
1128 - unset( $old_id, $new_id );
1129 - }
1130 -
1131 - return $string;
1132 - }
1133 -
1134 - /**
1135 819 * @param string $content
1136 820 * @return string
1137 821 */
1138 822 private static function maybe_prepare_json_view_content( $content ) {
@@ -1185,9 +869,9 @@
1185 869 'key' => (string) $meta->meta_key,
1186 870 'value' => (string) $meta->meta_value,
1187 871 );
1188 872
1189 - // Switch old form and field ids to new ones.
873 + //switch old form and field ids to new ones
1190 874 if ( 'frm_form_id' === $m['key'] && isset( $imported['forms'][ (int) $m['value'] ] ) ) {
1191 875 $m['value'] = $imported['forms'][ (int) $m['value'] ];
1192 876 } else {
1193 877 $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
@@ -1203,36 +887,10 @@
1203 887 $m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ];
1204 888 }
1205 889 }
1206 890
1207 - if ( ! empty( $m['value']['map_address_fields'] ) ) {
1208 - foreach ( $m['value']['map_address_fields'] as $address_field_key => $address_field_id ) {
1209 - if ( isset( $frm_duplicate_ids[ $address_field_id ] ) ) {
1210 - $m['value']['map_address_fields'][ $address_field_key ] = $frm_duplicate_ids[ $address_field_id ];
1211 - }
1212 - }
1213 - }
1214 -
1215 - if ( ! empty( $m['value']['calendar_options'] ) ) {
1216 - foreach ( $m['value']['calendar_options'] as $calendar_option_group_key => $calendar_option ) {
1217 - if ( isset( $frm_duplicate_ids[ $calendar_option['value'] ] ) ) {
1218 - $m['value']['calendar_options'][ $calendar_option_group_key ]['value'] = $frm_duplicate_ids[ $calendar_option['value'] ];
1219 - }
1220 - }
1221 - }
1222 -
1223 - if ( ! empty( $m['value']['timeline_options'] ) ) {
1224 - foreach ( $m['value']['timeline_options'] as $timeline_option_group_key => $timeline_group_option ) {
1225 - foreach ( $timeline_group_option as $timeline_option_key => $timeline_option ) {
1226 - if ( isset( $frm_duplicate_ids[ $timeline_option ] ) ) {
1227 - $m['value']['timeline_options'][ $timeline_option_group_key ][ $timeline_option_key ] = $frm_duplicate_ids[ $timeline_option ];
1228 - }
1229 - }
1230 - }
1231 - }
1232 -
1233 891 $check_dup_array = array();
1234 - if ( ! empty( $m['value']['order_by'] ) ) {
892 + if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) {
1235 893 if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) {
1236 894 $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ];
1237 895 } elseif ( is_array( $m['value']['order_by'] ) ) {
1238 896 $check_dup_array[] = 'order_by';
@@ -1238,9 +896,9 @@
1238 896 $check_dup_array[] = 'order_by';
1239 897 }
1240 898 }
1241 899
1242 - if ( ! empty( $m['value']['where'] ) ) {
900 + if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) {
1243 901 $check_dup_array[] = 'where';
1244 902 }
1245 903
1246 904 foreach ( $check_dup_array as $check_k ) {
@@ -1250,11 +908,11 @@
1250 908 }
1251 909 unset( $mk, $mv );
1252 910 }
1253 911 }
1254 - }//end if
1255 - }//end if
1256 - }//end if
912 + }
913 + }
914 + }
1257 915
1258 916 if ( ! is_array( $m['value'] ) ) {
1259 917 $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
1260 918 }
@@ -1268,10 +926,10 @@
1268 926
1269 927 /**
1270 928 * Add terms to post
1271 929 *
1272 - * @param array $post By reference.
1273 - * @param object $item The XML object data.
930 + * @param array $post by reference
931 + * @param object $item The XML object data
1274 932 */
1275 933 private static function populate_taxonomies( &$post, $item ) {
1276 934 foreach ( $item->category as $c ) {
1277 935 $att = $c->attributes();
@@ -1296,13 +954,13 @@
1296 954 }
1297 955
1298 956 $post['tax_input'][ $taxonomy ][] = $name;
1299 957 unset( $name );
1300 - }//end foreach
958 + }
1301 959 }
1302 960
1303 961 /**
1304 - * Edit post if the key and created time match.
962 + * Edit post if the key and created time match
1305 963 */
1306 964 private static function maybe_editing_post( &$post ) {
1307 965 $match_by = array(
1308 966 'post_type' => $post['post_type'],
@@ -1310,9 +968,9 @@
1310 968 'post_status' => $post['post_status'],
1311 969 'posts_per_page' => 1,
1312 970 );
1313 971
1314 - if ( in_array( $post['post_status'], array( 'trash', 'draft' ), true ) ) {
972 + if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) {
1315 973 $match_by['include'] = $post['post_id'];
1316 974 unset( $match_by['name'] );
1317 975 }
1318 976
@@ -1323,42 +981,26 @@
1323 981 $post['ID'] = current( $editing )->ID;
1324 982 }
1325 983 }
1326 984
1327 - /**
1328 - * @param array $post
1329 - * @param int $post_id
1330 - * @return void
1331 - */
1332 985 private static function update_postmeta( &$post, $post_id ) {
1333 986 foreach ( $post['postmeta'] as $k => $v ) {
1334 - switch ( $k ) {
1335 - case '_edit_last':
1336 - $v = FrmAppHelper::get_user_id_param( $v );
1337 - break;
987 + if ( '_edit_last' == $k ) {
988 + $v = FrmAppHelper::get_user_id_param( $v );
989 + } elseif ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) {
990 + // Change the attachment ID.
991 + $field_obj = FrmFieldFactory::get_field_type( 'file' );
992 + $v = $field_obj->get_file_id( $v );
993 + }
1338 994
1339 - case '_thumbnail_id':
1340 - if ( FrmAppHelper::pro_is_installed() ) {
1341 - // Change the attachment ID.
1342 - $field_obj = FrmFieldFactory::get_field_type( 'file' );
1343 - $v = $field_obj->get_file_id( $v );
1344 - }
1345 - break;
995 + if ( 'frm_dyncontent' === $k && is_array( $v ) ) {
996 + $v = json_encode( $v );
997 + }
1346 998
1347 - case 'frm_dyncontent':
1348 - if ( is_array( $v ) ) {
1349 - $v = json_encode( $v );
1350 - }
1351 - break;
999 + update_post_meta( $post_id, $k, $v );
1352 1000
1353 - case 'frm_param':
1354 - add_rewrite_endpoint( $v, EP_PERMALINK | EP_PAGES );
1355 - break;
1356 - }//end switch
1357 -
1358 - update_post_meta( $post_id, $k, $v );
1359 1001 unset( $k, $v );
1360 - }//end foreach
1002 + }
1361 1003 }
1362 1004
1363 1005 /**
1364 1006 * @param array $post
@@ -1373,11 +1015,28 @@
1373 1015 }
1374 1016 }
1375 1017 }
1376 1018
1019 + /**
1020 + * If a template includes custom css, let's include it.
1021 + * The custom css is included on the default style.
1022 + *
1023 + * @since 2.03
1024 + */
1025 + private static function maybe_update_custom_css( $custom_css ) {
1026 + if ( empty( $custom_css ) ) {
1027 + return;
1028 + }
1029 +
1030 + $frm_style = new FrmStyle();
1031 + $default_style = $frm_style->get_default_style();
1032 + $default_style->post_content['custom_css'] .= "\r\n\r\n" . $custom_css;
1033 + $frm_style->save( $default_style );
1034 + }
1035 +
1377 1036 private static function maybe_update_stylesheet( $imported ) {
1378 - $new_styles = ! empty( $imported['imported']['styles'] );
1379 - $updated_styles = ! empty( $imported['updated']['styles'] );
1037 + $new_styles = isset( $imported['imported']['styles'] ) && ! empty( $imported['imported']['styles'] );
1038 + $updated_styles = isset( $imported['updated']['styles'] ) && ! empty( $imported['updated']['styles'] );
1380 1039 if ( $new_styles || $updated_styles ) {
1381 1040 if ( is_admin() && function_exists( 'get_filesystem_method' ) ) {
1382 1041 $frm_style = new FrmStyle();
1383 1042 $frm_style->update( 'default' );
@@ -1388,44 +1047,20 @@
1388 1047 }
1389 1048 }
1390 1049
1391 1050 /**
1392 - * @param mixed $result
1393 1051 * @param string $message
1394 - * @param array $errors
1395 1052 */
1396 1053 public static function parse_message( $result, &$message, &$errors ) {
1397 1054 if ( is_wp_error( $result ) ) {
1398 1055 $errors[] = $result->get_error_message();
1399 -
1400 - // Remove the SimpleXML_parse_error from the WP_Error object to avoid
1401 - // displaying duplicate error messages from $result->get_error_message()
1402 - $error_codes = $result->get_error_codes();
1403 - $error_details = array();
1404 - foreach ( $error_codes as $error_code ) {
1405 - // Clone WP_Error data because WP_Error removes all error messages and data
1406 - // associated with the specified error code when an item is removed.
1407 - // Source: https://developer.wordpress.org/reference/classes/wp_error/remove/#source
1408 - $error_details = $result->get_error_data( $error_code );
1409 - if ( $error_code === 'SimpleXML_parse_error' ) {
1410 - $result->remove( $error_code );
1411 - break;
1412 - }
1413 - }
1414 -
1415 - if ( ! empty( $error_details ) ) {
1416 - $errors[] = '<br />' . esc_html_x( 'Error details:', 'import xml message', 'formidable' ) . '<br />' . esc_html( print_r( $error_details, 1 ) );
1417 - }
1418 -
1056 + } elseif ( ! $result ) {
1419 1057 return;
1420 - }//end if
1421 -
1422 - if ( ! $result ) {
1423 - return;
1424 1058 }
1425 1059
1426 1060 if ( ! is_array( $result ) ) {
1427 1061 $message = is_string( $result ) ? $result : htmlentities( print_r( $result, 1 ) );
1062 +
1428 1063 return;
1429 1064 }
1430 1065
1431 1066 $t_strings = array(
@@ -1452,30 +1087,18 @@
1452 1087 $message .= '</li>';
1453 1088 }
1454 1089 }
1455 1090
1456 - if ( $message === '<ul>' ) {
1091 + if ( $message == '<ul>' ) {
1457 1092 $message = '';
1458 1093 $errors[] = __( 'Nothing was imported or updated', 'formidable' );
1459 1094 } else {
1460 1095 self::add_form_link_to_message( $result, $message );
1461 1096
1462 - /**
1463 - * @since 5.3
1464 - *
1465 - * @param string $message
1466 - * @param array $result
1467 - */
1468 - $message = apply_filters( 'frm_xml_parsed_message', $message, $result );
1469 1097 $message .= '</ul>';
1470 1098 }
1471 1099 }
1472 1100
1473 - /**
1474 - * @param int $m
1475 - * @param string $type
1476 - * @param array<string> $s_message
1477 - */
1478 1101 public static function item_count_message( $m, $type, &$s_message ) {
1479 1102 if ( ! $m ) {
1480 1103 return;
1481 1104 }
@@ -1489,9 +1112,9 @@
1489 1112 'items' => sprintf( _n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m ),
1490 1113 /* translators: %1$s: Number of items */
1491 1114 'views' => sprintf( _n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m ),
1492 1115 /* translators: %1$s: Number of items */
1493 - 'posts' => sprintf( _n( '%1$s Page/Post', '%1$s Pages/Posts', $m, 'formidable' ), $m ),
1116 + 'posts' => sprintf( _n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m ),
1494 1117 /* translators: %1$s: Number of items */
1495 1118 'styles' => sprintf( _n( '%1$s Style', '%1$s Styles', $m, 'formidable' ), $m ),
1496 1119 /* translators: %1$s: Number of items */
1497 1120 'terms' => sprintf( _n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m ),
@@ -1498,23 +1121,9 @@
1498 1121 /* translators: %1$s: Number of items */
1499 1122 'actions' => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ),
1500 1123 );
1501 1124
1502 - if ( isset( $strings[ $type ] ) ) {
1503 - $s_message[] = $strings[ $type ];
1504 - } else {
1505 - $string = ' ' . $m . ' ' . ucfirst( $type );
1506 -
1507 - /**
1508 - * @since 5.3
1509 - *
1510 - * @param string $string Message string for imported item.
1511 - * @param int $m Number of item that was imported.
1512 - * }
1513 - */
1514 - $string = apply_filters( 'frm_xml_' . $type . '_count_message', $string, $m );
1515 - $s_message[] = $string;
1516 - }
1125 + $s_message[] = isset( $strings[ $type ] ) ? $strings[ $type ] : ' ' . $m . ' ' . ucfirst( $type );
1517 1126 }
1518 1127
1519 1128 /**
1520 1129 * If a single form was imported, include a link in the success message.
@@ -1591,9 +1200,8 @@
1591 1200 * @since 3.06
1592 1201 */
1593 1202 public static function prepare_field_for_export( &$field ) {
1594 1203 self::remove_default_field_options( $field );
1595 - self::add_image_src_to_image_options( $field );
1596 1204 }
1597 1205
1598 1206 /**
1599 1207 * Remove defaults from field options too
@@ -1625,41 +1233,8 @@
1625 1233 $field->field_options = serialize( $options );
1626 1234 }
1627 1235
1628 1236 /**
1629 - * Add image "src" key to each image option so the image can be imported to another website.
1630 - *
1631 - * @since 5.5.1
1632 - *
1633 - * @param stdClass $field
1634 - * @return void
1635 - */
1636 - private static function add_image_src_to_image_options( $field ) {
1637 - if ( empty( $field->options ) || false === strpos( $field->options, 'image' ) ) {
1638 - return;
1639 - }
1640 -
1641 - $updated = false;
1642 - $options = $field->options;
1643 - FrmAppHelper::unserialize_or_decode( $options );
1644 -
1645 - if ( ! $options || ! is_array( $options ) ) {
1646 - return;
1647 - }
1648 -
1649 - foreach ( $options as $key => $option ) {
1650 - if ( is_array( $option ) && ! empty( $option['image'] ) ) {
1651 - $options[ $key ]['src'] = wp_get_attachment_url( $option['image'] );
1652 - $updated = true;
1653 - }
1654 - }
1655 -
1656 - if ( $updated ) {
1657 - $field->options = maybe_serialize( $options );
1658 - }
1659 - }
1660 -
1661 - /**
1662 1237 * @since 3.06.03
1663 1238 */
1664 1239 private static function default_field_options( $type ) {
1665 1240 $defaults = FrmFieldsHelper::get_default_field_options( $type );
@@ -1711,10 +1286,10 @@
1711 1286 public static function cdata( $str ) {
1712 1287 FrmAppHelper::unserialize_or_decode( $str );
1713 1288 if ( is_array( $str ) ) {
1714 1289 $str = json_encode( $str );
1715 - } elseif ( FrmAppHelper::is_valid_utf8( $str ) === false ) {
1716 - $str = FrmAppHelper::maybe_utf8_encode( $str );
1290 + } elseif ( seems_utf8( $str ) === false ) {
1291 + $str = utf8_encode( $str );
1717 1292 }
1718 1293
1719 1294 if ( is_numeric( $str ) ) {
1720 1295 return $str;
@@ -1758,13 +1333,9 @@
1758 1333
1759 1334 /**
1760 1335 * Migrate post settings to form action
1761 1336 *
1762 - * @param array $form_options
1763 - * @param int $form_id
1764 1337 * @param string $post_type
1765 - * @param array $imported
1766 - * @param bool $switch
1767 1338 */
1768 1339 private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
1769 1340 if ( ! isset( $form_options['create_post'] ) || ! $form_options['create_post'] ) {
1770 1341 return;
@@ -1833,9 +1404,9 @@
1833 1404
1834 1405 if ( ! $exists ) {
1835 1406 // this isn't an email, but we need to use a class that will always be included
1836 1407 FrmDb::save_json_post( $new_action );
1837 - ++$imported['imported']['actions'];
1408 + $imported['imported']['actions'] ++;
1838 1409 }
1839 1410 }
1840 1411
1841 1412 /**
@@ -1842,11 +1413,11 @@
1842 1413 * Switch old field IDs for new field IDs in emails and post
1843 1414 *
1844 1415 * @since 2.0
1845 1416 *
1846 - * @param array $post_content Check for old field IDs.
1847 - * @param array $basic_fields Fields with string or int saved.
1848 - * @param array $array_fields Fields with arrays saved.
1417 + * @param array $post_content - check for old field IDs
1418 + * @param array $basic_fields - fields with string or int saved
1419 + * @param array $array_fields - fields with arrays saved
1849 1420 *
1850 1421 * @return string $post_content - new field IDs
1851 1422 */
1852 1423 private static function switch_action_field_ids( $post_content, $basic_fields, $array_fields = array() ) {
@@ -1927,12 +1498,12 @@
1927 1498 );
1928 1499
1929 1500 if ( empty( $exists ) ) {
1930 1501 FrmDb::save_json_post( $new_notification );
1931 - ++$imported['imported']['actions'];
1502 + $imported['imported']['actions'] ++;
1932 1503 }
1933 1504 unset( $new_notification );
1934 - }//end foreach
1505 + }
1935 1506
1936 1507 self::remove_deprecated_notification_settings( $form_id, $form_options );
1937 1508 }
1938 1509
@@ -1941,9 +1512,9 @@
1941 1512 *
1942 1513 * @since 2.05
1943 1514 *
1944 1515 * @param int|string $form_id
1945 - * @param array $form_options
1516 + * @param array $form_options
1946 1517 */
1947 1518 private static function remove_deprecated_notification_settings( $form_id, $form_options ) {
1948 1519 $delete_settings = array( 'notification', 'autoresponder', 'email_to' );
1949 1520 foreach ( $delete_settings as $index ) {
@@ -1954,9 +1525,9 @@
1954 1525 FrmForm::update( $form_id, array( 'options' => $form_options ) );
1955 1526 }
1956 1527
1957 1528 private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) {
1958 - if ( ! isset( $form_options['notification'] ) && ! empty( $form_options['email_to'] ) ) {
1529 + if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) {
1959 1530 // add old settings into notification array
1960 1531 $form_options['notification'] = array( 0 => $form_options );
1961 1532 } elseif ( isset( $form_options['notification']['email_to'] ) ) {
1962 1533 // make sure it's in the correct format
@@ -1986,10 +1557,10 @@
1986 1557 $new_notification = array();
1987 1558 self::setup_new_notification( $new_notification, $notification, $atts );
1988 1559
1989 1560 $notifications[] = $new_notification;
1990 - }//end foreach
1991 - }//end if
1561 + }
1562 + }
1992 1563 }
1993 1564
1994 1565 private static function format_email_data( &$atts, $notification ) {
1995 1566 // Format email_to
@@ -2085,9 +1656,9 @@
2085 1656
2086 1657 /**
2087 1658 * Switch field IDs in pre-2.0 email conditional logic
2088 1659 *
2089 - * @param array $post_content Pass by reference.
1660 + * @param $post_content array, pass by reference
2090 1661 */
2091 1662 private static function switch_email_condition_field_ids( &$post_content ) {
2092 1663 // Switch field IDs in conditional logic
2093 1664 if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) {
@@ -2103,9 +1674,9 @@
2103 1674 private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) {
2104 1675 if ( isset( $form_options['auto_responder'] ) && $form_options['auto_responder'] && isset( $form_options['ar_email_message'] ) && $form_options['ar_email_message'] ) {
2105 1676 // migrate autoresponder
2106 1677
2107 - $email_field = $form_options['ar_email_to'] ?? 0;
1678 + $email_field = isset( $form_options['ar_email_to'] ) ? $form_options['ar_email_to'] : 0;
2108 1679 if ( strpos( $email_field, '|' ) ) {
2109 1680 // data from entries field
2110 1681 $email_field = explode( '|', $email_field );
2111 1682 if ( isset( $email_field[1] ) ) {
@@ -2119,18 +1690,18 @@
2119 1690 $notification = $form_options;
2120 1691 $new_notification2 = array(
2121 1692 'post_content' => array(
2122 1693 'email_message' => $notification['ar_email_message'],
2123 - 'email_subject' => $notification['ar_email_subject'] ?? '',
1694 + 'email_subject' => isset( $notification['ar_email_subject'] ) ? $notification['ar_email_subject'] : '',
2124 1695 'email_to' => $email_field,
2125 - 'plain_text' => $notification['ar_plain_text'] ?? 0,
1696 + 'plain_text' => isset( $notification['ar_plain_text'] ) ? $notification['ar_plain_text'] : 0,
2126 1697 'inc_user_info' => 0,
2127 1698 ),
2128 1699 'post_name' => $form_id . '_email_' . count( $notifications ),
2129 1700 );
2130 1701
2131 - $reply_to = $notification['ar_reply_to'] ?? '';
2132 - $reply_to_name = $notification['ar_reply_to_name'] ?? '';
1702 + $reply_to = isset( $notification['ar_reply_to'] ) ? $notification['ar_reply_to'] : '';
1703 + $reply_to_name = isset( $notification['ar_reply_to_name'] ) ? $notification['ar_reply_to_name'] : '';
2133 1704
2134 1705 if ( ! empty( $reply_to ) ) {
2135 1706 $new_notification2['post_content']['reply_to'] = $reply_to;
2136 1707 }
@@ -2140,17 +1711,17 @@
2140 1711 }
2141 1712
2142 1713 $notifications[] = $new_notification2;
2143 1714 unset( $new_notification2 );
2144 - }//end if
1715 + }
2145 1716 }
2146 1717
2147 1718 /**
2148 1719 * PHP 8 backward compatibility for the libxml_disable_entity_loader function
2149 1720 *
2150 - * @param bool $loader
1721 + * @param boolean $disable
2151 1722 *
2152 - * @return bool
1723 + * @return boolean
2153 1724 */
2154 1725 public static function maybe_libxml_disable_entity_loader( $loader ) {
2155 1726 if ( version_compare( phpversion(), '8.0', '<' ) && function_exists( 'libxml_disable_entity_loader' ) ) {
2156 1727 $loader = libxml_disable_entity_loader( $loader ); // phpcs:disable Generic.PHP.DeprecatedFunctions.Deprecated
@@ -2161,22 +1732,6 @@
2161 1732
2162 1733 public static function check_if_libxml_disable_entity_loader_exists() {
2163 1734 return version_compare( phpversion(), '8.0', '<' ) && ! function_exists( 'libxml_disable_entity_loader' );
2164 1735 }
1736 +}
2165 1737
2166 - /**
2167 - * Get the file types allowed for importing.
2168 - * This is used in the "accept" attribute for the file upload input on the XML import page.
2169 - *
2170 - * @since 6.8.3
2171 - *
2172 - * @return array
2173 - */
2174 - public static function get_supported_upload_file_types() {
2175 - $file_types = array( '.xml' );
2176 - if ( FrmAppHelper::pro_is_installed() ) {
2177 - // CSV Importing is only available in Pro.
2178 - $file_types[] = '.csv';
2179 - }
2180 - return $file_types;
2181 - }
2182 -}