| 1 |
<?php |
| 2 |
namespace Imagify\Optimization\Data; |
| 3 |
|
| 4 |
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' ); |
| 5 |
|
| 6 |
/** |
| 7 |
* Fallback class optimization data of "media groups" (aka attachments). |
| 8 |
* |
| 9 |
* @since 1.9 |
| 10 |
* @author Grégory Viguier |
| 11 |
*/ |
| 12 |
class Noop implements DataInterface { |
| 13 |
|
| 14 |
/** |
| 15 |
* Tell if the given entry can be accepted in the constructor. |
| 16 |
* For example it can include `is_numeric( $id )` if the constructor accepts integers. |
| 17 |
* |
| 18 |
* @since 1.9 |
| 19 |
* @access public |
| 20 |
* @author Grégory Viguier |
| 21 |
* |
| 22 |
* @param mixed $id Whatever. |
| 23 |
* @return bool |
| 24 |
*/ |
| 25 |
public static function constructor_accepts( $id ) { |
| 26 |
return false; |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Get the media instance. |
| 31 |
* |
| 32 |
* @since 1.9 |
| 33 |
* @access public |
| 34 |
* @author Grégory Viguier |
| 35 |
* |
| 36 |
* @return MediaInterface|false |
| 37 |
*/ |
| 38 |
public function get_media() { |
| 39 |
return false; |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Tell if the current media is valid. |
| 44 |
* |
| 45 |
* @since 1.9 |
| 46 |
* @access public |
| 47 |
* @author Grégory Viguier |
| 48 |
* |
| 49 |
* @return bool |
| 50 |
*/ |
| 51 |
public function is_valid() { |
| 52 |
return false; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
/** ----------------------------------------------------------------------------------------- */ |
| 57 |
/** OPTIMIZATION DATA ======================================================================= */ |
| 58 |
/** ----------------------------------------------------------------------------------------- */ |
| 59 |
|
| 60 |
/** |
| 61 |
* Check if the main file is optimized (by Imagify). |
| 62 |
* |
| 63 |
* @since 1.9 |
| 64 |
* @access public |
| 65 |
* @author Grégory Viguier |
| 66 |
* |
| 67 |
* @return bool True if the media is optimized. |
| 68 |
*/ |
| 69 |
public function is_optimized() { |
| 70 |
return false; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Check if the main file is optimized (NOT by Imagify). |
| 75 |
* |
| 76 |
* @since 1.9 |
| 77 |
* @access public |
| 78 |
* @author Grégory Viguier |
| 79 |
* |
| 80 |
* @return bool True if the media is optimized. |
| 81 |
*/ |
| 82 |
public function is_already_optimized() { |
| 83 |
return false; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Check if the main file is optimized (by Imagify). |
| 88 |
* |
| 89 |
* @since 1.9 |
| 90 |
* @access public |
| 91 |
* @author Grégory Viguier |
| 92 |
* |
| 93 |
* @return bool True if the media is optimized. |
| 94 |
*/ |
| 95 |
public function is_error() { |
| 96 |
return false; |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Get the whole media optimization data. |
| 101 |
* |
| 102 |
* @since 1.9 |
| 103 |
* @access public |
| 104 |
* @author Grégory Viguier |
| 105 |
* |
| 106 |
* @return array The data. See parent method for details. |
| 107 |
*/ |
| 108 |
public function get_optimization_data() { |
| 109 |
return [ |
| 110 |
'status' => '', |
| 111 |
'level' => false, |
| 112 |
'sizes' => [], |
| 113 |
'stats' => [ |
| 114 |
'original_size' => 0, |
| 115 |
'optimized_size' => 0, |
| 116 |
'percent' => 0, |
| 117 |
], |
| 118 |
]; |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Update the optimization data, level, and status for a size. |
| 123 |
* |
| 124 |
* @since 1.9 |
| 125 |
* @access public |
| 126 |
* @author Grégory Viguier |
| 127 |
* |
| 128 |
* @param string $size The size name. |
| 129 |
* @param array $data The optimization data. See parent method for details. |
| 130 |
*/ |
| 131 |
public function update_size_optimization_data( $size, array $data ) {} |
| 132 |
|
| 133 |
/** |
| 134 |
* Delete the media optimization data, level, and status. |
| 135 |
* |
| 136 |
* @since 1.9 |
| 137 |
* @access public |
| 138 |
* @author Grégory Viguier |
| 139 |
*/ |
| 140 |
public function delete_optimization_data() {} |
| 141 |
|
| 142 |
/** |
| 143 |
* Delete the optimization data for the given sizes. |
| 144 |
* If all sizes are removed, all optimization data is deleted. |
| 145 |
* Status and level are not modified nor removed if the "full" size is removed. This leaves the media in a Schrödinger state. |
| 146 |
* |
| 147 |
* @since 1.9.8 |
| 148 |
* @access public |
| 149 |
* @author Grégory Viguier |
| 150 |
* |
| 151 |
* @param array $sizes A list of sizes to remove. |
| 152 |
*/ |
| 153 |
public function delete_sizes_optimization_data( array $sizes ) {} |
| 154 |
|
| 155 |
/** |
| 156 |
* Get the media's optimization level. |
| 157 |
* |
| 158 |
* @since 1.9 |
| 159 |
* @access public |
| 160 |
* @author Grégory Viguier |
| 161 |
* |
| 162 |
* @return int|bool The optimization level. False if not optimized. |
| 163 |
*/ |
| 164 |
public function get_optimization_level() { |
| 165 |
return false; |
| 166 |
} |
| 167 |
|
| 168 |
/** |
| 169 |
* Get the media's optimization status (success or error). |
| 170 |
* |
| 171 |
* @since 1.9 |
| 172 |
* @access public |
| 173 |
* @author Grégory Viguier |
| 174 |
* |
| 175 |
* @return string The optimization status. An empty string if there is none. |
| 176 |
*/ |
| 177 |
public function get_optimization_status() { |
| 178 |
return ''; |
| 179 |
} |
| 180 |
|
| 181 |
/** |
| 182 |
* Count number of optimized sizes. |
| 183 |
* |
| 184 |
* @since 1.9 |
| 185 |
* @access public |
| 186 |
* @author Grégory Viguier |
| 187 |
* |
| 188 |
* @return int Number of optimized sizes. |
| 189 |
*/ |
| 190 |
public function get_optimized_sizes_count() { |
| 191 |
return 0; |
| 192 |
} |
| 193 |
|
| 194 |
/** |
| 195 |
* Get the original media's size (weight). |
| 196 |
* |
| 197 |
* @since 1.9 |
| 198 |
* @access public |
| 199 |
* @author Grégory Viguier |
| 200 |
* |
| 201 |
* @param bool $human_format True to display the image human format size (1Mb). |
| 202 |
* @param int $decimals Precision of number of decimal places. |
| 203 |
* @return string|int |
| 204 |
*/ |
| 205 |
public function get_original_size( $human_format = true, $decimals = 2 ) { |
| 206 |
return $human_format ? imagify_size_format( 0, $decimals ) : 0; |
| 207 |
} |
| 208 |
|
| 209 |
/** |
| 210 |
* Get the file size of the full size file. |
| 211 |
* If the WebP size is available, it is used. |
| 212 |
* |
| 213 |
* @since 1.9 |
| 214 |
* @access public |
| 215 |
* @author Grégory Viguier |
| 216 |
* |
| 217 |
* @param bool $human_format True to display the image human format size (1Mb). |
| 218 |
* @param int $decimals Precision of number of decimal places. |
| 219 |
* @param bool $use_webp Use the WebP size if available. |
| 220 |
* @return string|int |
| 221 |
*/ |
| 222 |
public function get_optimized_size( $human_format = true, $decimals = 2, $use_webp = true ) { |
| 223 |
return $human_format ? imagify_size_format( 0, $decimals ) : 0; |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
/** ----------------------------------------------------------------------------------------- */ |
| 228 |
/** OPTIMIZATION STATS ====================================================================== */ |
| 229 |
/** ----------------------------------------------------------------------------------------- */ |
| 230 |
|
| 231 |
/** |
| 232 |
* Get one or all statistics of a specific size. |
| 233 |
* |
| 234 |
* @since 1.9 |
| 235 |
* @access public |
| 236 |
* @author Grégory Viguier |
| 237 |
* |
| 238 |
* @param string $size The thumbnail slug. |
| 239 |
* @param string $key The specific data slug. |
| 240 |
* @return array|string |
| 241 |
*/ |
| 242 |
public function get_size_data( $size = 'full', $key = '' ) { |
| 243 |
return $key ? '' : []; |
| 244 |
} |
| 245 |
|
| 246 |
/** |
| 247 |
* Get the overall statistics data or a specific one. |
| 248 |
* |
| 249 |
* @since 1.9 |
| 250 |
* @access public |
| 251 |
* @author Grégory Viguier |
| 252 |
* |
| 253 |
* @param string $key The specific data slug. |
| 254 |
* @return array|string |
| 255 |
*/ |
| 256 |
public function get_stats_data( $key = '' ) { |
| 257 |
return $key ? '' : []; |
| 258 |
} |
| 259 |
|
| 260 |
/** |
| 261 |
* Get the optimized/original saving of the original image in percent. |
| 262 |
* |
| 263 |
* @since 1.9 |
| 264 |
* @access public |
| 265 |
* @author Grégory Viguier |
| 266 |
* |
| 267 |
* @return float A 2-decimals float. |
| 268 |
*/ |
| 269 |
public function get_saving_percent() { |
| 270 |
return round( (float) 0, 2 ); |
| 271 |
} |
| 272 |
|
| 273 |
/** |
| 274 |
* Get the overall optimized/original saving (original image + all thumbnails) in percent. |
| 275 |
* |
| 276 |
* @since 1.9 |
| 277 |
* @access public |
| 278 |
* @author Grégory Viguier |
| 279 |
* |
| 280 |
* @return float A 2-decimals float. |
| 281 |
*/ |
| 282 |
public function get_overall_saving_percent() { |
| 283 |
return round( (float) 0, 2 ); |
| 284 |
} |
| 285 |
} |
| 286 |
|