PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.2.01
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.2.01
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 +42 -119 6.265.2.01 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
@@ -103,9 +90,9 @@
103 90 * FrmEntryFormat constructor
104 91 *
105 92 * @since 2.04
106 93 *
107 - * @param array $atts
94 + * @param $atts
108 95 */
109 96 public function __construct( $atts ) {
110 97 $this->init_entry( $atts );
111 98
@@ -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;
@@ -387,10 +348,9 @@
387 348 $atts['source'] = 'entry_formatter';
388 349 $atts['wpautop'] = false;
389 350 $atts['return_array'] = true;
390 351
391 - $unset = array( 'id', 'form_id', 'format' );
392 -
352 + $unset = array( 'id', 'entry', 'form_id', 'format' );
393 353 foreach ( $unset as $param ) {
394 354 if ( isset( $atts[ $param ] ) ) {
395 355 unset( $atts[ $param ] );
396 356 }
@@ -395,10 +355,9 @@
395 355 unset( $atts[ $param ] );
396 356 }
397 357 }
398 358
399 - $this->atts = $atts;
400 - $this->atts['entry'] = $this->entry;
359 + $this->atts = $atts;
401 360 }
402 361
403 362 /**
404 363 * Get the field key or ID, depending on array_key property
@@ -406,12 +365,12 @@
406 365 * @since 2.05
407 366 *
408 367 * @param FrmFieldValue $field_value
409 368 *
410 - * @return int|string
369 + * @return string|int
411 370 */
412 371 protected function get_key_or_id( $field_value ) {
413 - return $this->array_key === 'key' ? $field_value->get_field_key() : $field_value->get_field_id();
372 + return $this->array_key == 'key' ? $field_value->get_field_key() : $field_value->get_field_id();
414 373 }
415 374
416 375 /**
417 376 * Package and return the formatted entry values
@@ -488,13 +447,12 @@
488 447 *
489 448 * @since 2.05
490 449 *
491 450 * @param string $content
492 - *
493 - * @return void
494 451 */
495 452 protected function add_field_values_to_content( &$content ) {
496 - foreach ( $this->entry_values->get_field_values() as $field_value ) {
453 + foreach ( $this->entry_values->get_field_values() as $field_id => $field_value ) {
454 +
497 455 /**
498 456 * @var FrmFieldValue $field_value
499 457 */
500 458 $field_value->prepare_displayed_value( $this->atts );
@@ -539,10 +497,8 @@
539 497 * @since 2.04
540 498 *
541 499 * @param array $field_values
542 500 * @param array $output
543 - *
544 - * @return void
545 501 */
546 502 protected function push_field_values_to_array( $field_values, &$output ) {
547 503 foreach ( $field_values as $field_value ) {
548 504 /**
@@ -558,11 +514,9 @@
558 514 *
559 515 * @since 2.04
560 516 *
561 517 * @param FrmFieldValue $field_value
562 - * @param array $output
563 - *
564 - * @return void
518 + * @param array $output
565 519 */
566 520 protected function push_single_field_to_array( $field_value, &$output ) {
567 521 if ( $this->include_field_in_content( $field_value ) ) {
568 522
@@ -570,9 +524,8 @@
570 524
571 525 $output[ $this->get_key_or_id( $field_value ) ] = $displayed_value;
572 526
573 527 $has_separate_value = (bool) $field_value->get_field_option( 'separate_value' );
574 -
575 528 if ( $has_separate_value || $displayed_value !== $field_value->get_saved_value() ) {
576 529 $output[ $this->get_key_or_id( $field_value ) . '-value' ] = $field_value->get_saved_value();
577 530 }
578 531 }
@@ -583,17 +536,15 @@
583 536 *
584 537 * @since 2.04
585 538 *
586 539 * @param string $label
587 - * @param mixed $display_value
540 + * @param mixed $display_value
588 541 * @param string $content
589 - *
590 - * @return void
591 542 */
592 543 protected function add_plain_text_row( $label, $display_value, &$content ) {
593 544 $display_value = $this->prepare_display_value_for_plain_text_content( $display_value );
594 545
595 - if ( 'rtl' === $this->direction ) {
546 + if ( 'rtl' == $this->direction ) {
596 547 $content .= wp_kses_post( $display_value . ' :' . $label ) . "\r\n";
597 548 } else {
598 549 $content .= wp_kses_post( $label . ': ' . $display_value ) . "\r\n";
599 550 }
@@ -604,11 +555,9 @@
604 555 *
605 556 * @since 2.04
606 557 *
607 558 * @param FrmFieldValue $field_value
608 - * @param string $content
609 - *
610 - * @return void
559 + * @param string $content
611 560 */
612 561 protected function add_field_value_to_content( $field_value, &$content ) {
613 562 if ( $this->is_extra_field( $field_value ) ) {
614 563 $this->add_row_for_extra_field( $field_value, $content );
@@ -623,11 +572,9 @@
623 572 *
624 573 * @since 3.0
625 574 *
626 575 * @param FrmFieldValue $field_value
627 - * @param string $content
628 - *
629 - * @return void
576 + * @param string $content
630 577 */
631 578 protected function add_row_for_extra_field( $field_value, &$content ) {
632 579 if ( ! $this->include_field_in_content( $field_value ) ) {
633 580 return;
@@ -645,11 +592,9 @@
645 592 *
646 593 * @since 3.0
647 594 *
648 595 * @param FrmFieldValue $field_value
649 - * @param string $content
650 - *
651 - * @return void
596 + * @param string $content
652 597 */
653 598 protected function add_row_for_standard_field( $field_value, &$content ) {
654 599 if ( ! $this->include_field_in_content( $field_value ) ) {
655 600 return;
@@ -668,11 +613,9 @@
668 613 *
669 614 * @since 3.0
670 615 *
671 616 * @param FrmFieldValue $field_value
672 - * @param string $content
673 - *
674 - * @return void
617 + * @param string $content
675 618 */
676 619 protected function add_html_row_for_included_extra( $field_value, &$content ) {
677 620 $this->prepare_html_display_value_for_extra_fields( $field_value, $display_value );
678 621
@@ -689,11 +632,9 @@
689 632 *
690 633 * @since 3.0
691 634 *
692 635 * @param FrmFieldValue $field_value
693 - * @param string $content
694 - *
695 - * @return void
636 + * @param string $content
696 637 */
697 638 protected function add_plain_text_row_for_included_extra( $field_value, &$content ) {
698 639 $this->prepare_plain_text_display_value_for_extra_fields( $field_value, $display_value );
699 640
@@ -710,10 +651,8 @@
710 651 * @since 3.0
711 652 *
712 653 * @param string $display_value
713 654 * @param string $content
714 - *
715 - * @return void
716 655 */
717 656 protected function add_single_cell_html_row( $display_value, &$content ) {
718 657 // TODO: maybe move to FrmFieldValue
719 658 $display_value = $this->prepare_display_value_for_html_table( $display_value );
@@ -727,10 +666,8 @@
727 666 * @since 3.0
728 667 *
729 668 * @param string $display_value
730 669 * @param string $content
731 - *
732 - * @return void
733 670 */
734 671 protected function add_single_value_plain_text_row( $display_value, &$content ) {
735 672 $content .= $this->prepare_display_value_for_plain_text_content( $display_value );
736 673 }
@@ -740,11 +677,9 @@
740 677 *
741 678 * @since 3.0
742 679 *
743 680 * @param FrmFieldValue $field_value
744 - * @param mixed $display_value
745 - *
746 - * @return void
681 + * @param mixed $display_value
747 682 */
748 683 protected function prepare_html_display_value_for_extra_fields( $field_value, &$display_value ) {
749 684 $display_value = $field_value->get_displayed_value();
750 685 }
@@ -754,11 +689,9 @@
754 689 *
755 690 * @since 3.0
756 691 *
757 692 * @param FrmFieldValue $field_value
758 - * @param mixed $display_value
759 - *
760 - * @return void
693 + * @param mixed $display_value
761 694 */
762 695 protected function prepare_plain_text_display_value_for_extra_fields( $field_value, &$display_value ) {
763 696 $display_value = $field_value->get_displayed_value() . "\r\n";
764 697 }
@@ -768,11 +701,9 @@
768 701 *
769 702 * @since 2.04
770 703 *
771 704 * @param FrmFieldValue $field_value
772 - * @param string $content
773 - *
774 - * @return void
705 + * @param string $content
775 706 */
776 707 protected function add_standard_row( $field_value, &$content ) {
777 708 if ( $this->format === 'plain_text_block' ) {
778 709 $this->add_plain_text_row( $field_value->get_field_label(), $field_value->get_displayed_value(), $content );
@@ -804,14 +735,14 @@
804 735 *
805 736 * @since 2.04
806 737 *
807 738 * @param string $content
808 - *
809 - * @return void
810 739 */
811 740 protected function add_user_info_to_html_table( &$content ) {
812 741 if ( $this->include_user_info ) {
742 +
813 743 foreach ( $this->entry_values->get_user_info() as $user_info ) {
744 +
814 745 $value_args = array(
815 746 'label' => $user_info['label'],
816 747 'value' => $user_info['value'],
817 748 'field_type' => 'none',
@@ -827,10 +758,8 @@
827 758 *
828 759 * @since 2.04
829 760 *
830 761 * @param string $content
831 - *
832 - * @return void
833 762 */
834 763 protected function add_user_info_to_plain_text_content( &$content ) {
835 764 if ( $this->include_user_info ) {
836 765
@@ -891,9 +820,9 @@
891 820 * Add a row in an HTML table
892 821 *
893 822 * @since 2.04
894 823 *
895 - * @param array $value_args
824 + * @param array $value_args
896 825 * $value_args = [
897 826 * 'label' => (string) The label. Required
898 827 * 'value' => (mixed) The value to add. Required
899 828 * 'field_type' => (string) The field type. Blank string if not a field.
@@ -898,19 +827,13 @@
898 827 * 'value' => (mixed) The value to add. Required
899 828 * 'field_type' => (string) The field type. Blank string if not a field.
900 829 * ]
901 830 * @param string $content
902 - *
903 - * @return void
904 831 */
905 832 protected function add_html_row( $value_args, &$content ) {
906 833 $display_value = $this->prepare_display_value_for_html_table( $value_args['value'], $value_args['field_type'] );
907 834
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 - );
835 + $content .= $this->table_generator->generate_two_cell_table_row( $value_args['label'], $display_value );
913 836 }
914 837
915 838 /**
916 839 * Prepare the displayed value for an array
@@ -929,9 +852,9 @@
929 852 * Prepare a field's display value for an HTML table
930 853 *
931 854 * @since 2.04
932 855 *
933 - * @param mixed $display_value
856 + * @param mixed $display_value
934 857 * @param string $field_type
935 858 *
936 859 * @return mixed|string
937 860 */
@@ -936,9 +859,8 @@
936 859 * @return mixed|string
937 860 */
938 861 protected function prepare_display_value_for_html_table( $display_value, $field_type = '' ) {
939 862 $display_value = $this->flatten_array( $display_value );
940 -
941 863 if ( ! isset( $this->atts['line_breaks'] ) || ! empty( $this->atts['line_breaks'] ) ) {
942 864 $display_value = str_replace( array( "\r\n", "\n" ), '<br/>', $display_value );
943 865 }
944 866
@@ -951,9 +873,9 @@
951 873 * @since 2.04
952 874 *
953 875 * @param mixed $display_value
954 876 *
955 - * @return int|string
877 + * @return string|int
956 878 */
957 879 protected function prepare_display_value_for_plain_text_content( $display_value ) {
958 880 $display_value = $this->flatten_array( $display_value );
959 881 $display_value = $this->strip_html( $display_value );
@@ -965,15 +887,15 @@
965 887 * Flatten an array
966 888 *
967 889 * @since 2.04
968 890 *
969 - * @param array|int|string $value
891 + * @param array|string|int $value
970 892 *
971 - * @return int|string
893 + * @return string|int
972 894 */
973 895 protected function flatten_array( $value ) {
974 896 if ( is_array( $value ) ) {
975 - $separator = $this->atts['array_separator'] ?? ', ';
897 + $separator = isset( $this->atts['array_separator'] ) ? $this->atts['array_separator'] : ', ';
976 898 $value = implode( $separator, $value );
977 899 }
978 900
979 901 return $value;
@@ -988,9 +910,11 @@
988 910 *
989 911 * @return mixed
990 912 */
991 913 protected function strip_html( $value ) {
914 +
992 915 if ( $this->is_plain_text ) {
916 +
993 917 if ( is_array( $value ) ) {
994 918 foreach ( $value as $key => $single_value ) {
995 919 $value[ $key ] = $this->strip_html( $single_value );
996 920 }
@@ -998,9 +922,8 @@
998 922 if ( strpos( $value, '<img' ) !== false ) {
999 923 $value = str_replace( array( '<img', 'src=', '/>', '"' ), '', $value );
1000 924 $value = trim( $value );
1001 925 }
1002 -
1003 926 $value = strip_tags( $value );
1004 927 }
1005 928 }
1006 929