PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.26.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.26.1
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
formidable / classes / models / FrmEntryFormatter.php

FrmEntryFormatter.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.26.1, at classes/models/FrmEntryFormatter.php

1,010 lines 21.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 /**
7 * @since 2.04
8 */
9 class FrmEntryFormatter {
10
11 /**
12 * @since 2.04
13 *
14 * @var stdClass|null
15 */
16 protected $entry;
17
18 /**
19 * @var FrmEntryValues|null
20 *
21 * @since 2.04
22 */
23 protected $entry_values;
24
25 /**
26 * @var bool
27 *
28 * @since 2.04
29 */
30 protected $is_plain_text = false;
31
32 /**
33 * @var bool
34 *
35 * @since 2.04
36 */
37 protected $include_user_info = false;
38
39 /**
40 * @var bool
41 *
42 * @since 2.04
43 */
44 protected $include_blank = false;
45
46 /**
47 * @var string
48 *
49 * @since 2.04
50 */
51 protected $format = 'text';
52
53 /**
54 * @var string
55 *
56 * @since 2.05
57 */
58 protected $array_key = 'key';
59
60 /**
61 * @var string
62 *
63 * @since 2.04
64 */
65 protected $direction = 'ltr';
66
67 /**
68 * @var FrmTableHTMLGenerator|null
69 *
70 * @since 2.04
71 */
72 protected $table_generator;
73
74 /**
75 * @var bool
76 *
77 * @since 2.04
78 */
79 protected $is_clickable = false;
80
81 /**
82 * @var array
83 *
84 * @since 2.04
85 */
86 protected $include_extras = array();
87
88 /**
89 * @var array
90 *
91 * @since 3.0
92 */
93 protected $single_cell_fields = array();
94
95 /**
96 * @var array
97 *
98 * @since 3.0
99 */
100 protected $atts = array();
101
102 /**
103 * FrmEntryFormat constructor
104 *
105 * @since 2.04
106 *
107 * @param array $atts
108 */
109 public function __construct( $atts ) {
110 $this->init_entry( $atts );
111
112 if ( $this->entry === null || $this->entry === false ) {
113 return;
114 }
115
116 $this->init_is_plain_text( $atts );
117 $this->init_format( $atts );
118 $this->init_array_key( $atts );
119 $this->init_include_blank( $atts );
120 $this->init_direction( $atts );
121 $this->init_include_user_info( $atts );
122 $this->init_include_extras( $atts );
123 $this->init_single_cell_fields();
124 $this->init_entry_values( $atts );
125
126 if ( $this->format === 'table' ) {
127 $this->init_table_generator( $atts );
128 $this->init_is_clickable( $atts );
129 }
130
131 $this->init_atts( $atts );
132 }
133
134 /**
135 * Set the entry property
136 *
137 * @since 2.04
138 *
139 * @param array $atts
140 *
141 * @return void
142 */
143 protected function init_entry( $atts ) {
144 if ( isset( $atts['entry'] ) && is_object( $atts['entry'] ) ) {
145
146 if ( isset( $atts['entry']->metas ) ) {
147 $this->entry = $atts['entry'];
148 } else {
149 $this->entry = FrmEntry::getOne( $atts['entry']->id, true );
150 }
151 } elseif ( ! empty( $atts['id'] ) ) {
152 $this->entry = FrmEntry::getOne( $atts['id'], true );
153 }
154 }
155
156 /**
157 * Set the entry values property
158 *
159 * @since 2.04
160 *
161 * @param array $atts
162 *
163 * @return void
164 */
165 protected function init_entry_values( $atts ) {
166 $entry_atts = $this->prepare_entry_attributes( $atts );
167 $this->entry_values = new FrmEntryValues( $this->entry->id, $entry_atts );
168 }
169
170 /**
171 * Prepare attributes array for FrmEntryValues constructor
172 *
173 * @since 2.05
174 *
175 * @param array $atts
176 *
177 * @return array
178 */
179 protected function prepare_entry_attributes( $atts ) {
180 $entry_atts = array();
181
182 $conditionally_add = array( 'include_fields', 'fields', 'exclude_fields', 'entry' );
183
184 foreach ( $conditionally_add as $index ) {
185 if ( isset( $atts[ $index ] ) ) {
186 $entry_atts[ $index ] = $atts[ $index ];
187 }
188 }
189
190 return $entry_atts;
191 }
192
193 /**
194 * Set the format property
195 *
196 * @since 2.04
197 *
198 * @param array $atts
199 *
200 * @return void
201 */
202 protected function init_format( $atts ) {
203 if ( $atts['format'] === 'array' ) {
204 $this->format = 'array';
205 } elseif ( $atts['format'] === 'json' ) {
206 $this->format = 'json';
207 } elseif ( $atts['format'] === 'text' ) {
208 if ( $this->is_plain_text === true ) {
209 $this->format = 'plain_text_block';
210 } else {
211 $this->format = 'table';
212 }
213 }
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 }
232
233 /**
234 * Set the array_key property that sets whether the keys in the
235 * returned array are field keys or ids
236 *
237 * @since 2.05
238 *
239 * @param array $atts
240 *
241 * @return void
242 */
243 protected function init_array_key( $atts ) {
244 if ( isset( $atts['array_key'] ) && $atts['array_key'] === 'id' ) {
245 $this->array_key = 'id';
246 }
247 }
248
249 /**
250 * Set the is_plain_text property
251 *
252 * @since 2.04
253 *
254 * @param array $atts
255 *
256 * @return void
257 */
258 protected function init_is_plain_text( $atts ) {
259 if ( isset( $atts['plain_text'] ) && $atts['plain_text'] ) {
260 $this->is_plain_text = true;
261 } elseif ( $atts['format'] !== 'text' ) {
262 $this->is_plain_text = true;
263 }
264 }
265
266 /**
267 * Set the include_blank property
268 *
269 * @since 2.04
270 *
271 * @param array $atts
272 *
273 * @return void
274 */
275 protected function init_include_blank( $atts ) {
276 if ( isset( $atts['include_blank'] ) && $atts['include_blank'] ) {
277 $this->include_blank = true;
278 }
279 }
280
281 /**
282 * Set the direction property
283 *
284 * @since 2.04
285 *
286 * @param array $atts
287 *
288 * @return void
289 */
290 protected function init_direction( $atts ) {
291 if ( isset( $atts['direction'] ) && $atts['direction'] === 'rtl' ) {
292 $this->direction = 'rtl';
293 }
294 }
295
296 /**
297 * Set the include_user_info property
298 *
299 * @since 2.04
300 *
301 * @param array $atts
302 *
303 * @return void
304 */
305 protected function init_include_user_info( $atts ) {
306 if ( isset( $atts['user_info'] ) && $atts['user_info'] ) {
307 $this->include_user_info = true;
308 }
309 }
310
311 /**
312 * Which fields to skip by default
313 *
314 * @since 3.0
315 *
316 * @return array
317 */
318 protected function skip_fields() {
319 return array( 'captcha', 'html', FrmSubmitHelper::FIELD_TYPE );
320 }
321
322 /**
323 * Set the include_extras property
324 *
325 * @since 3.0
326 *
327 * @param array $atts
328 *
329 * @return void
330 */
331 protected function init_include_extras( $atts ) {
332 if ( isset( $atts['include_extras'] ) && $atts['include_extras'] ) {
333 $this->include_extras = array_map( 'strtolower', array_map( 'trim', explode( ',', $atts['include_extras'] ) ) );
334 }
335 }
336
337 /**
338 * Initialize the single_cell_fields property
339 *
340 * @since 3.0
341 *
342 * @return void
343 */
344 protected function init_single_cell_fields() {
345 $this->single_cell_fields = array( 'html' );
346 }
347
348 /**
349 * Set the table_generator property
350 *
351 * @since 2.04
352 *
353 * @param array $atts
354 *
355 * @return void
356 */
357 protected function init_table_generator( $atts ) {
358 $this->table_generator = new FrmTableHTMLGenerator( 'entry', $atts );
359 }
360
361 /**
362 * Set the is_clickable property
363 *
364 * @since 2.04
365 *
366 * @param array $atts
367 *
368 * @return void
369 */
370 protected function init_is_clickable( $atts ) {
371 if ( isset( $atts['clickable'] ) && $atts['clickable'] ) {
372 $this->is_clickable = true;
373 }
374 }
375
376 /**
377 * Save the passed atts for other calls. Exclude some attributes to prevent
378 * interaction with processing field values like time format.
379 *
380 * @since 3.0
381 *
382 * @param array $atts
383 *
384 * @return void
385 */
386 protected function init_atts( $atts ) {
387 $atts['source'] = 'entry_formatter';
388 $atts['wpautop'] = false;
389 $atts['return_array'] = true;
390
391 $unset = array( 'id', 'form_id', 'format' );
392
393 foreach ( $unset as $param ) {
394 if ( isset( $atts[ $param ] ) ) {
395 unset( $atts[ $param ] );
396 }
397 }
398
399 $this->atts = $atts;
400 $this->atts['entry'] = $this->entry;
401 }
402
403 /**
404 * Get the field key or ID, depending on array_key property
405 *
406 * @since 2.05
407 *
408 * @param FrmFieldValue $field_value
409 *
410 * @return int|string
411 */
412 protected function get_key_or_id( $field_value ) {
413 return $this->array_key === 'key' ? $field_value->get_field_key() : $field_value->get_field_id();
414 }
415
416 /**
417 * Package and return the formatted entry values
418 *
419 * @since 2.04
420 *
421 * @return array|string
422 */
423 public function get_formatted_entry_values() {
424 if ( $this->entry === null || $this->entry === false ) {
425 return '';
426 }
427
428 if ( $this->format === 'json' ) {
429 $content = json_encode( $this->prepare_array() );
430
431 } elseif ( $this->format === 'array' ) {
432 $content = $this->prepare_array();
433
434 } elseif ( $this->format === 'table' ) {
435 $content = $this->prepare_html_table();
436
437 } elseif ( $this->format === 'plain_text_block' ) {
438 $content = $this->prepare_plain_text_block();
439
440 } else {
441 $content = '';
442 }
443
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 );
462 }
463
464 /**
465 * Return the formatted HTML table with entry values
466 *
467 * @since 2.04
468 *
469 * @return string
470 */
471 protected function prepare_html_table() {
472 $content = $this->table_generator->generate_table_header();
473
474 $this->add_field_values_to_content( $content );
475 $this->add_user_info_to_html_table( $content );
476
477 $content .= $this->table_generator->generate_table_footer();
478
479 if ( $this->is_clickable ) {
480 $content = make_clickable( $content );
481 }
482
483 return $content;
484 }
485
486 /**
487 * Add field values to table or plain text content
488 *
489 * @since 2.05
490 *
491 * @param string $content
492 *
493 * @return void
494 */
495 protected function add_field_values_to_content( &$content ) {
496 foreach ( $this->entry_values->get_field_values() as $field_value ) {
497 /**
498 * @var FrmFieldValue $field_value
499 */
500 $field_value->prepare_displayed_value( $this->atts );
501 $this->add_field_value_to_content( $field_value, $content );
502 }
503 }
504
505 /**
506 * Return the formatted plain text content
507 *
508 * @since 2.04
509 *
510 * @return string
511 */
512 protected function prepare_plain_text_block() {
513 $content = '';
514
515 $this->add_field_values_to_content( $content );
516 $this->add_user_info_to_plain_text_content( $content );
517
518 return $content;
519 }
520
521 /**
522 * Prepare the array output
523 *
524 * @since 2.04
525 *
526 * @return array
527 */
528 protected function prepare_array() {
529 $array_output = array();
530
531 $this->push_field_values_to_array( $this->entry_values->get_field_values(), $array_output );
532
533 return $array_output;
534 }
535
536 /**
537 * Push field values to array content
538 *
539 * @since 2.04
540 *
541 * @param array $field_values
542 * @param array $output
543 *
544 * @return void
545 */
546 protected function push_field_values_to_array( $field_values, &$output ) {
547 foreach ( $field_values as $field_value ) {
548 /**
549 * @var FrmFieldValue $field_value
550 */
551 $field_value->prepare_displayed_value( $this->atts );
552 $this->push_single_field_to_array( $field_value, $output );
553 }
554 }
555
556 /**
557 * Push a single field to the array content
558 *
559 * @since 2.04
560 *
561 * @param FrmFieldValue $field_value
562 * @param array $output
563 *
564 * @return void
565 */
566 protected function push_single_field_to_array( $field_value, &$output ) {
567 if ( $this->include_field_in_content( $field_value ) ) {
568
569 $displayed_value = $this->prepare_display_value_for_array( $field_value->get_displayed_value() );
570
571 $output[ $this->get_key_or_id( $field_value ) ] = $displayed_value;
572
573 $has_separate_value = (bool) $field_value->get_field_option( 'separate_value' );
574
575 if ( $has_separate_value || $displayed_value !== $field_value->get_saved_value() ) {
576 $output[ $this->get_key_or_id( $field_value ) . '-value' ] = $field_value->get_saved_value();
577 }
578 }
579 }
580
581 /**
582 * Add a row of values to the plain text content
583 *
584 * @since 2.04
585 *
586 * @param string $label
587 * @param mixed $display_value
588 * @param string $content
589 *
590 * @return void
591 */
592 protected function add_plain_text_row( $label, $display_value, &$content ) {
593 $display_value = $this->prepare_display_value_for_plain_text_content( $display_value );
594
595 if ( 'rtl' === $this->direction ) {
596 $content .= wp_kses_post( $display_value . ' :' . $label ) . "\r\n";
597 } else {
598 $content .= wp_kses_post( $label . ': ' . $display_value ) . "\r\n";
599 }
600 }
601
602 /**
603 * Add a field value to the HTML table or plain text content
604 *
605 * @since 2.04
606 *
607 * @param FrmFieldValue $field_value
608 * @param string $content
609 *
610 * @return void
611 */
612 protected function add_field_value_to_content( $field_value, &$content ) {
613 if ( $this->is_extra_field( $field_value ) ) {
614 $this->add_row_for_extra_field( $field_value, $content );
615
616 } else {
617 $this->add_row_for_standard_field( $field_value, $content );
618 }
619 }
620
621 /**
622 * Add an extra field to plain text or html table content
623 *
624 * @since 3.0
625 *
626 * @param FrmFieldValue $field_value
627 * @param string $content
628 *
629 * @return void
630 */
631 protected function add_row_for_extra_field( $field_value, &$content ) {
632 if ( ! $this->include_field_in_content( $field_value ) ) {
633 return;
634 }
635
636 if ( $this->format === 'plain_text_block' ) {
637 $this->add_plain_text_row_for_included_extra( $field_value, $content );
638 } elseif ( $this->format === 'table' ) {
639 $this->add_html_row_for_included_extra( $field_value, $content );
640 }
641 }
642
643 /**
644 * Add a standard row to plain text or html table content
645 *
646 * @since 3.0
647 *
648 * @param FrmFieldValue $field_value
649 * @param string $content
650 *
651 * @return void
652 */
653 protected function add_row_for_standard_field( $field_value, &$content ) {
654 if ( ! $this->include_field_in_content( $field_value ) ) {
655 return;
656 }
657
658 if ( $this->format === 'plain_text_block' ) {
659 $this->add_plain_text_row( $field_value->get_field_label(), $field_value->get_displayed_value(), $content );
660 } elseif ( $this->format === 'table' ) {
661 $value_args = $this->package_value_args( $field_value );
662 $this->add_html_row( $value_args, $content );
663 }
664 }
665
666 /**
667 * Add a row to table for included extra
668 *
669 * @since 3.0
670 *
671 * @param FrmFieldValue $field_value
672 * @param string $content
673 *
674 * @return void
675 */
676 protected function add_html_row_for_included_extra( $field_value, &$content ) {
677 $this->prepare_html_display_value_for_extra_fields( $field_value, $display_value );
678
679 if ( in_array( $field_value->get_field_type(), $this->single_cell_fields ) ) {
680 $this->add_single_cell_html_row( $display_value, $content );
681 } else {
682 $value_args = $this->package_value_args( $field_value );
683 $this->add_html_row( $value_args, $content );
684 }
685 }
686
687 /**
688 * Add a plain text row for included extra
689 *
690 * @since 3.0
691 *
692 * @param FrmFieldValue $field_value
693 * @param string $content
694 *
695 * @return void
696 */
697 protected function add_plain_text_row_for_included_extra( $field_value, &$content ) {
698 $this->prepare_plain_text_display_value_for_extra_fields( $field_value, $display_value );
699
700 if ( in_array( $field_value->get_field_type(), $this->single_cell_fields ) ) {
701 $this->add_single_value_plain_text_row( $display_value, $content );
702 } else {
703 $this->add_plain_text_row( $field_value->get_field_label(), $display_value, $content );
704 }
705 }
706
707 /**
708 * Add a single cell row to an HTML table
709 *
710 * @since 3.0
711 *
712 * @param string $display_value
713 * @param string $content
714 *
715 * @return void
716 */
717 protected function add_single_cell_html_row( $display_value, &$content ) {
718 // TODO: maybe move to FrmFieldValue
719 $display_value = $this->prepare_display_value_for_html_table( $display_value );
720
721 $content .= $this->table_generator->generate_single_cell_table_row( $display_value );
722 }
723
724 /**
725 * Add a single value plain text row
726 *
727 * @since 3.0
728 *
729 * @param string $display_value
730 * @param string $content
731 *
732 * @return void
733 */
734 protected function add_single_value_plain_text_row( $display_value, &$content ) {
735 $content .= $this->prepare_display_value_for_plain_text_content( $display_value );
736 }
737
738 /**
739 * Prepare the display value for extra fields an HTML table
740 *
741 * @since 3.0
742 *
743 * @param FrmFieldValue $field_value
744 * @param mixed $display_value
745 *
746 * @return void
747 */
748 protected function prepare_html_display_value_for_extra_fields( $field_value, &$display_value ) {
749 $display_value = $field_value->get_displayed_value();
750 }
751
752 /**
753 * Prepare a plain text value for extra fields
754 *
755 * @since 3.0
756 *
757 * @param FrmFieldValue $field_value
758 * @param mixed $display_value
759 *
760 * @return void
761 */
762 protected function prepare_plain_text_display_value_for_extra_fields( $field_value, &$display_value ) {
763 $display_value = $field_value->get_displayed_value() . "\r\n";
764 }
765
766 /**
767 * Add a standard row to plain text or html table content
768 *
769 * @since 2.04
770 *
771 * @param FrmFieldValue $field_value
772 * @param string $content
773 *
774 * @return void
775 */
776 protected function add_standard_row( $field_value, &$content ) {
777 if ( $this->format === 'plain_text_block' ) {
778 $this->add_plain_text_row( $field_value->get_field_label(), $field_value->get_displayed_value(), $content );
779 } elseif ( $this->format === 'table' ) {
780 $value_args = $this->package_value_args( $field_value );
781 $this->add_html_row( $value_args, $content );
782 }
783 }
784
785 /**
786 * Package the value arguments for an HTML row
787 *
788 * @since 2.04
789 *
790 * @param FrmFieldValue $field_value
791 *
792 * @return array
793 */
794 protected function package_value_args( $field_value ) {
795 return array(
796 'label' => $field_value->get_field_label(),
797 'value' => $field_value->get_displayed_value(),
798 'field_type' => $field_value->get_field_type(),
799 );
800 }
801
802 /**
803 * Add user info to an HTML table
804 *
805 * @since 2.04
806 *
807 * @param string $content
808 *
809 * @return void
810 */
811 protected function add_user_info_to_html_table( &$content ) {
812 if ( $this->include_user_info ) {
813 foreach ( $this->entry_values->get_user_info() as $user_info ) {
814 $value_args = array(
815 'label' => $user_info['label'],
816 'value' => $user_info['value'],
817 'field_type' => 'none',
818 );
819
820 $this->add_html_row( $value_args, $content );
821 }
822 }
823 }
824
825 /**
826 * Add user info to plain text content
827 *
828 * @since 2.04
829 *
830 * @param string $content
831 *
832 * @return void
833 */
834 protected function add_user_info_to_plain_text_content( &$content ) {
835 if ( $this->include_user_info ) {
836
837 foreach ( $this->entry_values->get_user_info() as $user_info ) {
838 $this->add_plain_text_row( $user_info['label'], $user_info['value'], $content );
839 }
840 }
841 }
842
843 /**
844 * Check if a field should be included in the content
845 *
846 * @since 2.04
847 *
848 * @param FrmFieldValue $field_value
849 *
850 * @return bool
851 */
852 protected function include_field_in_content( $field_value ) {
853 $include = true;
854
855 if ( $this->is_extra_field( $field_value ) ) {
856 $include = $this->is_extra_field_included( $field_value );
857 } elseif ( FrmAppHelper::is_empty_value( $field_value->get_displayed_value() ) && ! $this->include_blank ) {
858 $include = false;
859 }
860
861 return apply_filters( 'frm_include_field_in_content', $include, $field_value );
862 }
863
864 /**
865 * Check if a field is normally a skipped type
866 *
867 * @since 2.04
868 *
869 * @param FrmFieldValue $field_value
870 *
871 * @return bool
872 */
873 protected function is_extra_field( $field_value ) {
874 return in_array( $field_value->get_field_type(), $this->skip_fields() );
875 }
876
877 /**
878 * Check if an extra field is included
879 *
880 * @since 2.04
881 *
882 * @param FrmFieldValue $field_value
883 *
884 * @return bool
885 */
886 protected function is_extra_field_included( $field_value ) {
887 return in_array( $field_value->get_field_type(), $this->include_extras );
888 }
889
890 /**
891 * Add a row in an HTML table
892 *
893 * @since 2.04
894 *
895 * @param array $value_args
896 * $value_args = [
897 * 'label' => (string) The label. Required
898 * 'value' => (mixed) The value to add. Required
899 * 'field_type' => (string) The field type. Blank string if not a field.
900 * ]
901 * @param string $content
902 *
903 * @return void
904 */
905 protected function add_html_row( $value_args, &$content ) {
906 $display_value = $this->prepare_display_value_for_html_table( $value_args['value'], $value_args['field_type'] );
907
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 );
913 }
914
915 /**
916 * Prepare the displayed value for an array
917 *
918 * @since 2.04
919 *
920 * @param mixed $value
921 *
922 * @return mixed|string
923 */
924 protected function prepare_display_value_for_array( $value ) {
925 return $this->strip_html( $value );
926 }
927
928 /**
929 * Prepare a field's display value for an HTML table
930 *
931 * @since 2.04
932 *
933 * @param mixed $display_value
934 * @param string $field_type
935 *
936 * @return mixed|string
937 */
938 protected function prepare_display_value_for_html_table( $display_value, $field_type = '' ) {
939 $display_value = $this->flatten_array( $display_value );
940
941 if ( ! isset( $this->atts['line_breaks'] ) || ! empty( $this->atts['line_breaks'] ) ) {
942 $display_value = str_replace( array( "\r\n", "\n" ), '<br/>', $display_value );
943 }
944
945 return $display_value;
946 }
947
948 /**
949 * Prepare a field's display value for plain text content
950 *
951 * @since 2.04
952 *
953 * @param mixed $display_value
954 *
955 * @return int|string
956 */
957 protected function prepare_display_value_for_plain_text_content( $display_value ) {
958 $display_value = $this->flatten_array( $display_value );
959 $display_value = $this->strip_html( $display_value );
960
961 return $display_value;
962 }
963
964 /**
965 * Flatten an array
966 *
967 * @since 2.04
968 *
969 * @param array|int|string $value
970 *
971 * @return int|string
972 */
973 protected function flatten_array( $value ) {
974 if ( is_array( $value ) ) {
975 $separator = $this->atts['array_separator'] ?? ', ';
976 $value = implode( $separator, $value );
977 }
978
979 return $value;
980 }
981
982 /**
983 * Strip HTML if from email value if plain text is selected
984 *
985 * @since 2.0.21
986 *
987 * @param mixed $value
988 *
989 * @return mixed
990 */
991 protected function strip_html( $value ) {
992 if ( $this->is_plain_text ) {
993 if ( is_array( $value ) ) {
994 foreach ( $value as $key => $single_value ) {
995 $value[ $key ] = $this->strip_html( $single_value );
996 }
997 } elseif ( $this->is_plain_text && ! is_array( $value ) ) {
998 if ( strpos( $value, '<img' ) !== false ) {
999 $value = str_replace( array( '<img', 'src=', '/>', '"' ), '', $value );
1000 $value = trim( $value );
1001 }
1002
1003 $value = strip_tags( $value );
1004 }
1005 }
1006
1007 return $value;
1008 }
1009 }
1010