Начал делать API для постов
This commit is contained in:
36
api/post/create.php
Normal file
36
api/post/create.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php // Create new post
|
||||
|
||||
require_once("../_auth.php");
|
||||
require_once("../_utils.php");
|
||||
|
||||
|
||||
|
||||
// Create single publication
|
||||
function Post_Create ($author, $tags, $pic_path, $title = null, $prev_path = null, $comms_enabled = false, $edit_lock = false) {
|
||||
global $db;
|
||||
|
||||
// $s = $db->prepare("INSERT ...");
|
||||
// $s->bind_param("s", $author);
|
||||
// $s->execute();
|
||||
// $d = $s->get_result()->fetch_assoc();
|
||||
//
|
||||
// if (!(bool)$d) {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (ThisFileIsRequested(__FILE__)) {
|
||||
require_once("../_json.php");
|
||||
|
||||
// Check if there are necessary input
|
||||
if (!(isset($_POST["tags"]) && isset($_FILES["pic"])))
|
||||
ReturnJSONError($Err_RDP_InvalidArgs, "not enough arguments");
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
?>
|
@@ -5,6 +5,21 @@ require_once("../_utils.php");
|
||||
|
||||
|
||||
|
||||
// Increment number of views for post
|
||||
function Post_AddView ($id) {
|
||||
global $db;
|
||||
|
||||
$s = $db->prepare("UPDATE posts SET views = views + 1 WHERE id = ?");
|
||||
$s->bind_param("s", $id);
|
||||
$s->execute();
|
||||
$d = $s->get_result()->fetch_assoc();
|
||||
|
||||
if (!(bool)$d) {
|
||||
require_once("../_json.php");
|
||||
ReturnJSONError($Err_Int_Unexpected, "failed to increment number of views");
|
||||
}
|
||||
}
|
||||
|
||||
// Get single publication by ID
|
||||
function Post_GetByID ($id) {
|
||||
global $db;
|
||||
@@ -34,7 +49,7 @@ function Post_GetByID ($id) {
|
||||
$result["preview_path"] = $d["preview_path"];
|
||||
$result["edit_lock"] = $d["edit_lock"];
|
||||
|
||||
// TODO: increment views of post
|
||||
Post_AddView($id);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user