| @@ -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,36 +177,26 @@ | ||
| 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 | - | |
| 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 | 199 | } |
| 222 | 200 | |
| 223 | 201 | /** |
| 224 | 202 | * Set the array_key property that sets whether the keys in the |
| @@ -226,13 +204,11 @@ | ||
| 226 | 204 | * |
| 227 | 205 | * @since 2.05 |
| 228 | 206 | * |
| 229 | 207 | * @param array $atts |
| 230 | - * | |
| 231 | - * @return void | |
| 232 | 208 | */ |
| 233 | 209 | protected function init_array_key( $atts ) { |
| 234 | - if ( isset( $atts['array_key'] ) && $atts['array_key'] === 'id' ) { | |
| 210 | + if ( isset( $atts['array_key'] ) && $atts['array_key'] == 'id' ) { | |
| 235 | 211 | $this->array_key = 'id'; |
| 236 | 212 | } |
| 237 | 213 | } |
| 238 | 214 | |
| @@ -241,13 +217,11 @@ | ||
| 241 | 217 | * |
| 242 | 218 | * @since 2.04 |
| 243 | 219 | * |
| 244 | 220 | * @param array $atts |
| 245 | - * | |
| 246 | - * @return void | |
| 247 | 221 | */ |
| 248 | 222 | protected function init_is_plain_text( $atts ) { |
| 249 | - if ( ! empty( $atts['plain_text'] ) ) { | |
| 223 | + if ( isset( $atts['plain_text'] ) && $atts['plain_text'] ) { | |
| 250 | 224 | $this->is_plain_text = true; |
| 251 | 225 | } elseif ( $atts['format'] !== 'text' ) { |
| 252 | 226 | $this->is_plain_text = true; |
| 253 | 227 | } |
| @@ -258,13 +232,11 @@ | ||
| 258 | 232 | * |
| 259 | 233 | * @since 2.04 |
| 260 | 234 | * |
| 261 | 235 | * @param array $atts |
| 262 | - * | |
| 263 | - * @return void | |
| 264 | 236 | */ |
| 265 | 237 | protected function init_include_blank( $atts ) { |
| 266 | - if ( ! empty( $atts['include_blank'] ) ) { | |
| 238 | + if ( isset( $atts['include_blank'] ) && $atts['include_blank'] ) { | |
| 267 | 239 | $this->include_blank = true; |
| 268 | 240 | } |
| 269 | 241 | } |
| 270 | 242 | |
| @@ -273,10 +245,8 @@ | ||
| 273 | 245 | * |
| 274 | 246 | * @since 2.04 |
| 275 | 247 | * |
| 276 | 248 | * @param array $atts |
| 277 | - * | |
| 278 | - * @return void | |
| 279 | 249 | */ |
| 280 | 250 | protected function init_direction( $atts ) { |
| 281 | 251 | if ( isset( $atts['direction'] ) && $atts['direction'] === 'rtl' ) { |
| 282 | 252 | $this->direction = 'rtl'; |
| @@ -288,13 +258,11 @@ | ||
| 288 | 258 | * |
| 289 | 259 | * @since 2.04 |
| 290 | 260 | * |
| 291 | 261 | * @param array $atts |
| 292 | - * | |
| 293 | - * @return void | |
| 294 | 262 | */ |
| 295 | 263 | protected function init_include_user_info( $atts ) { |
| 296 | - if ( ! empty( $atts['user_info'] ) ) { | |
| 264 | + if ( isset( $atts['user_info'] ) && $atts['user_info'] ) { | |
| 297 | 265 | $this->include_user_info = true; |
| 298 | 266 | } |
| 299 | 267 | } |
| 300 | 268 | |
| @@ -301,13 +269,11 @@ | ||
| 301 | 269 | /** |
| 302 | 270 | * Which fields to skip by default |
| 303 | 271 | * |
| 304 | 272 | * @since 3.0 |
| 305 | - * | |
| 306 | - * @return array | |
| 307 | 273 | */ |
| 308 | 274 | protected function skip_fields() { |
| 309 | - return array( 'captcha', 'html', FrmSubmitHelper::FIELD_TYPE ); | |
| 275 | + return array( 'captcha', 'html' ); | |
| 310 | 276 | } |
| 311 | 277 | |
| 312 | 278 | /** |
| 313 | 279 | * Set the include_extras property |
| @@ -314,13 +280,11 @@ | ||
| 314 | 280 | * |
| 315 | 281 | * @since 3.0 |
| 316 | 282 | * |
| 317 | 283 | * @param array $atts |
| 318 | - * | |
| 319 | - * @return void | |
| 320 | 284 | */ |
| 321 | 285 | protected function init_include_extras( $atts ) { |
| 322 | - if ( ! empty( $atts['include_extras'] ) ) { | |
| 286 | + if ( isset( $atts['include_extras'] ) && $atts['include_extras'] ) { | |
| 323 | 287 | $this->include_extras = array_map( 'strtolower', array_map( 'trim', explode( ',', $atts['include_extras'] ) ) ); |
| 324 | 288 | } |
| 325 | 289 | } |
| 326 | 290 | |
| @@ -327,10 +291,8 @@ | ||
| 327 | 291 | /** |
| 328 | 292 | * Initialize the single_cell_fields property |
| 329 | 293 | * |
| 330 | 294 | * @since 3.0 |
| 331 | - * | |
| 332 | - * @return void | |
| 333 | 295 | */ |
| 334 | 296 | protected function init_single_cell_fields() { |
| 335 | 297 | $this->single_cell_fields = array( 'html' ); |
| 336 | 298 | } |
| @@ -340,10 +302,8 @@ | ||
| 340 | 302 | * |
| 341 | 303 | * @since 2.04 |
| 342 | 304 | * |
| 343 | 305 | * @param array $atts |
| 344 | - * | |
| 345 | - * @return void | |
| 346 | 306 | */ |
| 347 | 307 | protected function init_table_generator( $atts ) { |
| 348 | 308 | $this->table_generator = new FrmTableHTMLGenerator( 'entry', $atts ); |
| 349 | 309 | } |
| @@ -353,13 +313,11 @@ | ||
| 353 | 313 | * |
| 354 | 314 | * @since 2.04 |
| 355 | 315 | * |
| 356 | 316 | * @param array $atts |
| 357 | - * | |
| 358 | - * @return void | |
| 359 | 317 | */ |
| 360 | 318 | protected function init_is_clickable( $atts ) { |
| 361 | - if ( ! empty( $atts['clickable'] ) ) { | |
| 319 | + if ( isset( $atts['clickable'] ) && $atts['clickable'] ) { | |
| 362 | 320 | $this->is_clickable = true; |
| 363 | 321 | } |
| 364 | 322 | } |
| 365 | 323 | |
| @@ -367,12 +325,8 @@ | ||
| 367 | 325 | * Save the passed atts for other calls. Exclude some attributes to prevent |
| 368 | 326 | * interaction with processing field values like time format. |
| 369 | 327 | * |
| 370 | 328 | * @since 3.0 |
| 371 | - * | |
| 372 | - * @param array $atts | |
| 373 | - * | |
| 374 | - * @return void | |
| 375 | 329 | */ |
| 376 | 330 | protected function init_atts( $atts ) { |
| 377 | 331 | $atts['source'] = 'entry_formatter'; |
| 378 | 332 | $atts['wpautop'] = false; |
| @@ -377,10 +331,9 @@ | ||
| 377 | 331 | $atts['source'] = 'entry_formatter'; |
| 378 | 332 | $atts['wpautop'] = false; |
| 379 | 333 | $atts['return_array'] = true; |
| 380 | 334 | |
| 381 | - $unset = array( 'id', 'form_id', 'format' ); | |
| 382 | - | |
| 335 | + $unset = array( 'id', 'entry', 'form_id', 'format' ); | |
| 383 | 336 | foreach ( $unset as $param ) { |
| 384 | 337 | if ( isset( $atts[ $param ] ) ) { |
| 385 | 338 | unset( $atts[ $param ] ); |
| 386 | 339 | } |
| @@ -385,10 +338,9 @@ | ||
| 385 | 338 | unset( $atts[ $param ] ); |
| 386 | 339 | } |
| 387 | 340 | } |
| 388 | 341 | |
| 389 | - $this->atts = $atts; | |
| 390 | - $this->atts['entry'] = $this->entry; | |
| 342 | + $this->atts = $atts; | |
| 391 | 343 | } |
| 392 | 344 | |
| 393 | 345 | /** |
| 394 | 346 | * Get the field key or ID, depending on array_key property |
| @@ -396,12 +348,12 @@ | ||
| 396 | 348 | * @since 2.05 |
| 397 | 349 | * |
| 398 | 350 | * @param FrmFieldValue $field_value |
| 399 | 351 | * |
| 400 | - * @return int|string | |
| 352 | + * @return string|int | |
| 401 | 353 | */ |
| 402 | 354 | protected function get_key_or_id( $field_value ) { |
| 403 | - return $this->array_key === 'key' ? $field_value->get_field_key() : $field_value->get_field_id(); | |
| 355 | + return $this->array_key == 'key' ? $field_value->get_field_key() : $field_value->get_field_id(); | |
| 404 | 356 | } |
| 405 | 357 | |
| 406 | 358 | /** |
| 407 | 359 | * Package and return the formatted entry values |
| @@ -416,36 +368,23 @@ | ||
| 416 | 368 | } |
| 417 | 369 | |
| 418 | 370 | if ( $this->format === 'json' ) { |
| 419 | 371 | $content = json_encode( $this->prepare_array() ); |
| 372 | + | |
| 420 | 373 | } elseif ( $this->format === 'array' ) { |
| 421 | 374 | $content = $this->prepare_array(); |
| 375 | + | |
| 422 | 376 | } elseif ( $this->format === 'table' ) { |
| 423 | 377 | $content = $this->prepare_html_table(); |
| 378 | + | |
| 424 | 379 | } elseif ( $this->format === 'plain_text_block' ) { |
| 425 | 380 | $content = $this->prepare_plain_text_block(); |
| 381 | + | |
| 426 | 382 | } else { |
| 427 | 383 | $content = ''; |
| 428 | 384 | } |
| 429 | 385 | |
| 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 | - ); | |
| 386 | + return $content; | |
| 448 | 387 | } |
| 449 | 388 | |
| 450 | 389 | /** |
| 451 | 390 | * Return the formatted HTML table with entry values |
| @@ -461,9 +400,13 @@ | ||
| 461 | 400 | $this->add_user_info_to_html_table( $content ); |
| 462 | 401 | |
| 463 | 402 | $content .= $this->table_generator->generate_table_footer(); |
| 464 | 403 | |
| 465 | - return $this->is_clickable ? make_clickable( $content ) : $content; | |
| 404 | + if ( $this->is_clickable ) { | |
| 405 | + $content = make_clickable( $content ); | |
| 406 | + } | |
| 407 | + | |
| 408 | + return $content; | |
| 466 | 409 | } |
| 467 | 410 | |
| 468 | 411 | /** |
| 469 | 412 | * Add field values to table or plain text content |
| @@ -470,13 +413,12 @@ | ||
| 470 | 413 | * |
| 471 | 414 | * @since 2.05 |
| 472 | 415 | * |
| 473 | 416 | * @param string $content |
| 474 | - * | |
| 475 | - * @return void | |
| 476 | 417 | */ |
| 477 | 418 | protected function add_field_values_to_content( &$content ) { |
| 478 | - foreach ( $this->entry_values->get_field_values() as $field_value ) { | |
| 419 | + foreach ( $this->entry_values->get_field_values() as $field_id => $field_value ) { | |
| 420 | + | |
| 479 | 421 | /** |
| 480 | 422 | * @var FrmFieldValue $field_value |
| 481 | 423 | */ |
| 482 | 424 | $field_value->prepare_displayed_value( $this->atts ); |
| @@ -521,10 +463,8 @@ | ||
| 521 | 463 | * @since 2.04 |
| 522 | 464 | * |
| 523 | 465 | * @param array $field_values |
| 524 | 466 | * @param array $output |
| 525 | - * | |
| 526 | - * @return void | |
| 527 | 467 | */ |
| 528 | 468 | protected function push_field_values_to_array( $field_values, &$output ) { |
| 529 | 469 | foreach ( $field_values as $field_value ) { |
| 530 | 470 | /** |
| @@ -540,23 +480,21 @@ | ||
| 540 | 480 | * |
| 541 | 481 | * @since 2.04 |
| 542 | 482 | * |
| 543 | 483 | * @param FrmFieldValue $field_value |
| 544 | - * @param array $output | |
| 545 | - * | |
| 546 | - * @return void | |
| 484 | + * @param array $output | |
| 547 | 485 | */ |
| 548 | 486 | protected function push_single_field_to_array( $field_value, &$output ) { |
| 549 | - if ( ! $this->include_field_in_content( $field_value ) ) { | |
| 550 | - return; | |
| 551 | - } | |
| 487 | + if ( $this->include_field_in_content( $field_value ) ) { | |
| 552 | 488 | |
| 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' ); | |
| 489 | + $displayed_value = $this->prepare_display_value_for_array( $field_value->get_displayed_value() ); | |
| 556 | 490 | |
| 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(); | |
| 491 | + $output[ $this->get_key_or_id( $field_value ) ] = $displayed_value; | |
| 492 | + | |
| 493 | + $has_separate_value = (bool) $field_value->get_field_option( 'separate_value' ); | |
| 494 | + if ( $has_separate_value || $displayed_value !== $field_value->get_saved_value() ) { | |
| 495 | + $output[ $this->get_key_or_id( $field_value ) . '-value' ] = $field_value->get_saved_value(); | |
| 496 | + } | |
| 559 | 497 | } |
| 560 | 498 | } |
| 561 | 499 | |
| 562 | 500 | /** |
| @@ -564,17 +502,15 @@ | ||
| 564 | 502 | * |
| 565 | 503 | * @since 2.04 |
| 566 | 504 | * |
| 567 | 505 | * @param string $label |
| 568 | - * @param mixed $display_value | |
| 506 | + * @param mixed $display_value | |
| 569 | 507 | * @param string $content |
| 570 | - * | |
| 571 | - * @return void | |
| 572 | 508 | */ |
| 573 | 509 | protected function add_plain_text_row( $label, $display_value, &$content ) { |
| 574 | 510 | $display_value = $this->prepare_display_value_for_plain_text_content( $display_value ); |
| 575 | 511 | |
| 576 | - if ( 'rtl' === $this->direction ) { | |
| 512 | + if ( 'rtl' == $this->direction ) { | |
| 577 | 513 | $content .= wp_kses_post( $display_value . ' :' . $label ) . "\r\n"; |
| 578 | 514 | } else { |
| 579 | 515 | $content .= wp_kses_post( $label . ': ' . $display_value ) . "\r\n"; |
| 580 | 516 | } |
| @@ -585,15 +521,14 @@ | ||
| 585 | 521 | * |
| 586 | 522 | * @since 2.04 |
| 587 | 523 | * |
| 588 | 524 | * @param FrmFieldValue $field_value |
| 589 | - * @param string $content | |
| 590 | - * | |
| 591 | - * @return void | |
| 525 | + * @param string $content | |
| 592 | 526 | */ |
| 593 | 527 | protected function add_field_value_to_content( $field_value, &$content ) { |
| 594 | 528 | if ( $this->is_extra_field( $field_value ) ) { |
| 595 | 529 | $this->add_row_for_extra_field( $field_value, $content ); |
| 530 | + | |
| 596 | 531 | } else { |
| 597 | 532 | $this->add_row_for_standard_field( $field_value, $content ); |
| 598 | 533 | } |
| 599 | 534 | } |
| @@ -603,11 +538,9 @@ | ||
| 603 | 538 | * |
| 604 | 539 | * @since 3.0 |
| 605 | 540 | * |
| 606 | 541 | * @param FrmFieldValue $field_value |
| 607 | - * @param string $content | |
| 608 | - * | |
| 609 | - * @return void | |
| 542 | + * @param string $content | |
| 610 | 543 | */ |
| 611 | 544 | protected function add_row_for_extra_field( $field_value, &$content ) { |
| 612 | 545 | if ( ! $this->include_field_in_content( $field_value ) ) { |
| 613 | 546 | return; |
| @@ -625,11 +558,9 @@ | ||
| 625 | 558 | * |
| 626 | 559 | * @since 3.0 |
| 627 | 560 | * |
| 628 | 561 | * @param FrmFieldValue $field_value |
| 629 | - * @param string $content | |
| 630 | - * | |
| 631 | - * @return void | |
| 562 | + * @param string $content | |
| 632 | 563 | */ |
| 633 | 564 | protected function add_row_for_standard_field( $field_value, &$content ) { |
| 634 | 565 | if ( ! $this->include_field_in_content( $field_value ) ) { |
| 635 | 566 | return; |
| @@ -648,16 +579,14 @@ | ||
| 648 | 579 | * |
| 649 | 580 | * @since 3.0 |
| 650 | 581 | * |
| 651 | 582 | * @param FrmFieldValue $field_value |
| 652 | - * @param string $content | |
| 653 | - * | |
| 654 | - * @return void | |
| 583 | + * @param string $content | |
| 655 | 584 | */ |
| 656 | 585 | protected function add_html_row_for_included_extra( $field_value, &$content ) { |
| 657 | 586 | $this->prepare_html_display_value_for_extra_fields( $field_value, $display_value ); |
| 658 | 587 | |
| 659 | - if ( in_array( $field_value->get_field_type(), $this->single_cell_fields, true ) ) { | |
| 588 | + if ( in_array( $field_value->get_field_type(), $this->single_cell_fields ) ) { | |
| 660 | 589 | $this->add_single_cell_html_row( $display_value, $content ); |
| 661 | 590 | } else { |
| 662 | 591 | $value_args = $this->package_value_args( $field_value ); |
| 663 | 592 | $this->add_html_row( $value_args, $content ); |
| @@ -669,16 +598,14 @@ | ||
| 669 | 598 | * |
| 670 | 599 | * @since 3.0 |
| 671 | 600 | * |
| 672 | 601 | * @param FrmFieldValue $field_value |
| 673 | - * @param string $content | |
| 674 | - * | |
| 675 | - * @return void | |
| 602 | + * @param string $content | |
| 676 | 603 | */ |
| 677 | 604 | protected function add_plain_text_row_for_included_extra( $field_value, &$content ) { |
| 678 | 605 | $this->prepare_plain_text_display_value_for_extra_fields( $field_value, $display_value ); |
| 679 | 606 | |
| 680 | - if ( in_array( $field_value->get_field_type(), $this->single_cell_fields, true ) ) { | |
| 607 | + if ( in_array( $field_value->get_field_type(), $this->single_cell_fields ) ) { | |
| 681 | 608 | $this->add_single_value_plain_text_row( $display_value, $content ); |
| 682 | 609 | } else { |
| 683 | 610 | $this->add_plain_text_row( $field_value->get_field_label(), $display_value, $content ); |
| 684 | 611 | } |
| @@ -690,10 +617,8 @@ | ||
| 690 | 617 | * @since 3.0 |
| 691 | 618 | * |
| 692 | 619 | * @param string $display_value |
| 693 | 620 | * @param string $content |
| 694 | - * | |
| 695 | - * @return void | |
| 696 | 621 | */ |
| 697 | 622 | protected function add_single_cell_html_row( $display_value, &$content ) { |
| 698 | 623 | // TODO: maybe move to FrmFieldValue |
| 699 | 624 | $display_value = $this->prepare_display_value_for_html_table( $display_value ); |
| @@ -707,10 +632,8 @@ | ||
| 707 | 632 | * @since 3.0 |
| 708 | 633 | * |
| 709 | 634 | * @param string $display_value |
| 710 | 635 | * @param string $content |
| 711 | - * | |
| 712 | - * @return void | |
| 713 | 636 | */ |
| 714 | 637 | protected function add_single_value_plain_text_row( $display_value, &$content ) { |
| 715 | 638 | $content .= $this->prepare_display_value_for_plain_text_content( $display_value ); |
| 716 | 639 | } |
| @@ -720,11 +643,9 @@ | ||
| 720 | 643 | * |
| 721 | 644 | * @since 3.0 |
| 722 | 645 | * |
| 723 | 646 | * @param FrmFieldValue $field_value |
| 724 | - * @param mixed $display_value | |
| 725 | - * | |
| 726 | - * @return void | |
| 647 | + * @param mixed $display_value | |
| 727 | 648 | */ |
| 728 | 649 | protected function prepare_html_display_value_for_extra_fields( $field_value, &$display_value ) { |
| 729 | 650 | $display_value = $field_value->get_displayed_value(); |
| 730 | 651 | } |
| @@ -734,11 +655,9 @@ | ||
| 734 | 655 | * |
| 735 | 656 | * @since 3.0 |
| 736 | 657 | * |
| 737 | 658 | * @param FrmFieldValue $field_value |
| 738 | - * @param mixed $display_value | |
| 739 | - * | |
| 740 | - * @return void | |
| 659 | + * @param mixed $display_value | |
| 741 | 660 | */ |
| 742 | 661 | protected function prepare_plain_text_display_value_for_extra_fields( $field_value, &$display_value ) { |
| 743 | 662 | $display_value = $field_value->get_displayed_value() . "\r\n"; |
| 744 | 663 | } |
| @@ -747,12 +666,10 @@ | ||
| 747 | 666 | * Add a standard row to plain text or html table content |
| 748 | 667 | * |
| 749 | 668 | * @since 2.04 |
| 750 | 669 | * |
| 751 | - * @param FrmFieldValue $field_value | |
| 752 | - * @param string $content | |
| 753 | - * | |
| 754 | - * @return void | |
| 670 | + * @param FrmProFieldValue $field_value | |
| 671 | + * @param string $content | |
| 755 | 672 | */ |
| 756 | 673 | protected function add_standard_row( $field_value, &$content ) { |
| 757 | 674 | if ( $this->format === 'plain_text_block' ) { |
| 758 | 675 | $this->add_plain_text_row( $field_value->get_field_label(), $field_value->get_displayed_value(), $content ); |
| @@ -784,24 +701,22 @@ | ||
| 784 | 701 | * |
| 785 | 702 | * @since 2.04 |
| 786 | 703 | * |
| 787 | 704 | * @param string $content |
| 788 | - * | |
| 789 | - * @return void | |
| 790 | 705 | */ |
| 791 | 706 | protected function add_user_info_to_html_table( &$content ) { |
| 792 | - if ( ! $this->include_user_info ) { | |
| 793 | - return; | |
| 794 | - } | |
| 707 | + if ( $this->include_user_info ) { | |
| 795 | 708 | |
| 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 | - ); | |
| 709 | + foreach ( $this->entry_values->get_user_info() as $user_info ) { | |
| 802 | 710 | |
| 803 | - $this->add_html_row( $value_args, $content ); | |
| 711 | + $value_args = array( | |
| 712 | + 'label' => $user_info['label'], | |
| 713 | + 'value' => $user_info['value'], | |
| 714 | + 'field_type' => 'none', | |
| 715 | + ); | |
| 716 | + | |
| 717 | + $this->add_html_row( $value_args, $content ); | |
| 718 | + } | |
| 804 | 719 | } |
| 805 | 720 | } |
| 806 | 721 | |
| 807 | 722 | /** |
| @@ -809,18 +724,15 @@ | ||
| 809 | 724 | * |
| 810 | 725 | * @since 2.04 |
| 811 | 726 | * |
| 812 | 727 | * @param string $content |
| 813 | - * | |
| 814 | - * @return void | |
| 815 | 728 | */ |
| 816 | 729 | protected function add_user_info_to_plain_text_content( &$content ) { |
| 817 | - if ( ! $this->include_user_info ) { | |
| 818 | - return; | |
| 819 | - } | |
| 730 | + if ( $this->include_user_info ) { | |
| 820 | 731 | |
| 821 | - foreach ( $this->entry_values->get_user_info() as $user_info ) { | |
| 822 | - $this->add_plain_text_row( $user_info['label'], $user_info['value'], $content ); | |
| 732 | + foreach ( $this->entry_values->get_user_info() as $user_info ) { | |
| 733 | + $this->add_plain_text_row( $user_info['label'], $user_info['value'], $content ); | |
| 734 | + } | |
| 823 | 735 | } |
| 824 | 736 | } |
| 825 | 737 | |
| 826 | 738 | /** |
| @@ -853,9 +765,9 @@ | ||
| 853 | 765 | * |
| 854 | 766 | * @return bool |
| 855 | 767 | */ |
| 856 | 768 | protected function is_extra_field( $field_value ) { |
| 857 | - return in_array( $field_value->get_field_type(), $this->skip_fields(), true ); | |
| 769 | + return in_array( $field_value->get_field_type(), $this->skip_fields() ); | |
| 858 | 770 | } |
| 859 | 771 | |
| 860 | 772 | /** |
| 861 | 773 | * Check if an extra field is included |
| @@ -866,9 +778,9 @@ | ||
| 866 | 778 | * |
| 867 | 779 | * @return bool |
| 868 | 780 | */ |
| 869 | 781 | protected function is_extra_field_included( $field_value ) { |
| 870 | - return in_array( $field_value->get_field_type(), $this->include_extras, true ); | |
| 782 | + return in_array( $field_value->get_field_type(), $this->include_extras ); | |
| 871 | 783 | } |
| 872 | 784 | |
| 873 | 785 | /** |
| 874 | 786 | * Add a row in an HTML table |
| @@ -874,9 +786,9 @@ | ||
| 874 | 786 | * Add a row in an HTML table |
| 875 | 787 | * |
| 876 | 788 | * @since 2.04 |
| 877 | 789 | * |
| 878 | - * @param array $value_args | |
| 790 | + * @param array $value_args | |
| 879 | 791 | * $value_args = [ |
| 880 | 792 | * 'label' => (string) The label. Required |
| 881 | 793 | * 'value' => (mixed) The value to add. Required |
| 882 | 794 | * 'field_type' => (string) The field type. Blank string if not a field. |
| @@ -881,19 +793,13 @@ | ||
| 881 | 793 | * 'value' => (mixed) The value to add. Required |
| 882 | 794 | * 'field_type' => (string) The field type. Blank string if not a field. |
| 883 | 795 | * ] |
| 884 | 796 | * @param string $content |
| 885 | - * | |
| 886 | - * @return void | |
| 887 | 797 | */ |
| 888 | 798 | protected function add_html_row( $value_args, &$content ) { |
| 889 | 799 | $display_value = $this->prepare_display_value_for_html_table( $value_args['value'], $value_args['field_type'] ); |
| 890 | 800 | |
| 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 | - ); | |
| 801 | + $content .= $this->table_generator->generate_two_cell_table_row( $value_args['label'], $display_value ); | |
| 896 | 802 | } |
| 897 | 803 | |
| 898 | 804 | /** |
| 899 | 805 | * Prepare the displayed value for an array |
| @@ -912,9 +818,9 @@ | ||
| 912 | 818 | * Prepare a field's display value for an HTML table |
| 913 | 819 | * |
| 914 | 820 | * @since 2.04 |
| 915 | 821 | * |
| 916 | - * @param mixed $display_value | |
| 822 | + * @param mixed $display_value | |
| 917 | 823 | * @param string $field_type |
| 918 | 824 | * |
| 919 | 825 | * @return mixed|string |
| 920 | 826 | */ |
| @@ -919,11 +825,10 @@ | ||
| 919 | 825 | * @return mixed|string |
| 920 | 826 | */ |
| 921 | 827 | protected function prepare_display_value_for_html_table( $display_value, $field_type = '' ) { |
| 922 | 828 | $display_value = $this->flatten_array( $display_value ); |
| 923 | - | |
| 924 | 829 | if ( ! isset( $this->atts['line_breaks'] ) || ! empty( $this->atts['line_breaks'] ) ) { |
| 925 | - return str_replace( array( "\r\n", "\n" ), '<br/>', $display_value ); | |
| 830 | + $display_value = str_replace( array( "\r\n", "\n" ), '<br/>', $display_value ); | |
| 926 | 831 | } |
| 927 | 832 | |
| 928 | 833 | return $display_value; |
| 929 | 834 | } |
| @@ -934,13 +839,15 @@ | ||
| 934 | 839 | * @since 2.04 |
| 935 | 840 | * |
| 936 | 841 | * @param mixed $display_value |
| 937 | 842 | * |
| 938 | - * @return int|string | |
| 843 | + * @return string|int | |
| 939 | 844 | */ |
| 940 | 845 | protected function prepare_display_value_for_plain_text_content( $display_value ) { |
| 941 | 846 | $display_value = $this->flatten_array( $display_value ); |
| 942 | - return $this->strip_html( $display_value ); | |
| 847 | + $display_value = $this->strip_html( $display_value ); | |
| 848 | + | |
| 849 | + return $display_value; | |
| 943 | 850 | } |
| 944 | 851 | |
| 945 | 852 | /** |
| 946 | 853 | * Flatten an array |
| @@ -946,16 +853,15 @@ | ||
| 946 | 853 | * Flatten an array |
| 947 | 854 | * |
| 948 | 855 | * @since 2.04 |
| 949 | 856 | * |
| 950 | - * @param array|int|string $value | |
| 857 | + * @param array|string|int $value | |
| 951 | 858 | * |
| 952 | - * @return int|string | |
| 859 | + * @return string|int | |
| 953 | 860 | */ |
| 954 | 861 | protected function flatten_array( $value ) { |
| 955 | 862 | if ( is_array( $value ) ) { |
| 956 | - $separator = $this->atts['array_separator'] ?? ', '; | |
| 957 | - $value = implode( $separator, $value ); | |
| 863 | + $value = implode( ', ', $value ); | |
| 958 | 864 | } |
| 959 | 865 | |
| 960 | 866 | return $value; |
| 961 | 867 | } |
| @@ -969,23 +875,22 @@ | ||
| 969 | 875 | * |
| 970 | 876 | * @return mixed |
| 971 | 877 | */ |
| 972 | 878 | protected function strip_html( $value ) { |
| 973 | - if ( ! $this->is_plain_text ) { | |
| 974 | - return $value; | |
| 975 | - } | |
| 976 | 879 | |
| 977 | - if ( is_array( $value ) ) { | |
| 978 | - foreach ( $value as $key => $single_value ) { | |
| 979 | - $value[ $key ] = $this->strip_html( $single_value ); | |
| 880 | + if ( $this->is_plain_text ) { | |
| 881 | + | |
| 882 | + if ( is_array( $value ) ) { | |
| 883 | + foreach ( $value as $key => $single_value ) { | |
| 884 | + $value[ $key ] = $this->strip_html( $single_value ); | |
| 885 | + } | |
| 886 | + } elseif ( $this->is_plain_text && ! is_array( $value ) ) { | |
| 887 | + if ( strpos( $value, '<img' ) !== false ) { | |
| 888 | + $value = str_replace( array( '<img', 'src=', '/>', '"' ), '', $value ); | |
| 889 | + $value = trim( $value ); | |
| 890 | + } | |
| 891 | + $value = strip_tags( $value ); | |
| 980 | 892 | } |
| 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 | 893 | } |
| 989 | 894 | |
| 990 | 895 | return $value; |
| 991 | 896 | } |