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