page: maintain all placeholder includes in widget/
[minimedit.git] / widget / login / list.php
diff --git a/widget/login/list.php b/widget/login/list.php
new file mode 100644 (file)
index 0000000..698b805
--- /dev/null
@@ -0,0 +1,76 @@
+<?php
+$basepath = 'profile';
+if ($Args) $basepath .= '/.tags' . $Args;
+$users = glob("$basepath/*/");
+if (!$users) return;
+
+foreach ($users as $col => $userdir) {
+       $users[$col] = new User($userdir);
+}
+
+if (isset($Place['order'])) {
+       $ordercol = $Place['order'];
+       $order = array_map(function ($row) use ($ordercol) {
+               return $row->$ordercol;
+       }, $users);
+#      $order = array_column($users, $ordercol);  #TODO php7 simplification
+       if ($ordercol == 'seen') {
+               array_multisort($order, SORT_DESC, SORT_NUMERIC, $users);
+               $users = array_intersect_key($users, array_filter($order));
+       }
+       else {
+               array_multisort($order, SORT_ASC, SORT_NATURAL, $users);
+       }
+}
+
+if (isset($Place['n'])) {
+       array_splice($users, $Place['n']);  # limit number of results
+}
+
+print '<ul';
+if (@$Place['view'] == 'avatar') {
+       print ' class="gallery cat"';
+}
+elseif (count($users) > 5) {
+       print ' class="cols"';
+}
+print ">\n";
+
+foreach ($users as $user) {
+       $name = $user->name ?: $user->login;
+       if ($GLOBALS['User'] and $GLOBALS['User']->admin) {
+               $link = '/login/edit/'.$user->login;
+               $name = sprintf('<a href="%s">%s</a>', $link, $name);
+       }
+
+       switch (@$Place['view']) {
+       case 'avatar':
+               if (!file_exists("{$user->dir}/avatar.jpg")) {
+                       break;
+               }
+               $avatar = sprintf(
+                       '<img src="%s" alt="%s" />',
+                       "/thumb/100/profile/{$user->login}/avatar.jpg",
+                       $user->login
+               );
+               $name = sprintf(
+                       '<figure>%s<figcaption>%s</figcaption></figure>',
+                       $avatar, $name
+               );
+               break;
+       case 'visit':
+               if ($user->seen) {
+                       $name .= sprintf(' <small class="date">%s</small>', strftime('%F %H:%M', $user->seen));
+               }
+               # continue to default
+       default:
+               if ($user->admin) {
+                       $name .= ' <span class="icon admin" title="beheerder">&#x1F527;</span>';
+               }
+               $name = "<div>$name</div>";
+       }
+
+       print "<li>$name</li>\n";
+}
+
+print "</ul>\n\n";