From 4170b6fa20775eb1512d25dd962d39729da45abb Mon Sep 17 00:00:00 2001 From: lalka2016 <99399973+lalka2016@users.noreply.github.com> Date: Sat, 13 May 2023 11:30:55 +0300 Subject: [PATCH] Fast avatar changing --- Web/Models/Entities/Post.php | 5 + Web/Presenters/GroupPresenter.php | 45 ++++++++- Web/Presenters/UserPresenter.php | 22 ++++- Web/Presenters/templates/Group/View.xml | 20 +++- Web/Presenters/templates/User/View.xml | 26 +++++- .../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 | 84 +++++++++++++++++ locales/en.strings | 24 +++++ locales/ru.strings | 24 +++++ 14 files changed, 340 insertions(+), 6 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..42bb4f1d 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,23 @@ 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); + + $this->returnJson([ + "url" => $photo->getURL(), + "id" => $photo->getPrettyId() + ]); } function renderSettings(): void diff --git a/Web/Presenters/templates/Group/View.xml b/Web/Presenters/templates/Group/View.xml index 1abb5856..15c03145 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 $hasAvatar == false && $club->canBeModifiedBy($thisUser)} + {_add_image_group} + {elseif $hasAvatar == true && $club->canBeModifiedBy($thisUser)} +
+
+ +
+ +
+ {/if} - + +