diff --git a/VKAPI/Handlers/Account.php b/VKAPI/Handlers/Account.php index c8f501b8..adb9049d 100644 --- a/VKAPI/Handlers/Account.php +++ b/VKAPI/Handlers/Account.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace openvk\VKAPI\Handlers; use openvk\Web\Models\Exceptions\InvalidUserNameException; +use openvk\Web\Util\Validator; final class Account extends VKAPIRequestHandler { @@ -95,7 +96,7 @@ final class Account extends VKAPIRequestHandler # TODO: Filter } - public function saveProfileInfo(string $first_name = "", string $last_name = "", string $screen_name = "", int $sex = -1, int $relation = -1, string $bdate = "", int $bdate_visibility = -1, string $home_town = "", string $status = ""): object + public function saveProfileInfo(string $first_name = "", string $last_name = "", string $screen_name = "", int $sex = -1, int $relation = -1, string $bdate = "", int $bdate_visibility = -1, string $home_town = "", string $status = "", string $telegram = null): object { $this->requireUser(); $this->willExecuteWriteAction(); @@ -138,13 +139,13 @@ final class Account extends VKAPIRequestHandler $user->setSex($sex == 1 ? 1 : 0); } - if ($relation > -1) { + if ($relation > -1 && $relation <= 8) { $user->setMarital_Status($relation); } if (!empty($bdate)) { $birthday = strtotime($bdate); - if (!is_int($birthday)) { + if (!is_int($birthday) || $birthday > time()) { $this->fail(100, "invalid value of bdate."); } @@ -171,9 +172,26 @@ final class Account extends VKAPIRequestHandler $user->setStatus($status); } - if ($sex > 0 || $relation > -1 || $bdate_visibility > 1 || !empty("$first_name$last_name$screen_name$bdate$home_town$status")) { + if (!is_null($telegram)) { + if (empty($telegram)) { + $user->setTelegram(null); + } elseif (Validator::i()->telegramValid($telegram)) { + if (strpos($telegram, "t.me/") === 0) { + $user->setTelegram($telegram); + } else { + $user->setTelegram(ltrim($telegram, "@")); + } + } + } + + if ($sex > 0 || $relation > -1 || $bdate_visibility > 1 || !is_null($telegram) || !empty("$first_name$last_name$screen_name$bdate$home_town$status")) { $output["changed"] = 1; - $user->save(); + + try { + $user->save(); + } catch (\TypeError $e) { + $output["changed"] = 0; + } } return (object) $output; @@ -183,7 +201,7 @@ final class Account extends VKAPIRequestHandler { $this->requireUser(); if (!OPENVK_ROOT_CONF['openvk']['preferences']['commerce']) { - $this->fail(105, "Commerce is disabled on this instance"); + $this->fail(-105, "Commerce is disabled on this instance"); } return (object) ['votes' => $this->getUser()->getCoins()]; diff --git a/VKAPI/Handlers/Board.php b/VKAPI/Handlers/Board.php index c5b55fa8..e2e9b86b 100644 --- a/VKAPI/Handlers/Board.php +++ b/VKAPI/Handlers/Board.php @@ -14,7 +14,7 @@ use openvk\Web\Models\Entities\{Topic, Comment, User, Photo, Video}; final class Board extends VKAPIRequestHandler { - public function addTopic(int $group_id, string $title, string $text = "", bool $from_group = true) + public function addTopic(int $group_id, string $title, string $text = null, bool $from_group = true) { $this->requireUser(); $this->willExecuteWriteAction(); @@ -30,6 +30,7 @@ final class Board extends VKAPIRequestHandler } $flags = 0; + if ($from_group == true && $club->canBeModifiedBy($this->getUser())) { $flags |= 0b10000000; } @@ -40,17 +41,23 @@ final class Board extends VKAPIRequestHandler $topic->setTitle(ovk_proc_strtr($title, 127)); $topic->setCreated(time()); $topic->setFlags($flags); + $topic->save(); - if (!empty($text)) { - $comment = new Comment(); - $comment->setOwner($this->getUser()->getId()); - $comment->setModel(get_class($topic)); - $comment->setTarget($topic->getId()); - $comment->setContent($text); - $comment->setCreated(time()); - $comment->setFlags($flags); - $comment->save(); + try { + if (!empty($text)) { + $comment = new Comment(); + $comment->setOwner($this->getUser()->getId()); + $comment->setModel(get_class($topic)); + $comment->setTarget($topic->getId()); + $comment->setContent($text); + $comment->setCreated(time()); + $comment->setFlags($flags); + + $comment->save(); + } + } catch (\Throwable $e) { + return $topic->getId(); } return $topic->getId(); @@ -75,32 +82,35 @@ final class Board extends VKAPIRequestHandler return 1; } - public function createComment(int $group_id, int $topic_id, string $message = "", string $attachments = "", bool $from_group = true) + public function createComment(int $group_id, int $topic_id, string $message = "", bool $from_group = true) { $this->requireUser(); $this->willExecuteWriteAction(); - if (empty($message) && empty($attachments)) { + if (empty($message)) { $this->fail(100, "Required parameter 'message' missing."); } $topic = (new TopicsRepo())->getTopicById($group_id, $topic_id); + if (!$topic || $topic->isDeleted() || $topic->isClosed()) { $this->fail(15, "Access denied"); } $flags = 0; - if ($from_group != 0 && !is_null($topic->getClub()) && $topic->getClub()->canBeModifiedBy($this->user)) { + if ($from_group != 0 && ($topic->getClub()->canBeModifiedBy($this->user))) { $flags |= 0b10000000; } $comment = new Comment(); + $comment->setOwner($this->getUser()->getId()); $comment->setModel(get_class($topic)); $comment->setTarget($topic->getId()); $comment->setContent($message); $comment->setCreated(time()); $comment->setFlags($flags); + $comment->save(); return $comment->getId(); @@ -113,7 +123,7 @@ final class Board extends VKAPIRequestHandler $topic = (new TopicsRepo())->getTopicById($group_id, $topic_id); - if (!$topic || !$topic->getClub() || $topic->isDeleted() || !$topic->getClub()->canBeModifiedBy($this->getUser())) { + if (!$topic || $topic->isDeleted() || !$topic->getClub()->canBeModifiedBy($this->getUser())) { return 0; } @@ -129,7 +139,7 @@ final class Board extends VKAPIRequestHandler $topic = (new TopicsRepo())->getTopicById($group_id, $topic_id); - if (!$topic || !$topic->getClub() || $topic->isDeleted() || !$topic->getClub()->canBeModifiedBy($this->getUser())) { + if (!$topic || $topic->isDeleted() || !$topic->canBeModifiedBy($this->getUser())) { return 0; } @@ -147,7 +157,7 @@ final class Board extends VKAPIRequestHandler $topic = (new TopicsRepo())->getTopicById($group_id, $topic_id); - if (!$topic || !$topic->getClub() || !$topic->getClub()->canBeModifiedBy($this->getUser())) { + if (!$topic || !$topic->getClub()->canBeModifiedBy($this->getUser())) { return 0; } @@ -158,75 +168,92 @@ final class Board extends VKAPIRequestHandler return 1; } - public function getComments(int $group_id, int $topic_id, bool $need_likes = false, int $start_comment_id = 0, int $offset = 0, int $count = 40, bool $extended = false, string $sort = "asc") + public function getComments(int $group_id, int $topic_id, bool $need_likes = false, int $offset = 0, int $count = 10, bool $extended = false) { - # start_comment_id ne robit $this->requireUser(); + if ($count < 1 || $count > 100) { + $this->fail(4, "Invalid count"); + } + $topic = (new TopicsRepo())->getTopicById($group_id, $topic_id); - if (!$topic || !$topic->getClub() || $topic->isDeleted()) { - $this->fail(5, "Invalid topic"); + if (!$topic || $topic->isDeleted()) { + $this->fail(5, "Not found"); } - $arr = [ + $obj = (object) [ "items" => [], ]; - $comms = array_slice(iterator_to_array($topic->getComments(1, $count + $offset)), $offset); - foreach ($comms as $comm) { - $arr["items"][] = $this->getApiBoardComment($comm, $need_likes); + if ($extended) { + $obj->profiles = []; + $obj->groups = []; + } + + $comments = array_slice(iterator_to_array($topic->getComments(1, $count + $offset)), $offset); + + foreach ($comments as $comment) { + $obj->items[] = $comment->toVkApiStruct($this->getUser(), $need_likes); if ($extended) { - if ($comm->getOwner() instanceof \openvk\Web\Models\Entities\User) { - $arr["profiles"][] = $comm->getOwner()->toVkApiStruct(); + $owner = $comment->getOwner(); + + if ($owner instanceof \openvk\Web\Models\Entities\User) { + $obj->profiles[] = $owner->toVkApiStruct(); } - if ($comm->getOwner() instanceof \openvk\Web\Models\Entities\Club) { - $arr["groups"][] = $comm->getOwner()->toVkApiStruct(); + if ($owner instanceof \openvk\Web\Models\Entities\Club) { + $obj->groups[] = $owner->toVkApiStruct(); } } } - return $arr; + return $obj; } - public function getTopics(int $group_id, string $topic_ids = "", int $order = 1, int $offset = 0, int $count = 40, bool $extended = false, int $preview = 0, int $preview_length = 90) + public function getTopics(int $group_id, string $topic_ids = "", int $offset = 0, int $count = 10, bool $extended = false, int $preview = 0, int $preview_length = 90) { - # order и extended ничё не делают + # TODO: $extended + $this->requireUser(); - $arr = []; + if ($count < 1 || $count > 100) { + $this->fail(4, "Invalid count"); + } + + $obj = (object) []; + $club = (new ClubsRepo())->get($group_id); + if (!$club || !$club->canBeViewedBy($this->getUser())) { + $this->fail(15, "Access denied"); + } + $topics = array_slice(iterator_to_array((new TopicsRepo())->getClubTopics($club, 1, $count + $offset)), $offset); - $arr["count"] = (new TopicsRepo())->getClubTopicsCount($club); - $arr["items"] = []; - $arr["default_order"] = $order; - $arr["can_add_topics"] = $club->canBeModifiedBy($this->getUser()) ? true : ($club->isEveryoneCanCreateTopics() ? true : false); - $arr["profiles"] = []; + + $obj->count = (new TopicsRepo())->getClubTopicsCount($club); + $obj->items = []; + $obj->profiles = []; + $obj->can_add_topics = $club->canBeModifiedBy($this->getUser()) ? true : ($club->isEveryoneCanCreateTopics() ? true : false); if (empty($topic_ids)) { foreach ($topics as $topic) { - if ($topic->isDeleted()) { - continue; - } - $arr["items"][] = $topic->toVkApiStruct($preview, $preview_length > 1 ? $preview_length : 90); + $obj->items[] = $topic->toVkApiStruct($preview, $preview_length > 1 ? $preview_length : 90); } } else { $topics = explode(',', $topic_ids); - foreach ($topics as $topic) { - $id = explode("_", $topic); - $topicy = (new TopicsRepo())->getTopicById((int) $id[0], (int) $id[1]); + foreach ($topics as $topic_id) { + $topic = (new TopicsRepo())->getTopicById($group_id, (int) $topic_id); - if ($topicy && !$topicy->isDeleted()) { - $arr["items"][] = $topicy->toVkApiStruct($preview, $preview_length > 1 ? $preview_length : 90); + if ($topic && !$topic->isDeleted()) { + $obj->items[] = $topic->toVkApiStruct($preview, $preview_length > 1 ? $preview_length : 90); } } } - return $arr; + return $obj; } public function openTopic(int $group_id, int $topic_id) @@ -236,7 +263,7 @@ final class Board extends VKAPIRequestHandler $topic = (new TopicsRepo())->getTopicById($group_id, $topic_id); - if (!$topic || !$topic->getClub() || !$topic->isDeleted() || !$topic->getClub()->canBeModifiedBy($this->getUser())) { + if (!$topic || !$topic->isDeleted() || !$topic->getClub()->canBeModifiedBy($this->getUser())) { return 0; } @@ -248,11 +275,6 @@ final class Board extends VKAPIRequestHandler return 1; } - public function restoreComment(int $group_id, int $topic_id, int $comment_id) - { - $this->fail(501, "Not implemented"); - } - public function unfixTopic(int $group_id, int $topic_id) { $this->requireUser(); @@ -260,7 +282,7 @@ final class Board extends VKAPIRequestHandler $topic = (new TopicsRepo())->getTopicById($group_id, $topic_id); - if (!$topic || !$topic->getClub() || !$topic->getClub()->canBeModifiedBy($this->getUser())) { + if (!$topic || !$topic->getClub()->canBeModifiedBy($this->getUser())) { return 0; } @@ -275,33 +297,4 @@ final class Board extends VKAPIRequestHandler return 1; } - - private function getApiBoardComment(?Comment $comment, bool $need_likes = false) - { - $res = (object) []; - - $res->id = $comment->getId(); - $res->from_id = $comment->getOwner()->getId(); - $res->date = $comment->getPublicationTime()->timestamp(); - $res->text = $comment->getText(false); - $res->attachments = []; - $res->likes = []; - if ($need_likes) { - $res->likes = [ - "count" => $comment->getLikesCount(), - "user_likes" => (int) $comment->hasLikeFrom($this->getUser()), - "can_like" => 1, # а чё типо не может ахахаххахах - ]; - } - - foreach ($comment->getChildren() as $attachment) { - if ($attachment->isDeleted()) { - continue; - } - - $res->attachments[] = $attachment->toVkApiStruct(); - } - - return $res; - } } diff --git a/VKAPI/Handlers/Gifts.php b/VKAPI/Handlers/Gifts.php index fe1232b7..9ee5d222 100644 --- a/VKAPI/Handlers/Gifts.php +++ b/VKAPI/Handlers/Gifts.php @@ -10,62 +10,43 @@ use openvk\Web\Models\Entities\Notifications\GiftNotification; final class Gifts extends VKAPIRequestHandler { - public function get(int $user_id = null, int $count = 10, int $offset = 0) + public function get(int $user_id = 0, int $count = 10, int $offset = 0) { + # There is no extended :) + $this->requireUser(); - $i = 0; - $i += $offset; $server_url = ovk_scheme(true) . $_SERVER["HTTP_HOST"]; - if ($user_id) { - $user = (new UsersRepo())->get($user_id); - } else { - $user = $this->getUser(); + if ($user_id < 1) { + $user_id = $this->getUser()->getId(); } + $user = (new UsersRepo())->get($user_id); + if (!$user || $user->isDeleted()) { - $this->fail(177, "Invalid user"); - } - - if (!$user->canBeViewedBy($this->getUser())) { $this->fail(15, "Access denied"); } - /* - if(!$user->getPrivacyPermission('gifts.read', $this->getUser())) - $this->fail(15, "Access denied: this user chose to hide his gifts");*/ - - if (!$user->canBeViewedBy($this->getUser())) { $this->fail(15, "Access denied"); } $gift_item = []; + $user_gifts = array_slice(iterator_to_array($user->getGifts(1, $count)), $offset, $count); - $userGifts = array_slice(iterator_to_array($user->getGifts(1, $count, false)), $offset); - - if (sizeof($userGifts) < 0) { - return null; - } - - foreach ($userGifts as $gift) { - if ($i < $count) { - $gift_item[] = [ - "id" => $i, - "from_id" => $gift->anon == true ? 0 : $gift->sender->getId(), - "message" => $gift->caption == null ? "" : $gift->caption, - "date" => $gift->sent->timestamp(), - "gift" => [ - "id" => $gift->gift->getId(), - "thumb_256" => $server_url . $gift->gift->getImage(2), - "thumb_96" => $server_url . $gift->gift->getImage(2), - "thumb_48" => $server_url . $gift->gift->getImage(2), - ], - "privacy" => 0, - ]; - } - $i += 1; + foreach ($user_gifts as $gift) { + $gift_item[] = [ + "from_id" => $gift->anon == true ? 0 : $gift->sender->getId(), + "message" => $gift->caption == null ? "" : $gift->caption, + "date" => $gift->sent->timestamp(), + "gift" => [ + "id" => $gift->gift->getId(), + "thumb_256" => $server_url . $gift->gift->getImage(2), + "thumb_96" => $server_url . $gift->gift->getImage(2), + "thumb_48" => $server_url . $gift->gift->getImage(2), + ], + ]; } return $gift_item; @@ -76,14 +57,14 @@ final class Gifts extends VKAPIRequestHandler $this->requireUser(); $this->willExecuteWriteAction(); - $user = (new UsersRepo())->get((int) $user_ids); - if (!OPENVK_ROOT_CONF['openvk']['preferences']['commerce']) { - $this->fail(105, "Commerce is disabled on this instance"); + $this->fail(-105, "Commerce is disabled on this instance"); } + $user = (new UsersRepo())->get((int) $user_ids); # FAKE прогноз погоды (в данном случае user_ids) + if (!$user || $user->isDeleted()) { - $this->fail(177, "Invalid user"); + $this->fail(15, "Access denied"); } if (!$user->canBeViewedBy($this->getUser())) { @@ -93,7 +74,7 @@ final class Gifts extends VKAPIRequestHandler $gift = (new GiftsRepo())->get($gift_id); if (!$gift) { - $this->fail(165, "Invalid gift"); + $this->fail(15, "Invalid gift"); } $price = $gift->getPrice(); @@ -134,24 +115,17 @@ final class Gifts extends VKAPIRequestHandler ]; } - public function delete() - { - $this->requireUser(); - $this->willExecuteWriteAction(); - - $this->fail(501, "Not implemented"); - } - - # в vk кстати называется gifts.getCatalog public function getCategories(bool $extended = false, int $page = 1) { + $this->requireUser(); + $cats = (new GiftsRepo())->getCategories($page); $categ = []; $i = 0; $server_url = ovk_scheme(true) . $_SERVER["HTTP_HOST"]; if (!OPENVK_ROOT_CONF['openvk']['preferences']['commerce']) { - $this->fail(105, "Commerce is disabled on this instance"); + $this->fail(-105, "Commerce is disabled on this instance"); } foreach ($cats as $cat) { @@ -184,17 +158,19 @@ final class Gifts extends VKAPIRequestHandler $this->requireUser(); if (!OPENVK_ROOT_CONF['openvk']['preferences']['commerce']) { - $this->fail(105, "Commerce is disabled on this instance"); + $this->fail(-105, "Commerce is disabled on this instance"); } - if (!(new GiftsRepo())->getCat($id)) { - $this->fail(177, "Category not found"); + $gift_category = (new GiftsRepo())->getCat($id); + + if (!$gift_category) { + $this->fail(15, "Category not found"); } - $giftz = ((new GiftsRepo())->getCat($id))->getGifts($page); + $gifts_list = $gift_category->getGifts($page); $gifts = []; - foreach ($giftz as $gift) { + foreach ($gifts_list as $gift) { $gifts[] = [ "name" => $gift->getName(), "image" => $gift->getImage(2), diff --git a/VKAPI/Handlers/Groups.php b/VKAPI/Handlers/Groups.php index 7f80d108..8933ca5a 100644 --- a/VKAPI/Handlers/Groups.php +++ b/VKAPI/Handlers/Groups.php @@ -107,7 +107,6 @@ final class Groups extends VKAPIRequestHandler $backgrounds = $usr->getBackDropPictureURLs(); $rClubs[$i]->background = $backgrounds; break; - # unstandard feild case "suggested_count": if ($usr->getWallType() != 2) { $rClubs[$i]->suggested_count = null; @@ -246,7 +245,7 @@ final class Groups extends VKAPIRequestHandler $response[$i]->suggested_count = $clb->getSuggestedPostsCount($this->getUser()); break; case "contacts": - $contacts; + $contacts = []; $contactTmp = $clb->getManagers(1, true); foreach ($contactTmp as $contact) { @@ -335,23 +334,6 @@ final class Groups extends VKAPIRequestHandler return 1; } - public function create(string $title, string $description = "", string $type = "group", int $public_category = 1, int $public_subcategory = 1, int $subtype = 1) - { - $this->requireUser(); - $this->willExecuteWriteAction(); - - $club = new Club(); - - $club->setName($title); - $club->setAbout($description); - $club->setOwner($this->getUser()->getId()); - $club->save(); - - $club->toggleSubscription($this->getUser()); - - return $this->getById((string) $club->getId()); - } - public function edit( int $group_id, string $title = null, @@ -371,13 +353,15 @@ final class Groups extends VKAPIRequestHandler $club = (new ClubsRepo())->get($group_id); if (!$club) { - $this->fail(203, "Club not found"); + $this->fail(15, "Access denied"); } + if (!$club || !$club->canBeModifiedBy($this->getUser())) { - $this->fail(15, "You can't modify this group."); + $this->fail(15, "Access denied"); } + if (!empty($screen_name) && !$club->setShortcode($screen_name)) { - $this->fail(103, "Invalid shortcode."); + $this->fail(103, "Invalid screen_name"); } !empty($title) ? $club->setName($title) : null; @@ -404,260 +388,86 @@ final class Groups extends VKAPIRequestHandler try { $club->save(); } catch (\TypeError $e) { - $this->fail(15, "Nothing changed"); + return 1; } catch (\Exception $e) { - $this->fail(18, "An unknown error occurred: maybe you set an incorrect value?"); + return 0; } return 1; } - public function getMembers(string $group_id, string $sort = "id_asc", int $offset = 0, int $count = 100, string $fields = "", string $filter = "any") + public function getMembers(int $group_id, int $offset = 0, int $count = 10, string $fields = "") { - # bdate,can_post,can_see_all_posts,can_see_audio,can_write_private_message,city,common_count,connections,contacts,country,domain,education,has_mobile,last_seen,lists,online,online_mobile,photo_100,photo_200,photo_200_orig,photo_400_orig,photo_50,photo_max,photo_max_orig,relation,relatives,schools,sex,site,status,universities - $club = (new ClubsRepo())->get((int) $group_id); - if (!$club) { - $this->fail(125, "Invalid group id"); + $this->requireUser(); + + $club = (new ClubsRepo())->get($group_id); + + if (!$club || !$club->canBeViewedBy($this->getUser())) { + $this->fail(15, "Access denied"); } - $sorter = "follower ASC"; + $sort_string = "follower ASC"; + $members = array_slice(iterator_to_array($club->getFollowers(1, $count, $sort_string)), $offset, $count); - switch ($sort) { - default: - case "time_asc": - case "id_asc": - $sorter = "follower ASC"; - break; - case "time_desc": - case "id_desc": - $sorter = "follower DESC"; - break; - } + $obj = (object) [ + "count" => sizeof($members), + "items" => [], + ]; - $members = array_slice(iterator_to_array($club->getFollowers(1, $count, $sorter)), $offset); - $arr = (object) [ - "count" => count($members), - "items" => []]; - - $filds = explode(",", $fields); - - $i = 0; foreach ($members as $member) { - if ($i > $count) { - break; - } - - $arr->items[] = (object) [ - "id" => $member->getId(), - "first_name" => $member->getFirstName(), - "last_name" => $member->getLastName(), - ]; - - foreach ($filds as $fild) { - $canView = $member->canBeViewedBy($this->getUser()); - switch ($fild) { - case "bdate": - if (!$canView) { - $arr->items[$i]->bdate = "01.01.1970"; - break; - } - - $arr->items[$i]->bdate = $member->getBirthday() ? $member->getBirthday()->format('%e.%m.%Y') : null; - break; - case "can_post": - $arr->items[$i]->can_post = $club->canBeModifiedBy($member); - break; - case "can_see_all_posts": - $arr->items[$i]->can_see_all_posts = 1; - break; - case "can_see_audio": - $arr->items[$i]->can_see_audio = 1; - break; - case "can_write_private_message": - $arr->items[$i]->can_write_private_message = 0; - break; - case "common_count": - $arr->items[$i]->common_count = 420; - break; - case "connections": - $arr->items[$i]->connections = 1; - break; - case "contacts": - if (!$canView) { - $arr->items[$i]->contacts = "secret@gmail.com"; - break; - } - - $arr->items[$i]->contacts = $member->getContactEmail(); - break; - case "country": - $arr->items[$i]->country = 1; - break; - case "domain": - $arr->items[$i]->domain = ""; - break; - case "education": - $arr->items[$i]->education = ""; - break; - case "has_mobile": - $arr->items[$i]->has_mobile = false; - break; - case "last_seen": - if (!$canView) { - $arr->items[$i]->last_seen = 0; - break; - } - - $arr->items[$i]->last_seen = $member->getOnline()->timestamp(); - break; - case "lists": - $arr->items[$i]->lists = ""; - break; - case "online": - if (!$canView) { - $arr->items[$i]->online = false; - break; - } - - $arr->items[$i]->online = $member->isOnline(); - break; - case "online_mobile": - if (!$canView) { - $arr->items[$i]->online_mobile = false; - break; - } - - $arr->items[$i]->online_mobile = $member->getOnlinePlatform() == "android" || $member->getOnlinePlatform() == "iphone" || $member->getOnlinePlatform() == "mobile"; - break; - case "photo_100": - $arr->items[$i]->photo_100 = $member->getAvatarURL("tiny"); - break; - case "photo_200": - $arr->items[$i]->photo_200 = $member->getAvatarURL("normal"); - break; - case "photo_200_orig": - $arr->items[$i]->photo_200_orig = $member->getAvatarURL("normal"); - break; - case "photo_400_orig": - $arr->items[$i]->photo_400_orig = $member->getAvatarURL("normal"); - break; - case "photo_max": - $arr->items[$i]->photo_max = $member->getAvatarURL("original"); - break; - case "photo_max_orig": - $arr->items[$i]->photo_max_orig = $member->getAvatarURL(); - break; - case "relation": - $arr->items[$i]->relation = $member->getMaritalStatus(); - break; - case "relatives": - $arr->items[$i]->relatives = 0; - break; - case "schools": - $arr->items[$i]->schools = 0; - break; - case "sex": - if (!$canView) { - $arr->items[$i]->sex = -1; - break; - } - - $arr->items[$i]->sex = $member->isFemale() ? 1 : 2; - break; - case "site": - if (!$canView) { - $arr->items[$i]->site = null; - break; - } - - $arr->items[$i]->site = $member->getWebsite(); - break; - case "status": - if (!$canView) { - $arr->items[$i]->status = "r"; - break; - } - - $arr->items[$i]->status = $member->getStatus(); - break; - case "universities": - $arr->items[$i]->universities = 0; - break; - } - } - $i++; + $obj->items[] = $member->toVkApiStruct($this->getUser(), $fields); } - return $arr; + + return $obj; } public function getSettings(string $group_id) { $this->requireUser(); + $club = (new ClubsRepo())->get((int) $group_id); if (!$club || !$club->canBeModifiedBy($this->getUser())) { - $this->fail(15, "You can't get settings of this group."); + $this->fail(15, "Access denied"); } $arr = (object) [ "title" => $club->getName(), - "description" => $club->getDescription() != null ? $club->getDescription() : "", + "description" => $club->getDescription(), "address" => $club->getShortcode(), - "wall" => $club->getWallType(), # отличается от вкшных но да ладно + "wall" => $club->getWallType(), # is different from vk values "photos" => 1, "video" => 0, "audio" => $club->isEveryoneCanUploadAudios() ? 1 : 0, - "docs" => 0, + "docs" => 1, "topics" => $club->isEveryoneCanCreateTopics() == true ? 1 : 0, - "wiki" => 0, - "messages" => 0, - "obscene_filter" => 0, - "obscene_stopwords" => 0, - "obscene_words" => "", - "access" => 1, - "subject" => 1, - "subject_list" => [ - 0 => "в", - 1 => "опенвк", - 2 => "нет", - 3 => "категорий", - 4 => "групп", - ], - "rss" => "/club" . $club->getId() . "/rss", "website" => $club->getWebsite(), - "age_limits" => 0, - "market" => [], ]; return $arr; } - public function isMember(string $group_id, int $user_id, string $user_ids = "", bool $extended = false) + public function isMember(string $group_id, int $user_id, int $extended = 0) { $this->requireUser(); - $id = $user_id != null ? $user_id : explode(",", $user_ids); - if ($group_id < 0) { - $this->fail(228, "Remove the minus from group_id"); + $input_club = (new ClubsRepo())->get(abs((int) $group_id)); + $input_user = (new UsersRepo())->get(abs((int) $user_id)); + + if (!$input_club || !$input_club->canBeViewedBy($this->getUser())) { + $this->fail(15, "Access denied"); } - $club = (new ClubsRepo())->get((int) $group_id); - $usver = (new UsersRepo())->get((int) $id); - - if (!$club || $group_id == 0) { - $this->fail(203, "Invalid club"); + if (!$input_user || $input_user->isDeleted()) { + $this->fail(15, "Not found"); } - if (!$usver || $usver->isDeleted() || $user_id == 0) { - $this->fail(30, "Invalid user"); - } - - if ($extended == false) { - return $club->getSubscriptionStatus($usver) ? 1 : 0; + if ($extended == 0) { + return $input_club->getSubscriptionStatus($input_user) ? 1 : 0; } else { return (object) [ - "member" => $club->getSubscriptionStatus($usver) ? 1 : 0, + "member" => $input_club->getSubscriptionStatus($input_user) ? 1 : 0, "request" => 0, "invitation" => 0, "can_invite" => 0, @@ -665,11 +475,4 @@ final class Groups extends VKAPIRequestHandler ]; } } - - public function remove(int $group_id, int $user_id) - { - $this->requireUser(); - - $this->fail(501, "Not implemented"); - } } diff --git a/VKAPI/Handlers/Likes.php b/VKAPI/Handlers/Likes.php index 28a66911..02b880b4 100644 --- a/VKAPI/Handlers/Likes.php +++ b/VKAPI/Handlers/Likes.php @@ -118,7 +118,14 @@ final class Likes extends VKAPIRequestHandler } if (!$user->canBeViewedBy($this->getUser())) { - $this->fail(1984, "Access denied: you can't see this user"); + $this->fail(15, "Access denied"); + } + + if ($user->isPrivateLikes()) { + return (object) [ + "liked" => 1, + "copied" => 1, + ]; } $postable = null; diff --git a/VKAPI/Handlers/Notes.php b/VKAPI/Handlers/Notes.php index bde9df75..9e07454e 100644 --- a/VKAPI/Handlers/Notes.php +++ b/VKAPI/Handlers/Notes.php @@ -13,38 +13,49 @@ use openvk\Web\Models\Entities\{Note, Comment}; final class Notes extends VKAPIRequestHandler { - public function add(string $title, string $text, int $privacy = 0, int $comment_privacy = 0, string $privacy_view = "", string $privacy_comment = "") + public function add(string $title, string $text) { $this->requireUser(); $this->willExecuteWriteAction(); + if (empty($title)) { + $this->fail(100, "Required parameter 'title' missing."); + } + $note = new Note(); + $note->setOwner($this->getUser()->getId()); $note->setCreated(time()); $note->setName($title); $note->setSource($text); $note->setEdited(time()); + $note->save(); return $note->getVirtualId(); } - public function createComment(string $note_id, int $owner_id, string $message, int $reply_to = 0, string $attachments = "") + public function createComment(int $note_id, int $owner_id, string $message, string $attachments = "") { $this->requireUser(); $this->willExecuteWriteAction(); - $note = (new NotesRepo())->getNoteById((int) $owner_id, (int) $note_id); + + if (empty($message)) { + $this->fail(100, "Required parameter 'message' missing."); + } + + $note = (new NotesRepo())->getNoteById($owner_id, $note_id); if (!$note) { - $this->fail(180, "Note not found"); + $this->fail(15, "Access denied"); } if ($note->isDeleted()) { - $this->fail(189, "Note is deleted"); + $this->fail(15, "Access denied"); } if ($note->getOwner()->isDeleted()) { - $this->fail(403, "Owner is deleted"); + $this->fail(15, "Access denied"); } if (!$note->canBeViewedBy($this->getUser())) { @@ -52,11 +63,7 @@ final class Notes extends VKAPIRequestHandler } if (!$note->getOwner()->getPrivacyPermission('notes.read', $this->getUser())) { - $this->fail(43, "No access"); - } - - if (empty($message) && empty($attachments)) { - $this->fail(100, "Required parameter 'message' missing."); + $this->fail(15, "Access denied"); } $comment = new Comment(); @@ -67,78 +74,9 @@ final class Notes extends VKAPIRequestHandler $comment->setCreated(time()); $comment->save(); - if (!empty($attachments)) { - $attachmentsArr = explode(",", $attachments); - - if (sizeof($attachmentsArr) > 10) { - $this->fail(50, "Error: too many attachments"); - } - - foreach ($attachmentsArr as $attac) { - $attachmentType = null; - - if (str_contains($attac, "photo")) { - $attachmentType = "photo"; - } elseif (str_contains($attac, "video")) { - $attachmentType = "video"; - } else { - $this->fail(205, "Unknown attachment type"); - } - - $attachment = str_replace($attachmentType, "", $attac); - - $attachmentOwner = (int) explode("_", $attachment)[0]; - $attachmentId = (int) end(explode("_", $attachment)); - - $attacc = null; - - if ($attachmentType == "photo") { - $attacc = (new PhotosRepo())->getByOwnerAndVID($attachmentOwner, $attachmentId); - if (!$attacc || $attacc->isDeleted()) { - $this->fail(100, "Photo does not exists"); - } - if ($attacc->getOwner()->getId() != $this->getUser()->getId()) { - $this->fail(43, "You do not have access to this photo"); - } - - $comment->attach($attacc); - } elseif ($attachmentType == "video") { - $attacc = (new VideosRepo())->getByOwnerAndVID($attachmentOwner, $attachmentId); - if (!$attacc || $attacc->isDeleted()) { - $this->fail(100, "Video does not exists"); - } - if ($attacc->getOwner()->getId() != $this->getUser()->getId()) { - $this->fail(43, "You do not have access to this video"); - } - - $comment->attach($attacc); - } - } - } - return $comment->getId(); } - public function delete(string $note_id) - { - $this->requireUser(); - $this->willExecuteWriteAction(); - - $note = (new NotesRepo())->get((int) $note_id); - - if (!$note) { - $this->fail(180, "Note not found"); - } - - if (!$note->canBeModifiedBy($this->getUser())) { - $this->fail(15, "Access to note denied"); - } - - $note->delete(); - - return 1; - } - public function edit(string $note_id, string $title = "", string $text = "", int $privacy = 0, int $comment_privacy = 0, string $privacy_view = "", string $privacy_comment = "") { $this->requireUser(); @@ -147,15 +85,15 @@ final class Notes extends VKAPIRequestHandler $note = (new NotesRepo())->getNoteById($this->getUser()->getId(), (int) $note_id); if (!$note) { - $this->fail(180, "Note not found"); + $this->fail(15, "Access denied"); } if ($note->isDeleted()) { - $this->fail(189, "Note is deleted"); + $this->fail(15, "Access denied"); } if (!$note->canBeModifiedBy($this->getUser())) { - $this->fail(403, "No access"); + $this->fail(15, "Access denied"); } !empty($title) ? $note->setName($title) : null; @@ -171,26 +109,28 @@ final class Notes extends VKAPIRequestHandler public function get(int $user_id, string $note_ids = "", int $offset = 0, int $count = 10, int $sort = 0) { $this->requireUser(); + $user = (new UsersRepo())->get($user_id); if (!$user || $user->isDeleted()) { - $this->fail(15, "Invalid user"); + $this->fail(15, "Access denied"); } if (!$user->getPrivacyPermission('notes.read', $this->getUser())) { - $this->fail(15, "Access denied: this user chose to hide his notes"); + $this->fail(15, "Access denied"); } if (!$user->canBeViewedBy($this->getUser())) { $this->fail(15, "Access denied"); } - $nodez = (object) [ + $notes_return_object = (object) [ "count" => 0, - "notes" => [], + "items" => [], ]; + if (empty($note_ids)) { - $nodez->count = (new NotesRepo())->getUserNotesCount($user); + $notes_return_object->count = (new NotesRepo())->getUserNotesCount($user); $notes = array_slice(iterator_to_array((new NotesRepo())->getUserNotes($user, 1, $count + $offset, $sort == 0 ? "ASC" : "DESC")), $offset); @@ -199,25 +139,21 @@ final class Notes extends VKAPIRequestHandler continue; } - $nodez->notes[] = $note->toVkApiStruct(); + $notes_return_object->items[] = $note->toVkApiStruct(); } } else { - $notes = explode(',', $note_ids); + $notes_splitted = explode(',', $note_ids); - foreach ($notes as $note) { - $id = explode("_", $note); + foreach ($notes_splitted as $note_id) { + $note = (new NotesRepo())->getNoteById($user_id, $note_id); - $items = []; - - $note = (new NotesRepo())->getNoteById((int) $id[0], (int) $id[1]); if ($note && !$note->isDeleted()) { - $nodez->notes[] = $note->toVkApiStruct(); - $nodez->count++; + $notes_return_object->items[] = $note->toVkApiStruct(); } } } - return $nodez; + return $notes_return_object; } public function getById(int $note_id, int $owner_id, bool $need_wiki = false) @@ -227,23 +163,23 @@ final class Notes extends VKAPIRequestHandler $note = (new NotesRepo())->getNoteById($owner_id, $note_id); if (!$note) { - $this->fail(180, "Note not found"); + $this->fail(15, "Access denied"); } if ($note->isDeleted()) { - $this->fail(189, "Note is deleted"); + $this->fail(15, "Access denied"); } if (!$note->getOwner() || $note->getOwner()->isDeleted()) { - $this->fail(177, "Owner does not exists"); + $this->fail(15, "Access denied"); } if (!$note->getOwner()->getPrivacyPermission('notes.read', $this->getUser())) { - $this->fail(40, "Access denied: this user chose to hide his notes"); + $this->fail(15, "Access denied"); } if (!$note->canBeViewedBy($this->getUser())) { - $this->fail(15, "Access to note denied"); + $this->fail(15, "Access denied"); } return $note->toVkApiStruct(); @@ -256,23 +192,23 @@ final class Notes extends VKAPIRequestHandler $note = (new NotesRepo())->getNoteById($owner_id, $note_id); if (!$note) { - $this->fail(180, "Note not found"); + $this->fail(15, "Access denied"); } if ($note->isDeleted()) { - $this->fail(189, "Note is deleted"); + $this->fail(15, "Access denied"); } if (!$note->getOwner()) { - $this->fail(177, "Owner does not exists"); + $this->fail(15, "Access denied"); } if (!$note->getOwner()->getPrivacyPermission('notes.read', $this->getUser())) { - $this->fail(14, "No access"); + $this->fail(15, "Access denied"); } if (!$note->canBeViewedBy($this->getUser())) { - $this->fail(15, "Access to note denied"); + $this->fail(15, "Access denied"); } $arr = (object) [ @@ -286,14 +222,4 @@ final class Notes extends VKAPIRequestHandler return $arr; } - - public function getFriendsNotes(int $offset = 0, int $count = 0) - { - $this->fail(501, "Not implemented"); - } - - public function restoreComment(int $comment_id = 0, int $owner_id = 0) - { - $this->fail(501, "Not implemented"); - } } diff --git a/VKAPI/Handlers/Polls.php b/VKAPI/Handlers/Polls.php index 8c1842c9..53e3e8da 100755 --- a/VKAPI/Handlers/Polls.php +++ b/VKAPI/Handlers/Polls.php @@ -120,11 +120,11 @@ final class Polls extends VKAPIRequestHandler $poll = (new PollsRepo())->get($poll_id); if (!$poll) { - $this->fail(251, "Invalid poll"); + $this->fail(15, "Access denied"); } if ($poll->isAnonymous()) { - $this->fail(251, "Access denied: poll is anonymous."); + $this->fail(15, "Access denied"); } $voters = array_slice($poll->getVoters($answer_ids, 1, $offset + $count), $offset); @@ -175,10 +175,4 @@ final class Polls extends VKAPIRequestHandler return $this->getById($poll->getId()); } - - public function edit() - { - #todo - return 1; - } } diff --git a/VKAPI/Handlers/Video.php b/VKAPI/Handlers/Video.php index f8cecf05..43d7a468 100755 --- a/VKAPI/Handlers/Video.php +++ b/VKAPI/Handlers/Video.php @@ -20,12 +20,18 @@ final class Video extends VKAPIRequestHandler $this->requireUser(); if (!empty($videos)) { - $vids = explode(',', $videos); + $vids = array_unique(explode(',', $videos)); + + if (sizeof($vids) > 100) { + $this->fail(15, "Too many ids given"); + } + $profiles = []; $groups = []; + $items = []; + foreach ($vids as $vid) { $id = explode("_", $vid); - $items = []; $video = (new VideosRepo())->getByOwnerAndVID(intval($id[0]), intval($id[1])); if ($video && !$video->isDeleted()) { diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index 798aa5a3..9113eb6e 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -1104,13 +1104,18 @@ final class Wall extends VKAPIRequestHandler $post = (new PostsRepo())->getPostById($owner_id, $post_id, true); if (!$post || $post->isDeleted()) { - $this->fail(583, "Invalid post"); + $this->fail(15, "Not found"); } $wallOwner = $post->getWallOwner(); + # trying to solve the condition below. + # $post->getTargetWall() < 0 - if post on wall of club + # !$post->getWallOwner()->canBeModifiedBy($this->getUser()) - group is cannot be modifiet by %user% + # $post->getWallOwner()->getWallType() != 1 - wall is not open + # $post->getSuggestionType() == 0 - post is not suggested if ($post->getTargetWall() < 0 && !$post->getWallOwner()->canBeModifiedBy($this->getUser()) && $post->getWallOwner()->getWallType() != 1 && $post->getSuggestionType() == 0) { - $this->fail(12, "Access denied: you can't delete your accepted post."); + $this->fail(15, "Access denied"); } if ($post->getOwnerPost() == $this->getUser()->getId() || $post->getTargetWall() == $this->getUser()->getId() || $owner_id < 0 && $wallOwner->canBeModifiedBy($this->getUser())) { diff --git a/Web/Models/Entities/Club.php b/Web/Models/Entities/Club.php index 892a1647..6c8a0372 100644 --- a/Web/Models/Entities/Club.php +++ b/Web/Models/Entities/Club.php @@ -429,6 +429,11 @@ class Club extends RowModel $this->save(); } + public function delete(bool $softly = true): void + { + $this->ban(""); + } + public function unban(): void { $this->setBlock_Reason(null); diff --git a/Web/Models/Entities/MediaCollection.php b/Web/Models/Entities/MediaCollection.php index f3f340b4..91c9a247 100644 --- a/Web/Models/Entities/MediaCollection.php +++ b/Web/Models/Entities/MediaCollection.php @@ -60,6 +60,11 @@ abstract class MediaCollection extends RowModel } } + public function getOwnerId(): int + { + return (int) $this->getRecord()->owner; + } + public function getPrettyId(): string { return $this->getRecord()->owner . "_" . $this->getRecord()->id; diff --git a/Web/Models/Entities/Note.php b/Web/Models/Entities/Note.php index 17898a10..a44c421b 100644 --- a/Web/Models/Entities/Note.php +++ b/Web/Models/Entities/Note.php @@ -138,18 +138,13 @@ class Note extends Postable { $res = (object) []; - $res->type = "note"; $res->id = $this->getVirtualId(); $res->owner_id = $this->getOwner()->getId(); $res->title = $this->getName(); $res->text = $this->getText(); $res->date = $this->getPublicationTime()->timestamp(); $res->comments = $this->getCommentsCount(); - $res->read_comments = $this->getCommentsCount(); $res->view_url = "/note" . $this->getOwner()->getId() . "_" . $this->getVirtualId(); - $res->privacy_view = 1; - $res->can_comment = 1; - $res->text_wiki = "r"; return $res; } diff --git a/Web/Models/Entities/Photo.php b/Web/Models/Entities/Photo.php index 57ab2b8a..b0ee2e83 100644 --- a/Web/Models/Entities/Photo.php +++ b/Web/Models/Entities/Photo.php @@ -336,7 +336,12 @@ class Photo extends Media public function getAlbum(): ?Album { - return (new Albums())->getAlbumByPhotoId($this); + $album = (new Albums())->getAlbumByPhotoId($this); + if (!$album || $album->isDeleted()) { + return null; + } + + return $album; } public function toVkApiStruct(bool $photo_sizes = true, bool $extended = false): object diff --git a/Web/Models/Entities/Playlist.php b/Web/Models/Entities/Playlist.php index fedb2d98..4265d7e1 100644 --- a/Web/Models/Entities/Playlist.php +++ b/Web/Models/Entities/Playlist.php @@ -260,6 +260,7 @@ class Playlist extends MediaCollection $cover->setDescription("Playlist cover image"); $cover->setFile($file); $cover->setCreated(time()); + $cover->setSystem(true); $cover->save(); $this->setCover_photo_id($cover->getId()); diff --git a/Web/Models/Entities/Postable.php b/Web/Models/Entities/Postable.php index 75d774b5..b9309c45 100644 --- a/Web/Models/Entities/Postable.php +++ b/Web/Models/Entities/Postable.php @@ -75,9 +75,9 @@ abstract class Postable extends Attachable return new DateTime($edited); } - public function getComments(int $page, ?int $perPage = null): \Traversable + public function getComments(int $page, ?int $perPage = null, string $sort = "ASC"): \Traversable { - return (new Comments())->getCommentsByTarget($this, $page, $perPage); + return (new Comments())->getCommentsByTarget($this, $page, $perPage, $sort); } public function getCommentsCount(): int diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php index 8749b725..df4da4d0 100644 --- a/Web/Models/Entities/User.php +++ b/Web/Models/Entities/User.php @@ -1487,6 +1487,11 @@ class User extends RowModel return $this->isClosed(); } + public function HideGlobalFeed(): bool + { + return (bool) $this->getRecord()->hide_global_feed; + } + public function getRealId() { return $this->getId(); @@ -1497,7 +1502,7 @@ class User extends RowModel return $this->getPrivacySetting("likes.read") == User::PRIVACY_NO_ONE; } - public function toVkApiStruct(?User $user = null, string $fields = ''): object + public function toVkApiStruct(?User $relation_user = null, string $fields = ''): object { $res = (object) []; @@ -1507,8 +1512,8 @@ class User extends RowModel $res->deactivated = $this->isDeactivated(); $res->is_closed = $this->isClosed(); - if (!is_null($user)) { - $res->can_access_closed = (bool) $this->canBeViewedBy($user); + if (!is_null($relation_user)) { + $res->can_access_closed = (bool) $this->canBeViewedBy($relation_user); } if (!is_array($fields)) { @@ -1564,18 +1569,18 @@ class User extends RowModel $res->real_id = $this->getRealId(); break; case "blacklisted_by_me": - if (!$user) { + if (!$relation_user) { break; } - $res->blacklisted_by_me = (int) $this->isBlacklistedBy($user); + $res->blacklisted_by_me = (int) $this->isBlacklistedBy($relation_user); break; case "blacklisted": - if (!$user) { + if (!$relation_user) { break; } - $res->blacklisted = (int) $user->isBlacklistedBy($this); + $res->blacklisted = (int) $relation_user->isBlacklistedBy($this); break; case "games": $res->games = $this->getFavoriteGames(); diff --git a/Web/Presenters/AdminPresenter.php b/Web/Presenters/AdminPresenter.php index 8fad1052..1956b8e9 100644 --- a/Web/Presenters/AdminPresenter.php +++ b/Web/Presenters/AdminPresenter.php @@ -119,6 +119,7 @@ final class AdminPresenter extends OpenVKPresenter $user->setLast_Name($this->postParam("last_name")); $user->setPseudo($this->postParam("nickname")); $user->setStatus($this->postParam("status")); + $user->setHide_Global_Feed(empty($this->postParam("hide_global_feed") ? 0 : 1)); if (!$user->setShortCode(empty($this->postParam("shortcode")) ? null : $this->postParam("shortcode"))) { $this->flash("err", tr("error"), tr("error_shorturl_incorrect")); } diff --git a/Web/Presenters/DocumentsPresenter.php b/Web/Presenters/DocumentsPresenter.php index b003b932..dce7e4e3 100644 --- a/Web/Presenters/DocumentsPresenter.php +++ b/Web/Presenters/DocumentsPresenter.php @@ -73,10 +73,10 @@ final class DocumentsPresenter extends OpenVKPresenter $this->template->count = $docs->size(); $this->template->docs = iterator_to_array($docs->page($page, OPENVK_DEFAULT_PER_PAGE)); $this->template->locale_string = "you_have_x_documents"; - if ($owner_id < 0) { - $this->template->locale_string = "group_has_x_documents"; - } elseif ($current_tab != 0) { + if ($current_tab != 0) { $this->template->locale_string = "x_documents_in_tab"; + } elseif ($owner_id < 0) { + $this->template->locale_string = "group_has_x_documents"; } $this->template->canUpload = $owner_id == $this->user->id || $this->template->group->canBeModifiedBy($this->user->identity); diff --git a/Web/Presenters/GroupPresenter.php b/Web/Presenters/GroupPresenter.php index ba9ec1f4..a38dacaa 100644 --- a/Web/Presenters/GroupPresenter.php +++ b/Web/Presenters/GroupPresenter.php @@ -135,7 +135,7 @@ final class GroupPresenter extends OpenVKPresenter $this->template->paginatorConf = (object) [ "count" => $this->template->count, - "page" => $this->queryParam("p") ?? 1, + "page" => (int) ($this->queryParam("p") ?? 1), "amount" => 10, "perPage" => OPENVK_DEFAULT_PER_PAGE, ]; diff --git a/Web/Presenters/InternalAPIPresenter.php b/Web/Presenters/InternalAPIPresenter.php index 2e3a33ca..464059cb 100644 --- a/Web/Presenters/InternalAPIPresenter.php +++ b/Web/Presenters/InternalAPIPresenter.php @@ -13,6 +13,8 @@ final class InternalAPIPresenter extends OpenVKPresenter private function fail(int $code, string $message): void { header("HTTP/1.1 400 Bad Request"); + header("Content-Type: application/x-msgpack"); + exit(MessagePack::pack([ "brpc" => 1, "error" => [ @@ -25,6 +27,7 @@ final class InternalAPIPresenter extends OpenVKPresenter private function succ($payload): void { + header("Content-Type: application/x-msgpack"); exit(MessagePack::pack([ "brpc" => 1, "result" => $payload, @@ -146,7 +149,7 @@ final class InternalAPIPresenter extends OpenVKPresenter { if ($_SERVER["REQUEST_METHOD"] !== "POST") { header("HTTP/1.1 405 Method Not Allowed"); - exit("ты‍ не по адресу"); + $this->redirect("/"); } $type = $this->queryParam("type", false); @@ -165,7 +168,7 @@ final class InternalAPIPresenter extends OpenVKPresenter if ($type == 'post') { $this->template->_template = 'components/post.xml'; $this->template->post = $post; - $this->template->commentSection = true; + $this->template->commentSection = $this->queryParam("from_page") == "another"; } elseif ($type == 'comment') { $this->template->_template = 'components/comment.xml'; $this->template->comment = $post; diff --git a/Web/Presenters/NoSpamPresenter.php b/Web/Presenters/NoSpamPresenter.php index e6da910b..4d6a07d5 100644 --- a/Web/Presenters/NoSpamPresenter.php +++ b/Web/Presenters/NoSpamPresenter.php @@ -102,7 +102,7 @@ final class NoSpamPresenter extends OpenVKPresenter $item = new $model($item); - if (key_exists("deleted", $item->unwrap()) && $item->isDeleted()) { + if (property_exists($item->unwrap(), "deleted") && $item->isDeleted()) { $item->setDeleted(0); $item->save(); } diff --git a/Web/Presenters/PhotosPresenter.php b/Web/Presenters/PhotosPresenter.php index 6c294fdd..fc37f448 100644 --- a/Web/Presenters/PhotosPresenter.php +++ b/Web/Presenters/PhotosPresenter.php @@ -272,21 +272,27 @@ final class PhotosPresenter extends OpenVKPresenter $this->assertUserLoggedIn(); $this->willExecuteWriteAction(true); + $upload_context = $this->queryParam("upload_context"); + if (is_null($this->queryParam("album"))) { - $album = $this->albums->getUserWallAlbum($this->user->identity); + if ((int) $upload_context == $this->user->id) { + $album = $this->albums->getUserWallAlbum($this->user->identity); + } } else { [$owner, $id] = explode("_", $this->queryParam("album")); $album = $this->albums->get((int) $id); } - if (!$album) { - $this->flashFail("err", tr("error"), tr("error_adding_to_deleted"), 500, true); + if ($_SERVER["REQUEST_METHOD"] == "GET" || $this->queryParam("act") == "finish") { + if (!$album || $album->isCreatedBySystem()) { + $this->flashFail("err", tr("error"), tr("error_adding_to_deleted")); + } } - # Для быстрой загрузки фоток из пикера фотографий нужен альбом, но юзер не может загружать фото - # в системные альбомы, так что так. - if (is_null($this->user) || !is_null($this->queryParam("album")) && !$album->canBeModifiedBy($this->user->identity)) { - $this->flashFail("err", tr("error_access_denied_short"), tr("error_access_denied"), 500, true); + if ($album && !$album->canBeModifiedBy($this->user->identity)) { + if ($album->getOwnerId() != $this->user->id) { + $this->flashFail("err", tr("error_access_denied_short"), tr("error_access_denied")); + } } if ($_SERVER["REQUEST_METHOD"] === "POST") { @@ -306,8 +312,6 @@ final class PhotosPresenter extends OpenVKPresenter $phot->setDescription($description); $phot->save(); - - $album = $phot->getAlbum(); } $this->returnJson(["success" => true, @@ -346,9 +350,11 @@ final class PhotosPresenter extends OpenVKPresenter $this->flashFail("err", "Неизвестная ошибка", "Не удалось сохранить фотографию в $name.", 500, true); } - $album->addPhoto($photo); - $album->setEdited(time()); - $album->save(); + if ($album != null) { + $album->addPhoto($photo); + $album->setEdited(time()); + $album->save(); + } } $this->returnJson(["success" => true, diff --git a/Web/Presenters/VideosPresenter.php b/Web/Presenters/VideosPresenter.php index e2e1a6f4..84878540 100644 --- a/Web/Presenters/VideosPresenter.php +++ b/Web/Presenters/VideosPresenter.php @@ -133,6 +133,7 @@ final class VideosPresenter extends OpenVKPresenter 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->setUnlisted(false); $video->save(); $this->flash("succ", tr("changes_saved"), tr("changes_saved_video_comment")); diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index f4a8e898..dbdfdde0 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -210,7 +210,7 @@ final class WallPresenter extends OpenVKPresenter $pPage = min((int) ($_GET["posts"] ?? OPENVK_DEFAULT_PER_PAGE), 50); $queryBase = "FROM `posts` LEFT JOIN `groups` ON GREATEST(`posts`.`wall`, 0) = 0 AND `groups`.`id` = ABS(`posts`.`wall`) LEFT JOIN `profiles` ON LEAST(`posts`.`wall`, 0) = 0 AND `profiles`.`id` = ABS(`posts`.`wall`)"; - $queryBase .= "WHERE (`groups`.`hide_from_global_feed` = 0 OR `groups`.`name` IS NULL) AND (`profiles`.`profile_type` = 0 OR `profiles`.`first_name` IS NULL) AND `posts`.`deleted` = 0 AND `posts`.`suggested` = 0"; + $queryBase .= "WHERE (`groups`.`hide_from_global_feed` = 0 OR `groups`.`name` IS NULL) AND ((`profiles`.`profile_type` = 0 AND `profiles`.`hide_global_feed` = 0) OR `profiles`.`first_name` IS NULL) AND `posts`.`deleted` = 0 AND `posts`.`suggested` = 0"; if ($this->user->identity->getNsfwTolerance() === User::NSFW_INTOLERANT) { $queryBase .= " AND `nsfw` = 0"; @@ -469,7 +469,11 @@ final class WallPresenter extends OpenVKPresenter } $this->template->cCount = $post->getCommentsCount(); $this->template->cPage = (int) ($_GET["p"] ?? 1); - $this->template->comments = iterator_to_array($post->getComments($this->template->cPage)); + $this->template->sort = $this->queryParam("sort") ?? "asc"; + + $input_sort = $this->template->sort == "asc" ? "ASC" : "DESC"; + + $this->template->comments = iterator_to_array($post->getComments($this->template->cPage, null, $input_sort)); } public function renderLike(int $wall, int $post_id): void diff --git a/Web/Presenters/templates/@layout.xml b/Web/Presenters/templates/@layout.xml index 9e6475fe..f670dedb 100644 --- a/Web/Presenters/templates/@layout.xml +++ b/Web/Presenters/templates/@layout.xml @@ -210,7 +210,7 @@ {var $menuLinksAvaiable = sizeof(OPENVK_ROOT_CONF['openvk']['preferences']['menu']['links']) > 0 && $thisUser->getLeftMenuItemStatus('links')} {_admin} - {_helpdesk} + {_helpdesk} {if $helpdeskTicketNotAnsweredCount > 0} ({$helpdeskTicketNotAnsweredCount}) {/if} diff --git a/Web/Presenters/templates/Admin/User.xml b/Web/Presenters/templates/Admin/User.xml index 93cc0ad1..063a4c67 100644 --- a/Web/Presenters/templates/Admin/User.xml +++ b/Web/Presenters/templates/Admin/User.xml @@ -60,6 +60,10 @@ isVerified()} checked {/if} /> +
+ + +
- - - -
-
-
- -
- - {$tab["name"]} - {$tab["count"]} - +
-
+
{tr($locale_string, $count)}.
-

{_something} {_supports_xhtml}

+

{_something_is_supported_from_xhtml|noescape}

diff --git a/Web/Presenters/templates/Notes/Edit.xml b/Web/Presenters/templates/Notes/Edit.xml index b904c72e..ad8b9c80 100644 --- a/Web/Presenters/templates/Notes/Edit.xml +++ b/Web/Presenters/templates/Notes/Edit.xml @@ -18,7 +18,7 @@
-

{_something} {_supports_xhtml}

+

{_something_is_supported_from_xhtml|noescape}

diff --git a/Web/Presenters/templates/Photos/AlbumList.xml b/Web/Presenters/templates/Photos/AlbumList.xml index ad025ae3..c5c92290 100644 --- a/Web/Presenters/templates/Photos/AlbumList.xml +++ b/Web/Presenters/templates/Photos/AlbumList.xml @@ -5,7 +5,7 @@ {block title}{_albums} {$owner->getCanonicalName()}{/block} {block header} - {if isset($thisUser) && $thisUser->getId() == $owner->getId()} + {if isset($thisUser) && $thisUser->getId() == $owner->getRealId()} {_my_photos} {else} @@ -18,7 +18,7 @@ {block size}
- {if !is_null($thisUser) && $owner->getId() === $thisUser->getId()} + {if !is_null($thisUser) && $owner->getRealId() === $thisUser->getId()} {tr("albums_list", $count)} {else} {tr("albums", $count)} diff --git a/Web/Presenters/templates/Support/List.xml b/Web/Presenters/templates/Support/List.xml index a1898eed..254efc24 100644 --- a/Web/Presenters/templates/Support/List.xml +++ b/Web/Presenters/templates/Support/List.xml @@ -42,6 +42,6 @@ {block description} {var $author = $x->getUser()} - {ovk_proc_strtr($x->getContext(), 50)}
+ {ovk_proc_strtr($x->getContext(), 200)}
{_author}:
{$author->getCanonicalName()} {/block} diff --git a/Web/Presenters/templates/Topics/Create.xml b/Web/Presenters/templates/Topics/Create.xml index 659a50d4..0f95ecf9 100644 --- a/Web/Presenters/templates/Topics/Create.xml +++ b/Web/Presenters/templates/Topics/Create.xml @@ -76,14 +76,4 @@ - - {/block} diff --git a/Web/Presenters/templates/Topics/Edit.xml b/Web/Presenters/templates/Topics/Edit.xml index 0f3a7a5d..49a6156b 100644 --- a/Web/Presenters/templates/Topics/Edit.xml +++ b/Web/Presenters/templates/Topics/Edit.xml @@ -33,14 +33,14 @@ {if $topic->getClub()->canBeModifiedBy($thisUser)} - {_pin_topic}
+
{/if} - {_close_topic} + - {_delete_topic} + {_delete_topic} diff --git a/Web/Presenters/templates/User/Settings.xml b/Web/Presenters/templates/User/Settings.xml index 10e0cd1e..5e60b41f 100644 --- a/Web/Presenters/templates/User/Settings.xml +++ b/Web/Presenters/templates/User/Settings.xml @@ -409,7 +409,7 @@ diff --git a/Web/Presenters/templates/User/View.xml b/Web/Presenters/templates/User/View.xml index 9c013dd1..b9db5c87 100644 --- a/Web/Presenters/templates/User/View.xml +++ b/Web/Presenters/templates/User/View.xml @@ -419,7 +419,7 @@ {else}
- {$audioStatus->getName()} + {$audioStatus->getName()}
{/if} @@ -458,8 +458,8 @@ {_birth_date}: - {$user->getBirthday()->format('%e %B %Y')}, - {tr("years", $user->getAge())} + {$user->getBirthday()->format('%e %B %Y')}{if $user->onlineStatus() != 2}, + {tr("years", $user->getAge())}{/if} {$user->getBirthday()->format('%e %B')} diff --git a/Web/Presenters/templates/Wall/Post.xml b/Web/Presenters/templates/Wall/Post.xml index 3d136ebd..24a23d9a 100644 --- a/Web/Presenters/templates/Wall/Post.xml +++ b/Web/Presenters/templates/Wall/Post.xml @@ -36,9 +36,10 @@ count => $cCount, page => $cPage, model => "posts", - parent => $post } + parent => $post, + sort => $sort}
-
+

