Pages (2): 1 2   
Member
Member
mkanoute   23-06-2021, 03:09
#1

Hello,
I just upgraded from 1.5.7 to 1.5.8 and sorting of images in albums seems broken: next_image() now returns images out of order (I have a custom theme bu it has been working for years, upgraded after upgraded). The expected order is by date descending. It was working until 1.5.7. Could it be related to the use of a context?

Regards,
Mahamane

Member
Member
mkanoute   23-06-2021, 04:18
#2

Trying do debug what is going on: does not seem related to contextes. Album.getImages() does not return the images in the right order.

Member
Member
mkanoute   23-06-2021, 04:42
#3

The problem seems to be in functions.php, sortByKey().
For sorttype=date sortdirection=DESC
Album.sortImageArray() gets the data in the right order from the DB. It turns out that the images name include the date and time, making debuging easier (format=YYMMDD_HHMMSS) =>
{15894:Wed, 23 Jun 2021 04:32:33 GMT}
Album.sortImageArray(): filename=210622_150417_geraniums.jpg
{15894:Wed, 23 Jun 2021 04:32:33 GMT}
Album.sortImageArray(): filename=210607_191609_camelia.jpg
{15894:Wed, 23 Jun 2021 04:32:33 GMT}
Album.sortImageArray(): filename=210607_182848_clematite.jpg
{15894:Wed, 23 Jun 2021 04:32:33 GMT}
Album.sortImageArray(): filename=210607_182727_camelia.jpg
{15894:Wed, 23 Jun 2021 04:32:33 GMT}
Album.sortImageArray(): filename=210607_173926_clematite.jpg
{15894:Wed, 23 Jun 2021 04:32:33 GMT}
The records are storeds in the array $results.

Then $results is sorted by
$results = sortByKey($results, str_replace('`', '', $sortkey), $order);
and then $results is no longer sorted correctly.

Member
Member
mkanoute   23-06-2021, 04:59
#4

Digging further, the problem occurs when calling sortMultiArray() with $natsort = true
Called with false in sortByKey() solves the issue:
$results = sortMultiArray($results, $indicies, $order, true, false, true); -> does not work
$results = sortMultiArray($results, $indicies, $order, false, false, true); -> works

Administrator
Administrator
acrylian   23-06-2021, 07:34
#5

Thanks for investigating. The array sroting has indeed been extended to use "real natural" order if the Collator class is available on your system. The oder especially on non English terms may otherwise not be correct without it as plain PHP natsort does not cover it. I am not sure why this would affect sorting by filename actually.

In any case we will try to reproduce it.

But please tell iif your system has the Collator class available (https://www.php.net/manual/de/class.collator.php)? Because the sorting behaviour is different with and without even for "normal" strings. Sorting by date should also work with it but perhaps it needs an exception for date sorting to use the "standard" natsort.

Member
Member
mkanoute   23-06-2021, 18:14
#6

Thanks for looking into this.
Yes, the class Collator exists on my system (I can instantiate it as in new Collator('en_US'); for example)

Administrator
Administrator
acrylian   23-06-2021, 18:18
#7

It is really weird, so far we cannot reproduce any issue with sorting by date (the date stored in the database).

You mention filenames like 210622_150417_geraniums.jpg. Are you perhaps actually sorting by filename. Those numbers would not really work as date sorting, it would have to be internation format YYYY-MM-DD to work properly as "strings".

Member
Member
mkanoute   23-06-2021, 20:39
#8

As shown above, sorttype=date sortdirection=DESC. Could it be the descendant direction the issue?

Administrator
Administrator
acrylian   24-06-2021, 06:16
#9

It should not, we'll try to reproduce.

Administrator
Administrator
acrylian   24-06-2021, 09:10
#10

I am sorry; I tried again and image sorting by date ascending and descending does work for me as intended (with Collator class as well).

Be sure no cache plays tricks on you, e.g. visit the site loggedin and clear your browser cache by force. The latter is very persistent in almost all browsers and a constant source of confusion.

Member
Member
mkanoute   24-06-2021, 16:50
#11

It is not a browser cache issue.

I will keep my code change. Thanks for looking at it.

Administrator
Administrator
acrylian   24-06-2021, 17:18
#12

Are you doing something specific somehow?I tried with a standard album image thumb page and here all worked.

Member
Member
J_C   24-06-2021, 21:13
#13

I just added three videos, after updating to 1.5.8 from 1.5.7 the other day, and noticed that sorting by filename is now broken for me after the update. I’m on PHP version 7.4.20.

Member
Member
steam4m   25-06-2021, 05:45
#14

I came here to report the same issue that's appeared after upgrade to 1.5.8 (to solve missing metadata with Multiverse bug!).

Sorting by date is broken across albums that haven't been touched for months (eg https://gallery.steam4me.net/index.php?album=trams/2020) but tried sorting by filename (eg https://gallery.steam4me.net/index.php?album=trams/2021) and that seems to be working ok.

Administrator
Administrator
acrylian   25-06-2021, 07:06
#15

@J_C: Example please, especially what filenames you are using. The Collator class does realy natural ordering if available which is a bit different from the standard natural order PHP provides. That was actualyl raelly wrong for especially some languages (e.g. umauts in my native language German).

@steam4m: I can only tell that I cannot reproduce any issue with sorting by date.

In any case we always need the info if your system supports the collator class or not as that is cruical to investigate anything. Review phpinfo if the intl PHP extension is available or re-run setup to see if it is noted as not available.

Administrator
Administrator
acrylian   25-06-2021, 07:29
#16

All right, I can reproduce the issue now. What does not work is the setting "Options -> Gallery -> Sort gallery by" while the individual setting on an album does.

Please verify this.

COnfused my self, need more coffee…, of course setting album sorting does not work on images ;-)

