PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.11.02
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.11.02
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 +49 -382 6.3.24.11.02 View file →
@@ -4,13 +4,8 @@
4 4 }
5 5
6 6 class FrmXMLHelper {
7 7
8 - /**
9 - * @var bool $installing_template true if importing an XML from API, false if importing an XML file manually.
10 - */
11 - private static $installing_template = false;
12 -
13 8 public static function get_xml_values( $opt, $padding ) {
14 9 if ( is_array( $opt ) ) {
15 10 foreach ( $opt as $ok => $ov ) {
16 11 echo "\n" . esc_html( $padding );
@@ -22,9 +17,9 @@
22 17 }
23 18 echo '</' . esc_html( $tag ) . '>';
24 19 }
25 20 } else {
26 - echo self::cdata( $opt ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
21 + echo self::cdata( $opt ); // WPCS: XSS ok.
27 22 }
28 23 }
29 24
30 25 public static function import_xml( $file ) {
@@ -32,25 +27,13 @@
32 27 define( 'WP_IMPORTING', true );
33 28 }
34 29
35 30 if ( ! class_exists( 'DOMDocument' ) ) {
36 - $error_message = sprintf(
37 - /* translators: 1: Documentation link */
38 - __( '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' ),
39 - '<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>'
40 - );
41 -
42 - return new WP_Error( 'SimpleXML_parse_error', $error_message, libxml_get_errors() );
31 + return new WP_Error( 'SimpleXML_parse_error', __( 'Your server does not have XML enabled', 'formidable' ), libxml_get_errors() );
43 32 }
44 33
45 - $xml_string = file_get_contents( $file );
46 - self::maybe_fix_xml( $xml_string );
47 -
48 - $dom = new DOMDocument();
49 -
50 - // LIBXML_COMPACT activates small nodes allocation optimization.
51 - // Use LIBXML_PARSEHUGE to avoid "parser error : internal error: Huge input lookup" for large (300MB) files.
52 - $success = $dom->loadXML( $xml_string, LIBXML_COMPACT | LIBXML_PARSEHUGE );
34 + $dom = new DOMDocument();
35 + $success = $dom->loadXML( file_get_contents( $file ) );
53 36 if ( ! $success ) {
54 37 return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
55 38 }
56 39
@@ -69,50 +52,19 @@
69 52 return self::import_xml_now( $xml );
70 53 }
71 54
72 55 /**
73 - * @since 6.2.3
74 - *
75 - * @param string $xml_string
76 - * @return void
77 - */
78 - private static function maybe_fix_xml( &$xml_string ) {
79 - if ( '<?xml' !== substr( $xml_string, 0, 5 ) ) {
80 - // Some XML files have may have unexpected characters at the start.
81 - $xml_string = substr( $xml_string, strpos( $xml_string, '<?xml' ) );
82 - }
83 -
84 - // The Equity theme adds a <meta name="generator" content="Equity 1.7.13" /> tag using the "the_generator" filter.
85 - // Strip that out as it breaks the XML import.
86 - $channel_start_position = strpos( $xml_string, '<channel>' );
87 - $content_before_channel_tag = substr( $xml_string, 0, $channel_start_position );
88 - if ( 0 !== strpos( $content_before_channel_tag, '<meta name="generator" ' ) ) {
89 - $content_before_channel_tag = preg_replace(
90 - '/<meta\s+[^>]*name="generator"[^>]*\/>/i',
91 - '',
92 - $content_before_channel_tag,
93 - 1
94 - );
95 - $xml_string = $content_before_channel_tag . substr( $xml_string, $channel_start_position );
96 - }
97 - }
98 -
99 - /**
100 56 * Add terms, forms (form and field ids), posts (post ids), and entries to db, in that order
101 57 *
102 58 * @since 3.06
103 - *
104 - * @param object $xml
105 - * @param bool $installing_template
106 59 * @return array The number of items imported
107 60 */
108 - public static function import_xml_now( $xml, $installing_template = false ) {
61 + public static function import_xml_now( $xml ) {
109 62 if ( ! defined( 'WP_IMPORTING' ) ) {
110 63 define( 'WP_IMPORTING', true );
111 64 }
112 65
113 - self::$installing_template = $installing_template;
114 - $imported = self::pre_import_data();
66 + $imported = self::pre_import_data();
115 67
116 68 foreach ( array( 'term', 'form', 'view' ) as $item_type ) {
117 69 // Grab cats, tags, and terms, or forms or posts.
118 70 if ( isset( $xml->{$item_type} ) ) {
@@ -126,9 +78,9 @@
126 78
127 79 if ( ! isset( $imported['form_status'] ) || empty( $imported['form_status'] ) ) {
128 80 // Check for an error message in the XML.
129 81 if ( isset( $xml->Code ) && isset( $xml->Message ) ) { // phpcs:ignore WordPress.NamingConventions
130 - $imported['error'] = (string) $xml->Message; // phpcs:ignore WordPress.NamingConventions
82 + $imported['error'] = reset( $xml->Message ); // phpcs:ignore WordPress.NamingConventions
131 83 }
132 84 }
133 85
134 86 return $imported;
@@ -283,13 +235,8 @@
283 235 }
284 236
285 237 $form['options'] = FrmAppHelper::maybe_json_decode( $form['options'] );
286 238
287 - if ( self::$installing_template ) {
288 - // Templates don't necessarily have antispam on, but we want our templates to all have antispam on by default.
289 - $form['options']['antispam'] = 1;
290 - }
291 -
292 239 return $form;
293 240 }
294 241
295 242 private static function maybe_get_form( $form ) {
@@ -667,12 +614,8 @@
667 614 private static function create_imported_field( $f, &$imported ) {
668 615 $defaults = self::default_field_options( $f['type'] );
669 616 $f['field_options'] = array_merge( $defaults, $f['field_options'] );
670 617
671 - if ( is_callable( 'FrmProFileImport::import_attachment' ) ) {
672 - $f = self::maybe_import_images_for_options( $f );
673 - }
674 -
675 618 $new_id = FrmField::create( $f );
676 619 if ( $new_id != false ) {
677 620 $imported['imported']['fields'] ++;
678 621 do_action( 'frm_after_field_is_imported', $f, $new_id );
@@ -679,40 +622,8 @@
679 622 }
680 623 }
681 624
682 625 /**
683 - * Import images for radio buttons and checkboxes from image src if available.
684 - *
685 - * @since 5.5.1
686 - *
687 - * @param array $field
688 - * @return array
689 - */
690 - private static function maybe_import_images_for_options( $field ) {
691 - if ( empty( $field['options'] ) || ! is_array( $field['options'] ) ) {
692 - return $field;
693 - }
694 -
695 - foreach ( $field['options'] as $key => $option ) {
696 - if ( ! is_array( $option ) || empty( $option['src'] ) ) {
697 - continue;
698 - }
699 -
700 - $field_object = (object) $field;
701 - $field_object->type = 'file'; // Fake the file type as FrmProImport::import_attachment checks for file type.
702 -
703 - $image_id = FrmProFileImport::import_attachment( $option['src'], $field_object );
704 - unset( $field['options'][ $key ]['src'] ); // Remove the src from options as it isn't required after import.
705 -
706 - if ( is_numeric( $image_id ) ) {
707 - $field['options'][ $key ]['image'] = $image_id;
708 - }
709 - }
710 -
711 - return $field;
712 - }
713 -
714 - /**
715 626 * Fix field ids for fields that already exist prior to import.
716 627 *
717 628 * @since 4.07
718 629 * @param int $form_id
@@ -763,9 +674,9 @@
763 674 if ( ! isset( $form['options']['custom_style'] ) ) {
764 675 return;
765 676 }
766 677
767 - if ( is_numeric( $form['options']['custom_style'] ) && 1 === intval( $form['options']['custom_style'] ) ) {
678 + if ( is_numeric( $form['options']['custom_style'] ) ) {
768 679 // Set to default
769 680 $form['options']['custom_style'] = 1;
770 681 } else {
771 682 // Replace the style name with the style ID on import
@@ -820,11 +731,8 @@
820 731 $form_action_type => 'actions',
821 732 'frm_styles' => 'styles',
822 733 );
823 734
824 - $view_ids = array();
825 - $posts_with_shortcodes = array();
826 -
827 735 foreach ( $views as $item ) {
828 736 $post = array(
829 737 'post_title' => (string) $item->title,
830 738 'post_name' => (string) $item->post_name,
@@ -847,10 +755,8 @@
847 755 'layout' => array(),
848 756 'tax_input' => array(),
849 757 );
850 758
851 - $post['post_content'] = self::switch_form_ids( $post['post_content'], $imported['forms'] );
852 -
853 759 $old_id = $post['post_id'];
854 760 self::populate_post( $post, $item, $imported );
855 761
856 762 unset( $item );
@@ -855,27 +761,24 @@
855 761
856 762 unset( $item );
857 763
858 764 $post_id = false;
859 - if ( $post['post_type'] === $form_action_type ) {
765 + if ( $post['post_type'] == $form_action_type ) {
860 766 $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] );
861 767 if ( $action_control && is_object( $action_control ) ) {
862 768 $post_id = $action_control->maybe_create_action( $post, $imported['form_status'] );
863 769 }
864 770 unset( $action_control );
865 - } elseif ( $post['post_type'] === 'frm_styles' ) {
771 + } elseif ( $post['post_type'] == 'frm_styles' ) {
866 772 // Properly encode post content before inserting the post
867 773 $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] );
774 + $custom_css = isset( $post['post_content']['custom_css'] ) ? $post['post_content']['custom_css'] : '';
868 775 $post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] );
869 776
870 777 // Create/update post now
871 778 $post_id = wp_insert_post( $post );
779 + self::maybe_update_custom_css( $custom_css );
872 780 } else {
873 - if ( $post['post_type'] === 'frm_display' ) {
874 - $post['post_content'] = self::maybe_prepare_json_view_content( $post['post_content'] );
875 - } elseif ( 'page' === $post['post_type'] && isset( $imported['posts'][ $post['post_parent'] ] ) ) {
876 - $post['post_parent'] = $imported['posts'][ $post['post_parent'] ];
877 - }
878 781 // Create/update post now
879 782 $post_id = wp_insert_post( $post );
880 783 }
881 784
@@ -882,12 +785,8 @@
882 785 if ( ! is_numeric( $post_id ) ) {
883 786 continue;
884 787 }
885 788
886 - if ( false !== strpos( $post['post_content'], '[display-frm-data' ) || false !== strpos( $post['post_content'], '[formidable' ) ) {
887 - $posts_with_shortcodes[ $post_id ] = $post;
888 - }
889 -
890 789 self::update_postmeta( $post, $post_id );
891 790 self::update_layout( $post, $post_id );
892 791
893 792 $this_type = 'posts';
@@ -902,165 +801,18 @@
902 801 }
903 802
904 803 $imported['posts'][ (int) $old_id ] = $post_id;
905 804
906 - if ( $post['post_type'] === 'frm_display' ) {
907 - $view_ids[ (int) $old_id ] = $post_id;
908 - }
909 -
910 805 do_action( 'frm_after_import_view', $post_id, $post );
911 806
912 807 unset( $post );
913 808 }
914 809
915 - if ( $posts_with_shortcodes && $view_ids ) {
916 - self::maybe_switch_view_ids_after_importing_posts( $posts_with_shortcodes, $view_ids );
917 - }
918 - unset( $posts_with_shortcodes, $view_ids );
919 -
920 - if ( ! empty( $imported['forms'] ) ) {
921 - // clear imported forms style cache to make sure the new styles are applied to the forms
922 - self::clear_forms_style_caches( $imported['forms'] );
923 - }
924 -
925 810 self::maybe_update_stylesheet( $imported );
926 811
927 - flush_rewrite_rules();
928 -
929 812 return $imported;
930 813 }
931 814
932 - /**
933 - * Clears styles from cache for imported forms
934 - *
935 - * @param array $imported_forms
936 - */
937 - private static function clear_forms_style_caches( $imported_forms ) {
938 - $where = array(
939 - 'id' => $imported_forms,
940 - 'options LIKE' => '"old_style"',
941 - );
942 - $forms = FrmDb::get_results( 'frm_forms', $where );
943 -
944 - foreach ( $forms as $form ) {
945 - FrmAppHelper::unserialize_or_decode( $form->options );
946 - if ( ! $form->options ) {
947 - continue;
948 - }
949 - $where = array(
950 - 'post_name' => $form->options['old_style'],
951 - 'post_type' => FrmStylesController::$post_type,
952 - );
953 -
954 - $select = 'ID';
955 -
956 - $cache_key = FrmDb::generate_cache_key( $where, array( 'limit' => 1 ), $select, 'var' );
957 - FrmDb::delete_cache_and_transient( $cache_key, 'post' );
958 - }
959 - }
960 -
961 - /**
962 - * Replace old form ids with new ones in a string.
963 - *
964 - * @param string $string
965 - * @param array<int> $form_ids new form ids indexed by old form id.
966 - * @return string
967 - */
968 - private static function switch_form_ids( $string, $form_ids ) {
969 - if ( false === strpos( $string, '[formidable' ) ) {
970 - // Skip string replacing if there are no form shortcodes in string.
971 - return $string;
972 - }
973 -
974 - foreach ( $form_ids as $old_id => $new_id ) {
975 - $string = str_replace(
976 - array(
977 - '[formidable id="' . $old_id . '"',
978 - '[formidable id=' . $old_id . ']',
979 - '[formidable id=' . $old_id . ' ',
980 - '"formId":"' . $old_id . '"',
981 - ),
982 - array(
983 - '[formidable id="' . $new_id . '"',
984 - '[formidable id=' . $new_id . ']',
985 - '[formidable id=' . $new_id . ' ',
986 - '"formId":"' . $new_id . '"',
987 - ),
988 - $string
989 - );
990 - }
991 -
992 - return $string;
993 - }
994 -
995 - /**
996 - * @param array<array> $posts_with_shortcodes indexed by current post id.
997 - * @param array<int> $view_ids new view ids indexed by old view id.
998 - * @return void
999 - */
1000 - private static function maybe_switch_view_ids_after_importing_posts( $posts_with_shortcodes, $view_ids ) {
1001 - foreach ( $posts_with_shortcodes as $imported_post_id => $post ) {
1002 - $post_content = self::switch_view_ids( $post['post_content'], $view_ids );
1003 - if ( $post_content === $post['post_content'] ) {
1004 - continue;
1005 - }
1006 -
1007 - wp_update_post(
1008 - array(
1009 - 'ID' => $imported_post_id,
1010 - 'post_content' => $post_content,
1011 - )
1012 - );
1013 - }
1014 - }
1015 -
1016 - /**
1017 - * Replace old view ids with new ones in a string.
1018 - *
1019 - * @param string $string
1020 - * @param array<int> $view_ids new view ids indexed by old view id.
1021 - * @return string
1022 - */
1023 - private static function switch_view_ids( $string, $view_ids ) {
1024 - if ( false === strpos( $string, '[display-frm-data' ) ) {
1025 - // Skip string replacing if there are no view shortcodes in string.
1026 - return $string;
1027 - }
1028 -
1029 - foreach ( $view_ids as $old_id => $new_id ) {
1030 - $string = str_replace(
1031 - array(
1032 - '[display-frm-data id="' . $old_id . '"',
1033 - '[display-frm-data id=' . $old_id . ']',
1034 - '[display-frm-data id=' . $old_id . ' ',
1035 - '"viewId":"' . $old_id . '"',
1036 - ),
1037 - array(
1038 - '[display-frm-data id="' . $new_id . '"',
1039 - '[display-frm-data id=' . $new_id . ']',
1040 - '[display-frm-data id=' . $new_id . ' ',
1041 - '"viewId":"' . $new_id . '"',
1042 - ),
1043 - $string
1044 - );
1045 - unset( $old_id, $new_id );
1046 - }
1047 -
1048 - return $string;
1049 - }
1050 -
1051 - /**
1052 - * @param string $content
1053 - * @return string
1054 - */
1055 - private static function maybe_prepare_json_view_content( $content ) {
1056 - $maybe_decoded = FrmAppHelper::maybe_json_decode( $content );
1057 - if ( is_array( $maybe_decoded ) && isset( $maybe_decoded[0] ) && isset( $maybe_decoded[0]['box'] ) ) {
1058 - return FrmAppHelper::prepare_and_encode( $maybe_decoded );
1059 - }
1060 - return $content;
1061 - }
1062 -
1063 815 private static function populate_post( &$post, $item, $imported ) {
1064 816 if ( isset( $item->attachment_url ) ) {
1065 817 $post['attachment_url'] = (string) $item->attachment_url;
1066 818 }
@@ -1089,13 +841,8 @@
1089 841
1090 842 self::maybe_editing_post( $post );
1091 843 }
1092 844
1093 - /**
1094 - * @param array $post
1095 - * @param stdClass $meta
1096 - * @param array $imported
1097 - */
1098 845 private static function populate_postmeta( &$post, $meta, $imported ) {
1099 846 global $frm_duplicate_ids;
1100 847
1101 848 $m = array(
@@ -1103,18 +850,18 @@
1103 850 'value' => (string) $meta->meta_value,
1104 851 );
1105 852
1106 853 //switch old form and field ids to new ones
1107 - if ( 'frm_form_id' === $m['key'] && isset( $imported['forms'][ (int) $m['value'] ] ) ) {
854 + if ( $m['key'] == 'frm_form_id' && isset( $imported['forms'][ (int) $m['value'] ] ) ) {
1108 855 $m['value'] = $imported['forms'][ (int) $m['value'] ];
1109 856 } else {
1110 857 $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
1111 858
1112 859 if ( ! empty( $frm_duplicate_ids ) ) {
1113 - if ( 'frm_dyncontent' === $m['key'] ) {
1114 - $m['value'] = self::maybe_prepare_json_view_content( $m['value'] );
860 +
861 + if ( $m['key'] == 'frm_dyncontent' ) {
1115 862 $m['value'] = FrmFieldsHelper::switch_field_ids( $m['value'] );
1116 - } elseif ( 'frm_options' === $m['key'] ) {
863 + } elseif ( $m['key'] == 'frm_options' ) {
1117 864
1118 865 foreach ( array( 'date_field_id', 'edate_field_id' ) as $setting_name ) {
1119 866 if ( isset( $m['value'][ $setting_name ] ) && is_numeric( $m['value'][ $setting_name ] ) && isset( $frm_duplicate_ids[ $m['value'][ $setting_name ] ] ) ) {
1120 867 $m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ];
@@ -1214,40 +961,20 @@
1214 961 $post['ID'] = current( $editing )->ID;
1215 962 }
1216 963 }
1217 964
1218 - /**
1219 - * @param array $post
1220 - * @param int $post_id
1221 - * @return void
1222 - */
1223 965 private static function update_postmeta( &$post, $post_id ) {
1224 966 foreach ( $post['postmeta'] as $k => $v ) {
1225 - switch ( $k ) {
1226 - case '_edit_last':
1227 - $v = FrmAppHelper::get_user_id_param( $v );
1228 - break;
1229 -
1230 - case '_thumbnail_id':
1231 - if ( FrmAppHelper::pro_is_installed() ) {
1232 - // Change the attachment ID.
1233 - $field_obj = FrmFieldFactory::get_field_type( 'file' );
1234 - $v = $field_obj->get_file_id( $v );
1235 - }
1236 - break;
1237 -
1238 - case 'frm_dyncontent':
1239 - if ( is_array( $v ) ) {
1240 - $v = json_encode( $v );
1241 - }
1242 - break;
1243 -
1244 - case 'frm_param':
1245 - add_rewrite_endpoint( $v, EP_PERMALINK | EP_PAGES );
1246 - break;
967 + if ( '_edit_last' == $k ) {
968 + $v = FrmAppHelper::get_user_id_param( $v );
969 + } elseif ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) {
970 + // Change the attachment ID.
971 + $field_obj = FrmFieldFactory::get_field_type( 'file' );
972 + $v = $field_obj->get_file_id( $v );
1247 973 }
1248 974
1249 975 update_post_meta( $post_id, $k, $v );
976 +
1250 977 unset( $k, $v );
1251 978 }
1252 979 }
1253 980
@@ -1264,8 +991,25 @@
1264 991 }
1265 992 }
1266 993 }
1267 994
995 + /**
996 + * If a template includes custom css, let's include it.
997 + * The custom css is included on the default style.
998 + *
999 + * @since 2.03
1000 + */
1001 + private static function maybe_update_custom_css( $custom_css ) {
1002 + if ( empty( $custom_css ) ) {
1003 + return;
1004 + }
1005 +
1006 + $frm_style = new FrmStyle();
1007 + $default_style = $frm_style->get_default_style();
1008 + $default_style->post_content['custom_css'] .= "\r\n\r\n" . $custom_css;
1009 + $frm_style->save( $default_style );
1010 + }
1011 +
1268 1012 private static function maybe_update_stylesheet( $imported ) {
1269 1013 $new_styles = isset( $imported['imported']['styles'] ) && ! empty( $imported['imported']['styles'] );
1270 1014 $updated_styles = isset( $imported['updated']['styles'] ) && ! empty( $imported['updated']['styles'] );
1271 1015 if ( $new_styles || $updated_styles ) {
@@ -1284,29 +1028,8 @@
1284 1028 */
1285 1029 public static function parse_message( $result, &$message, &$errors ) {
1286 1030 if ( is_wp_error( $result ) ) {
1287 1031 $errors[] = $result->get_error_message();
1288 -
1289 - // Remove the SimpleXML_parse_error from the WP_Error object to avoid
1290 - // displaying duplicate error messages from $result->get_error_message()
1291 - $error_codes = $result->get_error_codes();
1292 - $error_details = array();
1293 - foreach ( $error_codes as $error_code ) {
1294 - // Clone WP_Error data because WP_Error removes all error messages and data
1295 - // associated with the specified error code when an item is removed.
1296 - // Source: https://developer.wordpress.org/reference/classes/wp_error/remove/#source
1297 - $error_details = $result->get_error_data( $error_code );
1298 - if ( $error_code === 'SimpleXML_parse_error' ) {
1299 - $result->remove( $error_code );
1300 - break;
1301 - }
1302 - }
1303 -
1304 - if ( ! empty( $error_details ) ) {
1305 - $errors[] = '<br />' . esc_html_x( 'Error details:', 'import xml message', 'formidable' ) . '<br />' . esc_html( print_r( $error_details, 1 ) );
1306 - }
1307 -
1308 - return;
1309 1032 } elseif ( ! $result ) {
1310 1033 return;
1311 1034 }
1312 1035
@@ -1346,24 +1069,12 @@
1346 1069 $errors[] = __( 'Nothing was imported or updated', 'formidable' );
1347 1070 } else {
1348 1071 self::add_form_link_to_message( $result, $message );
1349 1072
1350 - /**
1351 - * @since 5.3
1352 - *
1353 - * @param string $message
1354 - * @param array $result
1355 - */
1356 - $message = apply_filters( 'frm_xml_parsed_message', $message, $result );
1357 1073 $message .= '</ul>';
1358 1074 }
1359 1075 }
1360 1076
1361 - /**
1362 - * @param int $m
1363 - * @param string $type
1364 - * @param array<string> $s_message
1365 - */
1366 1077 public static function item_count_message( $m, $type, &$s_message ) {
1367 1078 if ( ! $m ) {
1368 1079 return;
1369 1080 }
@@ -1377,9 +1088,9 @@
1377 1088 'items' => sprintf( _n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m ),
1378 1089 /* translators: %1$s: Number of items */
1379 1090 'views' => sprintf( _n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m ),
1380 1091 /* translators: %1$s: Number of items */
1381 - 'posts' => sprintf( _n( '%1$s Page/Post', '%1$s Pages/Posts', $m, 'formidable' ), $m ),
1092 + 'posts' => sprintf( _n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m ),
1382 1093 /* translators: %1$s: Number of items */
1383 1094 'styles' => sprintf( _n( '%1$s Style', '%1$s Styles', $m, 'formidable' ), $m ),
1384 1095 /* translators: %1$s: Number of items */
1385 1096 'terms' => sprintf( _n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m ),
@@ -1386,23 +1097,9 @@
1386 1097 /* translators: %1$s: Number of items */
1387 1098 'actions' => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ),
1388 1099 );
1389 1100
1390 - if ( isset( $strings[ $type ] ) ) {
1391 - $s_message[] = $strings[ $type ];
1392 - } else {
1393 - $string = ' ' . $m . ' ' . ucfirst( $type );
1394 -
1395 - /**
1396 - * @since 5.3
1397 - *
1398 - * @param string $string Message string for imported item.
1399 - * @param int $m Number of item that was imported.
1400 - * }
1401 - */
1402 - $string = apply_filters( 'frm_xml_' . $type . '_count_message', $string, $m );
1403 - $s_message[] = $string;
1404 - }
1101 + $s_message[] = isset( $strings[ $type ] ) ? $strings[ $type ] : ' ' . $m . ' ' . ucfirst( $type );
1405 1102 }
1406 1103
1407 1104 /**
1408 1105 * If a single form was imported, include a link in the success message.
@@ -1479,9 +1176,8 @@
1479 1176 * @since 3.06
1480 1177 */
1481 1178 public static function prepare_field_for_export( &$field ) {
1482 1179 self::remove_default_field_options( $field );
1483 - self::add_image_src_to_image_options( $field );
1484 1180 }
1485 1181
1486 1182 /**
1487 1183 * Remove defaults from field options too
@@ -1513,41 +1209,8 @@
1513 1209 $field->field_options = serialize( $options );
1514 1210 }
1515 1211
1516 1212 /**
1517 - * Add image "src" key to each image option so the image can be imported to another website.
1518 - *
1519 - * @since 5.5.1
1520 - *
1521 - * @param stdClass $field
1522 - * @return void
1523 - */
1524 - private static function add_image_src_to_image_options( $field ) {
1525 - if ( empty( $field->options ) || false === strpos( $field->options, 'image' ) ) {
1526 - return;
1527 - }
1528 -
1529 - $updated = false;
1530 - $options = $field->options;
1531 - FrmAppHelper::unserialize_or_decode( $options );
1532 -
1533 - if ( ! $options || ! is_array( $options ) ) {
1534 - return;
1535 - }
1536 -
1537 - foreach ( $options as $key => $option ) {
1538 - if ( is_array( $option ) && ! empty( $option['image'] ) ) {
1539 - $options[ $key ]['src'] = wp_get_attachment_url( $option['image'] );
1540 - $updated = true;
1541 - }
1542 - }
1543 -
1544 - if ( $updated ) {
1545 - $field->options = maybe_serialize( $options );
1546 - }
1547 - }
1548 -
1549 - /**
1550 1213 * @since 3.06.03
1551 1214 */
1552 1215 private static function default_field_options( $type ) {
1553 1216 $defaults = FrmFieldsHelper::get_default_field_options( $type );
@@ -1598,11 +1261,15 @@
1598 1261
1599 1262 public static function cdata( $str ) {
1600 1263 FrmAppHelper::unserialize_or_decode( $str );
1601 1264 if ( is_array( $str ) ) {
1602 - $str = json_encode( $str );
1603 - } elseif ( seems_utf8( $str ) === false ) {
1604 - $str = FrmAppHelper::maybe_utf8_encode( $str );
1265 + if ( isset( $str[0] ) && isset( $str[0]['box'] ) ) {
1266 + $str = maybe_serialize( $str );
1267 + } else {
1268 + $str = json_encode( $str );
1269 + }
1270 + } elseif ( seems_utf8( $str ) == false ) {
1271 + $str = utf8_encode( $str );
1605 1272 }
1606 1273
1607 1274 if ( is_numeric( $str ) ) {
1608 1275 return $str;