novafacile / novagallery

novaGallery - a beautiful and and ease to use php image gallery for your photos - flat file - no database required - modern responsive design
https://novagallery.org
GNU Affero General Public License v3.0
74 stars 11 forks source link

Album ordering malfunctions when album is composed solely of more albums #52

Open awong234 opened 7 months ago

awong234 commented 7 months ago

Problem

Album ordering is not as expected.

Issue

Albums that are composed solely of sub-albums (that is to say, the album does not have any direct image descendents) cannot extract a modification time, because it's expecting at least one image in the level below it.

Solution

Easiest way to get around this is just to keep at least one image in the album itself.

The logic for obtaining album $modDate should recursively access modification times to order albums if there do not exist any images in the level directly below it. I suspect it might be done here; https://github.com/novafacile/novagallery/blob/b14352f6cacf7ae0a9d15c0ca31d169c9c7fbbd4/src/nova-base/lib/novaGallery.php#L264

Instead of returning an empty string, it might dig down to the first album that has images as a direct descendant. I might work on this but again I'm not great at PHP so it would take me a little longer, and this seems like a relatively simple fix.

Details

I have debugged this issue by placing the following code in the nova-themes/novagallery/home.php file, around line 17:

<div class="col-12 col-sm-6 col-md-4 col-lg-3 mb-5 element">
  <a href="<?php echo Site::basePath().'/album/'.$elementPath; ?>">
    <img src="<?php echo Image::url($elementPath, $gallery->coverImage($element, $order), Site::config('imageSizeThumb')); ?>" loading="lazy" class="rounded"><br>
    <?php echo ucwords($element . " MOD: " . array_values($modDate)[0]); ?> <!-- <----------- added this line -->
  </a>
</div>

It displayed a missing $modDate for the out-of-order album:

image

I suspect when it goes to get array_values($images)[0], it is expecting that at least one of the values in the array is a timestamp. But if all the elements of the array are albums, then the value isn't a straight time-stamp value, it's a key-value array of more images. To test this theory, if I placed at least one image in the out-of-order album, then it should reflect a correct modification time -- and it does.

image

Notice the 2015 album now has a value for $modDate and is ordered correctly.

The logic here therefore should recursively access modification times to order albums if there do not exist any images in the level directly below it.

david-novafacile commented 7 months ago

Thank you very much for the detailed bug research and for supporting novaGallery!

:+1: :+1:

This should be fixed and is on the roadmap now!