-
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into n1rwana-geo
- Loading branch information
Showing
26 changed files
with
512 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.