mirror of
https://github.com/openvk/openvk
synced 2024-12-23 00:51:03 +03:00
make compatible with vk api
This commit is contained in:
parent
63c5df579e
commit
7197863f00
3 changed files with 35 additions and 23 deletions
|
@ -5,37 +5,49 @@ use openvk\Web\Models\Repositories\Reports as ReportsRepo;
|
||||||
|
|
||||||
final class Reports extends VKAPIRequestHandler
|
final class Reports extends VKAPIRequestHandler
|
||||||
{
|
{
|
||||||
function add(string $type, int $id, string $reason): object
|
function add(int $owner_id = 0, string $comment = "", int $reason = 0, string $type = "", string $report_source = ""): int
|
||||||
{
|
{
|
||||||
$this->requireUser();
|
$this->requireUser();
|
||||||
$this->willExecuteWriteAction();
|
$this->willExecuteWriteAction();
|
||||||
|
|
||||||
if ($id <= 0) {
|
$allowed_types = ["post", "photo", "video", "group", "comment", "note", "app", "user", "audio"];
|
||||||
$this->fail(100, "ID must be a positive number");
|
if($type == "" || !in_array($type, $allowed_types)) {
|
||||||
|
$this->fail(100, "One of the parameters specified was missing or invalid: type should be ".implode(", ", $allowed_types));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mb_strlen(trim($reason)) === 0) {
|
if($owner_id <= 0) {
|
||||||
$this->fail(100, "Reason can't be empty");
|
$this->fail(100, "One of the parameters specified was missing or invalid: Bad input");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($type === "user" && $id === $this->getUser()->getId()) {
|
if(mb_strlen($comment) === 0) {
|
||||||
$this->fail(100, "You can't report yourself");
|
$this->fail(100, "One of the parameters specified was missing or invalid: Comment can't be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(in_array($type, ["post", "photo", "video", "group", "comment", "note", "app", "user"])) {
|
if($type == "user" && $owner_id == $this->getUser()->getId()) {
|
||||||
if (count(iterator_to_array((new ReportsRepo)->getDuplicates($type, $id, NULL, $this->getUser()->getId()))) <= 0) {
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->getUser()->isBannedInSupport()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sizeof(iterator_to_array((new ReportsRepo)->getDuplicates($type, $owner_id, NULL, $this->getUser()->getId()))) > 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
$report = new Report;
|
$report = new Report;
|
||||||
$report->setUser_id($this->getUser()->getId());
|
$report->setUser_id($this->getUser()->getId());
|
||||||
$report->setTarget_id($id);
|
$report->setTarget_id($owner_id);
|
||||||
$report->setType($type);
|
$report->setType($type);
|
||||||
$report->setReason($reason);
|
$report->setReason($comment);
|
||||||
$report->setCreated(time());
|
$report->setCreated(time());
|
||||||
|
|
||||||
$report->save();
|
$report->save();
|
||||||
|
} catch(\Throwable $e) {
|
||||||
|
$this->fail(-1, "Unknown error failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
return (object) [ "reason" => $reason ];
|
return 1;
|
||||||
} else {
|
|
||||||
$this->fail(3, "Unable to submit a report on this content type");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ final class ReportPresenter extends OpenVKPresenter
|
||||||
exit(json_encode([ "error" => tr("error_segmentation") ]));
|
exit(json_encode([ "error" => tr("error_segmentation") ]));
|
||||||
|
|
||||||
if ($this->queryParam("type") === "user" && $id === $this->user->id)
|
if ($this->queryParam("type") === "user" && $id === $this->user->id)
|
||||||
exit(json_encode(["reason" => "You can't report yourself"]));
|
exit(json_encode([ "error" => "You can't report yourself" ]));
|
||||||
|
|
||||||
if(in_array($this->queryParam("type"), ["post", "photo", "video", "group", "comment", "note", "app", "user", "audio"])) {
|
if(in_array($this->queryParam("type"), ["post", "photo", "video", "group", "comment", "note", "app", "user", "audio"])) {
|
||||||
if (count(iterator_to_array($this->reports->getDuplicates($this->queryParam("type"), $id, NULL, $this->user->id))) <= 0) {
|
if (count(iterator_to_array($this->reports->getDuplicates($this->queryParam("type"), $id, NULL, $this->user->id))) <= 0) {
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
{elseif $type == "group" || $type == "user"}
|
{elseif $type == "group" || $type == "user"}
|
||||||
{include "../components/group.xml", group => $object, isUser => $type == "user"}
|
{include "../components/group.xml", group => $object, isUser => $type == "user"}
|
||||||
{elseif $type == "comment"}
|
{elseif $type == "comment"}
|
||||||
{include "../components/comment.xml", comment => $object, timeOnly => true, linkWithPost => true}
|
{include "../components/comment.xml", comment => $object, timeOnly => true, correctLink => true}
|
||||||
{elseif $type == "note"}
|
{elseif $type == "note"}
|
||||||
{include "./content/note.xml", note => $object}
|
{include "./content/note.xml", note => $object}
|
||||||
{elseif $type == "app"}
|
{elseif $type == "app"}
|
||||||
|
|
Loading…
Reference in a new issue