add front-comments

This commit is contained in:
isUnknown 2024-09-10 17:14:38 +02:00
parent c3ea78cab5
commit c9f4af7e58
53 changed files with 2921 additions and 1 deletions

View file

@ -0,0 +1,32 @@
<?php
function storeComment()
{
$jsonRequest = file_get_contents("php://input");
$request = json_decode($jsonRequest, true);
if (isset($request['position']) && is_string($request['position'])) {
$request['position'] = json_decode($request['position'], true);
}
$dataFile = __DIR__ . '/../data/data.json';
$data = file_get_contents($dataFile);
$jsonData = json_decode($data, true);
$foundIndex = null;
foreach ($jsonData as $index => $item) {
if ($item['id'] === $request['id']) {
$foundIndex = $index;
break;
}
}
if (is_null($foundIndex)) {
$jsonData[] = $request;
} else {
$jsonData[$foundIndex] = $request;
}
file_put_contents($dataFile, json_encode($jsonData));
return $jsonData;
}