diff --git a/Web/Presenters/GroupPresenter.php b/Web/Presenters/GroupPresenter.php index 5e8919b4..88844fbe 100644 --- a/Web/Presenters/GroupPresenter.php +++ b/Web/Presenters/GroupPresenter.php @@ -282,48 +282,99 @@ final class GroupPresenter extends OpenVKPresenter function renderSetAvatar(int $id) { - $photo = new Photo; + $this->assertUserLoggedIn(); + $this->willExecuteWriteAction(); + $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(!$club || $club->isBanned() || !$club->canBeModifiedBy($this->user->identity)) + $this->flashFail("err", tr("error"), tr("forbidden"), NULL, true); + + if($_SERVER["REQUEST_METHOD"] === "POST" && $_FILES["blob"]["error"] === UPLOAD_ERR_OK) { try { + $photo = new Photo; + $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->setFile($_FILES["blob"]); $photo->setCreated(time()); $photo->setAnonymous($anon); $photo->save(); (new Albums)->getClubAvatarAlbum($club)->addPhoto($photo); - $flags = 0; - $flags |= 0b00010000; - $flags |= 0b10000000; + if($this->postParam("on_wall") == 1) { + $post = new Post; + + $post->setOwner($this->user->id); + $post->setWall($club->getId() * -1); + $post->setCreated(time()); + $post->setContent(""); - $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); + $flags = 0; + $flags |= 0b00010000; + $flags |= 0b10000000; - } catch(ISE $ex) { - $name = $album->getName(); - $this->flashFail("err", tr("error"), tr("error_when_uploading_photo")); + $post->setFlags($flags); + $post->save(); + + $post->attach($photo); + } + + } catch(\Throwable $ex) { + $this->flashFail("err", tr("error"), tr("error_when_uploading_photo"), NULL, true); } + + $this->returnJson([ + "success" => true, + "new_photo" => $photo->getPrettyId(), + "url" => $photo->getURL(), + ]); + } else { + return " "; } - $this->returnJson([ - "url" => $photo->getURL(), - "id" => $photo->getPrettyId() - ]); } + + function renderDeleteAvatar(int $id) { + $this->assertUserLoggedIn(); + $this->willExecuteWriteAction(); + + $club = $this->clubs->get($id); + + if(!$club || $club->isBanned() || !$club->canBeModifiedBy($this->user->identity)) + $this->flashFail("err", tr("error"), tr("forbidden"), NULL, true); + + $avatar = $club->getAvatarPhoto(); + + if(!$avatar) + $this->flashFail("succ", tr("error"), "no avatar bro", NULL, true); + + $avatar->isolate(); + + $newAvatar = $club->getAvatarPhoto(); + + if(!$newAvatar) + $this->returnJson([ + "success" => true, + "has_new_photo" => false, + "new_photo" => NULL, + "url" => "/assets/packages/static/openvk/img/camera_200.png", + ]); + else + $this->returnJson([ + "success" => true, + "has_new_photo" => true, + "new_photo" => $newAvatar->getPrettyId(), + "url" => $newAvatar->getURL(), + ]); + } + function renderEditBackdrop(int $id): void { $this->assertUserLoggedIn(); diff --git a/Web/Presenters/UserPresenter.php b/Web/Presenters/UserPresenter.php index 1c2fa02e..baf8f046 100644 --- a/Web/Presenters/UserPresenter.php +++ b/Web/Presenters/UserPresenter.php @@ -337,8 +337,7 @@ final class UserPresenter extends OpenVKPresenter $this->redirect($_SERVER['HTTP_REFERER']); } - function renderSetAvatar() - { + function renderSetAvatar() { $this->assertUserLoggedIn(); $this->willExecuteWriteAction(); @@ -349,8 +348,8 @@ final class UserPresenter extends OpenVKPresenter $photo->setFile($_FILES["blob"]); $photo->setCreated(time()); $photo->save(); - } catch(ISE $ex) { - $this->flashFail("err", tr("error"), tr("error_upload_failed")); + } catch(\Throwable $ex) { + $this->flashFail("err", tr("error"), tr("error_upload_failed"), NULL, (int)$this->postParam("ajax", true) == 1); } $album = (new Albums)->getUserAvatarAlbum($this->user->identity); @@ -361,23 +360,57 @@ final class UserPresenter extends OpenVKPresenter $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) { + if($this->postParam("on_wall") == 1) { + $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((int)$this->postParam("ajax", true) == 1) { $this->returnJson([ - "url" => $photo->getURL(), - "id" => $photo->getPrettyId() + "success" => true, + "new_photo" => $photo->getPrettyId(), + "url" => $photo->getURL(), ]); } else { $this->flashFail("succ", tr("photo_saved"), tr("photo_saved_comment")); } } + + function renderDeleteAvatar() { + $this->assertUserLoggedIn(); + $this->willExecuteWriteAction(); + + $avatar = $this->user->identity->getAvatarPhoto(); + + if(!$avatar) + $this->flashFail("succ", tr("error"), "no avatar bro", NULL, true); + + $avatar->isolate(); + + $newAvatar = $this->user->identity->getAvatarPhoto(); + + if(!$newAvatar) + $this->returnJson([ + "success" => true, + "has_new_photo" => false, + "new_photo" => NULL, + "url" => "/assets/packages/static/openvk/img/camera_200.png", + ]); + else + $this->returnJson([ + "success" => true, + "has_new_photo" => true, + "new_photo" => $newAvatar->getPrettyId(), + "url" => $newAvatar->getURL(), + ]); + } function renderSettings(): void { diff --git a/Web/Presenters/templates/@layout.xml b/Web/Presenters/templates/@layout.xml index aa2db799..803ebdd0 100644 --- a/Web/Presenters/templates/@layout.xml +++ b/Web/Presenters/templates/@layout.xml @@ -18,9 +18,11 @@ {script "js/l10n.js"} {script "js/openvk.cls.js"} {script "js/node_modules/dashjs/dist/dash.all.min.js"} + {script "js/al_music.js"} {css "js/node_modules/tippy.js/dist/backdrop.css"} + {css "js/node_modules/cropperjs/dist/cropper.css"} {css "js/node_modules/tippy.js/dist/border.css"} {css "js/node_modules/tippy.js/dist/svg-arrow.css"} {css "js/node_modules/tippy.js/themes/light.css"} diff --git a/Web/Presenters/templates/Group/View.xml b/Web/Presenters/templates/Group/View.xml index 91a96119..79ef3704 100644 --- a/Web/Presenters/templates/Group/View.xml +++ b/Web/Presenters/templates/Group/View.xml @@ -127,25 +127,19 @@
{_upload_new_picture}
-{_upload_new_picture}
-${isGroup == true ? tr('groups_avatar') : tr('friends_avatar')}
+${tr('formats_avatar')}
${tr('troubles_avatar')}
+${tr('webcam_avatar')}
+${tr("selected_area_rotate")}
+ +${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(); - }), - ]); -} - function expandSearch() { // console.log("search expanded") diff --git a/Web/static/js/package.json b/Web/static/js/package.json index f5c37008..bb622c72 100644 --- a/Web/static/js/package.json +++ b/Web/static/js/package.json @@ -2,6 +2,7 @@ "dependencies": { "@atlassian/aui": "^9.6.0", "create-react-class": "^15.7.0", + "cropperjs": "^1.6.1", "dashjs": "^4.3.0", "id3js": "^2.1.1", "handlebars": "^4.7.7", diff --git a/Web/static/js/yarn.lock b/Web/static/js/yarn.lock index 289fc81e..e87c407e 100644 --- a/Web/static/js/yarn.lock +++ b/Web/static/js/yarn.lock @@ -59,16 +59,16 @@ create-react-class@^15.7.0: loose-envify "^1.3.1" object-assign "^4.1.1" +cropperjs@^1.6.1: + version "1.6.1" + resolved "https://registry.yarnpkg.com/cropperjs/-/cropperjs-1.6.1.tgz#fd132021d93b824b1b0f2c2c3b763419fb792d89" + integrity sha512-F4wsi+XkDHCOMrHMYjrTEE4QBOrsHHN5/2VsVAaRq8P7E5z7xQpT75S+f/9WikmBEailas3+yo+6zPIomW+NOA== + css.escape@1.5.1: version "1.5.1" resolved "https://registry.yarnpkg.com/css.escape/-/css.escape-1.5.1.tgz#42e27d4fa04ae32f931a4b4d4191fa9cddee97cb" integrity sha512-YUifsXXuknHlUsmlgyY0PKzgPOr7/FjCePfHNt0jxm83wHZi44VDMQ7/fGNkjY3/jV1MC+1CmZbaHzugyeRtpg== -dompurify@2.4.5: - version "2.4.5" - resolved "https://registry.yarnpkg.com/dompurify/-/dompurify-2.4.5.tgz#0e89a27601f0bad978f9a924e7a05d5d2cccdd87" - integrity sha512-jggCCd+8Iqp4Tsz0nIvpcb22InKEBrGz5dw3EQJMs8HPJDsKbFIO3STYtAvCfDx26Muevn1MHVI0XxjgFfmiSA== - dashjs@^4.3.0: version "4.3.0" resolved "https://registry.yarnpkg.com/dashjs/-/dashjs-4.3.0.tgz#cccda5a490cabf6c3b48aa887ec8c8ac0df1a233" @@ -81,6 +81,11 @@ dashjs@^4.3.0: imsc "^1.0.2" localforage "^1.7.1" +dompurify@2.4.5: + version "2.4.5" + resolved "https://registry.yarnpkg.com/dompurify/-/dompurify-2.4.5.tgz#0e89a27601f0bad978f9a924e7a05d5d2cccdd87" + integrity sha512-jggCCd+8Iqp4Tsz0nIvpcb22InKEBrGz5dw3EQJMs8HPJDsKbFIO3STYtAvCfDx26Muevn1MHVI0XxjgFfmiSA== + encoding@^0.1.11: version "0.1.13" resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.13.tgz#56574afdd791f54a8e9b2785c0582a2d26210fa9" @@ -121,10 +126,6 @@ fbjs@^0.8.0: setimmediate "^1.0.5" ua-parser-js "^0.7.18" -html-entities@^1.2.1: - version "1.4.0" - resolved "https://registry.yarnpkg.com/html-entities/-/html-entities-1.4.0.tgz#cfbd1b01d2afaf9adca1b10ae7dffab98c71d2dc" - integrity sha512-8nxjcBcd8wovbeKx7h3wTji4e6+rhaVuPNpMqwWgnHh+N9ToqsCs6XztWRBPQ+UtzsoMAdKZtUENoVzU/EMtZA== handlebars@^4.7.7: version "4.7.7" resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.7.tgz#9ce33416aad02dbd6c8fafa8240d5d98004945a1" @@ -137,6 +138,11 @@ handlebars@^4.7.7: optionalDependencies: uglify-js "^3.1.4" +html-entities@^1.2.1: + version "1.4.0" + resolved "https://registry.yarnpkg.com/html-entities/-/html-entities-1.4.0.tgz#cfbd1b01d2afaf9adca1b10ae7dffab98c71d2dc" + integrity sha512-8nxjcBcd8wovbeKx7h3wTji4e6+rhaVuPNpMqwWgnHh+N9ToqsCs6XztWRBPQ+UtzsoMAdKZtUENoVzU/EMtZA== + iconv-lite@^0.6.2: version "0.6.3" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.6.3.tgz#a52f80bf38da1952eb5c681790719871a1a72501" diff --git a/locales/en.strings b/locales/en.strings index c4cfc172..9a8ddc52 100644 --- a/locales/en.strings +++ b/locales/en.strings @@ -469,16 +469,18 @@ "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."; +"webcam_avatar" = "If your computer has a webcam, you can take a snapshot »"; +"publish_on_wall" = "Make post on wall"; +"take_snapshot" = "Take snapshot"; +"your_browser_doesnt_support_webcam" = "Your browser does not support webcam video capture."; -"update_avatar_notification" = "Profile photo was updated"; -"update_avatar_description" = "Click to watch"; +"selected_area_user" = "The selected area will be shown on your page."; +"selected_area_club" = "The selected area will be shown on the group page."; +"selected_area_rotate" = "If the image is not oriented correctly, the photo can be rotated."; "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"; diff --git a/locales/ru.strings b/locales/ru.strings index 6eacddaa..c6728877 100644 --- a/locales/ru.strings +++ b/locales/ru.strings @@ -455,16 +455,18 @@ "groups_avatar" = "Хорошее фото сделает Ваше сообщество более узнаваемым."; "formats_avatar" = "Вы можете загрузить изображение в формате JPG, GIF или PNG."; "troubles_avatar" = "Если возникают проблемы с загрузкой, попробуйте выбрать фотографию меньшего размера."; -"webcam_avatar" = "Если ваш компьютер оснащён веб-камерой, Вы можете сделать моментальную фотографию »"; +"webcam_avatar" = "Если ваш компьютер оснащён веб-камерой, Вы можете сделать моментальную фотографию »"; +"publish_on_wall" = "Опубликовать запись на стене"; +"take_snapshot" = "Сделать снимок"; +"your_browser_doesnt_support_webcam" = "Ваш браузер не поддерживает съёмку видео с веб-камеры."; -"update_avatar_notification" = "Фотография профиля обновлена"; -"update_avatar_description" = "Нажмите сюда, чтобы перейти к просмотру"; +"selected_area_user" = "Выбранная область будет показываться на вашей странице."; +"selected_area_club" = "Выбранная область будет показываться на странице сообщества."; +"selected_area_rotate" = "Если изображение ориентировано неправильно, фотографию можно повернуть."; "deleting_avatar" = "Удаление фотографии"; "deleting_avatar_sure" = "Вы действительно хотите удалить аватар?"; -"deleted_avatar_notification" = "Фотография успешно удалена"; - "save_changes" = "Сохранить изменения"; "upd_m" = "обновил фотографию на своей странице"; diff --git a/locales/uk.strings b/locales/uk.strings index 17a65480..4bb3152b 100644 --- a/locales/uk.strings +++ b/locales/uk.strings @@ -368,7 +368,7 @@ "groups_avatar" = "Гарне фото зробить Вашу спільноту більш популярним."; "formats_avatar" = "Ви можете завантажити зображення у форматі JPG, GIF або PNG."; "troubles_avatar" = "Якщо виникають проблеми із завантаженням, спробуйте вибрати фотографію меншого розміру."; -"webcam_avatar" = "Якщо ваш комп'ютер оснащений веб-камерою, Ви можете зробити миттєву фотографію»"; +"webcam_avatar" = "Якщо ваш комп'ютер оснащений веб-камерою, Ви можете зробити миттєву фотографію »"; "update_avatar_notification" = "Фотографію профілю оновлено"; "update_avatar_description" = "Натисніть, щоб перейти до перегляду"; diff --git a/themepacks/midnight/stylesheet.css b/themepacks/midnight/stylesheet.css index 53c8e307..4cdef046 100644 --- a/themepacks/midnight/stylesheet.css +++ b/themepacks/midnight/stylesheet.css @@ -569,3 +569,7 @@ ul { .tabcontent { background: #2c2640 !important; } + +.add_image_text { + z-index: 999; +}