PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 3.06.06
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v3.06.06
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/controllers/FrmXMLController.php +73 -304 6.43.06.06 View file →
@@ -1,29 +1,20 @@
1 1 <?php
2 -if ( ! defined( 'ABSPATH' ) ) {
3 - die( 'You are not allowed to call this page directly.' );
4 -}
5 2
6 3 class FrmXMLController {
7 4
8 - /**
9 - * @return void
10 - */
11 5 public static function menu() {
12 6 add_submenu_page( 'formidable', 'Formidable | ' . __( 'Import/Export', 'formidable' ), __( 'Import/Export', 'formidable' ), 'frm_edit_forms', 'formidable-import', 'FrmXMLController::route' );
13 7 }
14 8
15 - /**
16 - * @return void
17 - */
18 9 public static function add_default_templates() {
19 - if ( FrmXMLHelper::check_if_libxml_disable_entity_loader_exists() ) {
10 + if ( ! function_exists( 'libxml_disable_entity_loader' ) ) {
20 11 // XML import is not enabled on your server
21 12 return;
22 13 }
23 14
24 15 $set_err = libxml_use_internal_errors( true );
25 - $loader = FrmXMLHelper::maybe_libxml_disable_entity_loader( true );
16 + $loader = libxml_disable_entity_loader( true );
26 17
27 18 $files = apply_filters( 'frm_default_templates_files', array() );
28 19
29 20 foreach ( (array) $files as $file ) {
@@ -33,41 +24,23 @@
33 24
34 25 unset( $files );
35 26
36 27 libxml_use_internal_errors( $set_err );
37 - FrmXMLHelper::maybe_libxml_disable_entity_loader( $loader );
28 + libxml_disable_entity_loader( $loader );
38 29 }
39 30
31 +
40 32 /**
41 33 * Use the template link to install the XML template
42 34 *
43 35 * @since 3.06
44 - * @return void
45 36 */
46 37 public static function install_template() {
47 - FrmAppHelper::permission_check( 'frm_edit_forms' );
38 + FrmAppHelper::permission_check( 'frm_create_forms' );
48 39 check_ajax_referer( 'frm_ajax', 'nonce' );
49 40
50 - if ( ! function_exists( 'simplexml_load_string' ) ) {
51 - $response = array(
52 - 'message' => __( 'Your server is missing the Simple XML extension. This is required to install a template.', 'formidable' ),
53 - );
54 - echo wp_json_encode( $response );
55 - wp_die();
56 - }
41 + $url = FrmAppHelper::get_param( 'xml', '', 'post', 'esc_url_raw' );
57 42
58 - $form = self::get_posted_form();
59 - $url = FrmAppHelper::get_param( 'xml', '', 'post', 'esc_url_raw' );
60 - self::override_url( $form, $url );
61 -
62 - if ( ! self::validate_xml_url( $url ) ) {
63 - $response = array(
64 - 'message' => __( 'The template you are trying to install could not be validated.', 'formidable' ),
65 - );
66 - echo wp_json_encode( $response );
67 - wp_die();
68 - }
69 -
70 43 $response = wp_remote_get( $url );
71 44 $body = wp_remote_retrieve_body( $response );
72 45 $xml = simplexml_load_string( $body );
73 46
@@ -72,9 +45,9 @@
72 45 $xml = simplexml_load_string( $body );
73 46
74 47 if ( ! $xml ) {
75 48 $response = array(
76 - 'message' => __( 'There was an error reading the form template.', 'formidable' ),
49 + 'message' => __( 'There was an error reading the form template', 'formidable' ),
77 50 );
78 51 echo wp_json_encode( $response );
79 52 wp_die();
80 53 }
@@ -80,171 +53,35 @@
80 53 }
81 54
82 55 self::set_new_form_name( $xml );
83 56
84 - $imported = FrmXMLHelper::import_xml_now( $xml, true );
85 - if ( ! empty( $imported['form_status'] ) ) {
57 + $imported = FrmXMLHelper::import_xml_now( $xml );
58 + if ( isset( $imported['form_status'] ) && ! empty( $imported['form_status'] ) ) {
86 59 // Get the last form id in case there are child forms.
87 60 end( $imported['form_status'] );
88 - $form_id = key( $imported['form_status'] );
61 + $form_id = key( $imported['form_status'] );
89 62 $response = array(
90 63 'id' => $form_id,
91 - 'redirect' => FrmForm::get_edit_link( $form_id ),
64 + 'redirect' => admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form_id ) ),
92 65 'success' => 1,
93 66 );
94 - if ( ! empty( $imported['imported']['posts'] ) ) {
95 - // Return the link to the last page created.
96 - $pages = $imported['posts'];
97 - }
98 -
99 - if ( ! empty( $form ) ) {
100 - // Create selected pages with the correct shortcodes.
101 - $pages = self::create_pages_for_import( $form );
102 - }
103 -
104 - if ( isset( $pages ) && ! empty( $pages ) ) {
105 - $post_id = end( $pages );
106 - $response['redirect'] = get_permalink( $post_id );
107 - }
108 67 } else {
109 - if ( isset( $imported['error'] ) ) {
110 - $message = $imported['error'];
111 - } else {
112 - $message = __( 'There was an error importing form', 'formidable' );
113 - }
114 68 $response = array(
115 - 'message' => $message,
69 + 'message' => __( 'There was an error importing form', 'formidable' ),
116 70 );
117 -
118 71 }
119 72
120 - $response = apply_filters( 'frm_xml_response', $response, compact( 'form', 'imported' ) );
121 -
122 73 echo wp_json_encode( $response );
123 74 wp_die();
124 75 }
125 76
126 77 /**
127 - * Make sure that the XML file we're trying to load is in fact an XML file, and that it's coming from our S3 bucket.
128 - * This is to make sure that the URL can't be exploited for a SSRF attack.
129 - *
130 - * @since 5.5.5
131 - * @param string $url
132 - *
133 - * @return bool True on success, False on error.
134 - */
135 - private static function validate_xml_url( $url ) {
136 - return FrmAppHelper::validate_url_is_in_s3_bucket( $url, 'xml' );
137 - }
138 -
139 - /**
140 - * @since 4.06.02
141 - *
142 - * @return mixed
143 - */
144 - private static function get_posted_form() {
145 - $form = FrmAppHelper::get_param( 'form', '', 'post', 'wp_unslash' );
146 - if ( empty( $form ) ) {
147 - return $form;
148 - }
149 - $form = json_decode( $form, true );
150 - return $form;
151 - }
152 -
153 - /**
154 - * Get a different URL depending on the selection in the form.
155 - *
156 - * @since 4.06.02
157 - *
158 - * @return void
159 - */
160 - private static function override_url( $form, &$url ) {
161 - $selected_form = self::get_selected_in_form( $form, 'form' );
162 - if ( empty( $selected_form ) ) {
163 - return;
164 - }
165 -
166 - $selected_xml = isset( $form['xml'] ) && isset( $form['xml'][ $selected_form ] ) ? $form['xml'][ $selected_form ] : '';
167 - if ( empty( $selected_xml ) || strpos( $selected_xml, 'http' ) !== 0 ) {
168 - return;
169 - }
170 -
171 - $url = $selected_xml;
172 - }
173 -
174 - /**
175 - * @since 4.06.02
176 - *
177 - * @param string $value
178 - * @param array $form
179 - */
180 - private static function get_selected_in_form( $form, $value = 'form' ) {
181 - if ( ! empty( $form ) && isset( $form[ $value ] ) && ! empty( $form[ $value ] ) ) {
182 - return $form[ $value ];
183 - }
184 -
185 - return '';
186 - }
187 -
188 - /**
189 - * @since 4.06.02
190 - *
191 - * @param array $form The posted form values.
192 - *
193 - * @return array The array of created pages.
194 - */
195 - private static function create_pages_for_import( $form ) {
196 - if ( ! isset( $form['pages'] ) || empty( $form['pages'] ) ) {
197 - return;
198 - }
199 -
200 - $form_key = self::get_selected_in_form( $form, 'form' );
201 - $view_keys = self::get_selected_in_form( $form, 'view' );
202 -
203 - $page_ids = array();
204 - foreach ( (array) $form['pages'] as $for => $name ) {
205 - if ( empty( $name ) ) {
206 - // Don't create a page if no title is given.
207 - continue;
208 - }
209 -
210 - if ( $for === 'view' ) {
211 - $item_key = is_array( $view_keys ) ? $view_keys[ $form_key ] : $view_keys;
212 - $shortcode = '[display-frm-data id=%1$s filter=limited]';
213 - } elseif ( $for === 'form' ) {
214 - $item_key = $form_key;
215 - $shortcode = '[formidable id=%1$s]';
216 - } else {
217 - $item_key = self::get_selected_in_form( $form, 'form' );
218 - $shortcode = '[' . esc_html( $for ) . ' id=%1$s]';
219 - }
220 -
221 - if ( empty( $item_key ) ) {
222 - // Don't create it if the shortcode won't show anything.
223 - continue;
224 - }
225 -
226 - $page_ids[ $for ] = wp_insert_post(
227 - array(
228 - 'post_title' => $name,
229 - 'post_type' => 'page',
230 - 'post_content' => sprintf( $shortcode, $item_key ),
231 - )
232 - );
233 - }
234 -
235 - return $page_ids;
236 - }
237 -
238 - /**
239 78 * Change the name of the last form that is not a child.
240 79 * This will allow for lookup fields and embedded forms
241 80 * since we redirect to the last form.
242 81 *
243 82 * @since 3.06
244 - *
245 83 * @param object $xml The values included in the XML.
246 - * @return void
247 84 */
248 85 private static function set_new_form_name( &$xml ) {
249 86 if ( ! isset( $xml->form ) ) {
250 87 return;
@@ -249,61 +86,44 @@
249 86 if ( ! isset( $xml->form ) ) {
250 87 return;
251 88 }
252 89
253 - $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' );
254 - $description = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' );
255 - if ( ! $name && ! $description ) {
256 - return;
257 - }
258 -
259 90 // Get the main form ID.
260 91 $set_name = 0;
261 92 foreach ( $xml->form as $form ) {
262 - if ( empty( $form->parent_form_id ) ) {
263 - $set_name = (int) $form->id;
93 + if ( ! isset( $form->parent_form_id ) || empty( $form->parent_form_id ) ) {
94 + $set_name = $form->id;
264 95 }
265 96 }
266 97
267 98 foreach ( $xml->form as $form ) {
268 99 // Maybe set the form name if this isn't a child form.
269 - if ( $set_name === (int) $form->id ) {
270 - $form->name = $name;
271 - $form->description = $description;
100 + if ( $set_name == $form->id ) {
101 + $form->name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' );
102 + $form->description = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' );
272 103 }
273 104
274 105 // Use a unique key to prevent editing existing form.
275 - $sanitized_form_name = sanitize_title( $form->name );
276 - $form->form_key = FrmAppHelper::get_unique_key( $sanitized_form_name, 'frm_forms', 'form_key' );
106 + $name = sanitize_title( $form->name );
107 + $form->form_key = FrmAppHelper::get_unique_key( $name, 'frm_forms', 'form_key' );
277 108 }
278 109 }
279 110
280 - /**
281 - * @return void
282 - */
283 111 public static function route() {
284 112 $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
285 113 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
286 - FrmAppHelper::include_svg();
287 -
288 114 if ( 'import_xml' === $action ) {
289 - self::import_xml();
115 + return self::import_xml();
290 116 } elseif ( 'export_xml' === $action ) {
291 - self::export_xml();
117 + return self::export_xml();
292 118 } elseif ( apply_filters( 'frm_xml_route', true, $action ) ) {
293 - self::form();
119 + return self::form();
294 120 }
295 121 }
296 122
297 - /**
298 - * @param string[] $errors
299 - * @param string $message
300 - *
301 - * @return void
302 - */
303 123 public static function form( $errors = array(), $message = '' ) {
304 124 $where = array(
305 - 'status' => array( null, '', 'published' ),
125 + 'status' => array( null, '', 'published' ),
306 126 );
307 127 $forms = FrmForm::getAll( $where, 'name' );
308 128
309 129 $export_types = array(
@@ -325,16 +145,13 @@
325 145 ),
326 146 );
327 147 $export_format = apply_filters( 'frm_export_formats', $export_format );
328 148
329 - include FrmAppHelper::plugin_path() . '/classes/views/xml/import_form.php';
149 + include( FrmAppHelper::plugin_path() . '/classes/views/xml/import_form.php' );
330 150 }
331 151
332 - /**
333 - * @return void
334 - */
335 152 public static function import_xml() {
336 - $errors = array();
153 + $errors = array();
337 154 $message = '';
338 155
339 156 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'import-xml', 'import-xml-nonce' );
340 157 if ( false !== $permission_error ) {
@@ -339,9 +156,8 @@
339 156 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'import-xml', 'import-xml-nonce' );
340 157 if ( false !== $permission_error ) {
341 158 $errors[] = $permission_error;
342 159 self::form( $errors );
343 -
344 160 return;
345 161 }
346 162
347 163 $has_file = isset( $_FILES ) && isset( $_FILES['frm_import_file'] ) && ! empty( $_FILES['frm_import_file']['name'] ) && ! empty( $_FILES['frm_import_file']['size'] ) && (int) $_FILES['frm_import_file']['size'] > 0;
@@ -347,20 +163,17 @@
347 163 $has_file = isset( $_FILES ) && isset( $_FILES['frm_import_file'] ) && ! empty( $_FILES['frm_import_file']['name'] ) && ! empty( $_FILES['frm_import_file']['size'] ) && (int) $_FILES['frm_import_file']['size'] > 0;
348 164 if ( ! $has_file ) {
349 165 $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' );
350 166 self::form( $errors );
351 -
352 167 return;
353 168 }
354 169
355 - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
356 - $file = isset( $_FILES['frm_import_file']['tmp_name'] ) ? sanitize_option( 'upload_path', $_FILES['frm_import_file']['tmp_name'] ) : '';
170 + $file = isset( $_FILES['frm_import_file']['tmp_name'] ) ? $_FILES['frm_import_file']['tmp_name'] : '';
357 171
358 172 if ( ! is_uploaded_file( $file ) ) {
359 173 unset( $file );
360 174 $errors[] = __( 'The file does not exist, please try again.', 'formidable' );
361 175 self::form( $errors );
362 -
363 176 return;
364 177 }
365 178
366 179 //add_filter('upload_mimes', 'FrmXMLController::allow_mime');
@@ -373,28 +186,24 @@
373 186 ),
374 187 );
375 188 $export_format = apply_filters( 'frm_export_formats', $export_format );
376 189
377 - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
378 - $file_type = sanitize_option( 'upload_path', $_FILES['frm_import_file']['name'] );
379 - $file_type = strtolower( pathinfo( $file_type, PATHINFO_EXTENSION ) );
190 + $file_type = strtolower( pathinfo( $_FILES['frm_import_file']['name'], PATHINFO_EXTENSION ) );
380 191 if ( 'xml' !== $file_type && isset( $export_format[ $file_type ] ) ) {
381 192 // allow other file types to be imported
382 193 do_action( 'frm_before_import_' . $file_type );
383 -
384 194 return;
385 195 }
386 196 unset( $file_type );
387 197
388 - if ( FrmXMLHelper::check_if_libxml_disable_entity_loader_exists() ) {
198 + if ( ! function_exists( 'libxml_disable_entity_loader' ) ) {
389 199 $errors[] = __( 'XML import is not enabled on your server with the libxml_disable_entity_loader function.', 'formidable' );
390 200 self::form( $errors );
391 -
392 201 return;
393 202 }
394 203
395 204 $set_err = libxml_use_internal_errors( true );
396 - $loader = FrmXMLHelper::maybe_libxml_disable_entity_loader( true );
205 + $loader = libxml_disable_entity_loader( true );
397 206
398 207 $result = FrmXMLHelper::import_xml( $file );
399 208 FrmXMLHelper::parse_message( $result, $message, $errors );
400 209
@@ -400,16 +209,13 @@
400 209
401 210 unset( $file );
402 211
403 212 libxml_use_internal_errors( $set_err );
404 - FrmXMLHelper::maybe_libxml_disable_entity_loader( $loader );
213 + libxml_disable_entity_loader( $loader );
405 214
406 215 self::form( $errors, $message );
407 216 }
408 217
409 - /**
410 - * @return void
411 - */
412 218 public static function export_xml() {
413 219 $error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'export-xml', 'export-xml-nonce' );
414 220 if ( ! empty( $error ) ) {
415 221 wp_die( esc_html( $error ) );
@@ -414,10 +220,10 @@
414 220 if ( ! empty( $error ) ) {
415 221 wp_die( esc_html( $error ) );
416 222 }
417 223
418 - $ids = FrmAppHelper::get_post_param( 'frm_export_forms', array(), 'sanitize_text_field' );
419 - $type = FrmAppHelper::get_post_param( 'type', array(), 'sanitize_text_field' );
224 + $ids = FrmAppHelper::get_post_param( 'frm_export_forms', array() );
225 + $type = FrmAppHelper::get_post_param( 'type', array() );
420 226 $format = FrmAppHelper::get_post_param( 'format', 'xml', 'sanitize_title' );
421 227
422 228 if ( ! headers_sent() && ! $type ) {
423 229 wp_redirect( esc_url_raw( admin_url( 'admin.php?page=formidable-import' ) ) );
@@ -434,15 +240,8 @@
434 240
435 241 wp_die();
436 242 }
437 243
438 - /**
439 - * @param array $args
440 - *
441 - * @psalm-param array{ids?: mixed} $args
442 - *
443 - * @return void
444 - */
445 244 public static function generate_xml( $type, $args = array() ) {
446 245 global $wpdb;
447 246
448 247 self::prepare_types_array( $type );
@@ -447,19 +246,19 @@
447 246
448 247 self::prepare_types_array( $type );
449 248
450 249 $tables = array(
451 - 'items' => $wpdb->prefix . 'frm_items',
452 - 'forms' => $wpdb->prefix . 'frm_forms',
453 - 'posts' => $wpdb->posts,
454 - 'styles' => $wpdb->posts,
455 - 'actions' => $wpdb->posts,
250 + 'items' => $wpdb->prefix . 'frm_items',
251 + 'forms' => $wpdb->prefix . 'frm_forms',
252 + 'posts' => $wpdb->posts,
253 + 'styles' => $wpdb->posts,
254 + 'actions' => $wpdb->posts,
456 255 );
457 256
458 257 $defaults = array(
459 258 'ids' => false,
460 259 );
461 - $args = wp_parse_args( $args, $defaults );
260 + $args = wp_parse_args( $args, $defaults );
462 261
463 262 // Make sure ids are numeric.
464 263 if ( is_array( $args['ids'] ) && ! empty( $args['ids'] ) ) {
465 264 $args['ids'] = array_filter( $args['ids'], 'is_numeric' );
@@ -468,12 +267,12 @@
468 267 $records = array();
469 268
470 269 foreach ( $type as $tb_type ) {
471 270 $where = array();
472 - $join = '';
271 + $join = '';
473 272 $table = $tables[ $tb_type ];
474 273
475 - $select = $table . '.id';
274 + $select = $table . '.id';
476 275 $query_vars = array();
477 276
478 277 switch ( $tb_type ) {
479 278 case 'forms':
@@ -479,10 +278,10 @@
479 278 case 'forms':
480 279 //add forms
481 280 if ( $args['ids'] ) {
482 281 $where[] = array(
483 - 'or' => 1,
484 - $table . '.id' => $args['ids'],
282 + 'or' => 1,
283 + $table . '.id' => $args['ids'],
485 284 $table . '.parent_form_id' => $args['ids'],
486 285 );
487 286 } else {
488 287 $where[ $table . '.status !' ] = 'draft';
@@ -488,9 +287,9 @@
488 287 $where[ $table . '.status !' ] = 'draft';
489 288 }
490 289 break;
491 290 case 'actions':
492 - $select = $table . '.ID';
291 + $select = $table . '.ID';
493 292 $where['post_type'] = FrmFormActionsController::$action_post_type;
494 293 if ( ! empty( $args['ids'] ) ) {
495 294 $where['menu_order'] = $args['ids'];
496 295 }
@@ -495,22 +294,22 @@
495 294 $where['menu_order'] = $args['ids'];
496 295 }
497 296 break;
498 297 case 'items':
499 - // $join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)";
298 + //$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)";
500 299 if ( $args['ids'] ) {
501 300 $where[ $table . '.form_id' ] = $args['ids'];
502 301 }
503 302 break;
504 303 case 'styles':
505 - // Loop through all exported forms and get their selected style IDs.
506 - $frm_style = new FrmStyle();
304 + // Loop through all exported forms and get their selected style IDs
305 + $frm_style = new FrmStyle();
507 306 $default_style = $frm_style->get_default_style();
508 - $form_ids = $args['ids'];
509 - $style_ids = array();
307 + $form_ids = $args['ids'];
308 + $style_ids = array();
510 309 foreach ( $form_ids as $form_id ) {
511 310 $form_data = FrmForm::getOne( $form_id );
512 - // For forms that have not been updated while running 2.0, check if custom_style is set.
311 + // For forms that have not been updated while running 2.0, check if custom_style is set
513 312 if ( isset( $form_data->options['custom_style'] ) ) {
514 313 if ( 1 === absint( $form_data->options['custom_style'] ) ) {
515 314 $style_ids[] = $default_style->ID;
516 315 } else {
@@ -518,19 +317,19 @@
518 317 }
519 318 }
520 319 unset( $form_id, $form_data );
521 320 }
522 - $select = $table . '.ID';
321 + $select = $table . '.ID';
523 322 $where['post_type'] = 'frm_styles';
524 323
525 - // Only export selected styles.
324 + // Only export selected styles
526 325 if ( ! empty( $style_ids ) ) {
527 326 $where['ID'] = $style_ids;
528 327 }
529 328 break;
530 329 default:
531 - $select = $table . '.ID';
532 - $join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)';
330 + $select = $table . '.ID';
331 + $join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)';
533 332 $where['pm.meta_key'] = 'frm_form_id';
534 333
535 334 if ( empty( $args['ids'] ) ) {
536 335 $where['pm.meta_value >'] = 1;
@@ -549,14 +348,11 @@
549 348 header( 'Content-Disposition: attachment; filename=' . $filename );
550 349 header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
551 350
552 351 echo '<?xml version="1.0" encoding="' . esc_attr( get_bloginfo( 'charset' ) ) . "\" ?>\n";
553 - include FrmAppHelper::plugin_path() . '/classes/views/xml/xml.php';
352 + include( FrmAppHelper::plugin_path() . '/classes/views/xml/xml.php' );
554 353 }
555 354
556 - /**
557 - * @return void
558 - */
559 355 private static function prepare_types_array( &$type ) {
560 356 $type = (array) $type;
561 357 if ( ! in_array( 'forms', $type ) && ( in_array( 'items', $type ) || in_array( 'posts', $type ) ) ) {
562 358 // make sure the form is included if there are entries
@@ -574,12 +370,8 @@
574 370 * Use the nme of the form if only one form is exported.
575 371 *
576 372 * @since 3.06
577 373 *
578 - * @param array $type
579 - * @param array $records
580 - * @param array $args
581 - *
582 374 * @return string
583 375 */
584 376 private static function get_file_name( $args, $type, $records ) {
585 377 $has_one_form = isset( $records['forms'] ) && ! empty( $records['forms'] ) && count( $args['ids'] ) === 1;
@@ -585,16 +377,13 @@
585 377 $has_one_form = isset( $records['forms'] ) && ! empty( $records['forms'] ) && count( $args['ids'] ) === 1;
586 378 if ( $has_one_form ) {
587 379 // one form is being exported
588 380 $selected_form_id = reset( $args['ids'] );
589 - $filename = 'form-' . $selected_form_id . '.xml';
590 -
591 381 foreach ( $records['forms'] as $form_id ) {
592 382 $filename = 'form-' . $form_id . '.xml';
593 383 if ( $selected_form_id === $form_id ) {
594 - $form = FrmForm::getOne( $form_id );
595 - $filename = $form->name !== '' ? $form->name : $form->form_key;
596 - $filename = sanitize_title( $filename ) . '-form.xml';
384 + $form = FrmForm::getOne( $form_id );
385 + $filename = sanitize_title( $form->name ) . '-form.xml';
597 386 break;
598 387 }
599 388 }
600 389 } else {
@@ -602,24 +391,13 @@
602 391
603 392 if ( ! empty( $sitename ) ) {
604 393 $sitename .= '.';
605 394 }
606 - $filename = $sitename . 'formidable.' . gmdate( 'Y-m-d' ) . '.xml';
395 + $filename = $sitename . 'formidable.' . date( 'Y-m-d' ) . '.xml';
607 396 }
608 -
609 - /**
610 - * @since 5.3
611 - *
612 - * @param string $filename
613 - */
614 - return apply_filters( 'frm_xml_filename', $filename );
397 + return $filename;
615 398 }
616 399
617 - /**
618 - * @param array $atts
619 - *
620 - * @return void
621 - */
622 400 public static function generate_csv( $atts ) {
623 401 $form_ids = $atts['ids'];
624 402 if ( empty( $form_ids ) ) {
625 403 wp_die( esc_html__( 'Please select a form', 'formidable' ) );
@@ -630,10 +408,8 @@
630 408 /**
631 409 * Export to CSV
632 410 *
633 411 * @since 2.0.19
634 - *
635 - * @return void
636 412 */
637 413 public static function csv( $form_id = false, $search = '', $fid = '' ) {
638 414 FrmAppHelper::permission_check( 'frm_view_entries' );
639 415
@@ -638,10 +414,10 @@
638 414 FrmAppHelper::permission_check( 'frm_view_entries' );
639 415
640 416 if ( ! $form_id ) {
641 417 $form_id = FrmAppHelper::get_param( 'form', '', 'get', 'sanitize_text_field' );
642 - $search = FrmAppHelper::get_param( ( isset( $_REQUEST['s'] ) ? 's' : 'search' ), '', 'get', 'sanitize_text_field' );
643 - $fid = FrmAppHelper::get_param( 'fid', '', 'get', 'sanitize_text_field' );
418 + $search = FrmAppHelper::get_param( ( isset( $_REQUEST['s'] ) ? 's' : 'search' ), '', 'get', 'sanitize_text_field' );
419 + $fid = FrmAppHelper::get_param( 'fid', '', 'get', 'sanitize_text_field' );
644 420 }
645 421
646 422 set_time_limit( 0 ); //Remove time limit to execute this function
647 423 $mem_limit = str_replace( 'M', '', ini_get( 'memory_limit' ) );
@@ -651,15 +427,10 @@
651 427
652 428 global $wpdb;
653 429
654 430 $form = FrmForm::getOne( $form_id );
431 + $form_id = $form->id;
655 432
656 - if ( ! $form ) {
657 - esc_html_e( 'Form not found.', 'formidable' );
658 - wp_die();
659 - }
660 -
661 - $form_id = $form->id;
662 433 $form_cols = self::get_fields_for_csv_export( $form_id, $form );
663 434
664 435 $item_id = FrmAppHelper::get_param( 'item_id', 0, 'get', 'sanitize_text_field' );
665 436 if ( ! empty( $item_id ) ) {
@@ -694,28 +465,26 @@
694 465 wp_die();
695 466 }
696 467
697 468 /**
698 - * Get the fields that should be included in the CSV export
699 - *
700 - * @since 2.0.19
701 - * @since 5.0.16 function went from private to public.
702 - *
703 - * @param int $form_id
704 - * @param object $form
705 - *
706 - * @return array $csv_fields
707 - */
708 - public static function get_fields_for_csv_export( $form_id, $form ) {
709 - $csv_fields = FrmField::get_all_for_form( $form_id, '', 'include', 'include' );
469 + * Get the fields that should be included in the CSV export
470 + *
471 + * @since 2.0.19
472 + *
473 + * @param int $form_id
474 + * @param object $form
475 + * @return array $csv_fields
476 + */
477 + private static function get_fields_for_csv_export( $form_id, $form ) {
478 + $csv_fields = FrmField::get_all_for_form( $form_id, '', 'include', 'include' );
710 479 $no_export_fields = FrmField::no_save_fields();
711 480 foreach ( $csv_fields as $k => $f ) {
712 - if ( in_array( $f->type, $no_export_fields, true ) ) {
481 + if ( in_array( $f->type, $no_export_fields ) ) {
713 482 unset( $csv_fields[ $k ] );
714 483 }
715 484 }
716 485
717 - return apply_filters( 'frm_fields_for_csv_export', $csv_fields, compact( 'form' ) );
486 + return $csv_fields;
718 487 }
719 488
720 489 public static function allow_mime( $mimes ) {
721 490 if ( ! isset( $mimes['csv'] ) ) {