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