From 00f5b53ea8ddeb32b50528c90f0cf88b9a1f6b59 Mon Sep 17 00:00:00 2001 From: n1rwana Date: Fri, 11 Aug 2023 20:39:40 +0300 Subject: [PATCH] =?UTF-8?q?API=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D1=82=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=B6=D0=B0=D0=BB=D0=BE=D0=B1?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VKAPI/Handlers/Reports.php | 41 ++++++++++++++++++++++++++++++ Web/Presenters/ReportPresenter.php | 3 +++ 2 files changed, 44 insertions(+) create mode 100644 VKAPI/Handlers/Reports.php diff --git a/VKAPI/Handlers/Reports.php b/VKAPI/Handlers/Reports.php new file mode 100644 index 00000000..104e3594 --- /dev/null +++ b/VKAPI/Handlers/Reports.php @@ -0,0 +1,41 @@ +requireUser(); + $this->willExecuteWriteAction(); + + if ($id <= 0) { + $this->fail(100, "ID must be a positive number"); + } + + if(mb_strlen(trim($reason)) === 0) { + $this->fail(100, "Reason can't be empty"); + } + + if ($type === "user" && $id === $this->getUser()->getId()) { + $this->fail(100, "You can't report yourself"); + } + + if(in_array($type, ["post", "photo", "video", "group", "comment", "note", "app", "user"])) { + if (count(iterator_to_array((new ReportsRepo)->getDuplicates($type, $id, NULL, $this->getUser()->getId()))) <= 0) { + $report = new Report; + $report->setUser_id($this->getUser()->getId()); + $report->setTarget_id($id); + $report->setType($type); + $report->setReason($reason); + $report->setCreated(time()); + $report->save(); + } + + return (object) [ "reason" => $reason ]; + } else { + $this->fail(3, "Unable to submit a report on this content type"); + } + } +} diff --git a/Web/Presenters/ReportPresenter.php b/Web/Presenters/ReportPresenter.php index 68d27861..2369ecb9 100644 --- a/Web/Presenters/ReportPresenter.php +++ b/Web/Presenters/ReportPresenter.php @@ -88,6 +88,9 @@ final class ReportPresenter extends OpenVKPresenter if(!$id) exit(json_encode([ "error" => tr("error_segmentation") ])); + if ($this->queryParam("type") === "user" && $id === $this->user->id) + exit(json_encode(["reason" => "You can't report yourself"])); + if(in_array($this->queryParam("type"), ["post", "photo", "video", "group", "comment", "note", "app", "user"])) { if (count(iterator_to_array($this->reports->getDuplicates($this->queryParam("type"), $id, NULL, $this->user->id))) <= 0) { $report = new Report;