widget/doclist: show hidden files to edit admins
authorMischa POSLAWSKY <perl@shiar.org>
Wed, 16 Oct 2019 21:53:56 +0000 (23:53 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Thu, 17 Oct 2019 01:00:36 +0000 (03:00 +0200)
Include private files as alternate options for editors.  Presence of html
still takes precedence, and extension formats are considered a last resort
and no longer include sizes.

widget/doclist.php

index 78b8c4941817c74e5a973e95f4be22e5bfdb5f98..e4fadef34a919700340f7e23b6ad883030193a80 100644 (file)
@@ -1,10 +1,17 @@
 <?php
+global $User;
+
 $cal = [];
 foreach (glob("$Page$Args/2*") as $url) {
-       $parts = pathinfo($url);
-       @list ($date, $suffix) = explode('.', $parts['filename'], 2);
-       $cal[$date][ $suffix ? '' : @$parts['extension'] ] =
-               preg_replace('/\.html$/', '', $url);
+       $link = preg_replace('/\.html$/', '', $url);
+       $name = pathinfo($link, PATHINFO_BASENAME);
+       @list ($date, $suffix) = explode('.', $name, 2);
+       if (!filesize($url)) {
+               $cal[$date] = [];
+       }
+       else {
+               $cal[$date][$suffix] = $link;
+       }
 }
 
 print '<ul';
@@ -12,20 +19,21 @@ if (count($cal) > 5) print ' class="cols"';
 print ">\n";
 foreach (array_reverse($cal) as $title => $versions) {
        print '<li>';
-       if ($url = @$versions['html']) {
+       if ($url = @$versions['']) {
                printf('<a href="/%s">%s</a>', $url, $title);
        }
-       elseif (implode('', array_keys($versions))) {
-               list ($format, $url) = each($versions);
-               include_once('format.inc.php');
-               printf('%s (<a href="/%s">%sB %s</a>)',
-                       $title, $url, showsize(filesize($url)), $format
-               );
-       }
        else {
                print $title;
+               if ($versions and $User->admin('edit')) {
+                       printf(' (%s)', implode(', ', array_map(
+                               function ($format, $url) {
+                                       return sprintf('<a href="/%s">%s</a>', $url, $format);
+                               },
+                               array_keys($versions), $versions)
+                       ));
+               }
        }
-       print "\n";
+       print "</li>\n";
 }
 print "</ul>\n\n";