designtopack/public/site/plugins/comments/routes/update.php

28 lines
718 B
PHP
Raw Normal View History

2024-10-23 11:32:51 +02:00
<?php
return [
'pattern' => '(:all)update-comment.json',
2024-10-23 11:32:51 +02:00
'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);
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
$comments[$data->id]['text'] = $data->text;
$comments[$data->id]['date'] = $data->date;
2024-10-23 11:32:51 +02:00
$newFile = $file->update([
'comments' => $comments
]);
$user->sendNotification('comments', $comments[$data->id]);
return getFileData($newFile);
2024-10-23 11:32:51 +02:00
}
];