Merge branch 'suggests' of https://github.com/lalka2016/openvkuh into suggests

This commit is contained in:
lalka2016 2023-08-09 16:38:11 +03:00
commit e9a0b5ab19
15 changed files with 96 additions and 26 deletions

View file

@ -289,7 +289,7 @@ class Club extends RowModel
return false; return false;
} }
return $query; return $query->group("follower");
} }
function getFollowersCount(): int function getFollowersCount(): int

View file

@ -84,7 +84,7 @@ abstract class Postable extends Attachable
return sizeof(DB::i()->getContext()->table("likes")->where([ return sizeof(DB::i()->getContext()->table("likes")->where([
"model" => static::class, "model" => static::class,
"target" => $this->getRecord()->id, "target" => $this->getRecord()->id,
])); ])->group("origin"));
} }
# TODO add pagination # TODO add pagination

View file

@ -39,10 +39,13 @@ class User extends RowModel
$query = "SELECT id FROM\n" . file_get_contents(__DIR__ . "/../sql/$filename.tsql"); $query = "SELECT id FROM\n" . file_get_contents(__DIR__ . "/../sql/$filename.tsql");
$query .= "\n LIMIT " . $limit . " OFFSET " . ( ($page - 1) * $limit ); $query .= "\n LIMIT " . $limit . " OFFSET " . ( ($page - 1) * $limit );
$ids = [];
$rels = DatabaseConnection::i()->getConnection()->query($query, $id, $id); $rels = DatabaseConnection::i()->getConnection()->query($query, $id, $id);
foreach($rels as $rel) { foreach($rels as $rel) {
$rel = (new Users)->get($rel->id); $rel = (new Users)->get($rel->id);
if(!$rel) continue; if(!$rel) continue;
if(in_array($rel->getId(), $ids)) continue;
$ids[] = $rel->getId();
yield $rel; yield $rel;
} }

View file

