Проект ещё жив!
This commit is contained in:
@@ -2,46 +2,127 @@
|
||||
|
||||
require_once("../_auth.php");
|
||||
require_once("../_utils.php");
|
||||
require_once("../_errorslist.php");
|
||||
require_once("../_types.php");
|
||||
require_once("../user/index.php");
|
||||
|
||||
|
||||
|
||||
// Get comments from range of selected comment section
|
||||
function ComSec_Get ($sec_id, $ts_from, $ts_to) {
|
||||
global $db;
|
||||
// Functions
|
||||
|
||||
/*
|
||||
* FUNCTION
|
||||
* Get comments from range of selected comment section
|
||||
*/
|
||||
function Comments_GetSectionRange (int $sec_id, int $ts_from = 0, int $ts_to = 0xffffffff): ReturnT {
|
||||
global $db, $LOGGED_IN, $THIS_USER;
|
||||
|
||||
$result = array();
|
||||
|
||||
$s = $db->prepare("SELECT * FROM posts WHERE id = ?");
|
||||
$s->bind_param("s", $id);
|
||||
$s = $db->prepare("SELECT * FROM comments WHERE comment_section_id=? AND created_at>=? AND created_at<=? ORDER BY created_at");
|
||||
$s->bind_param("sss", $sec_id, date("Y-m-d H:i:s", $ts_from), date("Y-m-d H:i:s", $ts_to));
|
||||
$s->execute();
|
||||
$d = $s->get_result()->fetch_assoc();
|
||||
$d = $s->get_result();
|
||||
|
||||
if (!(bool)$d) {
|
||||
return null;
|
||||
if (!(bool)$d)
|
||||
return new ReturnT(data: $result);
|
||||
|
||||
$isAdmin = false;
|
||||
if ($LOGGED_IN && User_HasRole($THIS_USER, "admin")->GetData())
|
||||
$isAdmin = true;
|
||||
|
||||
while ($row = $d->fetch_array()) {
|
||||
if (!$isAdmin && $row["needs_check"])
|
||||
continue;
|
||||
|
||||
$newResultRow = array(
|
||||
"id" => $row["id"],
|
||||
"author_id" => $row["author_id"],
|
||||
"created_at" => $row["created_at"],
|
||||
"contents" => $row["contents"]
|
||||
);
|
||||
|
||||
if ($isAdmin)
|
||||
$newResultRow["needs_check"] = (bool)$row["needs_check"];
|
||||
|
||||
$result[] = $newResultRow;
|
||||
}
|
||||
|
||||
return new ReturnT(data: $result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (ThisFileIsRequested(__FILE__)) {
|
||||
require_once("../_json.php");
|
||||
// Methods
|
||||
|
||||
/*
|
||||
* METHOD
|
||||
* Get comments from range of selected comment section
|
||||
*/
|
||||
function Comments_GetSectionRange_Method (array $req): ReturnT {
|
||||
// Input sanity checks
|
||||
|
||||
$SectionID = null;
|
||||
$TSFrom = 0;
|
||||
$TSTo = 0xffffffff;
|
||||
|
||||
if (isset($_REQUEST["id"])) {
|
||||
if (!ctype_digit($_REQUEST["id"]))
|
||||
ReturnJSONError($Err_RDP_InvalidID, "id must be numeric");
|
||||
$SectionID = intval($_REQUEST["id"]);
|
||||
if (isset($req["id"])) {
|
||||
if (!ctype_digit($req["id"]))
|
||||
return new ReturnT(err_code: E_UIN_BADARGS, err_desc: "id must be numeric");
|
||||
$SectionID = intval($req["id"]);
|
||||
} else {
|
||||
ReturnJSONError($Err_RDP_InvalidID, "id must be specified");
|
||||
return new ReturnT(err_code: E_UIN_INSUFARGS, err_desc: "id must be specified");
|
||||
}
|
||||
|
||||
/*
|
||||
$ResponseData = ComSec_GetComms($SectionID);
|
||||
if ($ResponseData)
|
||||
ReturnJSONData($ResponseData);
|
||||
if (isset($req["ts_from"])) {
|
||||
$TSFrom = $req["ts_from"];
|
||||
|
||||
if (strlen($TSFrom) > 24)
|
||||
return new ReturnT(err_code: E_UIN_BADARGS, err_desc: "start timestamp cant be this long");
|
||||
|
||||
if (!ctype_digit($TSFrom))
|
||||
return new ReturnT(err_code: E_UIN_BADARGS, err_desc: "start timestamp must be numeric");
|
||||
|
||||
$TSFrom = intval($TSFrom);
|
||||
|
||||
if ($TSFrom > 0xffffffff)
|
||||
return new ReturnT(err_code: E_UIN_BADARGS, err_desc: "start timestamp cant be bigger than INT32_MAX");
|
||||
}
|
||||
|
||||
if (isset($req["ts_to"])) {
|
||||
$TSTo = $req["ts_to"];
|
||||
|
||||
if (strlen($TSTo) > 24)
|
||||
return new ReturnT(err_code: E_UIN_BADARGS, err_desc: "start timestamp cant be this long");
|
||||
|
||||
if (!ctype_digit($TSTo))
|
||||
return new ReturnT(err_code: E_UIN_BADARGS, err_desc: "start timestamp must be numeric");
|
||||
|
||||
$TSTo = intval($TSTo);
|
||||
|
||||
if ($TSTo > 0xffffffff)
|
||||
return new ReturnT(err_code: E_UIN_BADARGS, err_desc: "start timestamp cant be bigger than INT32_MAX");
|
||||
}
|
||||
|
||||
if ($TSTo < $TSFrom)
|
||||
return new ReturnT(err_code: E_UIN_BADARGS, err_desc: "start timestamp cant be bigger than end timestamp");
|
||||
|
||||
// Actions
|
||||
|
||||
return Comments_GetSectionRange($SectionID, $TSFrom, $TSTo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (Utils_ThisFileIsRequested(__FILE__)) {
|
||||
require_once("../_json.php");
|
||||
|
||||
$result = Comments_GetSectionRange_Method($_REQUEST);
|
||||
|
||||
if ($result->IsError())
|
||||
$result->ThrowJSONError();
|
||||
else
|
||||
ReturnJSONError($Err_DP_IDNotFound, "wrong id");
|
||||
*/
|
||||
JSON_ReturnData($result->GetData());
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user