Opions -> Image -> Sort images by is the global setting and that also works for me as intended.

Sorry guys…

Administrator
Administrator
acrylian   25-06-2021, 08:18
#17

I should point out that all tests so far are done with Collator class support. Neither me nor @fretzl can reproduce your isssues so far.

Member
Member
J_C   25-06-2021, 08:28
#18

Here’s the subalbum I first noticed it in today. I just changed it from sort by Manual back to Filename, when I did this is the order that came up. I will tell you that when it was on sort by Filename earlier, some of the 2021 files were mixed in with the 2020 (the "Name" and "More info" have been changed to obscure the actual filenames, but I don't think that should affect the sort order since they start with dates).

2020-11-14 - Name - More info.mp4
2020-12-31 - Name - More info.mp4

2020-8-9 - Name - More info.mp4
2020-11-19 - Name - More info.mp4
2020-8-16 - Name - More info.mp4
2020-8-13 - Name - More info.mp4
2020-8-13 - Name - More info.mp4
2020-8-13 - Name - More info.mp4
2020-5 - Name - More info.mp4
2020-4-15 - Name - More info.mp4

2020-8-18 - Name - More info.mp4
2020-12-25 - Name - More info.mp4
2020-12-22 - Name - More info.mp4
2020-12-20 - Name - More info.mp4
2020-12-2 - Name - More info.mp4
2020-12-18 - Name - More info.mp4
2020-12-18 - Name - More info.mp4
2020-12-12 - Name - More info.mp4
2020-11-20 - Name - More info.mp4
2020-12-23 - Name - More info.mp4
2021-2-6 - Name - More info.mp4
2021-6-23 - Name - More info.mp4
2021-6-14 - Name - More info.mp4
2021-5-23 - Name - More info.mp4
2021-5-16 - Name - More info.mp4
2021-3-6 - Name - More info.mp4
2021-3-16 - Name - More info.mp4
2021-1-30 - Name - More info.mp4
2021-1-7 - Name - More info.mp4
2021-1-4 - Name - More info.mp4
2021-1-4 - Name - More info.mp4
2021-1-31 - Name - More info.mp4
2021-1-30 - Name - More info.mp4
2021-1-20 - Name - More info.mp4
2021-1-16 - Name - More info.mp4
2021-6-23 - Name - More info.mp4

The Collator class appears to be off when I tested for it in two languages.

PHP info has this for intl-

intl
Internationalization support enabled
ICU version 69.1
ICU Data version 69.1
ICU TZData version 2021a
ICU Unicode version 13.0

Directive Local Value Master Value
intl.default_locale no value no value
intl.error_level 0 0
intl.use_exceptions 0 0

Administrator
Administrator
acrylian   25-06-2021, 08:46
#19

If you have the intl class the collator class is included.

The problem you are encountering is that your filename - if I understand corrctly

  • have the date as prefix. And the date is not consitently following the yyyy-mm-dd internatlional date format. Like 2020-8-9which should be 2022-08-0. This is likely causing the wrong ordering as the real natural order really sortes by that. As the general order is ascending by year, just the months and dates are mixed up. Dates win other formats are never sorted correctly as they are as "strings".

If you can try with an album with plain alphabetical names. If that works for you as intended this is in your specific case the reason.

Otherwise we would need to add yet another option so users can choose between natural order and real natural order.

Administrator
Administrator
acrylian   25-06-2021, 09:14
#20

If you like to help, find the function sortArray() function within zp-core/functions.php. there you find the part:

       if (class_exists('collator')) {
            $locale = getUserLocale();
            $collator = new Collator($locale);
            if ($case_sensitive) {
                $collator->setAttribute(Collator::CASE_FIRST, Collator::UPPER_FIRST);
            }
            $collator->setAttribute(Collator::NUMERIC_COLLATION, Collator::ON);
            $success = $collator->asort($array);
        } else {
            if ($case_sensitive) {
                $success = natsort($array);
            } else {
                $success = natcasesort($array);
            }
        }

Remive the collator if check so it uses always the standard PHP natural order (which often is really wrong in some languages with umlauts, accents and other things):

      if ($case_sensitive) {
                $success = natsort($array);
            } else {
                $success = natcasesort($array);
            }

We really did a lot tests with this sorting and the wrong ordering of in this case French language terms reported by a user was the reason to add this.

Pages (2): 1 2   
  
Powered By MyBB, © 2002-2026 MyBB Group.
Made with by Curves UI.