2024-01-13 03:24:42 +03:00
|
|
|
<?php
|
|
|
|
// Get all comments from comment section by ID and base methods for managing comment sections
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Includes
|
|
|
|
if ($IS_FRONTEND) {
|
|
|
|
require_once("api/_auth.php");
|
|
|
|
require_once("api/_utils.php");
|
|
|
|
require_once("api/_errorslist.php");
|
|
|
|
require_once("api/_types.php");
|
|
|
|
require_once("api/user/index.php");
|
|
|
|
} else {
|
|
|
|
require_once("../_auth.php");
|
|
|
|
require_once("../_utils.php");
|
|
|
|
require_once("../_errorslist.php");
|
|
|
|
require_once("../_types.php");
|
|
|
|
require_once("../user/index.php");
|
|
|
|
}
|
2023-10-31 21:57:17 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-12-20 06:08:13 +03:00
|
|
|
// 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;
|
2023-10-31 21:57:17 +03:00
|
|
|
|
|
|
|
$result = array();
|
|
|
|
|
2023-12-20 06:08:13 +03:00
|
|
|
$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));
|
2023-10-31 21:57:17 +03:00
|
|
|
$s->execute();
|
2023-12-20 06:08:13 +03:00
|
|
|
$d = $s->get_result();
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2023-10-31 21:57:17 +03:00
|
|
|
|
2023-12-20 06:08:13 +03:00
|
|
|
return new ReturnT(data: $result);
|
2023-10-31 21:57:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-12-20 06:08:13 +03:00
|
|
|
// Methods
|
|
|
|
|
|
|
|
/*
|
|
|
|
* METHOD
|
|
|
|
* Get comments from range of selected comment section
|
|
|
|
*/
|
|
|
|
function Comments_GetSectionRange_Method (array $req): ReturnT {
|
|
|
|
// Input sanity checks
|
2023-10-31 21:57:17 +03:00
|
|
|
|
|
|
|
$SectionID = null;
|
2023-12-20 06:08:13 +03:00
|
|
|
$TSFrom = 0;
|
|
|
|
$TSTo = 0xffffffff;
|
2023-10-31 21:57:17 +03:00
|
|
|
|
2023-12-20 06:08:13 +03:00
|
|
|
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"]);
|
2023-10-31 21:57:17 +03:00
|
|
|
} else {
|
2023-12-20 06:08:13 +03:00
|
|
|
return new ReturnT(err_code: E_UIN_INSUFARGS, err_desc: "id must be specified");
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
2023-10-31 21:57:17 +03:00
|
|
|
}
|
|
|
|
|
2023-12-20 06:08:13 +03:00
|
|
|
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();
|
2023-10-31 21:57:17 +03:00
|
|
|
else
|
2023-12-20 06:08:13 +03:00
|
|
|
JSON_ReturnData($result->GetData());
|
2023-10-31 21:57:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|