diff --git a/admin.php b/admin.php index a478aeb..a0b34ea 100644 --- a/admin.php +++ b/admin.php @@ -19,6 +19,33 @@ if ($tokenExpected === '' || !hash_equals($tokenExpected, $tokenIncoming)) { exit('Forbidden'); } +$requestAction = (string)($_REQUEST['action'] ?? ''); +if ($_SERVER['REQUEST_METHOD'] === 'GET' && $requestAction === 'photo_comments') { + $photoId = (int)($_GET['photo_id'] ?? 0); + if ($photoId < 1) { + http_response_code(400); + header('Content-Type: application/json; charset=utf-8'); + echo json_encode(['ok' => false, 'message' => 'Некорректный photo_id'], JSON_UNESCAPED_UNICODE); + exit; + } + + $photo = photoById($photoId); + if (!$photo) { + http_response_code(404); + header('Content-Type: application/json; charset=utf-8'); + echo json_encode(['ok' => false, 'message' => 'Фото не найдено'], JSON_UNESCAPED_UNICODE); + exit; + } + + header('Content-Type: application/json; charset=utf-8'); + echo json_encode([ + 'ok' => true, + 'photo' => ['id' => (int)$photo['id'], 'code_name' => (string)$photo['code_name']], + 'comments' => commentsByPhoto($photoId), + ], JSON_UNESCAPED_UNICODE); + exit; +} + $message = ''; $errors = []; @@ -149,6 +176,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $st->execute(['pid' => $photoId, 'kind' => $kind]); $message = 'Изображение повернуто'; + if ($isAjax) { + header('Content-Type: application/json; charset=utf-8'); + echo json_encode(['ok' => true, 'message' => $message, 'photo_id' => $photoId, 'kind' => $kind], JSON_UNESCAPED_UNICODE); + exit; + } } if ($action === 'create_commenter') { @@ -181,6 +213,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($id > 0) { commentDelete($id); $message = 'Комментарий удалён'; + if ($isAjax) { + header('Content-Type: application/json; charset=utf-8'); + echo json_encode(['ok' => true, 'message' => $message], JSON_UNESCAPED_UNICODE); + exit; + } } } } catch (Throwable $e) { @@ -481,7 +518,38 @@ function nextUniqueCodeName(string $base): string Админка - +

Админка

@@ -596,13 +664,13 @@ function nextUniqueCodeName(string $base): string - -
-
+ +
+ -
+
@@ -611,13 +679,13 @@ function nextUniqueCodeName(string $base): string - -
-
+ +
+ -
+
@@ -635,15 +703,19 @@ function nextUniqueCodeName(string $base): string - 0): ?> -

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

- -

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

- -
- - -
+
+
+ 0): ?> + + + Комментариев нет + +
+
+ + +
+
@@ -728,6 +800,16 @@ function nextUniqueCodeName(string $base): string
+