PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.22
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.22
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/helpers/FrmCSVExportHelper.php +24 -120 6.276.22 View file →
@@ -113,19 +113,19 @@
113 113 // Do not add the UTF-8 with BOM option if this function is called on Global Settings.
114 114 // This is to improve compatibility with the Export View as CSV add-on (v1.10).
115 115 // Otherwise, the option will appear twice since it is added in the add-on as well.
116 116 $on_global_settings_page = 'formidable-settings' === FrmAppHelper::get_param( 'page' );
117 -
118 117 if ( ! $on_global_settings_page ) {
119 118 array_splice( $formats, 1, 0, 'UTF-8 with BOM' );
120 119 }
121 120
122 - return apply_filters( 'frm_csv_format_options', $formats );
121 + $formats = apply_filters( 'frm_csv_format_options', $formats );
122 +
123 + return $formats;
123 124 }
124 125
125 126 /**
126 127 * @param array $atts
127 - *
128 128 * @return false|string|null returns a string file path or false if $atts['mode'] is set to 'file'.
129 129 */
130 130 public static function generate_csv( $atts ) {
131 131 global $frm_vars;
@@ -144,9 +144,8 @@
144 144
145 145 if ( 'file' === self::$mode ) {
146 146 $filepath = get_temp_dir() . $filename;
147 147 self::$fp = @fopen( $filepath, 'w' );
148 -
149 148 if ( ! self::$fp ) {
150 149 return false;
151 150 }
152 151 } elseif ( 'echo' === self::$mode ) {
@@ -203,9 +202,8 @@
203 202 /**
204 203 * @since 6.8.4
205 204 *
206 205 * @param array $atts
207 - *
208 206 * @return void
209 207 */
210 208 private static function after_generate_csv( $atts ) {
211 209 /**
@@ -211,9 +209,8 @@
211 209 /**
212 210 * @since 6.8.4
213 211 *
214 212 * @param array $atts {
215 - *
216 213 * @type object $form
217 214 * @type array $entry_ids
218 215 * @type array $form_cols
219 216 * }
@@ -224,9 +221,8 @@
224 221 /**
225 222 * @since 5.0.16
226 223 *
227 224 * @param stdClass $form
228 - *
229 225 * @return string
230 226 */
231 227 private static function generate_csv_filename( $form ) {
232 228 $filename = gmdate( 'ymdHis', time() ) . '_' . sanitize_title_with_dashes( $form->name ) . '_formidable_entries.csv';
@@ -244,11 +240,8 @@
244 240 'meta' => self::$meta,
245 241 );
246 242 }
247 243
248 - /**
249 - * @return void
250 - */
251 244 private static function set_class_parameters() {
252 245 $args = self::get_standard_filter_args();
253 246 self::$separator = apply_filters( 'frm_csv_sep', self::$separator, $args );
254 247 self::$line_break = apply_filters( 'frm_csv_line_break', self::$line_break, $args );
@@ -255,28 +248,17 @@
255 248 self::$wp_date_format = apply_filters( 'frm_csv_date_format', self::$wp_date_format, $args );
256 249 self::get_csv_format();
257 250 self::$charset = get_option( 'blog_charset' );
258 251
259 - // phpcs:ignore WordPress.Security.NonceVerification.Missing
260 - $col_sep = ! empty( $_POST['csv_col_sep'] ) ? sanitize_text_field( wp_unslash( $_POST['csv_col_sep'] ) ) : self::$column_separator;
252 + $col_sep = ! empty( $_POST['csv_col_sep'] ) ? sanitize_text_field( wp_unslash( $_POST['csv_col_sep'] ) ) : self::$column_separator; // phpcs:ignore WordPress.Security.NonceVerification.Missing
261 253
262 254 self::$column_separator = apply_filters( 'frm_csv_column_sep', $col_sep, $args );
263 255 }
264 256
265 - /**
266 - * @param object $form
267 - *
268 - * @return void
269 - */
270 257 private static function set_has_parent_id( $form ) {
271 258 self::$has_parent_id = $form->parent_form_id > 0;
272 259 }
273 260
274 - /**
275 - * @param string $filename
276 - *
277 - * @return void
278 - */
279 261 private static function print_file_headers( $filename ) {
280 262 header( 'Content-Description: File Transfer' );
281 263 header( 'Content-Disposition: attachment; filename="' . esc_attr( $filename ) . '"' );
282 264 header( 'Content-Type: text/csv; charset=' . self::$charset, true );
@@ -314,11 +296,8 @@
314 296 $csv_format = apply_filters( 'frm_csv_format', $csv_format, self::get_standard_filter_args() );
315 297 self::$to_encoding = $csv_format;
316 298 }
317 299
318 - /**
319 - * @return void
320 - */
321 300 private static function prepare_csv_headings() {
322 301 $headings = array();
323 302 self::csv_headings( $headings );
324 303 $headings = apply_filters(
@@ -334,16 +313,10 @@
334 313
335 314 self::print_csv_row( $headings );
336 315 }
337 316
338 - /**
339 - * @param object $col
340 - *
341 - * @return array
342 - */
343 317 private static function field_headings( $col ) {
344 318 $field_type_obj = FrmFieldFactory::get_field_factory( $col );
345 -
346 319 if ( ! empty( $field_type_obj->is_combo_field ) ) {
347 320 // This is combo field.
348 321 return $field_type_obj->get_export_headings();
349 322 }
@@ -349,20 +322,14 @@
349 322 }
350 323
351 324 $field_headings = array();
352 325 $separate_values = array( 'user_id', 'file', 'data', 'date' );
353 -
354 326 if ( ! empty( $col->field_options['separate_value'] ) && ! in_array( $col->type, $separate_values, true ) ) {
355 327 $field_headings[ $col->id . '_label' ] = strip_tags( $col->name . ' ' . __( '(label)', 'formidable' ) );
356 328 }
357 329
358 - if ( ! empty( $field_headings[ $col->id . '_label' ] ) ) {
359 - $field_headings[ $col->id ] = strip_tags( $col->name . ' ' . __( '(value)', 'formidable' ) );
360 - } else {
361 - $field_headings[ $col->id ] = strip_tags( $col->name );
362 - }
363 -
364 - return apply_filters(
330 + $field_headings[ $col->id ] = strip_tags( $col->name );
331 + $field_headings = apply_filters(
365 332 'frm_csv_field_columns',
366 333 $field_headings,
367 334 array_merge(
368 335 self::get_standard_filter_args(),
@@ -368,16 +335,13 @@
368 335 self::get_standard_filter_args(),
369 336 array( 'field' => $col )
370 337 )
371 338 );
339 +
340 + return $field_headings;
372 341 }
373 342
374 - /**
375 - * @param array $headings
376 - *
377 - * @return void
378 - */
379 - private static function csv_headings( &$headings ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
343 + private static function csv_headings( &$headings ) {
380 344 $fields_by_repeater_id = array();
381 345 $repeater_ids = array();
382 346
383 347 foreach ( self::$fields as $col ) {
@@ -416,14 +380,13 @@
416 380 }
417 381 unset( $start, $end, $length, $row, $repeater_meta, $where );
418 382
419 383 $flat = array();
420 -
421 384 foreach ( $headings as $key => $heading ) {
422 385 if ( is_array( $heading ) ) {
423 - $repeater_id = str_replace( 'repeater', '', $key );
386 + $repeater_id = str_replace( 'repeater', '', $key );
387 +
424 388 $repeater_headings = array();
425 -
426 389 foreach ( $fields_by_repeater_id[ $repeater_id ] as $col ) {
427 390 $repeater_headings += self::field_headings( $col );
428 391 }
429 392
@@ -461,9 +424,8 @@
461 424 $headings['is_draft'] = __( 'Entry Status', 'formidable' );
462 425 $headings['ip'] = __( 'IP', 'formidable' );
463 426 $headings['id'] = __( 'ID', 'formidable' );
464 427 $headings['item_key'] = __( 'Key', 'formidable' );
465 -
466 428 if ( self::has_parent_id() ) {
467 429 $headings['parent_id'] = __( 'Parent ID', 'formidable' );
468 430 }
469 431
@@ -471,9 +433,8 @@
471 433 }
472 434
473 435 /**
474 436 * @param object $field
475 - *
476 437 * @return bool
477 438 */
478 439 private static function is_the_child_of_a_repeater( $field ) {
479 440 if ( $field->form_id === self::$form_id || empty( $field->field_options['in_section'] ) ) {
@@ -482,26 +443,22 @@
482 443
483 444 $section_id = $field->field_options['in_section'];
484 445 $section = FrmField::getOne( $section_id );
485 446
486 - return $section && FrmField::is_repeating_field( $section );
447 + if ( ! $section ) {
448 + return false;
449 + }
450 +
451 + return FrmField::is_repeating_field( $section );
487 452 }
488 453
489 - /**
490 - * @return bool
491 - */
492 454 private static function has_parent_id() {
493 455 return self::$has_parent_id;
494 456 }
495 457
496 - /**
497 - * @param array $next_set
498 - *
499 - * @return void
500 - */
501 458 private static function prepare_next_csv_rows( $next_set ) {
502 459 if ( FrmAppHelper::pro_is_installed() ) {
503 - $where = array(
460 + $where = array(
504 461 'or' => 1,
505 462 'id' => $next_set,
506 463 'parent_item_id' => $next_set,
507 464 );
@@ -529,11 +486,8 @@
529 486 }
530 487 }
531 488 }
532 489
533 - /**
534 - * @return void
535 - */
536 490 private static function prepare_csv_row() {
537 491 $row = array();
538 492 self::add_field_values_to_csv( $row );
539 493 self::add_entry_data_to_csv( $row );
@@ -549,13 +503,8 @@
549 503 );
550 504 self::print_csv_row( $row );
551 505 }
552 506
553 - /**
554 - * @param array $entries
555 - *
556 - * @return void
557 - */
558 507 private static function add_repeat_field_values_to_csv( &$entries ) {
559 508 if ( isset( self::$entry->metas ) ) {
560 509 // add child entries to the parent
561 510 foreach ( self::$entry->metas as $meta_id => $meta_value ) {
@@ -589,9 +538,8 @@
589 538 // add the embedded form id
590 539 if ( ! isset( $entries[ self::$entry->parent_item_id ]->embedded_fields ) ) {
591 540 $entries[ self::$entry->parent_item_id ]->embedded_fields = array();
592 541 }
593 -
594 542 $entries[ self::$entry->parent_item_id ]->embedded_fields[ self::$entry->id ] = self::$entry->form_id;
595 543 }
596 544
597 545 /**
@@ -599,9 +547,8 @@
599 547 * The export needs all of the meta to be filled in, so we put blank strings for every missing repeater child
600 548 *
601 549 * @param array $metas
602 550 * @param array $entries
603 - *
604 551 * @return array
605 552 */
606 553 private static function fill_missing_repeater_metas( $metas, &$entries ) {
607 554 $field_ids = array_keys( $metas );
@@ -612,9 +559,8 @@
612 559 return $metas;
613 560 }
614 561
615 562 $repeater_id = $field->field_options['in_section'];
616 -
617 563 if ( ! isset( self::$fields_by_repeater_id[ $repeater_id ] ) ) {
618 564 return $metas;
619 565 }
620 566
@@ -621,9 +567,9 @@
621 567 foreach ( self::$fields_by_repeater_id[ $repeater_id ] as $repeater_child ) {
622 568 if ( ! isset( $metas[ $repeater_child->id ] ) ) {
623 569 $metas[ $repeater_child->id ] = '';
624 570
625 - if ( ! isset( $entries[ self::$entry->parent_item_id ]->metas[ $repeater_child->id ] ) || ! is_array( $entries[ self::$entry->parent_item_id ]->metas[ $repeater_child->id ] ) ) { // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
571 + if ( ! isset( $entries[ self::$entry->parent_item_id ]->metas[ $repeater_child->id ] ) || ! is_array( $entries[ self::$entry->parent_item_id ]->metas[ $repeater_child->id ] ) ) {
626 572 $entries[ self::$entry->parent_item_id ]->metas[ $repeater_child->id ] = array();
627 573 }
628 574
629 575 $entries[ self::$entry->parent_item_id ]->metas[ $repeater_child->id ][] = '';
@@ -632,33 +578,21 @@
632 578
633 579 return $metas;
634 580 }
635 581
636 - /**
637 - * @param int|string $field_id
638 - *
639 - * @return false|object
640 - */
641 582 private static function get_field( $field_id ) {
642 583 $field_id = (int) $field_id;
643 -
644 584 foreach ( self::$fields as $field ) {
645 585 if ( $field_id === (int) $field->id ) {
646 586 return $field;
647 587 }
648 588 }
649 -
650 589 return false;
651 590 }
652 591
653 - /**
654 - * @param array $row
655 - *
656 - * @return void
657 - */
658 592 private static function add_field_values_to_csv( &$row ) {
659 593 foreach ( self::$fields as $col ) {
660 - $field_value = self::$entry->metas[ $col->id ] ?? false;
594 + $field_value = isset( self::$entry->metas[ $col->id ] ) ? self::$entry->metas[ $col->id ] : false;
661 595
662 596 FrmFieldsHelper::prepare_field_value( $field_value, $col->type );
663 597 self::add_array_values_to_columns( $row, compact( 'col', 'field_value' ) );
664 598
@@ -674,9 +608,8 @@
674 608 );
675 609
676 610 if ( ! empty( $col->field_options['separate_value'] ) ) {
677 611 $label_key = $col->id . '_label';
678 -
679 612 if ( self::is_the_child_of_a_repeater( $col ) ) {
680 613 $row[ $label_key ] = array();
681 614
682 615 if ( is_array( $field_value ) ) {
@@ -700,9 +633,8 @@
700 633 * @since 5.0.06
701 634 *
702 635 * @param mixed $field_value
703 636 * @param stdClass $field
704 - *
705 637 * @return string
706 638 */
707 639 private static function get_separate_value_label( $field_value, $field ) {
708 640 return FrmEntriesHelper::display_value(
@@ -713,9 +645,9 @@
713 645 'post_id' => self::$entry->post_id,
714 646 'show_icon' => false,
715 647 'entry_id' => self::$entry->id,
716 648 'sep' => self::$separator,
717 - 'embedded_field_id' => isset( self::$entry->embedded_fields ) && isset( self::$entry->embedded_fields[ self::$entry->id ] ) ? 'form' . self::$entry->embedded_fields[ self::$entry->id ] : 0, // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
649 + 'embedded_field_id' => isset( self::$entry->embedded_fields ) && isset( self::$entry->embedded_fields[ self::$entry->id ] ) ? 'form' . self::$entry->embedded_fields[ self::$entry->id ] : 0,
718 650 )
719 651 );
720 652 }
721 653
@@ -720,13 +652,8 @@
720 652 }
721 653
722 654 /**
723 655 * @since 2.0.23
724 - *
725 - * @param array $row
726 - * @param array $atts
727 - *
728 - * @return void
729 656 */
730 657 private static function add_array_values_to_columns( &$row, $atts ) {
731 658 if ( is_array( $atts['field_value'] ) ) {
732 659 foreach ( $atts['field_value'] as $key => $sub_value ) {
@@ -733,9 +660,8 @@
733 660 if ( is_array( $sub_value ) ) {
734 661 // This is combo field inside repeater. The heading key has this format: [86_first[0]].
735 662 foreach ( $sub_value as $sub_key => $sub_sub_value ) {
736 663 $column_key = $atts['col']->id . '_' . $sub_key . '[' . $key . ']';
737 -
738 664 if ( ! is_numeric( $sub_key ) && isset( self::$headings[ $column_key ] ) ) {
739 665 $row[ $column_key ] = $sub_sub_value;
740 666 }
741 667 }
@@ -743,21 +669,15 @@
743 669 continue;
744 670 }
745 671
746 672 $column_key = $atts['col']->id . '_' . $key;
747 -
748 673 if ( ! is_numeric( $key ) && isset( self::$headings[ $column_key ] ) ) {
749 674 $row[ $column_key ] = $sub_value;
750 675 }
751 676 }
752 - }//end if
677 + }
753 678 }
754 679
755 - /**
756 - * @param array $row
757 - *
758 - * @return void
759 - */
760 680 private static function add_entry_data_to_csv( &$row ) {
761 681 $row['created_at'] = FrmAppHelper::get_formatted_time( self::$entry->created_at, self::$wp_date_format, ' ' );
762 682 $row['updated_at'] = FrmAppHelper::get_formatted_time( self::$entry->updated_at, self::$wp_date_format, ' ' );
763 683 $row['user_id'] = self::$entry->user_id;
@@ -765,19 +685,13 @@
765 685 $row['is_draft'] = self::$entry->is_draft;
766 686 $row['ip'] = self::$entry->ip;
767 687 $row['id'] = self::$entry->id;
768 688 $row['item_key'] = self::$entry->item_key;
769 -
770 689 if ( self::has_parent_id() ) {
771 690 $row['parent_id'] = self::$entry->parent_item_id;
772 691 }
773 692 }
774 693
775 - /**
776 - * @param array $rows
777 - *
778 - * @return void
779 - */
780 694 private static function print_csv_row( $rows ) {
781 695 $sep = '';
782 696 $echo = 'echo' === self::$mode;
783 697
@@ -785,9 +699,8 @@
785 699 if ( isset( $rows[ $k ] ) ) {
786 700 $row = $rows[ $k ];
787 701 } else {
788 702 $row = '';
789 -
790 703 // array indexed data is not at $rows[ $k ]
791 704 if ( $k[ strlen( $k ) - 1 ] === ']' ) {
792 705 $start = strrpos( $k, '[' );
793 706 $key = substr( $k, 0, $start++ );
@@ -806,9 +719,8 @@
806 719 $row = implode( self::$separator, FrmAppHelper::array_flatten( $row, 'reset' ) );
807 720 }
808 721
809 722 $val = self::encode_value( $row );
810 -
811 723 if ( 'return' !== self::$line_break ) {
812 724 $val = str_replace( array( "\r\n", "\r", "\n" ), self::$line_break, $val );
813 725 }
814 726
@@ -816,14 +728,12 @@
816 728 echo $sep . '"' . $val . '"'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
817 729 } else {
818 730 fwrite( self::$fp, $sep . '"' . $val . '"' );
819 731 }
820 -
821 732 $sep = self::$column_separator;
822 733
823 734 unset( $k, $row );
824 735 }//end foreach
825 -
826 736 if ( $echo ) {
827 737 echo "\n";
828 738 } else {
829 739 fwrite( self::$fp, "\n" );
@@ -829,13 +739,8 @@
829 739 fwrite( self::$fp, "\n" );
830 740 }
831 741 }
832 742
833 - /**
834 - * @param string $line
835 - *
836 - * @return string
837 - */
838 743 public static function encode_value( $line ) {
839 744 if ( '' === $line ) {
840 745 return $line;
841 746 }
@@ -846,9 +751,9 @@
846 751 case 'macintosh':
847 752 // this map was derived from the differences between the MacRoman and UTF-8 Charsets
848 753 // Reference:
849 754 // http://www.alanwood.net/demos/macroman.html.
850 - $convmap = array( 256, 304, 0, 0xffff, 306, 337, 0, 0xffff, 340, 375, 0, 0xffff, 377, 401, 0, 0xffff, 403, 709, 0, 0xffff, 712, 727, 0, 0xffff, 734, 936, 0, 0xffff, 938, 959, 0, 0xffff, 961, 8210, 0, 0xffff, 8213, 8215, 0, 0xffff, 8219, 8219, 0, 0xffff, 8227, 8229, 0, 0xffff, 8231, 8239, 0, 0xffff, 8241, 8248, 0, 0xffff, 8251, 8259, 0, 0xffff, 8261, 8363, 0, 0xffff, 8365, 8481, 0, 0xffff, 8483, 8705, 0, 0xffff, 8707, 8709, 0, 0xffff, 8711, 8718, 0, 0xffff, 8720, 8720, 0, 0xffff, 8722, 8729, 0, 0xffff, 8731, 8733, 0, 0xffff, 8735, 8746, 0, 0xffff, 8748, 8775, 0, 0xffff, 8777, 8799, 0, 0xffff, 8801, 8803, 0, 0xffff, 8806, 9673, 0, 0xffff, 9675, 63742, 0, 0xffff, 63744, 64256, 0, 0xffff ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
755 + $convmap = array( 256, 304, 0, 0xffff, 306, 337, 0, 0xffff, 340, 375, 0, 0xffff, 377, 401, 0, 0xffff, 403, 709, 0, 0xffff, 712, 727, 0, 0xffff, 734, 936, 0, 0xffff, 938, 959, 0, 0xffff, 961, 8210, 0, 0xffff, 8213, 8215, 0, 0xffff, 8219, 8219, 0, 0xffff, 8227, 8229, 0, 0xffff, 8231, 8239, 0, 0xffff, 8241, 8248, 0, 0xffff, 8251, 8259, 0, 0xffff, 8261, 8363, 0, 0xffff, 8365, 8481, 0, 0xffff, 8483, 8705, 0, 0xffff, 8707, 8709, 0, 0xffff, 8711, 8718, 0, 0xffff, 8720, 8720, 0, 0xffff, 8722, 8729, 0, 0xffff, 8731, 8733, 0, 0xffff, 8735, 8746, 0, 0xffff, 8748, 8775, 0, 0xffff, 8777, 8799, 0, 0xffff, 8801, 8803, 0, 0xffff, 8806, 9673, 0, 0xffff, 9675, 63742, 0, 0xffff, 63744, 64256, 0, 0xffff );
851 756 break;
852 757 case 'ISO-8859-1':
853 758 $convmap = array( 256, 10000, 0, 0xffff );
854 759 }
@@ -867,11 +772,9 @@
867 772 /**
868 773 * Escape a " in a csv with another "
869 774 *
870 775 * @since 2.0
871 - *
872 776 * @param mixed $value
873 - *
874 777 * @return mixed
875 778 */
876 779 public static function escape_csv( $value ) {
877 780 if ( ! is_string( $value ) ) {
@@ -881,8 +784,9 @@
881 784 if ( '=' === $value[0] ) {
882 785 // escape the = to prevent vulnerability
883 786 $value = "'" . $value;
884 787 }
788 + $value = str_replace( '"', '""', $value );
885 789
886 - return str_replace( '"', '""', $value );
790 + return $value;
887 791 }
888 792 }