PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
← All changes | inc/3rd-party/nextgen-gallery/classes/Media/NGG.php +34 -12 2.2.8 → trunk View file →
@@ -80,18 +80,24 @@
80 80
81 81 // NGG storage.
82 82 if ( ! empty( $this->image->_ngiw ) ) {
83 83 $this->storage = $this->image->_ngiw->get_storage()->object;
84 - } else {
84 + // @codeCoverageIgnoreStart — requires live NGG v3 POPE classes or NGGFOLDER constant; not available in unit tests.
85 + } elseif ( imagify_ngg_has_pope_storage() ) {
86 + // C_Gallery_Storage is part of the NGG v3 POPE framework; absent on v4.
85 87 $this->storage = \C_Gallery_Storage::get_instance()->object;
86 88 }
89 + // else: $this->storage remains null on NGG v4 (no _ngiw and no POPE framework).
87 90
88 - // Load nggAdmin class.
89 - $ngg_admin_functions_path = WP_PLUGIN_DIR . '/' . NGGFOLDER . '/products/photocrati_nextgen/modules/ngglegacy/admin/functions.php';
91 + // Load nggAdmin class (NGGFOLDER may be undefined on NGG v4).
92 + if ( defined( 'NGGFOLDER' ) && ! class_exists( 'nggAdmin' ) ) {
93 + $ngg_admin_functions_path = WP_PLUGIN_DIR . '/' . NGGFOLDER . '/products/photocrati_nextgen/modules/ngglegacy/admin/functions.php';
90 94
91 - if ( ! class_exists( 'nggAdmin' ) && $this->filesystem->exists( $ngg_admin_functions_path ) ) {
92 - require_once $ngg_admin_functions_path;
95 + if ( $this->filesystem->exists( $ngg_admin_functions_path ) ) {
96 + require_once $ngg_admin_functions_path;
97 + }
93 98 }
99 + // @codeCoverageIgnoreEnd
94 100 }
95 101
96 102 /**
97 103 * Tell if the given entry can be accepted in the constructor.
@@ -177,9 +183,9 @@
177 183 /** FULL SIZE FILE ========================================================================== */
178 184 /** ----------------------------------------------------------------------------------------- */
179 185
180 186 /**
181 - * Get the URL of the media’s full size file.
187 + * Get the URL of the media's full size file.
182 188 *
183 189 * @since 1.9.8
184 190 * @access public
185 191 * @author Grégory Viguier
@@ -198,9 +204,9 @@
198 204 return ! empty( $this->image->imageURL ) ? $this->image->imageURL : false;
199 205 }
200 206
201 207 /**
202 - * Get the path to the media’s full size file, even if the file doesn't exist.
208 + * Get the path to the media's full size file, even if the file doesn't exist.
203 209 *
204 210 * @since 1.9.8
205 211 * @access public
206 212 * @author Grégory Viguier
@@ -276,8 +282,14 @@
276 282 if ( ! $this->is_valid() ) {
277 283 return new \WP_Error( 'invalid_media', __( 'This media is not valid.', 'imagify' ) );
278 284 }
279 285
286 + // @codeCoverageIgnoreStart — requires live NGG storage; not available in unit tests.
287 + if ( null === $this->storage ) {
288 + return new \WP_Error( 'no_ngg_storage', __( 'NextGen Gallery storage is not available.', 'imagify' ) );
289 + }
290 + // @codeCoverageIgnoreEnd
291 +
280 292 $image_data = $this->storage->_image_mapper->find( $this->get_id() );
281 293
282 294 if ( ! $image_data ) {
283 295 return new \WP_Error( 'no_ngg_image', __( 'Image not found in NextGen Gallery data.', 'imagify' ) );
@@ -336,11 +348,15 @@
336 348
337 349 $image_data->meta_data[ $size_name ] = $size_meta;
338 350 }
339 351
340 - // Keep our property up to date.
341 - $this->image->_ngiw->_cache['meta_data'] = $image_data->meta_data;
342 - $this->image->_ngiw->_orig_image = $image_data;
352 + // Keep our property up to date (defensively guard _ngiw in case it is absent).
353 + // @codeCoverageIgnoreStart — requires live NGG _ngiw storage object; not available in unit tests.
354 + if ( isset( $this->image->_ngiw ) ) {
355 + $this->image->_ngiw->_cache['meta_data'] = $image_data->meta_data;
356 + $this->image->_ngiw->_orig_image = $image_data;
357 + }
358 + // @codeCoverageIgnoreEnd
343 359
344 360 $post_id = $this->storage->_image_mapper->save( $image_data );
345 361
346 362 if ( ! $post_id ) {
@@ -400,9 +416,9 @@
400 416 * @type string $path Absolute path to the file.
401 417 * @type int $width The file width.
402 418 * @type int $height The file height.
403 419 * @type string $mime-type The file mime type.
404 - * @type bool $disabled True if the size is disabled in the plugin’s settings.
420 + * @type bool $disabled True if the size is disabled in the plugin's settings.
405 421 * }
406 422 */
407 423 public function get_media_files() {
408 424 if ( ! $this->is_valid() ) {
@@ -432,9 +448,9 @@
432 448 }
433 449
434 450 // Remove common values (that have no value for us here, lol). Also remove 'full' and 'backup'.
435 451 $image_data = array_diff_key(
436 - $this->image->meta_data,
452 + is_array( $this->image->meta_data ) ? $this->image->meta_data : [],
437 453 [
438 454 'full' => 1,
439 455 'backup' => 1,
440 456 'width' => 1,
@@ -458,8 +474,14 @@
458 474
459 475 if ( ! $image_data ) {
460 476 return $this->filter_media_files( $all_sizes );
461 477 }
478 +
479 + // @codeCoverageIgnoreStart — requires live NGG storage; not available in unit tests.
480 + if ( null === $this->storage ) {
481 + return $this->filter_media_files( $all_sizes );
482 + }
483 + // @codeCoverageIgnoreEnd
462 484
463 485 $ngg_data = $this->storage->_image_mapper->find( $this->get_id() );
464 486
465 487 foreach ( $image_data as $size => $size_data ) {