PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.5.4
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.5.4
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 +99 -590 6.26 → 5.5.4 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,15 @@
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 39 $dom = new DOMDocument();
61 -
62 40 // LIBXML_COMPACT activates small nodes allocation optimization.
63 41 // 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 -
42 + $success = $dom->loadXML( file_get_contents( $file ), LIBXML_COMPACT | LIBXML_PARSEHUGE );
66 43 if ( ! $success ) {
67 44 return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
68 45 }
69 46
@@ -82,37 +59,8 @@
82 59 return self::import_xml_now( $xml );
83 60 }
84 61
85 62 /**
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 63 * Add terms, forms (form and field ids), posts (post ids), and entries to db, in that order
116 64 *
117 65 * @since 3.06
118 66 *
@@ -117,9 +65,8 @@
117 65 * @since 3.06
118 66 *
119 67 * @param object $xml
120 68 * @param bool $installing_template
121 - *
122 69 * @return array The number of items imported
123 70 */
124 71 public static function import_xml_now( $xml, $installing_template = false ) {
125 72 if ( ! defined( 'WP_IMPORTING' ) ) {
@@ -139,9 +86,9 @@
139 86 }
140 87
141 88 $imported = apply_filters( 'frm_importing_xml', $imported, $xml );
142 89
143 - if ( empty( $imported['form_status'] ) ) {
90 + if ( ! isset( $imported['form_status'] ) || empty( $imported['form_status'] ) ) {
144 91 // Check for an error message in the XML.
145 92 if ( isset( $xml->Code ) && isset( $xml->Message ) ) { // phpcs:ignore WordPress.NamingConventions
146 93 $imported['error'] = (string) $xml->Message; // phpcs:ignore WordPress.NamingConventions
147 94 }
@@ -151,9 +98,8 @@
151 98 }
152 99
153 100 /**
154 101 * @since 3.06
155 - *
156 102 * @return array
157 103 */
158 104 private static function pre_import_data() {
159 105 $defaults = array(
@@ -173,14 +119,8 @@
173 119 'terms' => array(),
174 120 );
175 121 }
176 122
177 - /**
178 - * @param SimpleXMLElement $terms
179 - * @param array $imported
180 - *
181 - * @return array
182 - */
183 123 public static function import_xml_terms( $terms, $imported ) {
184 124 foreach ( $terms as $t ) {
185 125 if ( term_exists( (string) $t->term_slug, (string) $t->term_taxonomy ) ) {
186 126 continue;
@@ -198,14 +138,14 @@
198 138 )
199 139 );
200 140
201 141 if ( $term && is_array( $term ) ) {
202 - ++$imported['imported']['terms'];
142 + $imported['imported']['terms'] ++;
203 143 $imported['terms'][ (int) $t->term_id ] = $term['term_id'];
204 144 }
205 145
206 146 unset( $term, $t );
207 - }//end foreach
147 + }
208 148
209 149 return $imported;
210 150 }
211 151
@@ -210,19 +150,13 @@
210 150 }
211 151
212 152 /**
213 153 * @since 2.0.8
214 - *
215 - * @param object $t
216 - *
217 - * @return int|string
218 154 */
219 155 private static function get_term_parent_id( $t ) {
220 156 $parent = (string) $t->term_parent;
221 -
222 157 if ( ! empty( $parent ) ) {
223 158 $parent = term_exists( (string) $t->term_parent, (string) $t->term_taxonomy );
224 -
225 159 if ( $parent ) {
226 160 $parent = $parent['term_id'];
227 161 } else {
228 162 $parent = 0;
@@ -231,14 +165,8 @@
231 165
232 166 return $parent;
233 167 }
234 168
235 - /**
236 - * @param SimpleXMLElement $forms
237 - * @param array $imported
238 - *
239 - * @return array
240 - */
241 169 public static function import_xml_forms( $forms, $imported ) {
242 170 $child_forms = array();
243 171
244 172 // Import child forms first
@@ -252,9 +180,8 @@
252 180 $this_form = self::maybe_get_form( $form );
253 181
254 182 $old_id = false;
255 183 $form_fields = false;
256 -
257 184 if ( ! empty( $this_form ) ) {
258 185 $form_id = $this_form->id;
259 186 $old_id = $this_form->id;
260 187 self::update_form( $this_form, $form, $imported );
@@ -261,13 +188,12 @@
261 188
262 189 $form_fields = self::get_form_fields( $form_id );
263 190 } else {
264 191 $form_id = FrmForm::create( $form );
265 -
266 192 if ( $form_id ) {
267 193 if ( empty( $form['parent_form_id'] ) ) {
268 194 // Don't include the repeater form in the imported count.
269 - ++$imported['imported']['forms'];
195 + $imported['imported']['forms'] ++;
270 196 }
271 197
272 198 // Keep track of whether this specific form was updated or not.
273 199 $imported['form_status'][ $form_id ] = 'imported';
@@ -292,9 +218,9 @@
292 218
293 219 do_action( 'frm_after_import_form', $form_id, $form );
294 220
295 221 unset( $form, $item );
296 - }//end foreach
222 + }
297 223
298 224 self::maybe_update_child_form_parent_id( $imported['forms'], $child_forms );
299 225
300 226 return $imported;
@@ -299,13 +225,8 @@
299 225
300 226 return $imported;
301 227 }
302 228
303 - /**
304 - * @param object $item
305 - *
306 - * @return array
307 - */
308 229 private static function fill_form( $item ) {
309 230 $form = array(
310 231 'id' => (int) $item->id,
311 232 'form_key' => (string) $item->form_key,
@@ -333,13 +254,8 @@
333 254
334 255 return $form;
335 256 }
336 257
337 - /**
338 - * @param array $form
339 - *
340 - * @return false|object
341 - */
342 258 private static function maybe_get_form( $form ) {
343 259 // if template, allow to edit if form keys match, otherwise, creation date must also match
344 260 $edit_query = array(
345 261 'form_key' => $form['form_key'],
@@ -344,9 +260,8 @@
344 260 $edit_query = array(
345 261 'form_key' => $form['form_key'],
346 262 'is_template' => $form['is_template'],
347 263 );
348 -
349 264 if ( ! $form['is_template'] ) {
350 265 $edit_query['created_at'] = $form['created_at'];
351 266 }
352 267
@@ -351,32 +266,17 @@
351 266 }
352 267
353 268 $edit_query = apply_filters( 'frm_match_xml_form', $edit_query, $form );
354 269
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;
270 + return FrmForm::getAll( $edit_query, '', 1 );
363 271 }
364 272
365 - /**
366 - * @param object $this_form
367 - * @param array $form
368 - * @param array $imported
369 - *
370 - * @return void
371 - */
372 273 private static function update_form( $this_form, $form, &$imported ) {
373 274 $form_id = $this_form->id;
374 275 FrmForm::update( $form_id, $form );
375 -
376 276 if ( empty( $form['parent_form_id'] ) ) {
377 277 // Don't include the repeater form in the updated count.
378 - ++$imported['updated']['forms'];
278 + $imported['updated']['forms'] ++;
379 279 }
380 280
381 281 // Keep track of whether this specific form was updated or not
382 282 $imported['form_status'][ $form_id ] = 'updated';
@@ -381,23 +281,16 @@
381 281 // Keep track of whether this specific form was updated or not
382 282 $imported['form_status'][ $form_id ] = 'updated';
383 283 }
384 284
385 - /**
386 - * @param int|string $form_id
387 - *
388 - * @return array
389 - */
390 285 private static function get_form_fields( $form_id ) {
391 286 $form_fields = FrmField::get_all_for_form( $form_id, '', 'exclude', 'exclude' );
392 287 $old_fields = array();
393 -
394 288 foreach ( $form_fields as $f ) {
395 289 $old_fields[ $f->id ] = $f;
396 290 $old_fields[ $f->field_key ] = $f->id;
397 291 unset( $f );
398 292 }
399 -
400 293 $form_fields = $old_fields;
401 294
402 295 return $form_fields;
403 296 }
@@ -403,12 +296,8 @@
403 296 }
404 297
405 298 /**
406 299 * 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 300 */
412 301 private static function delete_removed_fields( $form_fields ) {
413 302 if ( ! empty( $form_fields ) ) {
414 303 foreach ( $form_fields as $field ) {
@@ -448,10 +337,10 @@
448 337 * Keep track of all imported child forms
449 338 *
450 339 * @since 2.0.16
451 340 *
452 - * @param int $form_id
453 - * @param int $parent_form_id
341 + * @param int $form_id
342 + * @param int $parent_form_id
454 343 * @param array $child_forms
455 344 */
456 345 private static function track_imported_child_forms( $form_id, $parent_form_id, &$child_forms ) {
457 346 if ( $parent_form_id ) {
@@ -484,14 +373,8 @@
484 373 *
485 374 * @since 2.0.13
486 375 *
487 376 * 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 377 */
495 378 private static function import_xml_fields( $xml_fields, $form_id, $this_form, &$form_fields, &$imported ) {
496 379 $in_section = 0;
497 380 $keys_by_original_field_id = array();
@@ -509,13 +392,13 @@
509 392 if ( ! empty( $this_form ) ) {
510 393 // check for field to edit by field id
511 394 if ( isset( $form_fields[ $f['id'] ] ) ) {
512 395 FrmField::update( $f['id'], $f );
513 - ++$imported['updated']['fields'];
396 + $imported['updated']['fields'] ++;
514 397
515 398 unset( $form_fields[ $f['id'] ] );
516 399
517 - // Unset old field key.
400 + //unset old field key
518 401 if ( isset( $form_fields[ $f['field_key'] ] ) ) {
519 402 unset( $form_fields[ $f['field_key'] ] );
520 403 }
521 404 } elseif ( isset( $form_fields[ $f['field_key'] ] ) ) {
@@ -520,32 +403,25 @@
520 403 }
521 404 } elseif ( isset( $form_fields[ $f['field_key'] ] ) ) {
522 405 $keys_by_original_field_id[ $f['id'] ] = $f['field_key'];
523 406
524 - $old_field_id = $f['id'];
525 -
526 407 // check for field to edit by field key
527 408 unset( $f['id'] );
528 409
529 410 FrmField::update( $form_fields[ $f['field_key'] ], $f );
530 - ++$imported['updated']['fields'];
411 + $imported['updated']['fields'] ++;
531 412
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'] ] );
413 + unset( $form_fields[ $form_fields[ $f['field_key'] ] ] ); //unset old field id
414 + unset( $form_fields[ $f['field_key'] ] ); //unset old field key
539 415 } else {
540 - // If no matching field id or key in this form, create the field.
416 + // if no matching field id or key in this form, create the field
541 417 self::create_imported_field( $f, $imported );
542 - }//end if
418 + }
543 419 } else {
544 420
545 421 self::create_imported_field( $f, $imported );
546 - }//end if
547 - }//end foreach
422 + }
423 + }
548 424
549 425 if ( $keys_by_original_field_id ) {
550 426 self::maybe_update_field_ids( $form_id, $keys_by_original_field_id );
551 427 }
@@ -550,53 +426,8 @@
550 426 self::maybe_update_field_ids( $form_id, $keys_by_original_field_id );
551 427 }
552 428 }
553 429
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 430 private static function fill_field( $field, $form_id ) {
600 431 return array(
601 432 'id' => (int) $field->id,
602 433 'field_key' => (string) $field->field_key,
@@ -613,12 +444,8 @@
613 444 }
614 445
615 446 /**
616 447 * @since 4.06
617 - *
618 - * @param array $f
619 - *
620 - * @return void
621 448 */
622 449 private static function set_default_value( &$f ) {
623 450 $has_default = array(
624 451 'text',
@@ -645,12 +472,8 @@
645 472 /**
646 473 * Make sure the required indicator is set.
647 474 *
648 475 * @since 4.05
649 - *
650 - * @param array $f
651 - *
652 - * @return void
653 476 */
654 477 private static function maybe_add_required( &$f ) {
655 478 if ( $f['required'] && ! isset( $f['field_options']['required_indicator'] ) ) {
656 479 $f['field_options']['required_indicator'] = '*';
@@ -660,13 +483,10 @@
660 483 /**
661 484 * Update the current in_section value at the beginning of the field loop
662 485 *
663 486 * @since 2.0.25
664 - *
665 - * @param int $in_section
487 + * @param int $in_section
666 488 * @param array $f
667 - *
668 - * @return void
669 489 */
670 490 private static function maybe_update_in_section_variable( &$in_section, &$f ) {
671 491 // If we're at the end of a section, switch $in_section is 0
672 492 if ( in_array( $f['type'], array( 'end_divider', 'break', 'form' ) ) ) {
@@ -678,9 +498,9 @@
678 498 $f['field_options']['in_section'] = $in_section;
679 499 }
680 500
681 501 // If we're starting a new section, switch $in_section to ID of divider
682 - if ( $f['type'] === 'divider' ) {
502 + if ( $f['type'] == 'divider' ) {
683 503 $in_section = $f['id'];
684 504 }
685 505 }
686 506
@@ -696,12 +516,11 @@
696 516 if ( ! isset( $imported['forms'] ) ) {
697 517 return;
698 518 }
699 519
700 - if ( $f['type'] === 'form' || ( $f['type'] === 'divider' && FrmField::is_option_true( $f['field_options'], 'repeat' ) ) ) {
520 + if ( $f['type'] == 'form' || ( $f['type'] == 'divider' && FrmField::is_option_true( $f['field_options'], 'repeat' ) ) ) {
701 521 if ( FrmField::is_option_true( $f['field_options'], 'form_select' ) ) {
702 522 $form_select = (int) $f['field_options']['form_select'];
703 -
704 523 if ( isset( $imported['forms'][ $form_select ] ) ) {
705 524 $f['field_options']['form_select'] = $imported['forms'][ $form_select ];
706 525 }
707 526 }
@@ -714,10 +533,8 @@
714 533 * @since 2.01.0
715 534 *
716 535 * @param array $imported
717 536 * @param array $f
718 - *
719 - * @return void
720 537 */
721 538 private static function maybe_update_get_values_form_setting( $imported, &$f ) {
722 539 if ( ! isset( $imported['forms'] ) ) {
723 540 return;
@@ -724,9 +541,8 @@
724 541 }
725 542
726 543 if ( FrmField::is_option_true_in_array( $f['field_options'], 'get_values_form' ) ) {
727 544 $old_form = $f['field_options']['get_values_form'];
728 -
729 545 if ( isset( $imported['forms'][ $old_form ] ) ) {
730 546 $f['field_options']['get_values_form'] = $imported['forms'][ $old_form ];
731 547 }
732 548 }
@@ -735,12 +551,8 @@
735 551 /**
736 552 * If field settings have been migrated, update the values during import.
737 553 *
738 554 * @since 4.0
739 - *
740 - * @param array $f
741 - *
742 - * @return void
743 555 */
744 556 private static function run_field_migrations( &$f ) {
745 557 self::migrate_placeholders( $f );
746 558 $f = apply_filters( 'frm_import_xml_field', $f );
@@ -747,22 +559,16 @@
747 559 }
748 560
749 561 /**
750 562 * @since 4.0
751 - *
752 - * @param array $f
753 - *
754 - * @return void
755 563 */
756 564 private static function migrate_placeholders( &$f ) {
757 565 $update_values = self::migrate_field_placeholder( $f, 'clear_on_focus' );
758 -
759 566 foreach ( $update_values as $k => $v ) {
760 567 $f[ $k ] = $v;
761 568 }
762 569
763 570 $update_values = self::migrate_field_placeholder( $f, 'default_blank' );
764 -
765 571 foreach ( $update_values as $k => $v ) {
766 572 $f[ $k ] = $v;
767 573 }
768 574 }
@@ -771,18 +577,13 @@
771 577 * Move clear_on_focus or default_blank to placeholder.
772 578 * Also called during database migration in FrmMigrate.
773 579 *
774 580 * @since 4.0
775 - *
776 - * @param array|object $field
777 - * @param string $type
778 - *
779 581 * @return array
780 582 */
781 583 public static function migrate_field_placeholder( $field, $type ) {
782 - $field = (array) $field;
584 + $field = (array) $field;
783 585 $field_options = $field['field_options'];
784 -
785 586 if ( empty( $field_options[ $type ] ) || empty( $field['default_value'] ) ) {
786 587 return array();
787 588 }
788 589
@@ -795,12 +596,10 @@
795 596 );
796 597
797 598 // If a dropdown placeholder was used, remove the option so it won't be included twice.
798 599 $options = $field['options'];
799 -
800 600 if ( $type === 'default_blank' && is_array( $options ) ) {
801 601 $default_value = $field['default_value'];
802 -
803 602 if ( is_array( $default_value ) ) {
804 603 $default_value = reset( $default_value );
805 604 }
806 605
@@ -805,9 +604,9 @@
805 604 }
806 605
807 606 foreach ( $options as $opt_key => $opt ) {
808 607 if ( is_array( $opt ) ) {
809 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
608 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
810 609 }
811 610
812 611 if ( $opt == $default_value ) {
813 612 unset( $options[ $opt_key ] );
@@ -826,13 +625,12 @@
826 625 * @since 2.0.25
827 626 *
828 627 * @param array $f
829 628 * @param array $imported
830 - *
831 - * @return void
832 629 */
833 630 private static function create_imported_field( $f, &$imported ) {
834 - $f = self::update_field_options_with_defaults( $f );
631 + $defaults = self::default_field_options( $f['type'] );
632 + $f['field_options'] = array_merge( $defaults, $f['field_options'] );
835 633
836 634 if ( is_callable( 'FrmProFileImport::import_attachment' ) ) {
837 635 $f = self::maybe_import_images_for_options( $f );
838 636 }
@@ -837,11 +635,10 @@
837 635 $f = self::maybe_import_images_for_options( $f );
838 636 }
839 637
840 638 $new_id = FrmField::create( $f );
841 -
842 639 if ( $new_id != false ) {
843 - ++$imported['imported']['fields'];
640 + $imported['imported']['fields'] ++;
844 641 do_action( 'frm_after_field_is_imported', $f, $new_id );
845 642 }
846 643 }
847 644
@@ -850,9 +647,8 @@
850 647 *
851 648 * @since 5.5.1
852 649 *
853 650 * @param array $field
854 - *
855 651 * @return array
856 652 */
857 653 private static function maybe_import_images_for_options( $field ) {
858 654 if ( empty( $field['options'] ) || ! is_array( $field['options'] ) ) {
@@ -863,15 +659,13 @@
863 659 if ( ! is_array( $option ) || empty( $option['src'] ) ) {
864 660 continue;
865 661 }
866 662
867 - $field_object = (object) $field;
868 - // Fake the file type as FrmProImport::import_attachment checks for file type.
869 - $field_object->type = 'file';
663 + $field_object = (object) $field;
664 + $field_object->type = 'file'; // Fake the file type as FrmProImport::import_attachment checks for file type.
870 665
871 666 $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'] );
667 + unset( $field['options'][ $key ]['src'] ); // Remove the src from options as it isn't required after import.
874 668
875 669 if ( is_numeric( $image_id ) ) {
876 670 $field['options'][ $key ]['image'] = $image_id;
877 671 }
@@ -883,13 +677,10 @@
883 677 /**
884 678 * Fix field ids for fields that already exist prior to import.
885 679 *
886 680 * @since 4.07
887 - *
888 - * @param int $form_id
681 + * @param int $form_id
889 682 * @param array $keys_by_original_field_id
890 - *
891 - * @return void
892 683 */
893 684 protected static function maybe_update_field_ids( $form_id, $keys_by_original_field_id ) {
894 685 global $frm_duplicate_ids;
895 686
@@ -929,10 +720,8 @@
929 720 *
930 721 * @since 2.0.19
931 722 *
932 723 * @param array $form
933 - *
934 - * @return void
935 724 */
936 725 private static function update_custom_style_setting_on_import( &$form ) {
937 726 if ( ! isset( $form['options']['custom_style'] ) ) {
938 727 return;
@@ -937,9 +726,9 @@
937 726 if ( ! isset( $form['options']['custom_style'] ) ) {
938 727 return;
939 728 }
940 729
941 - if ( is_numeric( $form['options']['custom_style'] ) && 1 === intval( $form['options']['custom_style'] ) ) {
730 + if ( is_numeric( $form['options']['custom_style'] ) ) {
942 731 // Set to default
943 732 $form['options']['custom_style'] = 1;
944 733 } else {
945 734 // Replace the style name with the style ID on import
@@ -960,9 +749,9 @@
960 749
961 750 // Set to default
962 751 $form['options']['custom_style'] = 1;
963 752 }
964 - }//end if
753 + }
965 754 }
966 755
967 756 /**
968 757 * After styles are imported, check for any forms that were linked
@@ -968,12 +757,8 @@
968 757 * After styles are imported, check for any forms that were linked
969 758 * and link them back up.
970 759 *
971 760 * @since 2.2.7
972 - *
973 - * @param int|string $form_id
974 - *
975 - * @return void
976 761 */
977 762 private static function update_custom_style_setting_after_import( $form_id ) {
978 763 $form = FrmForm::getOne( $form_id );
979 764
@@ -982,9 +767,8 @@
982 767 $saved_style = $form['options']['custom_style'];
983 768 $form['options']['custom_style'] = $form['options']['old_style'];
984 769 self::update_custom_style_setting_on_import( $form );
985 770 $has_changed = ( $form['options']['custom_style'] != $saved_style && $form['options']['custom_style'] != $form['options']['old_style'] );
986 -
987 771 if ( $has_changed ) {
988 772 FrmForm::update( $form['id'], $form );
989 773 }
990 774 }
@@ -989,16 +773,8 @@
989 773 }
990 774 }
991 775 }
992 776
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 777 public static function import_xml_views( $views, $imported ) {
1002 778 $imported['posts'] = array();
1003 779 $form_action_type = FrmFormActionsController::$action_post_type;
1004 780
@@ -1036,13 +812,8 @@
1036 812 );
1037 813
1038 814 $post['post_content'] = self::switch_form_ids( $post['post_content'], $imported['forms'] );
1039 815
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 816 $old_id = $post['post_id'];
1046 817 self::populate_post( $post, $item, $imported );
1047 818
1048 819 unset( $item );
@@ -1047,13 +818,11 @@
1047 818
1048 819 unset( $item );
1049 820
1050 821 $post_id = false;
1051 -
1052 822 if ( $post['post_type'] === $form_action_type ) {
1053 823 $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] );
1054 -
1055 - if ( $action_control && is_object( $action_control ) && isset( $imported['form_status'] ) ) {
824 + if ( $action_control && is_object( $action_control ) ) {
1056 825 $post_id = $action_control->maybe_create_action( $post, $imported['form_status'] );
1057 826 }
1058 827 unset( $action_control );
1059 828 } elseif ( $post['post_type'] === 'frm_styles' ) {
@@ -1058,14 +827,14 @@
1058 827 unset( $action_control );
1059 828 } elseif ( $post['post_type'] === 'frm_styles' ) {
1060 829 // Properly encode post content before inserting the post
1061 830 $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] );
831 + $custom_css = isset( $post['post_content']['custom_css'] ) ? $post['post_content']['custom_css'] : '';
1062 832 $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 833
1066 834 // Create/update post now
1067 835 $post_id = wp_insert_post( $post );
836 + self::maybe_update_custom_css( $custom_css );
1068 837 } else {
1069 838 if ( $post['post_type'] === 'frm_display' ) {
1070 839 $post['post_content'] = self::maybe_prepare_json_view_content( $post['post_content'] );
1071 840 } elseif ( 'page' === $post['post_type'] && isset( $imported['posts'][ $post['post_parent'] ] ) ) {
@@ -1072,9 +841,9 @@
1072 841 $post['post_parent'] = $imported['posts'][ $post['post_parent'] ];
1073 842 }
1074 843 // Create/update post now
1075 844 $post_id = wp_insert_post( $post );
1076 - }//end if
845 + }
1077 846
1078 847 if ( ! is_numeric( $post_id ) ) {
1079 848 continue;
1080 849 }
@@ -1086,29 +855,28 @@
1086 855 self::update_postmeta( $post, $post_id );
1087 856 self::update_layout( $post, $post_id );
1088 857
1089 858 $this_type = 'posts';
1090 -
1091 859 if ( isset( $post_types[ $post['post_type'] ] ) ) {
1092 860 $this_type = $post_types[ $post['post_type'] ];
1093 861 }
1094 862
1095 863 if ( isset( $post['ID'] ) && $post_id == $post['ID'] ) {
1096 - ++$imported['updated'][ $this_type ];
864 + $imported['updated'][ $this_type ] ++;
1097 865 } else {
1098 - ++$imported['imported'][ $this_type ];
866 + $imported['imported'][ $this_type ] ++;
1099 867 }
1100 868
1101 - $imported['posts'][ $old_id ] = $post_id;
869 + $imported['posts'][ (int) $old_id ] = $post_id;
1102 870
1103 871 if ( $post['post_type'] === 'frm_display' ) {
1104 - $view_ids[ $old_id ] = $post_id;
872 + $view_ids[ (int) $old_id ] = $post_id;
1105 873 }
1106 874
1107 875 do_action( 'frm_after_import_view', $post_id, $post );
1108 876
1109 877 unset( $post );
1110 - }//end foreach
878 + }
1111 879
1112 880 if ( $posts_with_shortcodes && $view_ids ) {
1113 881 self::maybe_switch_view_ids_after_importing_posts( $posts_with_shortcodes, $view_ids );
1114 882 }
@@ -1113,13 +881,8 @@
1113 881 self::maybe_switch_view_ids_after_importing_posts( $posts_with_shortcodes, $view_ids );
1114 882 }
1115 883 unset( $posts_with_shortcodes, $view_ids );
1116 884
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 885 self::maybe_update_stylesheet( $imported );
1123 886
1124 887 flush_rewrite_rules();
1125 888
@@ -1126,46 +889,12 @@
1126 889 return $imported;
1127 890 }
1128 891
1129 892 /**
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 893 * Replace old form ids with new ones in a string.
1164 894 *
1165 895 * @param string $string
1166 896 * @param array<int> $form_ids new form ids indexed by old form id.
1167 - *
1168 897 * @return string
1169 898 */
1170 899 private static function switch_form_ids( $string, $form_ids ) {
1171 900 if ( false === strpos( $string, '[formidable' ) ) {
@@ -1196,15 +925,13 @@
1196 925
1197 926 /**
1198 927 * @param array<array> $posts_with_shortcodes indexed by current post id.
1199 928 * @param array<int> $view_ids new view ids indexed by old view id.
1200 - *
1201 929 * @return void
1202 930 */
1203 931 private static function maybe_switch_view_ids_after_importing_posts( $posts_with_shortcodes, $view_ids ) {
1204 932 foreach ( $posts_with_shortcodes as $imported_post_id => $post ) {
1205 933 $post_content = self::switch_view_ids( $post['post_content'], $view_ids );
1206 -
1207 934 if ( $post_content === $post['post_content'] ) {
1208 935 continue;
1209 936 }
1210 937
@@ -1221,9 +948,8 @@
1221 948 * Replace old view ids with new ones in a string.
1222 949 *
1223 950 * @param string $string
1224 951 * @param array<int> $view_ids new view ids indexed by old view id.
1225 - *
1226 952 * @return string
1227 953 */
1228 954 private static function switch_view_ids( $string, $view_ids ) {
1229 955 if ( false === strpos( $string, '[display-frm-data' ) ) {
@@ -1254,14 +980,12 @@
1254 980 }
1255 981
1256 982 /**
1257 983 * @param string $content
1258 - *
1259 984 * @return string
1260 985 */
1261 986 private static function maybe_prepare_json_view_content( $content ) {
1262 987 $maybe_decoded = FrmAppHelper::maybe_json_decode( $content );
1263 -
1264 988 if ( is_array( $maybe_decoded ) && isset( $maybe_decoded[0] ) && isset( $maybe_decoded[0]['box'] ) ) {
1265 989 return FrmAppHelper::prepare_and_encode( $maybe_decoded );
1266 990 }
1267 991 return $content;
@@ -1266,15 +990,8 @@
1266 990 }
1267 991 return $content;
1268 992 }
1269 993
1270 - /**
1271 - * @param array $post
1272 - * @param object $item
1273 - * @param array $imported
1274 - *
1275 - * @return void
1276 - */
1277 994 private static function populate_post( &$post, $item, $imported ) {
1278 995 if ( isset( $item->attachment_url ) ) {
1279 996 $post['attachment_url'] = (string) $item->attachment_url;
1280 997 }
@@ -1316,9 +1033,9 @@
1316 1033 'key' => (string) $meta->meta_key,
1317 1034 'value' => (string) $meta->meta_value,
1318 1035 );
1319 1036
1320 - // Switch old form and field ids to new ones.
1037 + //switch old form and field ids to new ones
1321 1038 if ( 'frm_form_id' === $m['key'] && isset( $imported['forms'][ (int) $m['value'] ] ) ) {
1322 1039 $m['value'] = $imported['forms'][ (int) $m['value'] ];
1323 1040 } else {
1324 1041 $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
@@ -1334,37 +1051,10 @@
1334 1051 $m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ];
1335 1052 }
1336 1053 }
1337 1054
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 1055 $check_dup_array = array();
1365 -
1366 - if ( ! empty( $m['value']['order_by'] ) ) {
1056 + if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) {
1367 1057 if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) {
1368 1058 $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ];
1369 1059 } elseif ( is_array( $m['value']['order_by'] ) ) {
1370 1060 $check_dup_array[] = 'order_by';
@@ -1370,9 +1060,9 @@
1370 1060 $check_dup_array[] = 'order_by';
1371 1061 }
1372 1062 }
1373 1063
1374 - if ( ! empty( $m['value']['where'] ) ) {
1064 + if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) {
1375 1065 $check_dup_array[] = 'where';
1376 1066 }
1377 1067
1378 1068 foreach ( $check_dup_array as $check_k ) {
@@ -1382,11 +1072,11 @@
1382 1072 }
1383 1073 unset( $mk, $mv );
1384 1074 }
1385 1075 }
1386 - }//end if
1387 - }//end if
1388 - }//end if
1076 + }
1077 + }
1078 + }
1389 1079
1390 1080 if ( ! is_array( $m['value'] ) ) {
1391 1081 $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
1392 1082 }
@@ -1393,14 +1083,8 @@
1393 1083
1394 1084 $post['postmeta'][ (string) $meta->meta_key ] = $m['value'];
1395 1085 }
1396 1086
1397 - /**
1398 - * @param array $post
1399 - * @param object $layout
1400 - *
1401 - * @return void
1402 - */
1403 1087 private static function populate_layout( &$post, $layout ) {
1404 1088 $post['layout'][ (string) $layout->type ] = (string) $layout->data;
1405 1089 }
1406 1090
@@ -1406,25 +1090,22 @@
1406 1090
1407 1091 /**
1408 1092 * Add terms to post
1409 1093 *
1410 - * @param array $post By reference.
1411 - * @param object $item The XML object data.
1094 + * @param array $post by reference
1095 + * @param object $item The XML object data
1412 1096 */
1413 1097 private static function populate_taxonomies( &$post, $item ) {
1414 1098 foreach ( $item->category as $c ) {
1415 1099 $att = $c->attributes();
1416 -
1417 1100 if ( ! isset( $att['nicename'] ) ) {
1418 1101 continue;
1419 1102 }
1420 1103
1421 1104 $taxonomy = (string) $att['domain'];
1422 -
1423 1105 if ( is_taxonomy_hierarchical( $taxonomy ) ) {
1424 1106 $name = (string) $att['nicename'];
1425 1107 $h_term = get_term_by( 'slug', $name, $taxonomy );
1426 -
1427 1108 if ( $h_term ) {
1428 1109 $name = $h_term->term_id;
1429 1110 }
1430 1111 unset( $h_term );
@@ -1437,17 +1118,13 @@
1437 1118 }
1438 1119
1439 1120 $post['tax_input'][ $taxonomy ][] = $name;
1440 1121 unset( $name );
1441 - }//end foreach
1122 + }
1442 1123 }
1443 1124
1444 1125 /**
1445 - * Edit post if the key and created time match.
1446 - *
1447 - * @param array $post By reference.
1448 - *
1449 - * @return void
1126 + * Edit post if the key and created time match
1450 1127 */
1451 1128 private static function maybe_editing_post( &$post ) {
1452 1129 $match_by = array(
1453 1130 'post_type' => $post['post_type'],
@@ -1455,9 +1132,9 @@
1455 1132 'post_status' => $post['post_status'],
1456 1133 'posts_per_page' => 1,
1457 1134 );
1458 1135
1459 - if ( in_array( $post['post_status'], array( 'trash', 'draft' ), true ) ) {
1136 + if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) {
1460 1137 $match_by['include'] = $post['post_id'];
1461 1138 unset( $match_by['name'] );
1462 1139 }
1463 1140
@@ -1471,9 +1148,8 @@
1471 1148
1472 1149 /**
1473 1150 * @param array $post
1474 1151 * @param int $post_id
1475 - *
1476 1152 * @return void
1477 1153 */
1478 1154 private static function update_postmeta( &$post, $post_id ) {
1479 1155 foreach ( $post['postmeta'] as $k => $v ) {
@@ -1498,13 +1174,13 @@
1498 1174
1499 1175 case 'frm_param':
1500 1176 add_rewrite_endpoint( $v, EP_PERMALINK | EP_PAGES );
1501 1177 break;
1502 - }//end switch
1178 + }
1503 1179
1504 1180 update_post_meta( $post_id, $k, $v );
1505 1181 unset( $k, $v );
1506 - }//end foreach
1182 + }
1507 1183 }
1508 1184
1509 1185 /**
1510 1186 * @param array $post
@@ -1513,9 +1189,8 @@
1513 1189 private static function update_layout( &$post, $post_id ) {
1514 1190 if ( is_callable( 'FrmViewsLayout::maybe_create_layouts_for_view' ) ) {
1515 1191 $listing_layout = ! empty( $post['layout']['listing'] ) ? json_decode( $post['layout']['listing'], true ) : array();
1516 1192 $detail_layout = ! empty( $post['layout']['detail'] ) ? json_decode( $post['layout']['detail'], true ) : array();
1517 -
1518 1193 if ( $listing_layout || $detail_layout ) {
1519 1194 FrmViewsLayout::maybe_create_layouts_for_view( $post_id, $listing_layout, $detail_layout );
1520 1195 }
1521 1196 }
@@ -1521,22 +1196,32 @@
1521 1196 }
1522 1197 }
1523 1198
1524 1199 /**
1525 - * @param array $imported
1200 + * If a template includes custom css, let's include it.
1201 + * The custom css is included on the default style.
1526 1202 *
1527 - * @return void
1203 + * @since 2.03
1528 1204 */
1205 + private static function maybe_update_custom_css( $custom_css ) {
1206 + if ( empty( $custom_css ) ) {
1207 + return;
1208 + }
1209 +
1210 + $frm_style = new FrmStyle();
1211 + $default_style = $frm_style->get_default_style();
1212 + $default_style->post_content['custom_css'] .= "\r\n\r\n" . $custom_css;
1213 + $frm_style->save( $default_style );
1214 + }
1215 +
1529 1216 private static function maybe_update_stylesheet( $imported ) {
1530 - $new_styles = ! empty( $imported['imported']['styles'] );
1531 - $updated_styles = ! empty( $imported['updated']['styles'] );
1532 -
1217 + $new_styles = isset( $imported['imported']['styles'] ) && ! empty( $imported['imported']['styles'] );
1218 + $updated_styles = isset( $imported['updated']['styles'] ) && ! empty( $imported['updated']['styles'] );
1533 1219 if ( $new_styles || $updated_styles ) {
1534 1220 if ( is_admin() && function_exists( 'get_filesystem_method' ) ) {
1535 1221 $frm_style = new FrmStyle();
1536 1222 $frm_style->update( 'default' );
1537 1223 }
1538 -
1539 1224 foreach ( $imported['forms'] as $form_id ) {
1540 1225 self::update_custom_style_setting_after_import( $form_id );
1541 1226 }
1542 1227 }
@@ -1542,46 +1227,20 @@
1542 1227 }
1543 1228 }
1544 1229
1545 1230 /**
1546 - * @param mixed $result
1547 1231 * @param string $message
1548 - * @param array $errors
1549 1232 */
1550 1233 public static function parse_message( $result, &$message, &$errors ) {
1551 1234 if ( is_wp_error( $result ) ) {
1552 1235 $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 -
1236 + } elseif ( ! $result ) {
1575 1237 return;
1576 - }//end if
1577 -
1578 - if ( ! $result ) {
1579 - return;
1580 1238 }
1581 1239
1582 1240 if ( ! is_array( $result ) ) {
1583 1241 $message = is_string( $result ) ? $result : htmlentities( print_r( $result, 1 ) );
1242 +
1584 1243 return;
1585 1244 }
1586 1245
1587 1246 $t_strings = array(
@@ -1589,9 +1248,8 @@
1589 1248 'updated' => __( 'Updated', 'formidable' ),
1590 1249 );
1591 1250
1592 1251 $message = '<ul>';
1593 -
1594 1252 foreach ( $result as $type => $results ) {
1595 1253 if ( ! isset( $t_strings[ $type ] ) ) {
1596 1254 // only print imported and updated
1597 1255 continue;
@@ -1597,9 +1255,8 @@
1597 1255 continue;
1598 1256 }
1599 1257
1600 1258 $s_message = array();
1601 -
1602 1259 foreach ( $results as $k => $m ) {
1603 1260 self::item_count_message( $m, $k, $s_message );
1604 1261 unset( $k, $m );
1605 1262 }
@@ -1610,9 +1267,9 @@
1610 1267 $message .= '</li>';
1611 1268 }
1612 1269 }
1613 1270
1614 - if ( $message === '<ul>' ) {
1271 + if ( $message == '<ul>' ) {
1615 1272 $message = '';
1616 1273 $errors[] = __( 'Nothing was imported or updated', 'formidable' );
1617 1274 } else {
1618 1275 self::add_form_link_to_message( $result, $message );
@@ -1677,21 +1334,18 @@
1677 1334 /**
1678 1335 * If a single form was imported, include a link in the success message.
1679 1336 *
1680 1337 * @since 4.0
1681 - *
1682 1338 * @param array $result The response from the XML import.
1683 1339 * @param string $message The response shown on the page after import.
1684 1340 */
1685 1341 private static function add_form_link_to_message( $result, &$message ) {
1686 1342 $total_forms = $result['imported']['forms'] + $result['updated']['forms'];
1687 -
1688 1343 if ( $total_forms > 1 ) {
1689 1344 return;
1690 1345 }
1691 1346
1692 1347 $primary_form = reset( $result['forms'] );
1693 -
1694 1348 if ( ! empty( $primary_form ) ) {
1695 1349 $primary_form = FrmForm::getOne( $primary_form );
1696 1350 $form_id = empty( $primary_form->parent_form_id ) ? $primary_form->id : $primary_form->parent_form_id;
1697 1351
@@ -1711,9 +1365,8 @@
1711 1365 public static function prepare_form_options_for_export( $options ) {
1712 1366 FrmAppHelper::unserialize_or_decode( $options );
1713 1367 // Change custom_style to the post_name instead of ID (1 may be a string)
1714 1368 $not_default = isset( $options['custom_style'] ) && 1 != $options['custom_style'];
1715 -
1716 1369 if ( $not_default ) {
1717 1370 global $wpdb;
1718 1371 $table = $wpdb->prefix . 'posts';
1719 1372 $where = array( 'ID' => $options['custom_style'] );
@@ -1737,16 +1390,11 @@
1737 1390 * If the saved value is the same as the default, remove it from the export
1738 1391 * This keeps file size down and prevents overriding global settings after import
1739 1392 *
1740 1393 * @since 3.06
1741 - *
1742 - * @param array $options By reference.
1743 - *
1744 - * @return void
1745 1394 */
1746 1395 private static function remove_default_form_options( &$options ) {
1747 1396 $defaults = FrmFormsHelper::get_default_opts();
1748 -
1749 1397 if ( is_callable( 'FrmProFormsHelper::get_default_opts' ) ) {
1750 1398 $defaults += FrmProFormsHelper::get_default_opts();
1751 1399 }
1752 1400 self::remove_defaults( $defaults, $options );
@@ -1755,12 +1403,8 @@
1755 1403 /**
1756 1404 * Remove extra settings from field to keep file size down
1757 1405 *
1758 1406 * @since 3.06
1759 - *
1760 - * @param object $field
1761 - *
1762 - * @return void
1763 1407 */
1764 1408 public static function prepare_field_for_export( &$field ) {
1765 1409 self::remove_default_field_options( $field );
1766 1410 self::add_image_src_to_image_options( $field );
@@ -1769,16 +1413,11 @@
1769 1413 /**
1770 1414 * Remove defaults from field options too
1771 1415 *
1772 1416 * @since 3.06
1773 - *
1774 - * @param object $field
1775 - *
1776 - * @return void
1777 1417 */
1778 1418 private static function remove_default_field_options( &$field ) {
1779 1419 $defaults = self::default_field_options( $field->type );
1780 -
1781 1420 if ( empty( $defaults['blank'] ) ) {
1782 1421 $global_settings = new FrmSettings();
1783 1422 $global_defaults = $global_settings->default_options();
1784 1423 $defaults['blank'] = $global_defaults['blank_msg'];
@@ -1806,9 +1445,8 @@
1806 1445 *
1807 1446 * @since 5.5.1
1808 1447 *
1809 1448 * @param stdClass $field
1810 - *
1811 1449 * @return void
1812 1450 */
1813 1451 private static function add_image_src_to_image_options( $field ) {
1814 1452 if ( empty( $field->options ) || false === strpos( $field->options, 'image' ) ) {
@@ -1836,16 +1474,11 @@
1836 1474 }
1837 1475
1838 1476 /**
1839 1477 * @since 3.06.03
1840 - *
1841 - * @param string $type
1842 - *
1843 - * @return array
1844 1478 */
1845 1479 private static function default_field_options( $type ) {
1846 1480 $defaults = FrmFieldsHelper::get_default_field_options( $type );
1847 -
1848 1481 if ( empty( $defaults['custom_html'] ) ) {
1849 1482 $defaults['custom_html'] = FrmFieldsHelper::get_default_html( $type );
1850 1483 }
1851 1484 return $defaults;
@@ -1855,13 +1488,8 @@
1855 1488 * Compare the default array to the saved values and
1856 1489 * remove if they are the same
1857 1490 *
1858 1491 * @since 3.06
1859 - *
1860 - * @param array $defaults
1861 - * @param array $saved
1862 - *
1863 - * @return void
1864 1492 */
1865 1493 private static function remove_defaults( $defaults, &$saved ) {
1866 1494 foreach ( $saved as $key => $value ) {
1867 1495 if ( isset( $defaults[ $key ] ) && $defaults[ $key ] === $value ) {
@@ -1873,14 +1501,8 @@
1873 1501 /**
1874 1502 * The line endings may prevent html from being equal when it should
1875 1503 *
1876 1504 * @since 3.06
1877 - *
1878 - * @param string $html_name
1879 - * @param array $defaults
1880 - * @param array $options
1881 - *
1882 - * @return void
1883 1505 */
1884 1506 private static function remove_default_html( $html_name, $defaults, &$options ) {
1885 1507 if ( ! isset( $options[ $html_name ] ) || ! isset( $defaults[ $html_name ] ) ) {
1886 1508 return;
@@ -1887,9 +1509,8 @@
1887 1509 }
1888 1510
1889 1511 $old_html = str_replace( "\r\n", "\n", $options[ $html_name ] );
1890 1512 $default_html = $defaults[ $html_name ];
1891 -
1892 1513 if ( $old_html == $default_html ) {
1893 1514 unset( $options[ $html_name ] );
1894 1515
1895 1516 return;
@@ -1896,26 +1517,19 @@
1896 1517 }
1897 1518
1898 1519 // Account for some of the older field default HTML.
1899 1520 $default_html = str_replace( ' id="frm_desc_field_[key]"', '', $default_html );
1900 -
1901 - if ( $old_html === $default_html ) {
1521 + if ( $old_html == $default_html ) {
1902 1522 unset( $options[ $html_name ] );
1903 1523 }
1904 1524 }
1905 1525
1906 - /**
1907 - * @param string $str
1908 - *
1909 - * @return string
1910 - */
1911 1526 public static function cdata( $str ) {
1912 1527 FrmAppHelper::unserialize_or_decode( $str );
1913 -
1914 1528 if ( is_array( $str ) ) {
1915 1529 $str = json_encode( $str );
1916 - } elseif ( FrmAppHelper::is_valid_utf8( $str ) === false ) {
1917 - $str = FrmAppHelper::maybe_utf8_encode( $str );
1530 + } elseif ( seems_utf8( $str ) === false ) {
1531 + $str = utf8_encode( $str );
1918 1532 }
1919 1533
1920 1534 if ( is_numeric( $str ) ) {
1921 1535 return $str;
@@ -1934,10 +1548,8 @@
1934 1548 *
1935 1549 * @since 2.0.22
1936 1550 *
1937 1551 * @param string $str
1938 - *
1939 - * @return void
1940 1552 */
1941 1553 private static function remove_invalid_characters_from_xml( &$str ) {
1942 1554 // Remove <US> character
1943 1555 $str = str_replace( '\x1F', '', $str );
@@ -1942,18 +1554,8 @@
1942 1554 // Remove <US> character
1943 1555 $str = str_replace( '\x1F', '', $str );
1944 1556 }
1945 1557
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 1558 public static function migrate_form_settings_to_actions( $form_options, $form_id, &$imported = array(), $switch = false ) {
1957 1559 // Get post type
1958 1560 $post_type = FrmFormActionsController::$action_post_type;
1959 1561
@@ -1971,13 +1573,9 @@
1971 1573
1972 1574 /**
1973 1575 * Migrate post settings to form action
1974 1576 *
1975 - * @param array $form_options
1976 - * @param int $form_id
1977 1577 * @param string $post_type
1978 - * @param array $imported
1979 - * @param bool $switch
1980 1578 */
1981 1579 private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
1982 1580 if ( ! isset( $form_options['create_post'] ) || ! $form_options['create_post'] ) {
1983 1581 return;
@@ -2046,9 +1644,9 @@
2046 1644
2047 1645 if ( ! $exists ) {
2048 1646 // this isn't an email, but we need to use a class that will always be included
2049 1647 FrmDb::save_json_post( $new_action );
2050 - ++$imported['imported']['actions'];
1648 + $imported['imported']['actions'] ++;
2051 1649 }
2052 1650 }
2053 1651
2054 1652 /**
@@ -2055,11 +1653,11 @@
2055 1653 * Switch old field IDs for new field IDs in emails and post
2056 1654 *
2057 1655 * @since 2.0
2058 1656 *
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.
1657 + * @param array $post_content - check for old field IDs
1658 + * @param array $basic_fields - fields with string or int saved
1659 + * @param array $array_fields - fields with arrays saved
2062 1660 *
2063 1661 * @return string $post_content - new field IDs
2064 1662 */
2065 1663 private static function switch_action_field_ids( $post_content, $basic_fields, $array_fields = array() ) {
@@ -2092,19 +1690,8 @@
2092 1690
2093 1691 return $post_content;
2094 1692 }
2095 1693
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 1694 private static function migrate_email_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
2108 1695 // No old notifications or autoresponders to carry over
2109 1696 if ( ! isset( $form_options['auto_responder'] ) && ! isset( $form_options['notification'] ) && ! isset( $form_options['email_to'] ) ) {
2110 1697 return;
@@ -2151,12 +1738,12 @@
2151 1738 );
2152 1739
2153 1740 if ( empty( $exists ) ) {
2154 1741 FrmDb::save_json_post( $new_notification );
2155 - ++$imported['imported']['actions'];
1742 + $imported['imported']['actions'] ++;
2156 1743 }
2157 1744 unset( $new_notification );
2158 - }//end foreach
1745 + }
2159 1746
2160 1747 self::remove_deprecated_notification_settings( $form_id, $form_options );
2161 1748 }
2162 1749
@@ -2165,15 +1752,12 @@
2165 1752 *
2166 1753 * @since 2.05
2167 1754 *
2168 1755 * @param int|string $form_id
2169 - * @param array $form_options
2170 - *
2171 - * @return void
1756 + * @param array $form_options
2172 1757 */
2173 1758 private static function remove_deprecated_notification_settings( $form_id, $form_options ) {
2174 1759 $delete_settings = array( 'notification', 'autoresponder', 'email_to' );
2175 -
2176 1760 foreach ( $delete_settings as $index ) {
2177 1761 if ( isset( $form_options[ $index ] ) ) {
2178 1762 unset( $form_options[ $index ] );
2179 1763 }
@@ -2180,19 +1764,10 @@
2180 1764 }
2181 1765 FrmForm::update( $form_id, array( 'options' => $form_options ) );
2182 1766 }
2183 1767
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 1768 private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) {
2194 - if ( ! isset( $form_options['notification'] ) && ! empty( $form_options['email_to'] ) ) {
1769 + if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) {
2195 1770 // add old settings into notification array
2196 1771 $form_options['notification'] = array( 0 => $form_options );
2197 1772 } elseif ( isset( $form_options['notification']['email_to'] ) ) {
2198 1773 // make sure it's in the correct format
@@ -2222,20 +1797,12 @@
2222 1797 $new_notification = array();
2223 1798 self::setup_new_notification( $new_notification, $notification, $atts );
2224 1799
2225 1800 $notifications[] = $new_notification;
2226 - }//end foreach
2227 - }//end if
1801 + }
1802 + }
2228 1803 }
2229 1804
2230 - /**
2231 - * Format email data
2232 - *
2233 - * @param array $atts
2234 - * @param array $notification
2235 - *
2236 - * @return void
2237 - */
2238 1805 private static function format_email_data( &$atts, $notification ) {
2239 1806 // Format email_to
2240 1807 self::format_email_to_data( $atts, $notification );
2241 1808
@@ -2243,13 +1810,11 @@
2243 1810 $reply_fields = array(
2244 1811 'reply_to' => '',
2245 1812 'reply_to_name' => '',
2246 1813 );
2247 -
2248 1814 foreach ( $reply_fields as $f => $val ) {
2249 1815 if ( isset( $notification[ $f ] ) ) {
2250 1816 $atts[ $f ] = $notification[ $f ];
2251 -
2252 1817 if ( 'custom' == $notification[ $f ] ) {
2253 1818 $atts[ $f ] = $notification[ 'cust_' . $f ];
2254 1819 } elseif ( is_numeric( $atts[ $f ] ) && ! empty( $atts[ $f ] ) ) {
2255 1820 $atts[ $f ] = '[' . $atts[ $f ] . ']';
@@ -2259,9 +1824,8 @@
2259 1824 }
2260 1825
2261 1826 // Format event
2262 1827 $atts['event'] = array( 'create' );
2263 -
2264 1828 if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) {
2265 1829 $atts['event'][] = 'update';
2266 1830 } elseif ( isset( $notification['update_email'] ) && 2 == $notification['update_email'] ) {
2267 1831 $atts['event'] = array( 'update' );
@@ -2267,16 +1831,8 @@
2267 1831 $atts['event'] = array( 'update' );
2268 1832 }
2269 1833 }
2270 1834
2271 - /**
2272 - * Format email_to data
2273 - *
2274 - * @param array $atts
2275 - * @param array $notification
2276 - *
2277 - * @return void
2278 - */
2279 1835 private static function format_email_to_data( &$atts, $notification ) {
2280 1836 if ( isset( $notification['email_to'] ) ) {
2281 1837 $atts['email_to'] = preg_split( '/ (,|;) /', $notification['email_to'] );
2282 1838 } else {
@@ -2296,9 +1852,8 @@
2296 1852 }
2297 1853
2298 1854 if ( strpos( $email_field, '|' ) ) {
2299 1855 $email_opt = explode( '|', $email_field );
2300 -
2301 1856 if ( isset( $email_opt[0] ) ) {
2302 1857 $atts['email_to'][ $key ] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']';
2303 1858 }
2304 1859 unset( $email_opt );
@@ -2306,17 +1861,8 @@
2306 1861 }
2307 1862 $atts['email_to'] = implode( ', ', $atts['email_to'] );
2308 1863 }
2309 1864
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 1865 private static function setup_new_notification( &$new_notification, $notification, $atts ) {
2320 1866 // Set up new notification
2321 1867 $new_notification = array(
2322 1868 'post_content' => array(
@@ -2327,9 +1873,8 @@
2327 1873 );
2328 1874
2329 1875 // Add more fields to the new notification
2330 1876 $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' );
2331 -
2332 1877 foreach ( $add_fields as $add_field ) {
2333 1878 if ( isset( $notification[ $add_field ] ) ) {
2334 1879 $new_notification['post_content'][ $add_field ] = $notification[ $add_field ];
2335 1880 } elseif ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) {
@@ -2351,11 +1896,9 @@
2351 1896
2352 1897 /**
2353 1898 * Switch field IDs in pre-2.0 email conditional logic
2354 1899 *
2355 - * @param array $post_content Pass by reference.
2356 - *
2357 - * @return void
1900 + * @param $post_content array, pass by reference
2358 1901 */
2359 1902 private static function switch_email_condition_field_ids( &$post_content ) {
2360 1903 // Switch field IDs in conditional logic
2361 1904 if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) {
@@ -2367,32 +1910,20 @@
2367 1910 }
2368 1911 }
2369 1912 }
2370 1913
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 1914 private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) {
2381 1915 if ( isset( $form_options['auto_responder'] ) && $form_options['auto_responder'] && isset( $form_options['ar_email_message'] ) && $form_options['ar_email_message'] ) {
2382 1916 // migrate autoresponder
2383 1917
2384 - $email_field = $form_options['ar_email_to'] ?? 0;
2385 -
1918 + $email_field = isset( $form_options['ar_email_to'] ) ? $form_options['ar_email_to'] : 0;
2386 1919 if ( strpos( $email_field, '|' ) ) {
2387 1920 // data from entries field
2388 1921 $email_field = explode( '|', $email_field );
2389 -
2390 1922 if ( isset( $email_field[1] ) ) {
2391 1923 $email_field = $email_field[1];
2392 1924 }
2393 1925 }
2394 -
2395 1926 if ( is_numeric( $email_field ) && ! empty( $email_field ) ) {
2396 1927 $email_field = '[' . $email_field . ']';
2397 1928 }
2398 1929
@@ -2399,18 +1930,18 @@
2399 1930 $notification = $form_options;
2400 1931 $new_notification2 = array(
2401 1932 'post_content' => array(
2402 1933 'email_message' => $notification['ar_email_message'],
2403 - 'email_subject' => $notification['ar_email_subject'] ?? '',
1934 + 'email_subject' => isset( $notification['ar_email_subject'] ) ? $notification['ar_email_subject'] : '',
2404 1935 'email_to' => $email_field,
2405 - 'plain_text' => $notification['ar_plain_text'] ?? 0,
1936 + 'plain_text' => isset( $notification['ar_plain_text'] ) ? $notification['ar_plain_text'] : 0,
2406 1937 'inc_user_info' => 0,
2407 1938 ),
2408 1939 'post_name' => $form_id . '_email_' . count( $notifications ),
2409 1940 );
2410 1941
2411 - $reply_to = $notification['ar_reply_to'] ?? '';
2412 - $reply_to_name = $notification['ar_reply_to_name'] ?? '';
1942 + $reply_to = isset( $notification['ar_reply_to'] ) ? $notification['ar_reply_to'] : '';
1943 + $reply_to_name = isset( $notification['ar_reply_to_name'] ) ? $notification['ar_reply_to_name'] : '';
2413 1944
2414 1945 if ( ! empty( $reply_to ) ) {
2415 1946 $new_notification2['post_content']['reply_to'] = $reply_to;
2416 1947 }
@@ -2420,17 +1951,17 @@
2420 1951 }
2421 1952
2422 1953 $notifications[] = $new_notification2;
2423 1954 unset( $new_notification2 );
2424 - }//end if
1955 + }
2425 1956 }
2426 1957
2427 1958 /**
2428 1959 * PHP 8 backward compatibility for the libxml_disable_entity_loader function
2429 1960 *
2430 - * @param bool $loader
1961 + * @param boolean $disable
2431 1962 *
2432 - * @return bool
1963 + * @return boolean
2433 1964 */
2434 1965 public static function maybe_libxml_disable_entity_loader( $loader ) {
2435 1966 if ( version_compare( phpversion(), '8.0', '<' ) && function_exists( 'libxml_disable_entity_loader' ) ) {
2436 1967 $loader = libxml_disable_entity_loader( $loader ); // phpcs:disable Generic.PHP.DeprecatedFunctions.Deprecated
@@ -2438,31 +1969,9 @@
2438 1969
2439 1970 return $loader;
2440 1971 }
2441 1972
2442 - /**
2443 - * PHP 8 backward compatibility for the libxml_disable_entity_loader function
2444 - *
2445 - * @return bool
2446 - */
2447 1973 public static function check_if_libxml_disable_entity_loader_exists() {
2448 1974 return version_compare( phpversion(), '8.0', '<' ) && ! function_exists( 'libxml_disable_entity_loader' );
2449 1975 }
1976 +}
2450 1977
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 -}