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