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