diff --git a/Web/Presenters/AdminPresenter.php b/Web/Presenters/AdminPresenter.php index ff21612b..ed1f55eb 100644 --- a/Web/Presenters/AdminPresenter.php +++ b/Web/Presenters/AdminPresenter.php @@ -128,7 +128,8 @@ final class AdminPresenter extends OpenVKPresenter $club->save(); break; case "ban": - $club->setBlock_reason($this->postParam("ban_reason")); + $reason = mb_strlen(trim($this->postParam("ban_reason"))) > 0 ? $this->postParam("ban_reason") : NULL; + $club->setBlock_reason($reason); $club->save(); break; } diff --git a/Web/Presenters/CommentPresenter.php b/Web/Presenters/CommentPresenter.php index e75d7563..002b27ef 100644 --- a/Web/Presenters/CommentPresenter.php +++ b/Web/Presenters/CommentPresenter.php @@ -23,8 +23,13 @@ final class CommentPresenter extends OpenVKPresenter $comment = (new Comments)->get($id); if(!$comment || $comment->isDeleted()) $this->notFound(); - if (!($comment->getTarget() instanceof Post && $comment->getTarget()->getOwner() instanceof User && $comment->getTarget()->getOwner()->isServiceAccount())) + if (!($comment->getTarget() instanceof Post && $comment->getTarget()->getOwner() instanceof User && ($comment->getTarget()->getOwner()->isServiceAccount())) if(!is_null($this->user)) $comment->toggleLike($this->user->identity); + + if ($comment->getTarget() instanceof Post && $comment->getTarget()->getWallOwner()->isBanned()) + $this->flashFail("err", tr("error"), tr("forbidden")); + + if(!is_null($this->user)) $comment->toggleLike($this->user->identity); $this->redirect($_SERVER["HTTP_REFERER"]); } @@ -49,7 +54,7 @@ final class CommentPresenter extends OpenVKPresenter else if($entity instanceof Topic) $club = $entity->getClub(); - if ($entity instanceof Post && $entity->getOwner()->isServiceAccount()) + if ($entity instanceof Post && ($entity->getOwner()->isServiceAccount() || $entity->getWallOwner()->isBanned())) $this->flashFail("err", tr("error"), tr("forbidden")); if($_FILES["_vid_attachment"] && OPENVK_ROOT_CONF['openvk']['preferences']['videos']['disableUploading']) @@ -134,7 +139,9 @@ final class CommentPresenter extends OpenVKPresenter if(!$comment) $this->notFound(); if(!$comment->canBeDeletedBy($this->user->identity) || ($comment->getTarget() instanceof Post && $comment->getTarget()->getOwner() instanceof User && $comment->getTarget()->getOwner()->isServiceAccount())) $this->throwError(403, "Forbidden", "У вас недостаточно прав чтобы редактировать этот ресурс."); - + if ($comment->getTarget() instanceof Post && $comment->getTarget()->getWallOwner()->isBanned()) + $this->flashFail("err", tr("error"), tr("forbidden")); + $comment->delete(); $this->flashFail( "succ", diff --git a/Web/Presenters/GroupPresenter.php b/Web/Presenters/GroupPresenter.php index 4f671df3..d8fbcb79 100644 --- a/Web/Presenters/GroupPresenter.php +++ b/Web/Presenters/GroupPresenter.php @@ -24,10 +24,14 @@ final class GroupPresenter extends OpenVKPresenter if(!$club) { $this->notFound(); } else { - $this->template->albums = (new Albums)->getClubAlbums($club, 1, 3); - $this->template->albumsCount = (new Albums)->getClubAlbumsCount($club); - $this->template->topics = (new Topics)->getLastTopics($club, 3); - $this->template->topicsCount = (new Topics)->getClubTopicsCount($club); + if ($club->isBanned()) { + $this->template->_template = "Group/Banned.xml"; + } else { + $this->template->albums = (new Albums)->getClubAlbums($club, 1, 3); + $this->template->albumsCount = (new Albums)->getClubAlbumsCount($club); + $this->template->topics = (new Topics)->getLastTopics($club, 3); + $this->template->topicsCount = (new Topics)->getClubTopicsCount($club); + } $this->template->club = $club; } @@ -39,7 +43,7 @@ final class GroupPresenter extends OpenVKPresenter $this->willExecuteWriteAction(); if($_SERVER["REQUEST_METHOD"] === "POST") { - if(!empty($this->postParam("name"))) + if(!empty($this->postParam("name")) && mb_strlen(trim($this->postParam("name"))) > 0) { $club = new Club; $club->setName($this->postParam("name")); @@ -72,6 +76,7 @@ final class GroupPresenter extends OpenVKPresenter $club = $this->clubs->get((int) $this->postParam("id")); if(!$club) exit("Invalid state"); + if ($club->isBanned()) $this->flashFail("err", tr("error"), tr("forbidden")); $club->toggleSubscription($this->user->identity); @@ -83,6 +88,8 @@ final class GroupPresenter extends OpenVKPresenter $this->assertUserLoggedIn(); $this->template->club = $this->clubs->get($id); + if ($this->template->club->isBanned()) $this->flashFail("err", tr("error"), tr("forbidden")); + $this->template->onlyShowManagers = $this->queryParam("onlyAdmins") == "1"; if($this->template->onlyShowManagers) { $this->template->followers = NULL; @@ -118,6 +125,8 @@ final class GroupPresenter extends OpenVKPresenter $this->badRequest(); $club = $this->clubs->get($id); + if ($club->isBanned()) $this->flashFail("err", tr("error"), tr("forbidden")); + $user = (new Users)->get((int) $user); if(!$user || !$club) $this->notFound(); @@ -194,6 +203,8 @@ final class GroupPresenter extends OpenVKPresenter $club = $this->clubs->get($id); if(!$club || !$club->canBeModifiedBy($this->user->identity)) $this->notFound(); + else if ($club->isBanned()) + $this->flashFail("err", tr("error"), tr("forbidden")); else $this->template->club = $club; @@ -201,7 +212,7 @@ final class GroupPresenter extends OpenVKPresenter if(!$club->setShortcode( empty($this->postParam("shortcode")) ? NULL : $this->postParam("shortcode") )) $this->flashFail("err", tr("error"), tr("error_shorturl_incorrect")); - $club->setName(empty($this->postParam("name")) ? $club->getName() : $this->postParam("name")); + $club->setName((empty($this->postParam("name")) || mb_strlen(trim($this->postParam("name"))) === 0) ? $club->getName() : $this->postParam("name")); $club->setAbout(empty($this->postParam("about")) ? NULL : $this->postParam("about")); $club->setWall(empty($this->postParam("wall")) ? 0 : 1); $club->setAdministrators_List_Display(empty($this->postParam("administrators_list_display")) ? 0 : $this->postParam("administrators_list_display")); @@ -255,6 +266,7 @@ final class GroupPresenter extends OpenVKPresenter { $photo = new Photo; $club = $this->clubs->get($id); + if ($club->isBanned()) $this->flashFail("err", tr("error"), tr("forbidden")); if($_SERVER["REQUEST_METHOD"] === "POST" && $_FILES["ava"]["error"] === UPLOAD_ERR_OK) { try { $anon = OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["anonymousPosting"]["enable"]; @@ -343,6 +355,8 @@ final class GroupPresenter extends OpenVKPresenter $club = $this->clubs->get($id); if(!$club->canBeModifiedBy($this->user->identity)) $this->notFound(); + else if ($club->isBanned()) + $this->flashFail("err", tr("error"), tr("forbidden")); else $this->template->club = $club; @@ -375,6 +389,7 @@ final class GroupPresenter extends OpenVKPresenter $this->flashFail("err", tr("error"), tr("incorrect_password")); $club = $this->clubs->get($id); + if ($club->isBanned()) $this->flashFail("err", tr("error"), tr("forbidden")); $newOwner = (new Users)->get($newOwnerId); if($this->user->id !== $club->getOwner()->getId()) $this->flashFail("err", tr("error"), tr("forbidden")); diff --git a/Web/Presenters/PhotosPresenter.php b/Web/Presenters/PhotosPresenter.php index 18e5fccd..4e6b9d83 100644 --- a/Web/Presenters/PhotosPresenter.php +++ b/Web/Presenters/PhotosPresenter.php @@ -66,7 +66,7 @@ final class PhotosPresenter extends OpenVKPresenter } if($_SERVER["REQUEST_METHOD"] === "POST") { - if(empty($this->postParam("name"))) + if(empty($this->postParam("name")) || mb_strlen(trim($this->postParam("name"))) === 0) $this->flashFail("err", tr("error"), tr("error_segmentation")); else if(strlen($this->postParam("name")) > 36) $this->flashFail("err", tr("error"), tr("error_data_too_big", "name", 36, "bytes")); @@ -101,7 +101,7 @@ final class PhotosPresenter extends OpenVKPresenter if(strlen($this->postParam("name")) > 36) $this->flashFail("err", tr("error"), tr("error_data_too_big", "name", 36, "bytes")); - $album->setName(empty($this->postParam("name")) ? $album->getName() : $this->postParam("name")); + $album->setName((empty($this->postParam("name")) || mb_strlen(trim($this->postParam("name"))) === 0) ? $album->getName() : $this->postParam("name")); $album->setDescription(empty($this->postParam("desc")) ? NULL : $this->postParam("desc")); $album->setEdited(time()); $album->save(); diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index d89fc407..2d58e84b 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -46,13 +46,13 @@ final class WallPresenter extends OpenVKPresenter function renderWall(int $user, bool $embedded = false): void { $owner = ($user < 0 ? (new Clubs) : (new Users))->get(abs($user)); + if ($owner->isBanned()) + $this->flashFail("err", tr("error"), tr("forbidden")); + if(is_null($this->user)) { $canPost = false; } else if($user > 0) { - if(!$owner->isBanned()) - $canPost = $owner->getPrivacyPermission("wall.write", $this->user->identity); - else - $this->flashFail("err", tr("error"), tr("forbidden")); + $canPost = $owner->getPrivacyPermission("wall.write", $this->user->identity); } else if($user < 0) { if($owner->canBeModifiedBy($this->user->identity)) $canPost = true; @@ -103,6 +103,8 @@ final class WallPresenter extends OpenVKPresenter } else if($user < 0) { if($owner->canBeModifiedBy($this->user->identity)) $canPost = true; + else if ($owner->isBanned()) + $this->flashFail("err", tr("error"), tr("forbidden")); else $canPost = $owner->canPost(); } else { @@ -216,14 +218,11 @@ final class WallPresenter extends OpenVKPresenter $wallOwner = ($wall > 0 ? (new Users)->get($wall) : (new Clubs)->get($wall * -1)) ?? $this->flashFail("err", tr("failed_to_publish_post"), tr("error_4")); - if ($wallOwner instanceof User && $wallOwner->isServiceAccount()) + if ($wallOwner instanceof User && ($wallOwner->isServiceAccount() || $wallOwner->isBanned())) $this->flashFail("err", tr("error"), tr("forbidden")); if($wall > 0) { - if(!$wallOwner->isBanned()) - $canPost = $wallOwner->getPrivacyPermission("wall.write", $this->user->identity); - else - $this->flashFail("err", tr("not_enough_permissions"), tr("not_enough_permissions_comment")); + $canPost = $wallOwner->getPrivacyPermission("wall.write", $this->user->identity); } else if($wall < 0) { if($wallOwner->canBeModifiedBy($this->user->identity)) $canPost = true; @@ -364,6 +363,9 @@ final class WallPresenter extends OpenVKPresenter } else { $this->template->wallOwner = (new Clubs)->get(abs($post->getTargetWall())); $this->template->isWallOfGroup = true; + + if ($this->template->wallOwner->isBanned()) + $this->flashFail("err", tr("error"), tr("forbidden")); } $this->template->cCount = $post->getCommentsCount(); $this->template->cPage = (int) ($_GET["p"] ?? 1); @@ -377,8 +379,12 @@ final class WallPresenter extends OpenVKPresenter $this->assertNoCSRF(); $post = $this->posts->getPostById($wall, $post_id); + if(!$post || $post->isDeleted() || ($post->getOwner() instanceof User && $post->getOwner()->isServiceAccount())) $this->notFound(); - + + if ($post->getWallOwner()->isBanned()) + $this->flashFail("err", tr("error"), tr("forbidden")); + if(!is_null($this->user)) { $post->toggleLike($this->user->identity); } @@ -396,6 +402,9 @@ final class WallPresenter extends OpenVKPresenter if(!$post || $post->isDeleted() || ($post->getOwner() instanceof User && $post->getOwner()->isServiceAccount())) $this->notFound(); + + if ($post->getWallOwner()->isBanned()) + $this->flashFail("err", tr("error"), tr("forbidden")); $where = $this->postParam("type") ?? "wall"; $groupId = NULL; @@ -454,6 +463,9 @@ final class WallPresenter extends OpenVKPresenter $wallOwner = ($wall > 0 ? (new Users)->get($wall) : (new Clubs)->get($wall * -1)) ?? $this->flashFail("err", tr("failed_to_delete_post"), tr("error_4")); + if ($wallOwner->isBanned()) + $this->flashFail("err", tr("error"), tr("forbidden")); + if($wall < 0) $canBeDeletedByOtherUser = $wallOwner->canBeModifiedBy($this->user->identity); else $canBeDeletedByOtherUser = false; @@ -477,6 +489,9 @@ final class WallPresenter extends OpenVKPresenter $post = $this->posts->getPostById($wall, $post_id); if(!$post) $this->notFound(); + + if ($post->getWallOwner()->isBanned()) + $this->flashFail("err", tr("error"), tr("forbidden")); if(!$post->canBePinnedBy($this->user->identity)) $this->flashFail("err", tr("not_enough_permissions"), tr("not_enough_permissions_comment")); diff --git a/Web/Presenters/templates/Group/Banned.xml b/Web/Presenters/templates/Group/Banned.xml new file mode 100644 index 00000000..152bf10f --- /dev/null +++ b/Web/Presenters/templates/Group/Banned.xml @@ -0,0 +1,22 @@ +{extends "../@layout.xml"} + +{block title}{$club->getCanonicalName()}{/block} + +{block header}{include title}{/block} + +{block content} +
+ {tr("group_banned", htmlentities($club->getCanonicalName()))|noescape}
+
+ {_user_banned_comment} {$club->getBanReason()}.
+
+
+ {_edit}
+