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