foto: inline showthumb function to format img elements
[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 ($imgs = glob("$rootdir/*", GLOB_ONLYDIR)) {
52         natsort($imgs);
53         print '<ul class="gallery cat">'."\n";
54         foreach ($imgs as $path) {
55                 $album = htmlspecialchars(pathinfo($path, PATHINFO_FILENAME));
56                 $cover = "$path/index.jpg";
57                 if (!file_exists($cover)) $cover = 'foto/index.jpg';
58                 if (is_link($cover)) {
59                         $cover = preg_replace('{^(?:\.\./)*(?=data/)}', 'thumb/100/', readlink($cover));
60                 }
61
62                 $html = sprintf('<img src="/%s" />', htmlspecialchars($cover));
63                 $html .= "<figcaption>$album</figcaption>";
64                 if (!$User->login and file_exists("$path/.private")) {
65                         $html = '<s title="bewoners">'.$html.'</s>';
66                 }
67                 $html = "<figure>$html</figure>";
68
69                 printf('<li id="%s">', $album);
70                 printf('<a href="/%s">%s</a>'."\n", htmlspecialchars($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 $path) {
78                 if ($path == "$rootdir/index.jpg") {
79                         # cover image of current album
80                         $Page->image = "/$path";
81                         continue;
82                 }
83                 if (!is_link($path)) continue;
84
85                 // assume all album entries are symlinks to archive originals
86                 $target = preg_replace('{^(\.\./)*}', '', readlink($path));
87                 $thumb = 'thumb/262/' . $target;
88
89                 @list ($order, $size, $title) = explode(':', pathinfo($path, PATHINFO_FILENAME), 3);
90                 $imgtag = 'img src="/'.$thumb.'"';
91                 if ($title) {
92                         $imgtag .= ' title="'.htmlspecialchars(urldecode($title)).'"';
93                 }
94                 if ($size) {
95                         $imgtag .= ' data-size="'.$size.'"';
96                 }
97
98                 print '<li>';
99                 printf('<a href="/%s"><%s /></a>'."\n", $target, $imgtag);
100         }
101         print '</ul>'."\n\n";
102
103         include 'foto/album.inc.php';
104 }
105
106 return;