c2cc95c730a37361bc82143085340dc8593df233
[minimedit.git] / foto / index.php
1 <?php
2 $rootdir = $Page->link;
3
4 $nav = explode('/', $rootdir);
5 $nav[0] = "Foto's"; # override of root 'foto'
6 $title = array_pop($nav);
7 $Page->title = ($nav ? implode(' ', $nav) . ': ' : '') . $title;
8
9 if (!$User) {
10         $img = "$rootdir/index.jpg";
11         if (file_exists($img)) {
12                 # cover image of current album
13                 $Page->image = "/$img";
14         }
15         return;
16 }
17
18 if ($User->admin('foto')) {
19         if ($Page->restricted) {
20                 $access = '<span class="icon icon-locked">&#x1F512;</span> Bewoners';
21                 if ($Page->restricted != $rootdir) {
22                         $access .= sprintf(' vanaf <a href="%s">%s</a>',
23                                 "/{$Page->restricted}", pathinfo($Page->restricted, PATHINFO_FILENAME)
24                         );
25                 }
26         }
27         else {
28                 $access = '<span class="icon icon-locked">&#x1F513;</span> Openbaar';
29         }
30         print "<aside>$access</aside>\n\n";
31 }
32
33 $link = '';
34 print "<h2>";
35 foreach ($nav as $i => $linktitle) {
36         $link .= '/' . ($i ? $linktitle : $Page->handler);
37         printf('<a href="%s">%s</a> →'."\n", $link, $linktitle);
38 }
39 print $title;
40 print "</h2>\n\n";
41
42 if (isset($Page->raw)) {
43         print $Page->raw;  # page intro
44 }
45
46 if (!function_exists('showthumb')) {
47 function showthumb($path)
48 {
49         // assume all album entries are symlinks to archive originals
50         $target = preg_replace('{^(\.\./)*}', '', readlink($path));
51         $thumb = 'thumb/262/' . $target;
52
53         @list ($order, $size, $title) = explode(':', pathinfo($path, PATHINFO_FILENAME), 3);
54         $imgtag = 'img src="/'.$thumb.'"';
55         if ($title) {
56                 $imgtag .= ' title="'.htmlspecialchars(urldecode($title)).'"';
57         }
58         if ($size) {
59                 $imgtag .= ' data-size="'.$size.'"';
60         }
61
62         return sprintf('<a href="/%s"><%s /></a>'."\n", $target, $imgtag);
63 }
64 }
65
66 if ($imgs = glob("$rootdir/*", GLOB_ONLYDIR)) {
67         natsort($imgs);
68         print '<ul class="gallery cat">'."\n";
69         foreach ($imgs as $path) {
70                 $parts = pathinfo($path);
71                 $album = $parts['filename'];
72                 $cover = "$path/index.jpg";
73                 if (!file_exists($cover)) $cover = 'foto/index.jpg';
74                 if (is_link($cover)) {
75                         $cover = preg_replace('{^(?:\.\./)*(?=data/)}', 'thumb/100/', readlink($cover));
76                 }
77
78                 $html = '<img src="/'.$cover.'" />';
79                 $html .= "<figcaption>$album</figcaption>";
80                 if (!$User->login and file_exists("$path/.private")) {
81                         $html = '<s title="bewoners">'.$html.'</s>';
82                 }
83                 $html = "<figure>$html</figure>";
84
85                 printf('<li id="%s"><a href="%s">%s</a>'."\n", $album, "/$path", $html);
86         }
87         print "</ul>\n\n";
88 }
89
90 if ($imgs = glob("$rootdir/*.jpg")) {
91         print '<ul class="gallery album">'."\n";
92         foreach ($imgs as $img) {
93                 if ($img == "$rootdir/index.jpg") {
94                         # cover image of current album
95                         $Page->image = "/$img";
96                         continue;
97                 }
98                 if (!is_link($img)) continue;
99                 print '<li>'.showthumb($img);
100         }
101         print '</ul>'."\n\n";
102
103         include 'foto/album.inc.php';
104 }
105
106 return;