PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.7
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.7
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 +81 -493 6.266.7 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 }
@@ -61,9 +49,8 @@
61 49
62 50 // LIBXML_COMPACT activates small nodes allocation optimization.
63 51 // Use LIBXML_PARSEHUGE to avoid "parser error : internal error: Huge input lookup" for large (300MB) files.
64 52 $success = $dom->loadXML( $xml_string, LIBXML_COMPACT | LIBXML_PARSEHUGE );
65 -
66 53 if ( ! $success ) {
67 54 return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
68 55 }
69 56
@@ -85,9 +72,8 @@
85 72 /**
86 73 * @since 6.2.3
87 74 *
88 75 * @param string $xml_string
89 - *
90 76 * @return void
91 77 */
92 78 private static function maybe_fix_xml( &$xml_string ) {
93 79 if ( '<?xml' !== substr( $xml_string, 0, 5 ) ) {
@@ -98,9 +84,8 @@
98 84 // The Equity theme adds a <meta name="generator" content="Equity 1.7.13" /> tag using the "the_generator" filter.
99 85 // Strip that out as it breaks the XML import.
100 86 $channel_start_position = strpos( $xml_string, '<channel>' );
101 87 $content_before_channel_tag = substr( $xml_string, 0, $channel_start_position );
102 -
103 88 if ( 0 !== strpos( $content_before_channel_tag, '<meta name="generator" ' ) ) {
104 89 $content_before_channel_tag = preg_replace(
105 90 '/<meta\s+[^>]*name="generator"[^>]*\/>/i',
106 91 '',
@@ -106,9 +91,9 @@
106 91 '',
107 92 $content_before_channel_tag,
108 93 1
109 94 );
110 - $xml_string = $content_before_channel_tag . substr( $xml_string, $channel_start_position );
95 + $xml_string = $content_before_channel_tag . substr( $xml_string, $channel_start_position );
111 96 }
112 97 }
113 98
114 99 /**
@@ -117,9 +102,8 @@
117 102 * @since 3.06
118 103 *
119 104 * @param object $xml
120 105 * @param bool $installing_template
121 - *
122 106 * @return array The number of items imported
123 107 */
124 108 public static function import_xml_now( $xml, $installing_template = false ) {
125 109 if ( ! defined( 'WP_IMPORTING' ) ) {
@@ -139,9 +123,9 @@
139 123 }
140 124
141 125 $imported = apply_filters( 'frm_importing_xml', $imported, $xml );
142 126
143 - if ( empty( $imported['form_status'] ) ) {
127 + if ( ! isset( $imported['form_status'] ) || empty( $imported['form_status'] ) ) {
144 128 // Check for an error message in the XML.
145 129 if ( isset( $xml->Code ) && isset( $xml->Message ) ) { // phpcs:ignore WordPress.NamingConventions
146 130 $imported['error'] = (string) $xml->Message; // phpcs:ignore WordPress.NamingConventions
147 131 }
@@ -151,9 +135,8 @@
151 135 }
152 136
153 137 /**
154 138 * @since 3.06
155 - *
156 139 * @return array
157 140 */
158 141 private static function pre_import_data() {
159 142 $defaults = array(
@@ -173,14 +156,8 @@
173 156 'terms' => array(),
174 157 );
175 158 }
176 159
177 - /**
178 - * @param SimpleXMLElement $terms
179 - * @param array $imported
180 - *
181 - * @return array
182 - */
183 160 public static function import_xml_terms( $terms, $imported ) {
184 161 foreach ( $terms as $t ) {
185 162 if ( term_exists( (string) $t->term_slug, (string) $t->term_taxonomy ) ) {
186 163 continue;
@@ -198,14 +175,14 @@
198 175 )
199 176 );
200 177
201 178 if ( $term && is_array( $term ) ) {
202 - ++$imported['imported']['terms'];
179 + $imported['imported']['terms'] ++;
203 180 $imported['terms'][ (int) $t->term_id ] = $term['term_id'];
204 181 }
205 182
206 183 unset( $term, $t );
207 - }//end foreach
184 + }
208 185
209 186 return $imported;
210 187 }
211 188
@@ -210,19 +187,13 @@
210 187 }
211 188
212 189 /**
213 190 * @since 2.0.8
214 - *
215 - * @param object $t
216 - *
217 - * @return int|string
218 191 */
219 192 private static function get_term_parent_id( $t ) {
220 193 $parent = (string) $t->term_parent;
221 -
222 194 if ( ! empty( $parent ) ) {
223 195 $parent = term_exists( (string) $t->term_parent, (string) $t->term_taxonomy );
224 -
225 196 if ( $parent ) {
226 197 $parent = $parent['term_id'];
227 198 } else {
228 199 $parent = 0;
@@ -231,14 +202,8 @@
231 202
232 203 return $parent;
233 204 }
234 205
235 - /**
236 - * @param SimpleXMLElement $forms
237 - * @param array $imported
238 - *
239 - * @return array
240 - */
241 206 public static function import_xml_forms( $forms, $imported ) {
242 207 $child_forms = array();
243 208
244 209 // Import child forms first
@@ -252,9 +217,8 @@
252 217 $this_form = self::maybe_get_form( $form );
253 218
254 219 $old_id = false;
255 220 $form_fields = false;
256 -
257 221 if ( ! empty( $this_form ) ) {
258 222 $form_id = $this_form->id;
259 223 $old_id = $this_form->id;
260 224 self::update_form( $this_form, $form, $imported );
@@ -261,13 +225,12 @@
261 225
262 226 $form_fields = self::get_form_fields( $form_id );
263 227 } else {
264 228 $form_id = FrmForm::create( $form );
265 -
266 229 if ( $form_id ) {
267 230 if ( empty( $form['parent_form_id'] ) ) {
268 231 // Don't include the repeater form in the imported count.
269 - ++$imported['imported']['forms'];
232 + $imported['imported']['forms'] ++;
270 233 }
271 234
272 235 // Keep track of whether this specific form was updated or not.
273 236 $imported['form_status'][ $form_id ] = 'imported';
@@ -292,9 +255,9 @@
292 255
293 256 do_action( 'frm_after_import_form', $form_id, $form );
294 257
295 258 unset( $form, $item );
296 - }//end foreach
259 + }
297 260
298 261 self::maybe_update_child_form_parent_id( $imported['forms'], $child_forms );
299 262
300 263 return $imported;
@@ -299,13 +262,8 @@
299 262
300 263 return $imported;
301 264 }
302 265
303 - /**
304 - * @param object $item
305 - *
306 - * @return array
307 - */
308 266 private static function fill_form( $item ) {
309 267 $form = array(
310 268 'id' => (int) $item->id,
311 269 'form_key' => (string) $item->form_key,
@@ -333,13 +291,8 @@
333 291
334 292 return $form;
335 293 }
336 294
337 - /**
338 - * @param array $form
339 - *
340 - * @return false|object
341 - */
342 295 private static function maybe_get_form( $form ) {
343 296 // if template, allow to edit if form keys match, otherwise, creation date must also match
344 297 $edit_query = array(
345 298 'form_key' => $form['form_key'],
@@ -344,9 +297,8 @@
344 297 $edit_query = array(
345 298 'form_key' => $form['form_key'],
346 299 'is_template' => $form['is_template'],
347 300 );
348 -
349 301 if ( ! $form['is_template'] ) {
350 302 $edit_query['created_at'] = $form['created_at'];
351 303 }
352 304
@@ -352,9 +304,8 @@
352 304
353 305 $edit_query = apply_filters( 'frm_match_xml_form', $edit_query, $form );
354 306
355 307 $form = FrmForm::getAll( $edit_query, '', 1 );
356 -
357 308 if ( is_object( $form ) && $form->status === 'trash' ) {
358 309 FrmForm::destroy( $form->id );
359 310 return false;
360 311 }
@@ -361,22 +312,14 @@
361 312
362 313 return $form;
363 314 }
364 315
365 - /**
366 - * @param object $this_form
367 - * @param array $form
368 - * @param array $imported
369 - *
370 - * @return void
371 - */
372 316 private static function update_form( $this_form, $form, &$imported ) {
373 317 $form_id = $this_form->id;
374 318 FrmForm::update( $form_id, $form );
375 -
376 319 if ( empty( $form['parent_form_id'] ) ) {
377 320 // Don't include the repeater form in the updated count.
378 - ++$imported['updated']['forms'];
321 + $imported['updated']['forms'] ++;
379 322 }
380 323
381 324 // Keep track of whether this specific form was updated or not
382 325 $imported['form_status'][ $form_id ] = 'updated';
@@ -381,23 +324,16 @@
381 324 // Keep track of whether this specific form was updated or not
382 325 $imported['form_status'][ $form_id ] = 'updated';
383 326 }
384 327
385 - /**
386 - * @param int|string $form_id
387 - *
388 - * @return array
389 - */
390 328 private static function get_form_fields( $form_id ) {
391 329 $form_fields = FrmField::get_all_for_form( $form_id, '', 'exclude', 'exclude' );
392 330 $old_fields = array();
393 -
394 331 foreach ( $form_fields as $f ) {
395 332 $old_fields[ $f->id ] = $f;
396 333 $old_fields[ $f->field_key ] = $f->id;
397 334 unset( $f );
398 335 }
399 -
400 336 $form_fields = $old_fields;
401 337
402 338 return $form_fields;
403 339 }
@@ -403,12 +339,8 @@
403 339 }
404 340
405 341 /**
406 342 * 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 343 */
412 344 private static function delete_removed_fields( $form_fields ) {
413 345 if ( ! empty( $form_fields ) ) {
414 346 foreach ( $form_fields as $field ) {
@@ -448,10 +380,10 @@
448 380 * Keep track of all imported child forms
449 381 *
450 382 * @since 2.0.16
451 383 *
452 - * @param int $form_id
453 - * @param int $parent_form_id
384 + * @param int $form_id
385 + * @param int $parent_form_id
454 386 * @param array $child_forms
455 387 */
456 388 private static function track_imported_child_forms( $form_id, $parent_form_id, &$child_forms ) {
457 389 if ( $parent_form_id ) {
@@ -484,14 +416,8 @@
484 416 *
485 417 * @since 2.0.13
486 418 *
487 419 * 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 420 */
495 421 private static function import_xml_fields( $xml_fields, $form_id, $this_form, &$form_fields, &$imported ) {
496 422 $in_section = 0;
497 423 $keys_by_original_field_id = array();
@@ -509,13 +435,13 @@
509 435 if ( ! empty( $this_form ) ) {
510 436 // check for field to edit by field id
511 437 if ( isset( $form_fields[ $f['id'] ] ) ) {
512 438 FrmField::update( $f['id'], $f );
513 - ++$imported['updated']['fields'];
439 + $imported['updated']['fields'] ++;
514 440
515 441 unset( $form_fields[ $f['id'] ] );
516 442
517 - // Unset old field key.
443 + //unset old field key
518 444 if ( isset( $form_fields[ $f['field_key'] ] ) ) {
519 445 unset( $form_fields[ $f['field_key'] ] );
520 446 }
521 447 } elseif ( isset( $form_fields[ $f['field_key'] ] ) ) {
@@ -520,32 +446,25 @@
520 446 }
521 447 } elseif ( isset( $form_fields[ $f['field_key'] ] ) ) {
522 448 $keys_by_original_field_id[ $f['id'] ] = $f['field_key'];
523 449
524 - $old_field_id = $f['id'];
525 -
526 450 // check for field to edit by field key
527 451 unset( $f['id'] );
528 452
529 453 FrmField::update( $form_fields[ $f['field_key'] ], $f );
530 - ++$imported['updated']['fields'];
454 + $imported['updated']['fields'] ++;
531 455
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'] ] );
456 + unset( $form_fields[ $form_fields[ $f['field_key'] ] ] ); //unset old field id
457 + unset( $form_fields[ $f['field_key'] ] ); //unset old field key
539 458 } else {
540 - // If no matching field id or key in this form, create the field.
459 + // if no matching field id or key in this form, create the field
541 460 self::create_imported_field( $f, $imported );
542 - }//end if
461 + }
543 462 } else {
544 463
545 464 self::create_imported_field( $f, $imported );
546 - }//end if
547 - }//end foreach
465 + }
466 + }
548 467
549 468 if ( $keys_by_original_field_id ) {
550 469 self::maybe_update_field_ids( $form_id, $keys_by_original_field_id );
551 470 }
@@ -550,53 +469,8 @@
550 469 self::maybe_update_field_ids( $form_id, $keys_by_original_field_id );
551 470 }
552 471 }
553 472
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 473 private static function fill_field( $field, $form_id ) {
600 474 return array(
601 475 'id' => (int) $field->id,
602 476 'field_key' => (string) $field->field_key,
@@ -613,12 +487,8 @@
613 487 }
614 488
615 489 /**
616 490 * @since 4.06
617 - *
618 - * @param array $f
619 - *
620 - * @return void
621 491 */
622 492 private static function set_default_value( &$f ) {
623 493 $has_default = array(
624 494 'text',
@@ -645,12 +515,8 @@
645 515 /**
646 516 * Make sure the required indicator is set.
647 517 *
648 518 * @since 4.05
649 - *
650 - * @param array $f
651 - *
652 - * @return void
653 519 */
654 520 private static function maybe_add_required( &$f ) {
655 521 if ( $f['required'] && ! isset( $f['field_options']['required_indicator'] ) ) {
656 522 $f['field_options']['required_indicator'] = '*';
@@ -660,13 +526,10 @@
660 526 /**
661 527 * Update the current in_section value at the beginning of the field loop
662 528 *
663 529 * @since 2.0.25
664 - *
665 - * @param int $in_section
530 + * @param int $in_section
666 531 * @param array $f
667 - *
668 - * @return void
669 532 */
670 533 private static function maybe_update_in_section_variable( &$in_section, &$f ) {
671 534 // If we're at the end of a section, switch $in_section is 0
672 535 if ( in_array( $f['type'], array( 'end_divider', 'break', 'form' ) ) ) {
@@ -678,9 +541,9 @@
678 541 $f['field_options']['in_section'] = $in_section;
679 542 }
680 543
681 544 // If we're starting a new section, switch $in_section to ID of divider
682 - if ( $f['type'] === 'divider' ) {
545 + if ( $f['type'] == 'divider' ) {
683 546 $in_section = $f['id'];
684 547 }
685 548 }
686 549
@@ -696,12 +559,11 @@
696 559 if ( ! isset( $imported['forms'] ) ) {
697 560 return;
698 561 }
699 562
700 - if ( $f['type'] === 'form' || ( $f['type'] === 'divider' && FrmField::is_option_true( $f['field_options'], 'repeat' ) ) ) {
563 + if ( $f['type'] == 'form' || ( $f['type'] == 'divider' && FrmField::is_option_true( $f['field_options'], 'repeat' ) ) ) {
701 564 if ( FrmField::is_option_true( $f['field_options'], 'form_select' ) ) {
702 565 $form_select = (int) $f['field_options']['form_select'];
703 -
704 566 if ( isset( $imported['forms'][ $form_select ] ) ) {
705 567 $f['field_options']['form_select'] = $imported['forms'][ $form_select ];
706 568 }
707 569 }
@@ -714,10 +576,8 @@
714 576 * @since 2.01.0
715 577 *
716 578 * @param array $imported
717 579 * @param array $f
718 - *
719 - * @return void
720 580 */
721 581 private static function maybe_update_get_values_form_setting( $imported, &$f ) {
722 582 if ( ! isset( $imported['forms'] ) ) {
723 583 return;
@@ -724,9 +584,8 @@
724 584 }
725 585
726 586 if ( FrmField::is_option_true_in_array( $f['field_options'], 'get_values_form' ) ) {
727 587 $old_form = $f['field_options']['get_values_form'];
728 -
729 588 if ( isset( $imported['forms'][ $old_form ] ) ) {
730 589 $f['field_options']['get_values_form'] = $imported['forms'][ $old_form ];
731 590 }
732 591 }
@@ -735,12 +594,8 @@
735 594 /**
736 595 * If field settings have been migrated, update the values during import.
737 596 *
738 597 * @since 4.0
739 - *
740 - * @param array $f
741 - *
742 - * @return void
743 598 */
744 599 private static function run_field_migrations( &$f ) {
745 600 self::migrate_placeholders( $f );
746 601 $f = apply_filters( 'frm_import_xml_field', $f );
@@ -747,22 +602,16 @@
747 602 }
748 603
749 604 /**
750 605 * @since 4.0
751 - *
752 - * @param array $f
753 - *
754 - * @return void
755 606 */
756 607 private static function migrate_placeholders( &$f ) {
757 608 $update_values = self::migrate_field_placeholder( $f, 'clear_on_focus' );
758 -
759 609 foreach ( $update_values as $k => $v ) {
760 610 $f[ $k ] = $v;
761 611 }
762 612
763 613 $update_values = self::migrate_field_placeholder( $f, 'default_blank' );
764 -
765 614 foreach ( $update_values as $k => $v ) {
766 615 $f[ $k ] = $v;
767 616 }
768 617 }
@@ -771,18 +620,13 @@
771 620 * Move clear_on_focus or default_blank to placeholder.
772 621 * Also called during database migration in FrmMigrate.
773 622 *
774 623 * @since 4.0
775 - *
776 - * @param array|object $field
777 - * @param string $type
778 - *
779 624 * @return array
780 625 */
781 626 public static function migrate_field_placeholder( $field, $type ) {
782 - $field = (array) $field;
627 + $field = (array) $field;
783 628 $field_options = $field['field_options'];
784 -
785 629 if ( empty( $field_options[ $type ] ) || empty( $field['default_value'] ) ) {
786 630 return array();
787 631 }
788 632
@@ -795,12 +639,10 @@
795 639 );
796 640
797 641 // If a dropdown placeholder was used, remove the option so it won't be included twice.
798 642 $options = $field['options'];
799 -
800 643 if ( $type === 'default_blank' && is_array( $options ) ) {
801 644 $default_value = $field['default_value'];
802 -
803 645 if ( is_array( $default_value ) ) {
804 646 $default_value = reset( $default_value );
805 647 }
806 648
@@ -805,9 +647,9 @@
805 647 }
806 648
807 649 foreach ( $options as $opt_key => $opt ) {
808 650 if ( is_array( $opt ) ) {
809 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
651 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
810 652 }
811 653
812 654 if ( $opt == $default_value ) {
813 655 unset( $options[ $opt_key ] );
@@ -826,13 +668,12 @@
826 668 * @since 2.0.25
827 669 *
828 670 * @param array $f
829 671 * @param array $imported
830 - *
831 - * @return void
832 672 */
833 673 private static function create_imported_field( $f, &$imported ) {
834 - $f = self::update_field_options_with_defaults( $f );
674 + $defaults = self::default_field_options( $f['type'] );
675 + $f['field_options'] = array_merge( $defaults, $f['field_options'] );
835 676
836 677 if ( is_callable( 'FrmProFileImport::import_attachment' ) ) {
837 678 $f = self::maybe_import_images_for_options( $f );
838 679 }
@@ -837,11 +678,10 @@
837 678 $f = self::maybe_import_images_for_options( $f );
838 679 }
839 680
840 681 $new_id = FrmField::create( $f );
841 -
842 682 if ( $new_id != false ) {
843 - ++$imported['imported']['fields'];
683 + $imported['imported']['fields'] ++;
844 684 do_action( 'frm_after_field_is_imported', $f, $new_id );
845 685 }
846 686 }
847 687
@@ -850,9 +690,8 @@
850 690 *
851 691 * @since 5.5.1
852 692 *
853 693 * @param array $field
854 - *
855 694 * @return array
856 695 */
857 696 private static function maybe_import_images_for_options( $field ) {
858 697 if ( empty( $field['options'] ) || ! is_array( $field['options'] ) ) {
@@ -863,15 +702,13 @@
863 702 if ( ! is_array( $option ) || empty( $option['src'] ) ) {
864 703 continue;
865 704 }
866 705
867 - $field_object = (object) $field;
868 - // Fake the file type as FrmProImport::import_attachment checks for file type.
869 - $field_object->type = 'file';
706 + $field_object = (object) $field;
707 + $field_object->type = 'file'; // Fake the file type as FrmProImport::import_attachment checks for file type.
870 708
871 709 $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'] );
710 + unset( $field['options'][ $key ]['src'] ); // Remove the src from options as it isn't required after import.
874 711
875 712 if ( is_numeric( $image_id ) ) {
876 713 $field['options'][ $key ]['image'] = $image_id;
877 714 }
@@ -883,13 +720,10 @@
883 720 /**
884 721 * Fix field ids for fields that already exist prior to import.
885 722 *
886 723 * @since 4.07
887 - *
888 - * @param int $form_id
724 + * @param int $form_id
889 725 * @param array $keys_by_original_field_id
890 - *
891 - * @return void
892 726 */
893 727 protected static function maybe_update_field_ids( $form_id, $keys_by_original_field_id ) {
894 728 global $frm_duplicate_ids;
895 729
@@ -929,10 +763,8 @@
929 763 *
930 764 * @since 2.0.19
931 765 *
932 766 * @param array $form
933 - *
934 - * @return void
935 767 */
936 768 private static function update_custom_style_setting_on_import( &$form ) {
937 769 if ( ! isset( $form['options']['custom_style'] ) ) {
938 770 return;
@@ -960,9 +792,9 @@
960 792
961 793 // Set to default
962 794 $form['options']['custom_style'] = 1;
963 795 }
964 - }//end if
796 + }
965 797 }
966 798
967 799 /**
968 800 * After styles are imported, check for any forms that were linked
@@ -968,12 +800,8 @@
968 800 * After styles are imported, check for any forms that were linked
969 801 * and link them back up.
970 802 *
971 803 * @since 2.2.7
972 - *
973 - * @param int|string $form_id
974 - *
975 - * @return void
976 804 */
977 805 private static function update_custom_style_setting_after_import( $form_id ) {
978 806 $form = FrmForm::getOne( $form_id );
979 807
@@ -982,9 +810,8 @@
982 810 $saved_style = $form['options']['custom_style'];
983 811 $form['options']['custom_style'] = $form['options']['old_style'];
984 812 self::update_custom_style_setting_on_import( $form );
985 813 $has_changed = ( $form['options']['custom_style'] != $saved_style && $form['options']['custom_style'] != $form['options']['old_style'] );
986 -
987 814 if ( $has_changed ) {
988 815 FrmForm::update( $form['id'], $form );
989 816 }
990 817 }
@@ -989,16 +816,8 @@
989 816 }
990 817 }
991 818 }
992 819
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 820 public static function import_xml_views( $views, $imported ) {
1002 821 $imported['posts'] = array();
1003 822 $form_action_type = FrmFormActionsController::$action_post_type;
1004 823
@@ -1036,13 +855,8 @@
1036 855 );
1037 856
1038 857 $post['post_content'] = self::switch_form_ids( $post['post_content'], $imported['forms'] );
1039 858
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 859 $old_id = $post['post_id'];
1046 860 self::populate_post( $post, $item, $imported );
1047 861
1048 862 unset( $item );
@@ -1047,13 +861,11 @@
1047 861
1048 862 unset( $item );
1049 863
1050 864 $post_id = false;
1051 -
1052 865 if ( $post['post_type'] === $form_action_type ) {
1053 866 $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] );
1054 -
1055 - if ( $action_control && is_object( $action_control ) && isset( $imported['form_status'] ) ) {
867 + if ( $action_control && is_object( $action_control ) ) {
1056 868 $post_id = $action_control->maybe_create_action( $post, $imported['form_status'] );
1057 869 }
1058 870 unset( $action_control );
1059 871 } elseif ( $post['post_type'] === 'frm_styles' ) {
@@ -1059,10 +871,8 @@
1059 871 } elseif ( $post['post_type'] === 'frm_styles' ) {
1060 872 // Properly encode post content before inserting the post
1061 873 $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] );
1062 874 $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 875
1066 876 // Create/update post now
1067 877 $post_id = wp_insert_post( $post );
1068 878 } else {
@@ -1072,9 +882,9 @@
1072 882 $post['post_parent'] = $imported['posts'][ $post['post_parent'] ];
1073 883 }
1074 884 // Create/update post now
1075 885 $post_id = wp_insert_post( $post );
1076 - }//end if
886 + }
1077 887
1078 888 if ( ! is_numeric( $post_id ) ) {
1079 889 continue;
1080 890 }
@@ -1086,29 +896,28 @@
1086 896 self::update_postmeta( $post, $post_id );
1087 897 self::update_layout( $post, $post_id );
1088 898
1089 899 $this_type = 'posts';
1090 -
1091 900 if ( isset( $post_types[ $post['post_type'] ] ) ) {
1092 901 $this_type = $post_types[ $post['post_type'] ];
1093 902 }
1094 903
1095 904 if ( isset( $post['ID'] ) && $post_id == $post['ID'] ) {
1096 - ++$imported['updated'][ $this_type ];
905 + $imported['updated'][ $this_type ] ++;
1097 906 } else {
1098 - ++$imported['imported'][ $this_type ];
907 + $imported['imported'][ $this_type ] ++;
1099 908 }
1100 909
1101 - $imported['posts'][ $old_id ] = $post_id;
910 + $imported['posts'][ (int) $old_id ] = $post_id;
1102 911
1103 912 if ( $post['post_type'] === 'frm_display' ) {
1104 - $view_ids[ $old_id ] = $post_id;
913 + $view_ids[ (int) $old_id ] = $post_id;
1105 914 }
1106 915
1107 916 do_action( 'frm_after_import_view', $post_id, $post );
1108 917
1109 918 unset( $post );
1110 - }//end foreach
919 + }
1111 920
1112 921 if ( $posts_with_shortcodes && $view_ids ) {
1113 922 self::maybe_switch_view_ids_after_importing_posts( $posts_with_shortcodes, $view_ids );
1114 923 }
@@ -1129,14 +938,12 @@
1129 938 /**
1130 939 * Clears styles from cache for imported forms
1131 940 *
1132 941 * @param array $imported_forms
1133 - *
1134 - * @return void
1135 942 */
1136 943 private static function clear_forms_style_caches( $imported_forms ) {
1137 944 $where = array(
1138 - 'id' => $imported_forms,
945 + 'id' => $imported_forms,
1139 946 'options LIKE' => '"old_style"',
1140 947 );
1141 948 $forms = FrmDb::get_results( 'frm_forms', $where );
1142 949
@@ -1141,13 +948,11 @@
1141 948 $forms = FrmDb::get_results( 'frm_forms', $where );
1142 949
1143 950 foreach ( $forms as $form ) {
1144 951 FrmAppHelper::unserialize_or_decode( $form->options );
1145 -
1146 952 if ( ! $form->options ) {
1147 953 continue;
1148 954 }
1149 -
1150 955 $where = array(
1151 956 'post_name' => $form->options['old_style'],
1152 957 'post_type' => FrmStylesController::$post_type,
1153 958 );
@@ -1163,9 +968,8 @@
1163 968 * Replace old form ids with new ones in a string.
1164 969 *
1165 970 * @param string $string
1166 971 * @param array<int> $form_ids new form ids indexed by old form id.
1167 - *
1168 972 * @return string
1169 973 */
1170 974 private static function switch_form_ids( $string, $form_ids ) {
1171 975 if ( false === strpos( $string, '[formidable' ) ) {
@@ -1196,15 +1000,13 @@
1196 1000
1197 1001 /**
1198 1002 * @param array<array> $posts_with_shortcodes indexed by current post id.
1199 1003 * @param array<int> $view_ids new view ids indexed by old view id.
1200 - *
1201 1004 * @return void
1202 1005 */
1203 1006 private static function maybe_switch_view_ids_after_importing_posts( $posts_with_shortcodes, $view_ids ) {
1204 1007 foreach ( $posts_with_shortcodes as $imported_post_id => $post ) {
1205 1008 $post_content = self::switch_view_ids( $post['post_content'], $view_ids );
1206 -
1207 1009 if ( $post_content === $post['post_content'] ) {
1208 1010 continue;
1209 1011 }
1210 1012
@@ -1221,9 +1023,8 @@
1221 1023 * Replace old view ids with new ones in a string.
1222 1024 *
1223 1025 * @param string $string
1224 1026 * @param array<int> $view_ids new view ids indexed by old view id.
1225 - *
1226 1027 * @return string
1227 1028 */
1228 1029 private static function switch_view_ids( $string, $view_ids ) {
1229 1030 if ( false === strpos( $string, '[display-frm-data' ) ) {
@@ -1254,14 +1055,12 @@
1254 1055 }
1255 1056
1256 1057 /**
1257 1058 * @param string $content
1258 - *
1259 1059 * @return string
1260 1060 */
1261 1061 private static function maybe_prepare_json_view_content( $content ) {
1262 1062 $maybe_decoded = FrmAppHelper::maybe_json_decode( $content );
1263 -
1264 1063 if ( is_array( $maybe_decoded ) && isset( $maybe_decoded[0] ) && isset( $maybe_decoded[0]['box'] ) ) {
1265 1064 return FrmAppHelper::prepare_and_encode( $maybe_decoded );
1266 1065 }
1267 1066 return $content;
@@ -1266,15 +1065,8 @@
1266 1065 }
1267 1066 return $content;
1268 1067 }
1269 1068
1270 - /**
1271 - * @param array $post
1272 - * @param object $item
1273 - * @param array $imported
1274 - *
1275 - * @return void
1276 - */
1277 1069 private static function populate_post( &$post, $item, $imported ) {
1278 1070 if ( isset( $item->attachment_url ) ) {
1279 1071 $post['attachment_url'] = (string) $item->attachment_url;
1280 1072 }
@@ -1316,9 +1108,9 @@
1316 1108 'key' => (string) $meta->meta_key,
1317 1109 'value' => (string) $meta->meta_value,
1318 1110 );
1319 1111
1320 - // Switch old form and field ids to new ones.
1112 + //switch old form and field ids to new ones
1321 1113 if ( 'frm_form_id' === $m['key'] && isset( $imported['forms'][ (int) $m['value'] ] ) ) {
1322 1114 $m['value'] = $imported['forms'][ (int) $m['value'] ];
1323 1115 } else {
1324 1116 $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
@@ -1334,37 +1126,10 @@
1334 1126 $m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ];
1335 1127 }
1336 1128 }
1337 1129
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 1130 $check_dup_array = array();
1365 -
1366 - if ( ! empty( $m['value']['order_by'] ) ) {
1131 + if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) {
1367 1132 if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) {
1368 1133 $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ];
1369 1134 } elseif ( is_array( $m['value']['order_by'] ) ) {
1370 1135 $check_dup_array[] = 'order_by';
@@ -1370,9 +1135,9 @@
1370 1135 $check_dup_array[] = 'order_by';
1371 1136 }
1372 1137 }
1373 1138
1374 - if ( ! empty( $m['value']['where'] ) ) {
1139 + if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) {
1375 1140 $check_dup_array[] = 'where';
1376 1141 }
1377 1142
1378 1143 foreach ( $check_dup_array as $check_k ) {
@@ -1382,11 +1147,11 @@
1382 1147 }
1383 1148 unset( $mk, $mv );
1384 1149 }
1385 1150 }
1386 - }//end if
1387 - }//end if
1388 - }//end if
1151 + }
1152 + }
1153 + }
1389 1154
1390 1155 if ( ! is_array( $m['value'] ) ) {
1391 1156 $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
1392 1157 }
@@ -1393,14 +1158,8 @@
1393 1158
1394 1159 $post['postmeta'][ (string) $meta->meta_key ] = $m['value'];
1395 1160 }
1396 1161
1397 - /**
1398 - * @param array $post
1399 - * @param object $layout
1400 - *
1401 - * @return void
1402 - */
1403 1162 private static function populate_layout( &$post, $layout ) {
1404 1163 $post['layout'][ (string) $layout->type ] = (string) $layout->data;
1405 1164 }
1406 1165
@@ -1406,25 +1165,22 @@
1406 1165
1407 1166 /**
1408 1167 * Add terms to post
1409 1168 *
1410 - * @param array $post By reference.
1411 - * @param object $item The XML object data.
1169 + * @param array $post by reference
1170 + * @param object $item The XML object data
1412 1171 */
1413 1172 private static function populate_taxonomies( &$post, $item ) {
1414 1173 foreach ( $item->category as $c ) {
1415 1174 $att = $c->attributes();
1416 -
1417 1175 if ( ! isset( $att['nicename'] ) ) {
1418 1176 continue;
1419 1177 }
1420 1178
1421 1179 $taxonomy = (string) $att['domain'];
1422 -
1423 1180 if ( is_taxonomy_hierarchical( $taxonomy ) ) {
1424 1181 $name = (string) $att['nicename'];
1425 1182 $h_term = get_term_by( 'slug', $name, $taxonomy );
1426 -
1427 1183 if ( $h_term ) {
1428 1184 $name = $h_term->term_id;
1429 1185 }
1430 1186 unset( $h_term );
@@ -1437,17 +1193,13 @@
1437 1193 }
1438 1194
1439 1195 $post['tax_input'][ $taxonomy ][] = $name;
1440 1196 unset( $name );
1441 - }//end foreach
1197 + }
1442 1198 }
1443 1199
1444 1200 /**
1445 - * Edit post if the key and created time match.
1446 - *
1447 - * @param array $post By reference.
1448 - *
1449 - * @return void
1201 + * Edit post if the key and created time match
1450 1202 */
1451 1203 private static function maybe_editing_post( &$post ) {
1452 1204 $match_by = array(
1453 1205 'post_type' => $post['post_type'],
@@ -1455,9 +1207,9 @@
1455 1207 'post_status' => $post['post_status'],
1456 1208 'posts_per_page' => 1,
1457 1209 );
1458 1210
1459 - if ( in_array( $post['post_status'], array( 'trash', 'draft' ), true ) ) {
1211 + if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) {
1460 1212 $match_by['include'] = $post['post_id'];
1461 1213 unset( $match_by['name'] );
1462 1214 }
1463 1215
@@ -1471,9 +1223,8 @@
1471 1223
1472 1224 /**
1473 1225 * @param array $post
1474 1226 * @param int $post_id
1475 - *
1476 1227 * @return void
1477 1228 */
1478 1229 private static function update_postmeta( &$post, $post_id ) {
1479 1230 foreach ( $post['postmeta'] as $k => $v ) {
@@ -1498,13 +1249,13 @@
1498 1249
1499 1250 case 'frm_param':
1500 1251 add_rewrite_endpoint( $v, EP_PERMALINK | EP_PAGES );
1501 1252 break;
1502 - }//end switch
1253 + }
1503 1254
1504 1255 update_post_meta( $post_id, $k, $v );
1505 1256 unset( $k, $v );
1506 - }//end foreach
1257 + }
1507 1258 }
1508 1259
1509 1260 /**
1510 1261 * @param array $post
@@ -1513,9 +1264,8 @@
1513 1264 private static function update_layout( &$post, $post_id ) {
1514 1265 if ( is_callable( 'FrmViewsLayout::maybe_create_layouts_for_view' ) ) {
1515 1266 $listing_layout = ! empty( $post['layout']['listing'] ) ? json_decode( $post['layout']['listing'], true ) : array();
1516 1267 $detail_layout = ! empty( $post['layout']['detail'] ) ? json_decode( $post['layout']['detail'], true ) : array();
1517 -
1518 1268 if ( $listing_layout || $detail_layout ) {
1519 1269 FrmViewsLayout::maybe_create_layouts_for_view( $post_id, $listing_layout, $detail_layout );
1520 1270 }
1521 1271 }
@@ -1520,23 +1270,16 @@
1520 1270 }
1521 1271 }
1522 1272 }
1523 1273
1524 - /**
1525 - * @param array $imported
1526 - *
1527 - * @return void
1528 - */
1529 1274 private static function maybe_update_stylesheet( $imported ) {
1530 - $new_styles = ! empty( $imported['imported']['styles'] );
1531 - $updated_styles = ! empty( $imported['updated']['styles'] );
1532 -
1275 + $new_styles = isset( $imported['imported']['styles'] ) && ! empty( $imported['imported']['styles'] );
1276 + $updated_styles = isset( $imported['updated']['styles'] ) && ! empty( $imported['updated']['styles'] );
1533 1277 if ( $new_styles || $updated_styles ) {
1534 1278 if ( is_admin() && function_exists( 'get_filesystem_method' ) ) {
1535 1279 $frm_style = new FrmStyle();
1536 1280 $frm_style->update( 'default' );
1537 1281 }
1538 -
1539 1282 foreach ( $imported['forms'] as $form_id ) {
1540 1283 self::update_custom_style_setting_after_import( $form_id );
1541 1284 }
1542 1285 }
@@ -1542,11 +1285,9 @@
1542 1285 }
1543 1286 }
1544 1287
1545 1288 /**
1546 - * @param mixed $result
1547 1289 * @param string $message
1548 - * @param array $errors
1549 1290 */
1550 1291 public static function parse_message( $result, &$message, &$errors ) {
1551 1292 if ( is_wp_error( $result ) ) {
1552 1293 $errors[] = $result->get_error_message();
@@ -1552,17 +1293,15 @@
1552 1293 $errors[] = $result->get_error_message();
1553 1294
1554 1295 // Remove the SimpleXML_parse_error from the WP_Error object to avoid
1555 1296 // displaying duplicate error messages from $result->get_error_message()
1556 - $error_codes = $result->get_error_codes();
1297 + $error_codes = $result->get_error_codes();
1557 1298 $error_details = array();
1558 -
1559 1299 foreach ( $error_codes as $error_code ) {
1560 1300 // Clone WP_Error data because WP_Error removes all error messages and data
1561 1301 // associated with the specified error code when an item is removed.
1562 1302 // Source: https://developer.wordpress.org/reference/classes/wp_error/remove/#source
1563 1303 $error_details = $result->get_error_data( $error_code );
1564 -
1565 1304 if ( $error_code === 'SimpleXML_parse_error' ) {
1566 1305 $result->remove( $error_code );
1567 1306 break;
1568 1307 }
@@ -1572,16 +1311,15 @@
1572 1311 $errors[] = '<br />' . esc_html_x( 'Error details:', 'import xml message', 'formidable' ) . '<br />' . esc_html( print_r( $error_details, 1 ) );
1573 1312 }
1574 1313
1575 1314 return;
1576 - }//end if
1577 -
1578 - if ( ! $result ) {
1315 + } elseif ( ! $result ) {
1579 1316 return;
1580 1317 }
1581 1318
1582 1319 if ( ! is_array( $result ) ) {
1583 1320 $message = is_string( $result ) ? $result : htmlentities( print_r( $result, 1 ) );
1321 +
1584 1322 return;
1585 1323 }
1586 1324
1587 1325 $t_strings = array(
@@ -1589,9 +1327,8 @@
1589 1327 'updated' => __( 'Updated', 'formidable' ),
1590 1328 );
1591 1329
1592 1330 $message = '<ul>';
1593 -
1594 1331 foreach ( $result as $type => $results ) {
1595 1332 if ( ! isset( $t_strings[ $type ] ) ) {
1596 1333 // only print imported and updated
1597 1334 continue;
@@ -1597,9 +1334,8 @@
1597 1334 continue;
1598 1335 }
1599 1336
1600 1337 $s_message = array();
1601 -
1602 1338 foreach ( $results as $k => $m ) {
1603 1339 self::item_count_message( $m, $k, $s_message );
1604 1340 unset( $k, $m );
1605 1341 }
@@ -1610,9 +1346,9 @@
1610 1346 $message .= '</li>';
1611 1347 }
1612 1348 }
1613 1349
1614 - if ( $message === '<ul>' ) {
1350 + if ( $message == '<ul>' ) {
1615 1351 $message = '';
1616 1352 $errors[] = __( 'Nothing was imported or updated', 'formidable' );
1617 1353 } else {
1618 1354 self::add_form_link_to_message( $result, $message );
@@ -1677,21 +1413,18 @@
1677 1413 /**
1678 1414 * If a single form was imported, include a link in the success message.
1679 1415 *
1680 1416 * @since 4.0
1681 - *
1682 1417 * @param array $result The response from the XML import.
1683 1418 * @param string $message The response shown on the page after import.
1684 1419 */
1685 1420 private static function add_form_link_to_message( $result, &$message ) {
1686 1421 $total_forms = $result['imported']['forms'] + $result['updated']['forms'];
1687 -
1688 1422 if ( $total_forms > 1 ) {
1689 1423 return;
1690 1424 }
1691 1425
1692 1426 $primary_form = reset( $result['forms'] );
1693 -
1694 1427 if ( ! empty( $primary_form ) ) {
1695 1428 $primary_form = FrmForm::getOne( $primary_form );
1696 1429 $form_id = empty( $primary_form->parent_form_id ) ? $primary_form->id : $primary_form->parent_form_id;
1697 1430
@@ -1711,9 +1444,8 @@
1711 1444 public static function prepare_form_options_for_export( $options ) {
1712 1445 FrmAppHelper::unserialize_or_decode( $options );
1713 1446 // Change custom_style to the post_name instead of ID (1 may be a string)
1714 1447 $not_default = isset( $options['custom_style'] ) && 1 != $options['custom_style'];
1715 -
1716 1448 if ( $not_default ) {
1717 1449 global $wpdb;
1718 1450 $table = $wpdb->prefix . 'posts';
1719 1451 $where = array( 'ID' => $options['custom_style'] );
@@ -1737,16 +1469,11 @@
1737 1469 * If the saved value is the same as the default, remove it from the export
1738 1470 * This keeps file size down and prevents overriding global settings after import
1739 1471 *
1740 1472 * @since 3.06
1741 - *
1742 - * @param array $options By reference.
1743 - *
1744 - * @return void
1745 1473 */
1746 1474 private static function remove_default_form_options( &$options ) {
1747 1475 $defaults = FrmFormsHelper::get_default_opts();
1748 -
1749 1476 if ( is_callable( 'FrmProFormsHelper::get_default_opts' ) ) {
1750 1477 $defaults += FrmProFormsHelper::get_default_opts();
1751 1478 }
1752 1479 self::remove_defaults( $defaults, $options );
@@ -1755,12 +1482,8 @@
1755 1482 /**
1756 1483 * Remove extra settings from field to keep file size down
1757 1484 *
1758 1485 * @since 3.06
1759 - *
1760 - * @param object $field
1761 - *
1762 - * @return void
1763 1486 */
1764 1487 public static function prepare_field_for_export( &$field ) {
1765 1488 self::remove_default_field_options( $field );
1766 1489 self::add_image_src_to_image_options( $field );
@@ -1769,16 +1492,11 @@
1769 1492 /**
1770 1493 * Remove defaults from field options too
1771 1494 *
1772 1495 * @since 3.06
1773 - *
1774 - * @param object $field
1775 - *
1776 - * @return void
1777 1496 */
1778 1497 private static function remove_default_field_options( &$field ) {
1779 1498 $defaults = self::default_field_options( $field->type );
1780 -
1781 1499 if ( empty( $defaults['blank'] ) ) {
1782 1500 $global_settings = new FrmSettings();
1783 1501 $global_defaults = $global_settings->default_options();
1784 1502 $defaults['blank'] = $global_defaults['blank_msg'];
@@ -1806,9 +1524,8 @@
1806 1524 *
1807 1525 * @since 5.5.1
1808 1526 *
1809 1527 * @param stdClass $field
1810 - *
1811 1528 * @return void
1812 1529 */
1813 1530 private static function add_image_src_to_image_options( $field ) {
1814 1531 if ( empty( $field->options ) || false === strpos( $field->options, 'image' ) ) {
@@ -1836,16 +1553,11 @@
1836 1553 }
1837 1554
1838 1555 /**
1839 1556 * @since 3.06.03
1840 - *
1841 - * @param string $type
1842 - *
1843 - * @return array
1844 1557 */
1845 1558 private static function default_field_options( $type ) {
1846 1559 $defaults = FrmFieldsHelper::get_default_field_options( $type );
1847 -
1848 1560 if ( empty( $defaults['custom_html'] ) ) {
1849 1561 $defaults['custom_html'] = FrmFieldsHelper::get_default_html( $type );
1850 1562 }
1851 1563 return $defaults;
@@ -1855,13 +1567,8 @@
1855 1567 * Compare the default array to the saved values and
1856 1568 * remove if they are the same
1857 1569 *
1858 1570 * @since 3.06
1859 - *
1860 - * @param array $defaults
1861 - * @param array $saved
1862 - *
1863 - * @return void
1864 1571 */
1865 1572 private static function remove_defaults( $defaults, &$saved ) {
1866 1573 foreach ( $saved as $key => $value ) {
1867 1574 if ( isset( $defaults[ $key ] ) && $defaults[ $key ] === $value ) {
@@ -1873,14 +1580,8 @@
1873 1580 /**
1874 1581 * The line endings may prevent html from being equal when it should
1875 1582 *
1876 1583 * @since 3.06
1877 - *
1878 - * @param string $html_name
1879 - * @param array $defaults
1880 - * @param array $options
1881 - *
1882 - * @return void
1883 1584 */
1884 1585 private static function remove_default_html( $html_name, $defaults, &$options ) {
1885 1586 if ( ! isset( $options[ $html_name ] ) || ! isset( $defaults[ $html_name ] ) ) {
1886 1587 return;
@@ -1887,9 +1588,8 @@
1887 1588 }
1888 1589
1889 1590 $old_html = str_replace( "\r\n", "\n", $options[ $html_name ] );
1890 1591 $default_html = $defaults[ $html_name ];
1891 -
1892 1592 if ( $old_html == $default_html ) {
1893 1593 unset( $options[ $html_name ] );
1894 1594
1895 1595 return;
@@ -1896,25 +1596,18 @@
1896 1596 }
1897 1597
1898 1598 // Account for some of the older field default HTML.
1899 1599 $default_html = str_replace( ' id="frm_desc_field_[key]"', '', $default_html );
1900 -
1901 - if ( $old_html === $default_html ) {
1600 + if ( $old_html == $default_html ) {
1902 1601 unset( $options[ $html_name ] );
1903 1602 }
1904 1603 }
1905 1604
1906 - /**
1907 - * @param string $str
1908 - *
1909 - * @return string
1910 - */
1911 1605 public static function cdata( $str ) {
1912 1606 FrmAppHelper::unserialize_or_decode( $str );
1913 -
1914 1607 if ( is_array( $str ) ) {
1915 1608 $str = json_encode( $str );
1916 - } elseif ( FrmAppHelper::is_valid_utf8( $str ) === false ) {
1609 + } elseif ( seems_utf8( $str ) === false ) {
1917 1610 $str = FrmAppHelper::maybe_utf8_encode( $str );
1918 1611 }
1919 1612
1920 1613 if ( is_numeric( $str ) ) {
@@ -1934,10 +1627,8 @@
1934 1627 *
1935 1628 * @since 2.0.22
1936 1629 *
1937 1630 * @param string $str
1938 - *
1939 - * @return void
1940 1631 */
1941 1632 private static function remove_invalid_characters_from_xml( &$str ) {
1942 1633 // Remove <US> character
1943 1634 $str = str_replace( '\x1F', '', $str );
@@ -1942,18 +1633,8 @@
1942 1633 // Remove <US> character
1943 1634 $str = str_replace( '\x1F', '', $str );
1944 1635 }
1945 1636
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 1637 public static function migrate_form_settings_to_actions( $form_options, $form_id, &$imported = array(), $switch = false ) {
1957 1638 // Get post type
1958 1639 $post_type = FrmFormActionsController::$action_post_type;
1959 1640
@@ -1971,13 +1652,9 @@
1971 1652
1972 1653 /**
1973 1654 * Migrate post settings to form action
1974 1655 *
1975 - * @param array $form_options
1976 - * @param int $form_id
1977 1656 * @param string $post_type
1978 - * @param array $imported
1979 - * @param bool $switch
1980 1657 */
1981 1658 private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
1982 1659 if ( ! isset( $form_options['create_post'] ) || ! $form_options['create_post'] ) {
1983 1660 return;
@@ -2046,9 +1723,9 @@
2046 1723
2047 1724 if ( ! $exists ) {
2048 1725 // this isn't an email, but we need to use a class that will always be included
2049 1726 FrmDb::save_json_post( $new_action );
2050 - ++$imported['imported']['actions'];
1727 + $imported['imported']['actions'] ++;
2051 1728 }
2052 1729 }
2053 1730
2054 1731 /**
@@ -2055,11 +1732,11 @@
2055 1732 * Switch old field IDs for new field IDs in emails and post
2056 1733 *
2057 1734 * @since 2.0
2058 1735 *
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.
1736 + * @param array $post_content - check for old field IDs
1737 + * @param array $basic_fields - fields with string or int saved
1738 + * @param array $array_fields - fields with arrays saved
2062 1739 *
2063 1740 * @return string $post_content - new field IDs
2064 1741 */
2065 1742 private static function switch_action_field_ids( $post_content, $basic_fields, $array_fields = array() ) {
@@ -2092,19 +1769,8 @@
2092 1769
2093 1770 return $post_content;
2094 1771 }
2095 1772
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 1773 private static function migrate_email_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
2108 1774 // No old notifications or autoresponders to carry over
2109 1775 if ( ! isset( $form_options['auto_responder'] ) && ! isset( $form_options['notification'] ) && ! isset( $form_options['email_to'] ) ) {
2110 1776 return;
@@ -2151,12 +1817,12 @@
2151 1817 );
2152 1818
2153 1819 if ( empty( $exists ) ) {
2154 1820 FrmDb::save_json_post( $new_notification );
2155 - ++$imported['imported']['actions'];
1821 + $imported['imported']['actions'] ++;
2156 1822 }
2157 1823 unset( $new_notification );
2158 - }//end foreach
1824 + }
2159 1825
2160 1826 self::remove_deprecated_notification_settings( $form_id, $form_options );
2161 1827 }
2162 1828
@@ -2165,15 +1831,12 @@
2165 1831 *
2166 1832 * @since 2.05
2167 1833 *
2168 1834 * @param int|string $form_id
2169 - * @param array $form_options
2170 - *
2171 - * @return void
1835 + * @param array $form_options
2172 1836 */
2173 1837 private static function remove_deprecated_notification_settings( $form_id, $form_options ) {
2174 1838 $delete_settings = array( 'notification', 'autoresponder', 'email_to' );
2175 -
2176 1839 foreach ( $delete_settings as $index ) {
2177 1840 if ( isset( $form_options[ $index ] ) ) {
2178 1841 unset( $form_options[ $index ] );
2179 1842 }
@@ -2180,19 +1843,10 @@
2180 1843 }
2181 1844 FrmForm::update( $form_id, array( 'options' => $form_options ) );
2182 1845 }
2183 1846
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 1847 private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) {
2194 - if ( ! isset( $form_options['notification'] ) && ! empty( $form_options['email_to'] ) ) {
1848 + if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) {
2195 1849 // add old settings into notification array
2196 1850 $form_options['notification'] = array( 0 => $form_options );
2197 1851 } elseif ( isset( $form_options['notification']['email_to'] ) ) {
2198 1852 // make sure it's in the correct format
@@ -2222,20 +1876,12 @@
2222 1876 $new_notification = array();
2223 1877 self::setup_new_notification( $new_notification, $notification, $atts );
2224 1878
2225 1879 $notifications[] = $new_notification;
2226 - }//end foreach
2227 - }//end if
1880 + }
1881 + }
2228 1882 }
2229 1883
2230 - /**
2231 - * Format email data
2232 - *
2233 - * @param array $atts
2234 - * @param array $notification
2235 - *
2236 - * @return void
2237 - */
2238 1884 private static function format_email_data( &$atts, $notification ) {
2239 1885 // Format email_to
2240 1886 self::format_email_to_data( $atts, $notification );
2241 1887
@@ -2243,13 +1889,11 @@
2243 1889 $reply_fields = array(
2244 1890 'reply_to' => '',
2245 1891 'reply_to_name' => '',
2246 1892 );
2247 -
2248 1893 foreach ( $reply_fields as $f => $val ) {
2249 1894 if ( isset( $notification[ $f ] ) ) {
2250 1895 $atts[ $f ] = $notification[ $f ];
2251 -
2252 1896 if ( 'custom' == $notification[ $f ] ) {
2253 1897 $atts[ $f ] = $notification[ 'cust_' . $f ];
2254 1898 } elseif ( is_numeric( $atts[ $f ] ) && ! empty( $atts[ $f ] ) ) {
2255 1899 $atts[ $f ] = '[' . $atts[ $f ] . ']';
@@ -2259,9 +1903,8 @@
2259 1903 }
2260 1904
2261 1905 // Format event
2262 1906 $atts['event'] = array( 'create' );
2263 -
2264 1907 if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) {
2265 1908 $atts['event'][] = 'update';
2266 1909 } elseif ( isset( $notification['update_email'] ) && 2 == $notification['update_email'] ) {
2267 1910 $atts['event'] = array( 'update' );
@@ -2267,16 +1910,8 @@
2267 1910 $atts['event'] = array( 'update' );
2268 1911 }
2269 1912 }
2270 1913
2271 - /**
2272 - * Format email_to data
2273 - *
2274 - * @param array $atts
2275 - * @param array $notification
2276 - *
2277 - * @return void
2278 - */
2279 1914 private static function format_email_to_data( &$atts, $notification ) {
2280 1915 if ( isset( $notification['email_to'] ) ) {
2281 1916 $atts['email_to'] = preg_split( '/ (,|;) /', $notification['email_to'] );
2282 1917 } else {
@@ -2296,9 +1931,8 @@
2296 1931 }
2297 1932
2298 1933 if ( strpos( $email_field, '|' ) ) {
2299 1934 $email_opt = explode( '|', $email_field );
2300 -
2301 1935 if ( isset( $email_opt[0] ) ) {
2302 1936 $atts['email_to'][ $key ] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']';
2303 1937 }
2304 1938 unset( $email_opt );
@@ -2306,17 +1940,8 @@
2306 1940 }
2307 1941 $atts['email_to'] = implode( ', ', $atts['email_to'] );
2308 1942 }
2309 1943
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 1944 private static function setup_new_notification( &$new_notification, $notification, $atts ) {
2320 1945 // Set up new notification
2321 1946 $new_notification = array(
2322 1947 'post_content' => array(
@@ -2327,9 +1952,8 @@
2327 1952 );
2328 1953
2329 1954 // Add more fields to the new notification
2330 1955 $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' );
2331 -
2332 1956 foreach ( $add_fields as $add_field ) {
2333 1957 if ( isset( $notification[ $add_field ] ) ) {
2334 1958 $new_notification['post_content'][ $add_field ] = $notification[ $add_field ];
2335 1959 } elseif ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) {
@@ -2351,11 +1975,9 @@
2351 1975
2352 1976 /**
2353 1977 * Switch field IDs in pre-2.0 email conditional logic
2354 1978 *
2355 - * @param array $post_content Pass by reference.
2356 - *
2357 - * @return void
1979 + * @param $post_content array, pass by reference
2358 1980 */
2359 1981 private static function switch_email_condition_field_ids( &$post_content ) {
2360 1982 // Switch field IDs in conditional logic
2361 1983 if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) {
@@ -2367,32 +1989,20 @@
2367 1989 }
2368 1990 }
2369 1991 }
2370 1992
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 1993 private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) {
2381 1994 if ( isset( $form_options['auto_responder'] ) && $form_options['auto_responder'] && isset( $form_options['ar_email_message'] ) && $form_options['ar_email_message'] ) {
2382 1995 // migrate autoresponder
2383 1996
2384 - $email_field = $form_options['ar_email_to'] ?? 0;
2385 -
1997 + $email_field = isset( $form_options['ar_email_to'] ) ? $form_options['ar_email_to'] : 0;
2386 1998 if ( strpos( $email_field, '|' ) ) {
2387 1999 // data from entries field
2388 2000 $email_field = explode( '|', $email_field );
2389 -
2390 2001 if ( isset( $email_field[1] ) ) {
2391 2002 $email_field = $email_field[1];
2392 2003 }
2393 2004 }
2394 -
2395 2005 if ( is_numeric( $email_field ) && ! empty( $email_field ) ) {
2396 2006 $email_field = '[' . $email_field . ']';
2397 2007 }
2398 2008
@@ -2399,18 +2009,18 @@
2399 2009 $notification = $form_options;
2400 2010 $new_notification2 = array(
2401 2011 'post_content' => array(
2402 2012 'email_message' => $notification['ar_email_message'],
2403 - 'email_subject' => $notification['ar_email_subject'] ?? '',
2013 + 'email_subject' => isset( $notification['ar_email_subject'] ) ? $notification['ar_email_subject'] : '',
2404 2014 'email_to' => $email_field,
2405 - 'plain_text' => $notification['ar_plain_text'] ?? 0,
2015 + 'plain_text' => isset( $notification['ar_plain_text'] ) ? $notification['ar_plain_text'] : 0,
2406 2016 'inc_user_info' => 0,
2407 2017 ),
2408 2018 'post_name' => $form_id . '_email_' . count( $notifications ),
2409 2019 );
2410 2020
2411 - $reply_to = $notification['ar_reply_to'] ?? '';
2412 - $reply_to_name = $notification['ar_reply_to_name'] ?? '';
2021 + $reply_to = isset( $notification['ar_reply_to'] ) ? $notification['ar_reply_to'] : '';
2022 + $reply_to_name = isset( $notification['ar_reply_to_name'] ) ? $notification['ar_reply_to_name'] : '';
2413 2023
2414 2024 if ( ! empty( $reply_to ) ) {
2415 2025 $new_notification2['post_content']['reply_to'] = $reply_to;
2416 2026 }
@@ -2420,17 +2030,17 @@
2420 2030 }
2421 2031
2422 2032 $notifications[] = $new_notification2;
2423 2033 unset( $new_notification2 );
2424 - }//end if
2034 + }
2425 2035 }
2426 2036
2427 2037 /**
2428 2038 * PHP 8 backward compatibility for the libxml_disable_entity_loader function
2429 2039 *
2430 - * @param bool $loader
2040 + * @param boolean $disable
2431 2041 *
2432 - * @return bool
2042 + * @return boolean
2433 2043 */
2434 2044 public static function maybe_libxml_disable_entity_loader( $loader ) {
2435 2045 if ( version_compare( phpversion(), '8.0', '<' ) && function_exists( 'libxml_disable_entity_loader' ) ) {
2436 2046 $loader = libxml_disable_entity_loader( $loader ); // phpcs:disable Generic.PHP.DeprecatedFunctions.Deprecated
@@ -2438,31 +2048,9 @@
2438 2048
2439 2049 return $loader;
2440 2050 }
2441 2051
2442 - /**
2443 - * PHP 8 backward compatibility for the libxml_disable_entity_loader function
2444 - *
2445 - * @return bool
2446 - */
2447 2052 public static function check_if_libxml_disable_entity_loader_exists() {
2448 2053 return version_compare( phpversion(), '8.0', '<' ) && ! function_exists( 'libxml_disable_entity_loader' );
2449 2054 }
2055 +}
2450 2056
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 -}