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