PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8
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/models/FrmEntryFormatter.php +27 -103 6.266.8 View file →
@@ -8,24 +8,21 @@
8 8 */
9 9 class FrmEntryFormatter {
10 10
11 11 /**
12 + * @var stdClass
12 13 * @since 2.04
13 - *
14 - * @var stdClass|null
15 14 */
16 - protected $entry;
15 + protected $entry = null;
17 16
18 17 /**
19 - * @var FrmEntryValues|null
20 - *
18 + * @var FrmEntryValues
21 19 * @since 2.04
22 20 */
23 - protected $entry_values;
21 + protected $entry_values = null;
24 22
25 23 /**
26 24 * @var bool
27 - *
28 25 * @since 2.04
29 26 */
30 27 protected $is_plain_text = false;
31 28
@@ -30,9 +27,8 @@
30 27 protected $is_plain_text = false;
31 28
32 29 /**
33 30 * @var bool
34 - *
35 31 * @since 2.04
36 32 */
37 33 protected $include_user_info = false;
38 34
@@ -37,9 +33,8 @@
37 33 protected $include_user_info = false;
38 34
39 35 /**
40 36 * @var bool
41 - *
42 37 * @since 2.04
43 38 */
44 39 protected $include_blank = false;
45 40
@@ -44,9 +39,8 @@
44 39 protected $include_blank = false;
45 40
46 41 /**
47 42 * @var string
48 - *
49 43 * @since 2.04
50 44 */
51 45 protected $format = 'text';
52 46
@@ -51,9 +45,8 @@
51 45 protected $format = 'text';
52 46
53 47 /**
54 48 * @var string
55 - *
56 49 * @since 2.05
57 50 */
58 51 protected $array_key = 'key';
59 52
@@ -58,23 +51,20 @@
58 51 protected $array_key = 'key';
59 52
60 53 /**
61 54 * @var string
62 - *
63 55 * @since 2.04
64 56 */
65 57 protected $direction = 'ltr';
66 58
67 59 /**
68 - * @var FrmTableHTMLGenerator|null
69 - *
60 + * @var FrmTableHTMLGenerator
70 61 * @since 2.04
71 62 */
72 - protected $table_generator;
63 + protected $table_generator = null;
73 64
74 65 /**
75 66 * @var bool
76 - *
77 67 * @since 2.04
78 68 */
79 69 protected $is_clickable = false;
80 70
@@ -79,9 +69,8 @@
79 69 protected $is_clickable = false;
80 70
81 71 /**
82 72 * @var array
83 - *
84 73 * @since 2.04
85 74 */
86 75 protected $include_extras = array();
87 76
@@ -86,9 +75,8 @@
86 75 protected $include_extras = array();
87 76
88 77 /**
89 78 * @var array
90 - *
91 79 * @since 3.0
92 80 */
93 81 protected $single_cell_fields = array();
94 82
@@ -93,9 +81,8 @@
93 81 protected $single_cell_fields = array();
94 82
95 83 /**
96 84 * @var array
97 - *
98 85 * @since 3.0
99 86 */
100 87 protected $atts = array();
101 88
@@ -136,10 +123,8 @@
136 123 *
137 124 * @since 2.04
138 125 *
139 126 * @param array $atts
140 - *
141 - * @return void
142 127 */
143 128 protected function init_entry( $atts ) {
144 129 if ( isset( $atts['entry'] ) && is_object( $atts['entry'] ) ) {
145 130
@@ -158,10 +143,8 @@
158 143 *
159 144 * @since 2.04
160 145 *
161 146 * @param array $atts
162 - *
163 - * @return void
164 147 */
165 148 protected function init_entry_values( $atts ) {
166 149 $entry_atts = $this->prepare_entry_attributes( $atts );
167 150 $this->entry_values = new FrmEntryValues( $this->entry->id, $entry_atts );
@@ -179,9 +162,8 @@
179 162 protected function prepare_entry_attributes( $atts ) {
180 163 $entry_atts = array();
181 164
182 165 $conditionally_add = array( 'include_fields', 'fields', 'exclude_fields', 'entry' );
183 -
184 166 foreach ( $conditionally_add as $index ) {
185 167 if ( isset( $atts[ $index ] ) ) {
186 168 $entry_atts[ $index ] = $atts[ $index ];
187 169 }
@@ -195,17 +177,20 @@
195 177 *
196 178 * @since 2.04
197 179 *
198 180 * @param array $atts
199 - *
200 - * @return void
201 181 */
202 182 protected function init_format( $atts ) {
203 183 if ( $atts['format'] === 'array' ) {
184 +
204 185 $this->format = 'array';
186 +
205 187 } elseif ( $atts['format'] === 'json' ) {
188 +
206 189 $this->format = 'json';
190 +
207 191 } elseif ( $atts['format'] === 'text' ) {
192 +
208 193 if ( $this->is_plain_text === true ) {
209 194 $this->format = 'plain_text_block';
210 195 } else {
211 196 $this->format = 'table';
@@ -236,13 +221,11 @@
236 221 *
237 222 * @since 2.05
238 223 *
239 224 * @param array $atts
240 - *
241 - * @return void
242 225 */
243 226 protected function init_array_key( $atts ) {
244 - if ( isset( $atts['array_key'] ) && $atts['array_key'] === 'id' ) {
227 + if ( isset( $atts['array_key'] ) && $atts['array_key'] == 'id' ) {
245 228 $this->array_key = 'id';
246 229 }
247 230 }
248 231
@@ -251,10 +234,8 @@
251 234 *
252 235 * @since 2.04
253 236 *
254 237 * @param array $atts
255 - *
256 - * @return void
257 238 */
258 239 protected function init_is_plain_text( $atts ) {
259 240 if ( isset( $atts['plain_text'] ) && $atts['plain_text'] ) {
260 241 $this->is_plain_text = true;
@@ -268,10 +249,8 @@
268 249 *
269 250 * @since 2.04
270 251 *
271 252 * @param array $atts
272 - *
273 - * @return void
274 253 */
275 254 protected function init_include_blank( $atts ) {
276 255 if ( isset( $atts['include_blank'] ) && $atts['include_blank'] ) {
277 256 $this->include_blank = true;
@@ -283,10 +262,8 @@
283 262 *
284 263 * @since 2.04
285 264 *
286 265 * @param array $atts
287 - *
288 - * @return void
289 266 */
290 267 protected function init_direction( $atts ) {
291 268 if ( isset( $atts['direction'] ) && $atts['direction'] === 'rtl' ) {
292 269 $this->direction = 'rtl';
@@ -298,10 +275,8 @@
298 275 *
299 276 * @since 2.04
300 277 *
301 278 * @param array $atts
302 - *
303 - * @return void
304 279 */
305 280 protected function init_include_user_info( $atts ) {
306 281 if ( isset( $atts['user_info'] ) && $atts['user_info'] ) {
307 282 $this->include_user_info = true;
@@ -311,13 +286,11 @@
311 286 /**
312 287 * Which fields to skip by default
313 288 *
314 289 * @since 3.0
315 - *
316 - * @return array
317 290 */
318 291 protected function skip_fields() {
319 - return array( 'captcha', 'html', FrmSubmitHelper::FIELD_TYPE );
292 + return array( 'captcha', 'html' );
320 293 }
321 294
322 295 /**
323 296 * Set the include_extras property
@@ -324,10 +297,8 @@
324 297 *
325 298 * @since 3.0
326 299 *
327 300 * @param array $atts
328 - *
329 - * @return void
330 301 */
331 302 protected function init_include_extras( $atts ) {
332 303 if ( isset( $atts['include_extras'] ) && $atts['include_extras'] ) {
333 304 $this->include_extras = array_map( 'strtolower', array_map( 'trim', explode( ',', $atts['include_extras'] ) ) );
@@ -337,10 +308,8 @@
337 308 /**
338 309 * Initialize the single_cell_fields property
339 310 *
340 311 * @since 3.0
341 - *
342 - * @return void
343 312 */
344 313 protected function init_single_cell_fields() {
345 314 $this->single_cell_fields = array( 'html' );
346 315 }
@@ -350,10 +319,8 @@
350 319 *
351 320 * @since 2.04
352 321 *
353 322 * @param array $atts
354 - *
355 - * @return void
356 323 */
357 324 protected function init_table_generator( $atts ) {
358 325 $this->table_generator = new FrmTableHTMLGenerator( 'entry', $atts );
359 326 }
@@ -363,10 +330,8 @@
363 330 *
364 331 * @since 2.04
365 332 *
366 333 * @param array $atts
367 - *
368 - * @return void
369 334 */
370 335 protected function init_is_clickable( $atts ) {
371 336 if ( isset( $atts['clickable'] ) && $atts['clickable'] ) {
372 337 $this->is_clickable = true;
@@ -377,12 +342,8 @@
377 342 * Save the passed atts for other calls. Exclude some attributes to prevent
378 343 * interaction with processing field values like time format.
379 344 *
380 345 * @since 3.0
381 - *
382 - * @param array $atts
383 - *
384 - * @return void
385 346 */
386 347 protected function init_atts( $atts ) {
387 348 $atts['source'] = 'entry_formatter';
388 349 $atts['wpautop'] = false;
@@ -388,9 +349,8 @@
388 349 $atts['wpautop'] = false;
389 350 $atts['return_array'] = true;
390 351
391 352 $unset = array( 'id', 'form_id', 'format' );
392 -
393 353 foreach ( $unset as $param ) {
394 354 if ( isset( $atts[ $param ] ) ) {
395 355 unset( $atts[ $param ] );
396 356 }
@@ -406,12 +366,12 @@
406 366 * @since 2.05
407 367 *
408 368 * @param FrmFieldValue $field_value
409 369 *
410 - * @return int|string
370 + * @return string|int
411 371 */
412 372 protected function get_key_or_id( $field_value ) {
413 - return $this->array_key === 'key' ? $field_value->get_field_key() : $field_value->get_field_id();
373 + return $this->array_key == 'key' ? $field_value->get_field_key() : $field_value->get_field_id();
414 374 }
415 375
416 376 /**
417 377 * Package and return the formatted entry values
@@ -488,13 +448,12 @@
488 448 *
489 449 * @since 2.05
490 450 *
491 451 * @param string $content
492 - *
493 - * @return void
494 452 */
495 453 protected function add_field_values_to_content( &$content ) {
496 - foreach ( $this->entry_values->get_field_values() as $field_value ) {
454 + foreach ( $this->entry_values->get_field_values() as $field_id => $field_value ) {
455 +
497 456 /**
498 457 * @var FrmFieldValue $field_value
499 458 */
500 459 $field_value->prepare_displayed_value( $this->atts );
@@ -539,10 +498,8 @@
539 498 * @since 2.04
540 499 *
541 500 * @param array $field_values
542 501 * @param array $output
543 - *
544 - * @return void
545 502 */
546 503 protected function push_field_values_to_array( $field_values, &$output ) {
547 504 foreach ( $field_values as $field_value ) {
548 505 /**
@@ -559,10 +516,8 @@
559 516 * @since 2.04
560 517 *
561 518 * @param FrmFieldValue $field_value
562 519 * @param array $output
563 - *
564 - * @return void
565 520 */
566 521 protected function push_single_field_to_array( $field_value, &$output ) {
567 522 if ( $this->include_field_in_content( $field_value ) ) {
568 523
@@ -570,9 +525,8 @@
570 525
571 526 $output[ $this->get_key_or_id( $field_value ) ] = $displayed_value;
572 527
573 528 $has_separate_value = (bool) $field_value->get_field_option( 'separate_value' );
574 -
575 529 if ( $has_separate_value || $displayed_value !== $field_value->get_saved_value() ) {
576 530 $output[ $this->get_key_or_id( $field_value ) . '-value' ] = $field_value->get_saved_value();
577 531 }
578 532 }
@@ -585,15 +539,13 @@
585 539 *
586 540 * @param string $label
587 541 * @param mixed $display_value
588 542 * @param string $content
589 - *
590 - * @return void
591 543 */
592 544 protected function add_plain_text_row( $label, $display_value, &$content ) {
593 545 $display_value = $this->prepare_display_value_for_plain_text_content( $display_value );
594 546
595 - if ( 'rtl' === $this->direction ) {
547 + if ( 'rtl' == $this->direction ) {
596 548 $content .= wp_kses_post( $display_value . ' :' . $label ) . "\r\n";
597 549 } else {
598 550 $content .= wp_kses_post( $label . ': ' . $display_value ) . "\r\n";
599 551 }
@@ -605,10 +557,8 @@
605 557 * @since 2.04
606 558 *
607 559 * @param FrmFieldValue $field_value
608 560 * @param string $content
609 - *
610 - * @return void
611 561 */
612 562 protected function add_field_value_to_content( $field_value, &$content ) {
613 563 if ( $this->is_extra_field( $field_value ) ) {
614 564 $this->add_row_for_extra_field( $field_value, $content );
@@ -624,10 +574,8 @@
624 574 * @since 3.0
625 575 *
626 576 * @param FrmFieldValue $field_value
627 577 * @param string $content
628 - *
629 - * @return void
630 578 */
631 579 protected function add_row_for_extra_field( $field_value, &$content ) {
632 580 if ( ! $this->include_field_in_content( $field_value ) ) {
633 581 return;
@@ -646,10 +594,8 @@
646 594 * @since 3.0
647 595 *
648 596 * @param FrmFieldValue $field_value
649 597 * @param string $content
650 - *
651 - * @return void
652 598 */
653 599 protected function add_row_for_standard_field( $field_value, &$content ) {
654 600 if ( ! $this->include_field_in_content( $field_value ) ) {
655 601 return;
@@ -669,10 +615,8 @@
669 615 * @since 3.0
670 616 *
671 617 * @param FrmFieldValue $field_value
672 618 * @param string $content
673 - *
674 - * @return void
675 619 */
676 620 protected function add_html_row_for_included_extra( $field_value, &$content ) {
677 621 $this->prepare_html_display_value_for_extra_fields( $field_value, $display_value );
678 622
@@ -690,10 +634,8 @@
690 634 * @since 3.0
691 635 *
692 636 * @param FrmFieldValue $field_value
693 637 * @param string $content
694 - *
695 - * @return void
696 638 */
697 639 protected function add_plain_text_row_for_included_extra( $field_value, &$content ) {
698 640 $this->prepare_plain_text_display_value_for_extra_fields( $field_value, $display_value );
699 641
@@ -710,10 +652,8 @@
710 652 * @since 3.0
711 653 *
712 654 * @param string $display_value
713 655 * @param string $content
714 - *
715 - * @return void
716 656 */
717 657 protected function add_single_cell_html_row( $display_value, &$content ) {
718 658 // TODO: maybe move to FrmFieldValue
719 659 $display_value = $this->prepare_display_value_for_html_table( $display_value );
@@ -727,10 +667,8 @@
727 667 * @since 3.0
728 668 *
729 669 * @param string $display_value
730 670 * @param string $content
731 - *
732 - * @return void
733 671 */
734 672 protected function add_single_value_plain_text_row( $display_value, &$content ) {
735 673 $content .= $this->prepare_display_value_for_plain_text_content( $display_value );
736 674 }
@@ -741,10 +679,8 @@
741 679 * @since 3.0
742 680 *
743 681 * @param FrmFieldValue $field_value
744 682 * @param mixed $display_value
745 - *
746 - * @return void
747 683 */
748 684 protected function prepare_html_display_value_for_extra_fields( $field_value, &$display_value ) {
749 685 $display_value = $field_value->get_displayed_value();
750 686 }
@@ -755,10 +691,8 @@
755 691 * @since 3.0
756 692 *
757 693 * @param FrmFieldValue $field_value
758 694 * @param mixed $display_value
759 - *
760 - * @return void
761 695 */
762 696 protected function prepare_plain_text_display_value_for_extra_fields( $field_value, &$display_value ) {
763 697 $display_value = $field_value->get_displayed_value() . "\r\n";
764 698 }
@@ -769,10 +703,8 @@
769 703 * @since 2.04
770 704 *
771 705 * @param FrmFieldValue $field_value
772 706 * @param string $content
773 - *
774 - * @return void
775 707 */
776 708 protected function add_standard_row( $field_value, &$content ) {
777 709 if ( $this->format === 'plain_text_block' ) {
778 710 $this->add_plain_text_row( $field_value->get_field_label(), $field_value->get_displayed_value(), $content );
@@ -804,14 +736,14 @@
804 736 *
805 737 * @since 2.04
806 738 *
807 739 * @param string $content
808 - *
809 - * @return void
810 740 */
811 741 protected function add_user_info_to_html_table( &$content ) {
812 742 if ( $this->include_user_info ) {
743 +
813 744 foreach ( $this->entry_values->get_user_info() as $user_info ) {
745 +
814 746 $value_args = array(
815 747 'label' => $user_info['label'],
816 748 'value' => $user_info['value'],
817 749 'field_type' => 'none',
@@ -827,10 +759,8 @@
827 759 *
828 760 * @since 2.04
829 761 *
830 762 * @param string $content
831 - *
832 - * @return void
833 763 */
834 764 protected function add_user_info_to_plain_text_content( &$content ) {
835 765 if ( $this->include_user_info ) {
836 766
@@ -898,19 +828,13 @@
898 828 * 'value' => (mixed) The value to add. Required
899 829 * 'field_type' => (string) The field type. Blank string if not a field.
900 830 * ]
901 831 * @param string $content
902 - *
903 - * @return void
904 832 */
905 833 protected function add_html_row( $value_args, &$content ) {
906 834 $display_value = $this->prepare_display_value_for_html_table( $value_args['value'], $value_args['field_type'] );
907 835
908 - $content .= $this->table_generator->generate_two_cell_table_row(
909 - $value_args['label'],
910 - $display_value,
911 - array( 'field_type' => $value_args['field_type'] )
912 - );
836 + $content .= $this->table_generator->generate_two_cell_table_row( $value_args['label'], $display_value );
913 837 }
914 838
915 839 /**
916 840 * Prepare the displayed value for an array
@@ -936,9 +860,8 @@
936 860 * @return mixed|string
937 861 */
938 862 protected function prepare_display_value_for_html_table( $display_value, $field_type = '' ) {
939 863 $display_value = $this->flatten_array( $display_value );
940 -
941 864 if ( ! isset( $this->atts['line_breaks'] ) || ! empty( $this->atts['line_breaks'] ) ) {
942 865 $display_value = str_replace( array( "\r\n", "\n" ), '<br/>', $display_value );
943 866 }
944 867
@@ -951,9 +874,9 @@
951 874 * @since 2.04
952 875 *
953 876 * @param mixed $display_value
954 877 *
955 - * @return int|string
878 + * @return string|int
956 879 */
957 880 protected function prepare_display_value_for_plain_text_content( $display_value ) {
958 881 $display_value = $this->flatten_array( $display_value );
959 882 $display_value = $this->strip_html( $display_value );
@@ -965,15 +888,15 @@
965 888 * Flatten an array
966 889 *
967 890 * @since 2.04
968 891 *
969 - * @param array|int|string $value
892 + * @param array|string|int $value
970 893 *
971 - * @return int|string
894 + * @return string|int
972 895 */
973 896 protected function flatten_array( $value ) {
974 897 if ( is_array( $value ) ) {
975 - $separator = $this->atts['array_separator'] ?? ', ';
898 + $separator = isset( $this->atts['array_separator'] ) ? $this->atts['array_separator'] : ', ';
976 899 $value = implode( $separator, $value );
977 900 }
978 901
979 902 return $value;
@@ -988,9 +911,11 @@
988 911 *
989 912 * @return mixed
990 913 */
991 914 protected function strip_html( $value ) {
915 +
992 916 if ( $this->is_plain_text ) {
917 +
993 918 if ( is_array( $value ) ) {
994 919 foreach ( $value as $key => $single_value ) {
995 920 $value[ $key ] = $this->strip_html( $single_value );
996 921 }
@@ -998,9 +923,8 @@
998 923 if ( strpos( $value, '<img' ) !== false ) {
999 924 $value = str_replace( array( '<img', 'src=', '/>', '"' ), '', $value );
1000 925 $value = trim( $value );
1001 926 }
1002 -
1003 927 $value = strip_tags( $value );
1004 928 }
1005 929 }
1006 930