novafacile / bludit-plugins

Plugins for Bludit CMS - https://bludit-plugins.com | Contact3 - the contact form for Bludit CMS | ImageGallery - the image gallery for Bludit CMS | Online Store Plugin für Bludit
https://bludit-plugins.com
MIT License
16 stars 5 forks source link

Arbitary sorting of images on upload #35

Open apps4research opened 2 years ago

apps4research commented 2 years ago

I have a very weird problem! The default sorting of images in my ImageGallery Pro is "newest first" and the setting for the albums is typically left to "default". I have one particular album on my clients laptop, were the images seem to sort themselves arbitrarily after upload. Typically, the newest image is not first but last, but sometimes a newly uploaded image is placed somewhere in between. The sorting of the albums themselves in the admin area, when set to "newest" is also not correct.

Also, if I change the sorting for the particular album that is causing problem, then I can see that the images change their order in dem admin area, but the sorting does not change on the website itself.

apps4research commented 2 years ago

Update, I was able to fix the sorting on the public page ... I changed in the plugin.php (around line 485)

from:

if($config['albumSettings'][$album]['sort'] != 'default'){
    $imagesSort = $config['albumSettings'][$album]['sort'];
}
$images = $gallery->images($album, $config['imagesSort']);

to:

if($config['albumSettings'][$album]['sort'] != 'default'){
    $imagesSort = $config['albumSettings'][$album]['sort'];
} else { 
    $imagesSort = $this->getValue('default-image-sort');
}     
$images = $gallery->images($album, $imagesSort);

Now, when I change the sorting of an album in the admin area, the sorting also changes on the publicly visible album page. Thus it seems that the sorting variable is not properly defined ... I would guess its the same for the album sorting, but I still have to investigate that.

Still no idea why my clients upload sorting is weird (I can't seem to replicate the weird sorting after upload) ... If I get somewhere I'll post it here.

david-novafacile commented 2 years ago

Hi,

thank you very much for the bug report and directly provided bug fix. :-)

The sorting of the images is done based on the creation date in the exif data of the image. If this data is missing, the last file modification date is used. If some files have EXIF data and some don't, then the sorting gets messed up.

Could it be because there are images that are with and with no exif data?

Regards David

apps4research commented 2 years ago

Ahh, yes, thanks David ... I saw now after reading your comment that it even states that in the admin center in the sorting settings. I had just presumed that it was using the upload timestamp. The images my client used did have exif data, but they sent them to me via telegram which striped the exif data and so I had different effects than they did and just couldnt replicate the problem.

Anyway, the behaviour is unfortunately not what my client needs. They really do want the last uploaded images (for example) to be first if the setting is set to "newest".

david-novafacile commented 2 years ago

That would be a good feature. I will see how I can include this in the next update. The sorting of the files is in the integrated script novaGallery (located in the vendor folder), which also exists as a separate product. So I have to integrate this feature there, so that it can be used in Bludit. With this I want to say: This takes some time to avoid side effects in the other projects, which also use novaGallery in the core.

Until then, a workaround could be to remove the EXIF data before upload or you disable reading the EXIF data in the /bl-plugins/imagegallery-pro/vendors/novaGallery.php file.

e.g. add in line 71: return filemtime($file);

But test before if this really works, this is just a quick untested idea ;-)

With this you disable the complete EXIF check. If it should be only for a certain album, you could restrict it with a preg_match to the album or the associated file folder.

apps4research commented 2 years ago

Brilliant, thank you. Also thanks for the info, which saves me some time ... I'll give it a try and will report back :)

Update: Works perfectly :)