{_actions}

{if isset($thisUser)} {var $canDelete = $post->canBeDeletedBy($thisUser)} @@ -47,7 +48,7 @@ {/if} {/if} - {_delete} + {_delete} {_changes_history} - {_report} + {_report}
- {/block} diff --git a/Web/Presenters/templates/_includeCSS.xml b/Web/Presenters/templates/_includeCSS.xml index 5edd88ae..2553c981 100644 --- a/Web/Presenters/templates/_includeCSS.xml +++ b/Web/Presenters/templates/_includeCSS.xml @@ -17,7 +17,9 @@ {/if} {/if} - + {* remove the "n:if" if you having issues with your theme *} + + {if $isXmas} diff --git a/Web/Presenters/templates/components/comment.xml b/Web/Presenters/templates/components/comment.xml index c4e0de08..37c9cba2 100644 --- a/Web/Presenters/templates/components/comment.xml +++ b/Web/Presenters/templates/components/comment.xml @@ -44,7 +44,7 @@ {if !$timeOnly} {if $comment->canBeDeletedBy($thisUser)} | - {_delete} + {_delete} {/if} {if $comment->canBeEditedBy($thisUser)} | diff --git a/Web/Presenters/templates/components/comments.xml b/Web/Presenters/templates/components/comments.xml index 53253b5f..4e78ebe7 100644 --- a/Web/Presenters/templates/components/comments.xml +++ b/Web/Presenters/templates/components/comments.xml @@ -1,5 +1,18 @@ -

