'count_unsmushed' => $unsmushed_count, 'resmush' => array(), 'count_resmush' => $resmush_count, 'size_before' => (int) $array_utils->get_array_value( $stats, 'size_before' ), 'size_after' => (int) $array_utils->get_array_value( $stats, 'size_after' ), 'savings_bytes' => $bytes, 'human_bytes' => $human_bytes, 'savings_resize' => $resize_savings, 'savings_resize_human' => $resize_savings_human, 'savings_conversion' => $conversion_savings, 'savings_conversion_human'=> $conversion_savings_human, 'savings_dir_smush' => $this->dir_stats, 'savings_percent' => $savings_percent > 0 ? number_format_i18n( $savings_percent, 1 ) : 0, 'percent_grade' => $grade, 'percent_metric' => $percent_metric, 'percent_optimized' => $percent_optimized, 'remaining_count' => $remaining_count, ); } /** * Returns an array that can be consumed by the JS * * TODO: When we have rewritten the frontend of the plugin we can directly use {@see Global_Stats::to_array()} instead * * @return array */ public function get_global_stats() { $global_stats = Global_Stats::get(); if ( empty( $global_stats->get_stats_update_started_timestamp() ) ) { // A scan was never started, use the old stats return $this->get_backup_global_stats(); } $total_stats = $global_stats->get_sum_of_optimization_global_stats(); /** * @var $smush_stats Smush_Optimization_Global_Stats */ $smush_stats = $global_stats->get_persistable_stats_for_optimization( Smush_Optimization::get_key() ) ->get_stats(); $resize_stats = $global_stats->get_persistable_stats_for_optimization( Resize_Optimization::get_key() ) ->get_stats(); $png2jpg_stats = $global_stats->get_persistable_stats_for_optimization( Png2Jpg_Optimization::get_key() ) ->get_stats(); return array( 'stats_updated_timestamp' => $global_stats->get_stats_updated_timestamp(), 'is_outdated' => $global_stats->is_outdated(), 'count_supersmushed' => $smush_stats->get_lossy_count(), 'count_smushed' => $smush_stats->get_count(), 'count_total' => $global_stats->get_total_optimizable_items_count(), 'count_images' => $global_stats->get_optimized_images_count(), 'count_resize' => $resize_stats->get_count(), 'count_skipped' => $global_stats->get_skipped_count(), 'unsmushed' => $global_stats->get_optimize_list()->get_ids(), 'count_unsmushed' => $global_stats->get_optimize_list()->get_count(), 'resmush' => $global_stats->get_redo_ids(), 'count_resmush' => $global_stats->get_redo_count(), 'size_before' => $total_stats->get_size_before(), 'size_after' => $total_stats->get_size_after(), 'savings_bytes' => $total_stats->get_bytes(), 'human_bytes' => $total_stats->get_human_bytes(), 'savings_resize' => $resize_stats->get_bytes(), 'savings_resize_human' => $resize_stats->get_human_bytes(), 'savings_conversion' => $png2jpg_stats->get_bytes(), 'savings_conversion_human' => $png2jpg_stats->get_human_bytes(), 'savings_dir_smush' => $this->dir_stats, 'savings_percent' => $total_stats->get_percent() > 0 ? number_format_i18n( $total_stats->get_percent(), 1 ) : 0, 'percent_grade' => $global_stats->get_grade_class(), 'percent_metric' => $global_stats->get_percent_metric(), 'percent_optimized' => $global_stats->get_percent_optimized(), 'remaining_count' => $global_stats->get_remaining_count(), ); } /** * @return int */ public function get_query_limit() { return $this->query_limit; } /** * @param int $query_limit */ public function set_query_limit( $query_limit ) { $this->query_limit = $query_limit; return $this; } /** * @return int */ public function get_max_rows() { return $this->max_rows; } /** * @param int $max_rows */ public function set_max_rows( $max_rows ) { $this->max_rows = $max_rows; return $this; } /** * Get grade data (percent optimized and class name) for the score widget in summary meta box. * * @return array * @since 3.12.0 Moved it from Abstract_Summary_Page for reuse. * * @since 3.10.0 * */ public function get_grade_data( $total_images_to_smush, $total_count, $skipped_count ) { $total_images = $total_count - $skipped_count; $percent_optimized = 0; if ( 0 === $total_images ) { $grade = 'sui-grade-dismissed'; } elseif ( $total_images === $total_images_to_smush ) { $grade = 'sui-grade-f'; } else { $percent_optimized = floor( ( $total_images - $total_images_to_smush ) * 100 / $total_images ); $grade = 'sui-grade-f'; if ( $percent_optimized >= 60 && $percent_optimized < 90 ) { $grade = 'sui-grade-c'; } elseif ( $percent_optimized >= 90 ) { $grade = 'sui-grade-a'; } } // Don't let percentage go beyond 100 or less than 0 if ( $percent_optimized > 100 ) { $percent_optimized = 100; } elseif ( $percent_optimized < 0 ) { $percent_optimized = 0; } return array( $percent_optimized, 0.0 === (float) $percent_optimized ? 100 : $percent_optimized, $grade, ); } /** * Get resmush ids. * * @return array */ public function get_resmush_ids() { if ( $this->resmush_ids ) { return $this->resmush_ids; } return (array) get_option( 'wp-smush-resmush-list', array() ); } }