PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.13
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.13
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 +44 -103 6.276.13 View file →
@@ -16,9 +16,8 @@
16 16 protected $entry;
17 17
18 18 /**
19 19 * @var FrmEntryValues|null
20 - *
21 20 * @since 2.04
22 21 */
23 22 protected $entry_values;
24 23
@@ -23,9 +22,8 @@
23 22 protected $entry_values;
24 23
25 24 /**
26 25 * @var bool
27 - *
28 26 * @since 2.04
29 27 */
30 28 protected $is_plain_text = false;
31 29
@@ -30,9 +28,8 @@
30 28 protected $is_plain_text = false;
31 29
32 30 /**
33 31 * @var bool
34 - *
35 32 * @since 2.04
36 33 */
37 34 protected $include_user_info = false;
38 35
@@ -37,9 +34,8 @@
37 34 protected $include_user_info = false;
38 35
39 36 /**
40 37 * @var bool
41 - *
42 38 * @since 2.04
43 39 */
44 40 protected $include_blank = false;
45 41
@@ -44,9 +40,8 @@
44 40 protected $include_blank = false;
45 41
46 42 /**
47 43 * @var string
48 - *
49 44 * @since 2.04
50 45 */
51 46 protected $format = 'text';
52 47
@@ -51,9 +46,8 @@
51 46 protected $format = 'text';
52 47
53 48 /**
54 49 * @var string
55 - *
56 50 * @since 2.05
57 51 */
58 52 protected $array_key = 'key';
59 53
@@ -58,9 +52,8 @@
58 52 protected $array_key = 'key';
59 53
60 54 /**
61 55 * @var string
62 - *
63 56 * @since 2.04
64 57 */
65 58 protected $direction = 'ltr';
66 59
@@ -65,9 +58,8 @@
65 58 protected $direction = 'ltr';
66 59
67 60 /**
68 61 * @var FrmTableHTMLGenerator|null
69 - *
70 62 * @since 2.04
71 63 */
72 64 protected $table_generator;
73 65
@@ -72,9 +64,8 @@
72 64 protected $table_generator;
73 65
74 66 /**
75 67 * @var bool
76 - *
77 68 * @since 2.04
78 69 */
79 70 protected $is_clickable = false;
80 71
@@ -79,9 +70,8 @@
79 70 protected $is_clickable = false;
80 71
81 72 /**
82 73 * @var array
83 - *
84 74 * @since 2.04
85 75 */
86 76 protected $include_extras = array();
87 77
@@ -86,9 +76,8 @@
86 76 protected $include_extras = array();
87 77
88 78 /**
89 79 * @var array
90 - *
91 80 * @since 3.0
92 81 */
93 82 protected $single_cell_fields = array();
94 83
@@ -93,9 +82,8 @@
93 82 protected $single_cell_fields = array();
94 83
95 84 /**
96 85 * @var array
97 - *
98 86 * @since 3.0
99 87 */
100 88 protected $atts = array();
101 89
@@ -136,14 +124,17 @@
136 124 *
137 125 * @since 2.04
138 126 *
139 127 * @param array $atts
140 - *
141 - * @return void
142 128 */
143 129 protected function init_entry( $atts ) {
144 130 if ( isset( $atts['entry'] ) && is_object( $atts['entry'] ) ) {
145 - $this->entry = isset( $atts['entry']->metas ) ? $atts['entry'] : FrmEntry::getOne( $atts['entry']->id, true );
131 +
132 + if ( isset( $atts['entry']->metas ) ) {
133 + $this->entry = $atts['entry'];
134 + } else {
135 + $this->entry = FrmEntry::getOne( $atts['entry']->id, true );
136 + }
146 137 } elseif ( ! empty( $atts['id'] ) ) {
147 138 $this->entry = FrmEntry::getOne( $atts['id'], true );
148 139 }
149 140 }
@@ -153,10 +144,8 @@
153 144 *
154 145 * @since 2.04
155 146 *
156 147 * @param array $atts
157 - *
158 - * @return void
159 148 */
160 149 protected function init_entry_values( $atts ) {
161 150 $entry_atts = $this->prepare_entry_attributes( $atts );
162 151 $this->entry_values = new FrmEntryValues( $this->entry->id, $entry_atts );
@@ -171,11 +160,11 @@
171 160 *
172 161 * @return array
173 162 */
174 163 protected function prepare_entry_attributes( $atts ) {
175 - $entry_atts = array();
164 + $entry_atts = array();
165 +
176 166 $conditionally_add = array( 'include_fields', 'fields', 'exclude_fields', 'entry' );
177 -
178 167 foreach ( $conditionally_add as $index ) {
179 168 if ( isset( $atts[ $index ] ) ) {
180 169 $entry_atts[ $index ] = $atts[ $index ];
181 170 }
@@ -189,18 +178,25 @@
189 178 *
190 179 * @since 2.04
191 180 *
192 181 * @param array $atts
193 - *
194 - * @return void
195 182 */
196 183 protected function init_format( $atts ) {
197 184 if ( $atts['format'] === 'array' ) {
185 +
198 186 $this->format = 'array';
187 +
199 188 } elseif ( $atts['format'] === 'json' ) {
189 +
200 190 $this->format = 'json';
191 +
201 192 } elseif ( $atts['format'] === 'text' ) {
202 - $this->format = $this->is_plain_text === true ? 'plain_text_block' : 'table';
193 +
194 + if ( $this->is_plain_text === true ) {
195 + $this->format = 'plain_text_block';
196 + } else {
197 + $this->format = 'table';
198 + }
203 199 }
204 200
205 201 /**
206 202 * Allows modifying the format property of FrmEntryFormatter object.
@@ -226,10 +222,8 @@
226 222 *
227 223 * @since 2.05
228 224 *
229 225 * @param array $atts
230 - *
231 - * @return void
232 226 */
233 227 protected function init_array_key( $atts ) {
234 228 if ( isset( $atts['array_key'] ) && $atts['array_key'] === 'id' ) {
235 229 $this->array_key = 'id';
@@ -241,13 +235,11 @@
241 235 *
242 236 * @since 2.04
243 237 *
244 238 * @param array $atts
245 - *
246 - * @return void
247 239 */
248 240 protected function init_is_plain_text( $atts ) {
249 - if ( ! empty( $atts['plain_text'] ) ) {
241 + if ( isset( $atts['plain_text'] ) && $atts['plain_text'] ) {
250 242 $this->is_plain_text = true;
251 243 } elseif ( $atts['format'] !== 'text' ) {
252 244 $this->is_plain_text = true;
253 245 }
@@ -258,13 +250,11 @@
258 250 *
259 251 * @since 2.04
260 252 *
261 253 * @param array $atts
262 - *
263 - * @return void
264 254 */
265 255 protected function init_include_blank( $atts ) {
266 - if ( ! empty( $atts['include_blank'] ) ) {
256 + if ( isset( $atts['include_blank'] ) && $atts['include_blank'] ) {
267 257 $this->include_blank = true;
268 258 }
269 259 }
270 260
@@ -273,10 +263,8 @@
273 263 *
274 264 * @since 2.04
275 265 *
276 266 * @param array $atts
277 - *
278 - * @return void
279 267 */
280 268 protected function init_direction( $atts ) {
281 269 if ( isset( $atts['direction'] ) && $atts['direction'] === 'rtl' ) {
282 270 $this->direction = 'rtl';
@@ -288,13 +276,11 @@
288 276 *
289 277 * @since 2.04
290 278 *
291 279 * @param array $atts
292 - *
293 - * @return void
294 280 */
295 281 protected function init_include_user_info( $atts ) {
296 - if ( ! empty( $atts['user_info'] ) ) {
282 + if ( isset( $atts['user_info'] ) && $atts['user_info'] ) {
297 283 $this->include_user_info = true;
298 284 }
299 285 }
300 286
@@ -301,10 +287,8 @@
301 287 /**
302 288 * Which fields to skip by default
303 289 *
304 290 * @since 3.0
305 - *
306 - * @return array
307 291 */
308 292 protected function skip_fields() {
309 293 return array( 'captcha', 'html', FrmSubmitHelper::FIELD_TYPE );
310 294 }
@@ -314,13 +298,11 @@
314 298 *
315 299 * @since 3.0
316 300 *
317 301 * @param array $atts
318 - *
319 - * @return void
320 302 */
321 303 protected function init_include_extras( $atts ) {
322 - if ( ! empty( $atts['include_extras'] ) ) {
304 + if ( isset( $atts['include_extras'] ) && $atts['include_extras'] ) {
323 305 $this->include_extras = array_map( 'strtolower', array_map( 'trim', explode( ',', $atts['include_extras'] ) ) );
324 306 }
325 307 }
326 308
@@ -327,10 +309,8 @@
327 309 /**
328 310 * Initialize the single_cell_fields property
329 311 *
330 312 * @since 3.0
331 - *
332 - * @return void
333 313 */
334 314 protected function init_single_cell_fields() {
335 315 $this->single_cell_fields = array( 'html' );
336 316 }
@@ -340,10 +320,8 @@
340 320 *
341 321 * @since 2.04
342 322 *
343 323 * @param array $atts
344 - *
345 - * @return void
346 324 */
347 325 protected function init_table_generator( $atts ) {
348 326 $this->table_generator = new FrmTableHTMLGenerator( 'entry', $atts );
349 327 }
@@ -353,13 +331,11 @@
353 331 *
354 332 * @since 2.04
355 333 *
356 334 * @param array $atts
357 - *
358 - * @return void
359 335 */
360 336 protected function init_is_clickable( $atts ) {
361 - if ( ! empty( $atts['clickable'] ) ) {
337 + if ( isset( $atts['clickable'] ) && $atts['clickable'] ) {
362 338 $this->is_clickable = true;
363 339 }
364 340 }
365 341
@@ -367,12 +343,8 @@
367 343 * Save the passed atts for other calls. Exclude some attributes to prevent
368 344 * interaction with processing field values like time format.
369 345 *
370 346 * @since 3.0
371 - *
372 - * @param array $atts
373 - *
374 - * @return void
375 347 */
376 348 protected function init_atts( $atts ) {
377 349 $atts['source'] = 'entry_formatter';
378 350 $atts['wpautop'] = false;
@@ -378,9 +350,8 @@
378 350 $atts['wpautop'] = false;
379 351 $atts['return_array'] = true;
380 352
381 353 $unset = array( 'id', 'form_id', 'format' );
382 -
383 354 foreach ( $unset as $param ) {
384 355 if ( isset( $atts[ $param ] ) ) {
385 356 unset( $atts[ $param ] );
386 357 }
@@ -478,13 +449,12 @@
478 449 *
479 450 * @since 2.05
480 451 *
481 452 * @param string $content
482 - *
483 - * @return void
484 453 */
485 454 protected function add_field_values_to_content( &$content ) {
486 455 foreach ( $this->entry_values->get_field_values() as $field_value ) {
456 +
487 457 /**
488 458 * @var FrmFieldValue $field_value
489 459 */
490 460 $field_value->prepare_displayed_value( $this->atts );
@@ -529,10 +499,8 @@
529 499 * @since 2.04
530 500 *
531 501 * @param array $field_values
532 502 * @param array $output
533 - *
534 - * @return void
535 503 */
536 504 protected function push_field_values_to_array( $field_values, &$output ) {
537 505 foreach ( $field_values as $field_value ) {
538 506 /**
@@ -549,17 +517,17 @@
549 517 * @since 2.04
550 518 *
551 519 * @param FrmFieldValue $field_value
552 520 * @param array $output
553 - *
554 - * @return void
555 521 */
556 522 protected function push_single_field_to_array( $field_value, &$output ) {
557 523 if ( $this->include_field_in_content( $field_value ) ) {
558 - $displayed_value = $this->prepare_display_value_for_array( $field_value->get_displayed_value() );
524 +
525 + $displayed_value = $this->prepare_display_value_for_array( $field_value->get_displayed_value() );
526 +
559 527 $output[ $this->get_key_or_id( $field_value ) ] = $displayed_value;
560 - $has_separate_value = (bool) $field_value->get_field_option( 'separate_value' );
561 528
529 + $has_separate_value = (bool) $field_value->get_field_option( 'separate_value' );
562 530 if ( $has_separate_value || $displayed_value !== $field_value->get_saved_value() ) {
563 531 $output[ $this->get_key_or_id( $field_value ) . '-value' ] = $field_value->get_saved_value();
564 532 }
565 533 }
@@ -572,15 +540,13 @@
572 540 *
573 541 * @param string $label
574 542 * @param mixed $display_value
575 543 * @param string $content
576 - *
577 - * @return void
578 544 */
579 545 protected function add_plain_text_row( $label, $display_value, &$content ) {
580 546 $display_value = $this->prepare_display_value_for_plain_text_content( $display_value );
581 547
582 - if ( 'rtl' === $this->direction ) {
548 + if ( 'rtl' == $this->direction ) {
583 549 $content .= wp_kses_post( $display_value . ' :' . $label ) . "\r\n";
584 550 } else {
585 551 $content .= wp_kses_post( $label . ': ' . $display_value ) . "\r\n";
586 552 }
@@ -592,10 +558,8 @@
592 558 * @since 2.04
593 559 *
594 560 * @param FrmFieldValue $field_value
595 561 * @param string $content
596 - *
597 - * @return void
598 562 */
599 563 protected function add_field_value_to_content( $field_value, &$content ) {
600 564 if ( $this->is_extra_field( $field_value ) ) {
601 565 $this->add_row_for_extra_field( $field_value, $content );
@@ -611,10 +575,8 @@
611 575 * @since 3.0
612 576 *
613 577 * @param FrmFieldValue $field_value
614 578 * @param string $content
615 - *
616 - * @return void
617 579 */
618 580 protected function add_row_for_extra_field( $field_value, &$content ) {
619 581 if ( ! $this->include_field_in_content( $field_value ) ) {
620 582 return;
@@ -633,10 +595,8 @@
633 595 * @since 3.0
634 596 *
635 597 * @param FrmFieldValue $field_value
636 598 * @param string $content
637 - *
638 - * @return void
639 599 */
640 600 protected function add_row_for_standard_field( $field_value, &$content ) {
641 601 if ( ! $this->include_field_in_content( $field_value ) ) {
642 602 return;
@@ -656,15 +616,13 @@
656 616 * @since 3.0
657 617 *
658 618 * @param FrmFieldValue $field_value
659 619 * @param string $content
660 - *
661 - * @return void
662 620 */
663 621 protected function add_html_row_for_included_extra( $field_value, &$content ) {
664 622 $this->prepare_html_display_value_for_extra_fields( $field_value, $display_value );
665 623
666 - if ( in_array( $field_value->get_field_type(), $this->single_cell_fields, true ) ) {
624 + if ( in_array( $field_value->get_field_type(), $this->single_cell_fields ) ) {
667 625 $this->add_single_cell_html_row( $display_value, $content );
668 626 } else {
669 627 $value_args = $this->package_value_args( $field_value );
670 628 $this->add_html_row( $value_args, $content );
@@ -677,15 +635,13 @@
677 635 * @since 3.0
678 636 *
679 637 * @param FrmFieldValue $field_value
680 638 * @param string $content
681 - *
682 - * @return void
683 639 */
684 640 protected function add_plain_text_row_for_included_extra( $field_value, &$content ) {
685 641 $this->prepare_plain_text_display_value_for_extra_fields( $field_value, $display_value );
686 642
687 - if ( in_array( $field_value->get_field_type(), $this->single_cell_fields, true ) ) {
643 + if ( in_array( $field_value->get_field_type(), $this->single_cell_fields ) ) {
688 644 $this->add_single_value_plain_text_row( $display_value, $content );
689 645 } else {
690 646 $this->add_plain_text_row( $field_value->get_field_label(), $display_value, $content );
691 647 }
@@ -697,10 +653,8 @@
697 653 * @since 3.0
698 654 *
699 655 * @param string $display_value
700 656 * @param string $content
701 - *
702 - * @return void
703 657 */
704 658 protected function add_single_cell_html_row( $display_value, &$content ) {
705 659 // TODO: maybe move to FrmFieldValue
706 660 $display_value = $this->prepare_display_value_for_html_table( $display_value );
@@ -714,10 +668,8 @@
714 668 * @since 3.0
715 669 *
716 670 * @param string $display_value
717 671 * @param string $content
718 - *
719 - * @return void
720 672 */
721 673 protected function add_single_value_plain_text_row( $display_value, &$content ) {
722 674 $content .= $this->prepare_display_value_for_plain_text_content( $display_value );
723 675 }
@@ -728,10 +680,8 @@
728 680 * @since 3.0
729 681 *
730 682 * @param FrmFieldValue $field_value
731 683 * @param mixed $display_value
732 - *
733 - * @return void
734 684 */
735 685 protected function prepare_html_display_value_for_extra_fields( $field_value, &$display_value ) {
736 686 $display_value = $field_value->get_displayed_value();
737 687 }
@@ -742,10 +692,8 @@
742 692 * @since 3.0
743 693 *
744 694 * @param FrmFieldValue $field_value
745 695 * @param mixed $display_value
746 - *
747 - * @return void
748 696 */
749 697 protected function prepare_plain_text_display_value_for_extra_fields( $field_value, &$display_value ) {
750 698 $display_value = $field_value->get_displayed_value() . "\r\n";
751 699 }
@@ -756,10 +704,8 @@
756 704 * @since 2.04
757 705 *
758 706 * @param FrmFieldValue $field_value
759 707 * @param string $content
760 - *
761 - * @return void
762 708 */
763 709 protected function add_standard_row( $field_value, &$content ) {
764 710 if ( $this->format === 'plain_text_block' ) {
765 711 $this->add_plain_text_row( $field_value->get_field_label(), $field_value->get_displayed_value(), $content );
@@ -791,14 +737,14 @@
791 737 *
792 738 * @since 2.04
793 739 *
794 740 * @param string $content
795 - *
796 - * @return void
797 741 */
798 742 protected function add_user_info_to_html_table( &$content ) {
799 743 if ( $this->include_user_info ) {
744 +
800 745 foreach ( $this->entry_values->get_user_info() as $user_info ) {
746 +
801 747 $value_args = array(
802 748 'label' => $user_info['label'],
803 749 'value' => $user_info['value'],
804 750 'field_type' => 'none',
@@ -814,13 +760,12 @@
814 760 *
815 761 * @since 2.04
816 762 *
817 763 * @param string $content
818 - *
819 - * @return void
820 764 */
821 765 protected function add_user_info_to_plain_text_content( &$content ) {
822 766 if ( $this->include_user_info ) {
767 +
823 768 foreach ( $this->entry_values->get_user_info() as $user_info ) {
824 769 $this->add_plain_text_row( $user_info['label'], $user_info['value'], $content );
825 770 }
826 771 }
@@ -856,9 +801,9 @@
856 801 *
857 802 * @return bool
858 803 */
859 804 protected function is_extra_field( $field_value ) {
860 - return in_array( $field_value->get_field_type(), $this->skip_fields(), true );
805 + return in_array( $field_value->get_field_type(), $this->skip_fields() );
861 806 }
862 807
863 808 /**
864 809 * Check if an extra field is included
@@ -869,9 +814,9 @@
869 814 *
870 815 * @return bool
871 816 */
872 817 protected function is_extra_field_included( $field_value ) {
873 - return in_array( $field_value->get_field_type(), $this->include_extras, true );
818 + return in_array( $field_value->get_field_type(), $this->include_extras );
874 819 }
875 820
876 821 /**
877 822 * Add a row in an HTML table
@@ -884,19 +829,13 @@
884 829 * 'value' => (mixed) The value to add. Required
885 830 * 'field_type' => (string) The field type. Blank string if not a field.
886 831 * ]
887 832 * @param string $content
888 - *
889 - * @return void
890 833 */
891 834 protected function add_html_row( $value_args, &$content ) {
892 835 $display_value = $this->prepare_display_value_for_html_table( $value_args['value'], $value_args['field_type'] );
893 836
894 - $content .= $this->table_generator->generate_two_cell_table_row(
895 - $value_args['label'],
896 - $display_value,
897 - array( 'field_type' => $value_args['field_type'] )
898 - );
837 + $content .= $this->table_generator->generate_two_cell_table_row( $value_args['label'], $display_value );
899 838 }
900 839
901 840 /**
902 841 * Prepare the displayed value for an array
@@ -922,9 +861,8 @@
922 861 * @return mixed|string
923 862 */
924 863 protected function prepare_display_value_for_html_table( $display_value, $field_type = '' ) {
925 864 $display_value = $this->flatten_array( $display_value );
926 -
927 865 if ( ! isset( $this->atts['line_breaks'] ) || ! empty( $this->atts['line_breaks'] ) ) {
928 866 $display_value = str_replace( array( "\r\n", "\n" ), '<br/>', $display_value );
929 867 }
930 868
@@ -941,9 +879,11 @@
941 879 * @return int|string
942 880 */
943 881 protected function prepare_display_value_for_plain_text_content( $display_value ) {
944 882 $display_value = $this->flatten_array( $display_value );
945 - return $this->strip_html( $display_value );
883 + $display_value = $this->strip_html( $display_value );
884 +
885 + return $display_value;
946 886 }
947 887
948 888 /**
949 889 * Flatten an array
@@ -955,9 +895,9 @@
955 895 * @return int|string
956 896 */
957 897 protected function flatten_array( $value ) {
958 898 if ( is_array( $value ) ) {
959 - $separator = $this->atts['array_separator'] ?? ', ';
899 + $separator = isset( $this->atts['array_separator'] ) ? $this->atts['array_separator'] : ', ';
960 900 $value = implode( $separator, $value );
961 901 }
962 902
963 903 return $value;
@@ -972,19 +912,20 @@
972 912 *
973 913 * @return mixed
974 914 */
975 915 protected function strip_html( $value ) {
916 +
976 917 if ( $this->is_plain_text ) {
918 +
977 919 if ( is_array( $value ) ) {
978 920 foreach ( $value as $key => $single_value ) {
979 921 $value[ $key ] = $this->strip_html( $single_value );
980 922 }
981 923 } elseif ( $this->is_plain_text && ! is_array( $value ) ) {
982 - if ( str_contains( $value, '<img' ) ) {
924 + if ( strpos( $value, '<img' ) !== false ) {
983 925 $value = str_replace( array( '<img', 'src=', '/>', '"' ), '', $value );
984 926 $value = trim( $value );
985 927 }
986 -
987 928 $value = strip_tags( $value );
988 929 }
989 930 }
990 931