| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -namespace ImageOptimizer\Classes\Image; | |
| 3 | +namespace ImageOptimization\Classes\Image; | |
| 4 | 4 | |
| 5 | 5 | if ( ! defined( 'ABSPATH' ) ) { |
| 6 | 6 | exit; // Exit if accessed directly. |
| 7 | 7 | } |
| @@ -11,8 +11,9 @@ | ||
| 11 | 11 | private const INITIAL_META_VALUE = [ |
| 12 | 12 | 'status' => Image_Status::NOT_OPTIMIZED, |
| 13 | 13 | 'error_type' => null, |
| 14 | 14 | 'compression_level' => null, |
| 15 | + 'retry_count' => null, | |
| 15 | 16 | 'sizes_optimized' => [], |
| 16 | 17 | 'backups' => [], |
| 17 | 18 | 'original_data' => [ |
| 18 | 19 | 'sizes' => [], |
| @@ -51,14 +52,26 @@ | ||
| 51 | 52 | |
| 52 | 53 | return $this; |
| 53 | 54 | } |
| 54 | 55 | |
| 56 | + public function get_retry_count(): ?int { | |
| 57 | + return $this->image_meta['retry_count']; | |
| 58 | + } | |
| 59 | + | |
| 60 | + public function set_retry_count( ?int $retry_count ): Image_Meta { | |
| 61 | + $this->image_meta['retry_count'] = $retry_count; | |
| 62 | + | |
| 63 | + return $this; | |
| 64 | + } | |
| 65 | + | |
| 55 | 66 | public function get_optimized_sizes(): array { |
| 56 | 67 | return $this->image_meta['sizes_optimized']; |
| 57 | 68 | } |
| 58 | 69 | |
| 59 | 70 | public function add_optimized_size( string $optimized_size ): Image_Meta { |
| 60 | - $this->image_meta['sizes_optimized'][] = $optimized_size; | |
| 71 | + if ( ! in_array( $optimized_size, $this->image_meta['sizes_optimized'], true ) ) { | |
| 72 | + $this->image_meta['sizes_optimized'][] = $optimized_size; | |
| 73 | + } | |
| 61 | 74 | |
| 62 | 75 | return $this; |
| 63 | 76 | } |
| 64 | 77 | |
| @@ -67,8 +80,14 @@ | ||
| 67 | 80 | |
| 68 | 81 | return $this; |
| 69 | 82 | } |
| 70 | 83 | |
| 84 | + public function set_optimized_size( array $optimized_size ): Image_Meta { | |
| 85 | + $this->image_meta['sizes_optimized'] = $optimized_size; | |
| 86 | + | |
| 87 | + return $this; | |
| 88 | + } | |
| 89 | + | |
| 71 | 90 | public function clear_backups(): Image_Meta { |
| 72 | 91 | $this->image_meta['backups'] = []; |
| 73 | 92 | |
| 74 | 93 | return $this; |
| @@ -94,9 +113,9 @@ | ||
| 94 | 113 | return $this; |
| 95 | 114 | } |
| 96 | 115 | |
| 97 | 116 | public function get_original_file_size( string $image_size ): ?int { |
| 98 | - if ( ! isset( $this->image_meta['original_data']['sizes'][ $image_size ] ) ) { | |
| 117 | + if ( ! isset( $this->image_meta['original_data']['sizes'][ $image_size ]['filesize'] ) ) { | |
| 99 | 118 | return null; |
| 100 | 119 | } |
| 101 | 120 | |
| 102 | 121 | return $this->image_meta['original_data']['sizes'][ $image_size ]['filesize']; |