doclist: code cleanup and preparation
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 29 Nov 2019 21:19:34 +0000 (22:19 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Fri, 29 Nov 2019 23:01:55 +0000 (00:01 +0100)
widget/doclist.php

index 2d858843fd4f84026b27103e7ddf19be36b982f9..a4657680edd7efc2fab2273a49e82ee8ecbe6f72 100644 (file)
@@ -6,37 +6,40 @@ foreach (glob("$Page$Args/2*") as $url) {
        $link = preg_replace('/\.html$/', '', $url);
        $name = pathinfo($link, PATHINFO_BASENAME);
        @list ($date, $suffix) = explode('.', $name, 2);
-       if (!filesize($url)) {
+       if (!isset($cal[$date])) {
                $cal[$date] = [];
        }
-       else {
+       if (!is_dir($url) and filesize($url)) {
                $cal[$date][$suffix] = $link;
        }
 }
 
-$mindate = strtotime($date);
+$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
 
 print '<ul class="timeline">'."\n";
 foreach (array_reverse($cal) as $title => $versions) {
-       $time = ($mindate - strtotime($title)) / (3600 * 24 * 365 / 8); # ~8em/yr
-       printf('<li style="left:%.1fem">', $time);
-       if ($url = @$versions['']) {
-               printf('<a href="/%s">%s</a>', $url, $title);
-       }
-       else {
-               print '<span>';
-               print $title;
-               if ($versions and $User->admin("edit $Page$Args")) {
-                       printf(' (%s)', implode(', ', array_map(
-                               function ($format, $url) {
-                                       return sprintf('<a href="/%s">%s</a>', $url, $format);
-                               },
-                               array_keys($versions), $versions)
-                       ));
+               $time = 0;
+               $subtime = ($mindate - strtotime($title)) / $year * $scale - $time;
+               printf('<li style="left:%.1fem">', $subtime);
+               if ($url = @$versions['']) {
+                       printf('<a href="/%s">%s</a>', $url, $title);
                }
-               print '</span>';
-       }
-       print "</li>\n";
+               else {
+                       print '<span>';
+                       print $title;
+                       if ($versions and $User->admin("edit $Page$Args")) {
+                               printf(' (%s)', implode(', ', array_map(
+                                       function ($format, $url) {
+                                               return sprintf('<a href="/%s">%s</a>', $url, $format);
+                                       },
+                                       array_keys($versions), $versions
+                               )));
+                       }
+                       print '</span>';
+               }
+               print "</li>\n";
 }
 print "</ul>\n\n";