2024-10-23 11:32:51 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
return [
|
2024-10-29 11:12:57 +01:00
|
|
|
'pattern' => '(:all)delete-comment.json',
|
2025-02-09 10:57:25 +01:00
|
|
|
'method' => 'POST',
|
2024-10-23 11:32:51 +02:00
|
|
|
'action' => function () {
|
|
|
|
|
$json = file_get_contents('php://input');
|
|
|
|
|
$data = json_decode($json);
|
2025-02-09 10:57:25 +01:00
|
|
|
// kirby()->impersonate('kirby');
|
2024-10-23 11:32:51 +02:00
|
|
|
|
2024-11-18 12:00:19 +01:00
|
|
|
$page = page($data->location->page->uri);
|
2025-02-09 10:57:25 +01:00
|
|
|
|
2024-11-18 12:00:19 +01:00
|
|
|
$file = $page->file($data->location->file->uuid);
|
2024-10-28 16:52:59 +01:00
|
|
|
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
|
2024-10-23 11:32:51 +02:00
|
|
|
|
2025-01-15 14:18:48 +01:00
|
|
|
$isReply = $data->location->parent->id ?? false;
|
2024-10-30 16:32:13 +01:00
|
|
|
foreach ($comments as $key => &$comment) {
|
2025-02-09 10:57:25 +01:00
|
|
|
if ($isReply) {
|
|
|
|
|
if ($comment['id'] === $data->location->parent->id) {
|
|
|
|
|
foreach ($comment['replies'] as $replyKey => $reply) {
|
|
|
|
|
if ($reply['id'] === $data->id) {
|
|
|
|
|
unset($comment['replies'][$replyKey]);
|
|
|
|
|
$comment['replies'] = array_values($comment['replies']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if ($comment['id'] === $data->id) {
|
|
|
|
|
unset($comments[$key]);
|
2024-10-30 16:32:13 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-17 12:01:20 +01:00
|
|
|
$comments = array_values($comments);
|
2024-10-30 16:32:13 +01:00
|
|
|
|
2024-10-23 11:32:51 +02:00
|
|
|
$newFile = $file->update([
|
2025-02-09 10:57:25 +01:00
|
|
|
'comments' => $comments,
|
2024-10-23 11:32:51 +02:00
|
|
|
]);
|
2025-02-09 10:57:25 +01:00
|
|
|
|
2024-11-17 12:01:20 +01:00
|
|
|
echo json_encode(getFileData($newFile));
|
2025-02-09 10:57:25 +01:00
|
|
|
|
2026-01-15 10:31:31 +01:00
|
|
|
// Note: Les notifications sont maintenant dérivées des commentaires.
|
|
|
|
|
// La suppression du commentaire supprime automatiquement la notification.
|
2025-02-09 10:57:25 +01:00
|
|
|
|
2024-11-17 12:01:20 +01:00
|
|
|
exit;
|
2025-02-09 10:57:25 +01:00
|
|
|
},
|
2024-10-30 16:32:13 +01:00
|
|
|
];
|