From 00f5b53ea8ddeb32b50528c90f0cf88b9a1f6b59 Mon Sep 17 00:00:00 2001 From: n1rwana Date: Fri, 11 Aug 2023 20:39:40 +0300 Subject: [PATCH 1/2] =?UTF-8?q?API=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D1=82?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=B6=D0=B0=D0=BB=D0=BE?= =?UTF-8?q?=D0=B1=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; From 7197863f00283a5f3d6eec2e8892554042d7052e Mon Sep 17 00:00:00 2001 From: mrilyew <99399973+mrilyew@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:24:32 +0300 Subject: [PATCH 2/2] make compatible with vk api --- VKAPI/Handlers/Reports.php | 54 +++++++++++-------- Web/Presenters/ReportPresenter.php | 2 +- .../templates/Report/ViewContent.xml | 2 +- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/VKAPI/Handlers/Reports.php b/VKAPI/Handlers/Reports.php index 104e3594..3a5a1d19 100644 --- a/VKAPI/Handlers/Reports.php +++ b/VKAPI/Handlers/Reports.php @@ -5,37 +5,49 @@ use openvk\Web\Models\Repositories\Reports as ReportsRepo; 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->willExecuteWriteAction(); - if ($id <= 0) { - $this->fail(100, "ID must be a positive number"); + $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(mb_strlen(trim($reason)) === 0) { - $this->fail(100, "Reason can't be empty"); + if($owner_id <= 0) { + $this->fail(100, "One of the parameters specified was missing or invalid: Bad input"); } - if ($type === "user" && $id === $this->getUser()->getId()) { - $this->fail(100, "You can't report yourself"); + if(mb_strlen($comment) === 0) { + $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 (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"); + 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 2e762a8c..dfd2b962 100644 --- a/Web/Presenters/ReportPresenter.php +++ b/Web/Presenters/ReportPresenter.php @@ -91,7 +91,7 @@ final class ReportPresenter extends OpenVKPresenter 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"])); + 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"}