| @@ -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 false|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,14 +123,17 @@ | ||
| 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 | - $this->entry = isset( $atts['entry']->metas ) ? $atts['entry'] : FrmEntry::getOne( $atts['entry']->id, true ); | |
| 130 | + | |
| 131 | + if ( isset( $atts['entry']->metas ) ) { | |
| 132 | + $this->entry = $atts['entry']; | |
| 133 | + } else { | |
| 134 | + $this->entry = FrmEntry::getOne( $atts['entry']->id, true ); | |
| 135 | + } | |
| 146 | 136 | } elseif ( ! empty( $atts['id'] ) ) { |
| 147 | 137 | $this->entry = FrmEntry::getOne( $atts['id'], true ); |
| 148 | 138 | } |
| 149 | 139 | } |
| @@ -153,10 +143,8 @@ | ||
| 153 | 143 | * |
| 154 | 144 | * @since 2.04 |
| 155 | 145 | * |
| 156 | 146 | * @param array $atts |
| 157 | - * | |
| 158 | - * @return void | |
| 159 | 147 | */ |
| 160 | 148 | protected function init_entry_values( $atts ) { |
| 161 | 149 | $entry_atts = $this->prepare_entry_attributes( $atts ); |
| 162 | 150 | $this->entry_values = new FrmEntryValues( $this->entry->id, $entry_atts ); |
| @@ -171,11 +159,11 @@ | ||
| 171 | 159 | * |
| 172 | 160 | * @return array |
| 173 | 161 | */ |
| 174 | 162 | protected function prepare_entry_attributes( $atts ) { |
| 175 | - $entry_atts = array(); | |
| 163 | + $entry_atts = array(); | |
| 164 | + | |
| 176 | 165 | $conditionally_add = array( 'include_fields', 'fields', 'exclude_fields', 'entry' ); |
| 177 | - | |
| 178 | 166 | foreach ( $conditionally_add as $index ) { |
| 179 | 167 | if ( isset( $atts[ $index ] ) ) { |
| 180 | 168 | $entry_atts[ $index ] = $atts[ $index ]; |
| 181 | 169 | } |
| @@ -189,18 +177,25 @@ | ||
| 189 | 177 | * |
| 190 | 178 | * @since 2.04 |
| 191 | 179 | * |
| 192 | 180 | * @param array $atts |
| 193 | - * | |
| 194 | - * @return void | |
| 195 | 181 | */ |
| 196 | 182 | protected function init_format( $atts ) { |
| 197 | 183 | if ( $atts['format'] === 'array' ) { |
| 184 | + | |
| 198 | 185 | $this->format = 'array'; |
| 186 | + | |
| 199 | 187 | } elseif ( $atts['format'] === 'json' ) { |
| 188 | + | |
| 200 | 189 | $this->format = 'json'; |
| 190 | + | |
| 201 | 191 | } elseif ( $atts['format'] === 'text' ) { |
| 202 | - $this->format = $this->is_plain_text === true ? 'plain_text_block' : 'table'; | |
| 192 | + | |
| 193 | + if ( $this->is_plain_text === true ) { | |
| 194 | + $this->format = 'plain_text_block'; | |
| 195 | + } else { | |
| 196 | + $this->format = 'table'; | |
| 197 | + } | |
| 203 | 198 | } |
| 204 | 199 | |
| 205 | 200 | /** |
| 206 | 201 | * Allows modifying the format property of FrmEntryFormatter object. |
| @@ -226,13 +221,11 @@ | ||
| 226 | 221 | * |
| 227 | 222 | * @since 2.05 |
| 228 | 223 | * |
| 229 | 224 | * @param array $atts |
| 230 | - * | |
| 231 | - * @return void | |
| 232 | 225 | */ |
| 233 | 226 | protected function init_array_key( $atts ) { |
| 234 | - if ( isset( $atts['array_key'] ) && $atts['array_key'] === 'id' ) { | |
| 227 | + if ( isset( $atts['array_key'] ) && $atts['array_key'] == 'id' ) { | |
| 235 | 228 | $this->array_key = 'id'; |
| 236 | 229 | } |
| 237 | 230 | } |
| 238 | 231 | |
| @@ -241,13 +234,11 @@ | ||
| 241 | 234 | * |
| 242 | 235 | * @since 2.04 |
| 243 | 236 | * |
| 244 | 237 | * @param array $atts |
| 245 | - * | |
| 246 | - * @return void | |
| 247 | 238 | */ |
| 248 | 239 | protected function init_is_plain_text( $atts ) { |
| 249 | - if ( ! empty( $atts['plain_text'] ) ) { | |
| 240 | + if ( isset( $atts['plain_text'] ) && $atts['plain_text'] ) { | |
| 250 | 241 | $this->is_plain_text = true; |
| 251 | 242 | } elseif ( $atts['format'] !== 'text' ) { |
| 252 | 243 | $this->is_plain_text = true; |
| 253 | 244 | } |
| @@ -258,13 +249,11 @@ | ||
| 258 | 249 | * |
| 259 | 250 | * @since 2.04 |
| 260 | 251 | * |
| 261 | 252 | * @param array $atts |
| 262 | - * | |
| 263 | - * @return void | |
| 264 | 253 | */ |
| 265 | 254 | protected function init_include_blank( $atts ) { |
| 266 | - if ( ! empty( $atts['include_blank'] ) ) { | |
| 255 | + if ( isset( $atts['include_blank'] ) && $atts['include_blank'] ) { | |
| 267 | 256 | $this->include_blank = true; |
| 268 | 257 | } |
| 269 | 258 | } |
| 270 | 259 | |
| @@ -273,10 +262,8 @@ | ||
| 273 | 262 | * |
| 274 | 263 | * @since 2.04 |
| 275 | 264 | * |
| 276 | 265 | * @param array $atts |
| 277 | - * | |
| 278 | - * @return void | |
| 279 | 266 | */ |
| 280 | 267 | protected function init_direction( $atts ) { |
| 281 | 268 | if ( isset( $atts['direction'] ) && $atts['direction'] === 'rtl' ) { |
| 282 | 269 | $this->direction = 'rtl'; |
| @@ -288,13 +275,11 @@ | ||
| 288 | 275 | * |
| 289 | 276 | * @since 2.04 |
| 290 | 277 | * |
| 291 | 278 | * @param array $atts |
| 292 | - * | |
| 293 | - * @return void | |
| 294 | 279 | */ |
| 295 | 280 | protected function init_include_user_info( $atts ) { |
| 296 | - if ( ! empty( $atts['user_info'] ) ) { | |
| 281 | + if ( isset( $atts['user_info'] ) && $atts['user_info'] ) { | |
| 297 | 282 | $this->include_user_info = true; |
| 298 | 283 | } |
| 299 | 284 | } |
| 300 | 285 | |
| @@ -301,13 +286,11 @@ | ||
| 301 | 286 | /** |
| 302 | 287 | * Which fields to skip by default |
| 303 | 288 | * |
| 304 | 289 | * @since 3.0 |
| 305 | - * | |
| 306 | - * @return array | |
| 307 | 290 | */ |
| 308 | 291 | protected function skip_fields() { |
| 309 | - return array( 'captcha', 'html', FrmSubmitHelper::FIELD_TYPE ); | |
| 292 | + return array( 'captcha', 'html' ); | |
| 310 | 293 | } |
| 311 | 294 | |
| 312 | 295 | /** |
| 313 | 296 | * Set the include_extras property |
| @@ -314,13 +297,11 @@ | ||
| 314 | 297 | * |
| 315 | 298 | * @since 3.0 |
| 316 | 299 | * |
| 317 | 300 | * @param array $atts |
| 318 | - * | |
| 319 | - * @return void | |
| 320 | 301 | */ |
| 321 | 302 | protected function init_include_extras( $atts ) { |
| 322 | - if ( ! empty( $atts['include_extras'] ) ) { | |
| 303 | + if ( isset( $atts['include_extras'] ) && $atts['include_extras'] ) { | |
| 323 | 304 | $this->include_extras = array_map( 'strtolower', array_map( 'trim', explode( ',', $atts['include_extras'] ) ) ); |
| 324 | 305 | } |
| 325 | 306 | } |
| 326 | 307 | |
| @@ -327,10 +308,8 @@ | ||
| 327 | 308 | /** |
| 328 | 309 | * Initialize the single_cell_fields property |
| 329 | 310 | * |
| 330 | 311 | * @since 3.0 |
| 331 | - * | |
| 332 | - * @return void | |
| 333 | 312 | */ |
| 334 | 313 | protected function init_single_cell_fields() { |
| 335 | 314 | $this->single_cell_fields = array( 'html' ); |
| 336 | 315 | } |
| @@ -340,10 +319,8 @@ | ||
| 340 | 319 | * |
| 341 | 320 | * @since 2.04 |
| 342 | 321 | * |
| 343 | 322 | * @param array $atts |
| 344 | - * | |
| 345 | - * @return void | |
| 346 | 323 | */ |
| 347 | 324 | protected function init_table_generator( $atts ) { |
| 348 | 325 | $this->table_generator = new FrmTableHTMLGenerator( 'entry', $atts ); |
| 349 | 326 | } |
| @@ -353,13 +330,11 @@ | ||
| 353 | 330 | * |
| 354 | 331 | * @since 2.04 |
| 355 | 332 | * |
| 356 | 333 | * @param array $atts |
| 357 | - * | |
| 358 | - * @return void | |
| 359 | 334 | */ |
| 360 | 335 | protected function init_is_clickable( $atts ) { |
| 361 | - if ( ! empty( $atts['clickable'] ) ) { | |
| 336 | + if ( isset( $atts['clickable'] ) && $atts['clickable'] ) { | |
| 362 | 337 | $this->is_clickable = true; |
| 363 | 338 | } |
| 364 | 339 | } |
| 365 | 340 | |
| @@ -367,12 +342,8 @@ | ||
| 367 | 342 | * Save the passed atts for other calls. Exclude some attributes to prevent |
| 368 | 343 | * interaction with processing field values like time format. |
| 369 | 344 | * |
| 370 | 345 | * @since 3.0 |
| 371 | - * | |
| 372 | - * @param array $atts | |
| 373 | - * | |
| 374 | - * @return void | |
| 375 | 346 | */ |
| 376 | 347 | protected function init_atts( $atts ) { |
| 377 | 348 | $atts['source'] = 'entry_formatter'; |
| 378 | 349 | $atts['wpautop'] = false; |
| @@ -377,10 +348,9 @@ | ||
| 377 | 348 | $atts['source'] = 'entry_formatter'; |
| 378 | 349 | $atts['wpautop'] = false; |
| 379 | 350 | $atts['return_array'] = true; |
| 380 | 351 | |
| 381 | - $unset = array( 'id', 'form_id', 'format' ); | |
| 382 | - | |
| 352 | + $unset = array( 'id', 'entry', 'form_id', 'format' ); | |
| 383 | 353 | foreach ( $unset as $param ) { |
| 384 | 354 | if ( isset( $atts[ $param ] ) ) { |
| 385 | 355 | unset( $atts[ $param ] ); |
| 386 | 356 | } |
| @@ -385,10 +355,9 @@ | ||
| 385 | 355 | unset( $atts[ $param ] ); |
| 386 | 356 | } |
| 387 | 357 | } |
| 388 | 358 | |
| 389 | - $this->atts = $atts; | |
| 390 | - $this->atts['entry'] = $this->entry; | |
| 359 | + $this->atts = $atts; | |
| 391 | 360 | } |
| 392 | 361 | |
| 393 | 362 | /** |
| 394 | 363 | * Get the field key or ID, depending on array_key property |
| @@ -396,12 +365,12 @@ | ||
| 396 | 365 | * @since 2.05 |
| 397 | 366 | * |
| 398 | 367 | * @param FrmFieldValue $field_value |
| 399 | 368 | * |
| 400 | - * @return int|string | |
| 369 | + * @return string|int | |
| 401 | 370 | */ |
| 402 | 371 | protected function get_key_or_id( $field_value ) { |
| 403 | - return $this->array_key === 'key' ? $field_value->get_field_key() : $field_value->get_field_id(); | |
| 372 | + return $this->array_key == 'key' ? $field_value->get_field_key() : $field_value->get_field_id(); | |
| 404 | 373 | } |
| 405 | 374 | |
| 406 | 375 | /** |
| 407 | 376 | * Package and return the formatted entry values |
| @@ -416,14 +385,18 @@ | ||
| 416 | 385 | } |
| 417 | 386 | |
| 418 | 387 | if ( $this->format === 'json' ) { |
| 419 | 388 | $content = json_encode( $this->prepare_array() ); |
| 389 | + | |
| 420 | 390 | } elseif ( $this->format === 'array' ) { |
| 421 | 391 | $content = $this->prepare_array(); |
| 392 | + | |
| 422 | 393 | } elseif ( $this->format === 'table' ) { |
| 423 | 394 | $content = $this->prepare_html_table(); |
| 395 | + | |
| 424 | 396 | } elseif ( $this->format === 'plain_text_block' ) { |
| 425 | 397 | $content = $this->prepare_plain_text_block(); |
| 398 | + | |
| 426 | 399 | } else { |
| 427 | 400 | $content = ''; |
| 428 | 401 | } |
| 429 | 402 | |
| @@ -461,9 +434,13 @@ | ||
| 461 | 434 | $this->add_user_info_to_html_table( $content ); |
| 462 | 435 | |
| 463 | 436 | $content .= $this->table_generator->generate_table_footer(); |
| 464 | 437 | |
| 465 | - return $this->is_clickable ? make_clickable( $content ) : $content; | |
| 438 | + if ( $this->is_clickable ) { | |
| 439 | + $content = make_clickable( $content ); | |
| 440 | + } | |
| 441 | + | |
| 442 | + return $content; | |
| 466 | 443 | } |
| 467 | 444 | |
| 468 | 445 | /** |
| 469 | 446 | * Add field values to table or plain text content |
| @@ -470,13 +447,12 @@ | ||
| 470 | 447 | * |
| 471 | 448 | * @since 2.05 |
| 472 | 449 | * |
| 473 | 450 | * @param string $content |
| 474 | - * | |
| 475 | - * @return void | |
| 476 | 451 | */ |
| 477 | 452 | protected function add_field_values_to_content( &$content ) { |
| 478 | - foreach ( $this->entry_values->get_field_values() as $field_value ) { | |
| 453 | + foreach ( $this->entry_values->get_field_values() as $field_id => $field_value ) { | |
| 454 | + | |
| 479 | 455 | /** |
| 480 | 456 | * @var FrmFieldValue $field_value |
| 481 | 457 | */ |
| 482 | 458 | $field_value->prepare_displayed_value( $this->atts ); |
| @@ -521,10 +497,8 @@ | ||
| 521 | 497 | * @since 2.04 |
| 522 | 498 | * |
| 523 | 499 | * @param array $field_values |
| 524 | 500 | * @param array $output |
| 525 | - * | |
| 526 | - * @return void | |
| 527 | 501 | */ |
| 528 | 502 | protected function push_field_values_to_array( $field_values, &$output ) { |
| 529 | 503 | foreach ( $field_values as $field_value ) { |
| 530 | 504 | /** |
| @@ -540,23 +514,21 @@ | ||
| 540 | 514 | * |
| 541 | 515 | * @since 2.04 |
| 542 | 516 | * |
| 543 | 517 | * @param FrmFieldValue $field_value |
| 544 | - * @param array $output | |
| 545 | - * | |
| 546 | - * @return void | |
| 518 | + * @param array $output | |
| 547 | 519 | */ |
| 548 | 520 | protected function push_single_field_to_array( $field_value, &$output ) { |
| 549 | - if ( ! $this->include_field_in_content( $field_value ) ) { | |
| 550 | - return; | |
| 551 | - } | |
| 521 | + if ( $this->include_field_in_content( $field_value ) ) { | |
| 552 | 522 | |
| 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' ); | |
| 523 | + $displayed_value = $this->prepare_display_value_for_array( $field_value->get_displayed_value() ); | |
| 556 | 524 | |
| 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(); | |
| 525 | + $output[ $this->get_key_or_id( $field_value ) ] = $displayed_value; | |
| 526 | + | |
| 527 | + $has_separate_value = (bool) $field_value->get_field_option( 'separate_value' ); | |
| 528 | + if ( $has_separate_value || $displayed_value !== $field_value->get_saved_value() ) { | |
| 529 | + $output[ $this->get_key_or_id( $field_value ) . '-value' ] = $field_value->get_saved_value(); | |
| 530 | + } | |
| 559 | 531 | } |
| 560 | 532 | } |
| 561 | 533 | |
| 562 | 534 | /** |
| @@ -564,17 +536,15 @@ | ||
| 564 | 536 | * |
| 565 | 537 | * @since 2.04 |
| 566 | 538 | * |
| 567 | 539 | * @param string $label |
| 568 | - * @param mixed $display_value | |
| 540 | + * @param mixed $display_value | |
| 569 | 541 | * @param string $content |
| 570 | - * | |
| 571 | - * @return void | |
| 572 | 542 | */ |
| 573 | 543 | protected function add_plain_text_row( $label, $display_value, &$content ) { |
| 574 | 544 | $display_value = $this->prepare_display_value_for_plain_text_content( $display_value ); |
| 575 | 545 | |
| 576 | - if ( 'rtl' === $this->direction ) { | |
| 546 | + if ( 'rtl' == $this->direction ) { | |
| 577 | 547 | $content .= wp_kses_post( $display_value . ' :' . $label ) . "\r\n"; |
| 578 | 548 | } else { |
| 579 | 549 | $content .= wp_kses_post( $label . ': ' . $display_value ) . "\r\n"; |
| 580 | 550 | } |
| @@ -585,15 +555,14 @@ | ||
| 585 | 555 | * |
| 586 | 556 | * @since 2.04 |
| 587 | 557 | * |
| 588 | 558 | * @param FrmFieldValue $field_value |
| 589 | - * @param string $content | |
| 590 | - * | |
| 591 | - * @return void | |
| 559 | + * @param string $content | |
| 592 | 560 | */ |
| 593 | 561 | protected function add_field_value_to_content( $field_value, &$content ) { |
| 594 | 562 | if ( $this->is_extra_field( $field_value ) ) { |
| 595 | 563 | $this->add_row_for_extra_field( $field_value, $content ); |
| 564 | + | |
| 596 | 565 | } else { |
| 597 | 566 | $this->add_row_for_standard_field( $field_value, $content ); |
| 598 | 567 | } |
| 599 | 568 | } |
| @@ -603,11 +572,9 @@ | ||
| 603 | 572 | * |
| 604 | 573 | * @since 3.0 |
| 605 | 574 | * |
| 606 | 575 | * @param FrmFieldValue $field_value |
| 607 | - * @param string $content | |
| 608 | - * | |
| 609 | - * @return void | |
| 576 | + * @param string $content | |
| 610 | 577 | */ |
| 611 | 578 | protected function add_row_for_extra_field( $field_value, &$content ) { |
| 612 | 579 | if ( ! $this->include_field_in_content( $field_value ) ) { |
| 613 | 580 | return; |
| @@ -625,11 +592,9 @@ | ||
| 625 | 592 | * |
| 626 | 593 | * @since 3.0 |
| 627 | 594 | * |
| 628 | 595 | * @param FrmFieldValue $field_value |
| 629 | - * @param string $content | |
| 630 | - * | |
| 631 | - * @return void | |
| 596 | + * @param string $content | |
| 632 | 597 | */ |
| 633 | 598 | protected function add_row_for_standard_field( $field_value, &$content ) { |
| 634 | 599 | if ( ! $this->include_field_in_content( $field_value ) ) { |
| 635 | 600 | return; |
| @@ -648,16 +613,14 @@ | ||
| 648 | 613 | * |
| 649 | 614 | * @since 3.0 |
| 650 | 615 | * |
| 651 | 616 | * @param FrmFieldValue $field_value |
| 652 | - * @param string $content | |
| 653 | - * | |
| 654 | - * @return void | |
| 617 | + * @param string $content | |
| 655 | 618 | */ |
| 656 | 619 | protected function add_html_row_for_included_extra( $field_value, &$content ) { |
| 657 | 620 | $this->prepare_html_display_value_for_extra_fields( $field_value, $display_value ); |
| 658 | 621 | |
| 659 | - if ( in_array( $field_value->get_field_type(), $this->single_cell_fields, true ) ) { | |
| 622 | + if ( in_array( $field_value->get_field_type(), $this->single_cell_fields ) ) { | |
| 660 | 623 | $this->add_single_cell_html_row( $display_value, $content ); |
| 661 | 624 | } else { |
| 662 | 625 | $value_args = $this->package_value_args( $field_value ); |
| 663 | 626 | $this->add_html_row( $value_args, $content ); |
| @@ -669,16 +632,14 @@ | ||
| 669 | 632 | * |
| 670 | 633 | * @since 3.0 |
| 671 | 634 | * |
| 672 | 635 | * @param FrmFieldValue $field_value |
| 673 | - * @param string $content | |
| 674 | - * | |
| 675 | - * @return void | |
| 636 | + * @param string $content | |
| 676 | 637 | */ |
| 677 | 638 | protected function add_plain_text_row_for_included_extra( $field_value, &$content ) { |
| 678 | 639 | $this->prepare_plain_text_display_value_for_extra_fields( $field_value, $display_value ); |
| 679 | 640 | |
| 680 | - if ( in_array( $field_value->get_field_type(), $this->single_cell_fields, true ) ) { | |
| 641 | + if ( in_array( $field_value->get_field_type(), $this->single_cell_fields ) ) { | |
| 681 | 642 | $this->add_single_value_plain_text_row( $display_value, $content ); |
| 682 | 643 | } else { |
| 683 | 644 | $this->add_plain_text_row( $field_value->get_field_label(), $display_value, $content ); |
| 684 | 645 | } |
| @@ -690,10 +651,8 @@ | ||
| 690 | 651 | * @since 3.0 |
| 691 | 652 | * |
| 692 | 653 | * @param string $display_value |
| 693 | 654 | * @param string $content |
| 694 | - * | |
| 695 | - * @return void | |
| 696 | 655 | */ |
| 697 | 656 | protected function add_single_cell_html_row( $display_value, &$content ) { |
| 698 | 657 | // TODO: maybe move to FrmFieldValue |
| 699 | 658 | $display_value = $this->prepare_display_value_for_html_table( $display_value ); |
| @@ -707,10 +666,8 @@ | ||
| 707 | 666 | * @since 3.0 |
| 708 | 667 | * |
| 709 | 668 | * @param string $display_value |
| 710 | 669 | * @param string $content |
| 711 | - * | |
| 712 | - * @return void | |
| 713 | 670 | */ |
| 714 | 671 | protected function add_single_value_plain_text_row( $display_value, &$content ) { |
| 715 | 672 | $content .= $this->prepare_display_value_for_plain_text_content( $display_value ); |
| 716 | 673 | } |
| @@ -720,11 +677,9 @@ | ||
| 720 | 677 | * |
| 721 | 678 | * @since 3.0 |
| 722 | 679 | * |
| 723 | 680 | * @param FrmFieldValue $field_value |
| 724 | - * @param mixed $display_value | |
| 725 | - * | |
| 726 | - * @return void | |
| 681 | + * @param mixed $display_value | |
| 727 | 682 | */ |
| 728 | 683 | protected function prepare_html_display_value_for_extra_fields( $field_value, &$display_value ) { |
| 729 | 684 | $display_value = $field_value->get_displayed_value(); |
| 730 | 685 | } |
| @@ -734,11 +689,9 @@ | ||
| 734 | 689 | * |
| 735 | 690 | * @since 3.0 |
| 736 | 691 | * |
| 737 | 692 | * @param FrmFieldValue $field_value |
| 738 | - * @param mixed $display_value | |
| 739 | - * | |
| 740 | - * @return void | |
| 693 | + * @param mixed $display_value | |
| 741 | 694 | */ |
| 742 | 695 | protected function prepare_plain_text_display_value_for_extra_fields( $field_value, &$display_value ) { |
| 743 | 696 | $display_value = $field_value->get_displayed_value() . "\r\n"; |
| 744 | 697 | } |
| @@ -748,11 +701,9 @@ | ||
| 748 | 701 | * |
| 749 | 702 | * @since 2.04 |
| 750 | 703 | * |
| 751 | 704 | * @param FrmFieldValue $field_value |
| 752 | - * @param string $content | |
| 753 | - * | |
| 754 | - * @return void | |
| 705 | + * @param string $content | |
| 755 | 706 | */ |
| 756 | 707 | protected function add_standard_row( $field_value, &$content ) { |
| 757 | 708 | if ( $this->format === 'plain_text_block' ) { |
| 758 | 709 | $this->add_plain_text_row( $field_value->get_field_label(), $field_value->get_displayed_value(), $content ); |
| @@ -784,24 +735,22 @@ | ||
| 784 | 735 | * |
| 785 | 736 | * @since 2.04 |
| 786 | 737 | * |
| 787 | 738 | * @param string $content |
| 788 | - * | |
| 789 | - * @return void | |
| 790 | 739 | */ |
| 791 | 740 | protected function add_user_info_to_html_table( &$content ) { |
| 792 | - if ( ! $this->include_user_info ) { | |
| 793 | - return; | |
| 794 | - } | |
| 741 | + if ( $this->include_user_info ) { | |
| 795 | 742 | |
| 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 | - ); | |
| 743 | + foreach ( $this->entry_values->get_user_info() as $user_info ) { | |
| 802 | 744 | |
| 803 | - $this->add_html_row( $value_args, $content ); | |
| 745 | + $value_args = array( | |
| 746 | + 'label' => $user_info['label'], | |
| 747 | + 'value' => $user_info['value'], | |
| 748 | + 'field_type' => 'none', | |
| 749 | + ); | |
| 750 | + | |
| 751 | + $this->add_html_row( $value_args, $content ); | |
| 752 | + } | |
| 804 | 753 | } |
| 805 | 754 | } |
| 806 | 755 | |
| 807 | 756 | /** |
| @@ -809,18 +758,15 @@ | ||
| 809 | 758 | * |
| 810 | 759 | * @since 2.04 |
| 811 | 760 | * |
| 812 | 761 | * @param string $content |
| 813 | - * | |
| 814 | - * @return void | |
| 815 | 762 | */ |
| 816 | 763 | protected function add_user_info_to_plain_text_content( &$content ) { |
| 817 | - if ( ! $this->include_user_info ) { | |
| 818 | - return; | |
| 819 | - } | |
| 764 | + if ( $this->include_user_info ) { | |
| 820 | 765 | |
| 821 | - foreach ( $this->entry_values->get_user_info() as $user_info ) { | |
| 822 | - $this->add_plain_text_row( $user_info['label'], $user_info['value'], $content ); | |
| 766 | + foreach ( $this->entry_values->get_user_info() as $user_info ) { | |
| 767 | + $this->add_plain_text_row( $user_info['label'], $user_info['value'], $content ); | |
| 768 | + } | |
| 823 | 769 | } |
| 824 | 770 | } |
| 825 | 771 | |
| 826 | 772 | /** |
| @@ -853,9 +799,9 @@ | ||
| 853 | 799 | * |
| 854 | 800 | * @return bool |
| 855 | 801 | */ |
| 856 | 802 | protected function is_extra_field( $field_value ) { |
| 857 | - return in_array( $field_value->get_field_type(), $this->skip_fields(), true ); | |
| 803 | + return in_array( $field_value->get_field_type(), $this->skip_fields() ); | |
| 858 | 804 | } |
| 859 | 805 | |
| 860 | 806 | /** |
| 861 | 807 | * Check if an extra field is included |
| @@ -866,9 +812,9 @@ | ||
| 866 | 812 | * |
| 867 | 813 | * @return bool |
| 868 | 814 | */ |
| 869 | 815 | protected function is_extra_field_included( $field_value ) { |
| 870 | - return in_array( $field_value->get_field_type(), $this->include_extras, true ); | |
| 816 | + return in_array( $field_value->get_field_type(), $this->include_extras ); | |
| 871 | 817 | } |
| 872 | 818 | |
| 873 | 819 | /** |
| 874 | 820 | * Add a row in an HTML table |
| @@ -874,9 +820,9 @@ | ||
| 874 | 820 | * Add a row in an HTML table |
| 875 | 821 | * |
| 876 | 822 | * @since 2.04 |
| 877 | 823 | * |
| 878 | - * @param array $value_args | |
| 824 | + * @param array $value_args | |
| 879 | 825 | * $value_args = [ |
| 880 | 826 | * 'label' => (string) The label. Required |
| 881 | 827 | * 'value' => (mixed) The value to add. Required |
| 882 | 828 | * 'field_type' => (string) The field type. Blank string if not a field. |
| @@ -881,19 +827,13 @@ | ||
| 881 | 827 | * 'value' => (mixed) The value to add. Required |
| 882 | 828 | * 'field_type' => (string) The field type. Blank string if not a field. |
| 883 | 829 | * ] |
| 884 | 830 | * @param string $content |
| 885 | - * | |
| 886 | - * @return void | |
| 887 | 831 | */ |
| 888 | 832 | protected function add_html_row( $value_args, &$content ) { |
| 889 | 833 | $display_value = $this->prepare_display_value_for_html_table( $value_args['value'], $value_args['field_type'] ); |
| 890 | 834 | |
| 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 | - ); | |
| 835 | + $content .= $this->table_generator->generate_two_cell_table_row( $value_args['label'], $display_value ); | |
| 896 | 836 | } |
| 897 | 837 | |
| 898 | 838 | /** |
| 899 | 839 | * Prepare the displayed value for an array |
| @@ -912,9 +852,9 @@ | ||
| 912 | 852 | * Prepare a field's display value for an HTML table |
| 913 | 853 | * |
| 914 | 854 | * @since 2.04 |
| 915 | 855 | * |
| 916 | - * @param mixed $display_value | |
| 856 | + * @param mixed $display_value | |
| 917 | 857 | * @param string $field_type |
| 918 | 858 | * |
| 919 | 859 | * @return mixed|string |
| 920 | 860 | */ |
| @@ -919,11 +859,10 @@ | ||
| 919 | 859 | * @return mixed|string |
| 920 | 860 | */ |
| 921 | 861 | protected function prepare_display_value_for_html_table( $display_value, $field_type = '' ) { |
| 922 | 862 | $display_value = $this->flatten_array( $display_value ); |
| 923 | - | |
| 924 | 863 | if ( ! isset( $this->atts['line_breaks'] ) || ! empty( $this->atts['line_breaks'] ) ) { |
| 925 | - return str_replace( array( "\r\n", "\n" ), '<br/>', $display_value ); | |
| 864 | + $display_value = str_replace( array( "\r\n", "\n" ), '<br/>', $display_value ); | |
| 926 | 865 | } |
| 927 | 866 | |
| 928 | 867 | return $display_value; |
| 929 | 868 | } |
| @@ -934,13 +873,15 @@ | ||
| 934 | 873 | * @since 2.04 |
| 935 | 874 | * |
| 936 | 875 | * @param mixed $display_value |
| 937 | 876 | * |
| 938 | - * @return int|string | |
| 877 | + * @return string|int | |
| 939 | 878 | */ |
| 940 | 879 | protected function prepare_display_value_for_plain_text_content( $display_value ) { |
| 941 | 880 | $display_value = $this->flatten_array( $display_value ); |
| 942 | - return $this->strip_html( $display_value ); | |
| 881 | + $display_value = $this->strip_html( $display_value ); | |
| 882 | + | |
| 883 | + return $display_value; | |
| 943 | 884 | } |
| 944 | 885 | |
| 945 | 886 | /** |
| 946 | 887 | * Flatten an array |
| @@ -946,15 +887,15 @@ | ||
| 946 | 887 | * Flatten an array |
| 947 | 888 | * |
| 948 | 889 | * @since 2.04 |
| 949 | 890 | * |
| 950 | - * @param array|int|string $value | |
| 891 | + * @param array|string|int $value | |
| 951 | 892 | * |
| 952 | - * @return int|string | |
| 893 | + * @return string|int | |
| 953 | 894 | */ |
| 954 | 895 | protected function flatten_array( $value ) { |
| 955 | 896 | if ( is_array( $value ) ) { |
| 956 | - $separator = $this->atts['array_separator'] ?? ', '; | |
| 897 | + $separator = isset( $this->atts['array_separator'] ) ? $this->atts['array_separator'] : ', '; | |
| 957 | 898 | $value = implode( $separator, $value ); |
| 958 | 899 | } |
| 959 | 900 | |
| 960 | 901 | return $value; |
| @@ -969,23 +910,22 @@ | ||
| 969 | 910 | * |
| 970 | 911 | * @return mixed |
| 971 | 912 | */ |
| 972 | 913 | protected function strip_html( $value ) { |
| 973 | - if ( ! $this->is_plain_text ) { | |
| 974 | - return $value; | |
| 975 | - } | |
| 976 | 914 | |
| 977 | - if ( is_array( $value ) ) { | |
| 978 | - foreach ( $value as $key => $single_value ) { | |
| 979 | - $value[ $key ] = $this->strip_html( $single_value ); | |
| 915 | + if ( $this->is_plain_text ) { | |
| 916 | + | |
| 917 | + if ( is_array( $value ) ) { | |
| 918 | + foreach ( $value as $key => $single_value ) { | |
| 919 | + $value[ $key ] = $this->strip_html( $single_value ); | |
| 920 | + } | |
| 921 | + } elseif ( $this->is_plain_text && ! is_array( $value ) ) { | |
| 922 | + if ( strpos( $value, '<img' ) !== false ) { | |
| 923 | + $value = str_replace( array( '<img', 'src=', '/>', '"' ), '', $value ); | |
| 924 | + $value = trim( $value ); | |
| 925 | + } | |
| 926 | + $value = strip_tags( $value ); | |
| 980 | 927 | } |
| 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 | 928 | } |
| 989 | 929 | |
| 990 | 930 | return $value; |
| 991 | 931 | } |