diff --git a/VKAPI/Handlers/Account.php b/VKAPI/Handlers/Account.php index d1722b29..d2e619df 100644 --- a/VKAPI/Handlers/Account.php +++ b/VKAPI/Handlers/Account.php @@ -8,16 +8,16 @@ final class Account extends VKAPIRequestHandler $this->requireUser(); return (object) [ - "first_name" => $this->getUser()->getFirstName(), - "id" => $this->getUser()->getId(), - "last_name" => $this->getUser()->getLastName(), - "home_town" => $this->getUser()->getHometown(), - "status" => $this->getUser()->getStatus(), - "bdate" => "1.1.1970", # TODO + "first_name" => $this->getUser()->getFirstName(), + "id" => $this->getUser()->getId(), + "last_name" => $this->getUser()->getLastName(), + "home_town" => $this->getUser()->getHometown(), + "status" => $this->getUser()->getStatus(), + "bdate" => "1.1.1970", # TODO "bdate_visibility" => 0, # TODO - "phone" => "+420 ** *** 228", # TODO - "relation" => $this->getUser()->getMaritalStatus(), - "sex" => $this->getUser()->isFemale() ? 1 : 2 + "phone" => "+420 ** *** 228", # TODO + "relation" => $this->getUser()->getMaritalStatus(), + "sex" => $this->getUser()->isFemale() ? 1 : 2 ]; } @@ -28,17 +28,17 @@ final class Account extends VKAPIRequestHandler # Цiй метод є заглушка return (object) [ - "2fa_required" => 0, - "country" => "CZ", # TODO - "eu_user" => false, # TODO - "https_required" => 1, - "intro" => 0, - "community_comments" => false, - "is_live_streaming_enabled" => false, + "2fa_required" => 0, + "country" => "CZ", # TODO + "eu_user" => false, # TODO + "https_required" => 1, + "intro" => 0, + "community_comments" => false, + "is_live_streaming_enabled" => false, "is_new_live_streaming_enabled" => false, - "lang" => 1, - "no_wall_replies" => 0, - "own_posts_default" => 0 + "lang" => 1, + "no_wall_replies" => 0, + "own_posts_default" => 0 ]; } @@ -68,9 +68,9 @@ final class Account extends VKAPIRequestHandler function getCounters(string $filter = ""): object { return (object) [ - "friends" => $this->getUser()->getFollowersCount(), + "friends" => $this->getUser()->getFollowersCount(), "notifications" => $this->getUser()->getNotificationsCount(), - "messages" => $this->getUser()->getUnreadMessagesCount() + "messages" => $this->getUser()->getUnreadMessagesCount() ]; # TODO: Filter diff --git a/VKAPI/Handlers/Audio.php b/VKAPI/Handlers/Audio.php index 9fc4a535..3fa68e72 100644 --- a/VKAPI/Handlers/Audio.php +++ b/VKAPI/Handlers/Audio.php @@ -10,12 +10,12 @@ final class Audio extends VKAPIRequestHandler return (object) [ "count" => 1, "items" => [(object) [ - "id" => 1, + "id" => 1, "owner_id" => 1, - "artist" => "В ОВК ПОКА НЕТ МУЗЫКИ", - "title" => "ЖДИТЕ :)))", + "artist" => "В ОВК ПОКА НЕТ МУЗЫКИ", + "title" => "ЖДИТЕ :)))", "duration" => 22, - "url" => $serverUrl . "/assets/packages/static/openvk/audio/nomusic.mp3" + "url" => $serverUrl . "/assets/packages/static/openvk/audio/nomusic.mp3" ]] ]; } diff --git a/VKAPI/Handlers/Friends.php b/VKAPI/Handlers/Friends.php index 760cef21..3332df44 100644 --- a/VKAPI/Handlers/Friends.php +++ b/VKAPI/Handlers/Friends.php @@ -1,6 +1,5 @@ requireUser(); - foreach ($users->get($user_id)->getFriends($offset, $count) as $friend) { + foreach($users->get($user_id)->getFriends($offset, $count) as $friend) { $friends[$i] = $friend->getId(); $i++; } @@ -24,7 +23,7 @@ final class Friends extends VKAPIRequestHandler $usersApi = new Users($this->getUser()); - if (!is_null($fields)) { + if(!is_null($fields)) { $response = $usersApi->get(implode(',', $friends), $fields, 0, $count); # FIXME } @@ -70,33 +69,28 @@ final class Friends extends VKAPIRequestHandler $this->requireUser(); $users = new UsersRepo; - - $user = $users->get(intval($user_id)); + $user = $users->get(intval($user_id)); - if(is_null($user)){ + if(is_null($user)) { $this->fail(177, "Cannot add this user to friends as user not found"); } else if($user->getId() == $this->getUser()->getId()) { $this->fail(174, "Cannot add user himself as friend"); } - switch ($user->getSubscriptionStatus($this->getUser())) { + switch($user->getSubscriptionStatus($this->getUser())) { case 0: $user->toggleSubscription($this->getUser()); return 1; - break; case 1: $user->toggleSubscription($this->getUser()); return 2; - break; case 3: return 2; - break; default: return 1; - break; } } @@ -108,15 +102,13 @@ final class Friends extends VKAPIRequestHandler $user = $users->get(intval($user_id)); - switch ($user->getSubscriptionStatus($this->getUser())) { + switch($user->getSubscriptionStatus($this->getUser())) { case 3: $user->toggleSubscription($this->getUser()); return 1; - break; default: fail(15, "Access denied: No friend or friend request found."); - break; } } @@ -130,28 +122,12 @@ final class Friends extends VKAPIRequestHandler $response = []; - for ($i=0; $i < sizeof($friends); $i++) { + for($i=0; $i < sizeof($friends); $i++) { $friend = $users->get(intval($friends[$i])); - $status = 0; - switch ($friend->getSubscriptionStatus($this->getUser())) { - case 3: - case 0: - $status = $friend->getSubscriptionStatus($this->getUser()); - break; - - case 1: - $status = 2; - break; - - case 2: - $status = 1; - break; - } - $response[] = (object)[ "friend_status" => $friend->getSubscriptionStatus($this->getUser()), - "user_id" => $friend->getId() + "user_id" => $friend->getId() ]; } diff --git a/VKAPI/Handlers/Groups.php b/VKAPI/Handlers/Groups.php index ef1a64d0..108834b1 100644 --- a/VKAPI/Handlers/Groups.php +++ b/VKAPI/Handlers/Groups.php @@ -1,12 +1,7 @@ requireUser(); - if ($user_id == 0) { - foreach($this->getUser()->getClubs($offset+1) as $club) { + if($user_id == 0) { + foreach($this->getUser()->getClubs($offset+1) as $club) $clbs[] = $club; - } $clbsCount = $this->getUser()->getClubCount(); } else { $users = new UsersRepo; - $user = $users->get($user_id); - if (is_null($user)) { + $user = $users->get($user_id); + + if(is_null($user)) $this->fail(15, "Access denied"); - } - foreach($user->getClubs($offset+1) as $club) { + + foreach($user->getClubs($offset+1) as $club) $clbs[] = $club; - } + $clbsCount = $user->getClubCount(); } $rClubs; $ic = sizeof($clbs); + if(sizeof($clbs) > $count) + $ic = $count; - if(sizeof($clbs) > $count) $ic = $count; - - if (!empty($clbs)) { + if(!empty($clbs)) { $clbs = array_slice($clbs, $offset * $count); - for ($i=0; $i < $ic; $i++) { + for($i=0; $i < $ic; $i++) { $usr = $clbs[$i]; - if(is_null($usr)) - { + if(is_null($usr)) { $rClubs[$i] = (object)[ "id" => $clbs[$i], "name" => "DELETED", "deactivated" => "deleted" ]; - }else if($clbs[$i] == NULL){ + } else if($clbs[$i] == NULL) { - }else{ - $rClubs[$i] = (object)[ + } else { + $rClubs[$i] = (object) [ "id" => $usr->getId(), "name" => $usr->getName(), "screen_name" => $usr->getShortCode(), @@ -63,35 +57,35 @@ final class Groups extends VKAPIRequestHandler $flds = explode(',', $fields); foreach($flds as $field) { - switch ($field) { - case 'verified': + switch($field) { + case "verified": $rClubs[$i]->verified = intval($usr->isVerified()); break; - case 'has_photo': + case "has_photo": $rClubs[$i]->has_photo = is_null($usr->getAvatarPhoto()) ? 0 : 1; break; - case 'photo_max_orig': + case "photo_max_orig": $rClubs[$i]->photo_max_orig = $usr->getAvatarURL(); break; - case 'photo_max': + case "photo_max": $rClubs[$i]->photo_max = $usr->getAvatarURL("original"); // ORIGINAL ANDREI CHINITEL 🥵🥵🥵🥵 break; - case 'photo_50': + case "photo_50": $rClubs[$i]->photo_50 = $usr->getAvatarURL(); break; - case 'photo_100': + case "photo_100": $rClubs[$i]->photo_100 = $usr->getAvatarURL("tiny"); break; - case 'photo_200': + case "photo_200": $rClubs[$i]->photo_200 = $usr->getAvatarURL("normal"); break; - case 'photo_200_orig': + case "photo_200_orig": $rClubs[$i]->photo_200_orig = $usr->getAvatarURL("normal"); break; - case 'photo_400_orig': + case "photo_400_orig": $rClubs[$i]->photo_400_orig = $usr->getAvatarURL("normal"); break; - case 'members_count': + case "members_count": $rClubs[$i]->members_count = $usr->getFollowersCount(); break; } @@ -112,10 +106,10 @@ final class Groups extends VKAPIRequestHandler { $clubs = new ClubsRepo; - if ($group_ids == NULL && $group_id != NULL) + if($group_ids == NULL && $group_id != NULL) $group_ids = $group_id; - if ($group_ids == NULL && $group_id == NULL) + if($group_ids == NULL && $group_id == NULL) $this->fail(100, "One of the parameters specified was missing or invalid: group_ids is undefined"); $clbs = explode(',', $group_ids); @@ -123,7 +117,7 @@ final class Groups extends VKAPIRequestHandler $ic = sizeof($clbs); - for ($i=0; $i < $ic; $i++) { + for($i=0; $i < $ic; $i++) { if($i > 500) break; @@ -131,64 +125,64 @@ final class Groups extends VKAPIRequestHandler $this->fail(100, "ты ошибся чутка, у айди группы убери минус"); $clb = $clubs->get((int) $clbs[$i]); - if(is_null($clb)) - { + if(is_null($clb)) { $response[$i] = (object)[ - "id" => intval($clbs[$i]), - "name" => "DELETED", + "id" => intval($clbs[$i]), + "name" => "DELETED", "screen_name" => "club".intval($clbs[$i]), - "type" => "group", + "type" => "group", "description" => "This group was deleted or it doesn't exist" ]; - }else if($clbs[$i] == NULL){ + } else if($clbs[$i] == NULL) { - }else{ + } else { $response[$i] = (object)[ - "id" => $clb->getId(), - "name" => $clb->getName(), - "screen_name" => $clb->getShortCode() ?? "club".$clb->getId(), - "is_closed" => false, - "type" => "group", + "id" => $clb->getId(), + "name" => $clb->getName(), + "screen_name" => $clb->getShortCode() ?? "club".$clb->getId(), + "is_closed" => false, + "type" => "group", "can_access_closed" => true, ]; $flds = explode(',', $fields); foreach($flds as $field) { - switch ($field) { - case 'verified': + switch($field) { + case "verified": $response[$i]->verified = intval($clb->isVerified()); break; - case 'has_photo': + case "has_photo": $response[$i]->has_photo = is_null($clb->getAvatarPhoto()) ? 0 : 1; break; - case 'photo_max_orig': + case "photo_max_orig": $response[$i]->photo_max_orig = $clb->getAvatarURL(); break; - case 'photo_max': + case "photo_max": $response[$i]->photo_max = $clb->getAvatarURL(); break; - case 'members_count': + case "members_count": $response[$i]->members_count = $clb->getFollowersCount(); break; - case 'site': + case "site": $response[$i]->site = $clb->getWebsite(); break; - case 'description': + case "description": $response[$i]->desctiption = $clb->getDescription(); break; - case 'contacts': + case "contacts": $contacts; $contactTmp = $clb->getManagers(1, true); - foreach($contactTmp as $contact) { + + foreach($contactTmp as $contact) $contacts[] = array( - 'user_id' => $contact->getUser()->getId(), - 'desc' => $contact->getComment() + "user_id" => $contact->getUser()->getId(), + "desc" => $contact->getComment() ); - } + $response[$i]->contacts = $contacts; break; - case 'can_post': + case "can_post": if(!is_null($this->getUser())) if($clb->canBeModifiedBy($this->getUser())) $response[$i]->can_post = true; diff --git a/VKAPI/Handlers/Likes.php b/VKAPI/Handlers/Likes.php index 5283d5b9..38a76893 100644 --- a/VKAPI/Handlers/Likes.php +++ b/VKAPI/Handlers/Likes.php @@ -9,19 +9,19 @@ final class Likes extends VKAPIRequestHandler { $this->requireUser(); - switch ($type) { - case 'post': + switch($type) { + case "post": $post = (new PostsRepo)->getPostById($owner_id, $item_id); - if (is_null($post)) $this->fail(100, 'One of the parameters specified was missing or invalid: object not found'); + if(is_null($post)) + $this->fail(100, "One of the parameters specified was missing or invalid: object not found"); $post->setLike(true, $this->getUser()); - return (object)[ + + return (object) [ "likes" => $post->getLikesCount() ]; - break; default: - $this->fail(100, 'One of the parameters specified was missing or invalid: incorrect type'); - break; + $this->fail(100, "One of the parameters specified was missing or invalid: incorrect type"); } } @@ -29,19 +29,18 @@ final class Likes extends VKAPIRequestHandler { $this->requireUser(); - switch ($type) { - case 'post': + switch($type) { + case "post": $post = (new PostsRepo)->getPostById($owner_id, $item_id); - if (is_null($post)) $this->fail(100, 'One of the parameters specified was missing or invalid: object not found'); + if (is_null($post)) + $this->fail(100, "One of the parameters specified was missing or invalid: object not found"); $post->setLike(false, $this->getUser()); - return (object)[ + return (object) [ "likes" => $post->getLikesCount() ]; - break; default: - $this->fail(100, 'One of the parameters specified was missing or invalid: incorrect type'); - break; + $this->fail(100, "One of the parameters specified was missing or invalid: incorrect type"); } } @@ -49,26 +48,26 @@ final class Likes extends VKAPIRequestHandler { $this->requireUser(); - switch ($type) { - case 'post': + switch($type) { + case "post": $user = (new UsersRepo)->get($user_id); - if (is_null($user)) return (object)[ - "liked" => 0, - "copied" => 0, - "sex" => 0 - ]; + if (is_null($user)) + return (object) [ + "liked" => 0, + "copied" => 0, + "sex" => 0 + ]; $post = (new PostsRepo)->getPostById($owner_id, $item_id); - if (is_null($post)) $this->fail(100, 'One of the parameters specified was missing or invalid: object not found'); + if (is_null($post)) + $this->fail(100, "One of the parameters specified was missing or invalid: object not found"); - return (object)[ - "liked" => (int) $post->hasLikeFrom($user), + return (object) [ + "liked" => (int) $post->hasLikeFrom($user), "copied" => 0 # TODO: handle this ]; - break; default: - $this->fail(100, 'One of the parameters specified was missing or invalid: incorrect type'); - break; + $this->fail(100, "One of the parameters specified was missing or invalid: incorrect type"); } } } diff --git a/VKAPI/Handlers/Messages.php b/VKAPI/Handlers/Messages.php index b555502f..0d48dd1a 100644 --- a/VKAPI/Handlers/Messages.php +++ b/VKAPI/Handlers/Messages.php @@ -40,7 +40,7 @@ final class Messages extends VKAPIRequestHandler continue; $author = $message->getSender()->getId() === $this->getUser()->getId() ? $message->getRecipient()->getId() : $message->getSender()->getId(); - $rMsg = new APIMsg; + $rMsg = new APIMsg; $rMsg->id = $message->getId(); $rMsg->user_id = $author; @@ -123,9 +123,8 @@ final class Messages extends VKAPIRequestHandler $items = []; foreach($ids as $id) { $message = $msgs->get((int) $id); - if(!$message || $message->getSender()->getId() !== $this->getUser()->getId() && $message->getRecipient()->getId() !== $this->getUser()->getId()) { + if(!$message || $message->getSender()->getId() !== $this->getUser()->getId() && $message->getRecipient()->getId() !== $this->getUser()->getId()) $items[$id] = 0; - } $message->delete(); $items[$id] = 1; @@ -186,7 +185,7 @@ final class Messages extends VKAPIRequestHandler else $author = $lastMessage->getSender()->getId(); - $lastMessagePreview = new APIMsg; + $lastMessagePreview = new APIMsg; $lastMessagePreview->id = $lastMessage->getId(); $lastMessagePreview->user_id = $author; $lastMessagePreview->from_id = $lastMessage->getSender()->getId(); @@ -218,8 +217,8 @@ final class Messages extends VKAPIRequestHandler $users = array_unique($users); return (object) [ - "count" => sizeof($list), - "items" => $list, + "count" => sizeof($list), + "items" => $list, "profiles" => (!empty($users) ? (new APIUsers)->get(implode(',', $users), $fields, $offset, $count) : []) ]; } @@ -249,7 +248,7 @@ final class Messages extends VKAPIRequestHandler $dialogue = new Correspondence($this->getUser(), $user); $iterator = $dialogue->getMessages(Correspondence::CAP_BEHAVIOUR_START_MESSAGE_ID, 0, 1, 0, false); - $msg = $iterator[0]->unwrap(); // шоб удобнее было + $msg = $iterator[0]->unwrap(); // шоб удобнее было $output['items'][] = [ "peer" => [ "id" => $user->getId(), @@ -276,7 +275,7 @@ final class Messages extends VKAPIRequestHandler } if($extended == 1) { - $userslist = array_unique($userslist); + $userslist = array_unique($userslist); $output['profiles'] = (!empty($userslist) ? (new APIUsers)->get(implode(',', $userslist), $fields) : []); } diff --git a/VKAPI/Handlers/Newsfeed.php b/VKAPI/Handlers/Newsfeed.php index dd4fd436..71379256 100644 --- a/VKAPI/Handlers/Newsfeed.php +++ b/VKAPI/Handlers/Newsfeed.php @@ -1,8 +1,5 @@ requireUser(); - if($offset != 0) $start_from = $offset; + if($offset != 0) + $start_from = $offset; $id = $this->getUser()->getId(); $subs = DatabaseConnection::i() @@ -26,12 +24,12 @@ final class Newsfeed extends VKAPIRequestHandler $ids[] = $this->getUser()->getId(); $posts = DatabaseConnection::i() - ->getContext() - ->table("posts") - ->select("id") - ->where("wall IN (?)", $ids) - ->where("deleted", 0) - ->order("created DESC"); + ->getContext() + ->table("posts") + ->select("id") + ->where("wall IN (?)", $ids) + ->where("deleted", 0) + ->order("created DESC"); $rposts = []; foreach($posts->page((int) ($offset + 1), $count) as $post) diff --git a/VKAPI/Handlers/Ovk.php b/VKAPI/Handlers/Ovk.php index c02827be..a260f1c4 100644 --- a/VKAPI/Handlers/Ovk.php +++ b/VKAPI/Handlers/Ovk.php @@ -2,7 +2,6 @@ namespace openvk\VKAPI\Handlers; use openvk\Web\Models\Repositories\{Users as UsersRepo, Clubs as ClubsRepo, Posts as PostsRepo}; - final class Ovk extends VKAPIRequestHandler { function version(): string diff --git a/VKAPI/Handlers/Users.php b/VKAPI/Handlers/Users.php index 5e7cadec..1279fda2 100644 --- a/VKAPI/Handlers/Users.php +++ b/VKAPI/Handlers/Users.php @@ -7,92 +7,91 @@ final class Users extends VKAPIRequestHandler { function get(string $user_ids = "0", string $fields = "", int $offset = 0, int $count = 100, User $authuser = null /* костыль(( */): array { - # $this->requireUser(); - if($authuser == NULL) $authuser = $this->getUser(); $users = new UsersRepo; if($user_ids == "0") $user_ids = (string) $authuser->getId(); - $usrs = explode(',', $user_ids); + $usrs = explode(',', $user_ids);',' $response; $ic = sizeof($usrs); - if(sizeof($usrs) > $count) $ic = $count; + if(sizeof($usrs) > $count) + $ic = $count; $usrs = array_slice($usrs, $offset * $count); - for ($i=0; $i < $ic; $i++) { + for($i=0; $i < $ic; $i++) { $usr = $users->get((int) $usrs[$i]); - if(is_null($usr)) - { + if(is_null($usr)) { $response[$i] = (object)[ - "id" => $usrs[$i], - "first_name" => "DELETED", - "last_name" => "", + "id" => $usrs[$i], + "first_name" => "DELETED", + "last_name" => "", "deactivated" => "deleted" ]; - }else if($usrs[$i] == NULL){ + } else if($usrs[$i] == NULL) { - }else{ + } else { $response[$i] = (object)[ - "id" => $usr->getId(), - "first_name" => $usr->getFirstName(), - "last_name" => $usr->getLastName(), - "is_closed" => false, + "id" => $usr->getId(), + "first_name" => $usr->getFirstName(), + "last_name" => $usr->getLastName(), + "is_closed" => false, "can_access_closed" => true, ]; $flds = explode(',', $fields); foreach($flds as $field) { - switch ($field) { - case 'verified': + switch($field) { + case "verified": $response[$i]->verified = intval($usr->isVerified()); break; - case 'sex': + case "sex": $response[$i]->sex = $usr->isFemale() ? 1 : 2; break; - case 'has_photo': + case "has_photo": $response[$i]->has_photo = is_null($usr->getAvatarPhoto()) ? 0 : 1; break; - case 'photo_max_orig': + case "photo_max_orig": $response[$i]->photo_max_orig = $usr->getAvatarURL(); break; - case 'photo_max': + case "photo_max": $response[$i]->photo_max = $usr->getAvatarURL("original"); break; - case 'photo_50': + case "photo_50": $response[$i]->photo_50 = $usr->getAvatarURL(); break; - case 'photo_100': + case "photo_100": $response[$i]->photo_100 = $usr->getAvatarURL("tiny"); break; - case 'photo_200': + case "photo_200": $response[$i]->photo_200 = $usr->getAvatarURL("normal"); break; - case 'photo_200_orig': # вообще не ебу к чему эта строка ну пусть будет кек + case "photo_200_orig": # вообще не ебу к чему эта строка ну пусть будет кек $response[$i]->photo_200_orig = $usr->getAvatarURL("normal"); break; - case 'photo_400_orig': + case "photo_400_orig": $response[$i]->photo_400_orig = $usr->getAvatarURL("normal"); break; # Она хочет быть выебанной видя матан # Покайфу когда ты Виет а вокруг лишь дискриминант - case 'status': + case "status": if($usr->getStatus() != NULL) $response[$i]->status = $usr->getStatus(); break; - case 'screen_name': + case "screen_name": if($usr->getShortCode() != NULL) $response[$i]->screen_name = $usr->getShortCode(); break; - case 'friend_status': + case "friend_status": switch($usr->getSubscriptionStatus($authuser)) { case 3: + # NOTICE falling through case 0: $response[$i]->friend_status = $usr->getSubscriptionStatus($authuser); break; @@ -104,50 +103,43 @@ final class Users extends VKAPIRequestHandler break; } break; - case 'last_seen': - if ($usr->onlineStatus() == 0) { + case "last_seen": + if ($usr->onlineStatus() == 0) $response[$i]->last_seen = (object) [ "platform" => 1, - "time" => $usr->getOnline()->timestamp() + "time" => $usr->getOnline()->timestamp() ]; - } - case 'music': + case "music": $response[$i]->music = $usr->getFavoriteMusic(); break; - case 'movies': + case "movies": $response[$i]->movies = $usr->getFavoriteFilms(); break; - case 'tv': + case "tv": $response[$i]->tv = $usr->getFavoriteShows(); break; - case 'books': + case "books": $response[$i]->books = $usr->getFavoriteBooks(); break; - case 'city': + case "city": $response[$i]->city = $usr->getCity(); break; - case 'interests': + case "interests": $response[$i]->interests = $usr->getInterests(); break; } } - if($usr->getOnline()->timestamp() + 300 > time()) { + if($usr->getOnline()->timestamp() + 300 > time()) $response[$i]->online = 1; - }else{ + else $response[$i]->online = 0; - } - } } return $response; } - /* private function getUsersById(string $user_ids, string $fields = "", int $offset = 0, int $count = PHP_INT_MAX){ - - } */ - function getFollowers(int $user_id, string $fields = "", int $offset = 0, int $count = 100): object { $offset++; @@ -157,15 +149,13 @@ final class Users extends VKAPIRequestHandler $this->requireUser(); - foreach ($users->get($user_id)->getFollowers($offset, $count) as $follower) { + foreach($users->get($user_id)->getFollowers($offset, $count) as $follower) $followers[] = $follower->getId(); - } $response = $followers; - if (!is_null($fields)) { + if(!is_null($fields)) $response = $this->get(implode(',', $followers), $fields, 0, $count); - } return (object) [ "count" => $users->get($user_id)->getFollowersCount(), @@ -173,18 +163,17 @@ final class Users extends VKAPIRequestHandler ]; } - function search(string $q, string $fields = '', int $offset = 0, int $count = 100) + function search(string $q, string $fields = "", int $offset = 0, int $count = 100) { $users = new UsersRepo; $array = []; - $find = $users->find($q); + $find = $users->find($q); - foreach ($find as $user) { + foreach ($find as $user) $array[] = $user->getId(); - } - return (object)[ + return (object) [ "count" => $find->size(), "items" => $this->get(implode(',', $array), $fields, $offset, $count) ]; diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index 8d9f9c4a..11fb11b9 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -6,21 +6,20 @@ use openvk\Web\Models\Repositories\Users as UsersRepo; use openvk\Web\Models\Entities\Club; use openvk\Web\Models\Repositories\Clubs as ClubsRepo; use openvk\Web\Models\Entities\Post; -use openvk\Web\Models\Entities\Postable; use openvk\Web\Models\Repositories\Posts as PostsRepo; final class Wall extends VKAPIRequestHandler { function get(string $owner_id, string $domain = "", int $offset = 0, int $count = 30, int $extended = 0): object { - $posts = new PostsRepo; + $posts = new PostsRepo; - $items = []; + $items = []; $profiles = []; - $groups = []; - $count = $posts->getPostCountOnUserWall((int) $owner_id); + $groups = []; + $count = $posts->getPostCountOnUserWall((int) $owner_id); - foreach ($posts->getPostsFromUsersWall((int)$owner_id, 1, $count, $offset) as $post) { + foreach($posts->getPostsFromUsersWall((int)$owner_id, 1, $count, $offset) as $post) { $from_id = get_class($post->getOwner()) == "openvk\Web\Models\Entities\Club" ? $post->getOwner()->getId() * (-1) : $post->getOwner()->getId(); $attachments = []; @@ -45,32 +44,32 @@ final class Wall extends VKAPIRequestHandler } $items[] = (object)[ - "id" => $post->getVirtualId(), - "from_id" => $from_id, - "owner_id" => $post->getTargetWall(), - "date" => $post->getPublicationTime()->timestamp(), - "post_type" => "post", - "text" => $post->getText(false), - "can_edit" => 0, # TODO - "can_delete" => $post->canBeDeletedBy($this->getUser()), - "can_pin" => $post->canBePinnedBy($this->getUser()), - "can_archive" => false, # TODO MAYBE - "is_archived" => false, - "is_pinned" => $post->isPinned(), - "attachments" => $attachments, - "post_source" => (object)["type" => "vk"], - "comments" => (object)[ - "count" => $post->getCommentsCount(), + "id" => $post->getVirtualId(), + "from_id" => $from_id, + "owner_id" => $post->getTargetWall(), + "date" => $post->getPublicationTime()->timestamp(), + "post_type" => "post", + "text" => $post->getText(false), + "can_edit" => 0, # TODO + "can_delete" => $post->canBeDeletedBy($this->getUser()), + "can_pin" => $post->canBePinnedBy($this->getUser()), + "can_archive" => false, # TODO MAYBE + "is_archived" => false, + "is_pinned" => $post->isPinned(), + "attachments" => $attachments, + "post_source" => (object)["type" => "vk"], + "comments" => (object)[ + "count" => $post->getCommentsCount(), "can_post" => 1 ], "likes" => (object)[ - "count" => $post->getLikesCount(), - "user_likes" => (int) $post->hasLikeFrom($this->getUser()), - "can_like" => 1, + "count" => $post->getLikesCount(), + "user_likes" => (int) $post->hasLikeFrom($this->getUser()), + "can_like" => 1, "can_publish" => 1, ], "reposts" => (object)[ - "count" => $post->getRepostCount(), + "count" => $post->getRepostCount(), "user_reposted" => 0 ] ]; @@ -78,58 +77,56 @@ final class Wall extends VKAPIRequestHandler if ($from_id > 0) $profiles[] = $from_id; else - $groups[] = $from_id * -1; + $groups[] = $from_id * -1; $attachments = NULL; # free attachments so it will not clone everythingg } - if($extended == 1) - { + if($extended == 1) { $profiles = array_unique($profiles); - $groups = array_unique($groups); + $groups = array_unique($groups); $profilesFormatted = []; - $groupsFormatted = []; + $groupsFormatted = []; - foreach ($profiles as $prof) { - $user = (new UsersRepo)->get($prof); + foreach($profiles as $prof) { + $user = (new UsersRepo)->get($prof); $profilesFormatted[] = (object)[ - "first_name" => $user->getFirstName(), - "id" => $user->getId(), - "last_name" => $user->getLastName(), + "first_name" => $user->getFirstName(), + "id" => $user->getId(), + "last_name" => $user->getLastName(), "can_access_closed" => false, - "is_closed" => false, - "sex" => $user->isFemale() ? 1 : 2, - "screen_name" => $user->getShortCode(), - "photo_50" => $user->getAvatarUrl(), - "photo_100" => $user->getAvatarUrl(), - "online" => $user->isOnline() + "is_closed" => false, + "sex" => $user->isFemale() ? 1 : 2, + "screen_name" => $user->getShortCode(), + "photo_50" => $user->getAvatarUrl(), + "photo_100" => $user->getAvatarUrl(), + "online" => $user->isOnline() ]; } foreach($groups as $g) { - $group = (new ClubsRepo)->get($g); + $group = (new ClubsRepo)->get($g); $groupsFormatted[] = (object)[ - "id" => $group->getId(), - "name" => $group->getName(), + "id" => $group->getId(), + "name" => $group->getName(), "screen_name" => $group->getShortCode(), - "is_closed" => 0, - "type" => "group", - "photo_50" => $group->getAvatarUrl(), - "photo_100" => $group->getAvatarUrl(), - "photo_200" => $group->getAvatarUrl(), + "is_closed" => 0, + "type" => "group", + "photo_50" => $group->getAvatarUrl(), + "photo_100" => $group->getAvatarUrl(), + "photo_200" => $group->getAvatarUrl(), ]; } - return (object)[ - "count" => $count, - "items" => (array)$items, + return (object) [ + "count" => $count, + "items" => (array)$items, "profiles" => (array)$profilesFormatted, - "groups" => (array)$groupsFormatted + "groups" => (array)$groupsFormatted ]; - } - else - return (object)[ + } else + return (object) [ "count" => $count, "items" => (array)$items ]; @@ -137,71 +134,68 @@ final class Wall extends VKAPIRequestHandler function getById(string $posts, int $extended = 0, string $fields = "", User $user = NULL) { - if($user == NULL) $user = $this->getUser(); # костыли костыли крылышки + if($user == NULL) + $user = $this->getUser(); # костыли костыли крылышки - $items = []; + $items = []; $profiles = []; - $groups = []; - # $count = $posts->getPostCountOnUserWall((int) $owner_id); + $groups = []; - $psts = explode(",", $posts); + $psts = explode(',', $posts); - foreach($psts as $pst) - { - $id = explode("_", $pst); + foreach($psts as $pst) { + $id = explode("_", $pst); $post = (new PostsRepo)->getPostById(intval($id[0]), intval($id[1])); if($post) { $from_id = get_class($post->getOwner()) == "openvk\Web\Models\Entities\Club" ? $post->getOwner()->getId() * (-1) : $post->getOwner()->getId(); $attachments; - foreach($post->getChildren() as $attachment) - { - if($attachment instanceof \openvk\Web\Models\Entities\Photo) - { + foreach($post->getChildren() as $attachment) { + if($attachment instanceof \openvk\Web\Models\Entities\Photo) { $attachments[] = [ - "type" => "photo", + "type" => "photo", "photo" => [ "album_id" => $attachment->getAlbum() ? $attachment->getAlbum()->getId() : NULL, - "date" => $attachment->getPublicationTime()->timestamp(), - "id" => $attachment->getVirtualId(), + "date" => $attachment->getPublicationTime()->timestamp(), + "id" => $attachment->getVirtualId(), "owner_id" => $attachment->getOwner()->getId(), - "sizes" => array( + "sizes" => array( [ "height" => 2560, - "url" => $attachment->getURLBySizeId("normal"), - "type" => "m", - "width" => 2560, + "url" => $attachment->getURLBySizeId("normal"), + "type" => "m", + "width" => 2560, ], [ "height" => 130, - "url" => $attachment->getURLBySizeId("tiny"), - "type" => "o", - "width" => 130, + "url" => $attachment->getURLBySizeId("tiny"), + "type" => "o", + "width" => 130, ], [ "height" => 604, - "url" => $attachment->getURLBySizeId("normal"), - "type" => "p", - "width" => 604, + "url" => $attachment->getURLBySizeId("normal"), + "type" => "p", + "width" => 604, ], [ "height" => 807, - "url" => $attachment->getURLBySizeId("large"), - "type" => "q", - "width" => 807, + "url" => $attachment->getURLBySizeId("large"), + "type" => "q", + "width" => 807, ], [ "height" => 1280, - "url" => $attachment->getURLBySizeId("larger"), - "type" => "r", - "width" => 1280, + "url" => $attachment->getURLBySizeId("larger"), + "type" => "r", + "width" => 1280, ], [ "height" => 75, # Для временного компросима оставляю статическое число. Если каждый раз обращаться к файлу за количеством пикселов, то наступает пuпuська полная с производительностью, так что пока так - "url" => $attachment->getURLBySizeId("miniscule"), - "type" => "s", - "width" => 75, + "url" => $attachment->getURLBySizeId("miniscule"), + "type" => "s", + "width" => 75, ]), - "text" => "", + "text" => "", "has_tags" => false ] ]; @@ -209,32 +203,32 @@ final class Wall extends VKAPIRequestHandler } $items[] = (object)[ - "id" => $post->getVirtualId(), - "from_id" => $from_id, - "owner_id" => $post->getTargetWall(), - "date" => $post->getPublicationTime()->timestamp(), - "post_type" => "post", - "text" => $post->getText(false), - "can_edit" => 0, # TODO - "can_delete" => $post->canBeDeletedBy($user), - "can_pin" => $post->canBePinnedBy($user), - "can_archive" => false, # TODO MAYBE - "is_archived" => false, - "is_pinned" => $post->isPinned(), - "post_source" => (object)["type" => "vk"], - "attachments" => $attachments, - "comments" => (object)[ - "count" => $post->getCommentsCount(), + "id" => $post->getVirtualId(), + "from_id" => $from_id, + "owner_id" => $post->getTargetWall(), + "date" => $post->getPublicationTime()->timestamp(), + "post_type" => "post", + "text" => $post->getText(false), + "can_edit" => 0, # TODO + "can_delete" => $post->canBeDeletedBy($user), + "can_pin" => $post->canBePinnedBy($user), + "can_archive" => false, # TODO MAYBE + "is_archived" => false, + "is_pinned" => $post->isPinned(), + "post_source" => (object)["type" => "vk"], + "attachments" => $attachments, + "comments" => (object)[ + "count" => $post->getCommentsCount(), "can_post" => 1 ], "likes" => (object)[ - "count" => $post->getLikesCount(), - "user_likes" => (int) $post->hasLikeFrom($user), - "can_like" => 1, + "count" => $post->getLikesCount(), + "user_likes" => (int) $post->hasLikeFrom($user), + "can_like" => 1, "can_publish" => 1, ], "reposts" => (object)[ - "count" => $post->getRepostCount(), + "count" => $post->getRepostCount(), "user_reposted" => 0 ] ]; @@ -242,58 +236,56 @@ final class Wall extends VKAPIRequestHandler if ($from_id > 0) $profiles[] = $from_id; else - $groups[] = $from_id * -1; + $groups[] = $from_id * -1; $attachments = NULL; # free attachments so it will not clone everythingg } } - if($extended == 1) - { + if($extended == 1) { $profiles = array_unique($profiles); - $groups = array_unique($groups); + $groups = array_unique($groups); $profilesFormatted = []; - $groupsFormatted = []; + $groupsFormatted = []; - foreach ($profiles as $prof) { - $user = (new UsersRepo)->get($prof); + foreach($profiles as $prof) { + $user = (new UsersRepo)->get($prof); $profilesFormatted[] = (object)[ - "first_name" => $user->getFirstName(), - "id" => $user->getId(), - "last_name" => $user->getLastName(), + "first_name" => $user->getFirstName(), + "id" => $user->getId(), + "last_name" => $user->getLastName(), "can_access_closed" => false, - "is_closed" => false, - "sex" => $user->isFemale() ? 1 : 2, - "screen_name" => $user->getShortCode(), - "photo_50" => $user->getAvatarUrl(), - "photo_100" => $user->getAvatarUrl(), - "online" => $user->isOnline() + "is_closed" => false, + "sex" => $user->isFemale() ? 1 : 2, + "screen_name" => $user->getShortCode(), + "photo_50" => $user->getAvatarUrl(), + "photo_100" => $user->getAvatarUrl(), + "online" => $user->isOnline() ]; } foreach($groups as $g) { - $group = (new ClubsRepo)->get($g); + $group = (new ClubsRepo)->get($g); $groupsFormatted[] = (object)[ - "id" => $group->getId(), - "name" => $group->getName(), - "screen_name" => $group->getShortCode(), - "is_closed" => 0, - "type" => "group", - "photo_50" => $group->getAvatarUrl(), - "photo_100" => $group->getAvatarUrl(), - "photo_200" => $group->getAvatarUrl(), + "id" => $group->getId(), + "name" => $group->getName(), + "screen_name" => $group->getShortCode(), + "is_closed" => 0, + "type" => "group", + "photo_50" => $group->getAvatarUrl(), + "photo_100" => $group->getAvatarUrl(), + "photo_200" => $group->getAvatarUrl(), ]; } - return (object)[ - "items" => (array)$items, + return (object) [ + "items" => (array)$items, "profiles" => (array)$profilesFormatted, - "groups" => (array)$groupsFormatted + "groups" => (array)$groupsFormatted ]; - } - else - return (object)[ + } else + return (object) [ "items" => (array)$items ]; } @@ -302,7 +294,7 @@ final class Wall extends VKAPIRequestHandler { $this->requireUser(); - $owner_id = intval($owner_id); + $owner_id = intval($owner_id); $wallOwner = ($owner_id > 0 ? (new UsersRepo)->get($owner_id) : (new ClubsRepo)->get($owner_id * -1)) ?? $this->fail(18, "User was deleted or banned");