improvements to appearance

additions to administrator mode

added a landing page for main page
This commit is contained in:
Brandon4466
2025-07-28 17:01:59 -07:00
parent ce8c47d50d
commit c76247119b
6 changed files with 534 additions and 130 deletions

View File

@@ -4,8 +4,7 @@
$dir = __DIR__ . '/images/';
$extensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp'];
$albums = [];
$passwordFile = __DIR__ . '/passwords.json';
$passwords = file_exists($passwordFile) ? json_decode(file_get_contents($passwordFile), true) : [];
// Passwords now stored per album in images/<album>/password.txt
// If album is requested, check password
if (isset($_GET['album'])) {
@@ -16,8 +15,29 @@ if (isset($_GET['album'])) {
echo json_encode(['error' => 'Album not found']);
exit;
}
if (isset($passwords[$album]) && $passwords[$album] !== '') {
if ($pw !== $passwords[$album]) {
$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;
@@ -39,7 +59,7 @@ if (isset($_GET['album'])) {
}
}
header('Content-Type: application/json');
echo json_encode($albumImages);
echo json_encode(['title' => $albumTitle, 'images' => $albumImages]);
exit;
}
@@ -47,8 +67,24 @@ if (isset($_GET['album'])) {
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' => isset($passwords[$album]) && $passwords[$album] !== '',
'protected' => $protected,
];
}
}