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