PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.32
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.32
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 +149 -86 6.36.32 View file →
@@ -8,9 +8,9 @@
8 8 /**
9 9 * @return void
10 10 */
11 11 public static function menu() {
12 - add_submenu_page( 'formidable', 'Formidable | ' . __( 'Import/Export', 'formidable' ), __( 'Import/Export', 'formidable' ), 'frm_edit_forms', 'formidable-import', 'FrmXMLController::route' );
12 + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Import/Export', 'formidable' ), __( 'Import/Export', 'formidable' ), 'frm_edit_forms', 'formidable-import', 'FrmXMLController::route' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
13 13 }
14 14
15 15 /**
16 16 * @return void
@@ -16,17 +16,16 @@
16 16 * @return void
17 17 */
18 18 public static function add_default_templates() {
19 19 if ( FrmXMLHelper::check_if_libxml_disable_entity_loader_exists() ) {
20 - // XML import is not enabled on your server
20 + // XML import is not enabled on your server.
21 21 return;
22 22 }
23 23
24 24 $set_err = libxml_use_internal_errors( true );
25 25 $loader = FrmXMLHelper::maybe_libxml_disable_entity_loader( true );
26 + $files = apply_filters( 'frm_default_templates_files', array() );
26 27
27 - $files = apply_filters( 'frm_default_templates_files', array() );
28 -
29 28 foreach ( (array) $files as $file ) {
30 29 FrmXMLHelper::import_xml( $file );
31 30 unset( $file );
32 31 }
@@ -40,8 +39,9 @@
40 39 /**
41 40 * Use the template link to install the XML template
42 41 *
43 42 * @since 3.06
43 + *
44 44 * @return void
45 45 */
46 46 public static function install_template() {
47 47 FrmAppHelper::permission_check( 'frm_edit_forms' );
@@ -81,45 +81,44 @@
81 81
82 82 self::set_new_form_name( $xml );
83 83
84 84 $imported = FrmXMLHelper::import_xml_now( $xml, true );
85 +
85 86 if ( ! empty( $imported['form_status'] ) ) {
86 87 // Get the last form id in case there are child forms.
87 - end( $imported['form_status'] );
88 - $form_id = key( $imported['form_status'] );
88 + $form_id = array_key_last( $imported['form_status'] );
89 89 $response = array(
90 90 'id' => $form_id,
91 - 'redirect' => FrmForm::get_edit_link( $form_id ),
91 + 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true',
92 92 'success' => 1,
93 93 );
94 +
94 95 if ( ! empty( $imported['imported']['posts'] ) ) {
95 96 // Return the link to the last page created.
96 97 $pages = $imported['posts'];
97 98 }
98 99
99 - if ( ! empty( $form ) ) {
100 + if ( $form ) {
100 101 // Create selected pages with the correct shortcodes.
101 102 $pages = self::create_pages_for_import( $form );
102 103 }
103 104
104 - if ( isset( $pages ) && ! empty( $pages ) ) {
105 - $post_id = end( $pages );
105 + if ( ! empty( $pages ) ) {
106 + $post_id = end( $pages );
106 107 $response['redirect'] = get_permalink( $post_id );
107 108 }
108 109 } else {
109 - if ( isset( $imported['error'] ) ) {
110 - $message = $imported['error'];
111 - } else {
112 - $message = __( 'There was an error importing form', 'formidable' );
113 - }
110 + $message = $imported['error'] ?? __( 'There was an error importing form', 'formidable' );
114 111 $response = array(
115 112 'message' => $message,
116 113 );
114 + }//end if
117 115
118 - }
116 + /**
117 + * @since 6.18 Added `url` to the $args.
118 + */
119 + $response = apply_filters( 'frm_xml_response', $response, compact( 'form', 'imported', 'url' ) );
119 120
120 - $response = apply_filters( 'frm_xml_response', $response, compact( 'form', 'imported' ) );
121 -
122 121 echo wp_json_encode( $response );
123 122 wp_die();
124 123 }
125 124
@@ -127,8 +126,9 @@
127 126 * 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 127 * This is to make sure that the URL can't be exploited for a SSRF attack.
129 128 *
130 129 * @since 5.5.5
130 + *
131 131 * @param string $url
132 132 *
133 133 * @return bool True on success, False on error.
134 134 */
@@ -142,13 +142,9 @@
142 142 * @return mixed
143 143 */
144 144 private static function get_posted_form() {
145 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;
146 + return $form ? json_decode( $form, true ) : $form;
151 147 }
152 148
153 149 /**
154 150 * Get a different URL depending on the selection in the form.
@@ -154,18 +150,23 @@
154 150 * Get a different URL depending on the selection in the form.
155 151 *
156 152 * @since 4.06.02
157 153 *
154 + * @param array $form The posted form values.
155 + * @param string $url The URL to override.
156 + *
158 157 * @return void
159 158 */
160 159 private static function override_url( $form, &$url ) {
161 160 $selected_form = self::get_selected_in_form( $form, 'form' );
162 - if ( empty( $selected_form ) ) {
161 +
162 + if ( ! $selected_form ) {
163 163 return;
164 164 }
165 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 ) {
166 + $selected_xml = isset( $form['xml'] ) && isset( $form['xml'][ $selected_form ] ) ? $form['xml'][ $selected_form ] : '';
167 +
168 + if ( ! $selected_xml || ! str_starts_with( $selected_xml, 'http' ) ) {
168 169 return;
169 170 }
170 171
171 172 $url = $selected_xml;
@@ -173,13 +174,15 @@
173 174
174 175 /**
175 176 * @since 4.06.02
176 177 *
178 + * @param array $form
177 179 * @param string $value
178 - * @param array $form
180 + *
181 + * @return array|string
179 182 */
180 183 private static function get_selected_in_form( $form, $value = 'form' ) {
181 - if ( ! empty( $form ) && isset( $form[ $value ] ) && ! empty( $form[ $value ] ) ) {
184 + if ( $form && ! empty( $form[ $value ] ) ) {
182 185 return $form[ $value ];
183 186 }
184 187
185 188 return '';
@@ -189,21 +192,21 @@
189 192 * @since 4.06.02
190 193 *
191 194 * @param array $form The posted form values.
192 195 *
193 - * @return array The array of created pages.
196 + * @return array|null The array of created pages.
194 197 */
195 198 private static function create_pages_for_import( $form ) {
196 - if ( ! isset( $form['pages'] ) || empty( $form['pages'] ) ) {
197 - return;
199 + if ( empty( $form['pages'] ) ) {
200 + return null;
198 201 }
199 202
200 - $form_key = self::get_selected_in_form( $form, 'form' );
203 + $form_key = self::get_selected_in_form( $form, 'form' );
201 204 $view_keys = self::get_selected_in_form( $form, 'view' );
205 + $page_ids = array();
202 206
203 - $page_ids = array();
204 207 foreach ( (array) $form['pages'] as $for => $name ) {
205 - if ( empty( $name ) ) {
208 + if ( ! $name ) {
206 209 // Don't create a page if no title is given.
207 210 continue;
208 211 }
209 212
@@ -210,9 +213,9 @@
210 213 if ( $for === 'view' ) {
211 214 $item_key = is_array( $view_keys ) ? $view_keys[ $form_key ] : $view_keys;
212 215 $shortcode = '[display-frm-data id=%1$s filter=limited]';
213 216 } elseif ( $for === 'form' ) {
214 - $item_key = $form_key;
217 + $item_key = $form_key;
215 218 $shortcode = '[formidable id=%1$s]';
216 219 } else {
217 220 $item_key = self::get_selected_in_form( $form, 'form' );
218 221 $shortcode = '[' . esc_html( $for ) . ' id=%1$s]';
@@ -229,9 +232,9 @@
229 232 'post_type' => 'page',
230 233 'post_content' => sprintf( $shortcode, $item_key ),
231 234 )
232 235 );
233 - }
236 + }//end foreach
234 237
235 238 return $page_ids;
236 239 }
237 240
@@ -242,8 +245,9 @@
242 245 *
243 246 * @since 3.06
244 247 *
245 248 * @param object $xml The values included in the XML.
249 + *
246 250 * @return void
247 251 */
248 252 private static function set_new_form_name( &$xml ) {
249 253 if ( ! isset( $xml->form ) ) {
@@ -251,8 +255,9 @@
251 255 }
252 256
253 257 $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' );
254 258 $description = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' );
259 +
255 260 if ( ! $name && ! $description ) {
256 261 return;
257 262 }
258 263
@@ -257,8 +262,9 @@
257 262 }
258 263
259 264 // Get the main form ID.
260 265 $set_name = 0;
266 +
261 267 foreach ( $xml->form as $form ) {
262 268 if ( empty( $form->parent_form_id ) ) {
263 269 $set_name = (int) $form->id;
264 270 }
@@ -295,15 +301,15 @@
295 301 }
296 302
297 303 /**
298 304 * @param string[] $errors
299 - * @param string $message
305 + * @param string $message
300 306 *
301 307 * @return void
302 308 */
303 309 public static function form( $errors = array(), $message = '' ) {
304 310 $where = array(
305 - 'status' => array( null, '', 'published' ),
311 + 'status' => array( null, '', 'published' ),
306 312 );
307 313 $forms = FrmForm::getAll( $where, 'name' );
308 314
309 315 $export_types = array(
@@ -332,12 +338,12 @@
332 338 /**
333 339 * @return void
334 340 */
335 341 public static function import_xml() {
336 - $errors = array();
337 - $message = '';
342 + $errors = array();
343 + $message = '';
344 + $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'import-xml', 'import-xml-nonce' );
338 345
339 - $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'import-xml', 'import-xml-nonce' );
340 346 if ( false !== $permission_error ) {
341 347 $errors[] = $permission_error;
342 348 self::form( $errors );
343 349
@@ -343,9 +349,11 @@
343 349
344 350 return;
345 351 }
346 352
347 - $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;
353 + // phpcs:ignore WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
354 + $has_file = ! empty( $_FILES['frm_import_file'] ) && ! empty( $_FILES['frm_import_file']['name'] ) && ! empty( $_FILES['frm_import_file']['size'] ) && (int) $_FILES['frm_import_file']['size'] > 0;
355 +
348 356 if ( ! $has_file ) {
349 357 $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' );
350 358 self::form( $errors );
351 359
@@ -351,9 +359,9 @@
351 359
352 360 return;
353 361 }
354 362
355 - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
363 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing
356 364 $file = isset( $_FILES['frm_import_file']['tmp_name'] ) ? sanitize_option( 'upload_path', $_FILES['frm_import_file']['tmp_name'] ) : '';
357 365
358 366 if ( ! is_uploaded_file( $file ) ) {
359 367 unset( $file );
@@ -362,10 +370,8 @@
362 370
363 371 return;
364 372 }
365 373
366 - //add_filter('upload_mimes', 'FrmXMLController::allow_mime');
367 -
368 374 $export_format = array(
369 375 'xml' => array(
370 376 'name' => 'XML',
371 377 'support' => 'forms',
@@ -373,13 +379,14 @@
373 379 ),
374 380 );
375 381 $export_format = apply_filters( 'frm_export_formats', $export_format );
376 382
377 - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
383 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing
378 384 $file_type = sanitize_option( 'upload_path', $_FILES['frm_import_file']['name'] );
379 385 $file_type = strtolower( pathinfo( $file_type, PATHINFO_EXTENSION ) );
386 +
380 387 if ( 'xml' !== $file_type && isset( $export_format[ $file_type ] ) ) {
381 - // allow other file types to be imported
388 + // Allow other file types to be imported
382 389 do_action( 'frm_before_import_' . $file_type );
383 390
384 391 return;
385 392 }
@@ -393,10 +400,9 @@
393 400 }
394 401
395 402 $set_err = libxml_use_internal_errors( true );
396 403 $loader = FrmXMLHelper::maybe_libxml_disable_entity_loader( true );
397 -
398 - $result = FrmXMLHelper::import_xml( $file );
404 + $result = FrmXMLHelper::import_xml( $file );
399 405 FrmXMLHelper::parse_message( $result, $message, $errors );
400 406
401 407 unset( $file );
402 408
@@ -410,9 +416,10 @@
410 416 * @return void
411 417 */
412 418 public static function export_xml() {
413 419 $error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'export-xml', 'export-xml-nonce' );
414 - if ( ! empty( $error ) ) {
420 +
421 + if ( $error ) {
415 422 wp_die( esc_html( $error ) );
416 423 }
417 424
418 425 $ids = FrmAppHelper::get_post_param( 'frm_export_forms', array(), 'sanitize_text_field' );
@@ -419,9 +426,9 @@
419 426 $type = FrmAppHelper::get_post_param( 'type', array(), 'sanitize_text_field' );
420 427 $format = FrmAppHelper::get_post_param( 'format', 'xml', 'sanitize_title' );
421 428
422 429 if ( ! headers_sent() && ! $type ) {
423 - wp_redirect( esc_url_raw( admin_url( 'admin.php?page=formidable-import' ) ) );
430 + wp_safe_redirect( esc_url_raw( admin_url( 'admin.php?page=formidable-import' ) ) );
424 431 die();
425 432 }
426 433
427 434 if ( 'xml' === $format ) {
@@ -435,19 +442,27 @@
435 442 wp_die();
436 443 }
437 444
438 445 /**
439 - * @param array $args
446 + * @param array<string>|string $type
447 + * @param array $args
440 448 *
441 449 * @psalm-param array{ids?: mixed} $args
442 450 *
443 451 * @return void
444 452 */
445 - public static function generate_xml( $type, $args = array() ) {
453 + public static function generate_xml( $type, $args = array() ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
446 454 global $wpdb;
447 455
448 456 self::prepare_types_array( $type );
449 457
458 + if ( ! is_array( $type ) ) {
459 + // This shouldn't be possible.
460 + // It is cast to array in prepare_types_array.
461 + // This is just for static analysis.
462 + return;
463 + }
464 +
450 465 $tables = array(
451 466 'items' => $wpdb->prefix . 'frm_items',
452 467 'forms' => $wpdb->prefix . 'frm_forms',
453 468 'posts' => $wpdb->posts,
@@ -460,9 +475,9 @@
460 475 );
461 476 $args = wp_parse_args( $args, $defaults );
462 477
463 478 // Make sure ids are numeric.
464 - if ( is_array( $args['ids'] ) && ! empty( $args['ids'] ) ) {
479 + if ( is_array( $args['ids'] ) && $args['ids'] ) {
465 480 $args['ids'] = array_filter( $args['ids'], 'is_numeric' );
466 481 }
467 482
468 483 $records = array();
@@ -467,18 +482,17 @@
467 482
468 483 $records = array();
469 484
470 485 foreach ( $type as $tb_type ) {
471 - $where = array();
472 - $join = '';
473 - $table = $tables[ $tb_type ];
474 -
486 + $where = array();
487 + $join = '';
488 + $table = $tables[ $tb_type ];
475 489 $select = $table . '.id';
476 490 $query_vars = array();
477 491
478 492 switch ( $tb_type ) {
479 493 case 'forms':
480 - //add forms
494 + // Add forms.
481 495 if ( $args['ids'] ) {
482 496 $where[] = array(
483 497 'or' => 1,
484 498 $table . '.id' => $args['ids'],
@@ -490,8 +504,9 @@
490 504 break;
491 505 case 'actions':
492 506 $select = $table . '.ID';
493 507 $where['post_type'] = FrmFormActionsController::$action_post_type;
508 +
494 509 if ( ! empty( $args['ids'] ) ) {
495 510 $where['menu_order'] = $args['ids'];
496 511 }
497 512 break;
@@ -506,10 +521,12 @@
506 521 $frm_style = new FrmStyle();
507 522 $default_style = $frm_style->get_default_style();
508 523 $form_ids = $args['ids'];
509 524 $style_ids = array();
525 +
510 526 foreach ( $form_ids as $form_id ) {
511 527 $form_data = FrmForm::getOne( $form_id );
528 +
512 529 // For forms that have not been updated while running 2.0, check if custom_style is set.
513 530 if ( isset( $form_data->options['custom_style'] ) ) {
514 531 if ( 1 === absint( $form_data->options['custom_style'] ) ) {
515 532 $style_ids[] = $default_style->ID;
@@ -518,13 +535,14 @@
518 535 }
519 536 }
520 537 unset( $form_id, $form_data );
521 538 }
539 +
522 540 $select = $table . '.ID';
523 541 $where['post_type'] = 'frm_styles';
524 542
525 543 // Only export selected styles.
526 - if ( ! empty( $style_ids ) ) {
544 + if ( $style_ids ) {
527 545 $where['ID'] = $style_ids;
528 546 }
529 547 break;
530 548 default:
@@ -536,15 +554,15 @@
536 554 $where['pm.meta_value >'] = 1;
537 555 } else {
538 556 $where['pm.meta_value'] = $args['ids'];
539 557 }
540 - }
558 + }//end switch
541 559
542 560 $records[ $tb_type ] = FrmDb::get_col( $table . $join, $where, $select );
543 561 unset( $tb_type );
544 - }
562 + }//end foreach
545 563
546 - $filename = self::get_file_name( $args, $type, $records );
564 + $filename = self::get_file_name( $args, $records );
547 565
548 566 header( 'Content-Description: File Transfer' );
549 567 header( 'Content-Disposition: attachment; filename=' . $filename );
550 568 header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
@@ -553,19 +571,46 @@
553 571 include FrmAppHelper::plugin_path() . '/classes/views/xml/xml.php';
554 572 }
555 573
556 574 /**
575 + * Returns an array that has parent term slugs for the terms provided.
576 + *
577 + * @since 6.8.3
578 + *
579 + * @param array $terms
580 + *
581 + * @return array
582 + */
583 + public static function get_parent_terms_slugs( $terms ) {
584 + $parent_term_ids = array_filter( array_unique( wp_list_pluck( $terms, 'parent' ) ) );
585 + $parent_slugs = array();
586 +
587 + if ( ! $parent_term_ids ) {
588 + return $parent_slugs;
589 + }
590 +
591 + $results = FrmDb::get_results( 'terms', array( 'term_id' => $parent_term_ids ), 'term_id, slug' );
592 +
593 + return wp_list_pluck( $results, 'slug', 'term_id' );
594 + }
595 +
596 + /**
597 + * Prepare the types array.
598 + *
599 + * @param array<string>|string $type
600 + *
557 601 * @return void
558 602 */
559 603 private static function prepare_types_array( &$type ) {
560 604 $type = (array) $type;
561 - if ( ! in_array( 'forms', $type ) && ( in_array( 'items', $type ) || in_array( 'posts', $type ) ) ) {
562 - // make sure the form is included if there are entries
605 +
606 + if ( ! in_array( 'forms', $type, true ) && ( in_array( 'items', $type, true ) || in_array( 'posts', $type, true ) ) ) {
607 + // Make sure the form is included if there are entries
563 608 $type[] = 'forms';
564 609 }
565 610
566 - if ( in_array( 'forms', $type ) ) {
567 - // include actions with forms
611 + if ( in_array( 'forms', $type, true ) ) {
612 + // Include actions with forms
568 613 $type[] = 'actions';
569 614 }
570 615 }
571 616
@@ -574,23 +619,24 @@
574 619 * Use the nme of the form if only one form is exported.
575 620 *
576 621 * @since 3.06
577 622 *
578 - * @param array $type
623 + * @param array $args
579 624 * @param array $records
580 - * @param array $args
581 625 *
582 626 * @return string
583 627 */
584 - private static function get_file_name( $args, $type, $records ) {
585 - $has_one_form = isset( $records['forms'] ) && ! empty( $records['forms'] ) && count( $args['ids'] ) === 1;
628 + private static function get_file_name( $args, $records ) {
629 + $has_one_form = ! empty( $records['forms'] ) && count( $args['ids'] ) === 1;
630 +
586 631 if ( $has_one_form ) {
587 - // one form is being exported
632 + // One form is being exported
588 633 $selected_form_id = reset( $args['ids'] );
589 634 $filename = 'form-' . $selected_form_id . '.xml';
590 635
591 636 foreach ( $records['forms'] as $form_id ) {
592 637 $filename = 'form-' . $form_id . '.xml';
638 +
593 639 if ( $selected_form_id === $form_id ) {
594 640 $form = FrmForm::getOne( $form_id );
595 641 $filename = $form->name !== '' ? $form->name : $form->form_key;
596 642 $filename = sanitize_title( $filename ) . '-form.xml';
@@ -599,13 +645,14 @@
599 645 }
600 646 } else {
601 647 $sitename = sanitize_key( get_bloginfo( 'name' ) );
602 648
603 - if ( ! empty( $sitename ) ) {
649 + if ( $sitename ) {
604 650 $sitename .= '.';
605 651 }
652 +
606 653 $filename = $sitename . 'formidable.' . gmdate( 'Y-m-d' ) . '.xml';
607 - }
654 + }//end if
608 655
609 656 /**
610 657 * @since 5.3
611 658 *
@@ -620,9 +667,10 @@
620 667 * @return void
621 668 */
622 669 public static function generate_csv( $atts ) {
623 670 $form_ids = $atts['ids'];
624 - if ( empty( $form_ids ) ) {
671 +
672 + if ( ! $form_ids ) {
625 673 wp_die( esc_html__( 'Please select a form', 'formidable' ) );
626 674 }
627 675 self::csv( reset( $form_ids ) );
628 676 }
@@ -631,8 +679,12 @@
631 679 * Export to CSV
632 680 *
633 681 * @since 2.0.19
634 682 *
683 + * @param false|int|string $form_id
684 + * @param string $search
685 + * @param string $fid
686 + *
635 687 * @return void
636 688 */
637 689 public static function csv( $form_id = false, $search = '', $fid = '' ) {
638 690 FrmAppHelper::permission_check( 'frm_view_entries' );
@@ -638,14 +690,19 @@
638 690 FrmAppHelper::permission_check( 'frm_view_entries' );
639 691
640 692 if ( ! $form_id ) {
641 693 $form_id = FrmAppHelper::get_param( 'form', '', 'get', 'sanitize_text_field' );
642 - $search = FrmAppHelper::get_param( ( isset( $_REQUEST['s'] ) ? 's' : 'search' ), '', 'get', 'sanitize_text_field' );
694 + $search = FrmAppHelper::get_param( isset( $_REQUEST['s'] ) ? 's' : 'search', '', 'get', 'sanitize_text_field' );
643 695 $fid = FrmAppHelper::get_param( 'fid', '', 'get', 'sanitize_text_field' );
644 696 }
645 697
646 - set_time_limit( 0 ); //Remove time limit to execute this function
698 + // Remove time limit to execute this function.
699 + if ( function_exists( 'set_time_limit' ) ) {
700 + set_time_limit( 0 );
701 + }
702 +
647 703 $mem_limit = str_replace( 'M', '', ini_get( 'memory_limit' ) );
704 +
648 705 if ( (int) $mem_limit < 256 ) {
649 706 wp_raise_memory_limit();
650 707 }
651 708
@@ -659,11 +716,11 @@
659 716 }
660 717
661 718 $form_id = $form->id;
662 719 $form_cols = self::get_fields_for_csv_export( $form_id, $form );
720 + $item_id = FrmAppHelper::get_param( 'item_id', 0, 'get', 'sanitize_text_field' );
663 721
664 - $item_id = FrmAppHelper::get_param( 'item_id', 0, 'get', 'sanitize_text_field' );
665 - if ( ! empty( $item_id ) ) {
722 + if ( $item_id ) {
666 723 $item_id = explode( ',', $item_id );
667 724 }
668 725
669 726 $query = array(
@@ -684,12 +741,12 @@
684 741
685 742 $entry_ids = FrmDb::get_col( $wpdb->prefix . 'frm_items it', $query );
686 743 unset( $query );
687 744
688 - if ( empty( $entry_ids ) ) {
745 + if ( $entry_ids ) {
746 + FrmCSVExportHelper::generate_csv( compact( 'form', 'entry_ids', 'form_cols' ) );
747 + } else {
689 748 esc_html_e( 'There are no entries for that form.', 'formidable' );
690 - } else {
691 - FrmCSVExportHelper::generate_csv( compact( 'form', 'entry_ids', 'form_cols' ) );
692 749 }
693 750
694 751 wp_die();
695 752 }
@@ -699,16 +756,17 @@
699 756 *
700 757 * @since 2.0.19
701 758 * @since 5.0.16 function went from private to public.
702 759 *
703 - * @param int $form_id
760 + * @param int $form_id
704 761 * @param object $form
705 762 *
706 - * @return array $csv_fields
763 + * @return array CSV fields.
707 764 */
708 765 public static function get_fields_for_csv_export( $form_id, $form ) {
709 766 $csv_fields = FrmField::get_all_for_form( $form_id, '', 'include', 'include' );
710 767 $no_export_fields = FrmField::no_save_fields();
768 +
711 769 foreach ( $csv_fields as $k => $f ) {
712 770 if ( in_array( $f->type, $no_export_fields, true ) ) {
713 771 unset( $csv_fields[ $k ] );
714 772 }
@@ -716,16 +774,21 @@
716 774
717 775 return apply_filters( 'frm_fields_for_csv_export', $csv_fields, compact( 'form' ) );
718 776 }
719 777
778 + /**
779 + * @param array $mimes
780 + *
781 + * @return array
782 + */
720 783 public static function allow_mime( $mimes ) {
721 784 if ( ! isset( $mimes['csv'] ) ) {
722 - // allow csv files
785 + // Allow csv files
723 786 $mimes['csv'] = 'text/csv';
724 787 }
725 788
726 789 if ( ! isset( $mimes['xml'] ) ) {
727 - // allow xml
790 + // Allow xml
728 791 $mimes['xml'] = 'text/xml';
729 792 }
730 793
731 794 return $mimes;