widget/doclist: show hidden files to edit admins
[minimedit.git] / widget / doclist.php
1 <?php
2 global $User;
3
4 $cal = [];
5 foreach (glob("$Page$Args/2*") as $url) {
6         $link = preg_replace('/\.html$/', '', $url);
7         $name = pathinfo($link, PATHINFO_BASENAME);
8         @list ($date, $suffix) = explode('.', $name, 2);
9         if (!filesize($url)) {
10                 $cal[$date] = [];
11         }
12         else {
13                 $cal[$date][$suffix] = $link;
14         }
15 }
16
17 print '<ul';
18 if (count($cal) > 5) print ' class="cols"';
19 print ">\n";
20 foreach (array_reverse($cal) as $title => $versions) {
21         print '<li>';
22         if ($url = @$versions['']) {
23                 printf('<a href="/%s">%s</a>', $url, $title);
24         }
25         else {
26                 print $title;
27                 if ($versions and $User->admin('edit')) {
28                         printf(' (%s)', implode(', ', array_map(
29                                 function ($format, $url) {
30                                         return sprintf('<a href="/%s">%s</a>', $url, $format);
31                                 },
32                                 array_keys($versions), $versions)
33                         ));
34                 }
35         }
36         print "</li>\n";
37 }
38 print "</ul>\n\n";
39