This commit is contained in:
n1rwana 2024-12-10 14:24:51 +00:00 committed by GitHub
commit 1de1ebe719
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 57 additions and 1 deletions

View file

@ -0,0 +1,53 @@
<?php declare(strict_types=1);
namespace openvk\VKAPI\Handlers;
use openvk\Web\Models\Entities\Report;
use openvk\Web\Models\Repositories\Reports as ReportsRepo;
final class Reports extends VKAPIRequestHandler
{
function add(int $owner_id = 0, string $comment = "", int $reason = 0, string $type = "", string $report_source = ""): int
{
$this->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;
}
}

View file

@ -89,6 +89,9 @@ final class ReportPresenter extends OpenVKPresenter
if(!$id) if(!$id)
exit(json_encode([ "error" => tr("error_segmentation") ])); 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(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) {

View file

@ -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"}