login/pass: error messages below page title
[minimedit.git] / widget / doclist.php
index a4657680edd7efc2fab2273a49e82ee8ecbe6f72..e0751b0df77b1c593189c860ba4c824cfca64911 100644 (file)
@@ -1,26 +1,45 @@
 <?php
 global $User;
+if (isset($Page->place[0])) {
+       $Page->link .= '/'.$Page->place[0];
+}
 
 $cal = [];
-foreach (glob("$Page$Args/2*") as $url) {
+foreach (glob("{$Page->link}/2*") as $url) {
        $link = preg_replace('/\.html$/', '', $url);
        $name = pathinfo($link, PATHINFO_BASENAME);
        @list ($date, $suffix) = explode('.', $name, 2);
-       if (!isset($cal[$date])) {
-               $cal[$date] = [];
+       $group = substr($date, 0, 4);
+       if (!isset($cal[$group][$date])) {
+               $cal[$group][$date] = [];
        }
-       if (!is_dir($url) and filesize($url)) {
-               $cal[$date][$suffix] = $link;
+       if (is_dir($url) ? file_exists("$url/index.html") : filesize($url)) {
+               $cal[$group][$date][$suffix] = $link;
        }
 }
+if (!$cal) {
+       return;
+}
 
 $year = 3600 * 24 * 365;  # seconds per year
-$scale = 8;  # em width per year
-$mindate = strtotime($date) + ($year / $scale * 3);  # first point plus about 3em for centered text
+$scale = 7;  # em width per year
+$mindate = max(time(), strtotime($date) + ($year / $scale * 3));  # at least last entry plus 3em for centered text
+$length = ($mindate - strtotime(key(current($cal)))) / $year * $scale;  # earliest entry position
 
-print '<ul class="timeline">'."\n";
-foreach (array_reverse($cal) as $title => $versions) {
+printf('<ul class="timeline" style="background-size:%.1fem">'."\n", $length);
+foreach (array_reverse($cal, TRUE) as $group => $rows) {
+       if (count($rows) > 1) {
+               $time = ($mindate - strtotime("$group-12-31T23:59")) / $year * $scale;
+               printf('<li class="range" style="left:%.1fem; width:%.1fem">',
+                       $time, $time + $scale > $length ? $length - $time + 2 : $scale
+               );
+               print "<strong>$group</strong><ul>\n";
+       }
+       else {
                $time = 0;
+       }
+
+       foreach ($rows as $title => $versions) {
                $subtime = ($mindate - strtotime($title)) / $year * $scale - $time;
                printf('<li style="left:%.1fem">', $subtime);
                if ($url = @$versions['']) {
@@ -29,7 +48,7 @@ foreach (array_reverse($cal) as $title => $versions) {
                else {
                        print '<span>';
                        print $title;
-                       if ($versions and $User->admin("edit $Page$Args")) {
+                       if ($versions and $User->admin("edit {$Page->link}")) {
                                printf(' (%s)', implode(', ', array_map(
                                        function ($format, $url) {
                                                return sprintf('<a href="/%s">%s</a>', $url, $format);
@@ -40,6 +59,11 @@ foreach (array_reverse($cal) as $title => $versions) {
                        print '</span>';
                }
                print "</li>\n";
+       }
+
+       if (count($rows) > 1) {
+               print "</ul></li>\n";
+       }
 }
 print "</ul>\n\n";