diff options
-rw-r--r-- | api/php/api.php | 13 |
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": |