login/admin: recent visitors summary
[minimedit.git] / login / list.php
1 <?php
2 $basepath = 'profile';
3 if ($Args) $basepath .= '/.tags' . $Args;
4 $users = glob("$basepath/*/");
5 if (!$users) return;
6
7 foreach ($users as $col => $userdir) {
8         $users[$col] = new User($userdir);
9 }
10
11 if (@$Place['order'] == 'seen') {
12         $order = array_map(function ($col) { return $col->seen; }, $users);
13 #       $order = array_column($users, 'seen');  #TODO php7 simplification
14         array_multisort($order, SORT_DESC, SORT_NUMERIC, $users);
15 }
16
17 if (isset($Place['n'])) {
18         array_splice($users, $Place['n']);  # limit number of results
19 }
20
21 print '<ul';
22 if (@$Place['view'] == 'avatar') {
23         print ' class="gallery cat"';
24 }
25 elseif (count($users) > 5) {
26         print ' class="cols"';
27 }
28 print ">\n";
29
30 foreach ($users as $user) {
31         $name = $user->name ?: $user->login;
32         if (!empty($GLOBALS['User']['admin'])) {
33                 $link = '/login/edit/'.$user->login;
34                 $name = sprintf('<a href="%s">%s</a>', $link, $name);
35         }
36
37         switch (@$Place['view']) {
38         case 'avatar':
39                 if (!file_exists("{$user->dir}/avatar.jpg")) {
40                         break;
41                 }
42                 $avatar = sprintf(
43                         '<img src="%s" alt="%s" />',
44                         "/thumb/100/profile/{$user->login}/avatar.jpg",
45                         $user->login
46                 );
47                 $name = sprintf(
48                         '<figure>%s<figcaption>%s</figcaption></figure>',
49                         $avatar, $name
50                 );
51                 break;
52         case 'visit':
53                 if ($user->seen) {
54                         $name .= sprintf(' <small class="date">%s</small>', strftime('%F %H:%M', $user->seen));
55                 }
56                 # continue to default
57         default:
58                 if ($user->admin) {
59                         $name .= ' <em>(beheerder)</em>';
60                 }
61         }
62
63         print "<li>$name</li>\n";
64 }
65
66 print "</ul>\n\n";