LuminaWebsite/gallery.php
Maaxxs b748d380ce Gallery: screenshots of all members on one page, with a "new" count in the sidebar
- New menu item "Galerie" (gallery.php, permission members.view): all visible gallery pictures of active
  members, 48 per page, without profile backgrounds.
  - Sort by newest, oldest, most reactions or member (?sort=neu|alt|reaktionen|mitglied), optionally one
    member only (?mitglied=ID, dropdown with picture counts).
  - Lightbox through the page; comments and reactions only where the member allows them (like the profile).
  - "Eigene Bilder hochladen" links to the gallery section of member_edit.php (#galerie).
  - Two pictures per row on phones.
- Pictures by others since the last visit (users.gallery_seen_at, set when the page is opened, schema v45)
  are marked "Neu", and their number shows in the sidebar; without a visit, the last 7 days count.
- Privacy policy (Aktivität), account anonymization (resets gallery_seen_at), README and a member patch
  note are updated. Idea from the legion.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-24 17:37:15 +02:00

184 lines
10 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Galerie: die Screenshots aus den Profil-Galerien aller Mitglieder auf einer Seite - neueste zuerst
* oder nach Reaktionen bzw. Mitglied sortiert, auf Wunsch nur die eines Mitglieds. Gezeigt werden wie
* auf den Profilseiten nur freigegebene Bilder aktiver Mitglieder; Reaktionen und Kommentare nur, wo
* das Mitglied sie erlaubt. Bilder seit dem letzten Besuch sind als "Neu" markiert, die Seitenleiste
* zeigt ihre Zahl (users.gallery_seen_at, includes/header.php).
*/
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/member_profile.php';
require_once __DIR__ . '/includes/reactions.php';
require_permission('members.view');
const GALLERY_PER_PAGE = 48;
const GALLERY_SORTS = [
'neu' => 'Neueste',
'alt' => 'Älteste',
'reaktionen' => 'Meiste Reaktionen',
'mitglied' => 'Nach Mitglied',
];
$sort = (string) ($_GET['sort'] ?? 'neu');
if (!isset(GALLERY_SORTS[$sort])) {
$sort = 'neu';
}
$memberFilter = max(0, (int) ($_GET['mitglied'] ?? 0));
$page = max(1, (int) ($_GET['page'] ?? 1));
$me = current_user();
$myId = (int) $me['id'];
// Was seit dem letzten Besuch dazukam, ist "neu" - danach gilt die Galerie als gesehen
$seenStmt = db()->prepare('SELECT gallery_seen_at FROM users WHERE id = ?');
$seenStmt->execute([$myId]);
$seenAt = $seenStmt->fetchColumn();
$seenTs = is_string($seenAt) && $seenAt !== '' ? (int) strtotime($seenAt) : time() - 7 * 86400;
db()->prepare('UPDATE users SET gallery_seen_at = NOW() WHERE id = ?')->execute([$myId]);
$where = "g.status = 'visible' AND g.is_background = 0 AND u.status = 'active'";
$params = [];
if ($memberFilter > 0) {
$where .= ' AND g.user_id = ?';
$params[] = $memberFilter;
}
$countStmt = db()->prepare("SELECT COUNT(*) FROM member_gallery g JOIN users u ON u.id = g.user_id WHERE $where");
$countStmt->execute($params);
$total = (int) $countStmt->fetchColumn();
$pageCount = max(1, (int) ceil($total / GALLERY_PER_PAGE));
$page = min($page, $pageCount);
$nameSql = "LOWER(COALESCE(NULLIF(u.display_name, ''), u.username))";
$orderBy = [
'neu' => 'g.created_at DESC, g.id DESC',
'alt' => 'g.created_at ASC, g.id ASC',
'reaktionen' => 'reaction_count DESC, g.created_at DESC, g.id DESC',
'mitglied' => $nameSql . ', g.user_id, g.sort_order, g.id',
][$sort];
$stmt = db()->prepare(
"SELECT g.id, g.user_id, g.filename, g.caption, g.created_at, u.username, u.display_name, u.avatar_filename,
u.gallery_comments_enabled,
IF(u.gallery_comments_enabled = 1,
(SELECT COUNT(*) FROM reactions r WHERE r.content_type = 'picture' AND r.content_id = g.id), 0) AS reaction_count
FROM member_gallery g JOIN users u ON u.id = g.user_id
WHERE $where
ORDER BY $orderBy
LIMIT " . GALLERY_PER_PAGE . ' OFFSET ' . (($page - 1) * GALLERY_PER_PAGE)
);
$stmt->execute($params);
$pictures = $stmt->fetchAll();
// Reaktionen und Kommentare nur bei Mitgliedern, die sie erlauben (wie auf der Profilseite)
$interactiveIds = array_map('intval', array_column(array_filter($pictures, static fn (array $p): bool => !empty($p['gallery_comments_enabled'])), 'id'));
$commentCounts = gallery_comment_counts($interactiveIds);
$pictureReactions = reactions_for('picture', $interactiveIds);
// Mitglieder mit Bildern fuer die Auswahl
$owners = db()->query(
"SELECT u.id, u.username, u.display_name, COUNT(*) AS pictures
FROM member_gallery g JOIN users u ON u.id = g.user_id
WHERE g.status = 'visible' AND g.is_background = 0 AND u.status = 'active'
GROUP BY u.id, u.username, u.display_name
ORDER BY LOWER(COALESCE(NULLIF(u.display_name, ''), u.username))"
)->fetchAll();
// Adresse mit den aktuellen Einstellungen, einzelne geaendert (null = weglassen)
$query = static function (array $changes) use ($sort, $memberFilter): string {
$params = array_merge(['sort' => $sort === 'neu' ? null : $sort, 'mitglied' => $memberFilter ?: null], $changes);
$params = array_filter($params, static fn ($value): bool => $value !== null);
return '/gallery.php' . ($params ? '?' . http_build_query($params) : '');
};
$pageBase = $query(['page' => null]);
$pageBase .= strpos($pageBase, '?') === false ? '?' : '&';
$displayName = static fn (array $row): string => $row['display_name'] !== '' ? (string) $row['display_name'] : (string) $row['username'];
$pageTitle = 'Galerie';
include __DIR__ . '/includes/header.php';
?>
<div class="panel">
<div class="raid-header gallery-feed-head">
<div>
<h1>Galerie</h1>
<p class="text-muted">Die Screenshots aus den Profilseiten aller Mitglieder - <?= $total ?> <?= $total === 1 ? 'Bild' : 'Bilder' ?><?= $memberFilter > 0 ? ' von diesem Mitglied' : '' ?>.</p>
</div>
<a class="button button-secondary" href="/member_edit.php#galerie"><?= icon('edit') ?> Eigene Bilder hochladen</a>
</div>
<div class="gallery-feed-controls">
<div class="members-chips" role="group" aria-label="Sortieren">
<?php foreach (GALLERY_SORTS as $key => $label): ?>
<a class="members-chip<?= $key === $sort ? ' active' : '' ?>" href="<?= e($query(['sort' => $key === 'neu' ? null : $key, 'page' => null])) ?>"<?= $key === $sort ? ' aria-current="true"' : '' ?>><?= e($label) ?></a>
<?php endforeach; ?>
</div>
<?php if (count($owners) > 1 || $memberFilter > 0): ?>
<form method="get" action="/gallery.php" class="gallery-feed-filter">
<?php if ($sort !== 'neu'): ?><input type="hidden" name="sort" value="<?= e($sort) ?>"><?php endif; ?>
<label for="gallery-member" class="members-filter-label">Mitglied</label>
<select id="gallery-member" name="mitglied" data-autosubmit>
<option value="">Alle Mitglieder</option>
<?php foreach ($owners as $owner): ?>
<option value="<?= (int) $owner['id'] ?>"<?= (int) $owner['id'] === $memberFilter ? ' selected' : '' ?>><?= e($displayName($owner)) ?> (<?= (int) $owner['pictures'] ?>)</option>
<?php endforeach; ?>
</select>
<noscript><button type="submit" class="button-small">Anzeigen</button></noscript>
</form>
<?php endif; ?>
</div>
</div>
<?php if (!$pictures): ?>
<div class="panel">
<p class="text-muted">Hier ist noch nichts. Lade auf deiner <a href="/member_edit.php#galerie">Profilseite</a> Screenshots hoch - sie erscheinen dann hier für alle.</p>
</div>
<?php else: ?>
<div class="panel">
<div class="gallery-grid gallery-feed">
<?php foreach ($pictures as $picture): ?>
<?php
$pictureId = (int) $picture['id'];
$url = profile_image_url($picture['filename']);
$pictureUrl = '/member_picture.php?id=' . $pictureId;
$ownerName = $displayName($picture);
$interactive = !empty($picture['gallery_comments_enabled']);
$commentCount = $commentCounts[$pictureId] ?? 0;
$reactionsHere = $pictureReactions[$pictureId] ?? [];
$isNew = (int) $picture['user_id'] !== $myId && strtotime((string) $picture['created_at']) > $seenTs;
$caption = trim((string) $picture['caption']);
?>
<figure class="gallery-item gallery-feed-item">
<a class="gallery-feed-image" href="<?= e((string) $url) ?>" data-lightbox="galerie" data-caption="<?= e(($caption !== '' ? $caption . ' – ' : '') . $ownerName) ?>"
<?php if ($interactive): ?>data-comments-url="<?= e($pictureUrl . '#kommentare') ?>" data-comments-count="<?= $commentCount ?>"<?php endif; ?>>
<img src="<?= e((string) $url) ?>" alt="<?= e($caption !== '' ? $caption : 'Bild von ' . $ownerName) ?>" loading="lazy">
<?php if ($isNew): ?><span class="gallery-new-badge" title="Neu seit deinem letzten Besuch">Neu</span><?php endif; ?>
</a>
<?php if ($reactionsHere): ?>
<?php arsort($reactionsHere); ?>
<a class="gallery-reaction-summary" href="<?= e($pictureUrl) ?>" title="Reaktionen ansehen">
<?= e(implode('', array_slice(array_keys($reactionsHere), 0, 3))) ?>
<span><?= array_sum(array_column($reactionsHere, 'count')) ?></span>
</a>
<?php endif; ?>
<?php if ($interactive): ?>
<a class="gallery-comment-badge<?= $commentCount > 0 ? ' has-comments' : '' ?>" href="<?= e($pictureUrl . '#kommentare') ?>"
title="<?= $commentCount > 0 ? $commentCount . ' ' . ($commentCount === 1 ? 'Kommentar' : 'Kommentare') . ' ansehen' : 'Kommentieren' ?>">
<?= icon('message') ?><?= $commentCount > 0 ? ' ' . $commentCount : '' ?>
</a>
<?php endif; ?>
<figcaption>
<a class="gallery-feed-author" href="/member.php?id=<?= (int) $picture['user_id'] ?>"><?= avatar_html(['id' => (int) $picture['user_id']] + $picture, 20) ?><span><?= e($ownerName) ?></span></a>
<span class="gallery-feed-date" title="<?= e(date('d.m.Y, H:i', (int) strtotime((string) $picture['created_at']))) ?> Uhr"><?= e(date('d.m.Y', (int) strtotime((string) $picture['created_at']))) ?></span>
<?php if ($caption !== ''): ?><span class="gallery-feed-caption"><?= e($caption) ?></span><?php endif; ?>
</figcaption>
</figure>
<?php endforeach; ?>
</div>
<?php render_pagination($pageBase, $page, $pageCount); ?>
</div>
<?php endif; ?>
<script src="<?= e(asset_url('/assets/js/lightbox.js')) ?>" defer></script>
<script>
// Mitglied auswaehlen = gleich anzeigen
document.querySelectorAll('[data-autosubmit]').forEach(function (select) {
select.addEventListener('change', function () { select.form.submit(); });
});
</script>
<?php include __DIR__ . '/includes/footer.php'; ?>