| @@ -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 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,13 +120,11 @@ | ||
| 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'] ) ) { | |
| 126 | + if ( is_object( $atts['entry'] ) ) { | |
| 145 | 127 | |
| 146 | 128 | if ( isset( $atts['entry']->metas ) ) { |
| 147 | 129 | $this->entry = $atts['entry']; |
| 148 | 130 | } else { |
| @@ -147,9 +129,9 @@ | ||
| 147 | 129 | $this->entry = $atts['entry']; |
| 148 | 130 | } else { |
| 149 | 131 | $this->entry = FrmEntry::getOne( $atts['entry']->id, true ); |
| 150 | 132 | } |
| 151 | - } elseif ( ! empty( $atts['id'] ) ) { | |
| 133 | + } else if ( $atts['id'] ) { | |
| 152 | 134 | $this->entry = FrmEntry::getOne( $atts['id'], true ); |
| 153 | 135 | } |
| 154 | 136 | } |
| 155 | 137 | |
| @@ -158,13 +140,11 @@ | ||
| 158 | 140 | * |
| 159 | 141 | * @since 2.04 |
| 160 | 142 | * |
| 161 | 143 | * @param array $atts |
| 162 | - * | |
| 163 | - * @return void | |
| 164 | 144 | */ |
| 165 | 145 | protected function init_entry_values( $atts ) { |
| 166 | - $entry_atts = $this->prepare_entry_attributes( $atts ); | |
| 146 | + $entry_atts = $this->prepare_entry_attributes( $atts ); | |
| 167 | 147 | $this->entry_values = new FrmEntryValues( $this->entry->id, $entry_atts ); |
| 168 | 148 | } |
| 169 | 149 | |
| 170 | 150 | /** |
| @@ -178,10 +158,9 @@ | ||
| 178 | 158 | */ |
| 179 | 159 | protected function prepare_entry_attributes( $atts ) { |
| 180 | 160 | $entry_atts = array(); |
| 181 | 161 | |
| 182 | - $conditionally_add = array( 'include_fields', 'fields', 'exclude_fields', 'entry' ); | |
| 183 | - | |
| 162 | + $conditionally_add = array( 'include_fields', 'fields', 'exclude_fields' ); | |
| 184 | 163 | foreach ( $conditionally_add as $index ) { |
| 185 | 164 | if ( isset( $atts[ $index ] ) ) { |
| 186 | 165 | $entry_atts[ $index ] = $atts[ $index ]; |
| 187 | 166 | } |
| @@ -195,17 +174,20 @@ | ||
| 195 | 174 | * |
| 196 | 175 | * @since 2.04 |
| 197 | 176 | * |
| 198 | 177 | * @param array $atts |
| 199 | - * | |
| 200 | - * @return void | |
| 201 | 178 | */ |
| 202 | 179 | protected function init_format( $atts ) { |
| 203 | 180 | if ( $atts['format'] === 'array' ) { |
| 181 | + | |
| 204 | 182 | $this->format = 'array'; |
| 205 | - } elseif ( $atts['format'] === 'json' ) { | |
| 183 | + | |
| 184 | + } else if ( $atts['format'] === 'json' ) { | |
| 185 | + | |
| 206 | 186 | $this->format = 'json'; |
| 207 | - } elseif ( $atts['format'] === 'text' ) { | |
| 187 | + | |
| 188 | + } else if ( $atts['format'] === 'text' ) { | |
| 189 | + | |
| 208 | 190 | if ( $this->is_plain_text === true ) { |
| 209 | 191 | $this->format = 'plain_text_block'; |
| 210 | 192 | } else { |
| 211 | 193 | $this->format = 'table'; |
| @@ -210,25 +192,8 @@ | ||
| 210 | 192 | } else { |
| 211 | 193 | $this->format = 'table'; |
| 212 | 194 | } |
| 213 | 195 | } |
| 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 | 196 | } |
| 232 | 197 | |
| 233 | 198 | /** |
| 234 | 199 | * Set the array_key property that sets whether the keys in the |
| @@ -236,13 +201,11 @@ | ||
| 236 | 201 | * |
| 237 | 202 | * @since 2.05 |
| 238 | 203 | * |
| 239 | 204 | * @param array $atts |
| 240 | - * | |
| 241 | - * @return void | |
| 242 | 205 | */ |
| 243 | 206 | protected function init_array_key( $atts ) { |
| 244 | - if ( isset( $atts['array_key'] ) && $atts['array_key'] === 'id' ) { | |
| 207 | + if ( isset( $atts['array_key'] ) && $atts['array_key'] == 'id' ) { | |
| 245 | 208 | $this->array_key = 'id'; |
| 246 | 209 | } |
| 247 | 210 | } |
| 248 | 211 | |
| @@ -251,15 +214,13 @@ | ||
| 251 | 214 | * |
| 252 | 215 | * @since 2.04 |
| 253 | 216 | * |
| 254 | 217 | * @param array $atts |
| 255 | - * | |
| 256 | - * @return void | |
| 257 | 218 | */ |
| 258 | 219 | protected function init_is_plain_text( $atts ) { |
| 259 | 220 | if ( isset( $atts['plain_text'] ) && $atts['plain_text'] ) { |
| 260 | 221 | $this->is_plain_text = true; |
| 261 | - } elseif ( $atts['format'] !== 'text' ) { | |
| 222 | + } else if ( $atts['format'] !== 'text' ) { | |
| 262 | 223 | $this->is_plain_text = true; |
| 263 | 224 | } |
| 264 | 225 | } |
| 265 | 226 | |
| @@ -268,10 +229,8 @@ | ||
| 268 | 229 | * |
| 269 | 230 | * @since 2.04 |
| 270 | 231 | * |
| 271 | 232 | * @param array $atts |
| 272 | - * | |
| 273 | - * @return void | |
| 274 | 233 | */ |
| 275 | 234 | protected function init_include_blank( $atts ) { |
| 276 | 235 | if ( isset( $atts['include_blank'] ) && $atts['include_blank'] ) { |
| 277 | 236 | $this->include_blank = true; |
| @@ -283,10 +242,8 @@ | ||
| 283 | 242 | * |
| 284 | 243 | * @since 2.04 |
| 285 | 244 | * |
| 286 | 245 | * @param array $atts |
| 287 | - * | |
| 288 | - * @return void | |
| 289 | 246 | */ |
| 290 | 247 | protected function init_direction( $atts ) { |
| 291 | 248 | if ( isset( $atts['direction'] ) && $atts['direction'] === 'rtl' ) { |
| 292 | 249 | $this->direction = 'rtl'; |
| @@ -298,10 +255,8 @@ | ||
| 298 | 255 | * |
| 299 | 256 | * @since 2.04 |
| 300 | 257 | * |
| 301 | 258 | * @param array $atts |
| 302 | - * | |
| 303 | - * @return void | |
| 304 | 259 | */ |
| 305 | 260 | protected function init_include_user_info( $atts ) { |
| 306 | 261 | if ( isset( $atts['user_info'] ) && $atts['user_info'] ) { |
| 307 | 262 | $this->include_user_info = true; |
| @@ -311,13 +266,11 @@ | ||
| 311 | 266 | /** |
| 312 | 267 | * Which fields to skip by default |
| 313 | 268 | * |
| 314 | 269 | * @since 3.0 |
| 315 | - * | |
| 316 | - * @return array | |
| 317 | 270 | */ |
| 318 | 271 | protected function skip_fields() { |
| 319 | - return array( 'captcha', 'html', FrmSubmitHelper::FIELD_TYPE ); | |
| 272 | + return array( 'captcha', 'html' ); | |
| 320 | 273 | } |
| 321 | 274 | |
| 322 | 275 | /** |
| 323 | 276 | * Set the include_extras property |
| @@ -324,10 +277,8 @@ | ||
| 324 | 277 | * |
| 325 | 278 | * @since 3.0 |
| 326 | 279 | * |
| 327 | 280 | * @param array $atts |
| 328 | - * | |
| 329 | - * @return void | |
| 330 | 281 | */ |
| 331 | 282 | protected function init_include_extras( $atts ) { |
| 332 | 283 | if ( isset( $atts['include_extras'] ) && $atts['include_extras'] ) { |
| 333 | 284 | $this->include_extras = array_map( 'strtolower', array_map( 'trim', explode( ',', $atts['include_extras'] ) ) ); |
| @@ -337,10 +288,8 @@ | ||
| 337 | 288 | /** |
| 338 | 289 | * Initialize the single_cell_fields property |
| 339 | 290 | * |
| 340 | 291 | * @since 3.0 |
| 341 | - * | |
| 342 | - * @return void | |
| 343 | 292 | */ |
| 344 | 293 | protected function init_single_cell_fields() { |
| 345 | 294 | $this->single_cell_fields = array( 'html' ); |
| 346 | 295 | } |
| @@ -350,10 +299,8 @@ | ||
| 350 | 299 | * |
| 351 | 300 | * @since 2.04 |
| 352 | 301 | * |
| 353 | 302 | * @param array $atts |
| 354 | - * | |
| 355 | - * @return void | |
| 356 | 303 | */ |
| 357 | 304 | protected function init_table_generator( $atts ) { |
| 358 | 305 | $this->table_generator = new FrmTableHTMLGenerator( 'entry', $atts ); |
| 359 | 306 | } |
| @@ -363,10 +310,8 @@ | ||
| 363 | 310 | * |
| 364 | 311 | * @since 2.04 |
| 365 | 312 | * |
| 366 | 313 | * @param array $atts |
| 367 | - * | |
| 368 | - * @return void | |
| 369 | 314 | */ |
| 370 | 315 | protected function init_is_clickable( $atts ) { |
| 371 | 316 | if ( isset( $atts['clickable'] ) && $atts['clickable'] ) { |
| 372 | 317 | $this->is_clickable = true; |
| @@ -377,20 +322,15 @@ | ||
| 377 | 322 | * Save the passed atts for other calls. Exclude some attributes to prevent |
| 378 | 323 | * interaction with processing field values like time format. |
| 379 | 324 | * |
| 380 | 325 | * @since 3.0 |
| 381 | - * | |
| 382 | - * @param array $atts | |
| 383 | - * | |
| 384 | - * @return void | |
| 385 | 326 | */ |
| 386 | 327 | protected function init_atts( $atts ) { |
| 387 | - $atts['source'] = 'entry_formatter'; | |
| 388 | - $atts['wpautop'] = false; | |
| 328 | + $atts['source'] = 'entry_formatter'; | |
| 329 | + $atts['wpautop'] = false; | |
| 389 | 330 | $atts['return_array'] = true; |
| 390 | 331 | |
| 391 | - $unset = array( 'id', 'form_id', 'format' ); | |
| 392 | - | |
| 332 | + $unset = array( 'id', 'entry', 'form_id', 'format', 'plain_text' ); | |
| 393 | 333 | foreach ( $unset as $param ) { |
| 394 | 334 | if ( isset( $atts[ $param ] ) ) { |
| 395 | 335 | unset( $atts[ $param ] ); |
| 396 | 336 | } |
| @@ -395,10 +335,9 @@ | ||
| 395 | 335 | unset( $atts[ $param ] ); |
| 396 | 336 | } |
| 397 | 337 | } |
| 398 | 338 | |
| 399 | - $this->atts = $atts; | |
| 400 | - $this->atts['entry'] = $this->entry; | |
| 339 | + $this->atts = $atts; | |
| 401 | 340 | } |
| 402 | 341 | |
| 403 | 342 | /** |
| 404 | 343 | * Get the field key or ID, depending on array_key property |
| @@ -406,12 +345,12 @@ | ||
| 406 | 345 | * @since 2.05 |
| 407 | 346 | * |
| 408 | 347 | * @param FrmFieldValue $field_value |
| 409 | 348 | * |
| 410 | - * @return int|string | |
| 349 | + * @return string|int | |
| 411 | 350 | */ |
| 412 | 351 | protected function get_key_or_id( $field_value ) { |
| 413 | - 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(); | |
| 414 | 353 | } |
| 415 | 354 | |
| 416 | 355 | /** |
| 417 | 356 | * Package and return the formatted entry values |
| @@ -427,15 +366,15 @@ | ||
| 427 | 366 | |
| 428 | 367 | if ( $this->format === 'json' ) { |
| 429 | 368 | $content = json_encode( $this->prepare_array() ); |
| 430 | 369 | |
| 431 | - } elseif ( $this->format === 'array' ) { | |
| 370 | + } else if ( $this->format === 'array' ) { | |
| 432 | 371 | $content = $this->prepare_array(); |
| 433 | 372 | |
| 434 | - } elseif ( $this->format === 'table' ) { | |
| 373 | + } else if ( $this->format === 'table' ) { | |
| 435 | 374 | $content = $this->prepare_html_table(); |
| 436 | 375 | |
| 437 | - } elseif ( $this->format === 'plain_text_block' ) { | |
| 376 | + } else if ( $this->format === 'plain_text_block' ) { | |
| 438 | 377 | $content = $this->prepare_plain_text_block(); |
| 439 | 378 | |
| 440 | 379 | } else { |
| 441 | 380 | $content = ''; |
| @@ -440,26 +379,9 @@ | ||
| 440 | 379 | } else { |
| 441 | 380 | $content = ''; |
| 442 | 381 | } |
| 443 | 382 | |
| 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 | - ); | |
| 383 | + return $content; | |
| 462 | 384 | } |
| 463 | 385 | |
| 464 | 386 | /** |
| 465 | 387 | * Return the formatted HTML table with entry values |
| @@ -488,13 +410,12 @@ | ||
| 488 | 410 | * |
| 489 | 411 | * @since 2.05 |
| 490 | 412 | * |
| 491 | 413 | * @param string $content |
| 492 | - * | |
| 493 | - * @return void | |
| 494 | 414 | */ |
| 495 | 415 | protected function add_field_values_to_content( &$content ) { |
| 496 | - foreach ( $this->entry_values->get_field_values() as $field_value ) { | |
| 416 | + foreach ( $this->entry_values->get_field_values() as $field_id => $field_value ) { | |
| 417 | + | |
| 497 | 418 | /** |
| 498 | 419 | * @var FrmFieldValue $field_value |
| 499 | 420 | */ |
| 500 | 421 | $field_value->prepare_displayed_value( $this->atts ); |
| @@ -539,10 +460,8 @@ | ||
| 539 | 460 | * @since 2.04 |
| 540 | 461 | * |
| 541 | 462 | * @param array $field_values |
| 542 | 463 | * @param array $output |
| 543 | - * | |
| 544 | - * @return void | |
| 545 | 464 | */ |
| 546 | 465 | protected function push_field_values_to_array( $field_values, &$output ) { |
| 547 | 466 | foreach ( $field_values as $field_value ) { |
| 548 | 467 | /** |
| @@ -558,21 +477,17 @@ | ||
| 558 | 477 | * |
| 559 | 478 | * @since 2.04 |
| 560 | 479 | * |
| 561 | 480 | * @param FrmFieldValue $field_value |
| 562 | - * @param array $output | |
| 563 | - * | |
| 564 | - * @return void | |
| 481 | + * @param array $output | |
| 565 | 482 | */ |
| 566 | 483 | protected function push_single_field_to_array( $field_value, &$output ) { |
| 567 | 484 | if ( $this->include_field_in_content( $field_value ) ) { |
| 568 | 485 | |
| 569 | 486 | $displayed_value = $this->prepare_display_value_for_array( $field_value->get_displayed_value() ); |
| 570 | - | |
| 571 | 487 | $output[ $this->get_key_or_id( $field_value ) ] = $displayed_value; |
| 572 | 488 | |
| 573 | 489 | $has_separate_value = (bool) $field_value->get_field_option( 'separate_value' ); |
| 574 | - | |
| 575 | 490 | if ( $has_separate_value || $displayed_value !== $field_value->get_saved_value() ) { |
| 576 | 491 | $output[ $this->get_key_or_id( $field_value ) . '-value' ] = $field_value->get_saved_value(); |
| 577 | 492 | } |
| 578 | 493 | } |
| @@ -583,20 +498,18 @@ | ||
| 583 | 498 | * |
| 584 | 499 | * @since 2.04 |
| 585 | 500 | * |
| 586 | 501 | * @param string $label |
| 587 | - * @param mixed $display_value | |
| 502 | + * @param mixed $display_value | |
| 588 | 503 | * @param string $content |
| 589 | - * | |
| 590 | - * @return void | |
| 591 | 504 | */ |
| 592 | 505 | protected function add_plain_text_row( $label, $display_value, &$content ) { |
| 593 | 506 | $display_value = $this->prepare_display_value_for_plain_text_content( $display_value ); |
| 594 | 507 | |
| 595 | - if ( 'rtl' === $this->direction ) { | |
| 596 | - $content .= wp_kses_post( $display_value . ' :' . $label ) . "\r\n"; | |
| 508 | + if ( 'rtl' == $this->direction ) { | |
| 509 | + $content .= $display_value . ' :' . $label . "\r\n"; | |
| 597 | 510 | } else { |
| 598 | - $content .= wp_kses_post( $label . ': ' . $display_value ) . "\r\n"; | |
| 511 | + $content .= $label . ': ' . $display_value . "\r\n"; | |
| 599 | 512 | } |
| 600 | 513 | } |
| 601 | 514 | |
| 602 | 515 | /** |
| @@ -604,11 +517,9 @@ | ||
| 604 | 517 | * |
| 605 | 518 | * @since 2.04 |
| 606 | 519 | * |
| 607 | 520 | * @param FrmFieldValue $field_value |
| 608 | - * @param string $content | |
| 609 | - * | |
| 610 | - * @return void | |
| 521 | + * @param string $content | |
| 611 | 522 | */ |
| 612 | 523 | protected function add_field_value_to_content( $field_value, &$content ) { |
| 613 | 524 | if ( $this->is_extra_field( $field_value ) ) { |
| 614 | 525 | $this->add_row_for_extra_field( $field_value, $content ); |
| @@ -623,11 +534,9 @@ | ||
| 623 | 534 | * |
| 624 | 535 | * @since 3.0 |
| 625 | 536 | * |
| 626 | 537 | * @param FrmFieldValue $field_value |
| 627 | - * @param string $content | |
| 628 | - * | |
| 629 | - * @return void | |
| 538 | + * @param string $content | |
| 630 | 539 | */ |
| 631 | 540 | protected function add_row_for_extra_field( $field_value, &$content ) { |
| 632 | 541 | if ( ! $this->include_field_in_content( $field_value ) ) { |
| 633 | 542 | return; |
| @@ -634,9 +543,9 @@ | ||
| 634 | 543 | } |
| 635 | 544 | |
| 636 | 545 | if ( $this->format === 'plain_text_block' ) { |
| 637 | 546 | $this->add_plain_text_row_for_included_extra( $field_value, $content ); |
| 638 | - } elseif ( $this->format === 'table' ) { | |
| 547 | + } else if ( $this->format === 'table' ) { | |
| 639 | 548 | $this->add_html_row_for_included_extra( $field_value, $content ); |
| 640 | 549 | } |
| 641 | 550 | } |
| 642 | 551 | |
| @@ -645,11 +554,9 @@ | ||
| 645 | 554 | * |
| 646 | 555 | * @since 3.0 |
| 647 | 556 | * |
| 648 | 557 | * @param FrmFieldValue $field_value |
| 649 | - * @param string $content | |
| 650 | - * | |
| 651 | - * @return void | |
| 558 | + * @param string $content | |
| 652 | 559 | */ |
| 653 | 560 | protected function add_row_for_standard_field( $field_value, &$content ) { |
| 654 | 561 | if ( ! $this->include_field_in_content( $field_value ) ) { |
| 655 | 562 | return; |
| @@ -656,9 +563,9 @@ | ||
| 656 | 563 | } |
| 657 | 564 | |
| 658 | 565 | if ( $this->format === 'plain_text_block' ) { |
| 659 | 566 | $this->add_plain_text_row( $field_value->get_field_label(), $field_value->get_displayed_value(), $content ); |
| 660 | - } elseif ( $this->format === 'table' ) { | |
| 567 | + } else if ( $this->format === 'table' ) { | |
| 661 | 568 | $value_args = $this->package_value_args( $field_value ); |
| 662 | 569 | $this->add_html_row( $value_args, $content ); |
| 663 | 570 | } |
| 664 | 571 | } |
| @@ -668,11 +575,9 @@ | ||
| 668 | 575 | * |
| 669 | 576 | * @since 3.0 |
| 670 | 577 | * |
| 671 | 578 | * @param FrmFieldValue $field_value |
| 672 | - * @param string $content | |
| 673 | - * | |
| 674 | - * @return void | |
| 579 | + * @param string $content | |
| 675 | 580 | */ |
| 676 | 581 | protected function add_html_row_for_included_extra( $field_value, &$content ) { |
| 677 | 582 | $this->prepare_html_display_value_for_extra_fields( $field_value, $display_value ); |
| 678 | 583 | |
| @@ -689,11 +594,9 @@ | ||
| 689 | 594 | * |
| 690 | 595 | * @since 3.0 |
| 691 | 596 | * |
| 692 | 597 | * @param FrmFieldValue $field_value |
| 693 | - * @param string $content | |
| 694 | - * | |
| 695 | - * @return void | |
| 598 | + * @param string $content | |
| 696 | 599 | */ |
| 697 | 600 | protected function add_plain_text_row_for_included_extra( $field_value, &$content ) { |
| 698 | 601 | $this->prepare_plain_text_display_value_for_extra_fields( $field_value, $display_value ); |
| 699 | 602 | |
| @@ -710,10 +613,8 @@ | ||
| 710 | 613 | * @since 3.0 |
| 711 | 614 | * |
| 712 | 615 | * @param string $display_value |
| 713 | 616 | * @param string $content |
| 714 | - * | |
| 715 | - * @return void | |
| 716 | 617 | */ |
| 717 | 618 | protected function add_single_cell_html_row( $display_value, &$content ) { |
| 718 | 619 | // TODO: maybe move to FrmFieldValue |
| 719 | 620 | $display_value = $this->prepare_display_value_for_html_table( $display_value ); |
| @@ -727,10 +628,8 @@ | ||
| 727 | 628 | * @since 3.0 |
| 728 | 629 | * |
| 729 | 630 | * @param string $display_value |
| 730 | 631 | * @param string $content |
| 731 | - * | |
| 732 | - * @return void | |
| 733 | 632 | */ |
| 734 | 633 | protected function add_single_value_plain_text_row( $display_value, &$content ) { |
| 735 | 634 | $content .= $this->prepare_display_value_for_plain_text_content( $display_value ); |
| 736 | 635 | } |
| @@ -740,11 +639,9 @@ | ||
| 740 | 639 | * |
| 741 | 640 | * @since 3.0 |
| 742 | 641 | * |
| 743 | 642 | * @param FrmFieldValue $field_value |
| 744 | - * @param mixed $display_value | |
| 745 | - * | |
| 746 | - * @return void | |
| 643 | + * @param mixed $display_value | |
| 747 | 644 | */ |
| 748 | 645 | protected function prepare_html_display_value_for_extra_fields( $field_value, &$display_value ) { |
| 749 | 646 | $display_value = $field_value->get_displayed_value(); |
| 750 | 647 | } |
| @@ -754,11 +651,9 @@ | ||
| 754 | 651 | * |
| 755 | 652 | * @since 3.0 |
| 756 | 653 | * |
| 757 | 654 | * @param FrmFieldValue $field_value |
| 758 | - * @param mixed $display_value | |
| 759 | - * | |
| 760 | - * @return void | |
| 655 | + * @param mixed $display_value | |
| 761 | 656 | */ |
| 762 | 657 | protected function prepare_plain_text_display_value_for_extra_fields( $field_value, &$display_value ) { |
| 763 | 658 | $display_value = $field_value->get_displayed_value() . "\r\n"; |
| 764 | 659 | } |
| @@ -767,17 +662,15 @@ | ||
| 767 | 662 | * Add a standard row to plain text or html table content |
| 768 | 663 | * |
| 769 | 664 | * @since 2.04 |
| 770 | 665 | * |
| 771 | - * @param FrmFieldValue $field_value | |
| 772 | - * @param string $content | |
| 773 | - * | |
| 774 | - * @return void | |
| 666 | + * @param FrmProFieldValue $field_value | |
| 667 | + * @param string $content | |
| 775 | 668 | */ |
| 776 | 669 | protected function add_standard_row( $field_value, &$content ) { |
| 777 | 670 | if ( $this->format === 'plain_text_block' ) { |
| 778 | 671 | $this->add_plain_text_row( $field_value->get_field_label(), $field_value->get_displayed_value(), $content ); |
| 779 | - } elseif ( $this->format === 'table' ) { | |
| 672 | + } else if ( $this->format === 'table' ) { | |
| 780 | 673 | $value_args = $this->package_value_args( $field_value ); |
| 781 | 674 | $this->add_html_row( $value_args, $content ); |
| 782 | 675 | } |
| 783 | 676 | } |
| @@ -792,11 +685,11 @@ | ||
| 792 | 685 | * @return array |
| 793 | 686 | */ |
| 794 | 687 | protected function package_value_args( $field_value ) { |
| 795 | 688 | return array( |
| 796 | - 'label' => $field_value->get_field_label(), | |
| 797 | - 'value' => $field_value->get_displayed_value(), | |
| 798 | - '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(), | |
| 799 | 692 | ); |
| 800 | 693 | } |
| 801 | 694 | |
| 802 | 695 | /** |
| @@ -804,18 +697,18 @@ | ||
| 804 | 697 | * |
| 805 | 698 | * @since 2.04 |
| 806 | 699 | * |
| 807 | 700 | * @param string $content |
| 808 | - * | |
| 809 | - * @return void | |
| 810 | 701 | */ |
| 811 | 702 | protected function add_user_info_to_html_table( &$content ) { |
| 812 | 703 | if ( $this->include_user_info ) { |
| 704 | + | |
| 813 | 705 | foreach ( $this->entry_values->get_user_info() as $user_info ) { |
| 706 | + | |
| 814 | 707 | $value_args = array( |
| 815 | - 'label' => $user_info['label'], | |
| 816 | - 'value' => $user_info['value'], | |
| 817 | - 'field_type' => 'none', | |
| 708 | + 'label' => $user_info['label'], | |
| 709 | + 'value' => $user_info['value'], | |
| 710 | + 'field_type' => 'none', | |
| 818 | 711 | ); |
| 819 | 712 | |
| 820 | 713 | $this->add_html_row( $value_args, $content ); |
| 821 | 714 | } |
| @@ -827,10 +720,8 @@ | ||
| 827 | 720 | * |
| 828 | 721 | * @since 2.04 |
| 829 | 722 | * |
| 830 | 723 | * @param string $content |
| 831 | - * | |
| 832 | - * @return void | |
| 833 | 724 | */ |
| 834 | 725 | protected function add_user_info_to_plain_text_content( &$content ) { |
| 835 | 726 | if ( $this->include_user_info ) { |
| 836 | 727 | |
| @@ -891,9 +782,9 @@ | ||
| 891 | 782 | * Add a row in an HTML table |
| 892 | 783 | * |
| 893 | 784 | * @since 2.04 |
| 894 | 785 | * |
| 895 | - * @param array $value_args | |
| 786 | + * @param array $value_args | |
| 896 | 787 | * $value_args = [ |
| 897 | 788 | * 'label' => (string) The label. Required |
| 898 | 789 | * 'value' => (mixed) The value to add. Required |
| 899 | 790 | * 'field_type' => (string) The field type. Blank string if not a field. |
| @@ -898,19 +789,13 @@ | ||
| 898 | 789 | * 'value' => (mixed) The value to add. Required |
| 899 | 790 | * 'field_type' => (string) The field type. Blank string if not a field. |
| 900 | 791 | * ] |
| 901 | 792 | * @param string $content |
| 902 | - * | |
| 903 | - * @return void | |
| 904 | 793 | */ |
| 905 | 794 | protected function add_html_row( $value_args, &$content ) { |
| 906 | 795 | $display_value = $this->prepare_display_value_for_html_table( $value_args['value'], $value_args['field_type'] ); |
| 907 | 796 | |
| 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 | - ); | |
| 797 | + $content .= $this->table_generator->generate_two_cell_table_row( $value_args['label'], $display_value ); | |
| 913 | 798 | } |
| 914 | 799 | |
| 915 | 800 | /** |
| 916 | 801 | * Prepare the displayed value for an array |
| @@ -924,14 +809,15 @@ | ||
| 924 | 809 | protected function prepare_display_value_for_array( $value ) { |
| 925 | 810 | return $this->strip_html( $value ); |
| 926 | 811 | } |
| 927 | 812 | |
| 813 | + | |
| 928 | 814 | /** |
| 929 | 815 | * Prepare a field's display value for an HTML table |
| 930 | 816 | * |
| 931 | 817 | * @since 2.04 |
| 932 | 818 | * |
| 933 | - * @param mixed $display_value | |
| 819 | + * @param mixed $display_value | |
| 934 | 820 | * @param string $field_type |
| 935 | 821 | * |
| 936 | 822 | * @return mixed|string |
| 937 | 823 | */ |
| @@ -936,13 +822,10 @@ | ||
| 936 | 822 | * @return mixed|string |
| 937 | 823 | */ |
| 938 | 824 | protected function prepare_display_value_for_html_table( $display_value, $field_type = '' ) { |
| 939 | 825 | $display_value = $this->flatten_array( $display_value ); |
| 826 | + $display_value = str_replace( array( "\r\n", "\n" ), '<br/>', $display_value ); | |
| 940 | 827 | |
| 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 | 828 | return $display_value; |
| 946 | 829 | } |
| 947 | 830 | |
| 948 | 831 | /** |
| @@ -951,9 +834,9 @@ | ||
| 951 | 834 | * @since 2.04 |
| 952 | 835 | * |
| 953 | 836 | * @param mixed $display_value |
| 954 | 837 | * |
| 955 | - * @return int|string | |
| 838 | + * @return string|int | |
| 956 | 839 | */ |
| 957 | 840 | protected function prepare_display_value_for_plain_text_content( $display_value ) { |
| 958 | 841 | $display_value = $this->flatten_array( $display_value ); |
| 959 | 842 | $display_value = $this->strip_html( $display_value ); |
| @@ -965,16 +848,15 @@ | ||
| 965 | 848 | * Flatten an array |
| 966 | 849 | * |
| 967 | 850 | * @since 2.04 |
| 968 | 851 | * |
| 969 | - * @param array|int|string $value | |
| 852 | + * @param array|string|int $value | |
| 970 | 853 | * |
| 971 | - * @return int|string | |
| 854 | + * @return string|int | |
| 972 | 855 | */ |
| 973 | 856 | protected function flatten_array( $value ) { |
| 974 | 857 | if ( is_array( $value ) ) { |
| 975 | - $separator = $this->atts['array_separator'] ?? ', '; | |
| 976 | - $value = implode( $separator, $value ); | |
| 858 | + $value = implode( ', ', $value ); | |
| 977 | 859 | } |
| 978 | 860 | |
| 979 | 861 | return $value; |
| 980 | 862 | } |
| @@ -988,19 +870,20 @@ | ||
| 988 | 870 | * |
| 989 | 871 | * @return mixed |
| 990 | 872 | */ |
| 991 | 873 | protected function strip_html( $value ) { |
| 874 | + | |
| 992 | 875 | if ( $this->is_plain_text ) { |
| 876 | + | |
| 993 | 877 | if ( is_array( $value ) ) { |
| 994 | 878 | foreach ( $value as $key => $single_value ) { |
| 995 | 879 | $value[ $key ] = $this->strip_html( $single_value ); |
| 996 | 880 | } |
| 997 | - } elseif ( $this->is_plain_text && ! is_array( $value ) ) { | |
| 881 | + } else if ( $this->is_plain_text && ! is_array( $value ) ) { | |
| 998 | 882 | if ( strpos( $value, '<img' ) !== false ) { |
| 999 | 883 | $value = str_replace( array( '<img', 'src=', '/>', '"' ), '', $value ); |
| 1000 | 884 | $value = trim( $value ); |
| 1001 | 885 | } |
| 1002 | - | |
| 1003 | 886 | $value = strip_tags( $value ); |
| 1004 | 887 | } |
| 1005 | 888 | } |
| 1006 | 889 | |