foto: translate tag album requests to .tag
[minimedit.git] / foto / index.php
index e7f1bab54132b0766eba3ecb8a4e54849676b03c..1ebb53986bc08c3046e94ca32a1b5b60d137ef64 100644 (file)
@@ -2,11 +2,24 @@
 $rootdir = $Page->link;
 
 $nav = explode('/', $rootdir);
+if (count($nav) > 1 and $nav[1] == 'tag') {
+       $rootdir = preg_replace('{/}', '/.', $rootdir, 1);
+}
 $nav[0] = "Foto's"; # override of root 'foto'
 $title = array_pop($nav);
 $Page->title = ($nav ? implode(' ', $nav) . ': ' : '') . $title;
 
-if ($Page->api) {
+if ($_SERVER['HTTP_ACCEPT'] === 'application/json') {
+       header('Access-Control-Allow-Origin: *');
+       $imgs = [];
+       foreach (glob("$rootdir/*.jpg") as $path) {
+               $target = preg_replace('{^(\.\./)*}', '', readlink($path));
+               $imgs[] = ["/$target"];
+       }
+       print json_encode($imgs);
+       exit;
+}
+elseif ($Page->api) {
        $img = "$rootdir/index.jpg";
        if (file_exists($img)) {
                # cover image of current album