Skip to content

Commit

Permalink
Merge branch 'develop' into uat
Browse files Browse the repository at this point in the history
  • Loading branch information
pereirinha committed Nov 19, 2024
2 parents 626e396 + 31bf160 commit c897b7a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
20 changes: 7 additions & 13 deletions php/class-media.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,22 +356,16 @@ public function maybe_file_exist_in_url( $url ) {
if ( ! filter_var( $url, FILTER_VALIDATE_URL ) ) {
return false;
}
// phpcs:disable WordPress.WP.AlternativeFunctions
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_NOBODY, true );
curl_exec( $ch );
$code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );

if ( 200 === $code ) {
$status = true;
} else {
$status = false;

$head = wp_safe_remote_head( $url );

if ( is_wp_error( $head ) ) {
return false;
}

curl_close( $ch );
// phpcs:enable
$code = wp_remote_retrieve_response_code( $head );

return $status;
return 200 === $code;
}

/**
Expand Down
8 changes: 7 additions & 1 deletion php/relate/class-relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,17 @@ public function flush_cache() {
* @param array $post_ids The post ids.
*/
public static function preload( $post_ids ) {
// Check if the post_ids are objects.
$maybe_ids = array_column( $post_ids, 'ID' );
if ( ! empty( $maybe_ids ) ) {
// If so, make sure to just use the IDs.
$post_ids = $maybe_ids;
}
global $wpdb;
$table_name = Utils::get_relationship_table();
// Do the public_ids.
$list = implode( ', ', array_fill( 0, count( $post_ids ), '%d' ) );
$where = "post_id IN( {$list} )";
$where = "post_id IN ( {$list} )";

$sql = $wpdb->prepare( "SELECT * FROM {$table_name} WHERE {$where}", $post_ids ); // phpcs:ignore WordPress.DB
$posts = $wpdb->get_results( $sql, ARRAY_A ); // phpcs:ignore WordPress.DB
Expand Down
10 changes: 5 additions & 5 deletions php/sync/class-sync-queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,18 +394,18 @@ public function get_total_synced_media() {
$return = array(
// Original sizes.
'original_size' => $total_local_size,
'original_size_percent' => '100%', // The original will always be 100%, as it's the comparison to optimized.
'original_size_percent' => 0 !== $total_assets ? '100%' : '0%', // The original will always be 100%, as it's the comparison to optimized.
'original_size_hr' => size_format( $total_local_size ),

// Optimized size. We use the `original_size` to determine the percentage between for the progress bar.
'optimized_size' => $total_remote_size,
'optimized_size_percent' => round( abs( $total_remote_size ) / abs( $total_local_size ) * 100 ) . '%', // This is the percentage difference.
'optimized_diff_percent' => round( ( $total_local_size - $total_remote_size ) / $total_local_size * 100 ) . '%', // We use this for the "Size saved.." status text.
'optimized_size_percent' => $total_local_size > 0 ? round( abs( $total_remote_size ) / abs( $total_local_size ) * 100 ) . '%' : '0%', // This is the percentage difference.
'optimized_diff_percent' => $total_local_size > 0 ? round( ( $total_local_size - $total_remote_size ) / $total_local_size * 100 ) . '%' : '0%', // We use this for the "Size saved.." status text.
'optimized_size_hr' => size_format( $total_remote_size ), // This is the formatted byte size.

// Optimized is the % optimized vs unoptimized.
'optimized_percent' => round( $total_optimized / $total_assets, 4 ),
'optimized_percent_hr' => round( $total_optimized / $total_assets * 100, 1 ) . '%',
'optimized_percent' => $total_assets > 0 ? round( $total_optimized / $total_assets, 4 ) : 0,
'optimized_percent_hr' => $total_assets > 0 ? round( $total_optimized / $total_assets * 100, 1 ) . '%' : '0%',
'optimized_info' => __( 'Optimized assets', 'cloudinary' ),

// Error size: No mockups on what to display here.
Expand Down

0 comments on commit c897b7a

Please sign in to comment.