| @@ -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 | } |
| @@ -9,9 +9,11 @@ | ||
| 9 | 9 | class Image_Meta { |
| 10 | 10 | public const IMAGE_OPTIMIZER_METADATA_KEY = 'image_optimizer_metadata'; |
| 11 | 11 | private const INITIAL_META_VALUE = [ |
| 12 | 12 | 'status' => Image_Status::NOT_OPTIMIZED, |
| 13 | + 'error_type' => null, | |
| 13 | 14 | 'compression_level' => null, |
| 15 | + 'retry_count' => null, | |
| 14 | 16 | 'sizes_optimized' => [], |
| 15 | 17 | 'backups' => [], |
| 16 | 18 | 'original_data' => [ |
| 17 | 19 | 'sizes' => [], |
| @@ -30,8 +32,18 @@ | ||
| 30 | 32 | |
| 31 | 33 | return $this; |
| 32 | 34 | } |
| 33 | 35 | |
| 36 | + public function get_error_type(): ?string { | |
| 37 | + return $this->image_meta['error_type']; | |
| 38 | + } | |
| 39 | + | |
| 40 | + public function set_error_type( ?string $type ): Image_Meta { | |
| 41 | + $this->image_meta['error_type'] = $type; | |
| 42 | + | |
| 43 | + return $this; | |
| 44 | + } | |
| 45 | + | |
| 34 | 46 | public function get_compression_level(): ?string { |
| 35 | 47 | return $this->image_meta['compression_level']; |
| 36 | 48 | } |
| 37 | 49 | |
| @@ -40,14 +52,26 @@ | ||
| 40 | 52 | |
| 41 | 53 | return $this; |
| 42 | 54 | } |
| 43 | 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 | + | |
| 44 | 66 | public function get_optimized_sizes(): array { |
| 45 | 67 | return $this->image_meta['sizes_optimized']; |
| 46 | 68 | } |
| 47 | 69 | |
| 48 | 70 | public function add_optimized_size( string $optimized_size ): Image_Meta { |
| 49 | - $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 | + } | |
| 50 | 74 | |
| 51 | 75 | return $this; |
| 52 | 76 | } |
| 53 | 77 | |
| @@ -56,8 +80,20 @@ | ||
| 56 | 80 | |
| 57 | 81 | return $this; |
| 58 | 82 | } |
| 59 | 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 | + | |
| 90 | + public function clear_backups(): Image_Meta { | |
| 91 | + $this->image_meta['backups'] = []; | |
| 92 | + | |
| 93 | + return $this; | |
| 94 | + } | |
| 95 | + | |
| 60 | 96 | public function get_image_backup_paths(): array { |
| 61 | 97 | return $this->image_meta['backups']; |
| 62 | 98 | } |
| 63 | 99 | |
| @@ -77,9 +113,9 @@ | ||
| 77 | 113 | return $this; |
| 78 | 114 | } |
| 79 | 115 | |
| 80 | 116 | public function get_original_file_size( string $image_size ): ?int { |
| 81 | - if ( ! isset( $this->image_meta['original_data']['sizes'][ $image_size ] ) ) { | |
| 117 | + if ( ! isset( $this->image_meta['original_data']['sizes'][ $image_size ]['filesize'] ) ) { | |
| 82 | 118 | return null; |
| 83 | 119 | } |
| 84 | 120 | |
| 85 | 121 | return $this->image_meta['original_data']['sizes'][ $image_size ]['filesize']; |