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