From 2e70a262835cb28a40c0358a1bbcacd5efc1c43d Mon Sep 17 00:00:00 2001 From: n1rwana Date: Fri, 13 Dec 2024 17:11:26 +0300 Subject: [PATCH] feat(api): reports (#959) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * API для отправки жалобы * make compatible with vk api --------- Co-authored-by: mrilyew <99399973+mrilyew@users.noreply.github.com> --- VKAPI/Handlers/Reports.php | 53 +++++++++++++++++++ Web/Presenters/ReportPresenter.php | 3 ++ .../templates/Report/ViewContent.xml | 2 +- 3 files changed, 57 insertions(+), 1 deletion(-) 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..3a5a1d19 --- /dev/null +++ b/VKAPI/Handlers/Reports.php @@ -0,0 +1,53 @@ +requireUser(); + $this->willExecuteWriteAction(); + + $allowed_types = ["post", "photo", "video", "group", "comment", "note", "app", "user", "audio"]; + 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($owner_id <= 0) { + $this->fail(100, "One of the parameters specified was missing or invalid: Bad input"); + } + + if(mb_strlen($comment) === 0) { + $this->fail(100, "One of the parameters specified was missing or invalid: Comment can't be empty"); + } + + if($type == "user" && $owner_id == $this->getUser()->getId()) { + 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->setUser_id($this->getUser()->getId()); + $report->setTarget_id($owner_id); + $report->setType($type); + $report->setReason($comment); + $report->setCreated(time()); + + $report->save(); + } catch(\Throwable $e) { + $this->fail(-1, "Unknown error failed"); + } + + return 1; + } +} diff --git a/Web/Presenters/ReportPresenter.php b/Web/Presenters/ReportPresenter.php index a627efa4..dfd2b962 100644 --- a/Web/Presenters/ReportPresenter.php +++ b/Web/Presenters/ReportPresenter.php @@ -89,6 +89,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([ "error" => "You can't report yourself" ])); 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) { diff --git a/Web/Presenters/templates/Report/ViewContent.xml b/Web/Presenters/templates/Report/ViewContent.xml index 1f5918d5..677dc37b 100644 --- a/Web/Presenters/templates/Report/ViewContent.xml +++ b/Web/Presenters/templates/Report/ViewContent.xml @@ -16,7 +16,7 @@ {elseif $type == "group" || $type == "user"} {include "../components/group.xml", group => $object, isUser => $type == "user"} {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"} {include "./content/note.xml", note => $object} {elseif $type == "app"}