/password.txt // If album is requested, check password if (isset($_GET['album'])) { $album = $_GET['album']; $pw = isset($_GET['password']) ? $_GET['password'] : null; if (!is_dir($dir . $album)) { http_response_code(404); echo json_encode(['error' => 'Album not found']); exit; } $pwFile = $dir . $album . '/info.yaml'; $albumPassword = ''; $albumTitle = ''; if (file_exists($pwFile)) { if (function_exists('yaml_parse_file')) { $yaml = yaml_parse_file($pwFile); $albumPassword = isset($yaml['password']) ? $yaml['password'] : ''; $albumTitle = isset($yaml['title']) ? $yaml['title'] : ''; } else { // Fallback: parse manually $lines = file($pwFile); foreach ($lines as $line) { if (preg_match('/^password:\s*(.+)$/', trim($line), $m)) { $albumPassword = $m[1]; } if (preg_match('/^title:\s*(.+)$/', trim($line), $m)) { $albumTitle = $m[1]; } } } } if ($albumPassword !== '') { if ($pw !== $albumPassword) { http_response_code(403); echo json_encode(['error' => 'Password required']); exit; } } $albumImages = []; $thumbDir = $dir . $album . '/thumbnails/'; $albumDir = $dir . $album . '/'; foreach (scandir($albumDir) as $file) { $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION)); if (in_array($ext, $extensions)) { $thumbPath = 'images/' . $album . '/thumbnails/' . $file; $fullPath = 'images/' . $album . '/' . $file; if (file_exists($thumbDir . $file)) { $albumImages[] = ['thumb' => $thumbPath, 'full' => $fullPath]; } else { $albumImages[] = ['thumb' => $fullPath, 'full' => $fullPath]; } } } header('Content-Type: application/json'); echo json_encode(['title' => $albumTitle, 'images' => $albumImages]); exit; } // Otherwise, return album list (for landing page) if (is_dir($dir)) { foreach (scandir($dir) as $album) { if ($album === '.' || $album === '..' || !is_dir($dir . $album)) continue; $pwFile = $dir . $album . '/info.yaml'; $protected = false; if (file_exists($pwFile)) { if (function_exists('yaml_parse_file')) { $yaml = yaml_parse_file($pwFile); $protected = isset($yaml['password']) && $yaml['password'] !== ''; } else { $lines = file($pwFile); foreach ($lines as $line) { if (preg_match('/^password:\s*(.+)$/', trim($line), $m)) { if ($m[1] !== '') $protected = true; break; } } } } $albums[$album] = [ 'protected' => $protected, ]; } } header('Content-Type: application/json'); echo json_encode($albums); ?>