PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0
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 -156 6.265.0 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';
@@ -210,25 +195,8 @@
210 195 } else {
211 196 $this->format = 'table';
212 197 }
213 198 }
214 -
215 - /**
216 - * Allows modifying the format property of FrmEntryFormatter object.
217 - *
218 - * @since 5.0.16
219 - *
220 - * @param string $format The format.
221 - * @param array $args Includes `atts`, `entry`.
222 - */
223 - $this->format = apply_filters(
224 - 'frm_entry_formatter_format',
225 - $this->format,
226 - array(
227 - 'atts' => $atts,
228 - 'entry' => $this->entry,
229 - )
230 - );
231 199 }
232 200
233 201 /**
234 202 * Set the array_key property that sets whether the keys in the
@@ -236,13 +204,11 @@
236 204 *
237 205 * @since 2.05
238 206 *
239 207 * @param array $atts
240 - *
241 - * @return void
242 208 */
243 209 protected function init_array_key( $atts ) {
244 - if ( isset( $atts['array_key'] ) && $atts['array_key'] === 'id' ) {
210 + if ( isset( $atts['array_key'] ) && $atts['array_key'] == 'id' ) {
245 211 $this->array_key = 'id';
246 212 }
247 213 }
248 214
@@ -251,10 +217,8 @@
251 217 *
252 218 * @since 2.04
253 219 *
254 220 * @param array $atts
255 - *
256 - * @return void
257 221 */
258 222 protected function init_is_plain_text( $atts ) {
259 223 if ( isset( $atts['plain_text'] ) && $atts['plain_text'] ) {
260 224 $this->is_plain_text = true;
@@ -268,10 +232,8 @@
268 232 *
269 233 * @since 2.04
270 234 *
271 235 * @param array $atts
272 - *
273 - * @return void
274 236 */
275 237 protected function init_include_blank( $atts ) {
276 238 if ( isset( $atts['include_blank'] ) && $atts['include_blank'] ) {
277 239 $this->include_blank = true;
@@ -283,10 +245,8 @@
283 245 *
284 246 * @since 2.04
285 247 *
286 248 * @param array $atts
287 - *
288 - * @return void
289 249 */
290 250 protected function init_direction( $atts ) {
291 251 if ( isset( $atts['direction'] ) && $atts['direction'] === 'rtl' ) {
292 252 $this->direction = 'rtl';
@@ -298,10 +258,8 @@
298 258 *
299 259 * @since 2.04
300 260 *
301 261 * @param array $atts
302 - *
303 - * @return void
304 262 */
305 263 protected function init_include_user_info( $atts ) {
306 264 if ( isset( $atts['user_info'] ) && $atts['user_info'] ) {
307 265 $this->include_user_info = true;
@@ -311,13 +269,11 @@
311 269 /**
312 270 * Which fields to skip by default
313 271 *
314 272 * @since 3.0
315 - *
316 - * @return array
317 273 */
318 274 protected function skip_fields() {
319 - return array( 'captcha', 'html', FrmSubmitHelper::FIELD_TYPE );
275 + return array( 'captcha', 'html' );
320 276 }
321 277
322 278 /**
323 279 * Set the include_extras property
@@ -324,10 +280,8 @@
324 280 *
325 281 * @since 3.0
326 282 *
327 283 * @param array $atts
328 - *
329 - * @return void
330 284 */
331 285 protected function init_include_extras( $atts ) {
332 286 if ( isset( $atts['include_extras'] ) && $atts['include_extras'] ) {
333 287 $this->include_extras = array_map( 'strtolower', array_map( 'trim', explode( ',', $atts['include_extras'] ) ) );
@@ -337,10 +291,8 @@
337 291 /**
338 292 * Initialize the single_cell_fields property
339 293 *
340 294 * @since 3.0
341 - *
342 - * @return void
343 295 */
344 296 protected function init_single_cell_fields() {
345 297 $this->single_cell_fields = array( 'html' );
346 298 }
@@ -350,10 +302,8 @@
350 302 *
351 303 * @since 2.04
352 304 *
353 305 * @param array $atts
354 - *
355 - * @return void
356 306 */
357 307 protected function init_table_generator( $atts ) {
358 308 $this->table_generator = new FrmTableHTMLGenerator( 'entry', $atts );
359 309 }
@@ -363,10 +313,8 @@
363 313 *
364 314 * @since 2.04
365 315 *
366 316 * @param array $atts
367 - *
368 - * @return void
369 317 */
370 318 protected function init_is_clickable( $atts ) {
371 319 if ( isset( $atts['clickable'] ) && $atts['clickable'] ) {
372 320 $this->is_clickable = true;
@@ -377,12 +325,8 @@
377 325 * Save the passed atts for other calls. Exclude some attributes to prevent
378 326 * interaction with processing field values like time format.
379 327 *
380 328 * @since 3.0
381 - *
382 - * @param array $atts
383 - *
384 - * @return void
385 329 */
386 330 protected function init_atts( $atts ) {
387 331 $atts['source'] = 'entry_formatter';
388 332 $atts['wpautop'] = false;
@@ -387,10 +331,9 @@
387 331 $atts['source'] = 'entry_formatter';
388 332 $atts['wpautop'] = false;
389 333 $atts['return_array'] = true;
390 334
391 - $unset = array( 'id', 'form_id', 'format' );
392 -
335 + $unset = array( 'id', 'entry', 'form_id', 'format' );
393 336 foreach ( $unset as $param ) {
394 337 if ( isset( $atts[ $param ] ) ) {
395 338 unset( $atts[ $param ] );
396 339 }
@@ -395,10 +338,9 @@
395 338 unset( $atts[ $param ] );
396 339 }
397 340 }
398 341
399 - $this->atts = $atts;
400 - $this->atts['entry'] = $this->entry;
342 + $this->atts = $atts;
401 343 }
402 344
403 345 /**
404 346 * Get the field key or ID, depending on array_key property
@@ -406,12 +348,12 @@
406 348 * @since 2.05
407 349 *
408 350 * @param FrmFieldValue $field_value
409 351 *
410 - * @return int|string
352 + * @return string|int
411 353 */
412 354 protected function get_key_or_id( $field_value ) {
413 - return $this->array_key === 'key' ? $field_value->get_field_key() : $field_value->get_field_id();
355 + return $this->array_key == 'key' ? $field_value->get_field_key() : $field_value->get_field_id();
414 356 }
415 357
416 358 /**
417 359 * Package and return the formatted entry values
@@ -440,26 +382,9 @@
440 382 } else {
441 383 $content = '';
442 384 }
443 385
444 - /**
445 - * Allows modifying the formatted entry values content.
446 - *
447 - * @since 5.0.16
448 - *
449 - * @param string $content The formatted entry values content.
450 - * @param array $args Includes `entry`, `atts`, `format`, `entry_values`.
451 - */
452 - return apply_filters(
453 - 'frm_formatted_entry_values_content',
454 - $content,
455 - array(
456 - 'entry' => $this->entry,
457 - 'atts' => $this->atts,
458 - 'format' => $this->format,
459 - 'entry_values' => $this->entry_values,
460 - )
461 - );
386 + return $content;
462 387 }
463 388
464 389 /**
465 390 * Return the formatted HTML table with entry values
@@ -488,13 +413,12 @@
488 413 *
489 414 * @since 2.05
490 415 *
491 416 * @param string $content
492 - *
493 - * @return void
494 417 */
495 418 protected function add_field_values_to_content( &$content ) {
496 - foreach ( $this->entry_values->get_field_values() as $field_value ) {
419 + foreach ( $this->entry_values->get_field_values() as $field_id => $field_value ) {
420 +
497 421 /**
498 422 * @var FrmFieldValue $field_value
499 423 */
500 424 $field_value->prepare_displayed_value( $this->atts );
@@ -539,10 +463,8 @@
539 463 * @since 2.04
540 464 *
541 465 * @param array $field_values
542 466 * @param array $output
543 - *
544 - * @return void
545 467 */
546 468 protected function push_field_values_to_array( $field_values, &$output ) {
547 469 foreach ( $field_values as $field_value ) {
548 470 /**
@@ -558,11 +480,9 @@
558 480 *
559 481 * @since 2.04
560 482 *
561 483 * @param FrmFieldValue $field_value
562 - * @param array $output
563 - *
564 - * @return void
484 + * @param array $output
565 485 */
566 486 protected function push_single_field_to_array( $field_value, &$output ) {
567 487 if ( $this->include_field_in_content( $field_value ) ) {
568 488
@@ -570,9 +490,8 @@
570 490
571 491 $output[ $this->get_key_or_id( $field_value ) ] = $displayed_value;
572 492
573 493 $has_separate_value = (bool) $field_value->get_field_option( 'separate_value' );
574 -
575 494 if ( $has_separate_value || $displayed_value !== $field_value->get_saved_value() ) {
576 495 $output[ $this->get_key_or_id( $field_value ) . '-value' ] = $field_value->get_saved_value();
577 496 }
578 497 }
@@ -583,17 +502,15 @@
583 502 *
584 503 * @since 2.04
585 504 *
586 505 * @param string $label
587 - * @param mixed $display_value
506 + * @param mixed $display_value
588 507 * @param string $content
589 - *
590 - * @return void
591 508 */
592 509 protected function add_plain_text_row( $label, $display_value, &$content ) {
593 510 $display_value = $this->prepare_display_value_for_plain_text_content( $display_value );
594 511
595 - if ( 'rtl' === $this->direction ) {
512 + if ( 'rtl' == $this->direction ) {
596 513 $content .= wp_kses_post( $display_value . ' :' . $label ) . "\r\n";
597 514 } else {
598 515 $content .= wp_kses_post( $label . ': ' . $display_value ) . "\r\n";
599 516 }
@@ -604,11 +521,9 @@
604 521 *
605 522 * @since 2.04
606 523 *
607 524 * @param FrmFieldValue $field_value
608 - * @param string $content
609 - *
610 - * @return void
525 + * @param string $content
611 526 */
612 527 protected function add_field_value_to_content( $field_value, &$content ) {
613 528 if ( $this->is_extra_field( $field_value ) ) {
614 529 $this->add_row_for_extra_field( $field_value, $content );
@@ -623,11 +538,9 @@
623 538 *
624 539 * @since 3.0
625 540 *
626 541 * @param FrmFieldValue $field_value
627 - * @param string $content
628 - *
629 - * @return void
542 + * @param string $content
630 543 */
631 544 protected function add_row_for_extra_field( $field_value, &$content ) {
632 545 if ( ! $this->include_field_in_content( $field_value ) ) {
633 546 return;
@@ -645,11 +558,9 @@
645 558 *
646 559 * @since 3.0
647 560 *
648 561 * @param FrmFieldValue $field_value
649 - * @param string $content
650 - *
651 - * @return void
562 + * @param string $content
652 563 */
653 564 protected function add_row_for_standard_field( $field_value, &$content ) {
654 565 if ( ! $this->include_field_in_content( $field_value ) ) {
655 566 return;
@@ -668,11 +579,9 @@
668 579 *
669 580 * @since 3.0
670 581 *
671 582 * @param FrmFieldValue $field_value
672 - * @param string $content
673 - *
674 - * @return void
583 + * @param string $content
675 584 */
676 585 protected function add_html_row_for_included_extra( $field_value, &$content ) {
677 586 $this->prepare_html_display_value_for_extra_fields( $field_value, $display_value );
678 587
@@ -689,11 +598,9 @@
689 598 *
690 599 * @since 3.0
691 600 *
692 601 * @param FrmFieldValue $field_value
693 - * @param string $content
694 - *
695 - * @return void
602 + * @param string $content
696 603 */
697 604 protected function add_plain_text_row_for_included_extra( $field_value, &$content ) {
698 605 $this->prepare_plain_text_display_value_for_extra_fields( $field_value, $display_value );
699 606
@@ -710,10 +617,8 @@
710 617 * @since 3.0
711 618 *
712 619 * @param string $display_value
713 620 * @param string $content
714 - *
715 - * @return void
716 621 */
717 622 protected function add_single_cell_html_row( $display_value, &$content ) {
718 623 // TODO: maybe move to FrmFieldValue
719 624 $display_value = $this->prepare_display_value_for_html_table( $display_value );
@@ -727,10 +632,8 @@
727 632 * @since 3.0
728 633 *
729 634 * @param string $display_value
730 635 * @param string $content
731 - *
732 - * @return void
733 636 */
734 637 protected function add_single_value_plain_text_row( $display_value, &$content ) {
735 638 $content .= $this->prepare_display_value_for_plain_text_content( $display_value );
736 639 }
@@ -740,11 +643,9 @@
740 643 *
741 644 * @since 3.0
742 645 *
743 646 * @param FrmFieldValue $field_value
744 - * @param mixed $display_value
745 - *
746 - * @return void
647 + * @param mixed $display_value
747 648 */
748 649 protected function prepare_html_display_value_for_extra_fields( $field_value, &$display_value ) {
749 650 $display_value = $field_value->get_displayed_value();
750 651 }
@@ -754,11 +655,9 @@
754 655 *
755 656 * @since 3.0
756 657 *
757 658 * @param FrmFieldValue $field_value
758 - * @param mixed $display_value
759 - *
760 - * @return void
659 + * @param mixed $display_value
761 660 */
762 661 protected function prepare_plain_text_display_value_for_extra_fields( $field_value, &$display_value ) {
763 662 $display_value = $field_value->get_displayed_value() . "\r\n";
764 663 }
@@ -767,12 +666,10 @@
767 666 * Add a standard row to plain text or html table content
768 667 *
769 668 * @since 2.04
770 669 *
771 - * @param FrmFieldValue $field_value
772 - * @param string $content
773 - *
774 - * @return void
670 + * @param FrmProFieldValue $field_value
671 + * @param string $content
775 672 */
776 673 protected function add_standard_row( $field_value, &$content ) {
777 674 if ( $this->format === 'plain_text_block' ) {
778 675 $this->add_plain_text_row( $field_value->get_field_label(), $field_value->get_displayed_value(), $content );
@@ -804,14 +701,14 @@
804 701 *
805 702 * @since 2.04
806 703 *
807 704 * @param string $content
808 - *
809 - * @return void
810 705 */
811 706 protected function add_user_info_to_html_table( &$content ) {
812 707 if ( $this->include_user_info ) {
708 +
813 709 foreach ( $this->entry_values->get_user_info() as $user_info ) {
710 +
814 711 $value_args = array(
815 712 'label' => $user_info['label'],
816 713 'value' => $user_info['value'],
817 714 'field_type' => 'none',
@@ -827,10 +724,8 @@
827 724 *
828 725 * @since 2.04
829 726 *
830 727 * @param string $content
831 - *
832 - * @return void
833 728 */
834 729 protected function add_user_info_to_plain_text_content( &$content ) {
835 730 if ( $this->include_user_info ) {
836 731
@@ -891,9 +786,9 @@
891 786 * Add a row in an HTML table
892 787 *
893 788 * @since 2.04
894 789 *
895 - * @param array $value_args
790 + * @param array $value_args
896 791 * $value_args = [
897 792 * 'label' => (string) The label. Required
898 793 * 'value' => (mixed) The value to add. Required
899 794 * 'field_type' => (string) The field type. Blank string if not a field.
@@ -898,19 +793,13 @@
898 793 * 'value' => (mixed) The value to add. Required
899 794 * 'field_type' => (string) The field type. Blank string if not a field.
900 795 * ]
901 796 * @param string $content
902 - *
903 - * @return void
904 797 */
905 798 protected function add_html_row( $value_args, &$content ) {
906 799 $display_value = $this->prepare_display_value_for_html_table( $value_args['value'], $value_args['field_type'] );
907 800
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 - );
801 + $content .= $this->table_generator->generate_two_cell_table_row( $value_args['label'], $display_value );
913 802 }
914 803
915 804 /**
916 805 * Prepare the displayed value for an array
@@ -929,9 +818,9 @@
929 818 * Prepare a field's display value for an HTML table
930 819 *
931 820 * @since 2.04
932 821 *
933 - * @param mixed $display_value
822 + * @param mixed $display_value
934 823 * @param string $field_type
935 824 *
936 825 * @return mixed|string
937 826 */
@@ -936,9 +825,8 @@
936 825 * @return mixed|string
937 826 */
938 827 protected function prepare_display_value_for_html_table( $display_value, $field_type = '' ) {
939 828 $display_value = $this->flatten_array( $display_value );
940 -
941 829 if ( ! isset( $this->atts['line_breaks'] ) || ! empty( $this->atts['line_breaks'] ) ) {
942 830 $display_value = str_replace( array( "\r\n", "\n" ), '<br/>', $display_value );
943 831 }
944 832
@@ -951,9 +839,9 @@
951 839 * @since 2.04
952 840 *
953 841 * @param mixed $display_value
954 842 *
955 - * @return int|string
843 + * @return string|int
956 844 */
957 845 protected function prepare_display_value_for_plain_text_content( $display_value ) {
958 846 $display_value = $this->flatten_array( $display_value );
959 847 $display_value = $this->strip_html( $display_value );
@@ -965,16 +853,15 @@
965 853 * Flatten an array
966 854 *
967 855 * @since 2.04
968 856 *
969 - * @param array|int|string $value
857 + * @param array|string|int $value
970 858 *
971 - * @return int|string
859 + * @return string|int
972 860 */
973 861 protected function flatten_array( $value ) {
974 862 if ( is_array( $value ) ) {
975 - $separator = $this->atts['array_separator'] ?? ', ';
976 - $value = implode( $separator, $value );
863 + $value = implode( ', ', $value );
977 864 }
978 865
979 866 return $value;
980 867 }
@@ -988,9 +875,11 @@
988 875 *
989 876 * @return mixed
990 877 */
991 878 protected function strip_html( $value ) {
879 +
992 880 if ( $this->is_plain_text ) {
881 +
993 882 if ( is_array( $value ) ) {
994 883 foreach ( $value as $key => $single_value ) {
995 884 $value[ $key ] = $this->strip_html( $single_value );
996 885 }
@@ -998,9 +887,8 @@
998 887 if ( strpos( $value, '<img' ) !== false ) {
999 888 $value = str_replace( array( '<img', 'src=', '/>', '"' ), '', $value );
1000 889 $value = trim( $value );
1001 890 }
1002 -
1003 891 $value = strip_tags( $value );
1004 892 }
1005 893 }
1006 894