PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.2.07
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.2.07
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 +120 -823 6.26.15.2.07 View file →
@@ -5,18 +5,12 @@
5 5
6 6 class FrmXMLHelper {
7 7
8 8 /**
9 - * @var bool true if importing an XML from API, false if importing an XML file manually.
9 + * @var bool $installing_template 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 - /**
14 - * @param array|string $opt
15 - * @param string $padding
16 - *
17 - * @return void
18 - */
19 13 public static function get_xml_values( $opt, $padding ) {
20 14 if ( is_array( $opt ) ) {
21 15 foreach ( $opt as $ok => $ov ) {
22 16 echo "\n" . esc_html( $padding );
@@ -22,9 +16,8 @@
22 16 echo "\n" . esc_html( $padding );
23 17 $tag = ( is_numeric( $ok ) ? 'key:' : '' ) . $ok;
24 18 echo '<' . esc_html( $tag ) . '>';
25 19 self::get_xml_values( $ov, $padding . ' ' );
26 -
27 20 if ( is_array( $ov ) ) {
28 21 echo "\n" . esc_html( $padding );
29 22 }
30 23 echo '</' . esc_html( $tag ) . '>';
@@ -33,13 +26,8 @@
33 26 echo self::cdata( $opt ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
34 27 }
35 28 }
36 29
37 - /**
38 - * @param string $file
39 - *
40 - * @return array|WP_Error The items imported
41 - */
42 30 public static function import_xml( $file ) {
43 31 if ( ! defined( 'WP_IMPORTING' ) ) {
44 32 define( 'WP_IMPORTING', true );
45 33 }
@@ -44,26 +32,13 @@
44 32 define( 'WP_IMPORTING', true );
45 33 }
46 34
47 35 if ( ! class_exists( 'DOMDocument' ) ) {
48 - $error_message = sprintf(
49 - /* translators: 1: Documentation link */
50 - __( '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' ),
51 - '<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>'
52 - );
53 -
54 - return new WP_Error( 'SimpleXML_parse_error', $error_message, libxml_get_errors() );
36 + return new WP_Error( 'SimpleXML_parse_error', __( 'Your server does not have XML enabled', 'formidable' ), libxml_get_errors() );
55 37 }
56 38
57 - $xml_string = file_get_contents( $file );
58 - self::maybe_fix_xml( $xml_string );
59 -
60 - $dom = new DOMDocument();
61 -
62 - // LIBXML_COMPACT activates small nodes allocation optimization.
63 - // Use LIBXML_PARSEHUGE to avoid "parser error : internal error: Huge input lookup" for large (300MB) files.
64 - $success = $dom->loadXML( $xml_string, LIBXML_COMPACT | LIBXML_PARSEHUGE );
65 -
39 + $dom = new DOMDocument();
40 + $success = $dom->loadXML( file_get_contents( $file ) );
66 41 if ( ! $success ) {
67 42 return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
68 43 }
69 44
@@ -82,37 +57,8 @@
82 57 return self::import_xml_now( $xml );
83 58 }
84 59
85 60 /**
86 - * @since 6.2.3
87 - *
88 - * @param string $xml_string
89 - *
90 - * @return void
91 - */
92 - private static function maybe_fix_xml( &$xml_string ) {
93 - if ( '<?xml' !== substr( $xml_string, 0, 5 ) ) {
94 - // Some XML files have may have unexpected characters at the start.
95 - $xml_string = substr( $xml_string, strpos( $xml_string, '<?xml' ) );
96 - }
97 -
98 - // The Equity theme adds a <meta name="generator" content="Equity 1.7.13" /> tag using the "the_generator" filter.
99 - // Strip that out as it breaks the XML import.
100 - $channel_start_position = strpos( $xml_string, '<channel>' );
101 - $content_before_channel_tag = substr( $xml_string, 0, $channel_start_position );
102 -
103 - if ( 0 !== strpos( $content_before_channel_tag, '<meta name="generator" ' ) ) {
104 - $content_before_channel_tag = preg_replace(
105 - '/<meta\s+[^>]*name="generator"[^>]*\/>/i',
106 - '',
107 - $content_before_channel_tag,
108 - 1
109 - );
110 - $xml_string = $content_before_channel_tag . substr( $xml_string, $channel_start_position );
111 - }
112 - }
113 -
114 - /**
115 61 * Add terms, forms (form and field ids), posts (post ids), and entries to db, in that order
116 62 *
117 63 * @since 3.06
118 64 *
@@ -117,9 +63,8 @@
117 63 * @since 3.06
118 64 *
119 65 * @param object $xml
120 66 * @param bool $installing_template
121 - *
122 67 * @return array The number of items imported
123 68 */
124 69 public static function import_xml_now( $xml, $installing_template = false ) {
125 70 if ( ! defined( 'WP_IMPORTING' ) ) {
@@ -139,12 +84,12 @@
139 84 }
140 85
141 86 $imported = apply_filters( 'frm_importing_xml', $imported, $xml );
142 87
143 - if ( empty( $imported['form_status'] ) ) {
88 + if ( ! isset( $imported['form_status'] ) || empty( $imported['form_status'] ) ) {
144 89 // Check for an error message in the XML.
145 90 if ( isset( $xml->Code ) && isset( $xml->Message ) ) { // phpcs:ignore WordPress.NamingConventions
146 - $imported['error'] = (string) $xml->Message; // phpcs:ignore WordPress.NamingConventions
91 + $imported['error'] = reset( $xml->Message ); // phpcs:ignore WordPress.NamingConventions
147 92 }
148 93 }
149 94
150 95 return $imported;
@@ -151,9 +96,8 @@
151 96 }
152 97
153 98 /**
154 99 * @since 3.06
155 - *
156 100 * @return array
157 101 */
158 102 private static function pre_import_data() {
159 103 $defaults = array(
@@ -173,14 +117,8 @@
173 117 'terms' => array(),
174 118 );
175 119 }
176 120
177 - /**
178 - * @param SimpleXMLElement $terms
179 - * @param array $imported
180 - *
181 - * @return array
182 - */
183 121 public static function import_xml_terms( $terms, $imported ) {
184 122 foreach ( $terms as $t ) {
185 123 if ( term_exists( (string) $t->term_slug, (string) $t->term_taxonomy ) ) {
186 124 continue;
@@ -198,14 +136,14 @@
198 136 )
199 137 );
200 138
201 139 if ( $term && is_array( $term ) ) {
202 - ++$imported['imported']['terms'];
140 + $imported['imported']['terms'] ++;
203 141 $imported['terms'][ (int) $t->term_id ] = $term['term_id'];
204 142 }
205 143
206 144 unset( $term, $t );
207 - }//end foreach
145 + }
208 146
209 147 return $imported;
210 148 }
211 149
@@ -210,19 +148,13 @@
210 148 }
211 149
212 150 /**
213 151 * @since 2.0.8
214 - *
215 - * @param object $t
216 - *
217 - * @return int|string
218 152 */
219 153 private static function get_term_parent_id( $t ) {
220 154 $parent = (string) $t->term_parent;
221 -
222 155 if ( ! empty( $parent ) ) {
223 156 $parent = term_exists( (string) $t->term_parent, (string) $t->term_taxonomy );
224 -
225 157 if ( $parent ) {
226 158 $parent = $parent['term_id'];
227 159 } else {
228 160 $parent = 0;
@@ -231,14 +163,8 @@
231 163
232 164 return $parent;
233 165 }
234 166
235 - /**
236 - * @param SimpleXMLElement $forms
237 - * @param array $imported
238 - *
239 - * @return array
240 - */
241 167 public static function import_xml_forms( $forms, $imported ) {
242 168 $child_forms = array();
243 169
244 170 // Import child forms first
@@ -252,9 +178,8 @@
252 178 $this_form = self::maybe_get_form( $form );
253 179
254 180 $old_id = false;
255 181 $form_fields = false;
256 -
257 182 if ( ! empty( $this_form ) ) {
258 183 $form_id = $this_form->id;
259 184 $old_id = $this_form->id;
260 185 self::update_form( $this_form, $form, $imported );
@@ -261,13 +186,12 @@
261 186
262 187 $form_fields = self::get_form_fields( $form_id );
263 188 } else {
264 189 $form_id = FrmForm::create( $form );
265 -
266 190 if ( $form_id ) {
267 191 if ( empty( $form['parent_form_id'] ) ) {
268 192 // Don't include the repeater form in the imported count.
269 - ++$imported['imported']['forms'];
193 + $imported['imported']['forms'] ++;
270 194 }
271 195
272 196 // Keep track of whether this specific form was updated or not.
273 197 $imported['form_status'][ $form_id ] = 'imported';
@@ -292,9 +216,9 @@
292 216
293 217 do_action( 'frm_after_import_form', $form_id, $form );
294 218
295 219 unset( $form, $item );
296 - }//end foreach
220 + }
297 221
298 222 self::maybe_update_child_form_parent_id( $imported['forms'], $child_forms );
299 223
300 224 return $imported;
@@ -299,13 +223,8 @@
299 223
300 224 return $imported;
301 225 }
302 226
303 - /**
304 - * @param object $item
305 - *
306 - * @return array
307 - */
308 227 private static function fill_form( $item ) {
309 228 $form = array(
310 229 'id' => (int) $item->id,
311 230 'form_key' => (string) $item->form_key,
@@ -333,13 +252,8 @@
333 252
334 253 return $form;
335 254 }
336 255
337 - /**
338 - * @param array $form
339 - *
340 - * @return false|object
341 - */
342 256 private static function maybe_get_form( $form ) {
343 257 // if template, allow to edit if form keys match, otherwise, creation date must also match
344 258 $edit_query = array(
345 259 'form_key' => $form['form_key'],
@@ -344,9 +258,8 @@
344 258 $edit_query = array(
345 259 'form_key' => $form['form_key'],
346 260 'is_template' => $form['is_template'],
347 261 );
348 -
349 262 if ( ! $form['is_template'] ) {
350 263 $edit_query['created_at'] = $form['created_at'];
351 264 }
352 265
@@ -351,32 +264,17 @@
351 264 }
352 265
353 266 $edit_query = apply_filters( 'frm_match_xml_form', $edit_query, $form );
354 267
355 - $form = FrmForm::getAll( $edit_query, '', 1 );
356 -
357 - if ( is_object( $form ) && $form->status === 'trash' ) {
358 - FrmForm::destroy( $form->id );
359 - return false;
360 - }
361 -
362 - return $form;
268 + return FrmForm::getAll( $edit_query, '', 1 );
363 269 }
364 270
365 - /**
366 - * @param object $this_form
367 - * @param array $form
368 - * @param array $imported
369 - *
370 - * @return void
371 - */
372 271 private static function update_form( $this_form, $form, &$imported ) {
373 272 $form_id = $this_form->id;
374 273 FrmForm::update( $form_id, $form );
375 -
376 274 if ( empty( $form['parent_form_id'] ) ) {
377 275 // Don't include the repeater form in the updated count.
378 - ++$imported['updated']['forms'];
276 + $imported['updated']['forms'] ++;
379 277 }
380 278
381 279 // Keep track of whether this specific form was updated or not
382 280 $imported['form_status'][ $form_id ] = 'updated';
@@ -381,23 +279,16 @@
381 279 // Keep track of whether this specific form was updated or not
382 280 $imported['form_status'][ $form_id ] = 'updated';
383 281 }
384 282
385 - /**
386 - * @param int|string $form_id
387 - *
388 - * @return array
389 - */
390 283 private static function get_form_fields( $form_id ) {
391 284 $form_fields = FrmField::get_all_for_form( $form_id, '', 'exclude', 'exclude' );
392 285 $old_fields = array();
393 -
394 286 foreach ( $form_fields as $f ) {
395 287 $old_fields[ $f->id ] = $f;
396 288 $old_fields[ $f->field_key ] = $f->id;
397 289 unset( $f );
398 290 }
399 -
400 291 $form_fields = $old_fields;
401 292
402 293 return $form_fields;
403 294 }
@@ -403,12 +294,8 @@
403 294 }
404 295
405 296 /**
406 297 * Delete any fields attached to this form that were not included in the template
407 - *
408 - * @param array $form_fields
409 - *
410 - * @return void
411 298 */
412 299 private static function delete_removed_fields( $form_fields ) {
413 300 if ( ! empty( $form_fields ) ) {
414 301 foreach ( $form_fields as $field ) {
@@ -448,10 +335,10 @@
448 335 * Keep track of all imported child forms
449 336 *
450 337 * @since 2.0.16
451 338 *
452 - * @param int $form_id
453 - * @param int $parent_form_id
339 + * @param int $form_id
340 + * @param int $parent_form_id
454 341 * @param array $child_forms
455 342 */
456 343 private static function track_imported_child_forms( $form_id, $parent_form_id, &$child_forms ) {
457 344 if ( $parent_form_id ) {
@@ -484,14 +371,8 @@
484 371 *
485 372 * @since 2.0.13
486 373 *
487 374 * TODO: Cut down on params
488 - *
489 - * @param SimpleXMLElement $xml_fields
490 - * @param int|string $form_id
491 - * @param object $this_form
492 - * @param array $form_fields
493 - * @param array $imported
494 375 */
495 376 private static function import_xml_fields( $xml_fields, $form_id, $this_form, &$form_fields, &$imported ) {
496 377 $in_section = 0;
497 378 $keys_by_original_field_id = array();
@@ -509,13 +390,13 @@
509 390 if ( ! empty( $this_form ) ) {
510 391 // check for field to edit by field id
511 392 if ( isset( $form_fields[ $f['id'] ] ) ) {
512 393 FrmField::update( $f['id'], $f );
513 - ++$imported['updated']['fields'];
394 + $imported['updated']['fields'] ++;
514 395
515 396 unset( $form_fields[ $f['id'] ] );
516 397
517 - // Unset old field key.
398 + //unset old field key
518 399 if ( isset( $form_fields[ $f['field_key'] ] ) ) {
519 400 unset( $form_fields[ $f['field_key'] ] );
520 401 }
521 402 } elseif ( isset( $form_fields[ $f['field_key'] ] ) ) {
@@ -520,32 +401,25 @@
520 401 }
521 402 } elseif ( isset( $form_fields[ $f['field_key'] ] ) ) {
522 403 $keys_by_original_field_id[ $f['id'] ] = $f['field_key'];
523 404
524 - $old_field_id = $f['id'];
525 -
526 405 // check for field to edit by field key
527 406 unset( $f['id'] );
528 407
529 408 FrmField::update( $form_fields[ $f['field_key'] ], $f );
530 - ++$imported['updated']['fields'];
409 + $imported['updated']['fields'] ++;
531 410
532 - self::do_after_field_imported_action( $f, $form_fields, $old_field_id );
533 -
534 - // Unset old field id.
535 - unset( $form_fields[ $form_fields[ $f['field_key'] ] ] );
536 -
537 - // Unset old field key.
538 - unset( $form_fields[ $f['field_key'] ] );
411 + unset( $form_fields[ $form_fields[ $f['field_key'] ] ] ); //unset old field id
412 + unset( $form_fields[ $f['field_key'] ] ); //unset old field key
539 413 } else {
540 - // If no matching field id or key in this form, create the field.
414 + // if no matching field id or key in this form, create the field
541 415 self::create_imported_field( $f, $imported );
542 - }//end if
416 + }
543 417 } else {
544 418
545 419 self::create_imported_field( $f, $imported );
546 - }//end if
547 - }//end foreach
420 + }
421 + }
548 422
549 423 if ( $keys_by_original_field_id ) {
550 424 self::maybe_update_field_ids( $form_id, $keys_by_original_field_id );
551 425 }
@@ -550,53 +424,8 @@
550 424 self::maybe_update_field_ids( $form_id, $keys_by_original_field_id );
551 425 }
552 426 }
553 427
554 - /**
555 - * @since 6.8.4
556 - *
557 - * @param array $field_array
558 - *
559 - * @return array
560 - */
561 - private static function update_field_options_with_defaults( $field_array ) {
562 - $defaults = self::default_field_options( $field_array['type'] );
563 - $field_array['field_options'] = array_merge( $defaults, $field_array['field_options'] );
564 -
565 - return $field_array;
566 - }
567 -
568 - /**
569 - * @since 6.8.4
570 - *
571 - * @param array $field_array
572 - * @param array $form_fields
573 - * @param int $old_field_id
574 - *
575 - * @return void
576 - */
577 - private static function do_after_field_imported_action( $field_array, $form_fields, $old_field_id ) {
578 - // Assign field array the update field's ID.
579 - $field_array['id'] = $form_fields[ $field_array['field_key'] ];
580 -
581 - /**
582 - * Fires when an existing field is imported.
583 - *
584 - * @since 6.8.4
585 - *
586 - * @param array $field_array
587 - * @param int $field_id
588 - * @param int $old_field_id
589 - */
590 - do_action( 'frm_after_existing_field_is_imported', $field_array, $form_fields[ $field_array['field_key'] ], $old_field_id );
591 - }
592 -
593 - /**
594 - * @param object $field
595 - * @param int|string $form_id
596 - *
597 - * @return array
598 - */
599 428 private static function fill_field( $field, $form_id ) {
600 429 return array(
601 430 'id' => (int) $field->id,
602 431 'field_key' => (string) $field->field_key,
@@ -613,12 +442,8 @@
613 442 }
614 443
615 444 /**
616 445 * @since 4.06
617 - *
618 - * @param array $f
619 - *
620 - * @return void
621 446 */
622 447 private static function set_default_value( &$f ) {
623 448 $has_default = array(
624 449 'text',
@@ -645,12 +470,8 @@
645 470 /**
646 471 * Make sure the required indicator is set.
647 472 *
648 473 * @since 4.05
649 - *
650 - * @param array $f
651 - *
652 - * @return void
653 474 */
654 475 private static function maybe_add_required( &$f ) {
655 476 if ( $f['required'] && ! isset( $f['field_options']['required_indicator'] ) ) {
656 477 $f['field_options']['required_indicator'] = '*';
@@ -660,13 +481,10 @@
660 481 /**
661 482 * Update the current in_section value at the beginning of the field loop
662 483 *
663 484 * @since 2.0.25
664 - *
665 - * @param int $in_section
485 + * @param int $in_section
666 486 * @param array $f
667 - *
668 - * @return void
669 487 */
670 488 private static function maybe_update_in_section_variable( &$in_section, &$f ) {
671 489 // If we're at the end of a section, switch $in_section is 0
672 490 if ( in_array( $f['type'], array( 'end_divider', 'break', 'form' ) ) ) {
@@ -678,9 +496,9 @@
678 496 $f['field_options']['in_section'] = $in_section;
679 497 }
680 498
681 499 // If we're starting a new section, switch $in_section to ID of divider
682 - if ( $f['type'] === 'divider' ) {
500 + if ( $f['type'] == 'divider' ) {
683 501 $in_section = $f['id'];
684 502 }
685 503 }
686 504
@@ -696,12 +514,11 @@
696 514 if ( ! isset( $imported['forms'] ) ) {
697 515 return;
698 516 }
699 517
700 - if ( $f['type'] === 'form' || ( $f['type'] === 'divider' && FrmField::is_option_true( $f['field_options'], 'repeat' ) ) ) {
518 + if ( $f['type'] == 'form' || ( $f['type'] == 'divider' && FrmField::is_option_true( $f['field_options'], 'repeat' ) ) ) {
701 519 if ( FrmField::is_option_true( $f['field_options'], 'form_select' ) ) {
702 520 $form_select = (int) $f['field_options']['form_select'];
703 -
704 521 if ( isset( $imported['forms'][ $form_select ] ) ) {
705 522 $f['field_options']['form_select'] = $imported['forms'][ $form_select ];
706 523 }
707 524 }
@@ -714,10 +531,8 @@
714 531 * @since 2.01.0
715 532 *
716 533 * @param array $imported
717 534 * @param array $f
718 - *
719 - * @return void
720 535 */
721 536 private static function maybe_update_get_values_form_setting( $imported, &$f ) {
722 537 if ( ! isset( $imported['forms'] ) ) {
723 538 return;
@@ -724,9 +539,8 @@
724 539 }
725 540
726 541 if ( FrmField::is_option_true_in_array( $f['field_options'], 'get_values_form' ) ) {
727 542 $old_form = $f['field_options']['get_values_form'];
728 -
729 543 if ( isset( $imported['forms'][ $old_form ] ) ) {
730 544 $f['field_options']['get_values_form'] = $imported['forms'][ $old_form ];
731 545 }
732 546 }
@@ -732,23 +546,27 @@
732 546 }
733 547 }
734 548
735 549 /**
550 + * If field settings have been migrated, update the values during import.
551 + *
736 552 * @since 4.0
737 - *
738 - * @param array $f
739 - *
740 - * @return void
741 553 */
554 + private static function run_field_migrations( &$f ) {
555 + self::migrate_placeholders( $f );
556 + $f = apply_filters( 'frm_import_xml_field', $f );
557 + }
558 +
559 + /**
560 + * @since 4.0
561 + */
742 562 private static function migrate_placeholders( &$f ) {
743 563 $update_values = self::migrate_field_placeholder( $f, 'clear_on_focus' );
744 -
745 564 foreach ( $update_values as $k => $v ) {
746 565 $f[ $k ] = $v;
747 566 }
748 567
749 568 $update_values = self::migrate_field_placeholder( $f, 'default_blank' );
750 -
751 569 foreach ( $update_values as $k => $v ) {
752 570 $f[ $k ] = $v;
753 571 }
754 572 }
@@ -757,18 +575,13 @@
757 575 * Move clear_on_focus or default_blank to placeholder.
758 576 * Also called during database migration in FrmMigrate.
759 577 *
760 578 * @since 4.0
761 - *
762 - * @param array|object $field
763 - * @param string $type
764 - *
765 579 * @return array
766 580 */
767 581 public static function migrate_field_placeholder( $field, $type ) {
768 - $field = (array) $field;
582 + $field = (array) $field;
769 583 $field_options = $field['field_options'];
770 -
771 584 if ( empty( $field_options[ $type ] ) || empty( $field['default_value'] ) ) {
772 585 return array();
773 586 }
774 587
@@ -781,12 +594,10 @@
781 594 );
782 595
783 596 // If a dropdown placeholder was used, remove the option so it won't be included twice.
784 597 $options = $field['options'];
785 -
786 598 if ( $type === 'default_blank' && is_array( $options ) ) {
787 599 $default_value = $field['default_value'];
788 -
789 600 if ( is_array( $default_value ) ) {
790 601 $default_value = reset( $default_value );
791 602 }
792 603
@@ -791,9 +602,9 @@
791 602 }
792 603
793 604 foreach ( $options as $opt_key => $opt ) {
794 605 if ( is_array( $opt ) ) {
795 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
606 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
796 607 }
797 608
798 609 if ( $opt == $default_value ) {
799 610 unset( $options[ $opt_key ] );
@@ -812,70 +623,26 @@
812 623 * @since 2.0.25
813 624 *
814 625 * @param array $f
815 626 * @param array $imported
816 - *
817 - * @return void
818 627 */
819 628 private static function create_imported_field( $f, &$imported ) {
820 - $f = self::update_field_options_with_defaults( $f );
629 + $defaults = self::default_field_options( $f['type'] );
630 + $f['field_options'] = array_merge( $defaults, $f['field_options'] );
821 631
822 - if ( is_callable( 'FrmProFileImport::import_attachment' ) ) {
823 - $f = self::maybe_import_images_for_options( $f );
824 - }
825 -
826 632 $new_id = FrmField::create( $f );
827 -
828 633 if ( $new_id != false ) {
829 - ++$imported['imported']['fields'];
634 + $imported['imported']['fields'] ++;
830 635 do_action( 'frm_after_field_is_imported', $f, $new_id );
831 636 }
832 637 }
833 638
834 639 /**
835 - * Import images for radio buttons and checkboxes from image src if available.
836 - *
837 - * @since 5.5.1
838 - *
839 - * @param array $field
840 - *
841 - * @return array
842 - */
843 - private static function maybe_import_images_for_options( $field ) {
844 - if ( empty( $field['options'] ) || ! is_array( $field['options'] ) ) {
845 - return $field;
846 - }
847 -
848 - foreach ( $field['options'] as $key => $option ) {
849 - if ( ! is_array( $option ) || empty( $option['src'] ) ) {
850 - continue;
851 - }
852 -
853 - $field_object = (object) $field;
854 - // Fake the file type as FrmProImport::import_attachment checks for file type.
855 - $field_object->type = 'file';
856 -
857 - $image_id = FrmProFileImport::import_attachment( $option['src'], $field_object );
858 - // Remove the src from options as it isn't required after import.
859 - unset( $field['options'][ $key ]['src'] );
860 -
861 - if ( is_numeric( $image_id ) ) {
862 - $field['options'][ $key ]['image'] = $image_id;
863 - }
864 - }
865 -
866 - return $field;
867 - }
868 -
869 - /**
870 640 * Fix field ids for fields that already exist prior to import.
871 641 *
872 642 * @since 4.07
873 - *
874 - * @param int $form_id
643 + * @param int $form_id
875 644 * @param array $keys_by_original_field_id
876 - *
877 - * @return void
878 645 */
879 646 protected static function maybe_update_field_ids( $form_id, $keys_by_original_field_id ) {
880 647 global $frm_duplicate_ids;
881 648
@@ -915,10 +682,8 @@
915 682 *
916 683 * @since 2.0.19
917 684 *
918 685 * @param array $form
919 - *
920 - * @return void
921 686 */
922 687 private static function update_custom_style_setting_on_import( &$form ) {
923 688 if ( ! isset( $form['options']['custom_style'] ) ) {
924 689 return;
@@ -923,9 +688,9 @@
923 688 if ( ! isset( $form['options']['custom_style'] ) ) {
924 689 return;
925 690 }
926 691
927 - if ( is_numeric( $form['options']['custom_style'] ) && 1 === intval( $form['options']['custom_style'] ) ) {
692 + if ( is_numeric( $form['options']['custom_style'] ) ) {
928 693 // Set to default
929 694 $form['options']['custom_style'] = 1;
930 695 } else {
931 696 // Replace the style name with the style ID on import
@@ -946,9 +711,9 @@
946 711
947 712 // Set to default
948 713 $form['options']['custom_style'] = 1;
949 714 }
950 - }//end if
715 + }
951 716 }
952 717
953 718 /**
954 719 * After styles are imported, check for any forms that were linked
@@ -954,12 +719,8 @@
954 719 * After styles are imported, check for any forms that were linked
955 720 * and link them back up.
956 721 *
957 722 * @since 2.2.7
958 - *
959 - * @param int|string $form_id
960 - *
961 - * @return void
962 723 */
963 724 private static function update_custom_style_setting_after_import( $form_id ) {
964 725 $form = FrmForm::getOne( $form_id );
965 726
@@ -968,9 +729,8 @@
968 729 $saved_style = $form['options']['custom_style'];
969 730 $form['options']['custom_style'] = $form['options']['old_style'];
970 731 self::update_custom_style_setting_on_import( $form );
971 732 $has_changed = ( $form['options']['custom_style'] != $saved_style && $form['options']['custom_style'] != $form['options']['old_style'] );
972 -
973 733 if ( $has_changed ) {
974 734 FrmForm::update( $form['id'], $form );
975 735 }
976 736 }
@@ -975,16 +735,8 @@
975 735 }
976 736 }
977 737 }
978 738
979 - /**
980 - * Handle import for all posts. This includes views, styles, pages, and form actions.
981 - *
982 - * @param SimpleXMLElement $views
983 - * @param array $imported
984 - *
985 - * @return array
986 - */
987 739 public static function import_xml_views( $views, $imported ) {
988 740 $imported['posts'] = array();
989 741 $form_action_type = FrmFormActionsController::$action_post_type;
990 742
@@ -993,11 +745,8 @@
993 745 $form_action_type => 'actions',
994 746 'frm_styles' => 'styles',
995 747 );
996 748
997 - $view_ids = array();
998 - $posts_with_shortcodes = array();
999 -
1000 749 foreach ( $views as $item ) {
1001 750 $post = array(
1002 751 'post_title' => (string) $item->title,
1003 752 'post_name' => (string) $item->post_name,
@@ -1020,15 +769,8 @@
1020 769 'layout' => array(),
1021 770 'tax_input' => array(),
1022 771 );
1023 772
1024 - $post['post_content'] = self::switch_form_ids( $post['post_content'], $imported['forms'] );
1025 -
1026 - // Fix issue with line breaks appearing in descriptions as "rn".
1027 - if ( $post['post_type'] === $form_action_type ) {
1028 - $post['post_content'] = str_replace( '\\\\r\\\\n', '\\r\\n', $post['post_content'] );
1029 - }
1030 -
1031 773 $old_id = $post['post_id'];
1032 774 self::populate_post( $post, $item, $imported );
1033 775
1034 776 unset( $item );
@@ -1033,221 +775,67 @@
1033 775
1034 776 unset( $item );
1035 777
1036 778 $post_id = false;
1037 -
1038 - if ( $post['post_type'] === $form_action_type ) {
779 + if ( $post['post_type'] == $form_action_type ) {
1039 780 $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] );
1040 -
1041 - if ( $action_control && is_object( $action_control ) && isset( $imported['form_status'] ) ) {
781 + if ( $action_control && is_object( $action_control ) ) {
1042 782 $post_id = $action_control->maybe_create_action( $post, $imported['form_status'] );
1043 783 }
1044 784 unset( $action_control );
1045 - } elseif ( $post['post_type'] === 'frm_styles' ) {
785 + } elseif ( $post['post_type'] == 'frm_styles' ) {
1046 786 // Properly encode post content before inserting the post
1047 787 $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] );
788 + $custom_css = isset( $post['post_content']['custom_css'] ) ? $post['post_content']['custom_css'] : '';
1048 789 $post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] );
1049 - // Store template data additionally to a postmeta that can be used to revert the style to default template style.
1050 - $post['postmeta']['frm_style_default'] = $post['post_content'];
1051 790
1052 791 // Create/update post now
1053 792 $post_id = wp_insert_post( $post );
793 + self::maybe_update_custom_css( $custom_css );
1054 794 } else {
1055 795 if ( $post['post_type'] === 'frm_display' ) {
1056 796 $post['post_content'] = self::maybe_prepare_json_view_content( $post['post_content'] );
1057 - } elseif ( 'page' === $post['post_type'] && isset( $imported['posts'][ $post['post_parent'] ] ) ) {
1058 - $post['post_parent'] = $imported['posts'][ $post['post_parent'] ];
1059 797 }
1060 798 // Create/update post now
1061 799 $post_id = wp_insert_post( $post );
1062 - }//end if
800 + }
1063 801
1064 802 if ( ! is_numeric( $post_id ) ) {
1065 803 continue;
1066 804 }
1067 805
1068 - if ( false !== strpos( $post['post_content'], '[display-frm-data' ) || false !== strpos( $post['post_content'], '[formidable' ) ) {
1069 - $posts_with_shortcodes[ $post_id ] = $post;
1070 - }
1071 -
1072 806 self::update_postmeta( $post, $post_id );
1073 807 self::update_layout( $post, $post_id );
1074 808
1075 809 $this_type = 'posts';
1076 -
1077 810 if ( isset( $post_types[ $post['post_type'] ] ) ) {
1078 811 $this_type = $post_types[ $post['post_type'] ];
1079 812 }
1080 813
1081 814 if ( isset( $post['ID'] ) && $post_id == $post['ID'] ) {
1082 - ++$imported['updated'][ $this_type ];
815 + $imported['updated'][ $this_type ] ++;
1083 816 } else {
1084 - ++$imported['imported'][ $this_type ];
817 + $imported['imported'][ $this_type ] ++;
1085 818 }
1086 819
1087 - $imported['posts'][ $old_id ] = $post_id;
820 + $imported['posts'][ (int) $old_id ] = $post_id;
1088 821
1089 - if ( $post['post_type'] === 'frm_display' ) {
1090 - $view_ids[ $old_id ] = $post_id;
1091 - }
1092 -
1093 822 do_action( 'frm_after_import_view', $post_id, $post );
1094 823
1095 824 unset( $post );
1096 - }//end foreach
1097 -
1098 - if ( $posts_with_shortcodes && $view_ids ) {
1099 - self::maybe_switch_view_ids_after_importing_posts( $posts_with_shortcodes, $view_ids );
1100 825 }
1101 - unset( $posts_with_shortcodes, $view_ids );
1102 826
1103 - if ( ! empty( $imported['forms'] ) ) {
1104 - // clear imported forms style cache to make sure the new styles are applied to the forms
1105 - self::clear_forms_style_caches( $imported['forms'] );
1106 - }
1107 -
1108 827 self::maybe_update_stylesheet( $imported );
1109 828
1110 - flush_rewrite_rules();
1111 -
1112 829 return $imported;
1113 830 }
1114 831
1115 832 /**
1116 - * Clears styles from cache for imported forms
1117 - *
1118 - * @param array $imported_forms
1119 - *
1120 - * @return void
1121 - */
1122 - private static function clear_forms_style_caches( $imported_forms ) {
1123 - $where = array(
1124 - 'id' => $imported_forms,
1125 - 'options LIKE' => '"old_style"',
1126 - );
1127 - $forms = FrmDb::get_results( 'frm_forms', $where );
1128 -
1129 - foreach ( $forms as $form ) {
1130 - FrmAppHelper::unserialize_or_decode( $form->options );
1131 -
1132 - if ( ! $form->options ) {
1133 - continue;
1134 - }
1135 -
1136 - $where = array(
1137 - 'post_name' => $form->options['old_style'],
1138 - 'post_type' => FrmStylesController::$post_type,
1139 - );
1140 -
1141 - $select = 'ID';
1142 -
1143 - $cache_key = FrmDb::generate_cache_key( $where, array( 'limit' => 1 ), $select, 'var' );
1144 - FrmDb::delete_cache_and_transient( $cache_key, 'post' );
1145 - }
1146 - }
1147 -
1148 - /**
1149 - * Replace old form ids with new ones in a string.
1150 - *
1151 - * @param string $string
1152 - * @param array<int> $form_ids new form ids indexed by old form id.
1153 - *
1154 - * @return string
1155 - */
1156 - private static function switch_form_ids( $string, $form_ids ) {
1157 - if ( false === strpos( $string, '[formidable' ) ) {
1158 - // Skip string replacing if there are no form shortcodes in string.
1159 - return $string;
1160 - }
1161 -
1162 - foreach ( $form_ids as $old_id => $new_id ) {
1163 - $string = str_replace(
1164 - array(
1165 - '[formidable id="' . $old_id . '"',
1166 - '[formidable id=' . $old_id . ']',
1167 - '[formidable id=' . $old_id . ' ',
1168 - '"formId":"' . $old_id . '"',
1169 - ),
1170 - array(
1171 - '[formidable id="' . $new_id . '"',
1172 - '[formidable id=' . $new_id . ']',
1173 - '[formidable id=' . $new_id . ' ',
1174 - '"formId":"' . $new_id . '"',
1175 - ),
1176 - $string
1177 - );
1178 - }
1179 -
1180 - return $string;
1181 - }
1182 -
1183 - /**
1184 - * @param array<array> $posts_with_shortcodes indexed by current post id.
1185 - * @param array<int> $view_ids new view ids indexed by old view id.
1186 - *
1187 - * @return void
1188 - */
1189 - private static function maybe_switch_view_ids_after_importing_posts( $posts_with_shortcodes, $view_ids ) {
1190 - foreach ( $posts_with_shortcodes as $imported_post_id => $post ) {
1191 - $post_content = self::switch_view_ids( $post['post_content'], $view_ids );
1192 -
1193 - if ( $post_content === $post['post_content'] ) {
1194 - continue;
1195 - }
1196 -
1197 - wp_update_post(
1198 - array(
1199 - 'ID' => $imported_post_id,
1200 - 'post_content' => $post_content,
1201 - )
1202 - );
1203 - }
1204 - }
1205 -
1206 - /**
1207 - * Replace old view ids with new ones in a string.
1208 - *
1209 - * @param string $string
1210 - * @param array<int> $view_ids new view ids indexed by old view id.
1211 - *
1212 - * @return string
1213 - */
1214 - private static function switch_view_ids( $string, $view_ids ) {
1215 - if ( false === strpos( $string, '[display-frm-data' ) ) {
1216 - // Skip string replacing if there are no view shortcodes in string.
1217 - return $string;
1218 - }
1219 -
1220 - foreach ( $view_ids as $old_id => $new_id ) {
1221 - $string = str_replace(
1222 - array(
1223 - '[display-frm-data id="' . $old_id . '"',
1224 - '[display-frm-data id=' . $old_id . ']',
1225 - '[display-frm-data id=' . $old_id . ' ',
1226 - '"viewId":"' . $old_id . '"',
1227 - ),
1228 - array(
1229 - '[display-frm-data id="' . $new_id . '"',
1230 - '[display-frm-data id=' . $new_id . ']',
1231 - '[display-frm-data id=' . $new_id . ' ',
1232 - '"viewId":"' . $new_id . '"',
1233 - ),
1234 - $string
1235 - );
1236 - unset( $old_id, $new_id );
1237 - }
1238 -
1239 - return $string;
1240 - }
1241 -
1242 - /**
1243 833 * @param string $content
1244 - *
1245 834 * @return string
1246 835 */
1247 836 private static function maybe_prepare_json_view_content( $content ) {
1248 837 $maybe_decoded = FrmAppHelper::maybe_json_decode( $content );
1249 -
1250 838 if ( is_array( $maybe_decoded ) && isset( $maybe_decoded[0] ) && isset( $maybe_decoded[0]['box'] ) ) {
1251 839 return FrmAppHelper::prepare_and_encode( $maybe_decoded );
1252 840 }
1253 841 return $content;
@@ -1252,15 +840,8 @@
1252 840 }
1253 841 return $content;
1254 842 }
1255 843
1256 - /**
1257 - * @param array $post
1258 - * @param object $item
1259 - * @param array $imported
1260 - *
1261 - * @return void
1262 - */
1263 844 private static function populate_post( &$post, $item, $imported ) {
1264 845 if ( isset( $item->attachment_url ) ) {
1265 846 $post['attachment_url'] = (string) $item->attachment_url;
1266 847 }
@@ -1302,9 +883,9 @@
1302 883 'key' => (string) $meta->meta_key,
1303 884 'value' => (string) $meta->meta_value,
1304 885 );
1305 886
1306 - // Switch old form and field ids to new ones.
887 + //switch old form and field ids to new ones
1307 888 if ( 'frm_form_id' === $m['key'] && isset( $imported['forms'][ (int) $m['value'] ] ) ) {
1308 889 $m['value'] = $imported['forms'][ (int) $m['value'] ];
1309 890 } else {
1310 891 $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
@@ -1320,37 +901,10 @@
1320 901 $m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ];
1321 902 }
1322 903 }
1323 904
1324 - if ( ! empty( $m['value']['map_address_fields'] ) ) {
1325 - foreach ( $m['value']['map_address_fields'] as $address_field_key => $address_field_id ) {
1326 - if ( isset( $frm_duplicate_ids[ $address_field_id ] ) ) {
1327 - $m['value']['map_address_fields'][ $address_field_key ] = $frm_duplicate_ids[ $address_field_id ];
1328 - }
1329 - }
1330 - }
1331 -
1332 - if ( ! empty( $m['value']['calendar_options'] ) ) {
1333 - foreach ( $m['value']['calendar_options'] as $calendar_option_group_key => $calendar_option ) {
1334 - if ( isset( $frm_duplicate_ids[ $calendar_option['value'] ] ) ) {
1335 - $m['value']['calendar_options'][ $calendar_option_group_key ]['value'] = $frm_duplicate_ids[ $calendar_option['value'] ];
1336 - }
1337 - }
1338 - }
1339 -
1340 - if ( ! empty( $m['value']['timeline_options'] ) ) {
1341 - foreach ( $m['value']['timeline_options'] as $timeline_option_group_key => $timeline_group_option ) {
1342 - foreach ( $timeline_group_option as $timeline_option_key => $timeline_option ) {
1343 - if ( isset( $frm_duplicate_ids[ $timeline_option ] ) ) {
1344 - $m['value']['timeline_options'][ $timeline_option_group_key ][ $timeline_option_key ] = $frm_duplicate_ids[ $timeline_option ];
1345 - }
1346 - }
1347 - }
1348 - }
1349 -
1350 905 $check_dup_array = array();
1351 -
1352 - if ( ! empty( $m['value']['order_by'] ) ) {
906 + if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) {
1353 907 if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) {
1354 908 $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ];
1355 909 } elseif ( is_array( $m['value']['order_by'] ) ) {
1356 910 $check_dup_array[] = 'order_by';
@@ -1356,9 +910,9 @@
1356 910 $check_dup_array[] = 'order_by';
1357 911 }
1358 912 }
1359 913
1360 - if ( ! empty( $m['value']['where'] ) ) {
914 + if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) {
1361 915 $check_dup_array[] = 'where';
1362 916 }
1363 917
1364 918 foreach ( $check_dup_array as $check_k ) {
@@ -1368,11 +922,11 @@
1368 922 }
1369 923 unset( $mk, $mv );
1370 924 }
1371 925 }
1372 - }//end if
1373 - }//end if
1374 - }//end if
926 + }
927 + }
928 + }
1375 929
1376 930 if ( ! is_array( $m['value'] ) ) {
1377 931 $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
1378 932 }
@@ -1379,14 +933,8 @@
1379 933
1380 934 $post['postmeta'][ (string) $meta->meta_key ] = $m['value'];
1381 935 }
1382 936
1383 - /**
1384 - * @param array $post
1385 - * @param object $layout
1386 - *
1387 - * @return void
1388 - */
1389 937 private static function populate_layout( &$post, $layout ) {
1390 938 $post['layout'][ (string) $layout->type ] = (string) $layout->data;
1391 939 }
1392 940
@@ -1392,25 +940,22 @@
1392 940
1393 941 /**
1394 942 * Add terms to post
1395 943 *
1396 - * @param array $post By reference.
1397 - * @param object $item The XML object data.
944 + * @param array $post by reference
945 + * @param object $item The XML object data
1398 946 */
1399 947 private static function populate_taxonomies( &$post, $item ) {
1400 948 foreach ( $item->category as $c ) {
1401 949 $att = $c->attributes();
1402 -
1403 950 if ( ! isset( $att['nicename'] ) ) {
1404 951 continue;
1405 952 }
1406 953
1407 954 $taxonomy = (string) $att['domain'];
1408 -
1409 955 if ( is_taxonomy_hierarchical( $taxonomy ) ) {
1410 956 $name = (string) $att['nicename'];
1411 957 $h_term = get_term_by( 'slug', $name, $taxonomy );
1412 -
1413 958 if ( $h_term ) {
1414 959 $name = $h_term->term_id;
1415 960 }
1416 961 unset( $h_term );
@@ -1423,17 +968,13 @@
1423 968 }
1424 969
1425 970 $post['tax_input'][ $taxonomy ][] = $name;
1426 971 unset( $name );
1427 - }//end foreach
972 + }
1428 973 }
1429 974
1430 975 /**
1431 - * Edit post if the key and created time match.
1432 - *
1433 - * @param array $post By reference.
1434 - *
1435 - * @return void
976 + * Edit post if the key and created time match
1436 977 */
1437 978 private static function maybe_editing_post( &$post ) {
1438 979 $match_by = array(
1439 980 'post_type' => $post['post_type'],
@@ -1441,9 +982,9 @@
1441 982 'post_status' => $post['post_status'],
1442 983 'posts_per_page' => 1,
1443 984 );
1444 985
1445 - if ( in_array( $post['post_status'], array( 'trash', 'draft' ), true ) ) {
986 + if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) {
1446 987 $match_by['include'] = $post['post_id'];
1447 988 unset( $match_by['name'] );
1448 989 }
1449 990
@@ -1454,43 +995,26 @@
1454 995 $post['ID'] = current( $editing )->ID;
1455 996 }
1456 997 }
1457 998
1458 - /**
1459 - * @param array $post
1460 - * @param int $post_id
1461 - *
1462 - * @return void
1463 - */
1464 999 private static function update_postmeta( &$post, $post_id ) {
1465 1000 foreach ( $post['postmeta'] as $k => $v ) {
1466 - switch ( $k ) {
1467 - case '_edit_last':
1468 - $v = FrmAppHelper::get_user_id_param( $v );
1469 - break;
1001 + if ( '_edit_last' == $k ) {
1002 + $v = FrmAppHelper::get_user_id_param( $v );
1003 + } elseif ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) {
1004 + // Change the attachment ID.
1005 + $field_obj = FrmFieldFactory::get_field_type( 'file' );
1006 + $v = $field_obj->get_file_id( $v );
1007 + }
1470 1008
1471 - case '_thumbnail_id':
1472 - if ( FrmAppHelper::pro_is_installed() ) {
1473 - // Change the attachment ID.
1474 - $field_obj = FrmFieldFactory::get_field_type( 'file' );
1475 - $v = $field_obj->get_file_id( $v );
1476 - }
1477 - break;
1009 + if ( 'frm_dyncontent' === $k && is_array( $v ) ) {
1010 + $v = json_encode( $v );
1011 + }
1478 1012
1479 - case 'frm_dyncontent':
1480 - if ( is_array( $v ) ) {
1481 - $v = json_encode( $v );
1482 - }
1483 - break;
1013 + update_post_meta( $post_id, $k, $v );
1484 1014
1485 - case 'frm_param':
1486 - add_rewrite_endpoint( $v, EP_PERMALINK | EP_PAGES );
1487 - break;
1488 - }//end switch
1489 -
1490 - update_post_meta( $post_id, $k, $v );
1491 1015 unset( $k, $v );
1492 - }//end foreach
1016 + }
1493 1017 }
1494 1018
1495 1019 /**
1496 1020 * @param array $post
@@ -1499,9 +1023,8 @@
1499 1023 private static function update_layout( &$post, $post_id ) {
1500 1024 if ( is_callable( 'FrmViewsLayout::maybe_create_layouts_for_view' ) ) {
1501 1025 $listing_layout = ! empty( $post['layout']['listing'] ) ? json_decode( $post['layout']['listing'], true ) : array();
1502 1026 $detail_layout = ! empty( $post['layout']['detail'] ) ? json_decode( $post['layout']['detail'], true ) : array();
1503 -
1504 1027 if ( $listing_layout || $detail_layout ) {
1505 1028 FrmViewsLayout::maybe_create_layouts_for_view( $post_id, $listing_layout, $detail_layout );
1506 1029 }
1507 1030 }
@@ -1507,22 +1030,32 @@
1507 1030 }
1508 1031 }
1509 1032
1510 1033 /**
1511 - * @param array $imported
1034 + * If a template includes custom css, let's include it.
1035 + * The custom css is included on the default style.
1512 1036 *
1513 - * @return void
1037 + * @since 2.03
1514 1038 */
1039 + private static function maybe_update_custom_css( $custom_css ) {
1040 + if ( empty( $custom_css ) ) {
1041 + return;
1042 + }
1043 +
1044 + $frm_style = new FrmStyle();
1045 + $default_style = $frm_style->get_default_style();
1046 + $default_style->post_content['custom_css'] .= "\r\n\r\n" . $custom_css;
1047 + $frm_style->save( $default_style );
1048 + }
1049 +
1515 1050 private static function maybe_update_stylesheet( $imported ) {
1516 - $new_styles = ! empty( $imported['imported']['styles'] );
1517 - $updated_styles = ! empty( $imported['updated']['styles'] );
1518 -
1051 + $new_styles = isset( $imported['imported']['styles'] ) && ! empty( $imported['imported']['styles'] );
1052 + $updated_styles = isset( $imported['updated']['styles'] ) && ! empty( $imported['updated']['styles'] );
1519 1053 if ( $new_styles || $updated_styles ) {
1520 1054 if ( is_admin() && function_exists( 'get_filesystem_method' ) ) {
1521 1055 $frm_style = new FrmStyle();
1522 1056 $frm_style->update( 'default' );
1523 1057 }
1524 -
1525 1058 foreach ( $imported['forms'] as $form_id ) {
1526 1059 self::update_custom_style_setting_after_import( $form_id );
1527 1060 }
1528 1061 }
@@ -1528,46 +1061,20 @@
1528 1061 }
1529 1062 }
1530 1063
1531 1064 /**
1532 - * @param mixed $result
1533 1065 * @param string $message
1534 - * @param array $errors
1535 1066 */
1536 1067 public static function parse_message( $result, &$message, &$errors ) {
1537 1068 if ( is_wp_error( $result ) ) {
1538 1069 $errors[] = $result->get_error_message();
1539 -
1540 - // Remove the SimpleXML_parse_error from the WP_Error object to avoid
1541 - // displaying duplicate error messages from $result->get_error_message()
1542 - $error_codes = $result->get_error_codes();
1543 - $error_details = array();
1544 -
1545 - foreach ( $error_codes as $error_code ) {
1546 - // Clone WP_Error data because WP_Error removes all error messages and data
1547 - // associated with the specified error code when an item is removed.
1548 - // Source: https://developer.wordpress.org/reference/classes/wp_error/remove/#source
1549 - $error_details = $result->get_error_data( $error_code );
1550 -
1551 - if ( $error_code === 'SimpleXML_parse_error' ) {
1552 - $result->remove( $error_code );
1553 - break;
1554 - }
1555 - }
1556 -
1557 - if ( ! empty( $error_details ) ) {
1558 - $errors[] = '<br />' . esc_html_x( 'Error details:', 'import xml message', 'formidable' ) . '<br />' . esc_html( print_r( $error_details, 1 ) );
1559 - }
1560 -
1070 + } elseif ( ! $result ) {
1561 1071 return;
1562 - }//end if
1563 -
1564 - if ( ! $result ) {
1565 - return;
1566 1072 }
1567 1073
1568 1074 if ( ! is_array( $result ) ) {
1569 1075 $message = is_string( $result ) ? $result : htmlentities( print_r( $result, 1 ) );
1076 +
1570 1077 return;
1571 1078 }
1572 1079
1573 1080 $t_strings = array(
@@ -1575,9 +1082,8 @@
1575 1082 'updated' => __( 'Updated', 'formidable' ),
1576 1083 );
1577 1084
1578 1085 $message = '<ul>';
1579 -
1580 1086 foreach ( $result as $type => $results ) {
1581 1087 if ( ! isset( $t_strings[ $type ] ) ) {
1582 1088 // only print imported and updated
1583 1089 continue;
@@ -1583,9 +1089,8 @@
1583 1089 continue;
1584 1090 }
1585 1091
1586 1092 $s_message = array();
1587 -
1588 1093 foreach ( $results as $k => $m ) {
1589 1094 self::item_count_message( $m, $k, $s_message );
1590 1095 unset( $k, $m );
1591 1096 }
@@ -1596,30 +1101,18 @@
1596 1101 $message .= '</li>';
1597 1102 }
1598 1103 }
1599 1104
1600 - if ( $message === '<ul>' ) {
1105 + if ( $message == '<ul>' ) {
1601 1106 $message = '';
1602 1107 $errors[] = __( 'Nothing was imported or updated', 'formidable' );
1603 1108 } else {
1604 1109 self::add_form_link_to_message( $result, $message );
1605 1110
1606 - /**
1607 - * @since 5.3
1608 - *
1609 - * @param string $message
1610 - * @param array $result
1611 - */
1612 - $message = apply_filters( 'frm_xml_parsed_message', $message, $result );
1613 1111 $message .= '</ul>';
1614 1112 }
1615 1113 }
1616 1114
1617 - /**
1618 - * @param int $m
1619 - * @param string $type
1620 - * @param array<string> $s_message
1621 - */
1622 1115 public static function item_count_message( $m, $type, &$s_message ) {
1623 1116 if ( ! $m ) {
1624 1117 return;
1625 1118 }
@@ -1633,9 +1126,9 @@
1633 1126 'items' => sprintf( _n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m ),
1634 1127 /* translators: %1$s: Number of items */
1635 1128 'views' => sprintf( _n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m ),
1636 1129 /* translators: %1$s: Number of items */
1637 - 'posts' => sprintf( _n( '%1$s Page/Post', '%1$s Pages/Posts', $m, 'formidable' ), $m ),
1130 + 'posts' => sprintf( _n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m ),
1638 1131 /* translators: %1$s: Number of items */
1639 1132 'styles' => sprintf( _n( '%1$s Style', '%1$s Styles', $m, 'formidable' ), $m ),
1640 1133 /* translators: %1$s: Number of items */
1641 1134 'terms' => sprintf( _n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m ),
@@ -1642,23 +1135,9 @@
1642 1135 /* translators: %1$s: Number of items */
1643 1136 'actions' => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ),
1644 1137 );
1645 1138
1646 - if ( isset( $strings[ $type ] ) ) {
1647 - $s_message[] = $strings[ $type ];
1648 - } else {
1649 - $string = ' ' . $m . ' ' . ucfirst( $type );
1650 -
1651 - /**
1652 - * @since 5.3
1653 - *
1654 - * @param string $string Message string for imported item.
1655 - * @param int $m Number of item that was imported.
1656 - * }
1657 - */
1658 - $string = apply_filters( 'frm_xml_' . $type . '_count_message', $string, $m );
1659 - $s_message[] = $string;
1660 - }
1139 + $s_message[] = isset( $strings[ $type ] ) ? $strings[ $type ] : ' ' . $m . ' ' . ucfirst( $type );
1661 1140 }
1662 1141
1663 1142 /**
1664 1143 * If a single form was imported, include a link in the success message.
@@ -1663,21 +1142,18 @@
1663 1142 /**
1664 1143 * If a single form was imported, include a link in the success message.
1665 1144 *
1666 1145 * @since 4.0
1667 - *
1668 1146 * @param array $result The response from the XML import.
1669 1147 * @param string $message The response shown on the page after import.
1670 1148 */
1671 1149 private static function add_form_link_to_message( $result, &$message ) {
1672 1150 $total_forms = $result['imported']['forms'] + $result['updated']['forms'];
1673 -
1674 1151 if ( $total_forms > 1 ) {
1675 1152 return;
1676 1153 }
1677 1154
1678 1155 $primary_form = reset( $result['forms'] );
1679 -
1680 1156 if ( ! empty( $primary_form ) ) {
1681 1157 $primary_form = FrmForm::getOne( $primary_form );
1682 1158 $form_id = empty( $primary_form->parent_form_id ) ? $primary_form->id : $primary_form->parent_form_id;
1683 1159
@@ -1697,9 +1173,8 @@
1697 1173 public static function prepare_form_options_for_export( $options ) {
1698 1174 FrmAppHelper::unserialize_or_decode( $options );
1699 1175 // Change custom_style to the post_name instead of ID (1 may be a string)
1700 1176 $not_default = isset( $options['custom_style'] ) && 1 != $options['custom_style'];
1701 -
1702 1177 if ( $not_default ) {
1703 1178 global $wpdb;
1704 1179 $table = $wpdb->prefix . 'posts';
1705 1180 $where = array( 'ID' => $options['custom_style'] );
@@ -1723,16 +1198,11 @@
1723 1198 * If the saved value is the same as the default, remove it from the export
1724 1199 * This keeps file size down and prevents overriding global settings after import
1725 1200 *
1726 1201 * @since 3.06
1727 - *
1728 - * @param array $options By reference.
1729 - *
1730 - * @return void
1731 1202 */
1732 1203 private static function remove_default_form_options( &$options ) {
1733 1204 $defaults = FrmFormsHelper::get_default_opts();
1734 -
1735 1205 if ( is_callable( 'FrmProFormsHelper::get_default_opts' ) ) {
1736 1206 $defaults += FrmProFormsHelper::get_default_opts();
1737 1207 }
1738 1208 self::remove_defaults( $defaults, $options );
@@ -1741,16 +1211,11 @@
1741 1211 /**
1742 1212 * Remove extra settings from field to keep file size down
1743 1213 *
1744 1214 * @since 3.06
1745 - *
1746 - * @param object $field
1747 - *
1748 - * @return void
1749 1215 */
1750 1216 public static function prepare_field_for_export( &$field ) {
1751 1217 self::remove_default_field_options( $field );
1752 - self::add_image_src_to_image_options( $field );
1753 1218 }
1754 1219
1755 1220 /**
1756 1221 * Remove defaults from field options too
@@ -1755,16 +1220,11 @@
1755 1220 /**
1756 1221 * Remove defaults from field options too
1757 1222 *
1758 1223 * @since 3.06
1759 - *
1760 - * @param object $field
1761 - *
1762 - * @return void
1763 1224 */
1764 1225 private static function remove_default_field_options( &$field ) {
1765 1226 $defaults = self::default_field_options( $field->type );
1766 -
1767 1227 if ( empty( $defaults['blank'] ) ) {
1768 1228 $global_settings = new FrmSettings();
1769 1229 $global_defaults = $global_settings->default_options();
1770 1230 $defaults['blank'] = $global_defaults['blank_msg'];
@@ -1787,51 +1247,12 @@
1787 1247 $field->field_options = serialize( $options );
1788 1248 }
1789 1249
1790 1250 /**
1791 - * Add image "src" key to each image option so the image can be imported to another website.
1792 - *
1793 - * @since 5.5.1
1794 - *
1795 - * @param stdClass $field
1796 - *
1797 - * @return void
1798 - */
1799 - private static function add_image_src_to_image_options( $field ) {
1800 - if ( empty( $field->options ) || false === strpos( $field->options, 'image' ) ) {
1801 - return;
1802 - }
1803 -
1804 - $updated = false;
1805 - $options = $field->options;
1806 - FrmAppHelper::unserialize_or_decode( $options );
1807 -
1808 - if ( ! $options || ! is_array( $options ) ) {
1809 - return;
1810 - }
1811 -
1812 - foreach ( $options as $key => $option ) {
1813 - if ( is_array( $option ) && ! empty( $option['image'] ) ) {
1814 - $options[ $key ]['src'] = wp_get_attachment_url( $option['image'] );
1815 - $updated = true;
1816 - }
1817 - }
1818 -
1819 - if ( $updated ) {
1820 - $field->options = maybe_serialize( $options );
1821 - }
1822 - }
1823 -
1824 - /**
1825 1251 * @since 3.06.03
1826 - *
1827 - * @param string $type
1828 - *
1829 - * @return array
1830 1252 */
1831 1253 private static function default_field_options( $type ) {
1832 1254 $defaults = FrmFieldsHelper::get_default_field_options( $type );
1833 -
1834 1255 if ( empty( $defaults['custom_html'] ) ) {
1835 1256 $defaults['custom_html'] = FrmFieldsHelper::get_default_html( $type );
1836 1257 }
1837 1258 return $defaults;
@@ -1841,13 +1262,8 @@
1841 1262 * Compare the default array to the saved values and
1842 1263 * remove if they are the same
1843 1264 *
1844 1265 * @since 3.06
1845 - *
1846 - * @param array $defaults
1847 - * @param array $saved
1848 - *
1849 - * @return void
1850 1266 */
1851 1267 private static function remove_defaults( $defaults, &$saved ) {
1852 1268 foreach ( $saved as $key => $value ) {
1853 1269 if ( isset( $defaults[ $key ] ) && $defaults[ $key ] === $value ) {
@@ -1859,14 +1275,8 @@
1859 1275 /**
1860 1276 * The line endings may prevent html from being equal when it should
1861 1277 *
1862 1278 * @since 3.06
1863 - *
1864 - * @param string $html_name
1865 - * @param array $defaults
1866 - * @param array $options
1867 - *
1868 - * @return void
1869 1279 */
1870 1280 private static function remove_default_html( $html_name, $defaults, &$options ) {
1871 1281 if ( ! isset( $options[ $html_name ] ) || ! isset( $defaults[ $html_name ] ) ) {
1872 1282 return;
@@ -1873,9 +1283,8 @@
1873 1283 }
1874 1284
1875 1285 $old_html = str_replace( "\r\n", "\n", $options[ $html_name ] );
1876 1286 $default_html = $defaults[ $html_name ];
1877 -
1878 1287 if ( $old_html == $default_html ) {
1879 1288 unset( $options[ $html_name ] );
1880 1289
1881 1290 return;
@@ -1882,26 +1291,19 @@
1882 1291 }
1883 1292
1884 1293 // Account for some of the older field default HTML.
1885 1294 $default_html = str_replace( ' id="frm_desc_field_[key]"', '', $default_html );
1886 -
1887 - if ( $old_html === $default_html ) {
1295 + if ( $old_html == $default_html ) {
1888 1296 unset( $options[ $html_name ] );
1889 1297 }
1890 1298 }
1891 1299
1892 - /**
1893 - * @param string $str
1894 - *
1895 - * @return string
1896 - */
1897 1300 public static function cdata( $str ) {
1898 1301 FrmAppHelper::unserialize_or_decode( $str );
1899 -
1900 1302 if ( is_array( $str ) ) {
1901 1303 $str = json_encode( $str );
1902 - } elseif ( FrmAppHelper::is_valid_utf8( $str ) === false ) {
1903 - $str = FrmAppHelper::maybe_utf8_encode( $str );
1304 + } elseif ( seems_utf8( $str ) === false ) {
1305 + $str = utf8_encode( $str );
1904 1306 }
1905 1307
1906 1308 if ( is_numeric( $str ) ) {
1907 1309 return $str;
@@ -1920,10 +1322,8 @@
1920 1322 *
1921 1323 * @since 2.0.22
1922 1324 *
1923 1325 * @param string $str
1924 - *
1925 - * @return void
1926 1326 */
1927 1327 private static function remove_invalid_characters_from_xml( &$str ) {
1928 1328 // Remove <US> character
1929 1329 $str = str_replace( '\x1F', '', $str );
@@ -1928,18 +1328,8 @@
1928 1328 // Remove <US> character
1929 1329 $str = str_replace( '\x1F', '', $str );
1930 1330 }
1931 1331
1932 - /**
1933 - * Migrate form settings to actions
1934 - *
1935 - * @param array $form_options
1936 - * @param int $form_id
1937 - * @param array $imported
1938 - * @param bool $switch
1939 - *
1940 - * @return void
1941 - */
1942 1332 public static function migrate_form_settings_to_actions( $form_options, $form_id, &$imported = array(), $switch = false ) {
1943 1333 // Get post type
1944 1334 $post_type = FrmFormActionsController::$action_post_type;
1945 1335
@@ -1957,13 +1347,9 @@
1957 1347
1958 1348 /**
1959 1349 * Migrate post settings to form action
1960 1350 *
1961 - * @param array $form_options
1962 - * @param int $form_id
1963 1351 * @param string $post_type
1964 - * @param array $imported
1965 - * @param bool $switch
1966 1352 */
1967 1353 private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
1968 1354 if ( ! isset( $form_options['create_post'] ) || ! $form_options['create_post'] ) {
1969 1355 return;
@@ -2032,9 +1418,9 @@
2032 1418
2033 1419 if ( ! $exists ) {
2034 1420 // this isn't an email, but we need to use a class that will always be included
2035 1421 FrmDb::save_json_post( $new_action );
2036 - ++$imported['imported']['actions'];
1422 + $imported['imported']['actions'] ++;
2037 1423 }
2038 1424 }
2039 1425
2040 1426 /**
@@ -2041,11 +1427,11 @@
2041 1427 * Switch old field IDs for new field IDs in emails and post
2042 1428 *
2043 1429 * @since 2.0
2044 1430 *
2045 - * @param array $post_content Check for old field IDs.
2046 - * @param array $basic_fields Fields with string or int saved.
2047 - * @param array $array_fields Fields with arrays saved.
1431 + * @param array $post_content - check for old field IDs
1432 + * @param array $basic_fields - fields with string or int saved
1433 + * @param array $array_fields - fields with arrays saved
2048 1434 *
2049 1435 * @return string $post_content - new field IDs
2050 1436 */
2051 1437 private static function switch_action_field_ids( $post_content, $basic_fields, $array_fields = array() ) {
@@ -2078,19 +1464,8 @@
2078 1464
2079 1465 return $post_content;
2080 1466 }
2081 1467
2082 - /**
2083 - * Migrate email settings to action
2084 - *
2085 - * @param array $form_options
2086 - * @param int $form_id
2087 - * @param string $post_type
2088 - * @param array $imported
2089 - * @param bool $switch
2090 - *
2091 - * @return void
2092 - */
2093 1468 private static function migrate_email_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
2094 1469 // No old notifications or autoresponders to carry over
2095 1470 if ( ! isset( $form_options['auto_responder'] ) && ! isset( $form_options['notification'] ) && ! isset( $form_options['email_to'] ) ) {
2096 1471 return;
@@ -2137,12 +1512,12 @@
2137 1512 );
2138 1513
2139 1514 if ( empty( $exists ) ) {
2140 1515 FrmDb::save_json_post( $new_notification );
2141 - ++$imported['imported']['actions'];
1516 + $imported['imported']['actions'] ++;
2142 1517 }
2143 1518 unset( $new_notification );
2144 - }//end foreach
1519 + }
2145 1520
2146 1521 self::remove_deprecated_notification_settings( $form_id, $form_options );
2147 1522 }
2148 1523
@@ -2151,15 +1526,12 @@
2151 1526 *
2152 1527 * @since 2.05
2153 1528 *
2154 1529 * @param int|string $form_id
2155 - * @param array $form_options
2156 - *
2157 - * @return void
1530 + * @param array $form_options
2158 1531 */
2159 1532 private static function remove_deprecated_notification_settings( $form_id, $form_options ) {
2160 1533 $delete_settings = array( 'notification', 'autoresponder', 'email_to' );
2161 -
2162 1534 foreach ( $delete_settings as $index ) {
2163 1535 if ( isset( $form_options[ $index ] ) ) {
2164 1536 unset( $form_options[ $index ] );
2165 1537 }
@@ -2166,19 +1538,10 @@
2166 1538 }
2167 1539 FrmForm::update( $form_id, array( 'options' => $form_options ) );
2168 1540 }
2169 1541
2170 - /**
2171 - * Migrate notifications to action
2172 - *
2173 - * @param array $form_options
2174 - * @param int $form_id
2175 - * @param array $notifications
2176 - *
2177 - * @return void
2178 - */
2179 1542 private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) {
2180 - if ( ! isset( $form_options['notification'] ) && ! empty( $form_options['email_to'] ) ) {
1543 + if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) {
2181 1544 // add old settings into notification array
2182 1545 $form_options['notification'] = array( 0 => $form_options );
2183 1546 } elseif ( isset( $form_options['notification']['email_to'] ) ) {
2184 1547 // make sure it's in the correct format
@@ -2208,20 +1571,12 @@
2208 1571 $new_notification = array();
2209 1572 self::setup_new_notification( $new_notification, $notification, $atts );
2210 1573
2211 1574 $notifications[] = $new_notification;
2212 - }//end foreach
2213 - }//end if
1575 + }
1576 + }
2214 1577 }
2215 1578
2216 - /**
2217 - * Format email data
2218 - *
2219 - * @param array $atts
2220 - * @param array $notification
2221 - *
2222 - * @return void
2223 - */
2224 1579 private static function format_email_data( &$atts, $notification ) {
2225 1580 // Format email_to
2226 1581 self::format_email_to_data( $atts, $notification );
2227 1582
@@ -2229,13 +1584,11 @@
2229 1584 $reply_fields = array(
2230 1585 'reply_to' => '',
2231 1586 'reply_to_name' => '',
2232 1587 );
2233 -
2234 1588 foreach ( $reply_fields as $f => $val ) {
2235 1589 if ( isset( $notification[ $f ] ) ) {
2236 1590 $atts[ $f ] = $notification[ $f ];
2237 -
2238 1591 if ( 'custom' == $notification[ $f ] ) {
2239 1592 $atts[ $f ] = $notification[ 'cust_' . $f ];
2240 1593 } elseif ( is_numeric( $atts[ $f ] ) && ! empty( $atts[ $f ] ) ) {
2241 1594 $atts[ $f ] = '[' . $atts[ $f ] . ']';
@@ -2245,9 +1598,8 @@
2245 1598 }
2246 1599
2247 1600 // Format event
2248 1601 $atts['event'] = array( 'create' );
2249 -
2250 1602 if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) {
2251 1603 $atts['event'][] = 'update';
2252 1604 } elseif ( isset( $notification['update_email'] ) && 2 == $notification['update_email'] ) {
2253 1605 $atts['event'] = array( 'update' );
@@ -2253,16 +1605,8 @@
2253 1605 $atts['event'] = array( 'update' );
2254 1606 }
2255 1607 }
2256 1608
2257 - /**
2258 - * Format email_to data
2259 - *
2260 - * @param array $atts
2261 - * @param array $notification
2262 - *
2263 - * @return void
2264 - */
2265 1609 private static function format_email_to_data( &$atts, $notification ) {
2266 1610 if ( isset( $notification['email_to'] ) ) {
2267 1611 $atts['email_to'] = preg_split( '/ (,|;) /', $notification['email_to'] );
2268 1612 } else {
@@ -2282,9 +1626,8 @@
2282 1626 }
2283 1627
2284 1628 if ( strpos( $email_field, '|' ) ) {
2285 1629 $email_opt = explode( '|', $email_field );
2286 -
2287 1630 if ( isset( $email_opt[0] ) ) {
2288 1631 $atts['email_to'][ $key ] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']';
2289 1632 }
2290 1633 unset( $email_opt );
@@ -2292,17 +1635,8 @@
2292 1635 }
2293 1636 $atts['email_to'] = implode( ', ', $atts['email_to'] );
2294 1637 }
2295 1638
2296 - /**
2297 - * Setup new notification
2298 - *
2299 - * @param array $new_notification
2300 - * @param array $notification
2301 - * @param array $atts
2302 - *
2303 - * @return void
2304 - */
2305 1639 private static function setup_new_notification( &$new_notification, $notification, $atts ) {
2306 1640 // Set up new notification
2307 1641 $new_notification = array(
2308 1642 'post_content' => array(
@@ -2313,9 +1647,8 @@
2313 1647 );
2314 1648
2315 1649 // Add more fields to the new notification
2316 1650 $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' );
2317 -
2318 1651 foreach ( $add_fields as $add_field ) {
2319 1652 if ( isset( $notification[ $add_field ] ) ) {
2320 1653 $new_notification['post_content'][ $add_field ] = $notification[ $add_field ];
2321 1654 } elseif ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) {
@@ -2337,11 +1670,9 @@
2337 1670
2338 1671 /**
2339 1672 * Switch field IDs in pre-2.0 email conditional logic
2340 1673 *
2341 - * @param array $post_content Pass by reference.
2342 - *
2343 - * @return void
1674 + * @param $post_content array, pass by reference
2344 1675 */
2345 1676 private static function switch_email_condition_field_ids( &$post_content ) {
2346 1677 // Switch field IDs in conditional logic
2347 1678 if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) {
@@ -2353,32 +1684,20 @@
2353 1684 }
2354 1685 }
2355 1686 }
2356 1687
2357 - /**
2358 - * Migrate autoresponder to action
2359 - *
2360 - * @param array $form_options
2361 - * @param int $form_id
2362 - * @param array $notifications
2363 - *
2364 - * @return void
2365 - */
2366 1688 private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) {
2367 1689 if ( isset( $form_options['auto_responder'] ) && $form_options['auto_responder'] && isset( $form_options['ar_email_message'] ) && $form_options['ar_email_message'] ) {
2368 1690 // migrate autoresponder
2369 1691
2370 - $email_field = $form_options['ar_email_to'] ?? 0;
2371 -
1692 + $email_field = isset( $form_options['ar_email_to'] ) ? $form_options['ar_email_to'] : 0;
2372 1693 if ( strpos( $email_field, '|' ) ) {
2373 1694 // data from entries field
2374 1695 $email_field = explode( '|', $email_field );
2375 -
2376 1696 if ( isset( $email_field[1] ) ) {
2377 1697 $email_field = $email_field[1];
2378 1698 }
2379 1699 }
2380 -
2381 1700 if ( is_numeric( $email_field ) && ! empty( $email_field ) ) {
2382 1701 $email_field = '[' . $email_field . ']';
2383 1702 }
2384 1703
@@ -2385,18 +1704,18 @@
2385 1704 $notification = $form_options;
2386 1705 $new_notification2 = array(
2387 1706 'post_content' => array(
2388 1707 'email_message' => $notification['ar_email_message'],
2389 - 'email_subject' => $notification['ar_email_subject'] ?? '',
1708 + 'email_subject' => isset( $notification['ar_email_subject'] ) ? $notification['ar_email_subject'] : '',
2390 1709 'email_to' => $email_field,
2391 - 'plain_text' => $notification['ar_plain_text'] ?? 0,
1710 + 'plain_text' => isset( $notification['ar_plain_text'] ) ? $notification['ar_plain_text'] : 0,
2392 1711 'inc_user_info' => 0,
2393 1712 ),
2394 1713 'post_name' => $form_id . '_email_' . count( $notifications ),
2395 1714 );
2396 1715
2397 - $reply_to = $notification['ar_reply_to'] ?? '';
2398 - $reply_to_name = $notification['ar_reply_to_name'] ?? '';
1716 + $reply_to = isset( $notification['ar_reply_to'] ) ? $notification['ar_reply_to'] : '';
1717 + $reply_to_name = isset( $notification['ar_reply_to_name'] ) ? $notification['ar_reply_to_name'] : '';
2399 1718
2400 1719 if ( ! empty( $reply_to ) ) {
2401 1720 $new_notification2['post_content']['reply_to'] = $reply_to;
2402 1721 }
@@ -2406,17 +1725,17 @@
2406 1725 }
2407 1726
2408 1727 $notifications[] = $new_notification2;
2409 1728 unset( $new_notification2 );
2410 - }//end if
1729 + }
2411 1730 }
2412 1731
2413 1732 /**
2414 1733 * PHP 8 backward compatibility for the libxml_disable_entity_loader function
2415 1734 *
2416 - * @param bool $loader
1735 + * @param boolean $disable
2417 1736 *
2418 - * @return bool
1737 + * @return boolean
2419 1738 */
2420 1739 public static function maybe_libxml_disable_entity_loader( $loader ) {
2421 1740 if ( version_compare( phpversion(), '8.0', '<' ) && function_exists( 'libxml_disable_entity_loader' ) ) {
2422 1741 $loader = libxml_disable_entity_loader( $loader ); // phpcs:disable Generic.PHP.DeprecatedFunctions.Deprecated
@@ -2424,31 +1743,9 @@
2424 1743
2425 1744 return $loader;
2426 1745 }
2427 1746
2428 - /**
2429 - * PHP 8 backward compatibility for the libxml_disable_entity_loader function
2430 - *
2431 - * @return bool
2432 - */
2433 1747 public static function check_if_libxml_disable_entity_loader_exists() {
2434 1748 return version_compare( phpversion(), '8.0', '<' ) && ! function_exists( 'libxml_disable_entity_loader' );
2435 1749 }
1750 +}
2436 1751
2437 - /**
2438 - * Get the file types allowed for importing.
2439 - * This is used in the "accept" attribute for the file upload input on the XML import page.
2440 - *
2441 - * @since 6.8.3
2442 - *
2443 - * @return array
2444 - */
2445 - public static function get_supported_upload_file_types() {
2446 - $file_types = array( '.xml' );
2447 -
2448 - if ( FrmAppHelper::pro_is_installed() ) {
2449 - // CSV Importing is only available in Pro.
2450 - $file_types[] = '.csv';
2451 - }
2452 - return $file_types;
2453 - }
2454 -}