From 0995989b5699374dddd7b956c8296af59881ca36 Mon Sep 17 00:00:00 2001 From: Alex Assistant Date: Fri, 20 Feb 2026 15:13:46 +0300 Subject: [PATCH] Public badge for restored photos and commenter link retrieval/regeneration --- README.md | 2 +- admin.php | 22 +++++++++++++++++++- index.php | 3 ++- lib/db_gallery.php | 13 ++++++++++-- migrations/003_comment_users_plain_token.sql | 2 ++ 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 migrations/003_comment_users_plain_token.sql diff --git a/README.md b/README.md index 3246eae..bbf48b1 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ BRANCH=master bash scripts/deploy.sh - после загрузки автоматический prefill имени (code_name) из имени файла, - для каждой карточки фото можно отредактировать: имя, сортировку, комментарий и добавить/заменить фото "после", - запись в таблицы `sections`, `photos`, `photo_files`, -- персональные комментаторы (генерация ссылок), +- персональные комментаторы (генерация ссылок + повторный просмотр/перевыпуск ссылки), - плоские комментарии к фото, - удаление комментариев админом, - watermark на выдаче версии "после". diff --git a/admin.php b/admin.php index 786dd9e..3dcd909 100644 --- a/admin.php +++ b/admin.php @@ -114,6 +114,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } } + if ($action === 'regenerate_commenter_token') { + $id = (int)($_POST['id'] ?? 0); + if ($id > 0) { + $token = commenterRegenerateToken($id); + $link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http') . '://' . ($_SERVER['HTTP_HOST'] ?? 'localhost') . '/?viewer=' . urlencode($token); + $message = 'Токен обновлён | ссылка: ' . $link; + } + } + if ($action === 'delete_comment') { $id = (int)($_POST['id'] ?? 0); if ($id > 0) { @@ -371,9 +380,20 @@ function nextUniqueCodeName(string $base): string

Комментаторы и комментарии

- +
ПользовательДействие
+
ПользовательСсылкаДействия
+ + + + Нет сохранённой ссылки (старый пользователь) + + +
+ + +
diff --git a/index.php b/index.php index 23c9683..dbd08bc 100644 --- a/index.php +++ b/index.php @@ -178,8 +178,9 @@ function outputWatermarked(string $path, string $mime): never
- + + AI

diff --git a/lib/db_gallery.php b/lib/db_gallery.php index c7d4c22..4ea7601 100644 --- a/lib/db_gallery.php +++ b/lib/db_gallery.php @@ -100,8 +100,8 @@ function commenterCreate(string $displayName): array { $token = bin2hex(random_bytes(16)); $hash = hash('sha256', $token); - $st = db()->prepare('INSERT INTO comment_users(display_name, token_hash, is_active) VALUES (:n,:h,1)'); - $st->execute(['n' => $displayName, 'h' => $hash]); + $st = db()->prepare('INSERT INTO comment_users(display_name, token_hash, token_plain, is_active) VALUES (:n,:h,:p,1)'); + $st->execute(['n' => $displayName, 'h' => $hash, 'p' => $token]); return [ 'id' => (int)db()->lastInsertId(), @@ -121,6 +121,15 @@ function commenterDelete(int $id): void $st->execute(['id' => $id]); } +function commenterRegenerateToken(int $id): string +{ + $token = bin2hex(random_bytes(16)); + $hash = hash('sha256', $token); + $st = db()->prepare('UPDATE comment_users SET token_hash=:h, token_plain=:p WHERE id=:id'); + $st->execute(['h' => $hash, 'p' => $token, 'id' => $id]); + return $token; +} + function commentsByPhoto(int $photoId): array { $sql = 'SELECT c.*, u.display_name diff --git a/migrations/003_comment_users_plain_token.sql b/migrations/003_comment_users_plain_token.sql new file mode 100644 index 0000000..44dcba3 --- /dev/null +++ b/migrations/003_comment_users_plain_token.sql @@ -0,0 +1,2 @@ +ALTER TABLE comment_users + ADD COLUMN token_plain VARCHAR(128) NULL AFTER token_hash;