28 lines
No EOL
718 B
PHP
28 lines
No EOL
718 B
PHP
<?php
|
|
|
|
return [
|
|
'pattern' => '(:all)update-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());
|
|
|
|
$comments[$data->id]['text'] = $data->text;
|
|
$comments[$data->id]['date'] = $data->date;
|
|
|
|
$newFile = $file->update([
|
|
'comments' => $comments
|
|
]);
|
|
|
|
$user->sendNotification('comments', $comments[$data->id]);
|
|
|
|
return getFileData($newFile);
|
|
}
|
|
]; |