Part of API related to posts development started
This commit is contained in:
64
api/post/index.php
Normal file
64
api/post/index.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php // Get single post by ID
|
||||
|
||||
require_once("../_auth.php");
|
||||
require_once("../_utils.php");
|
||||
|
||||
|
||||
|
||||
// Get single publication by ID
|
||||
function Post_GetByID ($id) {
|
||||
global $db;
|
||||
|
||||
$result = array();
|
||||
|
||||
$s = $db->prepare("SELECT * FROM posts WHERE id = ?");
|
||||
$s->bind_param("s", $id);
|
||||
$s->execute();
|
||||
$d = $s->get_result()->fetch_assoc();
|
||||
|
||||
if (!(bool)$d) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$result["id"] = $d["id"];
|
||||
$result["author_id"] = $d["author_id"];
|
||||
if ($d["comments_enabled"])
|
||||
$result["comment_section_id"] = $d["comment_section_id"];
|
||||
$result["created_at"] = $d["created_at"];
|
||||
$result["tags"] = $d["tags"];
|
||||
$result["title"] = $d["title"];
|
||||
$result["votes_up"] = $d["votes_up"];
|
||||
$result["votes_down"] = $d["votes_down"];
|
||||
$result["views"] = $d["views"] + 1;
|
||||
$result["pic_path"] = $d["pic_path"];
|
||||
$result["preview_path"] = $d["preview_path"];
|
||||
$result["edit_lock"] = $d["edit_lock"];
|
||||
|
||||
// TODO: increment views of post
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (ThisFileIsRequested(__FILE__)) {
|
||||
require_once("../_json.php");
|
||||
|
||||
if (isset($_REQUEST["id"])) {
|
||||
if (!ctype_digit($_REQUEST["id"]))
|
||||
ReturnJSONError($Err_RDP_InvalidID, "id must be numeric");
|
||||
$UserID = intval($_REQUEST["id"]);
|
||||
} else {
|
||||
ReturnJSONError($Err_RDP_InvalidID, "id must be specified");
|
||||
}
|
||||
|
||||
// TODO: check permissions
|
||||
|
||||
$ResponseData = Post_GetByID($_REQUEST["id"]);
|
||||
if ($ResponseData)
|
||||
ReturnJSONData($ResponseData);
|
||||
else
|
||||
ReturnJSONError($Err_DP_IDNotFound, "wrong id");
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user