From cb6578228e8b392a812b47ad4c28ea7f9e220b12 Mon Sep 17 00:00:00 2001 From: lalka2018 <99399973+lalka2016@users.noreply.github.com> Date: Sun, 14 May 2023 23:49:33 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=BE=D1=80=D0=BC=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=81=D0=BC=D0=B5=D0=BD=D0=B0=20=D0=B0?= =?UTF-8?q?=D0=B2=D0=B0=D1=82=D0=B0=D1=80=D0=BE=D0=BA=20=D0=BA=D0=B0=D0=BA?= =?UTF-8?q?=20=D0=B2=20=D1=81=D1=82=D0=B0=D1=80=D0=BE=D0=BC=20=D0=B2=D0=BA?= =?UTF-8?q?=20(#874)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fast avatar changing * Fixed changing avatar from settings * fixed otstup --- Web/Models/Entities/Post.php | 5 + Web/Presenters/GroupPresenter.php | 45 ++++++++- Web/Presenters/UserPresenter.php | 25 ++++- Web/Presenters/templates/Group/View.xml | 24 ++++- Web/Presenters/templates/User/View.xml | 19 +++- Web/Presenters/templates/_includeCSS.xml | 3 + .../components/post/microblogpost.xml | 2 + .../templates/components/post/oldpost.xml | 4 + Web/routes.yml | 2 + Web/static/css/avataredit.css | 88 ++++++++++++++++++ Web/static/img/delete.png | Bin 0 -> 263 bytes Web/static/img/upload.png | Bin 0 -> 165 bytes Web/static/js/openvk.cls.js | 85 +++++++++++++++++ locales/en.strings | 24 +++++ locales/ru.strings | 24 +++++ 15 files changed, 342 insertions(+), 8 deletions(-) create mode 100644 Web/static/css/avataredit.css create mode 100644 Web/static/img/delete.png create mode 100644 Web/static/img/upload.png diff --git a/Web/Models/Entities/Post.php b/Web/Models/Entities/Post.php index 8c1c6a62..42941901 100644 --- a/Web/Models/Entities/Post.php +++ b/Web/Models/Entities/Post.php @@ -99,6 +99,11 @@ class Post extends Postable return (($this->getRecord()->flags & 0b00100000) > 0) && ($this->getRecord()->owner > 0); } + function isUpdateAvatarMessage(): bool + { + return (($this->getRecord()->flags & 0b00010000) > 0) && ($this->getRecord()->owner > 0); + } + function isExplicit(): bool { return (bool) $this->getRecord()->nsfw; diff --git a/Web/Presenters/GroupPresenter.php b/Web/Presenters/GroupPresenter.php index a0b83a59..4f671df3 100644 --- a/Web/Presenters/GroupPresenter.php +++ b/Web/Presenters/GroupPresenter.php @@ -1,6 +1,6 @@ clubs->get($id); + if($_SERVER["REQUEST_METHOD"] === "POST" && $_FILES["ava"]["error"] === UPLOAD_ERR_OK) { + try { + $anon = OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["anonymousPosting"]["enable"]; + if($anon && $this->user->id === $club->getOwner()->getId()) + $anon = $club->isOwnerHidden(); + else if($anon) + $anon = $club->getManager($this->user->identity)->isHidden(); + $photo->setOwner($this->user->id); + $photo->setDescription("Club image"); + $photo->setFile($_FILES["ava"]); + $photo->setCreated(time()); + $photo->setAnonymous($anon); + $photo->save(); + + (new Albums)->getClubAvatarAlbum($club)->addPhoto($photo); + + $flags = 0; + $flags |= 0b00010000; + $flags |= 0b10000000; + + $post = new Post; + $post->setOwner($this->user->id); + $post->setWall($club->getId()*-1); + $post->setCreated(time()); + $post->setContent(""); + $post->setFlags($flags); + $post->save(); + $post->attach($photo); + + } catch(ISE $ex) { + $name = $album->getName(); + $this->flashFail("err", "Неизвестная ошибка", "Не удалось сохранить фотографию."); + } + } + $this->returnJson([ + "url" => $photo->getURL(), + "id" => $photo->getPrettyId() + ]); + } function renderEditBackdrop(int $id): void { $this->assertUserLoggedIn(); diff --git a/Web/Presenters/UserPresenter.php b/Web/Presenters/UserPresenter.php index 3cf68757..9cfa3654 100644 --- a/Web/Presenters/UserPresenter.php +++ b/Web/Presenters/UserPresenter.php @@ -39,6 +39,7 @@ final class UserPresenter extends OpenVKPresenter } } else { $this->template->albums = (new Albums)->getUserAlbums($user); + $this->template->avatarAlbum = (new Albums)->getUserAvatarAlbum($user); $this->template->albumsCount = (new Albums)->getUserAlbumsCount($user); $this->template->videos = (new Videos)->getByUser($user, 1, 2); $this->template->videosCount = (new Videos)->getUserVideosCount($user); @@ -301,7 +302,7 @@ final class UserPresenter extends OpenVKPresenter $this->redirect($user->getURL()); } - function renderSetAvatar(): void + function renderSetAvatar() { $this->assertUserLoggedIn(); $this->willExecuteWriteAction(); @@ -321,8 +322,26 @@ final class UserPresenter extends OpenVKPresenter $album->addPhoto($photo); $album->setEdited(time()); $album->save(); - - $this->flashFail("succ", tr("photo_saved"), tr("photo_saved_comment")); + + $flags = 0; + $flags |= 0b00010000; + + $post = new Post; + $post->setOwner($this->user->id); + $post->setWall($this->user->id); + $post->setCreated(time()); + $post->setContent(""); + $post->setFlags($flags); + $post->save(); + $post->attach($photo); + if($this->postParam("ava", true) == (int)1) { + $this->returnJson([ + "url" => $photo->getURL(), + "id" => $photo->getPrettyId() + ]); + } else { + $this->flashFail("succ", tr("photo_saved"), tr("photo_saved_comment")); + } } function renderSettings(): void diff --git a/Web/Presenters/templates/Group/View.xml b/Web/Presenters/templates/Group/View.xml index 1abb5856..eb4f2608 100644 --- a/Web/Presenters/templates/Group/View.xml +++ b/Web/Presenters/templates/Group/View.xml @@ -96,9 +96,27 @@
{var $avatarPhoto = $club->getAvatarPhoto()} {var $avatarLink = ((is_null($avatarPhoto) ? FALSE : $avatarPhoto->isAnonymous()) ? "/photo" . ("s/" . base_convert((string) $avatarPhoto->getId(), 10, 32)) : $club->getAvatarLink())} - - - +
+ {var $hasAvatar = !str_contains($club->getAvatarUrl('miniscule'), "/assets/packages/static/openvk/img/camera_200.png")} + {if !is_null($thisUser) && $hasAvatar == false && $club->canBeModifiedBy($thisUser)} + {_add_image_group} + {elseif !is_null($thisUser) && $hasAvatar == true && $club->canBeModifiedBy($thisUser)} +
+
+ +
+ +
+ {/if} + + + +