| @@ -113,19 +113,19 @@ | ||
| 113 | 113 | // Do not add the UTF-8 with BOM option if this function is called on Global Settings. |
| 114 | 114 | // This is to improve compatibility with the Export View as CSV add-on (v1.10). |
| 115 | 115 | // Otherwise, the option will appear twice since it is added in the add-on as well. |
| 116 | 116 | $on_global_settings_page = 'formidable-settings' === FrmAppHelper::get_param( 'page' ); |
| 117 | - | |
| 118 | 117 | if ( ! $on_global_settings_page ) { |
| 119 | 118 | array_splice( $formats, 1, 0, 'UTF-8 with BOM' ); |
| 120 | 119 | } |
| 121 | 120 | |
| 122 | - return apply_filters( 'frm_csv_format_options', $formats ); | |
| 121 | + $formats = apply_filters( 'frm_csv_format_options', $formats ); | |
| 122 | + | |
| 123 | + return $formats; | |
| 123 | 124 | } |
| 124 | 125 | |
| 125 | 126 | /** |
| 126 | 127 | * @param array $atts |
| 127 | - * | |
| 128 | 128 | * @return false|string|null returns a string file path or false if $atts['mode'] is set to 'file'. |
| 129 | 129 | */ |
| 130 | 130 | public static function generate_csv( $atts ) { |
| 131 | 131 | global $frm_vars; |
| @@ -144,9 +144,8 @@ | ||
| 144 | 144 | |
| 145 | 145 | if ( 'file' === self::$mode ) { |
| 146 | 146 | $filepath = get_temp_dir() . $filename; |
| 147 | 147 | self::$fp = @fopen( $filepath, 'w' ); |
| 148 | - | |
| 149 | 148 | if ( ! self::$fp ) { |
| 150 | 149 | return false; |
| 151 | 150 | } |
| 152 | 151 | } elseif ( 'echo' === self::$mode ) { |
| @@ -154,14 +153,14 @@ | ||
| 154 | 153 | } |
| 155 | 154 | |
| 156 | 155 | unset( $filename ); |
| 157 | 156 | |
| 158 | - self::$comment_count = FrmDb::get_count( | |
| 157 | + $comment_count = FrmDb::get_count( | |
| 159 | 158 | 'frm_item_metas', |
| 160 | 159 | array( |
| 161 | 160 | 'item_id' => $atts['entry_ids'], |
| 162 | 161 | 'field_id' => 0, |
| 163 | - 'meta_value like' => 's:7:"comment";', | |
| 162 | + 'meta_value like' => '{', | |
| 164 | 163 | ), |
| 165 | 164 | array( |
| 166 | 165 | 'group_by' => 'item_id', |
| 167 | 166 | 'order_by' => 'count(*) DESC', |
| @@ -167,8 +166,9 @@ | ||
| 167 | 166 | 'order_by' => 'count(*) DESC', |
| 168 | 167 | 'limit' => 1, |
| 169 | 168 | ) |
| 170 | 169 | ); |
| 170 | + self::$comment_count = $comment_count; | |
| 171 | 171 | |
| 172 | 172 | self::prepare_csv_headings(); |
| 173 | 173 | |
| 174 | 174 | /** |
| @@ -202,9 +202,8 @@ | ||
| 202 | 202 | /** |
| 203 | 203 | * @since 6.8.4 |
| 204 | 204 | * |
| 205 | 205 | * @param array $atts |
| 206 | - * | |
| 207 | 206 | * @return void |
| 208 | 207 | */ |
| 209 | 208 | private static function after_generate_csv( $atts ) { |
| 210 | 209 | /** |
| @@ -210,9 +209,8 @@ | ||
| 210 | 209 | /** |
| 211 | 210 | * @since 6.8.4 |
| 212 | 211 | * |
| 213 | 212 | * @param array $atts { |
| 214 | - * | |
| 215 | 213 | * @type object $form |
| 216 | 214 | * @type array $entry_ids |
| 217 | 215 | * @type array $form_cols |
| 218 | 216 | * } |
| @@ -223,9 +221,8 @@ | ||
| 223 | 221 | /** |
| 224 | 222 | * @since 5.0.16 |
| 225 | 223 | * |
| 226 | 224 | * @param stdClass $form |
| 227 | - * | |
| 228 | 225 | * @return string |
| 229 | 226 | */ |
| 230 | 227 | private static function generate_csv_filename( $form ) { |
| 231 | 228 | $filename = gmdate( 'ymdHis', time() ) . '_' . sanitize_title_with_dashes( $form->name ) . '_formidable_entries.csv'; |
| @@ -243,11 +240,8 @@ | ||
| 243 | 240 | 'meta' => self::$meta, |
| 244 | 241 | ); |
| 245 | 242 | } |
| 246 | 243 | |
| 247 | - /** | |
| 248 | - * @return void | |
| 249 | - */ | |
| 250 | 244 | private static function set_class_parameters() { |
| 251 | 245 | $args = self::get_standard_filter_args(); |
| 252 | 246 | self::$separator = apply_filters( 'frm_csv_sep', self::$separator, $args ); |
| 253 | 247 | self::$line_break = apply_filters( 'frm_csv_line_break', self::$line_break, $args ); |
| @@ -254,28 +248,17 @@ | ||
| 254 | 248 | self::$wp_date_format = apply_filters( 'frm_csv_date_format', self::$wp_date_format, $args ); |
| 255 | 249 | self::get_csv_format(); |
| 256 | 250 | self::$charset = get_option( 'blog_charset' ); |
| 257 | 251 | |
| 258 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 259 | - $col_sep = ! empty( $_POST['csv_col_sep'] ) ? sanitize_text_field( wp_unslash( $_POST['csv_col_sep'] ) ) : self::$column_separator; | |
| 252 | + $col_sep = ! empty( $_POST['csv_col_sep'] ) ? sanitize_text_field( wp_unslash( $_POST['csv_col_sep'] ) ) : self::$column_separator; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 260 | 253 | |
| 261 | 254 | self::$column_separator = apply_filters( 'frm_csv_column_sep', $col_sep, $args ); |
| 262 | 255 | } |
| 263 | 256 | |
| 264 | - /** | |
| 265 | - * @param object $form | |
| 266 | - * | |
| 267 | - * @return void | |
| 268 | - */ | |
| 269 | 257 | private static function set_has_parent_id( $form ) { |
| 270 | 258 | self::$has_parent_id = $form->parent_form_id > 0; |
| 271 | 259 | } |
| 272 | 260 | |
| 273 | - /** | |
| 274 | - * @param string $filename | |
| 275 | - * | |
| 276 | - * @return void | |
| 277 | - */ | |
| 278 | 261 | private static function print_file_headers( $filename ) { |
| 279 | 262 | header( 'Content-Description: File Transfer' ); |
| 280 | 263 | header( 'Content-Disposition: attachment; filename="' . esc_attr( $filename ) . '"' ); |
| 281 | 264 | header( 'Content-Type: text/csv; charset=' . self::$charset, true ); |
| @@ -313,11 +296,8 @@ | ||
| 313 | 296 | $csv_format = apply_filters( 'frm_csv_format', $csv_format, self::get_standard_filter_args() ); |
| 314 | 297 | self::$to_encoding = $csv_format; |
| 315 | 298 | } |
| 316 | 299 | |
| 317 | - /** | |
| 318 | - * @return void | |
| 319 | - */ | |
| 320 | 300 | private static function prepare_csv_headings() { |
| 321 | 301 | $headings = array(); |
| 322 | 302 | self::csv_headings( $headings ); |
| 323 | 303 | $headings = apply_filters( |
| @@ -333,16 +313,10 @@ | ||
| 333 | 313 | |
| 334 | 314 | self::print_csv_row( $headings ); |
| 335 | 315 | } |
| 336 | 316 | |
| 337 | - /** | |
| 338 | - * @param object $col | |
| 339 | - * | |
| 340 | - * @return array | |
| 341 | - */ | |
| 342 | 317 | private static function field_headings( $col ) { |
| 343 | 318 | $field_type_obj = FrmFieldFactory::get_field_factory( $col ); |
| 344 | - | |
| 345 | 319 | if ( ! empty( $field_type_obj->is_combo_field ) ) { |
| 346 | 320 | // This is combo field. |
| 347 | 321 | return $field_type_obj->get_export_headings(); |
| 348 | 322 | } |
| @@ -348,20 +322,14 @@ | ||
| 348 | 322 | } |
| 349 | 323 | |
| 350 | 324 | $field_headings = array(); |
| 351 | 325 | $separate_values = array( 'user_id', 'file', 'data', 'date' ); |
| 352 | - | |
| 353 | 326 | if ( ! empty( $col->field_options['separate_value'] ) && ! in_array( $col->type, $separate_values, true ) ) { |
| 354 | 327 | $field_headings[ $col->id . '_label' ] = strip_tags( $col->name . ' ' . __( '(label)', 'formidable' ) ); |
| 355 | 328 | } |
| 356 | 329 | |
| 357 | - if ( ! empty( $field_headings[ $col->id . '_label' ] ) ) { | |
| 358 | - $field_headings[ $col->id ] = strip_tags( $col->name . ' ' . __( '(value)', 'formidable' ) ); | |
| 359 | - } else { | |
| 360 | - $field_headings[ $col->id ] = strip_tags( $col->name ); | |
| 361 | - } | |
| 362 | - | |
| 363 | - return apply_filters( | |
| 330 | + $field_headings[ $col->id ] = strip_tags( $col->name ); | |
| 331 | + $field_headings = apply_filters( | |
| 364 | 332 | 'frm_csv_field_columns', |
| 365 | 333 | $field_headings, |
| 366 | 334 | array_merge( |
| 367 | 335 | self::get_standard_filter_args(), |
| @@ -367,16 +335,13 @@ | ||
| 367 | 335 | self::get_standard_filter_args(), |
| 368 | 336 | array( 'field' => $col ) |
| 369 | 337 | ) |
| 370 | 338 | ); |
| 339 | + | |
| 340 | + return $field_headings; | |
| 371 | 341 | } |
| 372 | 342 | |
| 373 | - /** | |
| 374 | - * @param array $headings | |
| 375 | - * | |
| 376 | - * @return void | |
| 377 | - */ | |
| 378 | - private static function csv_headings( &$headings ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh | |
| 343 | + private static function csv_headings( &$headings ) { | |
| 379 | 344 | $fields_by_repeater_id = array(); |
| 380 | 345 | $repeater_ids = array(); |
| 381 | 346 | |
| 382 | 347 | foreach ( self::$fields as $col ) { |
| @@ -415,26 +380,24 @@ | ||
| 415 | 380 | } |
| 416 | 381 | unset( $start, $end, $length, $row, $repeater_meta, $where ); |
| 417 | 382 | |
| 418 | 383 | $flat = array(); |
| 419 | - | |
| 420 | 384 | foreach ( $headings as $key => $heading ) { |
| 421 | - if ( ! is_array( $heading ) ) { | |
| 422 | - $flat[ $key ] = $heading; | |
| 423 | - continue; | |
| 424 | - } | |
| 385 | + if ( is_array( $heading ) ) { | |
| 386 | + $repeater_id = str_replace( 'repeater', '', $key ); | |
| 425 | 387 | |
| 426 | - $repeater_id = str_replace( 'repeater', '', $key ); | |
| 427 | - $repeater_headings = array(); | |
| 388 | + $repeater_headings = array(); | |
| 389 | + foreach ( $fields_by_repeater_id[ $repeater_id ] as $col ) { | |
| 390 | + $repeater_headings += self::field_headings( $col ); | |
| 391 | + } | |
| 428 | 392 | |
| 429 | - foreach ( $fields_by_repeater_id[ $repeater_id ] as $col ) { | |
| 430 | - $repeater_headings += self::field_headings( $col ); | |
| 431 | - } | |
| 432 | - | |
| 433 | - for ( $i = 0; $i < $max[ $repeater_id ]; $i++ ) { | |
| 434 | - foreach ( $repeater_headings as $repeater_key => $repeater_name ) { | |
| 435 | - $flat[ $repeater_key . '[' . $i . ']' ] = $repeater_name; | |
| 393 | + for ( $i = 0; $i < $max[ $repeater_id ]; $i++ ) { | |
| 394 | + foreach ( $repeater_headings as $repeater_key => $repeater_name ) { | |
| 395 | + $flat[ $repeater_key . '[' . $i . ']' ] = $repeater_name; | |
| 396 | + } | |
| 436 | 397 | } |
| 398 | + } else { | |
| 399 | + $flat[ $key ] = $heading; | |
| 437 | 400 | } |
| 438 | 401 | } |
| 439 | 402 | |
| 440 | 403 | self::$fields_by_repeater_id = $fields_by_repeater_id; |
| @@ -461,9 +424,8 @@ | ||
| 461 | 424 | $headings['is_draft'] = __( 'Entry Status', 'formidable' ); |
| 462 | 425 | $headings['ip'] = __( 'IP', 'formidable' ); |
| 463 | 426 | $headings['id'] = __( 'ID', 'formidable' ); |
| 464 | 427 | $headings['item_key'] = __( 'Key', 'formidable' ); |
| 465 | - | |
| 466 | 428 | if ( self::has_parent_id() ) { |
| 467 | 429 | $headings['parent_id'] = __( 'Parent ID', 'formidable' ); |
| 468 | 430 | } |
| 469 | 431 | |
| @@ -471,9 +433,8 @@ | ||
| 471 | 433 | } |
| 472 | 434 | |
| 473 | 435 | /** |
| 474 | 436 | * @param object $field |
| 475 | - * | |
| 476 | 437 | * @return bool |
| 477 | 438 | */ |
| 478 | 439 | private static function is_the_child_of_a_repeater( $field ) { |
| 479 | 440 | if ( $field->form_id === self::$form_id || empty( $field->field_options['in_section'] ) ) { |
| @@ -482,26 +443,22 @@ | ||
| 482 | 443 | |
| 483 | 444 | $section_id = $field->field_options['in_section']; |
| 484 | 445 | $section = FrmField::getOne( $section_id ); |
| 485 | 446 | |
| 486 | - return $section && FrmField::is_repeating_field( $section ); | |
| 447 | + if ( ! $section ) { | |
| 448 | + return false; | |
| 449 | + } | |
| 450 | + | |
| 451 | + return FrmField::is_repeating_field( $section ); | |
| 487 | 452 | } |
| 488 | 453 | |
| 489 | - /** | |
| 490 | - * @return bool | |
| 491 | - */ | |
| 492 | 454 | private static function has_parent_id() { |
| 493 | 455 | return self::$has_parent_id; |
| 494 | 456 | } |
| 495 | 457 | |
| 496 | - /** | |
| 497 | - * @param array $next_set | |
| 498 | - * | |
| 499 | - * @return void | |
| 500 | - */ | |
| 501 | 458 | private static function prepare_next_csv_rows( $next_set ) { |
| 502 | 459 | if ( FrmAppHelper::pro_is_installed() ) { |
| 503 | - $where = array( | |
| 460 | + $where = array( | |
| 504 | 461 | 'or' => 1, |
| 505 | 462 | 'id' => $next_set, |
| 506 | 463 | 'parent_item_id' => $next_set, |
| 507 | 464 | ); |
| @@ -508,9 +465,9 @@ | ||
| 508 | 465 | // Order by parent_item_id so children will be first. |
| 509 | 466 | $order_by = ' ORDER BY parent_item_id DESC'; |
| 510 | 467 | } else { |
| 511 | 468 | // When Pro is not installed, only query for direct ID matches only as we do not expect parent item id |
| 512 | - // Matches and the more simplified query is faster. | |
| 469 | + // matches and the more simplified query is faster. | |
| 513 | 470 | $where = array( |
| 514 | 471 | 'id' => $next_set, |
| 515 | 472 | ); |
| 516 | 473 | $order_by = ''; |
| @@ -521,19 +478,16 @@ | ||
| 521 | 478 | foreach ( $entries as $entry ) { |
| 522 | 479 | self::$entry = $entry; |
| 523 | 480 | unset( $entry ); |
| 524 | 481 | |
| 525 | - if ( self::$entry->form_id === self::$form_id ) { | |
| 482 | + if ( self::$entry->form_id !== self::$form_id ) { | |
| 483 | + self::add_repeat_field_values_to_csv( $entries ); | |
| 484 | + } else { | |
| 526 | 485 | self::prepare_csv_row(); |
| 527 | - } else { | |
| 528 | - self::add_repeat_field_values_to_csv( $entries ); | |
| 529 | 486 | } |
| 530 | 487 | } |
| 531 | 488 | } |
| 532 | 489 | |
| 533 | - /** | |
| 534 | - * @return void | |
| 535 | - */ | |
| 536 | 490 | private static function prepare_csv_row() { |
| 537 | 491 | $row = array(); |
| 538 | 492 | self::add_field_values_to_csv( $row ); |
| 539 | 493 | self::add_entry_data_to_csv( $row ); |
| @@ -549,20 +503,15 @@ | ||
| 549 | 503 | ); |
| 550 | 504 | self::print_csv_row( $row ); |
| 551 | 505 | } |
| 552 | 506 | |
| 553 | - /** | |
| 554 | - * @param array $entries | |
| 555 | - * | |
| 556 | - * @return void | |
| 557 | - */ | |
| 558 | 507 | private static function add_repeat_field_values_to_csv( &$entries ) { |
| 559 | 508 | if ( isset( self::$entry->metas ) ) { |
| 560 | - // Add child entries to the parent | |
| 509 | + // add child entries to the parent | |
| 561 | 510 | foreach ( self::$entry->metas as $meta_id => $meta_value ) { |
| 562 | 511 | if ( ! is_numeric( $meta_id ) || '' === $meta_value ) { |
| 563 | - // If the hook is being used to include field keys in the metas array, | |
| 564 | - // We need to skip the keys and only process field ids | |
| 512 | + // if the hook is being used to include field keys in the metas array, | |
| 513 | + // we need to skip the keys and only process field ids | |
| 565 | 514 | continue; |
| 566 | 515 | } |
| 567 | 516 | |
| 568 | 517 | if ( ! isset( $entries[ self::$entry->parent_item_id ] ) ) { |
| @@ -572,10 +521,10 @@ | ||
| 572 | 521 | |
| 573 | 522 | if ( ! isset( $entries[ self::$entry->parent_item_id ]->metas[ $meta_id ] ) ) { |
| 574 | 523 | $entries[ self::$entry->parent_item_id ]->metas[ $meta_id ] = array(); |
| 575 | 524 | } elseif ( ! is_array( $entries[ self::$entry->parent_item_id ]->metas[ $meta_id ] ) ) { |
| 576 | - // If the data is here, it should be an array but if this field has collected data | |
| 577 | - // Both while inside and outside of the repeating section, it's possible this is a string. | |
| 525 | + // if the data is here, it should be an array but if this field has collected data | |
| 526 | + // both while inside and outside of the repeating section, it's possible this is a string. | |
| 578 | 527 | $entries[ self::$entry->parent_item_id ]->metas[ $meta_id ] = (array) $entries[ self::$entry->parent_item_id ]->metas[ $meta_id ]; |
| 579 | 528 | } |
| 580 | 529 | |
| 581 | 530 | // Add the repeated values. |
| @@ -585,13 +534,12 @@ | ||
| 585 | 534 | self::$entry->metas = self::fill_missing_repeater_metas( self::$entry->metas, $entries ); |
| 586 | 535 | $entries[ self::$entry->parent_item_id ]->metas += self::$entry->metas; |
| 587 | 536 | }//end if |
| 588 | 537 | |
| 589 | - // Add the embedded form id | |
| 538 | + // add the embedded form id | |
| 590 | 539 | if ( ! isset( $entries[ self::$entry->parent_item_id ]->embedded_fields ) ) { |
| 591 | 540 | $entries[ self::$entry->parent_item_id ]->embedded_fields = array(); |
| 592 | 541 | } |
| 593 | - | |
| 594 | 542 | $entries[ self::$entry->parent_item_id ]->embedded_fields[ self::$entry->id ] = self::$entry->form_id; |
| 595 | 543 | } |
| 596 | 544 | |
| 597 | 545 | /** |
| @@ -599,14 +547,14 @@ | ||
| 599 | 547 | * The export needs all of the meta to be filled in, so we put blank strings for every missing repeater child |
| 600 | 548 | * |
| 601 | 549 | * @param array $metas |
| 602 | 550 | * @param array $entries |
| 603 | - * | |
| 604 | 551 | * @return array |
| 605 | 552 | */ |
| 606 | 553 | private static function fill_missing_repeater_metas( $metas, &$entries ) { |
| 607 | - $field_id = array_key_last( $metas ); | |
| 608 | - $field = self::get_field( $field_id ); | |
| 554 | + $field_ids = array_keys( $metas ); | |
| 555 | + $field_id = end( $field_ids ); | |
| 556 | + $field = self::get_field( $field_id ); | |
| 609 | 557 | |
| 610 | 558 | if ( ! $field || empty( $field->field_options['in_section'] ) ) { |
| 611 | 559 | return $metas; |
| 612 | 560 | } |
| @@ -611,55 +559,40 @@ | ||
| 611 | 559 | return $metas; |
| 612 | 560 | } |
| 613 | 561 | |
| 614 | 562 | $repeater_id = $field->field_options['in_section']; |
| 615 | - | |
| 616 | 563 | if ( ! isset( self::$fields_by_repeater_id[ $repeater_id ] ) ) { |
| 617 | 564 | return $metas; |
| 618 | 565 | } |
| 619 | 566 | |
| 620 | 567 | foreach ( self::$fields_by_repeater_id[ $repeater_id ] as $repeater_child ) { |
| 621 | - if ( isset( $metas[ $repeater_child->id ] ) ) { | |
| 622 | - continue; | |
| 623 | - } | |
| 568 | + if ( ! isset( $metas[ $repeater_child->id ] ) ) { | |
| 569 | + $metas[ $repeater_child->id ] = ''; | |
| 624 | 570 | |
| 625 | - $metas[ $repeater_child->id ] = ''; | |
| 571 | + if ( ! isset( $entries[ self::$entry->parent_item_id ]->metas[ $repeater_child->id ] ) || ! is_array( $entries[ self::$entry->parent_item_id ]->metas[ $repeater_child->id ] ) ) { | |
| 572 | + $entries[ self::$entry->parent_item_id ]->metas[ $repeater_child->id ] = array(); | |
| 573 | + } | |
| 626 | 574 | |
| 627 | - if ( ! isset( $entries[ self::$entry->parent_item_id ]->metas[ $repeater_child->id ] ) || ! is_array( $entries[ self::$entry->parent_item_id ]->metas[ $repeater_child->id ] ) ) { // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 628 | - $entries[ self::$entry->parent_item_id ]->metas[ $repeater_child->id ] = array(); | |
| 575 | + $entries[ self::$entry->parent_item_id ]->metas[ $repeater_child->id ][] = ''; | |
| 629 | 576 | } |
| 630 | - | |
| 631 | - $entries[ self::$entry->parent_item_id ]->metas[ $repeater_child->id ][] = ''; | |
| 632 | 577 | } |
| 633 | 578 | |
| 634 | 579 | return $metas; |
| 635 | 580 | } |
| 636 | 581 | |
| 637 | - /** | |
| 638 | - * @param int|string $field_id | |
| 639 | - * | |
| 640 | - * @return false|object | |
| 641 | - */ | |
| 642 | 582 | private static function get_field( $field_id ) { |
| 643 | 583 | $field_id = (int) $field_id; |
| 644 | - | |
| 645 | 584 | foreach ( self::$fields as $field ) { |
| 646 | 585 | if ( $field_id === (int) $field->id ) { |
| 647 | 586 | return $field; |
| 648 | 587 | } |
| 649 | 588 | } |
| 650 | - | |
| 651 | 589 | return false; |
| 652 | 590 | } |
| 653 | 591 | |
| 654 | - /** | |
| 655 | - * @param array $row | |
| 656 | - * | |
| 657 | - * @return void | |
| 658 | - */ | |
| 659 | 592 | private static function add_field_values_to_csv( &$row ) { |
| 660 | 593 | foreach ( self::$fields as $col ) { |
| 661 | - $field_value = self::$entry->metas[ $col->id ] ?? false; | |
| 594 | + $field_value = isset( self::$entry->metas[ $col->id ] ) ? self::$entry->metas[ $col->id ] : false; | |
| 662 | 595 | |
| 663 | 596 | FrmFieldsHelper::prepare_field_value( $field_value, $col->type ); |
| 664 | 597 | self::add_array_values_to_columns( $row, compact( 'col', 'field_value' ) ); |
| 665 | 598 | |
| @@ -675,9 +608,8 @@ | ||
| 675 | 608 | ); |
| 676 | 609 | |
| 677 | 610 | if ( ! empty( $col->field_options['separate_value'] ) ) { |
| 678 | 611 | $label_key = $col->id . '_label'; |
| 679 | - | |
| 680 | 612 | if ( self::is_the_child_of_a_repeater( $col ) ) { |
| 681 | 613 | $row[ $label_key ] = array(); |
| 682 | 614 | |
| 683 | 615 | if ( is_array( $field_value ) ) { |
| @@ -701,9 +633,8 @@ | ||
| 701 | 633 | * @since 5.0.06 |
| 702 | 634 | * |
| 703 | 635 | * @param mixed $field_value |
| 704 | 636 | * @param stdClass $field |
| 705 | - * | |
| 706 | 637 | * @return string |
| 707 | 638 | */ |
| 708 | 639 | private static function get_separate_value_label( $field_value, $field ) { |
| 709 | 640 | return FrmEntriesHelper::display_value( |
| @@ -714,9 +645,9 @@ | ||
| 714 | 645 | 'post_id' => self::$entry->post_id, |
| 715 | 646 | 'show_icon' => false, |
| 716 | 647 | 'entry_id' => self::$entry->id, |
| 717 | 648 | 'sep' => self::$separator, |
| 718 | - 'embedded_field_id' => isset( self::$entry->embedded_fields ) && isset( self::$entry->embedded_fields[ self::$entry->id ] ) ? 'form' . self::$entry->embedded_fields[ self::$entry->id ] : 0, // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 649 | + 'embedded_field_id' => isset( self::$entry->embedded_fields ) && isset( self::$entry->embedded_fields[ self::$entry->id ] ) ? 'form' . self::$entry->embedded_fields[ self::$entry->id ] : 0, | |
| 719 | 650 | ) |
| 720 | 651 | ); |
| 721 | 652 | } |
| 722 | 653 | |
| @@ -721,46 +652,32 @@ | ||
| 721 | 652 | } |
| 722 | 653 | |
| 723 | 654 | /** |
| 724 | 655 | * @since 2.0.23 |
| 725 | - * | |
| 726 | - * @param array $row | |
| 727 | - * @param array $atts | |
| 728 | - * | |
| 729 | - * @return void | |
| 730 | 656 | */ |
| 731 | 657 | private static function add_array_values_to_columns( &$row, $atts ) { |
| 732 | - if ( ! is_array( $atts['field_value'] ) ) { | |
| 733 | - return; | |
| 734 | - } | |
| 658 | + if ( is_array( $atts['field_value'] ) ) { | |
| 659 | + foreach ( $atts['field_value'] as $key => $sub_value ) { | |
| 660 | + if ( is_array( $sub_value ) ) { | |
| 661 | + // This is combo field inside repeater. The heading key has this format: [86_first[0]]. | |
| 662 | + foreach ( $sub_value as $sub_key => $sub_sub_value ) { | |
| 663 | + $column_key = $atts['col']->id . '_' . $sub_key . '[' . $key . ']'; | |
| 664 | + if ( ! is_numeric( $sub_key ) && isset( self::$headings[ $column_key ] ) ) { | |
| 665 | + $row[ $column_key ] = $sub_sub_value; | |
| 666 | + } | |
| 667 | + } | |
| 735 | 668 | |
| 736 | - foreach ( $atts['field_value'] as $key => $sub_value ) { | |
| 737 | - if ( is_array( $sub_value ) ) { | |
| 738 | - // This is combo field inside repeater. The heading key has this format: [86_first[0]]. | |
| 739 | - foreach ( $sub_value as $sub_key => $sub_sub_value ) { | |
| 740 | - $column_key = $atts['col']->id . '_' . $sub_key . '[' . $key . ']'; | |
| 669 | + continue; | |
| 670 | + } | |
| 741 | 671 | |
| 742 | - if ( ! is_numeric( $sub_key ) && isset( self::$headings[ $column_key ] ) ) { | |
| 743 | - $row[ $column_key ] = $sub_sub_value; | |
| 744 | - } | |
| 672 | + $column_key = $atts['col']->id . '_' . $key; | |
| 673 | + if ( ! is_numeric( $key ) && isset( self::$headings[ $column_key ] ) ) { | |
| 674 | + $row[ $column_key ] = $sub_value; | |
| 745 | 675 | } |
| 746 | - | |
| 747 | - continue; | |
| 748 | 676 | } |
| 749 | - | |
| 750 | - $column_key = $atts['col']->id . '_' . $key; | |
| 751 | - | |
| 752 | - if ( ! is_numeric( $key ) && isset( self::$headings[ $column_key ] ) ) { | |
| 753 | - $row[ $column_key ] = $sub_value; | |
| 754 | - } | |
| 755 | 677 | } |
| 756 | 678 | } |
| 757 | 679 | |
| 758 | - /** | |
| 759 | - * @param array $row | |
| 760 | - * | |
| 761 | - * @return void | |
| 762 | - */ | |
| 763 | 680 | private static function add_entry_data_to_csv( &$row ) { |
| 764 | 681 | $row['created_at'] = FrmAppHelper::get_formatted_time( self::$entry->created_at, self::$wp_date_format, ' ' ); |
| 765 | 682 | $row['updated_at'] = FrmAppHelper::get_formatted_time( self::$entry->updated_at, self::$wp_date_format, ' ' ); |
| 766 | 683 | $row['user_id'] = self::$entry->user_id; |
| @@ -768,19 +685,13 @@ | ||
| 768 | 685 | $row['is_draft'] = self::$entry->is_draft; |
| 769 | 686 | $row['ip'] = self::$entry->ip; |
| 770 | 687 | $row['id'] = self::$entry->id; |
| 771 | 688 | $row['item_key'] = self::$entry->item_key; |
| 772 | - | |
| 773 | 689 | if ( self::has_parent_id() ) { |
| 774 | 690 | $row['parent_id'] = self::$entry->parent_item_id; |
| 775 | 691 | } |
| 776 | 692 | } |
| 777 | 693 | |
| 778 | - /** | |
| 779 | - * @param array $rows | |
| 780 | - * | |
| 781 | - * @return void | |
| 782 | - */ | |
| 783 | 694 | private static function print_csv_row( $rows ) { |
| 784 | 695 | $sep = ''; |
| 785 | 696 | $echo = 'echo' === self::$mode; |
| 786 | 697 | |
| @@ -788,9 +699,8 @@ | ||
| 788 | 699 | if ( isset( $rows[ $k ] ) ) { |
| 789 | 700 | $row = $rows[ $k ]; |
| 790 | 701 | } else { |
| 791 | 702 | $row = ''; |
| 792 | - | |
| 793 | 703 | // array indexed data is not at $rows[ $k ] |
| 794 | 704 | if ( $k[ strlen( $k ) - 1 ] === ']' ) { |
| 795 | 705 | $start = strrpos( $k, '[' ); |
| 796 | 706 | $key = substr( $k, 0, $start++ ); |
| @@ -804,14 +714,13 @@ | ||
| 804 | 714 | } |
| 805 | 715 | } |
| 806 | 716 | |
| 807 | 717 | if ( is_array( $row ) ) { |
| 808 | - // Implode the repeated field values | |
| 718 | + // implode the repeated field values | |
| 809 | 719 | $row = implode( self::$separator, FrmAppHelper::array_flatten( $row, 'reset' ) ); |
| 810 | 720 | } |
| 811 | 721 | |
| 812 | 722 | $val = self::encode_value( $row ); |
| 813 | - | |
| 814 | 723 | if ( 'return' !== self::$line_break ) { |
| 815 | 724 | $val = str_replace( array( "\r\n", "\r", "\n" ), self::$line_break, $val ); |
| 816 | 725 | } |
| 817 | 726 | |
| @@ -819,14 +728,12 @@ | ||
| 819 | 728 | echo $sep . '"' . $val . '"'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 820 | 729 | } else { |
| 821 | 730 | fwrite( self::$fp, $sep . '"' . $val . '"' ); |
| 822 | 731 | } |
| 823 | - | |
| 824 | 732 | $sep = self::$column_separator; |
| 825 | 733 | |
| 826 | 734 | unset( $k, $row ); |
| 827 | 735 | }//end foreach |
| 828 | - | |
| 829 | 736 | if ( $echo ) { |
| 830 | 737 | echo "\n"; |
| 831 | 738 | } else { |
| 832 | 739 | fwrite( self::$fp, "\n" ); |
| @@ -832,13 +739,8 @@ | ||
| 832 | 739 | fwrite( self::$fp, "\n" ); |
| 833 | 740 | } |
| 834 | 741 | } |
| 835 | 742 | |
| 836 | - /** | |
| 837 | - * @param string $line | |
| 838 | - * | |
| 839 | - * @return string | |
| 840 | - */ | |
| 841 | 743 | public static function encode_value( $line ) { |
| 842 | 744 | if ( '' === $line ) { |
| 843 | 745 | return $line; |
| 844 | 746 | } |
| @@ -846,12 +748,12 @@ | ||
| 846 | 748 | $convmap = false; |
| 847 | 749 | |
| 848 | 750 | switch ( self::$to_encoding ) { |
| 849 | 751 | case 'macintosh': |
| 850 | - // This map was derived from the differences between the MacRoman and UTF-8 Charsets | |
| 752 | + // this map was derived from the differences between the MacRoman and UTF-8 Charsets | |
| 851 | 753 | // Reference: |
| 852 | 754 | // http://www.alanwood.net/demos/macroman.html. |
| 853 | - $convmap = array( 256, 304, 0, 0xffff, 306, 337, 0, 0xffff, 340, 375, 0, 0xffff, 377, 401, 0, 0xffff, 403, 709, 0, 0xffff, 712, 727, 0, 0xffff, 734, 936, 0, 0xffff, 938, 959, 0, 0xffff, 961, 8210, 0, 0xffff, 8213, 8215, 0, 0xffff, 8219, 8219, 0, 0xffff, 8227, 8229, 0, 0xffff, 8231, 8239, 0, 0xffff, 8241, 8248, 0, 0xffff, 8251, 8259, 0, 0xffff, 8261, 8363, 0, 0xffff, 8365, 8481, 0, 0xffff, 8483, 8705, 0, 0xffff, 8707, 8709, 0, 0xffff, 8711, 8718, 0, 0xffff, 8720, 8720, 0, 0xffff, 8722, 8729, 0, 0xffff, 8731, 8733, 0, 0xffff, 8735, 8746, 0, 0xffff, 8748, 8775, 0, 0xffff, 8777, 8799, 0, 0xffff, 8801, 8803, 0, 0xffff, 8806, 9673, 0, 0xffff, 9675, 63742, 0, 0xffff, 63744, 64256, 0, 0xffff ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 755 | + $convmap = array( 256, 304, 0, 0xffff, 306, 337, 0, 0xffff, 340, 375, 0, 0xffff, 377, 401, 0, 0xffff, 403, 709, 0, 0xffff, 712, 727, 0, 0xffff, 734, 936, 0, 0xffff, 938, 959, 0, 0xffff, 961, 8210, 0, 0xffff, 8213, 8215, 0, 0xffff, 8219, 8219, 0, 0xffff, 8227, 8229, 0, 0xffff, 8231, 8239, 0, 0xffff, 8241, 8248, 0, 0xffff, 8251, 8259, 0, 0xffff, 8261, 8363, 0, 0xffff, 8365, 8481, 0, 0xffff, 8483, 8705, 0, 0xffff, 8707, 8709, 0, 0xffff, 8711, 8718, 0, 0xffff, 8720, 8720, 0, 0xffff, 8722, 8729, 0, 0xffff, 8731, 8733, 0, 0xffff, 8735, 8746, 0, 0xffff, 8748, 8775, 0, 0xffff, 8777, 8799, 0, 0xffff, 8801, 8803, 0, 0xffff, 8806, 9673, 0, 0xffff, 9675, 63742, 0, 0xffff, 63744, 64256, 0, 0xffff ); | |
| 854 | 756 | break; |
| 855 | 757 | case 'ISO-8859-1': |
| 856 | 758 | $convmap = array( 256, 10000, 0, 0xffff ); |
| 857 | 759 | } |
| @@ -870,11 +772,9 @@ | ||
| 870 | 772 | /** |
| 871 | 773 | * Escape a " in a csv with another " |
| 872 | 774 | * |
| 873 | 775 | * @since 2.0 |
| 874 | - * | |
| 875 | 776 | * @param mixed $value |
| 876 | - * | |
| 877 | 777 | * @return mixed |
| 878 | 778 | */ |
| 879 | 779 | public static function escape_csv( $value ) { |
| 880 | 780 | if ( ! is_string( $value ) ) { |
| @@ -884,8 +784,9 @@ | ||
| 884 | 784 | if ( '=' === $value[0] ) { |
| 885 | 785 | // escape the = to prevent vulnerability |
| 886 | 786 | $value = "'" . $value; |
| 887 | 787 | } |
| 788 | + $value = str_replace( '"', '""', $value ); | |
| 888 | 789 | |
| 889 | - return str_replace( '"', '""', $value ); | |
| 790 | + return $value; | |
| 890 | 791 | } |
| 891 | 792 | } |