diff --git a/Web/Models/Entities/Club.php b/Web/Models/Entities/Club.php index 31485129..fbdc503b 100644 --- a/Web/Models/Entities/Club.php +++ b/Web/Models/Entities/Club.php @@ -224,7 +224,7 @@ class Club extends RowModel "shape" => "spline", "color" => "#597da3", ], - "name" => $unique ? "Полный охват" : "Все просмотры", + "name" => $unique ? tr("full_coverage") : tr("all_views"), ], "subs" => [ "x" => array_reverse(range(1, 7)), @@ -235,7 +235,7 @@ class Club extends RowModel "color" => "#b05c91", ], "fill" => "tozeroy", - "name" => $unique ? "Охват подписчиков" : "Просмотры подписчиков", + "name" => $unique ? tr("subs_coverage") : tr("subs_views"), ], "viral" => [ "x" => array_reverse(range(1, 7)), @@ -246,7 +246,7 @@ class Club extends RowModel "color" => "#4d9fab", ], "fill" => "tozeroy", - "name" => $unique ? "Виральный охват" : "Виральные просмотры", + "name" => $unique ? tr("viral_coverage") : tr("viral_views"), ], ]; } diff --git a/Web/Models/Entities/Comment.php b/Web/Models/Entities/Comment.php index d813d6be..d64a2763 100644 --- a/Web/Models/Entities/Comment.php +++ b/Web/Models/Entities/Comment.php @@ -90,4 +90,12 @@ class Comment extends Post { return "/wall" . $this->getTarget()->getPrettyId() . "#_comment" . $this->getId(); } + + function canBeEditedBy(?User $user = NULL): bool + { + if(!$user) + return false; + + return $user->getId() == $this->getOwner(false)->getId(); + } } diff --git a/Web/Models/Entities/Post.php b/Web/Models/Entities/Post.php index 42941901..6d0fe8cf 100644 --- a/Web/Models/Entities/Post.php +++ b/Web/Models/Entities/Post.php @@ -245,6 +245,20 @@ class Post extends Postable $this->unwire(); $this->save(); } + + function canBeEditedBy(?User $user = NULL): bool + { + if(!$user) + return false; + + if($this->isDeactivationMessage() || $this->isUpdateAvatarMessage()) + return false; + + if($this->getTargetWall() > 0) + return $this->getPublicationTime()->timestamp() + WEEK > time() && $user->getId() == $this->getOwner(false)->getId(); + + return $user->getId() == $this->getOwner(false)->getId(); + } use Traits\TRichText; } diff --git a/Web/Models/Entities/Postable.php b/Web/Models/Entities/Postable.php index 23981cc1..ffbf480c 100644 --- a/Web/Models/Entities/Postable.php +++ b/Web/Models/Entities/Postable.php @@ -167,9 +167,9 @@ abstract class Postable extends Attachable $this->stateChanges("created", time()); $this->stateChanges("virtual_id", $pCount + 1); - } else { + } /*else { $this->stateChanges("edited", time()); - } + }*/ parent::save(); } diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php index e5b8da06..aaf00ec9 100644 --- a/Web/Models/Entities/User.php +++ b/Web/Models/Entities/User.php @@ -462,6 +462,7 @@ class User extends RowModel "news", "links", "poster", + "apps" ], ])->get($id); } @@ -1026,6 +1027,7 @@ class User extends RowModel "news", "links", "poster", + "apps" ], ])->set($id, (int) $status)->toInteger(); diff --git a/Web/Presenters/AdminPresenter.php b/Web/Presenters/AdminPresenter.php index 37fb50e8..14fbbc74 100644 --- a/Web/Presenters/AdminPresenter.php +++ b/Web/Presenters/AdminPresenter.php @@ -283,7 +283,7 @@ final class AdminPresenter extends OpenVKPresenter $this->notFound(); $gift->delete(); - $this->flashFail("succ", "Gift moved successfully", "This gift will now be in Recycle Bin."); + $this->flashFail("succ", tr("admin_gift_moved_successfully"), tr("admin_gift_moved_to_recycle")); break; case "copy": case "move": @@ -302,7 +302,7 @@ final class AdminPresenter extends OpenVKPresenter $catTo->addGift($gift); $name = $catTo->getName(); - $this->flash("succ", "Gift moved successfully", "This gift will now be in $name."); + $this->flash("succ", tr("admin_gift_moved_successfully"), "This gift will now be in $name."); $this->redirect("/admin/gifts/" . $catTo->getSlug() . "." . $catTo->getId() . "/"); break; default: @@ -333,10 +333,10 @@ final class AdminPresenter extends OpenVKPresenter $gift->setUsages((int) $this->postParam("usages")); if(isset($_FILES["pic"]) && $_FILES["pic"]["error"] === UPLOAD_ERR_OK) { if(!$gift->setImage($_FILES["pic"]["tmp_name"])) - $this->flashFail("err", "Не удалось сохранить подарок", "Изображение подарка кривое."); + $this->flashFail("err", tr("error_when_saving_gift"), tr("error_when_saving_gift_bad_image")); } else if($gen) { # If there's no gift pic but it's newly created - $this->flashFail("err", "Не удалось сохранить подарок", "Пожалуйста, загрузите изображение подарка."); + $this->flashFail("err", tr("error_when_saving_gift"), tr("error_when_saving_gift_no_image")); } $gift->save(); diff --git a/Web/Presenters/CommentPresenter.php b/Web/Presenters/CommentPresenter.php index 65678fbe..b68c7d11 100644 --- a/Web/Presenters/CommentPresenter.php +++ b/Web/Presenters/CommentPresenter.php @@ -55,7 +55,7 @@ final class CommentPresenter extends OpenVKPresenter $this->flashFail("err", tr("error"), tr("forbidden")); 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"), tr("video_uploads_disabled")); $flags = 0; if($this->postParam("as_group") === "on" && !is_null($club) && $club->canBeModifiedBy($this->user->identity)) @@ -66,7 +66,7 @@ final class CommentPresenter extends OpenVKPresenter try { $photo = Photo::fastMake($this->user->id, $this->postParam("text"), $_FILES["_pic_attachment"]); } catch(ISE $ex) { - $this->flashFail("err", "Не удалось опубликовать пост", "Файл изображения повреждён, слишком велик или одна сторона изображения в разы больше другой."); + $this->flashFail("err", tr("error_when_publishing_comment"), tr("error_when_publishing_comment_description")); } } @@ -81,7 +81,7 @@ final class CommentPresenter extends OpenVKPresenter $photo = Photo::fastMake($this->user->id, $this->postParam("text"), $_FILES["_pic_attachment"], $album); } } catch(ISE $ex) { - $this->flashFail("err", "Не удалось опубликовать комментарий", "Файл медиаконтента повреждён или слишком велик."); + $this->flashFail("err", tr("error_when_publishing_comment"), tr("error_comment_file_too_big")); } $videos = []; @@ -104,7 +104,7 @@ final class CommentPresenter extends OpenVKPresenter } if(empty($this->postParam("text")) && !$photo && !$video) - $this->flashFail("err", "Не удалось опубликовать комментарий", "Комментарий пустой или слишком большой."); + $this->flashFail("err", tr("error_when_publishing_comment"), tr("error_comment_empty")); try { $comment = new Comment; @@ -116,7 +116,7 @@ final class CommentPresenter extends OpenVKPresenter $comment->setFlags($flags); $comment->save(); } catch (\LengthException $ex) { - $this->flashFail("err", "Не удалось опубликовать комментарий", "Комментарий слишком большой."); + $this->flashFail("err", tr("error_when_publishing_comment"), tr("error_comment_too_big")); } if(!is_null($photo)) @@ -139,7 +139,7 @@ final class CommentPresenter extends OpenVKPresenter if($mentionee instanceof User) (new MentionNotification($mentionee, $entity, $comment->getOwner(), strip_tags($comment->getText())))->emit(); - $this->flashFail("succ", "Комментарий добавлен", "Ваш комментарий появится на странице."); + $this->flashFail("succ", tr("comment_is_added"), tr("comment_is_added_desc")); } function renderDeleteComment(int $id): void @@ -150,15 +150,15 @@ final class CommentPresenter extends OpenVKPresenter $comment = (new Comments)->get($id); if(!$comment) $this->notFound(); if(!$comment->canBeDeletedBy($this->user->identity)) - $this->throwError(403, "Forbidden", "У вас недостаточно прав чтобы редактировать этот ресурс."); + $this->throwError(403, "Forbidden", tr("error_access_denied")); if ($comment->getTarget() instanceof Post && $comment->getTarget()->getWallOwner()->isBanned()) $this->flashFail("err", tr("error"), tr("forbidden")); $comment->delete(); $this->flashFail( "succ", - "Успешно", - "Этот комментарий больше не будет показыватся.
Отметить как спам?" + tr("success"), + tr("comment_will_not_appear") ); } } diff --git a/Web/Presenters/GiftsPresenter.php b/Web/Presenters/GiftsPresenter.php index 8f59bdcb..71480540 100644 --- a/Web/Presenters/GiftsPresenter.php +++ b/Web/Presenters/GiftsPresenter.php @@ -49,7 +49,7 @@ final class GiftsPresenter extends OpenVKPresenter $user = $this->users->get((int) ($this->queryParam("user") ?? 0)); $cat = $this->gifts->getCat((int) ($this->queryParam("pack") ?? 0)); if(!$user || !$cat) - $this->flashFail("err", "Не удалось подарить", "Пользователь или набор не существуют."); + $this->flashFail("err", tr("error_when_gifting"), tr("error_user_not_exists")); $this->template->page = $page = (int) ($this->queryParam("p") ?? 1); $gifts = $cat->getGifts($page, null, $this->template->count); @@ -66,14 +66,14 @@ final class GiftsPresenter extends OpenVKPresenter $gift = $this->gifts->get((int) ($this->queryParam("elid") ?? 0)); $cat = $this->gifts->getCat((int) ($this->queryParam("pack") ?? 0)); if(!$user || !$cat || !$gift || !$cat->hasGift($gift)) - $this->flashFail("err", "Не удалось подарить", "Не удалось подтвердить права на подарок."); + $this->flashFail("err", tr("error_when_gifting"), tr("error_no_rights_gifts")); if(!$gift->canUse($this->user->identity)) - $this->flashFail("err", "Не удалось подарить", "У вас больше не осталось таких подарков."); + $this->flashFail("err", tr("error_when_gifting"), tr("error_no_more_gifts")); $coinsLeft = $this->user->identity->getCoins() - $gift->getPrice(); if($coinsLeft < 0) - $this->flashFail("err", "Не удалось подарить", "Ору нищ не пук."); + $this->flashFail("err", tr("error_when_gifting"), tr("error_no_money")); $this->template->_template = "Gifts/Confirm.xml"; if($_SERVER["REQUEST_METHOD"] !== "POST") { @@ -91,7 +91,7 @@ final class GiftsPresenter extends OpenVKPresenter $user->gift($this->user->identity, $gift, $comment, !is_null($this->postParam("anonymous"))); $gift->used(); - $this->flash("succ", "Подарок отправлен", "Вы отправили подарок " . $user->getFirstName() . " за " . $gift->getPrice() . " голосов."); + $this->flash("succ", tr("gift_sent"), tr("gift_sent_desc", $user->getFirstName(), $gift->getPrice())); $this->redirect($user->getURL()); } diff --git a/Web/Presenters/GroupPresenter.php b/Web/Presenters/GroupPresenter.php index d8fbcb79..d3a46fd5 100644 --- a/Web/Presenters/GroupPresenter.php +++ b/Web/Presenters/GroupPresenter.php @@ -54,7 +54,7 @@ final class GroupPresenter extends OpenVKPresenter $club->save(); } catch(\PDOException $ex) { if($ex->getCode() == 23000) - $this->flashFail("err", "Ошибка", "Произошла ошибка на стороне сервера. Обратитесь к системному администратору."); + $this->flashFail("err", tr("error"), tr("error_on_server_side")); else throw $ex; } @@ -62,7 +62,7 @@ final class GroupPresenter extends OpenVKPresenter $club->toggleSubscription($this->user->identity); $this->redirect("/club" . $club->getId()); }else{ - $this->flashFail("err", "Ошибка", "Вы не ввели название группы."); + $this->flashFail("err", tr("error"), tr("error_no_group_name")); } } } @@ -132,7 +132,7 @@ final class GroupPresenter extends OpenVKPresenter $this->notFound(); if(!$club->canBeModifiedBy($this->user->identity ?? NULL)) - $this->flashFail("err", "Ошибка доступа", "У вас недостаточно прав, чтобы изменять этот ресурс."); + $this->flashFail("err", tr("error_access_denied_short"), tr("error_access_denied")); if(!is_null($hidden)) { if($club->getOwner()->getId() == $user->getId()) { @@ -150,9 +150,9 @@ final class GroupPresenter extends OpenVKPresenter } if($hidden) { - $this->flashFail("succ", "Операция успешна", "Теперь " . $user->getCanonicalName() . " будет показываться как обычный подписчик всем кроме других администраторов"); + $this->flashFail("succ", tr("success_action"), tr("x_is_now_hidden", $user->getCanonicalName())); } else { - $this->flashFail("succ", "Операция успешна", "Теперь все будут знать про то что " . $user->getCanonicalName() . " - администратор"); + $this->flashFail("succ", tr("success_action"), tr("x_is_now_showed", $user->getCanonicalName())); } } elseif($removeComment) { if($club->getOwner()->getId() == $user->getId()) { @@ -164,11 +164,11 @@ final class GroupPresenter extends OpenVKPresenter $manager->save(); } - $this->flashFail("succ", "Операция успешна", "Комментарий к администратору удален"); + $this->flashFail("succ", tr("success_action"), tr("comment_is_deleted")); } elseif($comment) { if(mb_strlen($comment) > 36) { $commentLength = (string) mb_strlen($comment); - $this->flashFail("err", "Ошибка", "Комментарий слишком длинный ($commentLength символов вместо 36 символов)"); + $this->flashFail("err", tr("error"), tr("comment_is_too_long", $commentLength)); } if($club->getOwner()->getId() == $user->getId()) { @@ -180,16 +180,16 @@ final class GroupPresenter extends OpenVKPresenter $manager->save(); } - $this->flashFail("succ", "Операция успешна", "Комментарий к администратору изменён"); + $this->flashFail("succ", tr("success_action"), tr("comment_is_changed")); }else{ if($club->canBeModifiedBy($user)) { $club->removeManager($user); - $this->flashFail("succ", "Операция успешна", $user->getCanonicalName() . " более не администратор."); + $this->flashFail("succ", tr("success_action"), tr("x_no_more_admin", $user->getCanonicalName())); } else { $club->addManager($user); (new ClubModeratorNotification($user, $club, $this->user->identity))->emit(); - $this->flashFail("succ", "Операция успешна", $user->getCanonicalName() . " назначен(а) администратором."); + $this->flashFail("succ", tr("success_action"), tr("x_is_admin", $user->getCanonicalName())); } } @@ -245,7 +245,7 @@ final class GroupPresenter extends OpenVKPresenter (new Albums)->getClubAvatarAlbum($club)->addPhoto($photo); } catch(ISE $ex) { $name = $album->getName(); - $this->flashFail("err", "Неизвестная ошибка", "Не удалось сохранить фотографию."); + $this->flashFail("err", tr("error"), tr("error_when_uploading_photo")); } } @@ -253,12 +253,12 @@ final class GroupPresenter extends OpenVKPresenter $club->save(); } catch(\PDOException $ex) { if($ex->getCode() == 23000) - $this->flashFail("err", "Ошибка", "Произошла ошибка на стороне сервера. Обратитесь к системному администратору."); + $this->flashFail("err", tr("error"), tr("error_on_server_side")); else throw $ex; } - $this->flash("succ", "Изменения сохранены", "Новые данные появятся в вашей группе."); + $this->flash("succ", tr("changes_saved"), tr("new_changes_desc")); } } @@ -298,7 +298,7 @@ final class GroupPresenter extends OpenVKPresenter } catch(ISE $ex) { $name = $album->getName(); - $this->flashFail("err", "Неизвестная ошибка", "Не удалось сохранить фотографию."); + $this->flashFail("err", tr("error"), tr("error_when_uploading_photo")); } } $this->returnJson([ @@ -350,7 +350,7 @@ final class GroupPresenter extends OpenVKPresenter $this->assertUserLoggedIn(); if(!eventdb()) - $this->flashFail("err", "Ошибка подключения", "Не удалось подключится к службе телеметрии."); + $this->flashFail("err", tr("connection_error"), tr("connection_error_desc")); $club = $this->clubs->get($id); if(!$club->canBeModifiedBy($this->user->identity)) diff --git a/Web/Presenters/NotesPresenter.php b/Web/Presenters/NotesPresenter.php index 50437ad7..4b71c8b1 100644 --- a/Web/Presenters/NotesPresenter.php +++ b/Web/Presenters/NotesPresenter.php @@ -107,7 +107,7 @@ final class NotesPresenter extends OpenVKPresenter if(!$note || $note->getOwner()->getId() !== $owner || $note->isDeleted()) $this->notFound(); if(is_null($this->user) || !$note->canBeModifiedBy($this->user->identity)) - $this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса."); + $this->flashFail("err", tr("error_access_denied_short"), tr("error_access_denied")); $this->template->note = $note; if($_SERVER["REQUEST_METHOD"] === "POST") { @@ -135,11 +135,11 @@ final class NotesPresenter extends OpenVKPresenter if(!$note) $this->notFound(); if($note->getOwner()->getId() . "_" . $note->getId() !== $owner . "_" . $id || $note->isDeleted()) $this->notFound(); if(is_null($this->user) || !$note->canBeModifiedBy($this->user->identity)) - $this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса."); + $this->flashFail("err", tr("error_access_denied_short"), tr("error_access_denied")); $name = $note->getName(); $note->delete(); - $this->flash("succ", "Заметка удалена", "Заметка \"$name\" была успешно удалена."); + $this->flash("succ", tr("note_is_deleted"), tr("note_x_is_now_deleted", $name)); $this->redirect("/notes" . $this->user->id); } } diff --git a/Web/Presenters/PhotosPresenter.php b/Web/Presenters/PhotosPresenter.php index 9d64ba20..bef984b7 100644 --- a/Web/Presenters/PhotosPresenter.php +++ b/Web/Presenters/PhotosPresenter.php @@ -27,7 +27,7 @@ final class PhotosPresenter extends OpenVKPresenter if(!$user) $this->notFound(); if (!$user->getPrivacyPermission('photos.read', $this->user->identity ?? NULL)) $this->flashFail("err", tr("forbidden"), tr("forbidden_comment")); - $this->template->albums = $this->albums->getUserAlbums($user, $this->queryParam("p") ?? 1); + $this->template->albums = $this->albums->getUserAlbums($user, (int)($this->queryParam("p") ?? 1)); $this->template->count = $this->albums->getUserAlbumsCount($user); $this->template->owner = $user; $this->template->canEdit = false; @@ -36,7 +36,7 @@ final class PhotosPresenter extends OpenVKPresenter } else { $club = (new Clubs)->get(abs($owner)); if(!$club) $this->notFound(); - $this->template->albums = $this->albums->getClubAlbums($club, $this->queryParam("p") ?? 1); + $this->template->albums = $this->albums->getClubAlbums($club, (int)($this->queryParam("p") ?? 1)); $this->template->count = $this->albums->getClubAlbumsCount($club); $this->template->owner = $club; $this->template->canEdit = false; @@ -46,7 +46,7 @@ final class PhotosPresenter extends OpenVKPresenter $this->template->paginatorConf = (object) [ "count" => $this->template->count, - "page" => $this->queryParam("p") ?? 1, + "page" => (int)($this->queryParam("p") ?? 1), "amount" => NULL, "perPage" => OPENVK_DEFAULT_PER_PAGE, ]; @@ -94,7 +94,7 @@ final class PhotosPresenter extends OpenVKPresenter if(!$album) $this->notFound(); if($album->getPrettyId() !== $owner . "_" . $id || $album->isDeleted()) $this->notFound(); if(is_null($this->user) || !$album->canBeModifiedBy($this->user->identity) || $album->isDeleted()) - $this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса."); + $this->flashFail("err", tr("error_access_denied_short"), tr("error_access_denied")); $this->template->album = $album; if($_SERVER["REQUEST_METHOD"] === "POST") { @@ -106,7 +106,7 @@ final class PhotosPresenter extends OpenVKPresenter $album->setEdited(time()); $album->save(); - $this->flash("succ", "Изменения сохранены", "Новые данные приняты."); + $this->flash("succ", tr("changes_saved"), tr("new_data_accepted")); } } @@ -120,13 +120,13 @@ final class PhotosPresenter extends OpenVKPresenter if(!$album) $this->notFound(); if($album->getPrettyId() !== $owner . "_" . $id || $album->isDeleted()) $this->notFound(); if(is_null($this->user) || !$album->canBeModifiedBy($this->user->identity)) - $this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса."); + $this->flashFail("err", tr("error_access_denied_short"), tr("error_access_denied")); $name = $album->getName(); $owner = $album->getOwner(); $album->delete(); - $this->flash("succ", "Альбом удалён", "Альбом $name был успешно удалён."); + $this->flash("succ", tr("album_is_deleted"), tr("album_x_is_deleted", $name)); $this->redirect("/albums" . ($owner instanceof Club ? "-" : "") . $owner->getId()); } @@ -147,7 +147,7 @@ final class PhotosPresenter extends OpenVKPresenter $this->template->photos = iterator_to_array( $album->getPhotos( (int) ($this->queryParam("p") ?? 1), 20) ); $this->template->paginatorConf = (object) [ "count" => $album->getPhotosCount(), - "page" => $this->queryParam("p") ?? 1, + "page" => (int)($this->queryParam("p") ?? 1), "amount" => sizeof($this->template->photos), "perPage" => 20, "atBottom" => true @@ -205,13 +205,13 @@ final class PhotosPresenter extends OpenVKPresenter $photo = $this->photos->getByOwnerAndVID($ownerId, $photoId); if(!$photo) $this->notFound(); if(is_null($this->user) || $this->user->id != $ownerId) - $this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса."); + $this->flashFail("err", tr("error_access_denied_short"), tr("error_access_denied")); if($_SERVER["REQUEST_METHOD"] === "POST") { $photo->setDescription(empty($this->postParam("desc")) ? NULL : $this->postParam("desc")); $photo->save(); - $this->flash("succ", "Изменения сохранены", "Обновлённое описание появится на странице с фоткой."); + $this->flash("succ", tr("changes_saved"), tr("new_description_will_appear")); $this->redirect("/photo" . $photo->getPrettyId()); } @@ -221,39 +221,74 @@ final class PhotosPresenter extends OpenVKPresenter function renderUploadPhoto(): void { $this->assertUserLoggedIn(); - $this->willExecuteWriteAction(); + $this->willExecuteWriteAction(true); if(is_null($this->queryParam("album"))) - $this->flashFail("err", "Неизвестная ошибка", "Не удалось сохранить фотографию в DELETED."); + $this->flashFail("err", tr("error"), tr("error_adding_to_deleted"), 500, true); [$owner, $id] = explode("_", $this->queryParam("album")); $album = $this->albums->get((int) $id); if(!$album) - $this->flashFail("err", "Неизвестная ошибка", "Не удалось сохранить фотографию в DELETED."); + $this->flashFail("err", tr("error"), tr("error_adding_to_deleted"), 500, true); if(is_null($this->user) || !$album->canBeModifiedBy($this->user->identity)) - $this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса."); + $this->flashFail("err", tr("error_access_denied_short"), tr("error_access_denied"), 500, true); if($_SERVER["REQUEST_METHOD"] === "POST") { - if(!isset($_FILES["blob"])) - $this->flashFail("err", "Нету фотографии", "Выберите файл."); - - try { - $photo = new Photo; - $photo->setOwner($this->user->id); - $photo->setDescription($this->postParam("desc")); - $photo->setFile($_FILES["blob"]); - $photo->setCreated(time()); - $photo->save(); - } catch(ISE $ex) { - $name = $album->getName(); - $this->flashFail("err", "Неизвестная ошибка", "Не удалось сохранить фотографию в $name."); - } - - $album->addPhoto($photo); - $album->setEdited(time()); - $album->save(); + if($this->queryParam("act") == "finish") { + $result = json_decode($this->postParam("photos"), true); + + foreach($result as $photoId => $description) { + $phot = $this->photos->get($photoId); - $this->redirect("/photo" . $photo->getPrettyId() . "?from=album" . $album->getId()); + if(!$phot || $phot->isDeleted() || $phot->getOwner()->getId() != $this->user->id) + continue; + + if(iconv_strlen($description) > 255) + $this->flashFail("err", tr("error"), tr("description_too_long"), 500, true); + + $phot->setDescription($description); + $phot->save(); + + $album = $phot->getAlbum(); + } + + $this->returnJson(["success" => true, + "album" => $album->getId(), + "owner" => $album->getOwner() instanceof User ? $album->getOwner()->getId() : $album->getOwner()->getId() * -1]); + } + + if(!isset($_FILES)) + $this->flashFail("err", tr("no_photo"), tr("select_file"), 500, true); + + $photos = []; + for($i = 0; $i < $this->postParam("count"); $i++) { + try { + $photo = new Photo; + $photo->setOwner($this->user->id); + $photo->setDescription(""); + $photo->setFile($_FILES["photo_".$i]); + $photo->setCreated(time()); + $photo->save(); + + $photos[] = [ + "url" => $photo->getURLBySizeId("tiny"), + "id" => $photo->getId(), + "vid" => $photo->getVirtualId(), + "owner" => $photo->getOwner()->getId(), + "link" => $photo->getURL() + ]; + } catch(ISE $ex) { + $name = $album->getName(); + $this->flashFail("err", "Неизвестная ошибка", "Не удалось сохранить фотографию в $name.", 500, true); + } + + $album->addPhoto($photo); + $album->setEdited(time()); + $album->save(); + } + + $this->returnJson(["success" => true, + "photos" => $photos]); } else { $this->template->album = $album; } @@ -269,7 +304,7 @@ final class PhotosPresenter extends OpenVKPresenter if(!$album || !$photo) $this->notFound(); if(!$album->hasPhoto($photo)) $this->notFound(); if(is_null($this->user) || !$album->canBeModifiedBy($this->user->identity)) - $this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса."); + $this->flashFail("err", tr("error_access_denied_short"), tr("error_access_denied")); if($_SERVER["REQUEST_METHOD"] === "POST") { $this->assertNoCSRF(); @@ -277,7 +312,7 @@ final class PhotosPresenter extends OpenVKPresenter $album->setEdited(time()); $album->save(); - $this->flash("succ", "Фотография удалена", "Эта фотография была успешно удалена."); + $this->flash("succ", tr("photo_is_deleted"), tr("photo_is_deleted_desc")); $this->redirect("/album" . $album->getPrettyId()); } } @@ -285,20 +320,23 @@ final class PhotosPresenter extends OpenVKPresenter function renderDeletePhoto(int $ownerId, int $photoId): void { $this->assertUserLoggedIn(); - $this->willExecuteWriteAction(); + $this->willExecuteWriteAction($_SERVER["REQUEST_METHOD"] === "POST"); $this->assertNoCSRF(); $photo = $this->photos->getByOwnerAndVID($ownerId, $photoId); if(!$photo) $this->notFound(); if(is_null($this->user) || $this->user->id != $ownerId) - $this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса."); + $this->flashFail("err", tr("error_access_denied_short"), tr("error_access_denied")); $redirect = $photo->getAlbum()->getOwner() instanceof User ? "/id0" : "/club" . $ownerId; $photo->isolate(); $photo->delete(); - $this->flash("succ", "Фотография удалена", "Эта фотография была успешно удалена."); + if($_SERVER["REQUEST_METHOD"] === "POST") + $this->returnJson(["success" => true]); + + $this->flash("succ", tr("photo_is_deleted"), tr("photo_is_deleted_desc")); $this->redirect($redirect); } } diff --git a/Web/Presenters/ReportPresenter.php b/Web/Presenters/ReportPresenter.php index 68d27861..a87154c8 100644 --- a/Web/Presenters/ReportPresenter.php +++ b/Web/Presenters/ReportPresenter.php @@ -118,22 +118,22 @@ final class ReportPresenter extends OpenVKPresenter $report->deleteContent(); $report->banUser($this->user->identity->getId()); - $this->flash("suc", "Смэрть...", "Пользователь успешно забанен."); + $this->flash("suc", tr("death"), tr("user_successfully_banned")); } else if ($this->postParam("delete")) { $report->deleteContent(); - $this->flash("suc", "Нехай живе!", "Контент удалён, а пользователю прилетело предупреждение."); + $this->flash("suc", tr("nehay"), tr("content_is_deleted")); } else if ($this->postParam("ignore")) { $report->delete(); - $this->flash("suc", "Нехай живе!", "Жалоба проигнорирована."); + $this->flash("suc", tr("nehay"), tr("report_is_ignored")); } else if ($this->postParam("banClubOwner") || $this->postParam("banClub")) { if ($report->getContentType() !== "group") - $this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса."); + $this->flashFail("err", tr("error_access_denied_short"), tr("error_access_denied")); $club = $report->getContentObject(); if (!$club || $club->isBanned()) - $this->flashFail("err", "Ошибка доступа", "Недостаточно прав для модификации данного ресурса."); + $this->flashFail("err", tr("error_access_denied_short"), tr("error_access_denied")); if ($this->postParam("banClubOwner")) { $club->getOwner()->ban("**content-" . $report->getContentType() . "-" . $report->getContentId() . "**", false, $club->getOwner()->getNewBanTime(), $this->user->identity->getId()); @@ -143,7 +143,7 @@ final class ReportPresenter extends OpenVKPresenter $report->delete(); - $this->flash("suc", "Смэрть...", ($this->postParam("banClubOwner") ? "Создатель сообщества успешно забанен." : "Сообщество успешно забанено")); + $this->flash("suc", tr("death"), ($this->postParam("banClubOwner") ? tr("group_owner_is_banned") : tr("group_is_banned"))); } $this->redirect("/scumfeed"); diff --git a/Web/Presenters/TopicsPresenter.php b/Web/Presenters/TopicsPresenter.php index e7b08ac3..92d67e84 100644 --- a/Web/Presenters/TopicsPresenter.php +++ b/Web/Presenters/TopicsPresenter.php @@ -111,7 +111,7 @@ final class TopicsPresenter extends OpenVKPresenter $video = Video::fastMake($this->user->id, $_FILES["_vid_attachment"]["name"], $this->postParam("text"), $_FILES["_vid_attachment"]); } } catch(ISE $ex) { - $this->flash("err", "Не удалось опубликовать комментарий", "Файл медиаконтента повреждён или слишком велик."); + $this->flash("err", tr("error_when_publishing_comment"), tr("error_comment_file_too_big")); $this->redirect("/topic" . $topic->getPrettyId()); } @@ -126,7 +126,7 @@ final class TopicsPresenter extends OpenVKPresenter $comment->setFlags($flags); $comment->save(); } catch (\LengthException $ex) { - $this->flash("err", "Не удалось опубликовать комментарий", "Комментарий слишком большой."); + $this->flash("err", tr("error_when_publishing_comment"), tr("error_comment_too_big")); $this->redirect("/topic" . $topic->getPrettyId()); } diff --git a/Web/Presenters/UserPresenter.php b/Web/Presenters/UserPresenter.php index 9cfa3654..51ddc6aa 100644 --- a/Web/Presenters/UserPresenter.php +++ b/Web/Presenters/UserPresenter.php @@ -72,7 +72,7 @@ final class UserPresenter extends OpenVKPresenter if(!is_null($this->user)) { if($this->template->mode !== "friends" && $this->user->id !== $id) { $name = $user->getFullName(); - $this->flash("err", "Ошибка доступа", "Вы не можете просматривать полный список подписок $name."); + $this->flash("err", tr("error_access_denied_short"), tr("error_viewing_subs", $name)); $this->redirect($user->getURL()); } @@ -107,11 +107,11 @@ final class UserPresenter extends OpenVKPresenter $this->notFound(); if(!$club->canBeModifiedBy($this->user->identity ?? NULL)) - $this->flashFail("err", "Ошибка доступа", "У вас недостаточно прав, чтобы изменять этот ресурс.", NULL, true); + $this->flashFail("err", tr("error_access_denied_short"), tr("error_access_denied"), NULL, true); $isClubPinned = $this->user->identity->isClubPinned($club); if(!$isClubPinned && $this->user->identity->getPinnedClubCount() > 10) - $this->flashFail("err", "Ошибка", "Находится в левом меню могут максимум 10 групп", NULL, true); + $this->flashFail("err", tr("error"), tr("error_max_pinned_clubs"), NULL, true); if($club->getOwner()->getId() === $this->user->identity->getId()) { $club->setOwner_Club_Pinned(!$isClubPinned); @@ -237,7 +237,7 @@ final class UserPresenter extends OpenVKPresenter } elseif($_GET['act'] === "status") { if(mb_strlen($this->postParam("status")) > 255) { $statusLength = (string) mb_strlen($this->postParam("status")); - $this->flashFail("err", "Ошибка", "Статус слишком длинный ($statusLength символов вместо 255 символов)", NULL, true); + $this->flashFail("err", tr("error"), tr("error_status_too_long", $statusLength), NULL, true); } $user->setStatus(empty($this->postParam("status")) ? NULL : $this->postParam("status")); @@ -281,7 +281,7 @@ final class UserPresenter extends OpenVKPresenter if($_SERVER["REQUEST_METHOD"] === "POST") { if(!$user->verifyNumber($this->postParam("code") ?? 0)) - $this->flashFail("err", "Ошибка", "Не удалось подтвердить номер телефона: неверный код."); + $this->flashFail("err", tr("error"), tr("invalid_code")); $this->flash("succ", tr("changes_saved"), tr("changes_saved_comment")); } @@ -481,6 +481,7 @@ final class UserPresenter extends OpenVKPresenter "menu_novajoj" => "news", "menu_ligiloj" => "links", "menu_standardo" => "poster", + "menu_aplikoj" => "apps" ]; foreach($settings as $checkbox => $setting) $user->setLeftMenuItemStatus($setting, $this->checkbox($checkbox)); diff --git a/Web/Presenters/VideosPresenter.php b/Web/Presenters/VideosPresenter.php index 4e4d484a..9d2fddc6 100644 --- a/Web/Presenters/VideosPresenter.php +++ b/Web/Presenters/VideosPresenter.php @@ -58,7 +58,7 @@ final class VideosPresenter extends OpenVKPresenter $this->willExecuteWriteAction(); if(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"), tr("video_uploads_disabled")); if($_SERVER["REQUEST_METHOD"] === "POST") { if(!empty($this->postParam("name"))) { @@ -74,18 +74,18 @@ final class VideosPresenter extends OpenVKPresenter else if(!empty($this->postParam("link"))) $video->setLink($this->postParam("link")); else - $this->flashFail("err", "Нету видеозаписи", "Выберите файл или укажите ссылку."); + $this->flashFail("err", tr("no_video"), tr("no_video_desc")); } catch(\DomainException $ex) { - $this->flashFail("err", "Произошла ошибка", "Файл повреждён или не содержит видео." ); + $this->flashFail("err", tr("error_occured"), tr("error_video_damaged_file")); } catch(ISE $ex) { - $this->flashFail("err", "Произошла ошибка", "Возможно, ссылка некорректна."); + $this->flashFail("err", tr("error_occured"), tr("error_video_incorrect_link")); } $video->save(); $this->redirect("/video" . $video->getPrettyId()); } else { - $this->flashFail("err", "Произошла ошибка", "Видео не может быть опубликовано без названия."); + $this->flashFail("err", tr("error_occured"), tr("error_video_no_title")); } } } @@ -99,14 +99,14 @@ final class VideosPresenter extends OpenVKPresenter if(!$video) $this->notFound(); if(is_null($this->user) || $this->user->id !== $owner) - $this->flashFail("err", "Ошибка доступа", "Вы не имеете права редактировать этот ресурс."); + $this->flashFail("err", tr("error_access_denied_short"), tr("error_access_denied")); if($_SERVER["REQUEST_METHOD"] === "POST") { $video->setName(empty($this->postParam("name")) ? NULL : $this->postParam("name")); $video->setDescription(empty($this->postParam("desc")) ? NULL : $this->postParam("desc")); $video->save(); - $this->flash("succ", "Изменения сохранены", "Обновлённое описание появится на странице с видосиком."); + $this->flash("succ", tr("changes_saved"), tr("new_data_video")); $this->redirect("/video" . $video->getPrettyId()); } @@ -128,7 +128,7 @@ final class VideosPresenter extends OpenVKPresenter $video->deleteVideo($owner, $vid); } } else { - $this->flashFail("err", "Не удалось удалить пост", "Вы не вошли в аккаунт."); + $this->flashFail("err", tr("error_deleting_video"), tr("login_please")); } $this->redirect("/videos" . $owner); diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index a195e4fb..ef9e4689 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -3,7 +3,7 @@ namespace openvk\Web\Presenters; use openvk\Web\Models\Exceptions\TooMuchOptionsException; use openvk\Web\Models\Entities\{Poll, Post, Photo, Video, Club, User}; use openvk\Web\Models\Entities\Notifications\{MentionNotification, RepostNotification, WallPostNotification}; -use openvk\Web\Models\Repositories\{Posts, Users, Clubs, Albums, Notes, Videos}; +use openvk\Web\Models\Repositories\{Posts, Users, Clubs, Albums, Notes, Videos, Comments}; use Chandler\Database\DatabaseConnection; use Nette\InvalidStateException as ISE; use Bhaktaraz\RSSGenerator\Item; @@ -231,7 +231,7 @@ final class WallPresenter extends OpenVKPresenter if(!$canPost) $this->flashFail("err", tr("not_enough_permissions"), tr("not_enough_permissions_comment")); - + $anon = OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["anonymousPosting"]["enable"]; if($wallOwner instanceof Club && $this->postParam("as_group") === "on" && $this->postParam("force_sign") !== "on" && $anon) { $manager = $wallOwner->getManager($this->user->identity); @@ -515,4 +515,64 @@ final class WallPresenter extends OpenVKPresenter # TODO localize message based on language and ?act=(un)pin $this->flashFail("succ", tr("information_-1"), tr("changes_saved_comment")); } + + function renderEdit() + { + $this->assertUserLoggedIn(); + $this->willExecuteWriteAction(); + + if($_SERVER["REQUEST_METHOD"] !== "POST") + $this->redirect("/id0"); + + if($this->postParam("type") == "post") + $post = $this->posts->get((int)$this->postParam("postid")); + else + $post = (new Comments)->get((int)$this->postParam("postid")); + + if(!$post || $post->isDeleted()) + $this->returnJson(["error" => "Invalid post"]); + + if(!$post->canBeEditedBy($this->user->identity)) + $this->returnJson(["error" => "Access denied"]); + + $attachmentsCount = sizeof(iterator_to_array($post->getChildren())); + + if(empty($this->postParam("newContent")) && $attachmentsCount < 1) + $this->returnJson(["error" => "Empty post"]); + + $post->setEdited(time()); + + try { + $post->setContent($this->postParam("newContent")); + } catch(\LengthException $e) { + $this->returnJson(["error" => $e->getMessage()]); + } + + if($this->postParam("type") === "post") { + $post->setNsfw($this->postParam("nsfw") == "true"); + $flags = 0; + + if($post->getTargetWall() < 0 && $post->getWallOwner()->canBeModifiedBy($this->user->identity)) { + if($this->postParam("fromgroup") == "true") { + $flags |= 0b10000000; + $post->setFlags($flags); + } else + $post->setFlags($flags); + } + } + + $post->save(true); + + $this->returnJson(["error" => "no", + "new_content" => $post->getText(), + "new_edited" => (string)$post->getEditTime(), + "nsfw" => $this->postParam("type") === "post" ? (int)$post->isExplicit() : 0, + "from_group" => $this->postParam("type") === "post" && $post->getTargetWall() < 0 ? + ((int)$post->isPostedOnBehalfOfGroup()) : "false", + "new_text" => $post->getText(false), + "author" => [ + "name" => $post->getOwner()->getCanonicalName(), + "avatar" => $post->getOwner()->getAvatarUrl() + ]]); + } } diff --git a/Web/Presenters/templates/@layout.xml b/Web/Presenters/templates/@layout.xml index 3d724cf5..f8a975e0 100644 --- a/Web/Presenters/templates/@layout.xml +++ b/Web/Presenters/templates/@layout.xml @@ -38,9 +38,8 @@

- Вы вошли как {$thisUser->getCanonicalName()}. Пожалуйста, уважайте - право на тайну переписки других людей и не злоупотребляйте подменой пользователя. - Нажмите здесь, чтобы выйти. + {_you_entered_as} {$thisUser->getCanonicalName()}. {_please_rights} + {_click_on} {_there}, {_to_leave}.

@@ -196,7 +195,7 @@ ({$thisUser->getNotificationsCount()}) {/if} - {_my_apps} + {_my_apps} {_my_settings} {var $canAccessAdminPanel = $thisUser->getChandlerUser()->can("access")->model("admin")->whichBelongsTo(NULL)} diff --git a/Web/Presenters/templates/About/BB.xml b/Web/Presenters/templates/About/BB.xml index 17ab3b0f..9aa745b6 100644 --- a/Web/Presenters/templates/About/BB.xml +++ b/Web/Presenters/templates/About/BB.xml @@ -1,12 +1,10 @@ {extends "../@layout.xml"} -{block title}Ваш браузер устарел{/block} +{block title}{_deprecated_browser}{/block} {block header} - Устаревший браузер + {_deprecated_browser} {/block} {block content} - Для просмотра этого контента вам понадобится Firefox ESR 52+ или - эквивалентный по функционалу навигатор по всемирной сети интернет.
- Сожалеем об этом. + {_deprecated_browser_description} {/block} diff --git a/Web/Presenters/templates/About/Help.xml b/Web/Presenters/templates/About/Help.xml index 060f1381..64be74a0 100644 --- a/Web/Presenters/templates/About/Help.xml +++ b/Web/Presenters/templates/About/Help.xml @@ -9,5 +9,5 @@
Для кого этот сайт?
Сайт предназначен для поиска друзей и знакомых, а также просмотр данных пользователя. Это как справочник города, с помощью которого люди могут быстро найти актуальную информацию о человеке. Также этот сайт подойдёт для ностальгираторов и тех, кто решил слезть с трубы "ВКонтакте", которого клон и является.
Я попозже допишу ок ~~ veselcraft - 12.01.2020 - 22:05 GMT+3 - + Давай {/block} diff --git a/Web/Presenters/templates/About/Sandbox.xml b/Web/Presenters/templates/About/Sandbox.xml index b84b515a..1b548a48 100644 --- a/Web/Presenters/templates/About/Sandbox.xml +++ b/Web/Presenters/templates/About/Sandbox.xml @@ -2,7 +2,7 @@ {block title}Sandbox{/block} {block header} - Sandbox для разработчиков + {_sandbox_for_developers} {/block} {block content} diff --git a/Web/Presenters/templates/Admin/BansHistory.xml b/Web/Presenters/templates/Admin/BansHistory.xml index c0dc1b64..2144c949 100644 --- a/Web/Presenters/templates/Admin/BansHistory.xml +++ b/Web/Presenters/templates/Admin/BansHistory.xml @@ -1,7 +1,7 @@ {extends "./@layout.xml"} {block title} - История блокировок + {_bans_history} {/block} {block heading} @@ -13,13 +13,13 @@ ID - Забаненный - Инициатор - Начало - Конец - Время - Причина - Снята + {_bans_history_blocked} + {_bans_history_initiator} + {_bans_history_start} + {_bans_history_end} + {_bans_history_time} + {_bans_history_reason} + {_bans_history_removed} @@ -77,7 +77,7 @@ {_admin_banned} {else} - Активная блокировка + {_bans_history_active} {/if} diff --git a/Web/Presenters/templates/Admin/Logs.xml b/Web/Presenters/templates/Admin/Logs.xml index d953a378..ab5e62f5 100644 --- a/Web/Presenters/templates/Admin/Logs.xml +++ b/Web/Presenters/templates/Admin/Logs.xml @@ -1,11 +1,11 @@ {extends "@layout.xml"} {block title} - Логи + {_logs} {/block} {block heading} - Логи + {_logs} {/block} {block content} @@ -18,23 +18,23 @@
- + + + + + - - + +
- + - +
@@ -42,11 +42,11 @@ ID - Пользователь - Объект - Тип - Изменения - Время + {_logs_user} + {_logs_object} + {_logs_type} + {_logs_changes} + {_logs_time} diff --git a/Web/Presenters/templates/Apps/Play.xml b/Web/Presenters/templates/Apps/Play.xml index facaa273..93637a2d 100644 --- a/Web/Presenters/templates/Apps/Play.xml +++ b/Web/Presenters/templates/Apps/Play.xml @@ -7,7 +7,7 @@ {block header} {$name} - Пожаловаться + {_report} {/block} {block content} @@ -37,20 +37,20 @@ - {_open_original}
{/block} diff --git a/Web/Presenters/templates/Photos/UnlinkPhoto.xml b/Web/Presenters/templates/Photos/UnlinkPhoto.xml index 54498e06..80a4ad2e 100644 --- a/Web/Presenters/templates/Photos/UnlinkPhoto.xml +++ b/Web/Presenters/templates/Photos/UnlinkPhoto.xml @@ -1,20 +1,20 @@ {extends "../@layout.xml"} -{block title}Удалить фотографию?{/block} +{block title}{_delete_photo}{/block} {block header} - Удаление фотографии + {_delete_photo} {/block} {block content} - Вы уверены что хотите удалить эту фотографию? + {_sure_deleting_photo}

- Нет + {_no}   - +
{/block} diff --git a/Web/Presenters/templates/Photos/UploadPhoto.xml b/Web/Presenters/templates/Photos/UploadPhoto.xml index 9876e5b9..ab81d3aa 100644 --- a/Web/Presenters/templates/Photos/UploadPhoto.xml +++ b/Web/Presenters/templates/Photos/UploadPhoto.xml @@ -2,9 +2,13 @@ {block title}{_upload_photo}{/block} {block header} - {$thisUser->getCanonicalName()} + {$album->getOwner()->getCanonicalName()} » - {_albums} + {if $album->getOwner() instanceof openvk\Web\Models\Entities\Club} + {_albums} + {else} + {_albums} + {/if} » {$album->getName()} » @@ -12,32 +16,53 @@ {/block} {block content} -
- - - - - - - - - - - - - - - -
{_description}:
{_photo}: - -
-
- - -
- - -
+
+
+ {_edit_album} +
+
+ {_add_photos} +
+
+ + + +
+
+
+
+

{_uploading_photos_from_computer}

+ +
+ {_admin_limits} +
    +
  • {_supported_formats}
  • +
  • {_max_load_photos}
  • +
+ +
+ +
+ +
+ {_tip}: {_tip_ctrl} +
+
+
+
+ +
+ + +
+ + + + +{/block} + +{block bodyScripts} + {script "js/al_photos.js"} {/block} diff --git a/Web/Presenters/templates/User/Edit.xml b/Web/Presenters/templates/User/Edit.xml index 6df070ea..b8e8398c 100644 --- a/Web/Presenters/templates/User/Edit.xml +++ b/Web/Presenters/templates/User/Edit.xml @@ -344,9 +344,9 @@
- +
- +
diff --git a/Web/Presenters/templates/User/Settings.xml b/Web/Presenters/templates/User/Settings.xml index e61f900d..c8f0f61b 100644 --- a/Web/Presenters/templates/User/Settings.xml +++ b/Web/Presenters/templates/User/Settings.xml @@ -190,13 +190,13 @@