index: lsort(): add support for sorting with '//'
authorTimothy Gu <timothygu99@gmail.com>
Wed, 11 Jun 2014 01:07:53 +0000 (18:07 -0700)
committerMichael Niedermayer <michaelni@gmx.at>
Mon, 16 Jun 2014 15:11:14 +0000 (17:11 +0200)
Signed-off-by: Timothy Gu <timothygu99@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
index.cgi

index 6603fda..7204591 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -111,14 +111,23 @@ sub lsort {
     $params .= '&' if $params;
     my ($text, $key) = @_;
 
-    if ($sort eq $key) {                           # $sort = $key
-        if ($key =~ /^desc/) {                     # $sort = desc*
-            $key =~ s/^desc//;
-        } else {                                   # $sort = *
-            $key = "desc$key";
+    my $newkey = '';
+    if ($sort eq $key) {                           # $key     = $sort
+        for my $thiskey (split /\/\//, $key) {
+            if ($thiskey =~ /^desc/) {             # $thiskey = desc*
+                $thiskey =~ s/^desc//;
+            } else {                               # $thiskey = *
+                $thiskey = "desc$thiskey";
+            }
+            if ($newkey eq '') {
+                $newkey = $thiskey;
+            } else {
+                $newkey .= "//$thiskey";
+            }
         }
     }
 
+    $key = $newkey if $newkey ne '';
     anchor $text, href => "$uri?${params}sort=$key";
 }