Ticket #49029: 49029.diff
File 49029.diff, 5.0 KB (added by , 5 years ago) |
---|
-
src/wp-admin/includes/privacy-tools.php
diff --git a/src/wp-admin/includes/privacy-tools.php b/src/wp-admin/includes/privacy-tools.php index efe46cce32..ca336532f7 100644
a b function wp_privacy_generate_personal_data_export_file( $request_id ) { 326 326 $file_basename = 'wp-personal-data-file-' . $stripped_email . '-' . $obscura; 327 327 $html_report_filename = $file_basename . '.html'; 328 328 $html_report_pathname = wp_normalize_path( $exports_dir . $html_report_filename ); 329 $ file = fopen( $html_report_pathname, 'w' );330 if ( false === $file ) {331 wp_send_json_error( __( 'Unable to open export file (HTML report) for writing.' ) ); 332 }329 $json_report_filename = $file_basename . '.json'; 330 $json_report_pathname = wp_normalize_path( $exports_dir . $json_report_filename ); 331 332 // Gather general data needed. 333 333 334 // Title. 334 335 $title = sprintf( 335 336 /* translators: %s: User's email address. */ 336 337 __( 'Personal Data Export for %s' ), 337 338 $email_address 338 339 ); 339 340 340 // Open HTML.341 fwrite( $file, "<!DOCTYPE html>\n" );342 fwrite( $file, "<html>\n" );343 344 // Head.345 fwrite( $file, "<head>\n" );346 fwrite( $file, "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />\n" );347 fwrite( $file, "<style type='text/css'>" );348 fwrite( $file, 'body { color: black; font-family: Arial, sans-serif; font-size: 11pt; margin: 15px auto; width: 860px; }' );349 fwrite( $file, 'table { background: #f0f0f0; border: 1px solid #ddd; margin-bottom: 20px; width: 100%; }' );350 fwrite( $file, 'th { padding: 5px; text-align: left; width: 20%; }' );351 fwrite( $file, 'td { padding: 5px; }' );352 fwrite( $file, 'tr:nth-child(odd) { background-color: #fafafa; }' );353 fwrite( $file, '</style>' );354 fwrite( $file, '<title>' );355 fwrite( $file, esc_html( $title ) );356 fwrite( $file, '</title>' );357 fwrite( $file, "</head>\n" );358 359 // Body.360 fwrite( $file, "<body>\n" );361 362 // Heading.363 fwrite( $file, '<h1>' . esc_html__( 'Personal Data Export' ) . '</h1>' );364 365 341 // And now, all the Groups. 366 342 $groups = get_post_meta( $request_id, '_export_data_grouped', true ); 367 343 … … function wp_privacy_generate_personal_data_export_file( $request_id ) { 396 372 // Merge in the special about group. 397 373 $groups = array_merge( array( 'about' => $about_group ), $groups ); 398 374 375 // Convert the groups to JSON format. 376 $groups_json = wp_json_encode( $groups ); 377 378 /** 379 * Handle the JSON export. 380 */ 381 $file = fopen( $json_report_pathname, 'w' ); 382 383 if ( false === $file ) { 384 wp_send_json_error( __( 'Unable to open export file (JSON report) for writing.' ) ); 385 } 386 387 fwrite( $file, '{' ); 388 fwrite( $file, '"' . $title . '":' ); 389 fwrite( $file, $groups_json ); 390 fwrite( $file, '}' ); 391 fclose( $file ); 392 393 /** 394 * Handle the HTML export. 395 */ 396 $file = fopen( $html_report_pathname, 'w' ); 397 398 if ( false === $file ) { 399 wp_send_json_error( __( 'Unable to open export file (HTML report) for writing.' ) ); 400 } 401 402 fwrite( $file, "<!DOCTYPE html>\n" ); 403 fwrite( $file, "<html>\n" ); 404 fwrite( $file, "<head>\n" ); 405 fwrite( $file, "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />\n" ); 406 fwrite( $file, "<style type='text/css'>" ); 407 fwrite( $file, 'body { color: black; font-family: Arial, sans-serif; font-size: 11pt; margin: 15px auto; width: 860px; }' ); 408 fwrite( $file, 'table { background: #f0f0f0; border: 1px solid #ddd; margin-bottom: 20px; width: 100%; }' ); 409 fwrite( $file, 'th { padding: 5px; text-align: left; width: 20%; }' ); 410 fwrite( $file, 'td { padding: 5px; }' ); 411 fwrite( $file, 'tr:nth-child(odd) { background-color: #fafafa; }' ); 412 fwrite( $file, '</style>' ); 413 fwrite( $file, '<title>' ); 414 fwrite( $file, esc_html( $title ) ); 415 fwrite( $file, '</title>' ); 416 fwrite( $file, "</head>\n" ); 417 fwrite( $file, "<body>\n" ); 418 fwrite( $file, '<h1>' . esc_html__( 'Personal Data Export' ) . '</h1>' ); 419 399 420 // Now, iterate over every group in $groups and have the formatter render it in HTML. 400 421 foreach ( (array) $groups as $group_id => $group_data ) { 401 422 fwrite( $file, wp_privacy_generate_personal_data_export_group_html( $group_data ) ); 402 423 } 403 424 404 425 fwrite( $file, "</body>\n" ); 405 406 // Close HTML.407 426 fwrite( $file, "</html>\n" ); 408 427 fclose( $file ); 409 428 … … function wp_privacy_generate_personal_data_export_file( $request_id ) { 433 452 434 453 $zip = new ZipArchive; 435 454 if ( true === $zip->open( $archive_pathname, ZipArchive::CREATE ) ) { 455 if ( ! $zip->addFile( $json_report_pathname, 'export.json' ) ) { 456 $error = __( 'Unable to add data to JSON file.' ); 457 } 458 436 459 if ( ! $zip->addFile( $html_report_pathname, 'index.html' ) ) { 437 $error = __( 'Unable to add data to exportfile.' );460 $error = __( 'Unable to add data to HTML file.' ); 438 461 } 439 462 440 463 $zip->close(); … … function wp_privacy_generate_personal_data_export_file( $request_id ) { 456 479 $error = __( 'Unable to open export file (archive) for writing.' ); 457 480 } 458 481 459 // And remove the HTML file. 482 // Remove the JSON file. 483 unlink( $json_report_pathname ); 484 485 // Remove the HTML file. 460 486 unlink( $html_report_pathname ); 461 487 462 488 if ( $error ) {