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 @@
{_upload_new_picture}
+{_upload_new_picture}
+${groupStrings == true ? tr('groups_avatar') : tr('friends_avatar')}
+${tr('formats_avatar')}
${tr('troubles_avatar')}
+${tr("deleting_avatar_sure")}
+ ` + let msg = MessageBox(tr('deleting_avatar'), body, [ + tr('yes'), + tr('cancel') + ], [ + (function() { + let xhr = new XMLHttpRequest(); + xhr.open("POST", "/photo"+avatar+"/delete") + xhr.onload = () => { + //не люблю формы + NewNotification(tr("deleted_avatar_notification"), ""); + location.reload() + } + xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); + xhr.send("hash="+u("meta[name=csrf]").attr("value")) + }), + (function() { + u("#tmpPhDelF").remove(); + }), + ]); +} + $(document).on("scroll", () => { if($(document).scrollTop() > $(".sidebar").height() + 50) { $(".floating_sidebar")[0].classList.add("show"); diff --git a/locales/en.strings b/locales/en.strings index 1e8bdb15..8e32ea66 100644 --- a/locales/en.strings +++ b/locales/en.strings @@ -351,6 +351,30 @@ "albums_list_one" = "You have one album"; "albums_list_other" = "You have $1 albums"; +"add_image" = "Add image"; +"add_image_group" = "Upload image"; +"upload_new_picture" = "Upload new photo"; +"uploading_new_image" = "Uploading new photo"; +"friends_avatar" = "It will be easier for friends to recognize you if you upload your real picture."; +"groups_avatar" = "Good photo can make your group more recognizable."; +"formats_avatar" = "You can upload an image in JPG, GIF or PNG format."; +"troubles_avatar" = "If you're having trouble uploading, try selecting a smaller photo."; +"webcam_avatar" = "If your computer is equipped with a webcam, you can take a snapshot."; + +"update_avatar_notification" = "Profile photo was updated"; +"update_avatar_description" = "Click to watch"; + +"deleting_avatar" = "Deleting photo"; +"deleting_avatar_sure" = "Do you sure you want to delete avatar?"; + +"deleted_avatar_notification" = "Picture successfully deleted"; + +"save_changes" = "Save changes"; + +"upd_m" = "updated his profile picture"; +"upd_f" = "updated her profile picture"; +"upd_g" = "updated group's picture"; + /* Notes */ "notes" = "Notes"; diff --git a/locales/ru.strings b/locales/ru.strings index 578259c8..567cdc2f 100644 --- a/locales/ru.strings +++ b/locales/ru.strings @@ -335,6 +335,30 @@ "albums_list_many" = "У Вас $1 альбомов"; "albums_list_other" = "У Вас $1 альбомов"; +"add_image" = "Поставить изображение"; +"add_image_group" = "Загрузить фотографию"; +"upload_new_picture" = "Загрузить новую фотографию"; +"uploading_new_image" = "Загрузка новой фотографии"; +"friends_avatar" = "Друзьям будет проще узнать Вас, если вы загрузите свою настоящую фотографию."; +"groups_avatar" = "Хорошее фото сделает Ваше сообщество более узнаваемым."; +"formats_avatar" = "Вы можете загрузить изображение в формате JPG, GIF или PNG."; +"troubles_avatar" = "Если возникают проблемы с загрузкой, попробуйте выбрать фотографию меньшего размера."; +"webcam_avatar" = "Если ваш компьютер оснащён веб-камерой, Вы можете сделать моментальную фотографию »"; + +"update_avatar_notification" = "Фотография профиля обновлена"; +"update_avatar_description" = "Нажмите сюда, чтобы перейти к просмотру"; + +"deleting_avatar" = "Удаление фотографии"; +"deleting_avatar_sure" = "Вы действительно хотите удалить аватар?"; + +"deleted_avatar_notification" = "Фотография успешно удалена"; + +"save_changes" = "Сохранить изменения"; + +"upd_m" = "обновил фотографию на своей странице"; +"upd_f" = "обновила фотографию на своей странице"; +"upd_g" = "обновило фотографию группы"; + /* Notes */ "notes" = "Заметки";