refactor comment system into comments plugin

This commit is contained in:
isUnknown 2024-10-29 11:12:57 +01:00
parent 31844269c0
commit fb36329556
8 changed files with 134 additions and 101 deletions

View file

@ -26,7 +26,6 @@ return [
require(__DIR__ . '/routes/save-file.php'),
require(__DIR__ . '/routes/remove-file.php'),
require(__DIR__ . '/routes/upload-pdf.php'),
require(__DIR__ . '/routes/add-comment.php'),
require(__DIR__ . '/routes/read-notification.php'),
],
'hooks' => [

View file

@ -1,36 +0,0 @@
<?php
return [
'pattern' => '(:all)add-comment.json',
'method' => 'POST',
'action' => function () {
$json = file_get_contents('php://input');
$data = json_decode($json);
$page = page($data->pageUri);
$file = $page->file($data->fileName);
$user = kirby()->user($data->userUuid);
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
$newComment = [
'fileUuid' => (string) $file->uuid(),
'page' => $data->targetPage,
'text' => $data->text,
'username' => $user->name()->isNotEmpty() ? (string) $user->name() : (string) $user->email(),
'date' => (string) $data->date,
'id' => $data->id,
];
$comments[$data->targetPage][$data->id] = $newComment;
$newFile = $file->update([
'comments' => $comments
]);
$user->sendNotification('comments', $newComment);
return getFileData($newFile);
}
];