diff --git a/admin.php b/admin.php index 394154d..a478aeb 100644 --- a/admin.php +++ b/admin.php @@ -213,10 +213,38 @@ if (!in_array($adminMode, ['sections', 'photos', 'comments', 'welcome'], true)) $adminMode = 'photos'; } $previewVersion = (string)time(); +$commentPhotoId = (int)($_GET['comment_photo_id'] ?? ($_POST['comment_photo_id'] ?? 0)); +if ($commentPhotoId < 0) { + $commentPhotoId = 0; +} +$selectedCommentPhoto = $commentPhotoId > 0 ? photoById($commentPhotoId) : null; +if (!$selectedCommentPhoto) { + $commentPhotoId = 0; +} +$photoComments = $commentPhotoId > 0 ? commentsByPhoto($commentPhotoId) : []; +$photoCommentCounts = commentCountsByPhotoIds(array_map(static fn(array $p): int => (int)$p['id'], $photos)); function h(string $v): string { return htmlspecialchars($v, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); } function assetUrl(string $path): string { $f=__DIR__ . '/' . ltrim($path,'/'); $v=is_file($f)?(string)filemtime($f):(string)time(); return $path . '?v=' . rawurlencode($v); } +function commentCountsByPhotoIds(array $photoIds): array +{ + $photoIds = array_values(array_unique(array_map('intval', $photoIds))); + if ($photoIds === []) { + return []; + } + + $placeholders = implode(',', array_fill(0, count($photoIds), '?')); + $st = db()->prepare("SELECT photo_id, COUNT(*) AS cnt FROM photo_comments WHERE photo_id IN ($placeholders) GROUP BY photo_id"); + $st->execute($photoIds); + + $map = []; + foreach ($st->fetchAll() as $row) { + $map[(int)$row['photo_id']] = (int)$row['cnt']; + } + return $map; +} + function saveBulkBefore(array $files, int $sectionId): array { $ok = 0; @@ -564,6 +592,7 @@ function nextUniqueCodeName(string $base): string +
ДоПослеПоляДействия
@@ -600,12 +629,17 @@ function nextUniqueCodeName(string $base): string

-

+

Фото после (опционально):

Сохраняется автоматически при выходе из карточки.
+ 0): ?> +

Комментарии ()

+ +

Комментариев нет

+
@@ -643,21 +677,45 @@ function nextUniqueCodeName(string $base): string

- - - - - - - - - -
ФотоПользовательКомментарий
- - - - -
+ 0 && $selectedCommentPhoto): ?> +

Комментарии к фото:

+ +

К этой карточке комментариев пока нет.

+ + + + + + + + + + +
ПользовательКомментарийДата
+
+ + +
+
+ +

Показать все последние комментарии

+ + + + + + + + + + +
ФотоПользовательКомментарий
+
+ + +
+
+