Skip to content

Commit

Permalink
Removes mime type logs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmigf committed Jul 4, 2024
1 parent 52d3d76 commit 2a4233a
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions includes/wcpdf-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,6 @@ function wpo_wcpdf_get_image_mime_type( string $src ): string {

if ( $image_info && isset( $image_info['mime'] ) ) {
$mime_type = $image_info['mime'];
} else {
wcpdf_log_error( 'getimagesize failed for file: ' . $src );
}
}

Expand All @@ -752,8 +750,6 @@ function wpo_wcpdf_get_image_mime_type( string $src ): string {
if ( $finfo ) {
$mime_type = finfo_file( $finfo, $src );
finfo_close( $finfo );
} else {
wcpdf_log_error( 'Fileinfo failed to open for file: ' . $src );
}
}

Expand All @@ -777,11 +773,7 @@ function wpo_wcpdf_get_image_mime_type( string $src ): string {
if ( $headers ) {
if ( isset( $headers['Content-Type'] ) ) {
$mime_type = is_array( $headers['Content-Type'] ) ? $headers['Content-Type'][0] : $headers['Content-Type'];
} else {
wcpdf_log_error( 'Content-Type header not found for URL: ' . $src );
}
} else {
wcpdf_log_error( 'Failed to get headers for URL: ' . $src );
}
}

Expand All @@ -796,24 +788,16 @@ function wpo_wcpdf_get_image_mime_type( string $src ): string {
if ( $finfo ) {
$mime_type = finfo_buffer( $finfo, $image_data );
finfo_close( $finfo );
} else {
wcpdf_log_error( 'Fileinfo failed to open for buffer.' );
}
}
} else {
wcpdf_log_error( 'Failed to fetch image data for URL: ' . $src );
}
}

// Determine using WP functions
if ( empty( $mime_type ) ) {
$path = wp_parse_url( $src, PHP_URL_PATH );
$file_info = wp_check_filetype( $path );
$mime_type = $file_info['type'] ?? 'application/octet-stream';

if ( 'application/octet-stream' === $mime_type ) {
wcpdf_log_error( 'Unknown file extension for file: ' . $src );
}
$mime_type = $file_info['type'] ?? '';
}

// Last chance, determine from file extension
Expand Down Expand Up @@ -841,9 +825,6 @@ function wpo_wcpdf_get_image_mime_type( string $src ): string {
case 'svg':
$mime_type = 'image/svg+xml';
break;
default:
$mime_type = 'application/octet-stream';
wcpdf_log_error( 'Unknown file extension: ' . $extension . ' for file: ' . $src );
}
}

Expand Down

0 comments on commit 2a4233a

Please sign in to comment.