PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.5.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.5.2
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 +25 -100 6.3 → 5.5.2 View file →
@@ -32,25 +32,13 @@
32 32 define( 'WP_IMPORTING', true );
33 33 }
34 34
35 35 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() );
36 + return new WP_Error( 'SimpleXML_parse_error', __( 'Your server does not have XML enabled', 'formidable' ), libxml_get_errors() );
43 37 }
44 38
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 );
39 + $dom = new DOMDocument();
40 + $success = $dom->loadXML( file_get_contents( $file ) );
53 41 if ( ! $success ) {
54 42 return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
55 43 }
56 44
@@ -69,35 +57,8 @@
69 57 return self::import_xml_now( $xml );
70 58 }
71 59
72 60 /**
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 61 * Add terms, forms (form and field ids), posts (post ids), and entries to db, in that order
101 62 *
102 63 * @since 3.06
103 64 *
@@ -763,9 +724,9 @@
763 724 if ( ! isset( $form['options']['custom_style'] ) ) {
764 725 return;
765 726 }
766 727
767 - if ( is_numeric( $form['options']['custom_style'] ) && 1 === intval( $form['options']['custom_style'] ) ) {
728 + if ( is_numeric( $form['options']['custom_style'] ) ) {
768 729 // Set to default
769 730 $form['options']['custom_style'] = 1;
770 731 } else {
771 732 // Replace the style name with the style ID on import
@@ -864,12 +825,14 @@
864 825 unset( $action_control );
865 826 } elseif ( $post['post_type'] === 'frm_styles' ) {
866 827 // Properly encode post content before inserting the post
867 828 $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] );
829 + $custom_css = isset( $post['post_content']['custom_css'] ) ? $post['post_content']['custom_css'] : '';
868 830 $post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] );
869 831
870 832 // Create/update post now
871 833 $post_id = wp_insert_post( $post );
834 + self::maybe_update_custom_css( $custom_css );
872 835 } else {
873 836 if ( $post['post_type'] === 'frm_display' ) {
874 837 $post['post_content'] = self::maybe_prepare_json_view_content( $post['post_content'] );
875 838 } elseif ( 'page' === $post['post_type'] && isset( $imported['posts'][ $post['post_parent'] ] ) ) {
@@ -882,9 +845,9 @@
882 845 if ( ! is_numeric( $post_id ) ) {
883 846 continue;
884 847 }
885 848
886 - if ( false !== strpos( $post['post_content'], '[display-frm-data' ) || false !== strpos( $post['post_content'], '[formidable' ) ) {
849 + if ( false !== strpos( $post['post_content'], '[frm-display-data' ) || false !== strpos( $post['post_content'], '[formidable' ) ) {
887 850 $posts_with_shortcodes[ $post_id ] = $post;
888 851 }
889 852
890 853 self::update_postmeta( $post, $post_id );
@@ -916,13 +879,8 @@
916 879 self::maybe_switch_view_ids_after_importing_posts( $posts_with_shortcodes, $view_ids );
917 880 }
918 881 unset( $posts_with_shortcodes, $view_ids );
919 882
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 883 self::maybe_update_stylesheet( $imported );
926 884
927 885 flush_rewrite_rules();
928 886
@@ -929,37 +887,8 @@
929 887 return $imported;
930 888 }
931 889
932 890 /**
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 891 * Replace old form ids with new ones in a string.
963 892 *
964 893 * @param string $string
965 894 * @param array<int> $form_ids new form ids indexed by old form id.
@@ -1264,8 +1193,25 @@
1264 1193 }
1265 1194 }
1266 1195 }
1267 1196
1197 + /**
1198 + * If a template includes custom css, let's include it.
1199 + * The custom css is included on the default style.
1200 + *
1201 + * @since 2.03
1202 + */
1203 + private static function maybe_update_custom_css( $custom_css ) {
1204 + if ( empty( $custom_css ) ) {
1205 + return;
1206 + }
1207 +
1208 + $frm_style = new FrmStyle();
1209 + $default_style = $frm_style->get_default_style();
1210 + $default_style->post_content['custom_css'] .= "\r\n\r\n" . $custom_css;
1211 + $frm_style->save( $default_style );
1212 + }
1213 +
1268 1214 private static function maybe_update_stylesheet( $imported ) {
1269 1215 $new_styles = isset( $imported['imported']['styles'] ) && ! empty( $imported['imported']['styles'] );
1270 1216 $updated_styles = isset( $imported['updated']['styles'] ) && ! empty( $imported['updated']['styles'] );
1271 1217 if ( $new_styles || $updated_styles ) {
@@ -1284,29 +1230,8 @@
1284 1230 */
1285 1231 public static function parse_message( $result, &$message, &$errors ) {
1286 1232 if ( is_wp_error( $result ) ) {
1287 1233 $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 1234 } elseif ( ! $result ) {
1310 1235 return;
1311 1236 }
1312 1237
@@ -1600,9 +1525,9 @@
1600 1525 FrmAppHelper::unserialize_or_decode( $str );
1601 1526 if ( is_array( $str ) ) {
1602 1527 $str = json_encode( $str );
1603 1528 } elseif ( seems_utf8( $str ) === false ) {
1604 - $str = FrmAppHelper::maybe_utf8_encode( $str );
1529 + $str = utf8_encode( $str );
1605 1530 }
1606 1531
1607 1532 if ( is_numeric( $str ) ) {
1608 1533 return $str;