]> git.mxchange.org Git - friendica.git/commitdiff
improve previous / next function in photo gallery
authorHannes Heute <5753419+haheute@users.noreply.github.com>
Wed, 4 Jan 2023 13:25:33 +0000 (14:25 +0100)
committerHannes Heute <5753419+haheute@users.noreply.github.com>
Wed, 4 Jan 2023 13:25:33 +0000 (14:25 +0100)
mod/photos.php

index a1aebfac6686f1ee59d1edd002c8c5319b883404..2f9c5ca310e5195ce273817eb151ad99246df74c 100644 (file)
@@ -937,11 +937,17 @@ function photos_content(App $a)
                                $nxt = null;
                                foreach ($prvnxt as $z => $entry) {
                                        if ($entry['resource-id'] == $ph[0]['resource-id']) {
-                                               $prv = $z - 1;
-                                               $nxt = $z + 1;
+                                               $prv = ($order_field === 'created') ? ($z - 1) : ($z + 1);
+                                               $nxt = ($order_field === 'created') ? ($z + 1) : ($z - 1);
                                                if ($prv < 0) {
                                                        $prv = count($prvnxt) - 1;
                                                }
+                                               if ($nxt < 0) {
+                                                       $nxt = count($prvnxt) - 1;
+                                               }
+                                               if ($prv >= count($prvnxt)) {
+                                                       $prv = 0;
+                                               }
                                                if ($nxt >= count($prvnxt)) {
                                                        $nxt = 0;
                                                }