add / show comments working
This commit is contained in:
parent
a9992b0ff5
commit
6bffbc1707
10 changed files with 163 additions and 40 deletions
32
public/site/config/routes/add-comment.php
Normal file
32
public/site/config/routes/add-comment.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'pattern' => '(:all)add-comment.json',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
$json = file_get_contents('php://input');
|
||||
$data = json_decode($json);
|
||||
|
||||
// return json_encode($data->pageUri);
|
||||
|
||||
$page = page($data->pageUri);
|
||||
$file = $page->file($data->fileName);
|
||||
$user = kirby()->user($data->userUuid);
|
||||
|
||||
|
||||
$comments = $file->comments()->isEmpty() == true ? [] : Data::decode($file->comments()->toArray()['comments'], 'yaml');
|
||||
|
||||
$comments[$data->targetPage][$data->id] = [
|
||||
'text' => $data->text,
|
||||
'username' => (string) $user->name(),
|
||||
'date' => (string) $data->date,
|
||||
];
|
||||
|
||||
|
||||
$newFile = $file->update([
|
||||
'comments' => $comments
|
||||
]);
|
||||
|
||||
return $comments;
|
||||
}
|
||||
];
|
||||
Loading…
Add table
Add a link
Reference in a new issue