f77b9c18414e1553e698e8a63e7ffd28b9b67423
[minimedit.git] / foto / index.php
1 <?php
2 $intro = ob_get_clean();
3
4 $rootdir = 'foto' . $Args;
5
6 if (!empty($User['admin'])) {
7         $access = '🔓 Openbaar';
8         if (isset($PageAccess)) {
9                 $access = "🔒 Bewoners";
10                 if ($PageAccess != $Page.$Args) {
11                         $access .= sprintf(' vanaf <a href="%s">%s</a>',
12                                 "/$PageAccess", pathinfo($PageAccess, PATHINFO_FILENAME)
13                         );
14                 }
15         }
16         print "<aside>$access</aside>\n\n";
17 }
18
19 $nav = explode('/', $Page.$Args);
20 $title = array_pop($nav);
21 $rootname = "Foto's"; # override of 'foto'
22 $link = '';
23 print "<h2>";
24 foreach ($nav as $i => $linktitle) {
25         $link .= "/$linktitle";
26         printf('<a href="%s">%s</a> â†’'."\n", $link, $i ? $linktitle : $rootname);
27 }
28 print $Args ? $title : $rootname;
29 print "</h2>\n\n";
30
31 print $intro;
32
33 function showthumb($path)
34 {
35         // assume all album entries are symlinks to archive originals
36         $target = preg_replace('{^(\.\./)*}', '', readlink($path));
37         $thumb = 'thumb/200/' . $target;
38
39         @list ($order, $size, $title) = explode(':', pathinfo($path, PATHINFO_FILENAME), 3);
40         $imgtag = 'img src="/'.$thumb.'"';
41         if ($title) {
42                 $imgtag .= ' title="'.htmlspecialchars(urldecode($title)).'"';
43         }
44         if ($size) {
45                 $imgtag .= ' data-size="'.$size.'"';
46         }
47
48         return sprintf('<a href="/%s"><%s /></a>'."\n", $target, $imgtag);
49 }
50
51 if ($imgs = glob("$rootdir/*", GLOB_ONLYDIR)) {
52         natsort($imgs);
53         print '<ul class="gallery cat">'."\n";
54         foreach ($imgs as $path) {
55                 $parts = pathinfo($path);
56                 $album = $parts['filename'];
57                 $cover = "$path/index.jpg";
58                 if (!file_exists($cover)) $cover = 'foto/index.jpg';
59                 if (is_link($cover)) {
60                         $cover = preg_replace('{^(?:\.\./)*(?=data/)}', 'thumb/100/', readlink($cover));
61                 }
62
63                 $html = '<img src="/'.$cover.'" />';
64                 $html .= "<figcaption>$album</figcaption>";
65                 if (empty($User) and file_exists("$path/.private")) {
66                         $html = '<strike title="bewoners">'.$html.'</strike>';
67                 }
68                 $html = "<figure>$html</figure>";
69
70                 printf('<li id="%s"><a href="%s">%s</a>'."\n", $album, "/$path", $html);
71         }
72         print "</ul>\n\n";
73 }
74
75 if ($imgs = glob("$rootdir/*.jpg")) {
76         print '<ul class="gallery album">'."\n";
77         foreach ($imgs as $img) {
78                 if ($img == "$rootdir/index.jpg") continue;
79                 if (!is_link($img)) continue;
80                 print '<li>'.showthumb($img);
81         }
82         print '</ul>'."\n\n";
83
84         include 'foto/album.inc.php';
85 }