add front-comments
This commit is contained in:
parent
c3ea78cab5
commit
c9f4af7e58
53 changed files with 2921 additions and 1 deletions
22
site/plugins/front-comments/routes/delete-comment.php
Normal file
22
site/plugins/front-comments/routes/delete-comment.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
function deleteComment()
|
||||
{
|
||||
$jsonRequest = file_get_contents("php://input");
|
||||
$request = json_decode($jsonRequest, true);
|
||||
|
||||
$dataFile = __DIR__ . '/../data/data.json';
|
||||
$jsonData = file_get_contents($dataFile);
|
||||
$data = json_decode($jsonData, true);
|
||||
|
||||
foreach ($data as $index => $item) {
|
||||
if ($item['id'] === $request['id']) {
|
||||
array_splice($data, $index, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
file_put_contents($dataFile, json_encode($data));
|
||||
|
||||
return json_encode($data);
|
||||
}
|
||||
32
site/plugins/front-comments/routes/store-comment.php
Normal file
32
site/plugins/front-comments/routes/store-comment.php
Normal 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue