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