PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.1
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 +110 -827 6.265.1 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 }
@@ -735,12 +549,8 @@
735 549 /**
736 550 * If field settings have been migrated, update the values during import.
737 551 *
738 552 * @since 4.0
739 - *
740 - * @param array $f
741 - *
742 - * @return void
743 553 */
744 554 private static function run_field_migrations( &$f ) {
745 555 self::migrate_placeholders( $f );
746 556 $f = apply_filters( 'frm_import_xml_field', $f );
@@ -747,22 +557,16 @@
747 557 }
748 558
749 559 /**
750 560 * @since 4.0
751 - *
752 - * @param array $f
753 - *
754 - * @return void
755 561 */
756 562 private static function migrate_placeholders( &$f ) {
757 563 $update_values = self::migrate_field_placeholder( $f, 'clear_on_focus' );
758 -
759 564 foreach ( $update_values as $k => $v ) {
760 565 $f[ $k ] = $v;
761 566 }
762 567
763 568 $update_values = self::migrate_field_placeholder( $f, 'default_blank' );
764 -
765 569 foreach ( $update_values as $k => $v ) {
766 570 $f[ $k ] = $v;
767 571 }
768 572 }
@@ -771,18 +575,13 @@
771 575 * Move clear_on_focus or default_blank to placeholder.
772 576 * Also called during database migration in FrmMigrate.
773 577 *
774 578 * @since 4.0
775 - *
776 - * @param array|object $field
777 - * @param string $type
778 - *
779 579 * @return array
780 580 */
781 581 public static function migrate_field_placeholder( $field, $type ) {
782 - $field = (array) $field;
582 + $field = (array) $field;
783 583 $field_options = $field['field_options'];
784 -
785 584 if ( empty( $field_options[ $type ] ) || empty( $field['default_value'] ) ) {
786 585 return array();
787 586 }
788 587
@@ -795,12 +594,10 @@
795 594 );
796 595
797 596 // If a dropdown placeholder was used, remove the option so it won't be included twice.
798 597 $options = $field['options'];
799 -
800 598 if ( $type === 'default_blank' && is_array( $options ) ) {
801 599 $default_value = $field['default_value'];
802 -
803 600 if ( is_array( $default_value ) ) {
804 601 $default_value = reset( $default_value );
805 602 }
806 603
@@ -805,9 +602,9 @@
805 602 }
806 603
807 604 foreach ( $options as $opt_key => $opt ) {
808 605 if ( is_array( $opt ) ) {
809 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
606 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
810 607 }
811 608
812 609 if ( $opt == $default_value ) {
813 610 unset( $options[ $opt_key ] );
@@ -826,70 +623,26 @@
826 623 * @since 2.0.25
827 624 *
828 625 * @param array $f
829 626 * @param array $imported
830 - *
831 - * @return void
832 627 */
833 628 private static function create_imported_field( $f, &$imported ) {
834 - $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'] );
835 631
836 - if ( is_callable( 'FrmProFileImport::import_attachment' ) ) {
837 - $f = self::maybe_import_images_for_options( $f );
838 - }
839 -
840 632 $new_id = FrmField::create( $f );
841 -
842 633 if ( $new_id != false ) {
843 - ++$imported['imported']['fields'];
634 + $imported['imported']['fields'] ++;
844 635 do_action( 'frm_after_field_is_imported', $f, $new_id );
845 636 }
846 637 }
847 638
848 639 /**
849 - * Import images for radio buttons and checkboxes from image src if available.
850 - *
851 - * @since 5.5.1
852 - *
853 - * @param array $field
854 - *
855 - * @return array
856 - */
857 - private static function maybe_import_images_for_options( $field ) {
858 - if ( empty( $field['options'] ) || ! is_array( $field['options'] ) ) {
859 - return $field;
860 - }
861 -
862 - foreach ( $field['options'] as $key => $option ) {
863 - if ( ! is_array( $option ) || empty( $option['src'] ) ) {
864 - continue;
865 - }
866 -
867 - $field_object = (object) $field;
868 - // Fake the file type as FrmProImport::import_attachment checks for file type.
869 - $field_object->type = 'file';
870 -
871 - $image_id = FrmProFileImport::import_attachment( $option['src'], $field_object );
872 - // Remove the src from options as it isn't required after import.
873 - unset( $field['options'][ $key ]['src'] );
874 -
875 - if ( is_numeric( $image_id ) ) {
876 - $field['options'][ $key ]['image'] = $image_id;
877 - }
878 - }
879 -
880 - return $field;
881 - }
882 -
883 - /**
884 640 * Fix field ids for fields that already exist prior to import.
885 641 *
886 642 * @since 4.07
887 - *
888 - * @param int $form_id
643 + * @param int $form_id
889 644 * @param array $keys_by_original_field_id
890 - *
891 - * @return void
892 645 */
893 646 protected static function maybe_update_field_ids( $form_id, $keys_by_original_field_id ) {
894 647 global $frm_duplicate_ids;
895 648
@@ -929,10 +682,8 @@
929 682 *
930 683 * @since 2.0.19
931 684 *
932 685 * @param array $form
933 - *
934 - * @return void
935 686 */
936 687 private static function update_custom_style_setting_on_import( &$form ) {
937 688 if ( ! isset( $form['options']['custom_style'] ) ) {
938 689 return;
@@ -937,9 +688,9 @@
937 688 if ( ! isset( $form['options']['custom_style'] ) ) {
938 689 return;
939 690 }
940 691
941 - if ( is_numeric( $form['options']['custom_style'] ) && 1 === intval( $form['options']['custom_style'] ) ) {
692 + if ( is_numeric( $form['options']['custom_style'] ) ) {
942 693 // Set to default
943 694 $form['options']['custom_style'] = 1;
944 695 } else {
945 696 // Replace the style name with the style ID on import
@@ -960,9 +711,9 @@
960 711
961 712 // Set to default
962 713 $form['options']['custom_style'] = 1;
963 714 }
964 - }//end if
715 + }
965 716 }
966 717
967 718 /**
968 719 * After styles are imported, check for any forms that were linked
@@ -968,12 +719,8 @@
968 719 * After styles are imported, check for any forms that were linked
969 720 * and link them back up.
970 721 *
971 722 * @since 2.2.7
972 - *
973 - * @param int|string $form_id
974 - *
975 - * @return void
976 723 */
977 724 private static function update_custom_style_setting_after_import( $form_id ) {
978 725 $form = FrmForm::getOne( $form_id );
979 726
@@ -982,9 +729,8 @@
982 729 $saved_style = $form['options']['custom_style'];
983 730 $form['options']['custom_style'] = $form['options']['old_style'];
984 731 self::update_custom_style_setting_on_import( $form );
985 732 $has_changed = ( $form['options']['custom_style'] != $saved_style && $form['options']['custom_style'] != $form['options']['old_style'] );
986 -
987 733 if ( $has_changed ) {
988 734 FrmForm::update( $form['id'], $form );
989 735 }
990 736 }
@@ -989,16 +735,8 @@
989 735 }
990 736 }
991 737 }
992 738
993 - /**
994 - * Handle import for all posts. This includes views, styles, pages, and form actions.
995 - *
996 - * @param SimpleXMLElement $views
997 - * @param array $imported
998 - *
999 - * @return array
1000 - */
1001 739 public static function import_xml_views( $views, $imported ) {
1002 740 $imported['posts'] = array();
1003 741 $form_action_type = FrmFormActionsController::$action_post_type;
1004 742
@@ -1007,11 +745,8 @@
1007 745 $form_action_type => 'actions',
1008 746 'frm_styles' => 'styles',
1009 747 );
1010 748
1011 - $view_ids = array();
1012 - $posts_with_shortcodes = array();
1013 -
1014 749 foreach ( $views as $item ) {
1015 750 $post = array(
1016 751 'post_title' => (string) $item->title,
1017 752 'post_name' => (string) $item->post_name,
@@ -1034,15 +769,8 @@
1034 769 'layout' => array(),
1035 770 'tax_input' => array(),
1036 771 );
1037 772
1038 - $post['post_content'] = self::switch_form_ids( $post['post_content'], $imported['forms'] );
1039 -
1040 - // Fix issue with line breaks appearing in descriptions as "rn".
1041 - if ( $post['post_type'] === $form_action_type ) {
1042 - $post['post_content'] = str_replace( '\\\\r\\\\n', '\\r\\n', $post['post_content'] );
1043 - }
1044 -
1045 773 $old_id = $post['post_id'];
1046 774 self::populate_post( $post, $item, $imported );
1047 775
1048 776 unset( $item );
@@ -1047,221 +775,67 @@
1047 775
1048 776 unset( $item );
1049 777
1050 778 $post_id = false;
1051 -
1052 - if ( $post['post_type'] === $form_action_type ) {
779 + if ( $post['post_type'] == $form_action_type ) {
1053 780 $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] );
1054 -
1055 - if ( $action_control && is_object( $action_control ) && isset( $imported['form_status'] ) ) {
781 + if ( $action_control && is_object( $action_control ) ) {
1056 782 $post_id = $action_control->maybe_create_action( $post, $imported['form_status'] );
1057 783 }
1058 784 unset( $action_control );
1059 - } elseif ( $post['post_type'] === 'frm_styles' ) {
785 + } elseif ( $post['post_type'] == 'frm_styles' ) {
1060 786 // Properly encode post content before inserting the post
1061 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'] : '';
1062 789 $post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] );
1063 - // Store template data additionally to a postmeta that can be used to revert the style to default template style.
1064 - $post['postmeta']['frm_style_default'] = $post['post_content'];
1065 790
1066 791 // Create/update post now
1067 792 $post_id = wp_insert_post( $post );
793 + self::maybe_update_custom_css( $custom_css );
1068 794 } else {
1069 795 if ( $post['post_type'] === 'frm_display' ) {
1070 796 $post['post_content'] = self::maybe_prepare_json_view_content( $post['post_content'] );
1071 - } elseif ( 'page' === $post['post_type'] && isset( $imported['posts'][ $post['post_parent'] ] ) ) {
1072 - $post['post_parent'] = $imported['posts'][ $post['post_parent'] ];
1073 797 }
1074 798 // Create/update post now
1075 799 $post_id = wp_insert_post( $post );
1076 - }//end if
800 + }
1077 801
1078 802 if ( ! is_numeric( $post_id ) ) {
1079 803 continue;
1080 804 }
1081 805
1082 - if ( false !== strpos( $post['post_content'], '[display-frm-data' ) || false !== strpos( $post['post_content'], '[formidable' ) ) {
1083 - $posts_with_shortcodes[ $post_id ] = $post;
1084 - }
1085 -
1086 806 self::update_postmeta( $post, $post_id );
1087 807 self::update_layout( $post, $post_id );
1088 808
1089 809 $this_type = 'posts';
1090 -
1091 810 if ( isset( $post_types[ $post['post_type'] ] ) ) {
1092 811 $this_type = $post_types[ $post['post_type'] ];
1093 812 }
1094 813
1095 814 if ( isset( $post['ID'] ) && $post_id == $post['ID'] ) {
1096 - ++$imported['updated'][ $this_type ];
815 + $imported['updated'][ $this_type ] ++;
1097 816 } else {
1098 - ++$imported['imported'][ $this_type ];
817 + $imported['imported'][ $this_type ] ++;
1099 818 }
1100 819
1101 - $imported['posts'][ $old_id ] = $post_id;
820 + $imported['posts'][ (int) $old_id ] = $post_id;
1102 821
1103 - if ( $post['post_type'] === 'frm_display' ) {
1104 - $view_ids[ $old_id ] = $post_id;
1105 - }
1106 -
1107 822 do_action( 'frm_after_import_view', $post_id, $post );
1108 823
1109 824 unset( $post );
1110 - }//end foreach
1111 -
1112 - if ( $posts_with_shortcodes && $view_ids ) {
1113 - self::maybe_switch_view_ids_after_importing_posts( $posts_with_shortcodes, $view_ids );
1114 825 }
1115 - unset( $posts_with_shortcodes, $view_ids );
1116 826
1117 - if ( ! empty( $imported['forms'] ) ) {
1118 - // clear imported forms style cache to make sure the new styles are applied to the forms
1119 - self::clear_forms_style_caches( $imported['forms'] );
1120 - }
1121 -
1122 827 self::maybe_update_stylesheet( $imported );
1123 828
1124 - flush_rewrite_rules();
1125 -
1126 829 return $imported;
1127 830 }
1128 831
1129 832 /**
1130 - * Clears styles from cache for imported forms
1131 - *
1132 - * @param array $imported_forms
1133 - *
1134 - * @return void
1135 - */
1136 - private static function clear_forms_style_caches( $imported_forms ) {
1137 - $where = array(
1138 - 'id' => $imported_forms,
1139 - 'options LIKE' => '"old_style"',
1140 - );
1141 - $forms = FrmDb::get_results( 'frm_forms', $where );
1142 -
1143 - foreach ( $forms as $form ) {
1144 - FrmAppHelper::unserialize_or_decode( $form->options );
1145 -
1146 - if ( ! $form->options ) {
1147 - continue;
1148 - }
1149 -
1150 - $where = array(
1151 - 'post_name' => $form->options['old_style'],
1152 - 'post_type' => FrmStylesController::$post_type,
1153 - );
1154 -
1155 - $select = 'ID';
1156 -
1157 - $cache_key = FrmDb::generate_cache_key( $where, array( 'limit' => 1 ), $select, 'var' );
1158 - FrmDb::delete_cache_and_transient( $cache_key, 'post' );
1159 - }
1160 - }
1161 -
1162 - /**
1163 - * Replace old form ids with new ones in a string.
1164 - *
1165 - * @param string $string
1166 - * @param array<int> $form_ids new form ids indexed by old form id.
1167 - *
1168 - * @return string
1169 - */
1170 - private static function switch_form_ids( $string, $form_ids ) {
1171 - if ( false === strpos( $string, '[formidable' ) ) {
1172 - // Skip string replacing if there are no form shortcodes in string.
1173 - return $string;
1174 - }
1175 -
1176 - foreach ( $form_ids as $old_id => $new_id ) {
1177 - $string = str_replace(
1178 - array(
1179 - '[formidable id="' . $old_id . '"',
1180 - '[formidable id=' . $old_id . ']',
1181 - '[formidable id=' . $old_id . ' ',
1182 - '"formId":"' . $old_id . '"',
1183 - ),
1184 - array(
1185 - '[formidable id="' . $new_id . '"',
1186 - '[formidable id=' . $new_id . ']',
1187 - '[formidable id=' . $new_id . ' ',
1188 - '"formId":"' . $new_id . '"',
1189 - ),
1190 - $string
1191 - );
1192 - }
1193 -
1194 - return $string;
1195 - }
1196 -
1197 - /**
1198 - * @param array<array> $posts_with_shortcodes indexed by current post id.
1199 - * @param array<int> $view_ids new view ids indexed by old view id.
1200 - *
1201 - * @return void
1202 - */
1203 - private static function maybe_switch_view_ids_after_importing_posts( $posts_with_shortcodes, $view_ids ) {
1204 - foreach ( $posts_with_shortcodes as $imported_post_id => $post ) {
1205 - $post_content = self::switch_view_ids( $post['post_content'], $view_ids );
1206 -
1207 - if ( $post_content === $post['post_content'] ) {
1208 - continue;
1209 - }
1210 -
1211 - wp_update_post(
1212 - array(
1213 - 'ID' => $imported_post_id,
1214 - 'post_content' => $post_content,
1215 - )
1216 - );
1217 - }
1218 - }
1219 -
1220 - /**
1221 - * Replace old view ids with new ones in a string.
1222 - *
1223 - * @param string $string
1224 - * @param array<int> $view_ids new view ids indexed by old view id.
1225 - *
1226 - * @return string
1227 - */
1228 - private static function switch_view_ids( $string, $view_ids ) {
1229 - if ( false === strpos( $string, '[display-frm-data' ) ) {
1230 - // Skip string replacing if there are no view shortcodes in string.
1231 - return $string;
1232 - }
1233 -
1234 - foreach ( $view_ids as $old_id => $new_id ) {
1235 - $string = str_replace(
1236 - array(
1237 - '[display-frm-data id="' . $old_id . '"',
1238 - '[display-frm-data id=' . $old_id . ']',
1239 - '[display-frm-data id=' . $old_id . ' ',
1240 - '"viewId":"' . $old_id . '"',
1241 - ),
1242 - array(
1243 - '[display-frm-data id="' . $new_id . '"',
1244 - '[display-frm-data id=' . $new_id . ']',
1245 - '[display-frm-data id=' . $new_id . ' ',
1246 - '"viewId":"' . $new_id . '"',
1247 - ),
1248 - $string
1249 - );
1250 - unset( $old_id, $new_id );
1251 - }
1252 -
1253 - return $string;
1254 - }
1255 -
1256 - /**
1257 833 * @param string $content
1258 - *
1259 834 * @return string
1260 835 */
1261 836 private static function maybe_prepare_json_view_content( $content ) {
1262 837 $maybe_decoded = FrmAppHelper::maybe_json_decode( $content );
1263 -
1264 838 if ( is_array( $maybe_decoded ) && isset( $maybe_decoded[0] ) && isset( $maybe_decoded[0]['box'] ) ) {
1265 839 return FrmAppHelper::prepare_and_encode( $maybe_decoded );
1266 840 }
1267 841 return $content;
@@ -1266,15 +840,8 @@
1266 840 }
1267 841 return $content;
1268 842 }
1269 843
1270 - /**
1271 - * @param array $post
1272 - * @param object $item
1273 - * @param array $imported
1274 - *
1275 - * @return void
1276 - */
1277 844 private static function populate_post( &$post, $item, $imported ) {
1278 845 if ( isset( $item->attachment_url ) ) {
1279 846 $post['attachment_url'] = (string) $item->attachment_url;
1280 847 }
@@ -1316,9 +883,9 @@
1316 883 'key' => (string) $meta->meta_key,
1317 884 'value' => (string) $meta->meta_value,
1318 885 );
1319 886
1320 - // Switch old form and field ids to new ones.
887 + //switch old form and field ids to new ones
1321 888 if ( 'frm_form_id' === $m['key'] && isset( $imported['forms'][ (int) $m['value'] ] ) ) {
1322 889 $m['value'] = $imported['forms'][ (int) $m['value'] ];
1323 890 } else {
1324 891 $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
@@ -1334,37 +901,10 @@
1334 901 $m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ];
1335 902 }
1336 903 }
1337 904
1338 - if ( ! empty( $m['value']['map_address_fields'] ) ) {
1339 - foreach ( $m['value']['map_address_fields'] as $address_field_key => $address_field_id ) {
1340 - if ( isset( $frm_duplicate_ids[ $address_field_id ] ) ) {
1341 - $m['value']['map_address_fields'][ $address_field_key ] = $frm_duplicate_ids[ $address_field_id ];
1342 - }
1343 - }
1344 - }
1345 -
1346 - if ( ! empty( $m['value']['calendar_options'] ) ) {
1347 - foreach ( $m['value']['calendar_options'] as $calendar_option_group_key => $calendar_option ) {
1348 - if ( isset( $frm_duplicate_ids[ $calendar_option['value'] ] ) ) {
1349 - $m['value']['calendar_options'][ $calendar_option_group_key ]['value'] = $frm_duplicate_ids[ $calendar_option['value'] ];
1350 - }
1351 - }
1352 - }
1353 -
1354 - if ( ! empty( $m['value']['timeline_options'] ) ) {
1355 - foreach ( $m['value']['timeline_options'] as $timeline_option_group_key => $timeline_group_option ) {
1356 - foreach ( $timeline_group_option as $timeline_option_key => $timeline_option ) {
1357 - if ( isset( $frm_duplicate_ids[ $timeline_option ] ) ) {
1358 - $m['value']['timeline_options'][ $timeline_option_group_key ][ $timeline_option_key ] = $frm_duplicate_ids[ $timeline_option ];
1359 - }
1360 - }
1361 - }
1362 - }
1363 -
1364 905 $check_dup_array = array();
1365 -
1366 - if ( ! empty( $m['value']['order_by'] ) ) {
906 + if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) {
1367 907 if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) {
1368 908 $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ];
1369 909 } elseif ( is_array( $m['value']['order_by'] ) ) {
1370 910 $check_dup_array[] = 'order_by';
@@ -1370,9 +910,9 @@
1370 910 $check_dup_array[] = 'order_by';
1371 911 }
1372 912 }
1373 913
1374 - if ( ! empty( $m['value']['where'] ) ) {
914 + if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) {
1375 915 $check_dup_array[] = 'where';
1376 916 }
1377 917
1378 918 foreach ( $check_dup_array as $check_k ) {
@@ -1382,11 +922,11 @@
1382 922 }
1383 923 unset( $mk, $mv );
1384 924 }
1385 925 }
1386 - }//end if
1387 - }//end if
1388 - }//end if
926 + }
927 + }
928 + }
1389 929
1390 930 if ( ! is_array( $m['value'] ) ) {
1391 931 $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
1392 932 }
@@ -1393,14 +933,8 @@
1393 933
1394 934 $post['postmeta'][ (string) $meta->meta_key ] = $m['value'];
1395 935 }
1396 936
1397 - /**
1398 - * @param array $post
1399 - * @param object $layout
1400 - *
1401 - * @return void
1402 - */
1403 937 private static function populate_layout( &$post, $layout ) {
1404 938 $post['layout'][ (string) $layout->type ] = (string) $layout->data;
1405 939 }
1406 940
@@ -1406,25 +940,22 @@
1406 940
1407 941 /**
1408 942 * Add terms to post
1409 943 *
1410 - * @param array $post By reference.
1411 - * @param object $item The XML object data.
944 + * @param array $post by reference
945 + * @param object $item The XML object data
1412 946 */
1413 947 private static function populate_taxonomies( &$post, $item ) {
1414 948 foreach ( $item->category as $c ) {
1415 949 $att = $c->attributes();
1416 -
1417 950 if ( ! isset( $att['nicename'] ) ) {
1418 951 continue;
1419 952 }
1420 953
1421 954 $taxonomy = (string) $att['domain'];
1422 -
1423 955 if ( is_taxonomy_hierarchical( $taxonomy ) ) {
1424 956 $name = (string) $att['nicename'];
1425 957 $h_term = get_term_by( 'slug', $name, $taxonomy );
1426 -
1427 958 if ( $h_term ) {
1428 959 $name = $h_term->term_id;
1429 960 }
1430 961 unset( $h_term );
@@ -1437,17 +968,13 @@
1437 968 }
1438 969
1439 970 $post['tax_input'][ $taxonomy ][] = $name;
1440 971 unset( $name );
1441 - }//end foreach
972 + }
1442 973 }
1443 974
1444 975 /**
1445 - * Edit post if the key and created time match.
1446 - *
1447 - * @param array $post By reference.
1448 - *
1449 - * @return void
976 + * Edit post if the key and created time match
1450 977 */
1451 978 private static function maybe_editing_post( &$post ) {
1452 979 $match_by = array(
1453 980 'post_type' => $post['post_type'],
@@ -1455,9 +982,9 @@
1455 982 'post_status' => $post['post_status'],
1456 983 'posts_per_page' => 1,
1457 984 );
1458 985
1459 - if ( in_array( $post['post_status'], array( 'trash', 'draft' ), true ) ) {
986 + if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) {
1460 987 $match_by['include'] = $post['post_id'];
1461 988 unset( $match_by['name'] );
1462 989 }
1463 990
@@ -1468,43 +995,26 @@
1468 995 $post['ID'] = current( $editing )->ID;
1469 996 }
1470 997 }
1471 998
1472 - /**
1473 - * @param array $post
1474 - * @param int $post_id
1475 - *
1476 - * @return void
1477 - */
1478 999 private static function update_postmeta( &$post, $post_id ) {
1479 1000 foreach ( $post['postmeta'] as $k => $v ) {
1480 - switch ( $k ) {
1481 - case '_edit_last':
1482 - $v = FrmAppHelper::get_user_id_param( $v );
1483 - 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 + }
1484 1008
1485 - case '_thumbnail_id':
1486 - if ( FrmAppHelper::pro_is_installed() ) {
1487 - // Change the attachment ID.
1488 - $field_obj = FrmFieldFactory::get_field_type( 'file' );
1489 - $v = $field_obj->get_file_id( $v );
1490 - }
1491 - break;
1009 + if ( 'frm_dyncontent' === $k && is_array( $v ) ) {
1010 + $v = json_encode( $v );
1011 + }
1492 1012
1493 - case 'frm_dyncontent':
1494 - if ( is_array( $v ) ) {
1495 - $v = json_encode( $v );
1496 - }
1497 - break;
1013 + update_post_meta( $post_id, $k, $v );
1498 1014
1499 - case 'frm_param':
1500 - add_rewrite_endpoint( $v, EP_PERMALINK | EP_PAGES );
1501 - break;
1502 - }//end switch
1503 -
1504 - update_post_meta( $post_id, $k, $v );
1505 1015 unset( $k, $v );
1506 - }//end foreach
1016 + }
1507 1017 }
1508 1018
1509 1019 /**
1510 1020 * @param array $post
@@ -1513,9 +1023,8 @@
1513 1023 private static function update_layout( &$post, $post_id ) {
1514 1024 if ( is_callable( 'FrmViewsLayout::maybe_create_layouts_for_view' ) ) {
1515 1025 $listing_layout = ! empty( $post['layout']['listing'] ) ? json_decode( $post['layout']['listing'], true ) : array();
1516 1026 $detail_layout = ! empty( $post['layout']['detail'] ) ? json_decode( $post['layout']['detail'], true ) : array();
1517 -
1518 1027 if ( $listing_layout || $detail_layout ) {
1519 1028 FrmViewsLayout::maybe_create_layouts_for_view( $post_id, $listing_layout, $detail_layout );
1520 1029 }
1521 1030 }
@@ -1521,22 +1030,32 @@
1521 1030 }
1522 1031 }
1523 1032
1524 1033 /**
1525 - * @param array $imported
1034 + * If a template includes custom css, let's include it.
1035 + * The custom css is included on the default style.
1526 1036 *
1527 - * @return void
1037 + * @since 2.03
1528 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 +
1529 1050 private static function maybe_update_stylesheet( $imported ) {
1530 - $new_styles = ! empty( $imported['imported']['styles'] );
1531 - $updated_styles = ! empty( $imported['updated']['styles'] );
1532 -
1051 + $new_styles = isset( $imported['imported']['styles'] ) && ! empty( $imported['imported']['styles'] );
1052 + $updated_styles = isset( $imported['updated']['styles'] ) && ! empty( $imported['updated']['styles'] );
1533 1053 if ( $new_styles || $updated_styles ) {
1534 1054 if ( is_admin() && function_exists( 'get_filesystem_method' ) ) {
1535 1055 $frm_style = new FrmStyle();
1536 1056 $frm_style->update( 'default' );
1537 1057 }
1538 -
1539 1058 foreach ( $imported['forms'] as $form_id ) {
1540 1059 self::update_custom_style_setting_after_import( $form_id );
1541 1060 }
1542 1061 }
@@ -1542,46 +1061,20 @@
1542 1061 }
1543 1062 }
1544 1063
1545 1064 /**
1546 - * @param mixed $result
1547 1065 * @param string $message
1548 - * @param array $errors
1549 1066 */
1550 1067 public static function parse_message( $result, &$message, &$errors ) {
1551 1068 if ( is_wp_error( $result ) ) {
1552 1069 $errors[] = $result->get_error_message();
1553 -
1554 - // Remove the SimpleXML_parse_error from the WP_Error object to avoid
1555 - // displaying duplicate error messages from $result->get_error_message()
1556 - $error_codes = $result->get_error_codes();
1557 - $error_details = array();
1558 -
1559 - foreach ( $error_codes as $error_code ) {
1560 - // Clone WP_Error data because WP_Error removes all error messages and data
1561 - // associated with the specified error code when an item is removed.
1562 - // Source: https://developer.wordpress.org/reference/classes/wp_error/remove/#source
1563 - $error_details = $result->get_error_data( $error_code );
1564 -
1565 - if ( $error_code === 'SimpleXML_parse_error' ) {
1566 - $result->remove( $error_code );
1567 - break;
1568 - }
1569 - }
1570 -
1571 - if ( ! empty( $error_details ) ) {
1572 - $errors[] = '<br />' . esc_html_x( 'Error details:', 'import xml message', 'formidable' ) . '<br />' . esc_html( print_r( $error_details, 1 ) );
1573 - }
1574 -
1070 + } elseif ( ! $result ) {
1575 1071 return;
1576 - }//end if
1577 -
1578 - if ( ! $result ) {
1579 - return;
1580 1072 }
1581 1073
1582 1074 if ( ! is_array( $result ) ) {
1583 1075 $message = is_string( $result ) ? $result : htmlentities( print_r( $result, 1 ) );
1076 +
1584 1077 return;
1585 1078 }
1586 1079
1587 1080 $t_strings = array(
@@ -1589,9 +1082,8 @@
1589 1082 'updated' => __( 'Updated', 'formidable' ),
1590 1083 );
1591 1084
1592 1085 $message = '<ul>';
1593 -
1594 1086 foreach ( $result as $type => $results ) {
1595 1087 if ( ! isset( $t_strings[ $type ] ) ) {
1596 1088 // only print imported and updated
1597 1089 continue;
@@ -1597,9 +1089,8 @@
1597 1089 continue;
1598 1090 }
1599 1091
1600 1092 $s_message = array();
1601 -
1602 1093 foreach ( $results as $k => $m ) {
1603 1094 self::item_count_message( $m, $k, $s_message );
1604 1095 unset( $k, $m );
1605 1096 }
@@ -1610,30 +1101,18 @@
1610 1101 $message .= '</li>';
1611 1102 }
1612 1103 }
1613 1104
1614 - if ( $message === '<ul>' ) {
1105 + if ( $message == '<ul>' ) {
1615 1106 $message = '';
1616 1107 $errors[] = __( 'Nothing was imported or updated', 'formidable' );
1617 1108 } else {
1618 1109 self::add_form_link_to_message( $result, $message );
1619 1110
1620 - /**
1621 - * @since 5.3
1622 - *
1623 - * @param string $message
1624 - * @param array $result
1625 - */
1626 - $message = apply_filters( 'frm_xml_parsed_message', $message, $result );
1627 1111 $message .= '</ul>';
1628 1112 }
1629 1113 }
1630 1114
1631 - /**
1632 - * @param int $m
1633 - * @param string $type
1634 - * @param array<string> $s_message
1635 - */
1636 1115 public static function item_count_message( $m, $type, &$s_message ) {
1637 1116 if ( ! $m ) {
1638 1117 return;
1639 1118 }
@@ -1647,9 +1126,9 @@
1647 1126 'items' => sprintf( _n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m ),
1648 1127 /* translators: %1$s: Number of items */
1649 1128 'views' => sprintf( _n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m ),
1650 1129 /* translators: %1$s: Number of items */
1651 - '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 ),
1652 1131 /* translators: %1$s: Number of items */
1653 1132 'styles' => sprintf( _n( '%1$s Style', '%1$s Styles', $m, 'formidable' ), $m ),
1654 1133 /* translators: %1$s: Number of items */
1655 1134 'terms' => sprintf( _n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m ),
@@ -1656,23 +1135,9 @@
1656 1135 /* translators: %1$s: Number of items */
1657 1136 'actions' => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ),
1658 1137 );
1659 1138
1660 - if ( isset( $strings[ $type ] ) ) {
1661 - $s_message[] = $strings[ $type ];
1662 - } else {
1663 - $string = ' ' . $m . ' ' . ucfirst( $type );
1664 -
1665 - /**
1666 - * @since 5.3
1667 - *
1668 - * @param string $string Message string for imported item.
1669 - * @param int $m Number of item that was imported.
1670 - * }
1671 - */
1672 - $string = apply_filters( 'frm_xml_' . $type . '_count_message', $string, $m );
1673 - $s_message[] = $string;
1674 - }
1139 + $s_message[] = isset( $strings[ $type ] ) ? $strings[ $type ] : ' ' . $m . ' ' . ucfirst( $type );
1675 1140 }
1676 1141
1677 1142 /**
1678 1143 * If a single form was imported, include a link in the success message.
@@ -1677,21 +1142,18 @@
1677 1142 /**
1678 1143 * If a single form was imported, include a link in the success message.
1679 1144 *
1680 1145 * @since 4.0
1681 - *
1682 1146 * @param array $result The response from the XML import.
1683 1147 * @param string $message The response shown on the page after import.
1684 1148 */
1685 1149 private static function add_form_link_to_message( $result, &$message ) {
1686 1150 $total_forms = $result['imported']['forms'] + $result['updated']['forms'];
1687 -
1688 1151 if ( $total_forms > 1 ) {
1689 1152 return;
1690 1153 }
1691 1154
1692 1155 $primary_form = reset( $result['forms'] );
1693 -
1694 1156 if ( ! empty( $primary_form ) ) {
1695 1157 $primary_form = FrmForm::getOne( $primary_form );
1696 1158 $form_id = empty( $primary_form->parent_form_id ) ? $primary_form->id : $primary_form->parent_form_id;
1697 1159
@@ -1711,9 +1173,8 @@
1711 1173 public static function prepare_form_options_for_export( $options ) {
1712 1174 FrmAppHelper::unserialize_or_decode( $options );
1713 1175 // Change custom_style to the post_name instead of ID (1 may be a string)
1714 1176 $not_default = isset( $options['custom_style'] ) && 1 != $options['custom_style'];
1715 -
1716 1177 if ( $not_default ) {
1717 1178 global $wpdb;
1718 1179 $table = $wpdb->prefix . 'posts';
1719 1180 $where = array( 'ID' => $options['custom_style'] );
@@ -1737,16 +1198,11 @@
1737 1198 * If the saved value is the same as the default, remove it from the export
1738 1199 * This keeps file size down and prevents overriding global settings after import
1739 1200 *
1740 1201 * @since 3.06
1741 - *
1742 - * @param array $options By reference.
1743 - *
1744 - * @return void
1745 1202 */
1746 1203 private static function remove_default_form_options( &$options ) {
1747 1204 $defaults = FrmFormsHelper::get_default_opts();
1748 -
1749 1205 if ( is_callable( 'FrmProFormsHelper::get_default_opts' ) ) {
1750 1206 $defaults += FrmProFormsHelper::get_default_opts();
1751 1207 }
1752 1208 self::remove_defaults( $defaults, $options );
@@ -1755,16 +1211,11 @@
1755 1211 /**
1756 1212 * Remove extra settings from field to keep file size down
1757 1213 *
1758 1214 * @since 3.06
1759 - *
1760 - * @param object $field
1761 - *
1762 - * @return void
1763 1215 */
1764 1216 public static function prepare_field_for_export( &$field ) {
1765 1217 self::remove_default_field_options( $field );
1766 - self::add_image_src_to_image_options( $field );
1767 1218 }
1768 1219
1769 1220 /**
1770 1221 * Remove defaults from field options too
@@ -1769,16 +1220,11 @@
1769 1220 /**
1770 1221 * Remove defaults from field options too
1771 1222 *
1772 1223 * @since 3.06
1773 - *
1774 - * @param object $field
1775 - *
1776 - * @return void
1777 1224 */
1778 1225 private static function remove_default_field_options( &$field ) {
1779 1226 $defaults = self::default_field_options( $field->type );
1780 -
1781 1227 if ( empty( $defaults['blank'] ) ) {
1782 1228 $global_settings = new FrmSettings();
1783 1229 $global_defaults = $global_settings->default_options();
1784 1230 $defaults['blank'] = $global_defaults['blank_msg'];
@@ -1801,51 +1247,12 @@
1801 1247 $field->field_options = serialize( $options );
1802 1248 }
1803 1249
1804 1250 /**
1805 - * Add image "src" key to each image option so the image can be imported to another website.
1806 - *
1807 - * @since 5.5.1
1808 - *
1809 - * @param stdClass $field
1810 - *
1811 - * @return void
1812 - */
1813 - private static function add_image_src_to_image_options( $field ) {
1814 - if ( empty( $field->options ) || false === strpos( $field->options, 'image' ) ) {
1815 - return;
1816 - }
1817 -
1818 - $updated = false;
1819 - $options = $field->options;
1820 - FrmAppHelper::unserialize_or_decode( $options );
1821 -
1822 - if ( ! $options || ! is_array( $options ) ) {
1823 - return;
1824 - }
1825 -
1826 - foreach ( $options as $key => $option ) {
1827 - if ( is_array( $option ) && ! empty( $option['image'] ) ) {
1828 - $options[ $key ]['src'] = wp_get_attachment_url( $option['image'] );
1829 - $updated = true;
1830 - }
1831 - }
1832 -
1833 - if ( $updated ) {
1834 - $field->options = maybe_serialize( $options );
1835 - }
1836 - }
1837 -
1838 - /**
1839 1251 * @since 3.06.03
1840 - *
1841 - * @param string $type
1842 - *
1843 - * @return array
1844 1252 */
1845 1253 private static function default_field_options( $type ) {
1846 1254 $defaults = FrmFieldsHelper::get_default_field_options( $type );
1847 -
1848 1255 if ( empty( $defaults['custom_html'] ) ) {
1849 1256 $defaults['custom_html'] = FrmFieldsHelper::get_default_html( $type );
1850 1257 }
1851 1258 return $defaults;
@@ -1855,13 +1262,8 @@
1855 1262 * Compare the default array to the saved values and
1856 1263 * remove if they are the same
1857 1264 *
1858 1265 * @since 3.06
1859 - *
1860 - * @param array $defaults
1861 - * @param array $saved
1862 - *
1863 - * @return void
1864 1266 */
1865 1267 private static function remove_defaults( $defaults, &$saved ) {
1866 1268 foreach ( $saved as $key => $value ) {
1867 1269 if ( isset( $defaults[ $key ] ) && $defaults[ $key ] === $value ) {
@@ -1873,14 +1275,8 @@
1873 1275 /**
1874 1276 * The line endings may prevent html from being equal when it should
1875 1277 *
1876 1278 * @since 3.06
1877 - *
1878 - * @param string $html_name
1879 - * @param array $defaults
1880 - * @param array $options
1881 - *
1882 - * @return void
1883 1279 */
1884 1280 private static function remove_default_html( $html_name, $defaults, &$options ) {
1885 1281 if ( ! isset( $options[ $html_name ] ) || ! isset( $defaults[ $html_name ] ) ) {
1886 1282 return;
@@ -1887,9 +1283,8 @@
1887 1283 }
1888 1284
1889 1285 $old_html = str_replace( "\r\n", "\n", $options[ $html_name ] );
1890 1286 $default_html = $defaults[ $html_name ];
1891 -
1892 1287 if ( $old_html == $default_html ) {
1893 1288 unset( $options[ $html_name ] );
1894 1289
1895 1290 return;
@@ -1896,26 +1291,19 @@
1896 1291 }
1897 1292
1898 1293 // Account for some of the older field default HTML.
1899 1294 $default_html = str_replace( ' id="frm_desc_field_[key]"', '', $default_html );
1900 -
1901 - if ( $old_html === $default_html ) {
1295 + if ( $old_html == $default_html ) {
1902 1296 unset( $options[ $html_name ] );
1903 1297 }
1904 1298 }
1905 1299
1906 - /**
1907 - * @param string $str
1908 - *
1909 - * @return string
1910 - */
1911 1300 public static function cdata( $str ) {
1912 1301 FrmAppHelper::unserialize_or_decode( $str );
1913 -
1914 1302 if ( is_array( $str ) ) {
1915 1303 $str = json_encode( $str );
1916 - } elseif ( FrmAppHelper::is_valid_utf8( $str ) === false ) {
1917 - $str = FrmAppHelper::maybe_utf8_encode( $str );
1304 + } elseif ( seems_utf8( $str ) === false ) {
1305 + $str = utf8_encode( $str );
1918 1306 }
1919 1307
1920 1308 if ( is_numeric( $str ) ) {
1921 1309 return $str;
@@ -1934,10 +1322,8 @@
1934 1322 *
1935 1323 * @since 2.0.22
1936 1324 *
1937 1325 * @param string $str
1938 - *
1939 - * @return void
1940 1326 */
1941 1327 private static function remove_invalid_characters_from_xml( &$str ) {
1942 1328 // Remove <US> character
1943 1329 $str = str_replace( '\x1F', '', $str );
@@ -1942,18 +1328,8 @@
1942 1328 // Remove <US> character
1943 1329 $str = str_replace( '\x1F', '', $str );
1944 1330 }
1945 1331
1946 - /**
1947 - * Migrate form settings to actions
1948 - *
1949 - * @param array $form_options
1950 - * @param int $form_id
1951 - * @param array $imported
1952 - * @param bool $switch
1953 - *
1954 - * @return void
1955 - */
1956 1332 public static function migrate_form_settings_to_actions( $form_options, $form_id, &$imported = array(), $switch = false ) {
1957 1333 // Get post type
1958 1334 $post_type = FrmFormActionsController::$action_post_type;
1959 1335
@@ -1971,13 +1347,9 @@
1971 1347
1972 1348 /**
1973 1349 * Migrate post settings to form action
1974 1350 *
1975 - * @param array $form_options
1976 - * @param int $form_id
1977 1351 * @param string $post_type
1978 - * @param array $imported
1979 - * @param bool $switch
1980 1352 */
1981 1353 private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
1982 1354 if ( ! isset( $form_options['create_post'] ) || ! $form_options['create_post'] ) {
1983 1355 return;
@@ -2046,9 +1418,9 @@
2046 1418
2047 1419 if ( ! $exists ) {
2048 1420 // this isn't an email, but we need to use a class that will always be included
2049 1421 FrmDb::save_json_post( $new_action );
2050 - ++$imported['imported']['actions'];
1422 + $imported['imported']['actions'] ++;
2051 1423 }
2052 1424 }
2053 1425
2054 1426 /**
@@ -2055,11 +1427,11 @@
2055 1427 * Switch old field IDs for new field IDs in emails and post
2056 1428 *
2057 1429 * @since 2.0
2058 1430 *
2059 - * @param array $post_content Check for old field IDs.
2060 - * @param array $basic_fields Fields with string or int saved.
2061 - * @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
2062 1434 *
2063 1435 * @return string $post_content - new field IDs
2064 1436 */
2065 1437 private static function switch_action_field_ids( $post_content, $basic_fields, $array_fields = array() ) {
@@ -2092,19 +1464,8 @@
2092 1464
2093 1465 return $post_content;
2094 1466 }
2095 1467
2096 - /**
2097 - * Migrate email settings to action
2098 - *
2099 - * @param array $form_options
2100 - * @param int $form_id
2101 - * @param string $post_type
2102 - * @param array $imported
2103 - * @param bool $switch
2104 - *
2105 - * @return void
2106 - */
2107 1468 private static function migrate_email_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
2108 1469 // No old notifications or autoresponders to carry over
2109 1470 if ( ! isset( $form_options['auto_responder'] ) && ! isset( $form_options['notification'] ) && ! isset( $form_options['email_to'] ) ) {
2110 1471 return;
@@ -2151,12 +1512,12 @@
2151 1512 );
2152 1513
2153 1514 if ( empty( $exists ) ) {
2154 1515 FrmDb::save_json_post( $new_notification );
2155 - ++$imported['imported']['actions'];
1516 + $imported['imported']['actions'] ++;
2156 1517 }
2157 1518 unset( $new_notification );
2158 - }//end foreach
1519 + }
2159 1520
2160 1521 self::remove_deprecated_notification_settings( $form_id, $form_options );
2161 1522 }
2162 1523
@@ -2165,15 +1526,12 @@
2165 1526 *
2166 1527 * @since 2.05
2167 1528 *
2168 1529 * @param int|string $form_id
2169 - * @param array $form_options
2170 - *
2171 - * @return void
1530 + * @param array $form_options
2172 1531 */
2173 1532 private static function remove_deprecated_notification_settings( $form_id, $form_options ) {
2174 1533 $delete_settings = array( 'notification', 'autoresponder', 'email_to' );
2175 -
2176 1534 foreach ( $delete_settings as $index ) {
2177 1535 if ( isset( $form_options[ $index ] ) ) {
2178 1536 unset( $form_options[ $index ] );
2179 1537 }
@@ -2180,19 +1538,10 @@
2180 1538 }
2181 1539 FrmForm::update( $form_id, array( 'options' => $form_options ) );
2182 1540 }
2183 1541
2184 - /**
2185 - * Migrate notifications to action
2186 - *
2187 - * @param array $form_options
2188 - * @param int $form_id
2189 - * @param array $notifications
2190 - *
2191 - * @return void
2192 - */
2193 1542 private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) {
2194 - 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'] ) ) {
2195 1544 // add old settings into notification array
2196 1545 $form_options['notification'] = array( 0 => $form_options );
2197 1546 } elseif ( isset( $form_options['notification']['email_to'] ) ) {
2198 1547 // make sure it's in the correct format
@@ -2222,20 +1571,12 @@
2222 1571 $new_notification = array();
2223 1572 self::setup_new_notification( $new_notification, $notification, $atts );
2224 1573
2225 1574 $notifications[] = $new_notification;
2226 - }//end foreach
2227 - }//end if
1575 + }
1576 + }
2228 1577 }
2229 1578
2230 - /**
2231 - * Format email data
2232 - *
2233 - * @param array $atts
2234 - * @param array $notification
2235 - *
2236 - * @return void
2237 - */
2238 1579 private static function format_email_data( &$atts, $notification ) {
2239 1580 // Format email_to
2240 1581 self::format_email_to_data( $atts, $notification );
2241 1582
@@ -2243,13 +1584,11 @@
2243 1584 $reply_fields = array(
2244 1585 'reply_to' => '',
2245 1586 'reply_to_name' => '',
2246 1587 );
2247 -
2248 1588 foreach ( $reply_fields as $f => $val ) {
2249 1589 if ( isset( $notification[ $f ] ) ) {
2250 1590 $atts[ $f ] = $notification[ $f ];
2251 -
2252 1591 if ( 'custom' == $notification[ $f ] ) {
2253 1592 $atts[ $f ] = $notification[ 'cust_' . $f ];
2254 1593 } elseif ( is_numeric( $atts[ $f ] ) && ! empty( $atts[ $f ] ) ) {
2255 1594 $atts[ $f ] = '[' . $atts[ $f ] . ']';
@@ -2259,9 +1598,8 @@
2259 1598 }
2260 1599
2261 1600 // Format event
2262 1601 $atts['event'] = array( 'create' );
2263 -
2264 1602 if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) {
2265 1603 $atts['event'][] = 'update';
2266 1604 } elseif ( isset( $notification['update_email'] ) && 2 == $notification['update_email'] ) {
2267 1605 $atts['event'] = array( 'update' );
@@ -2267,16 +1605,8 @@
2267 1605 $atts['event'] = array( 'update' );
2268 1606 }
2269 1607 }
2270 1608
2271 - /**
2272 - * Format email_to data
2273 - *
2274 - * @param array $atts
2275 - * @param array $notification
2276 - *
2277 - * @return void
2278 - */
2279 1609 private static function format_email_to_data( &$atts, $notification ) {
2280 1610 if ( isset( $notification['email_to'] ) ) {
2281 1611 $atts['email_to'] = preg_split( '/ (,|;) /', $notification['email_to'] );
2282 1612 } else {
@@ -2296,9 +1626,8 @@
2296 1626 }
2297 1627
2298 1628 if ( strpos( $email_field, '|' ) ) {
2299 1629 $email_opt = explode( '|', $email_field );
2300 -
2301 1630 if ( isset( $email_opt[0] ) ) {
2302 1631 $atts['email_to'][ $key ] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']';
2303 1632 }
2304 1633 unset( $email_opt );
@@ -2306,17 +1635,8 @@
2306 1635 }
2307 1636 $atts['email_to'] = implode( ', ', $atts['email_to'] );
2308 1637 }
2309 1638
2310 - /**
2311 - * Setup new notification
2312 - *
2313 - * @param array $new_notification
2314 - * @param array $notification
2315 - * @param array $atts
2316 - *
2317 - * @return void
2318 - */
2319 1639 private static function setup_new_notification( &$new_notification, $notification, $atts ) {
2320 1640 // Set up new notification
2321 1641 $new_notification = array(
2322 1642 'post_content' => array(
@@ -2327,9 +1647,8 @@
2327 1647 );
2328 1648
2329 1649 // Add more fields to the new notification
2330 1650 $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' );
2331 -
2332 1651 foreach ( $add_fields as $add_field ) {
2333 1652 if ( isset( $notification[ $add_field ] ) ) {
2334 1653 $new_notification['post_content'][ $add_field ] = $notification[ $add_field ];
2335 1654 } elseif ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) {
@@ -2351,11 +1670,9 @@
2351 1670
2352 1671 /**
2353 1672 * Switch field IDs in pre-2.0 email conditional logic
2354 1673 *
2355 - * @param array $post_content Pass by reference.
2356 - *
2357 - * @return void
1674 + * @param $post_content array, pass by reference
2358 1675 */
2359 1676 private static function switch_email_condition_field_ids( &$post_content ) {
2360 1677 // Switch field IDs in conditional logic
2361 1678 if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) {
@@ -2367,32 +1684,20 @@
2367 1684 }
2368 1685 }
2369 1686 }
2370 1687
2371 - /**
2372 - * Migrate autoresponder to action
2373 - *
2374 - * @param array $form_options
2375 - * @param int $form_id
2376 - * @param array $notifications
2377 - *
2378 - * @return void
2379 - */
2380 1688 private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) {
2381 1689 if ( isset( $form_options['auto_responder'] ) && $form_options['auto_responder'] && isset( $form_options['ar_email_message'] ) && $form_options['ar_email_message'] ) {
2382 1690 // migrate autoresponder
2383 1691
2384 - $email_field = $form_options['ar_email_to'] ?? 0;
2385 -
1692 + $email_field = isset( $form_options['ar_email_to'] ) ? $form_options['ar_email_to'] : 0;
2386 1693 if ( strpos( $email_field, '|' ) ) {
2387 1694 // data from entries field
2388 1695 $email_field = explode( '|', $email_field );
2389 -
2390 1696 if ( isset( $email_field[1] ) ) {
2391 1697 $email_field = $email_field[1];
2392 1698 }
2393 1699 }
2394 -
2395 1700 if ( is_numeric( $email_field ) && ! empty( $email_field ) ) {
2396 1701 $email_field = '[' . $email_field . ']';
2397 1702 }
2398 1703
@@ -2399,18 +1704,18 @@
2399 1704 $notification = $form_options;
2400 1705 $new_notification2 = array(
2401 1706 'post_content' => array(
2402 1707 'email_message' => $notification['ar_email_message'],
2403 - 'email_subject' => $notification['ar_email_subject'] ?? '',
1708 + 'email_subject' => isset( $notification['ar_email_subject'] ) ? $notification['ar_email_subject'] : '',
2404 1709 'email_to' => $email_field,
2405 - 'plain_text' => $notification['ar_plain_text'] ?? 0,
1710 + 'plain_text' => isset( $notification['ar_plain_text'] ) ? $notification['ar_plain_text'] : 0,
2406 1711 'inc_user_info' => 0,
2407 1712 ),
2408 1713 'post_name' => $form_id . '_email_' . count( $notifications ),
2409 1714 );
2410 1715
2411 - $reply_to = $notification['ar_reply_to'] ?? '';
2412 - $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'] : '';
2413 1718
2414 1719 if ( ! empty( $reply_to ) ) {
2415 1720 $new_notification2['post_content']['reply_to'] = $reply_to;
2416 1721 }
@@ -2420,17 +1725,17 @@
2420 1725 }
2421 1726
2422 1727 $notifications[] = $new_notification2;
2423 1728 unset( $new_notification2 );
2424 - }//end if
1729 + }
2425 1730 }
2426 1731
2427 1732 /**
2428 1733 * PHP 8 backward compatibility for the libxml_disable_entity_loader function
2429 1734 *
2430 - * @param bool $loader
1735 + * @param boolean $disable
2431 1736 *
2432 - * @return bool
1737 + * @return boolean
2433 1738 */
2434 1739 public static function maybe_libxml_disable_entity_loader( $loader ) {
2435 1740 if ( version_compare( phpversion(), '8.0', '<' ) && function_exists( 'libxml_disable_entity_loader' ) ) {
2436 1741 $loader = libxml_disable_entity_loader( $loader ); // phpcs:disable Generic.PHP.DeprecatedFunctions.Deprecated
@@ -2438,31 +1743,9 @@
2438 1743
2439 1744 return $loader;
2440 1745 }
2441 1746
2442 - /**
2443 - * PHP 8 backward compatibility for the libxml_disable_entity_loader function
2444 - *
2445 - * @return bool
2446 - */
2447 1747 public static function check_if_libxml_disable_entity_loader_exists() {
2448 1748 return version_compare( phpversion(), '8.0', '<' ) && ! function_exists( 'libxml_disable_entity_loader' );
2449 1749 }
1750 +}
2450 1751
2451 - /**
2452 - * Get the file types allowed for importing.
2453 - * This is used in the "accept" attribute for the file upload input on the XML import page.
2454 - *
2455 - * @since 6.8.3
2456 - *
2457 - * @return array
2458 - */
2459 - public static function get_supported_upload_file_types() {
2460 - $file_types = array( '.xml' );
2461 -
2462 - if ( FrmAppHelper::pro_is_installed() ) {
2463 - // CSV Importing is only available in Pro.
2464 - $file_types[] = '.csv';
2465 - }
2466 - return $file_types;
2467 - }
2468 -}