0d9eec2a73240a414961fe378dba12c09ab6eda8
[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         $users = array_intersect_key($users, array_filter($order));
16 }
17
18 if (isset($Place['n'])) {
19         array_splice($users, $Place['n']);  # limit number of results
20 }
21
22 print '<ul';
23 if (@$Place['view'] == 'avatar') {
24         print ' class="gallery cat"';
25 }
26 elseif (count($users) > 5) {
27         print ' class="cols"';
28 }
29 print ">\n";
30
31 foreach ($users as $user) {
32         $name = $user->name ?: $user->login;
33         if (!empty($GLOBALS['User']['admin'])) {
34                 $link = '/login/edit/'.$user->login;
35                 $name = sprintf('<a href="%s">%s</a>', $link, $name);
36         }
37
38         switch (@$Place['view']) {
39         case 'avatar':
40                 if (!file_exists("{$user->dir}/avatar.jpg")) {
41                         break;
42                 }
43                 $avatar = sprintf(
44                         '<img src="%s" alt="%s" />',
45                         "/thumb/100/profile/{$user->login}/avatar.jpg",
46                         $user->login
47                 );
48                 $name = sprintf(
49                         '<figure>%s<figcaption>%s</figcaption></figure>',
50                         $avatar, $name
51                 );
52                 break;
53         case 'visit':
54                 if ($user->seen) {
55                         $name .= sprintf(' <small class="date">%s</small>', strftime('%F %H:%M', $user->seen));
56                 }
57                 # continue to default
58         default:
59                 if ($user->admin) {
60                         $name .= ' <span class="icon admin" title="beheerder">&#x1F527;</span>';
61                 }
62                 $name = "<div>$name</div>";
63         }
64
65         print "<li>$name</li>\n";
66 }
67
68 print "</ul>\n\n";