login/pass: error messages below page title
[minimedit.git] / widget / doclist.php
1 <?php
2 global $User;
3 if (isset($Page->place[0])) {
4         $Page->link .= '/'.$Page->place[0];
5 }
6
7 $cal = [];
8 foreach (glob("{$Page->link}/2*") as $url) {
9         $link = preg_replace('/\.html$/', '', $url);
10         $name = pathinfo($link, PATHINFO_BASENAME);
11         @list ($date, $suffix) = explode('.', $name, 2);
12         $group = substr($date, 0, 4);
13         if (!isset($cal[$group][$date])) {
14                 $cal[$group][$date] = [];
15         }
16         if (is_dir($url) ? file_exists("$url/index.html") : filesize($url)) {
17                 $cal[$group][$date][$suffix] = $link;
18         }
19 }
20 if (!$cal) {
21         return;
22 }
23
24 $year = 3600 * 24 * 365;  # seconds per year
25 $scale = 7;  # em width per year
26 $mindate = max(time(), strtotime($date) + ($year / $scale * 3));  # at least last entry plus 3em for centered text
27 $length = ($mindate - strtotime(key(current($cal)))) / $year * $scale;  # earliest entry position
28
29 printf('<ul class="timeline" style="background-size:%.1fem">'."\n", $length);
30 foreach (array_reverse($cal, TRUE) as $group => $rows) {
31         if (count($rows) > 1) {
32                 $time = ($mindate - strtotime("$group-12-31T23:59")) / $year * $scale;
33                 printf('<li class="range" style="left:%.1fem; width:%.1fem">',
34                         $time, $time + $scale > $length ? $length - $time + 2 : $scale
35                 );
36                 print "<strong>$group</strong><ul>\n";
37         }
38         else {
39                 $time = 0;
40         }
41
42         foreach ($rows as $title => $versions) {
43                 $subtime = ($mindate - strtotime($title)) / $year * $scale - $time;
44                 printf('<li style="left:%.1fem">', $subtime);
45                 if ($url = @$versions['']) {
46                         printf('<a href="/%s">%s</a>', $url, $title);
47                 }
48                 else {
49                         print '<span>';
50                         print $title;
51                         if ($versions and $User->admin("edit {$Page->link}")) {
52                                 printf(' (%s)', implode(', ', array_map(
53                                         function ($format, $url) {
54                                                 return sprintf('<a href="/%s">%s</a>', $url, $format);
55                                         },
56                                         array_keys($versions), $versions
57                                 )));
58                         }
59                         print '</span>';
60                 }
61                 print "</li>\n";
62         }
63
64         if (count($rows) > 1) {
65                 print "</ul></li>\n";
66         }
67 }
68 print "</ul>\n\n";
69