<?php
session_start();
if (!isset($_SESSION['user'])) {
header('Location: index.php');
exit;
}
\$current_user = $_SESSION['user'];
\$users_dir = __DIR__ . '/users/';
\$media_posts = [];
foreach (glob(\$users_dir . '*.json') as \$file) {
\$data = json_decode(file_get_contents(\$file), true);
\$username = \$data['username'] ?? 'unknown';
foreach (\$data['posts'] ?? [] as \$post) {
\$v = \$post['visibility'] ?? 'public';
\$allowed = \$v === 'public' || (\$v === 'friends' && in_array(\$current_user, \$data['friends'] ?? [])) || (\$v === 'private' && \$username === \$current_user);
if (!\$allowed || empty(\$post['filename'])) continue;
\$ext = strtolower(pathinfo(\$post['filename'], PATHINFO_EXTENSION));
if (in_array(\$ext, ['pdf'])) {
\$post['username'] = \$username;
\$media_posts[] = \$post;
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Gallery Docs</title>
<style>
body {
background: black;
color: #00ff00;
font-family: monospace;
padding: 2rem;
}
.media {
border: 1px solid #00ff00;
margin-bottom: 1rem;
padding: 1rem;
}
img, video {
max-width: 100%;
}
a.pdf {
color: #00ff00;
}
</style>
</head>
<body>
<h1>Gallery Docs</h1>
<?php foreach (\$media_posts as \$post): ?>
<div class="media">
<div><strong>@<?= htmlspecialchars(\$post['username']) ?></strong></div>
<?php
$file = 'uploads/' . \$post['filename'];
$ext = pathinfo($file, PATHINFO_EXTENSION);
if (in_array(strtolower($ext), ['jpg','jpeg','png','gif'])) {
echo "<img src='\$file'>";
} elseif (\$ext === 'mp4') {
echo "<video controls src='\$file'></video>";
} elseif (\$ext === 'pdf') {
echo "<a class='pdf' href='\$file' target='_blank'>[View PDF]</a>";
}
?>
</div>
<?php endforeach; ?>
</body>
</html>