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