summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorsijanec <sijanecantonluka@gmail.com>2020-12-02 00:35:54 +0100
committersijanec <sijanecantonluka@gmail.com>2020-12-02 00:35:54 +0100
commit1137012367ace424cc44f04e829cb322882dfb14 (patch)
treec01a303832d39962d53a1cd25e57d55a165f8169 /api
parentlogic fix (diff)
downloadsijanec.eu-1137012367ace424cc44f04e829cb322882dfb14.tar
sijanec.eu-1137012367ace424cc44f04e829cb322882dfb14.tar.gz
sijanec.eu-1137012367ace424cc44f04e829cb322882dfb14.tar.bz2
sijanec.eu-1137012367ace424cc44f04e829cb322882dfb14.tar.lz
sijanec.eu-1137012367ace424cc44f04e829cb322882dfb14.tar.xz
sijanec.eu-1137012367ace424cc44f04e829cb322882dfb14.tar.zst
sijanec.eu-1137012367ace424cc44f04e829cb322882dfb14.zip
Diffstat (limited to 'api')
-rw-r--r--api/php/api.php13
1 files changed, 10 insertions, 3 deletions
diff --git a/api/php/api.php b/api/php/api.php
index c2893ac..6f82bc9 100644
--- a/api/php/api.php
+++ b/api/php/api.php
@@ -36,7 +36,7 @@
exit("400: Napaka. Preveč besedila - vzdevek je lahko dolg 256, sporočilo pa 1024 znakov.");
}
$datum = date("Y-m-d H:i:s");
- $cm = yaml_emit(array(
+ $cm = yaml_emit(array(array(
"author" => $vzdevek,
"date" => $datum,
"message" => $sporocilo,
@@ -44,12 +44,19 @@
"ip" => $_SERVER['REMOTE_ADDR'],
"addedby" => "PHP API 0.0.0",
"nonce" => hash('sha256', $vzdevek."|".$datum."|".random_bytes(69))
- ));
- $response = file_put_contents($commentsfile, $cm, FILE_APPEND); // pri append ni locka
+ )), YAML_UTF8_ENCODING, YAML_LN_BREAK);
+ $cmarray = explode("\n", $cm);
+ pop(pop(array_shift($cmarray)));
+ $cs = implode("\n", $cmarray)."\n";
+ $response = file_put_contents($commentsfile, $cs, FILE_APPEND); // pri append ni locka
if ($response === FALSE) {
http_response_code(500);
header("Content-Type: text/plain");
exit("500: Napaka. Komentarja ni uspelo zapisati.");
+ } else {
+ http_response_code(201);
+ header("Content-Type: text/plain");
+ exit("201: Uspelo! Komentar objavljen.");
}
break;
case "commentedit":