@ -1,4 +1,4 @@
(SELECT follower AS __id FROM (SELECT DISTINCT(follower) AS __id FROM
(SELECT follower FROM subscriptions WHERE target=? AND model="openvk\\Web\\Models\\Entities\\User") u0 (SELECT follower FROM subscriptions WHERE target=? AND model="openvk\\Web\\Models\\Entities\\User") u0
LEFT JOIN LEFT JOIN
(SELECT target FROM subscriptions WHERE follower=? AND model="openvk\\Web\\Models\\Entities\\User") u1 (SELECT target FROM subscriptions WHERE follower=? AND model="openvk\\Web\\Models\\Entities\\User") u1

View file

@ -1,4 +1,4 @@
(SELECT follower AS __id FROM (SELECT DISTINCT(follower) AS __id FROM
(SELECT follower FROM subscriptions WHERE target=? AND model="openvk\\Web\\Models\\Entities\\User") u0 (SELECT follower FROM subscriptions WHERE target=? AND model="openvk\\Web\\Models\\Entities\\User") u0
INNER JOIN INNER JOIN
(SELECT target FROM subscriptions WHERE follower=? AND model="openvk\\Web\\Models\\Entities\\User") u1 (SELECT target FROM subscriptions WHERE follower=? AND model="openvk\\Web\\Models\\Entities\\User") u1

View file

@ -1,4 +1,4 @@
(SELECT follower AS __id FROM (SELECT DISTINCT(follower) AS __id FROM
(SELECT follower FROM subscriptions WHERE target=? AND model="openvk\\Web\\Models\\Entities\\User") u0 (SELECT follower FROM subscriptions WHERE target=? AND model="openvk\\Web\\Models\\Entities\\User") u0
INNER JOIN INNER JOIN
(SELECT target FROM subscriptions WHERE follower=? AND model="openvk\\Web\\Models\\Entities\\User") u1 (SELECT target FROM subscriptions WHERE follower=? AND model="openvk\\Web\\Models\\Entities\\User") u1

View file

@ -1,4 +1,4 @@
(SELECT target AS __id FROM (SELECT DISTINCT(target) AS __id FROM
(SELECT follower FROM subscriptions WHERE target=? AND model="openvk\\Web\\Models\\Entities\\User") u0 (SELECT follower FROM subscriptions WHERE target=? AND model="openvk\\Web\\Models\\Entities\\User") u0
RIGHT JOIN RIGHT JOIN
(SELECT target FROM subscriptions WHERE follower=? AND model="openvk\\Web\\Models\\Entities\\User") u1 (SELECT target FROM subscriptions WHERE follower=? AND model="openvk\\Web\\Models\\Entities\\User") u1

View file

@ -128,7 +128,8 @@ final class AdminPresenter extends OpenVKPresenter
$club->save(); $club->save();
break; break;
case "ban": 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(); $club->save();
break; break;
} }

View file

@ -23,6 +23,9 @@ final class CommentPresenter extends OpenVKPresenter
$comment = (new Comments)->get($id); $comment = (new Comments)->get($id);
if(!$comment || $comment->isDeleted()) $this->notFound(); if(!$comment || $comment->isDeleted()) $this->notFound();
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); if(!is_null($this->user)) $comment->toggleLike($this->user->identity);
$this->redirect($_SERVER["HTTP_REFERER"]); $this->redirect($_SERVER["HTTP_REFERER"]);
@ -48,6 +51,9 @@ final class CommentPresenter extends OpenVKPresenter
else if($entity instanceof Topic) else if($entity instanceof Topic)
$club = $entity->getClub(); $club = $entity->getClub();
if ($entity instanceof Post && $entity->getWallOwner()->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
if($_FILES["_vid_attachment"] && OPENVK_ROOT_CONF['openvk']['preferences']['videos']['disableUploading']) if($_FILES["_vid_attachment"] && OPENVK_ROOT_CONF['openvk']['preferences']['videos']['disableUploading'])
$this->flashFail("err", tr("error"), "Video uploads are disabled by the system administrator."); $this->flashFail("err", tr("error"), "Video uploads are disabled by the system administrator.");
@ -130,6 +136,8 @@ final class CommentPresenter extends OpenVKPresenter
if(!$comment) $this->notFound(); if(!$comment) $this->notFound();
if(!$comment->canBeDeletedBy($this->user->identity)) if(!$comment->canBeDeletedBy($this->user->identity))
$this->throwError(403, "Forbidden", "У вас недостаточно прав чтобы редактировать этот ресурс."); $this->throwError(403, "Forbidden", "У вас недостаточно прав чтобы редактировать этот ресурс.");
if ($comment->getTarget() instanceof Post && $comment->getTarget()->getWallOwner()->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
$comment->delete(); $comment->delete();
$this->flashFail( $this->flashFail(

View file

@ -23,11 +23,15 @@ final class GroupPresenter extends OpenVKPresenter
$club = $this->clubs->get($id); $club = $this->clubs->get($id);
if(!$club) { if(!$club) {
$this->notFound(); $this->notFound();
} else {
if ($club->isBanned()) {
$this->template->_template = "Group/Banned.xml";
} else { } else {
$this->template->albums = (new Albums)->getClubAlbums($club, 1, 3); $this->template->albums = (new Albums)->getClubAlbums($club, 1, 3);
$this->template->albumsCount = (new Albums)->getClubAlbumsCount($club); $this->template->albumsCount = (new Albums)->getClubAlbumsCount($club);
$this->template->topics = (new Topics)->getLastTopics($club, 3); $this->template->topics = (new Topics)->getLastTopics($club, 3);
$this->template->topicsCount = (new Topics)->getClubTopicsCount($club); $this->template->topicsCount = (new Topics)->getClubTopicsCount($club);
}
if(!is_null($this->user->identity) && !$club->canBeModifiedBy($this->user->identity) && $club->getWallType() == 2) { if(!is_null($this->user->identity) && !$club->canBeModifiedBy($this->user->identity) && $club->getWallType() == 2) {
$this->template->suggestedPostsCountByUser = (new Posts)->getSuggestedPostsCountByUser($club->getId(), $this->user->id); $this->template->suggestedPostsCountByUser = (new Posts)->getSuggestedPostsCountByUser($club->getId(), $this->user->id);
@ -47,7 +51,7 @@ final class GroupPresenter extends OpenVKPresenter
$this->willExecuteWriteAction(); $this->willExecuteWriteAction();
if($_SERVER["REQUEST_METHOD"] === "POST") { 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 = new Club;
$club->setName($this->postParam("name")); $club->setName($this->postParam("name"));
@ -80,6 +84,7 @@ final class GroupPresenter extends OpenVKPresenter
$club = $this->clubs->get((int) $this->postParam("id")); $club = $this->clubs->get((int) $this->postParam("id"));
if(!$club) exit("Invalid state"); if(!$club) exit("Invalid state");
if ($club->isBanned()) $this->flashFail("err", tr("error"), tr("forbidden"));
$club->toggleSubscription($this->user->identity); $club->toggleSubscription($this->user->identity);
@ -91,6 +96,8 @@ final class GroupPresenter extends OpenVKPresenter
$this->assertUserLoggedIn(); $this->assertUserLoggedIn();
$this->template->club = $this->clubs->get($id); $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"; $this->template->onlyShowManagers = $this->queryParam("onlyAdmins") == "1";
if($this->template->onlyShowManagers) { if($this->template->onlyShowManagers) {
$this->template->followers = NULL; $this->template->followers = NULL;
@ -126,6 +133,8 @@ final class GroupPresenter extends OpenVKPresenter
$this->badRequest(); $this->badRequest();
$club = $this->clubs->get($id); $club = $this->clubs->get($id);
if ($club->isBanned()) $this->flashFail("err", tr("error"), tr("forbidden"));
$user = (new Users)->get((int) $user); $user = (new Users)->get((int) $user);
if(!$user || !$club) if(!$user || !$club)
$this->notFound(); $this->notFound();
@ -202,6 +211,8 @@ final class GroupPresenter extends OpenVKPresenter
$club = $this->clubs->get($id); $club = $this->clubs->get($id);
if(!$club || !$club->canBeModifiedBy($this->user->identity)) if(!$club || !$club->canBeModifiedBy($this->user->identity))
$this->notFound(); $this->notFound();
else if ($club->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
else else
$this->template->club = $club; $this->template->club = $club;
@ -209,7 +220,7 @@ final class GroupPresenter extends OpenVKPresenter
if(!$club->setShortcode( empty($this->postParam("shortcode")) ? NULL : $this->postParam("shortcode") )) if(!$club->setShortcode( empty($this->postParam("shortcode")) ? NULL : $this->postParam("shortcode") ))
$this->flashFail("err", tr("error"), tr("error_shorturl_incorrect")); $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->setAbout(empty($this->postParam("about")) ? NULL : $this->postParam("about"));
try { try {
$club->setWall(empty($this->postParam("wall")) ? 0 : (int)$this->postParam("wall")); $club->setWall(empty($this->postParam("wall")) ? 0 : (int)$this->postParam("wall"));
@ -268,6 +279,7 @@ final class GroupPresenter extends OpenVKPresenter
{ {
$photo = new Photo; $photo = new Photo;
$club = $this->clubs->get($id); $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) { if($_SERVER["REQUEST_METHOD"] === "POST" && $_FILES["ava"]["error"] === UPLOAD_ERR_OK) {
try { try {
$anon = OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["anonymousPosting"]["enable"]; $anon = OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["anonymousPosting"]["enable"];
@ -356,6 +368,8 @@ final class GroupPresenter extends OpenVKPresenter
$club = $this->clubs->get($id); $club = $this->clubs->get($id);
if(!$club->canBeModifiedBy($this->user->identity)) if(!$club->canBeModifiedBy($this->user->identity))
$this->notFound(); $this->notFound();
else if ($club->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
else else
$this->template->club = $club; $this->template->club = $club;
@ -388,6 +402,7 @@ final class GroupPresenter extends OpenVKPresenter
$this->flashFail("err", tr("error"), tr("incorrect_password")); $this->flashFail("err", tr("error"), tr("incorrect_password"));
$club = $this->clubs->get($id); $club = $this->clubs->get($id);
if ($club->isBanned()) $this->flashFail("err", tr("error"), tr("forbidden"));
$newOwner = (new Users)->get($newOwnerId); $newOwner = (new Users)->get($newOwnerId);
if($this->user->id !== $club->getOwner()->getId()) if($this->user->id !== $club->getOwner()->getId())
$this->flashFail("err", tr("error"), tr("forbidden")); $this->flashFail("err", tr("error"), tr("forbidden"));

View file

@ -66,7 +66,7 @@ final class PhotosPresenter extends OpenVKPresenter
} }
if($_SERVER["REQUEST_METHOD"] === "POST") { 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")); $this->flashFail("err", tr("error"), tr("error_segmentation"));
else if(strlen($this->postParam("name")) > 36) else if(strlen($this->postParam("name")) > 36)
$this->flashFail("err", tr("error"), tr("error_data_too_big", "name", 36, "bytes")); $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) if(strlen($this->postParam("name")) > 36)
$this->flashFail("err", tr("error"), tr("error_data_too_big", "name", 36, "bytes")); $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->setDescription(empty($this->postParam("desc")) ? NULL : $this->postParam("desc"));
$album->setEdited(time()); $album->setEdited(time());
$album->save(); $album->save();

View file

@ -46,13 +46,13 @@ final class WallPresenter extends OpenVKPresenter
function renderWall(int $user, bool $embedded = false): void function renderWall(int $user, bool $embedded = false): void
{ {
$owner = ($user < 0 ? (new Clubs) : (new Users))->get(abs($user)); $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)) { if(is_null($this->user)) {
$canPost = false; $canPost = false;
} else if($user > 0) { } else if($user > 0) {
if(!$owner->isBanned())
$canPost = $owner->getPrivacyPermission("wall.write", $this->user->identity); $canPost = $owner->getPrivacyPermission("wall.write", $this->user->identity);
else
$this->flashFail("err", tr("error"), tr("forbidden"));
} else if($user < 0) { } else if($user < 0) {
if($owner->canBeModifiedBy($this->user->identity)) if($owner->canBeModifiedBy($this->user->identity))
$canPost = true; $canPost = true;
@ -100,6 +100,8 @@ final class WallPresenter extends OpenVKPresenter
} else if($user < 0) { } else if($user < 0) {
if($owner->canBeModifiedBy($this->user->identity)) if($owner->canBeModifiedBy($this->user->identity))
$canPost = true; $canPost = true;
else if ($owner->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
else else
$canPost = $owner->canPost(); $canPost = $owner->canPost();
} else { } else {
@ -213,11 +215,12 @@ final class WallPresenter extends OpenVKPresenter
$wallOwner = ($wall > 0 ? (new Users)->get($wall) : (new Clubs)->get($wall * -1)) $wallOwner = ($wall > 0 ? (new Users)->get($wall) : (new Clubs)->get($wall * -1))
?? $this->flashFail("err", tr("failed_to_publish_post"), tr("error_4")); ?? $this->flashFail("err", tr("failed_to_publish_post"), tr("error_4"));
if ($wallOwner->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
if($wall > 0) { if($wall > 0) {
if(!$wallOwner->isBanned())
$canPost = $wallOwner->getPrivacyPermission("wall.write", $this->user->identity); $canPost = $wallOwner->getPrivacyPermission("wall.write", $this->user->identity);
else
$this->flashFail("err", tr("not_enough_permissions"), tr("not_enough_permissions_comment"));
} else if($wall < 0) { } else if($wall < 0) {
if($wallOwner->canBeModifiedBy($this->user->identity)) if($wallOwner->canBeModifiedBy($this->user->identity))
$canPost = true; $canPost = true;
@ -383,6 +386,9 @@ final class WallPresenter extends OpenVKPresenter
} else { } else {
$this->template->wallOwner = (new Clubs)->get(abs($post->getTargetWall())); $this->template->wallOwner = (new Clubs)->get(abs($post->getTargetWall()));
$this->template->isWallOfGroup = true; $this->template->isWallOfGroup = true;
if ($this->template->wallOwner->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
} }
$this->template->cCount = $post->getCommentsCount(); $this->template->cCount = $post->getCommentsCount();
$this->template->cPage = (int) ($_GET["p"] ?? 1); $this->template->cPage = (int) ($_GET["p"] ?? 1);
@ -398,6 +404,9 @@ final class WallPresenter extends OpenVKPresenter
$post = $this->posts->getPostById($wall, $post_id); $post = $this->posts->getPostById($wall, $post_id);
if(!$post || $post->isDeleted()) $this->notFound(); if(!$post || $post->isDeleted()) $this->notFound();
if ($post->getWallOwner()->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
if(!is_null($this->user)) { if(!is_null($this->user)) {
$post->toggleLike($this->user->identity); $post->toggleLike($this->user->identity);
} }
@ -416,6 +425,9 @@ final class WallPresenter extends OpenVKPresenter
if(!$post || $post->isDeleted()) if(!$post || $post->isDeleted())
$this->notFound(); $this->notFound();
if ($post->getWallOwner()->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
$where = $this->postParam("type") ?? "wall"; $where = $this->postParam("type") ?? "wall";
$groupId = NULL; $groupId = NULL;
$flags = 0; $flags = 0;
@ -473,6 +485,9 @@ final class WallPresenter extends OpenVKPresenter
$wallOwner = ($wall > 0 ? (new Users)->get($wall) : (new Clubs)->get($wall * -1)) $wallOwner = ($wall > 0 ? (new Users)->get($wall) : (new Clubs)->get($wall * -1))
?? $this->flashFail("err", tr("failed_to_delete_post"), tr("error_4")); ?? $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); if($wall < 0) $canBeDeletedByOtherUser = $wallOwner->canBeModifiedBy($this->user->identity);
else $canBeDeletedByOtherUser = false; else $canBeDeletedByOtherUser = false;
@ -497,6 +512,9 @@ final class WallPresenter extends OpenVKPresenter
if(!$post) if(!$post)
$this->notFound(); $this->notFound();
if ($post->getWallOwner()->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
if(!$post->canBePinnedBy($this->user->identity)) if(!$post->canBePinnedBy($this->user->identity))
$this->flashFail("err", tr("not_enough_permissions"), tr("not_enough_permissions_comment")); $this->flashFail("err", tr("not_enough_permissions"), tr("not_enough_permissions_comment"));

View file

@ -0,0 +1,22 @@
{extends "../@layout.xml"}
{block title}{$club->getCanonicalName()}{/block}
{block header}{include title}{/block}
{block content}
<center>
<img src="/assets/packages/static/openvk/img/oof.apng" alt="Сообщество заблокировано." style="width: 20%;"/>
<p>
{tr("group_banned", htmlentities($club->getCanonicalName()))|noescape}
<br/>
{_user_banned_comment} <b>{$club->getBanReason()}</b>.
</p>
{if isset($thisUser)}
<p n:if="$thisUser->getChandlerUser()->can('access')->model('admin')->whichBelongsTo(NULL)">
<br />
<a href="/admin/clubs/id{$club->getId()}?act=ban" target="_blank" class="button">{_edit}</a>
</p>
{/if}
</center>
{/block}

View file

@ -389,6 +389,8 @@
"error_suggestions_open" = "This group has open wall."; "error_suggestions_open" = "This group has open wall.";
"error_suggestions_access" = "Only group's administrators can view all suggested posts."; "error_suggestions_access" = "Only group's administrators can view all suggested posts.";
"group_banned" = "Unfortunately, we had to block the <b>$1</b> group.";
/* Albums */ /* Albums */
"create" = "Create"; "create" = "Create";

View file

@ -368,6 +368,7 @@
"search_group" = "Поиск группы"; "search_group" = "Поиск группы";
"search_by_groups" = "Поиск по группам"; "search_by_groups" = "Поиск по группам";
"search_group_desc" = "Здесь Вы можете просмотреть существующие группы и выбрать группу себе по вкусу..."; "search_group_desc" = "Здесь Вы можете просмотреть существующие группы и выбрать группу себе по вкусу...";
"group_banned" = "К сожалению, нам пришлось заблокировать сообщество <b>$1</b>.";
"error_suggestions" = "Ошибка доступа к предложенным"; "error_suggestions" = "Ошибка доступа к предложенным";
"error_suggestions_closed" = "У этой группы закрытая стена."; "error_suggestions_closed" = "У этой группы закрытая стена.";