{_comments} ({$count})

+
+

{_comments} ({$count})

+ {if !is_null($sort) && $count > 5} + + {if $sort == 'desc'} + {_new_first} + {else} + {_old_first} + {/if} + +
+
+ {/if} +
{var $commentsURL = "/al_comments/create/$model/" . $parent->getId()} {var $club = $parent instanceof \openvk\Web\Models\Entities\Post && $parent->getTargetWall() < 0 ? (new openvk\Web\Models\Repositories\Clubs)->get(abs($parent->getTargetWall())) : $club} @@ -11,7 +24,7 @@ {if sizeof($comments) > 0}
- {include "comment.xml", comment => $comment} + {include "comment.xml", comment => $comment, no_reply_button => $readOnly}
diff --git a/Web/Presenters/templates/components/post/microblogpost.xml b/Web/Presenters/templates/components/post/microblogpost.xml index b39b8239..a0bfeff9 100644 --- a/Web/Presenters/templates/components/post/microblogpost.xml +++ b/Web/Presenters/templates/components/post/microblogpost.xml @@ -58,6 +58,7 @@ {_pinned} + {if $canBePinned && !($forceNoPinLink ?? false) && $compact == false} {if $post->isPinned()} @@ -148,7 +149,7 @@ {/if}
- {_view_other_comments} + {_view_other_comments} ({$commentsCount - 3}) {foreach $comments as $comment} {include "../comment.xml", comment => $comment, $compact => true} {/foreach} diff --git a/Web/Presenters/templates/components/post/oldpost.xml b/Web/Presenters/templates/components/post/oldpost.xml index 3612aa1d..bece0c51 100644 --- a/Web/Presenters/templates/components/post/oldpost.xml +++ b/Web/Presenters/templates/components/post/oldpost.xml @@ -133,8 +133,16 @@ {if !($forceNoDeleteLink ?? false) && $canBeDeleted} {_delete}  |  + {/if} + + {if $feedIgnoreButton && !$canBeDeleted} + {_feed_ignore}  |  {/if} - + + {if !$canBeDeleted} + {_report}  |  + {/if} + {if !($forceNoPinLink ?? false) && $canBePinned} {if $post->isPinned()} {_unpin} diff --git a/Web/Presenters/templates/components/textArea.xml b/Web/Presenters/templates/components/textArea.xml index f1e3d475..2be32280 100644 --- a/Web/Presenters/templates/components/textArea.xml +++ b/Web/Presenters/templates/components/textArea.xml @@ -2,7 +2,7 @@ {var $textAreaId = ($post ?? NULL) === NULL ? (++$GLOBALS["textAreaCtr"]) : $post->getId()} {var $textAreaId = ($custom_id ?? NULL) === NULL ? $textAreaId : $custom_id} -
+
@@ -33,15 +33,15 @@ -