$ git clone http://thingshare.ion.nu/thingshare.git
commit b0f507c8584582df027d21bb478afc814728960e
Author: Alicia <...>
Date:   Fri Mar 20 20:00:32 2020 +0100

    Added sorting options in search results.

diff --git a/search.php b/search.php
index b2a8c3c..7ed4e2b 100644
--- a/search.php
+++ b/search.php
@@ -59,16 +59,16 @@ foreach($res as $peer=>$res2)
     $results[]=$thing;
   }
 }
-function sortthings($a, $b)
+function sortthings($a, $b) // Re-sort flattened results
 {
   global $sortby;
   // TODO: More sorting options?
   switch($sortby)
   {
-    case 'alpha': return ord($b['name'])-ord($a['name']);
-    case 'old': return strtotime($b['date'])-strtotime($a['date']);
+    case 'alpha': return ord($a['name'])-ord($b['name']);
+    case 'old': return strtotime($a['date'])-strtotime($b['date']);
     case 'new':
-    default: return strtotime($a['date'])-strtotime($b['date']);
+    default: return strtotime($b['date'])-strtotime($a['date']);
   }
 }
 usort($results, 'sortthings');
@@ -84,6 +84,11 @@ foreach($results as $thing)
   <form>
     <input type="hidden" name="q" value="<?=(isset($_GET['q'])?$_GET['q']:'')?>" />
     <?=_('Results per page (approximately):')?> <input type="number" name="perpage" value="<?=$perpage?>" /><br />
+    <?=_('Sort by:')?> <select name="sort">
+      <option value="new"<?=($sortby=='new'?' selected':'')?>><?=_('New')?></option>
+      <option value="old"<?=($sortby=='old'?' selected':'')?>><?=_('Old')?></option>
+      <option value="alpha"<?=($sortby=='alpha'?' selected':'')?>><?=_('Alphabetical')?></option>
+    </select>
     <button><?=_('Update')?></button>
   </form>
   <p>
@@ -94,5 +99,5 @@ foreach($results as $thing)
     <?=_('To match a specific phrase:')?> <span class="code">&quot;searchterm in multiple words&quot;</span><br />
   </p>
 </div><br />
-<?=$things?>
+<?=$things?><br />
 <?=$pagenav?>
diff --git a/style.css b/style.css
index bbd97be..563b6f7 100644
--- a/style.css
+++ b/style.css
@@ -159,3 +159,6 @@ div.message_unread {
 a.highlight {
   font-weight:bold;
 }
+a.pagenav {
+  margin-right:12px;
+}