mirror of
https://github.com/openvk/openvk
synced 2024-11-11 09:29:29 +03:00
Reports: Added report window
This commit is contained in:
parent
5380ad1b27
commit
1b2cf8f104
3 changed files with 50 additions and 32 deletions
|
@ -41,41 +41,31 @@ final class ReportPresenter extends OpenVKPresenter
|
|||
$this->template->report = $report;
|
||||
}
|
||||
|
||||
function renderCreate(): void
|
||||
function renderCreate(int $id): void
|
||||
{
|
||||
$this->assertUserLoggedIn();
|
||||
$this->willExecuteWriteAction();
|
||||
|
||||
// ЛАПСКИЙ Я НЕ ДО КОНЦА ДОДЕЛАЛ Я ПРОСТО МЫТЬСЯ ПОШЁЛ
|
||||
// А ВОТ ЩА ДОДЕЛАЮ
|
||||
// апд 01:00 по мск доделал фронт вроде!!!!
|
||||
if(!$id)
|
||||
$this->notFound();
|
||||
|
||||
if($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
if(empty($this->postParam("type")) && empty($this->postParam('id'))) {
|
||||
$this->flashFail("err", tr("error"), tr("error_segmentation"));
|
||||
}
|
||||
exit(json_encode([ "error" => tr("error_segmentation") ]));
|
||||
|
||||
// At this moment, only Posts will be implemented
|
||||
if($this->postParam("type") == 'posts') {
|
||||
$post = (new Posts)->get(intval($this->postParam("id")));
|
||||
if($this->queryParam("type") == 'posts') {
|
||||
$post = (new Posts)->get(intval($id));
|
||||
if(!$post)
|
||||
$this->flashFail("err", "Ага! Попался, гадёныш блядь!", "Нельзя отправить жалобу на несуществующий контент");
|
||||
exit(json_encode([ "error" => "Unable to report nonexistent content" ]));
|
||||
|
||||
$report = new Report;
|
||||
$report->setUser_id($this->user->id);
|
||||
$note->setContent_id($this->postParam("id"));
|
||||
$note->setReason($this->postParam("reason"));
|
||||
$note->setCreated(time());
|
||||
$note->setType($this->postParam("type"));
|
||||
$note->save();
|
||||
$report->setTarget_id($id);
|
||||
$report->setType($this->queryParam("type"));
|
||||
$report->setReason($this->queryParam("reason"));
|
||||
$report->setCreated(time());
|
||||
$report->save();
|
||||
|
||||
$this->flashFail("suc", "Жалоба отправлена", "Скоро её рассмотрят модераторы");
|
||||
exit(json_encode([ "reason" => $this->queryParam("reason") ]));
|
||||
} else {
|
||||
$this->flashFail("err", "Пока низя", "Нельзя отправить жалобу на данный тип контента");
|
||||
}
|
||||
|
||||
exit(json_encode([ "error" => "Unable to submit a report on this content type" ]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,7 +78,7 @@ final class ReportPresenter extends OpenVKPresenter
|
|||
if($this->postParam("ban")) {
|
||||
$report = $this->report->get($id);
|
||||
if(!$report) $this->notFound();
|
||||
if($note->isDeleted()) $this->notFound();
|
||||
if($report->isDeleted()) $this->notFound();
|
||||
if(is_null($this->user))
|
||||
$this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса.");
|
||||
|
||||
|
@ -98,7 +88,7 @@ final class ReportPresenter extends OpenVKPresenter
|
|||
}else if($this->postParam("delete")){
|
||||
$report = $this->report->get($id);
|
||||
if(!$report) $this->notFound();
|
||||
if($note->isDeleted()) $this->notFound();
|
||||
if($report->isDeleted()) $this->notFound();
|
||||
if(is_null($this->user))
|
||||
$this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса.");
|
||||
|
||||
|
|
|
@ -28,9 +28,35 @@
|
|||
<h4>{_actions}</h4>
|
||||
{if isset($thisUser)}
|
||||
{var canDelete = $post->canBeDeletedBy($thisUser)}
|
||||
{if $thisUser->getId() != $post->getOwner()->getId()}
|
||||
{var canReport = true}
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<a n:if="$canDelete ?? false" class="profile_link" style="display:block;width:96%;" href="/wall{$post->getPrettyId()}/delete">{_delete}</a>
|
||||
<a class="profile_link" style="display:block;width:96%;" href="/report.pl/{$post->getId()}?type=post">{_report}</a>
|
||||
<a n:if="$canReport ?? false" class="profile_link" style="display:block;width:96%;" href="javascript:reportPost()">{_report}</a>
|
||||
</div>
|
||||
<script n:if="$canReport ?? false">
|
||||
function reportPost() {
|
||||
uReportMsgTxt = "Вы собираетесь пожаловаться на данную запись.";
|
||||
uReportMsgTxt += "<br/>Что именно вам кажется недопустимым в этом материале?";
|
||||
uReportMsgTxt += "<br/><br/><b>Причина жалобы</b>: <input type='text' id='uReportMsgInput' placeholder='Причина' />"
|
||||
|
||||
MessageBox("Пожаловаться?", uReportMsgTxt, ["Подтвердить", "Отмена"], [
|
||||
(function() {
|
||||
res = document.querySelector("#uReportMsgInput").value;
|
||||
xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "/report.pl/" + {$post->getId()} + "?reason=" + res + "&type=posts", true);
|
||||
xhr.onload = (function() {
|
||||
if(xhr.responseText.indexOf("reason") === -1)
|
||||
MessageBox("Ошибка", "Не удалось подать жалобу...", ["OK"], [Function.noop]);
|
||||
else
|
||||
MessageBox("Операция успешна", "Скоро её рассмотрят модераторы", ["OK"], [Function.noop]);
|
||||
});
|
||||
xhr.send(null);
|
||||
}),
|
||||
Function.noop
|
||||
]);
|
||||
}
|
||||
</script>
|
||||
{/block}
|
||||
|
|
|
@ -219,6 +219,8 @@ routes:
|
|||
handler: "Report->view"
|
||||
- url: "/admin/reportAction{num}"
|
||||
handler: "Report->action"
|
||||
- url: "/report.pl/{num}"
|
||||
handler: "Report->create"
|
||||
- url: "/method/{text}.{text}"
|
||||
handler: "VKAPI->route"
|
||||
- url: "/token"
|
||||
|
|
Loading…
Reference in a new issue