VKAPI: Make code match the code style

This commit is contained in:
Maxim Leshchenko 2022-07-21 20:13:09 +01:00
parent a578dca41f
commit 771595ef9c
No known key found for this signature in database
GPG key ID: BB9C44A8733FBEEE
10 changed files with 312 additions and 366 deletions

View file

@ -8,16 +8,16 @@ final class Account extends VKAPIRequestHandler
$this->requireUser(); $this->requireUser();
return (object) [ return (object) [
"first_name" => $this->getUser()->getFirstName(), "first_name" => $this->getUser()->getFirstName(),
"id" => $this->getUser()->getId(), "id" => $this->getUser()->getId(),
"last_name" => $this->getUser()->getLastName(), "last_name" => $this->getUser()->getLastName(),
"home_town" => $this->getUser()->getHometown(), "home_town" => $this->getUser()->getHometown(),
"status" => $this->getUser()->getStatus(), "status" => $this->getUser()->getStatus(),
"bdate" => "1.1.1970", # TODO "bdate" => "1.1.1970", # TODO
"bdate_visibility" => 0, # TODO "bdate_visibility" => 0, # TODO
"phone" => "+420 ** *** 228", # TODO "phone" => "+420 ** *** 228", # TODO
"relation" => $this->getUser()->getMaritalStatus(), "relation" => $this->getUser()->getMaritalStatus(),
"sex" => $this->getUser()->isFemale() ? 1 : 2 "sex" => $this->getUser()->isFemale() ? 1 : 2
]; ];
} }
@ -28,17 +28,17 @@ final class Account extends VKAPIRequestHandler
# Цiй метод є заглушка # Цiй метод є заглушка
return (object) [ return (object) [
"2fa_required" => 0, "2fa_required" => 0,
"country" => "CZ", # TODO "country" => "CZ", # TODO
"eu_user" => false, # TODO "eu_user" => false, # TODO
"https_required" => 1, "https_required" => 1,
"intro" => 0, "intro" => 0,
"community_comments" => false, "community_comments" => false,
"is_live_streaming_enabled" => false, "is_live_streaming_enabled" => false,
"is_new_live_streaming_enabled" => false, "is_new_live_streaming_enabled" => false,
"lang" => 1, "lang" => 1,
"no_wall_replies" => 0, "no_wall_replies" => 0,
"own_posts_default" => 0 "own_posts_default" => 0
]; ];
} }
@ -68,9 +68,9 @@ final class Account extends VKAPIRequestHandler
function getCounters(string $filter = ""): object function getCounters(string $filter = ""): object
{ {
return (object) [ return (object) [
"friends" => $this->getUser()->getFollowersCount(), "friends" => $this->getUser()->getFollowersCount(),
"notifications" => $this->getUser()->getNotificationsCount(), "notifications" => $this->getUser()->getNotificationsCount(),
"messages" => $this->getUser()->getUnreadMessagesCount() "messages" => $this->getUser()->getUnreadMessagesCount()
]; ];
# TODO: Filter # TODO: Filter

View file

@ -10,12 +10,12 @@ final class Audio extends VKAPIRequestHandler
return (object) [ return (object) [
"count" => 1, "count" => 1,
"items" => [(object) [ "items" => [(object) [
"id" => 1, "id" => 1,
"owner_id" => 1, "owner_id" => 1,
"artist" => "В ОВК ПОКА НЕТ МУЗЫКИ", "artist" => "В ОВК ПОКА НЕТ МУЗЫКИ",
"title" => "ЖДИТЕ :)))", "title" => "ЖДИТЕ :)))",
"duration" => 22, "duration" => 22,
"url" => $serverUrl . "/assets/packages/static/openvk/audio/nomusic.mp3" "url" => $serverUrl . "/assets/packages/static/openvk/audio/nomusic.mp3"
]] ]]
]; ];
} }

View file

@ -1,6 +1,5 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
namespace openvk\VKAPI\Handlers; namespace openvk\VKAPI\Handlers;
use openvk\Web\Models\Entities\User;
use openvk\Web\Models\Repositories\Users as UsersRepo; use openvk\Web\Models\Repositories\Users as UsersRepo;
final class Friends extends VKAPIRequestHandler final class Friends extends VKAPIRequestHandler
@ -15,7 +14,7 @@ final class Friends extends VKAPIRequestHandler
$this->requireUser(); $this->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(); $friends[$i] = $friend->getId();
$i++; $i++;
} }
@ -24,7 +23,7 @@ final class Friends extends VKAPIRequestHandler
$usersApi = new Users($this->getUser()); $usersApi = new Users($this->getUser());
if (!is_null($fields)) { if(!is_null($fields)) {
$response = $usersApi->get(implode(',', $friends), $fields, 0, $count); # FIXME $response = $usersApi->get(implode(',', $friends), $fields, 0, $count); # FIXME
} }
@ -70,33 +69,28 @@ final class Friends extends VKAPIRequestHandler
$this->requireUser(); $this->requireUser();
$users = new UsersRepo; $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"); $this->fail(177, "Cannot add this user to friends as user not found");
} else if($user->getId() == $this->getUser()->getId()) { } else if($user->getId() == $this->getUser()->getId()) {
$this->fail(174, "Cannot add user himself as friend"); $this->fail(174, "Cannot add user himself as friend");
} }
switch ($user->getSubscriptionStatus($this->getUser())) { switch($user->getSubscriptionStatus($this->getUser())) {
case 0: case 0:
$user->toggleSubscription($this->getUser()); $user->toggleSubscription($this->getUser());
return 1; return 1;
break;
case 1: case 1:
$user->toggleSubscription($this->getUser()); $user->toggleSubscription($this->getUser());
return 2; return 2;
break;
case 3: case 3:
return 2; return 2;
break;
default: default:
return 1; return 1;
break;
} }
} }
@ -108,15 +102,13 @@ final class Friends extends VKAPIRequestHandler
$user = $users->get(intval($user_id)); $user = $users->get(intval($user_id));
switch ($user->getSubscriptionStatus($this->getUser())) { switch($user->getSubscriptionStatus($this->getUser())) {
case 3: case 3:
$user->toggleSubscription($this->getUser()); $user->toggleSubscription($this->getUser());
return 1; return 1;
break;
default: default:
fail(15, "Access denied: No friend or friend request found."); fail(15, "Access denied: No friend or friend request found.");
break;
} }
} }
@ -130,28 +122,12 @@ final class Friends extends VKAPIRequestHandler
$response = []; $response = [];
for ($i=0; $i < sizeof($friends); $i++) { for($i=0; $i < sizeof($friends); $i++) {
$friend = $users->get(intval($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)[ $response[] = (object)[
"friend_status" => $friend->getSubscriptionStatus($this->getUser()), "friend_status" => $friend->getSubscriptionStatus($this->getUser()),
"user_id" => $friend->getId() "user_id" => $friend->getId()
]; ];
} }

View file

@ -1,12 +1,7 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
namespace openvk\VKAPI\Handlers; namespace openvk\VKAPI\Handlers;
use openvk\Web\Models\Entities\User;
use openvk\Web\Models\Entities\Clubs;
use openvk\Web\Models\Repositories\Clubs as ClubsRepo; use openvk\Web\Models\Repositories\Clubs as ClubsRepo;
use openvk\Web\Models\Repositories\Users as UsersRepo; use openvk\Web\Models\Repositories\Users as UsersRepo;
use openvk\Web\Models\Entities\Post;
use openvk\Web\Models\Entities\Postable;
use openvk\Web\Models\Repositories\Posts as PostsRepo;
final class Groups extends VKAPIRequestHandler final class Groups extends VKAPIRequestHandler
{ {
@ -14,45 +9,44 @@ final class Groups extends VKAPIRequestHandler
{ {
$this->requireUser(); $this->requireUser();
if ($user_id == 0) { if($user_id == 0) {
foreach($this->getUser()->getClubs($offset+1) as $club) { foreach($this->getUser()->getClubs($offset+1) as $club)
$clbs[] = $club; $clbs[] = $club;
}
$clbsCount = $this->getUser()->getClubCount(); $clbsCount = $this->getUser()->getClubCount();
} else { } else {
$users = new UsersRepo; $users = new UsersRepo;
$user = $users->get($user_id); $user = $users->get($user_id);
if (is_null($user)) {
if(is_null($user))
$this->fail(15, "Access denied"); $this->fail(15, "Access denied");
}
foreach($user->getClubs($offset+1) as $club) { foreach($user->getClubs($offset+1) as $club)
$clbs[] = $club; $clbs[] = $club;
}
$clbsCount = $user->getClubCount(); $clbsCount = $user->getClubCount();
} }
$rClubs; $rClubs;
$ic = sizeof($clbs); $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); $clbs = array_slice($clbs, $offset * $count);
for ($i=0; $i < $ic; $i++) { for($i=0; $i < $ic; $i++) {
$usr = $clbs[$i]; $usr = $clbs[$i];
if(is_null($usr)) if(is_null($usr)) {
{
$rClubs[$i] = (object)[ $rClubs[$i] = (object)[
"id" => $clbs[$i], "id" => $clbs[$i],
"name" => "DELETED", "name" => "DELETED",
"deactivated" => "deleted" "deactivated" => "deleted"
]; ];
}else if($clbs[$i] == NULL){ } else if($clbs[$i] == NULL) {
}else{ } else {
$rClubs[$i] = (object)[ $rClubs[$i] = (object) [
"id" => $usr->getId(), "id" => $usr->getId(),
"name" => $usr->getName(), "name" => $usr->getName(),
"screen_name" => $usr->getShortCode(), "screen_name" => $usr->getShortCode(),
@ -63,35 +57,35 @@ final class Groups extends VKAPIRequestHandler
$flds = explode(',', $fields); $flds = explode(',', $fields);
foreach($flds as $field) { foreach($flds as $field) {
switch ($field) { switch($field) {
case 'verified': case "verified":
$rClubs[$i]->verified = intval($usr->isVerified()); $rClubs[$i]->verified = intval($usr->isVerified());
break; break;
case 'has_photo': case "has_photo":
$rClubs[$i]->has_photo = is_null($usr->getAvatarPhoto()) ? 0 : 1; $rClubs[$i]->has_photo = is_null($usr->getAvatarPhoto()) ? 0 : 1;
break; break;
case 'photo_max_orig': case "photo_max_orig":
$rClubs[$i]->photo_max_orig = $usr->getAvatarURL(); $rClubs[$i]->photo_max_orig = $usr->getAvatarURL();
break; break;
case 'photo_max': case "photo_max":
$rClubs[$i]->photo_max = $usr->getAvatarURL("original"); // ORIGINAL ANDREI CHINITEL 🥵🥵🥵🥵 $rClubs[$i]->photo_max = $usr->getAvatarURL("original"); // ORIGINAL ANDREI CHINITEL 🥵🥵🥵🥵
break; break;
case 'photo_50': case "photo_50":
$rClubs[$i]->photo_50 = $usr->getAvatarURL(); $rClubs[$i]->photo_50 = $usr->getAvatarURL();
break; break;
case 'photo_100': case "photo_100":
$rClubs[$i]->photo_100 = $usr->getAvatarURL("tiny"); $rClubs[$i]->photo_100 = $usr->getAvatarURL("tiny");
break; break;
case 'photo_200': case "photo_200":
$rClubs[$i]->photo_200 = $usr->getAvatarURL("normal"); $rClubs[$i]->photo_200 = $usr->getAvatarURL("normal");
break; break;
case 'photo_200_orig': case "photo_200_orig":
$rClubs[$i]->photo_200_orig = $usr->getAvatarURL("normal"); $rClubs[$i]->photo_200_orig = $usr->getAvatarURL("normal");
break; break;
case 'photo_400_orig': case "photo_400_orig":
$rClubs[$i]->photo_400_orig = $usr->getAvatarURL("normal"); $rClubs[$i]->photo_400_orig = $usr->getAvatarURL("normal");
break; break;
case 'members_count': case "members_count":
$rClubs[$i]->members_count = $usr->getFollowersCount(); $rClubs[$i]->members_count = $usr->getFollowersCount();
break; break;
} }
@ -112,10 +106,10 @@ final class Groups extends VKAPIRequestHandler
{ {
$clubs = new ClubsRepo; $clubs = new ClubsRepo;
if ($group_ids == NULL && $group_id != NULL) if($group_ids == NULL && $group_id != NULL)
$group_ids = $group_id; $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"); $this->fail(100, "One of the parameters specified was missing or invalid: group_ids is undefined");
$clbs = explode(',', $group_ids); $clbs = explode(',', $group_ids);
@ -123,7 +117,7 @@ final class Groups extends VKAPIRequestHandler
$ic = sizeof($clbs); $ic = sizeof($clbs);
for ($i=0; $i < $ic; $i++) { for($i=0; $i < $ic; $i++) {
if($i > 500) if($i > 500)
break; break;
@ -131,64 +125,64 @@ final class Groups extends VKAPIRequestHandler
$this->fail(100, "ты ошибся чутка, у айди группы убери минус"); $this->fail(100, "ты ошибся чутка, у айди группы убери минус");
$clb = $clubs->get((int) $clbs[$i]); $clb = $clubs->get((int) $clbs[$i]);
if(is_null($clb)) if(is_null($clb)) {
{
$response[$i] = (object)[ $response[$i] = (object)[
"id" => intval($clbs[$i]), "id" => intval($clbs[$i]),
"name" => "DELETED", "name" => "DELETED",
"screen_name" => "club".intval($clbs[$i]), "screen_name" => "club".intval($clbs[$i]),
"type" => "group", "type" => "group",
"description" => "This group was deleted or it doesn't exist" "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)[ $response[$i] = (object)[
"id" => $clb->getId(), "id" => $clb->getId(),
"name" => $clb->getName(), "name" => $clb->getName(),
"screen_name" => $clb->getShortCode() ?? "club".$clb->getId(), "screen_name" => $clb->getShortCode() ?? "club".$clb->getId(),
"is_closed" => false, "is_closed" => false,
"type" => "group", "type" => "group",
"can_access_closed" => true, "can_access_closed" => true,
]; ];
$flds = explode(',', $fields); $flds = explode(',', $fields);
foreach($flds as $field) { foreach($flds as $field) {
switch ($field) { switch($field) {
case 'verified': case "verified":
$response[$i]->verified = intval($clb->isVerified()); $response[$i]->verified = intval($clb->isVerified());
break; break;
case 'has_photo': case "has_photo":
$response[$i]->has_photo = is_null($clb->getAvatarPhoto()) ? 0 : 1; $response[$i]->has_photo = is_null($clb->getAvatarPhoto()) ? 0 : 1;
break; break;
case 'photo_max_orig': case "photo_max_orig":
$response[$i]->photo_max_orig = $clb->getAvatarURL(); $response[$i]->photo_max_orig = $clb->getAvatarURL();
break; break;
case 'photo_max': case "photo_max":
$response[$i]->photo_max = $clb->getAvatarURL(); $response[$i]->photo_max = $clb->getAvatarURL();
break; break;
case 'members_count': case "members_count":
$response[$i]->members_count = $clb->getFollowersCount(); $response[$i]->members_count = $clb->getFollowersCount();
break; break;
case 'site': case "site":
$response[$i]->site = $clb->getWebsite(); $response[$i]->site = $clb->getWebsite();
break; break;
case 'description': case "description":
$response[$i]->desctiption = $clb->getDescription(); $response[$i]->desctiption = $clb->getDescription();
break; break;
case 'contacts': case "contacts":
$contacts; $contacts;
$contactTmp = $clb->getManagers(1, true); $contactTmp = $clb->getManagers(1, true);
foreach($contactTmp as $contact) {
foreach($contactTmp as $contact)
$contacts[] = array( $contacts[] = array(
'user_id' => $contact->getUser()->getId(), "user_id" => $contact->getUser()->getId(),
'desc' => $contact->getComment() "desc" => $contact->getComment()
); );
}
$response[$i]->contacts = $contacts; $response[$i]->contacts = $contacts;
break; break;
case 'can_post': case "can_post":
if(!is_null($this->getUser())) if(!is_null($this->getUser()))
if($clb->canBeModifiedBy($this->getUser())) if($clb->canBeModifiedBy($this->getUser()))
$response[$i]->can_post = true; $response[$i]->can_post = true;

View file

@ -9,19 +9,19 @@ final class Likes extends VKAPIRequestHandler
{ {
$this->requireUser(); $this->requireUser();
switch ($type) { switch($type) {
case 'post': case "post":
$post = (new PostsRepo)->getPostById($owner_id, $item_id); $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()); $post->setLike(true, $this->getUser());
return (object)[
return (object) [
"likes" => $post->getLikesCount() "likes" => $post->getLikesCount()
]; ];
break;
default: default:
$this->fail(100, 'One of the parameters specified was missing or invalid: incorrect type'); $this->fail(100, "One of the parameters specified was missing or invalid: incorrect type");
break;
} }
} }
@ -29,19 +29,18 @@ final class Likes extends VKAPIRequestHandler
{ {
$this->requireUser(); $this->requireUser();
switch ($type) { switch($type) {
case 'post': case "post":
$post = (new PostsRepo)->getPostById($owner_id, $item_id); $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()); $post->setLike(false, $this->getUser());
return (object)[ return (object) [
"likes" => $post->getLikesCount() "likes" => $post->getLikesCount()
]; ];
break;
default: default:
$this->fail(100, 'One of the parameters specified was missing or invalid: incorrect type'); $this->fail(100, "One of the parameters specified was missing or invalid: incorrect type");
break;
} }
} }
@ -49,26 +48,26 @@ final class Likes extends VKAPIRequestHandler
{ {
$this->requireUser(); $this->requireUser();
switch ($type) { switch($type) {
case 'post': case "post":
$user = (new UsersRepo)->get($user_id); $user = (new UsersRepo)->get($user_id);
if (is_null($user)) return (object)[ if (is_null($user))
"liked" => 0, return (object) [
"copied" => 0, "liked" => 0,
"sex" => 0 "copied" => 0,
]; "sex" => 0
];
$post = (new PostsRepo)->getPostById($owner_id, $item_id); $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)[ return (object) [
"liked" => (int) $post->hasLikeFrom($user), "liked" => (int) $post->hasLikeFrom($user),
"copied" => 0 # TODO: handle this "copied" => 0 # TODO: handle this
]; ];
break;
default: default:
$this->fail(100, 'One of the parameters specified was missing or invalid: incorrect type'); $this->fail(100, "One of the parameters specified was missing or invalid: incorrect type");
break;
} }
} }
} }

View file

@ -40,7 +40,7 @@ final class Messages extends VKAPIRequestHandler
continue; continue;
$author = $message->getSender()->getId() === $this->getUser()->getId() ? $message->getRecipient()->getId() : $message->getSender()->getId(); $author = $message->getSender()->getId() === $this->getUser()->getId() ? $message->getRecipient()->getId() : $message->getSender()->getId();
$rMsg = new APIMsg; $rMsg = new APIMsg;
$rMsg->id = $message->getId(); $rMsg->id = $message->getId();
$rMsg->user_id = $author; $rMsg->user_id = $author;
@ -123,9 +123,8 @@ final class Messages extends VKAPIRequestHandler
$items = []; $items = [];
foreach($ids as $id) { foreach($ids as $id) {
$message = $msgs->get((int) $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; $items[$id] = 0;
}
$message->delete(); $message->delete();
$items[$id] = 1; $items[$id] = 1;
@ -186,7 +185,7 @@ final class Messages extends VKAPIRequestHandler
else else
$author = $lastMessage->getSender()->getId(); $author = $lastMessage->getSender()->getId();
$lastMessagePreview = new APIMsg; $lastMessagePreview = new APIMsg;
$lastMessagePreview->id = $lastMessage->getId(); $lastMessagePreview->id = $lastMessage->getId();
$lastMessagePreview->user_id = $author; $lastMessagePreview->user_id = $author;
$lastMessagePreview->from_id = $lastMessage->getSender()->getId(); $lastMessagePreview->from_id = $lastMessage->getSender()->getId();
@ -218,8 +217,8 @@ final class Messages extends VKAPIRequestHandler
$users = array_unique($users); $users = array_unique($users);
return (object) [ return (object) [
"count" => sizeof($list), "count" => sizeof($list),
"items" => $list, "items" => $list,
"profiles" => (!empty($users) ? (new APIUsers)->get(implode(',', $users), $fields, $offset, $count) : []) "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); $dialogue = new Correspondence($this->getUser(), $user);
$iterator = $dialogue->getMessages(Correspondence::CAP_BEHAVIOUR_START_MESSAGE_ID, 0, 1, 0, false); $iterator = $dialogue->getMessages(Correspondence::CAP_BEHAVIOUR_START_MESSAGE_ID, 0, 1, 0, false);
$msg = $iterator[0]->unwrap(); // шоб удобнее было $msg = $iterator[0]->unwrap(); // шоб удобнее было
$output['items'][] = [ $output['items'][] = [
"peer" => [ "peer" => [
"id" => $user->getId(), "id" => $user->getId(),
@ -276,7 +275,7 @@ final class Messages extends VKAPIRequestHandler
} }
if($extended == 1) { if($extended == 1) {
$userslist = array_unique($userslist); $userslist = array_unique($userslist);
$output['profiles'] = (!empty($userslist) ? (new APIUsers)->get(implode(',', $userslist), $fields) : []); $output['profiles'] = (!empty($userslist) ? (new APIUsers)->get(implode(',', $userslist), $fields) : []);
} }

View file

@ -1,8 +1,5 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
namespace openvk\VKAPI\Handlers; namespace openvk\VKAPI\Handlers;
use openvk\Web\Models\Entities\User;
use openvk\Web\Models\Entities\Post;
use openvk\Web\Models\Entities\Postable;
use Chandler\Database\DatabaseConnection; use Chandler\Database\DatabaseConnection;
use openvk\Web\Models\Repositories\Posts as PostsRepo; use openvk\Web\Models\Repositories\Posts as PostsRepo;
use openvk\VKAPI\Handlers\Wall; use openvk\VKAPI\Handlers\Wall;
@ -13,7 +10,8 @@ final class Newsfeed extends VKAPIRequestHandler
{ {
$this->requireUser(); $this->requireUser();
if($offset != 0) $start_from = $offset; if($offset != 0)
$start_from = $offset;
$id = $this->getUser()->getId(); $id = $this->getUser()->getId();
$subs = DatabaseConnection::i() $subs = DatabaseConnection::i()
@ -26,12 +24,12 @@ final class Newsfeed extends VKAPIRequestHandler
$ids[] = $this->getUser()->getId(); $ids[] = $this->getUser()->getId();
$posts = DatabaseConnection::i() $posts = DatabaseConnection::i()
->getContext() ->getContext()
->table("posts") ->table("posts")
->select("id") ->select("id")
->where("wall IN (?)", $ids) ->where("wall IN (?)", $ids)
->where("deleted", 0) ->where("deleted", 0)
->order("created DESC"); ->order("created DESC");
$rposts = []; $rposts = [];
foreach($posts->page((int) ($offset + 1), $count) as $post) foreach($posts->page((int) ($offset + 1), $count) as $post)

View file

@ -2,7 +2,6 @@
namespace openvk\VKAPI\Handlers; namespace openvk\VKAPI\Handlers;
use openvk\Web\Models\Repositories\{Users as UsersRepo, Clubs as ClubsRepo, Posts as PostsRepo}; use openvk\Web\Models\Repositories\{Users as UsersRepo, Clubs as ClubsRepo, Posts as PostsRepo};
final class Ovk extends VKAPIRequestHandler final class Ovk extends VKAPIRequestHandler
{ {
function version(): string function version(): string

View file

@ -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 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(); if($authuser == NULL) $authuser = $this->getUser();
$users = new UsersRepo; $users = new UsersRepo;
if($user_ids == "0") if($user_ids == "0")
$user_ids = (string) $authuser->getId(); $user_ids = (string) $authuser->getId();
$usrs = explode(',', $user_ids); $usrs = explode(',', $user_ids);','
$response; $response;
$ic = sizeof($usrs); $ic = sizeof($usrs);
if(sizeof($usrs) > $count) $ic = $count; if(sizeof($usrs) > $count)
$ic = $count;
$usrs = array_slice($usrs, $offset * $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]); $usr = $users->get((int) $usrs[$i]);
if(is_null($usr)) if(is_null($usr)) {
{
$response[$i] = (object)[ $response[$i] = (object)[
"id" => $usrs[$i], "id" => $usrs[$i],
"first_name" => "DELETED", "first_name" => "DELETED",
"last_name" => "", "last_name" => "",
"deactivated" => "deleted" "deactivated" => "deleted"
]; ];
}else if($usrs[$i] == NULL){ } else if($usrs[$i] == NULL) {
}else{ } else {
$response[$i] = (object)[ $response[$i] = (object)[
"id" => $usr->getId(), "id" => $usr->getId(),
"first_name" => $usr->getFirstName(), "first_name" => $usr->getFirstName(),
"last_name" => $usr->getLastName(), "last_name" => $usr->getLastName(),
"is_closed" => false, "is_closed" => false,
"can_access_closed" => true, "can_access_closed" => true,
]; ];
$flds = explode(',', $fields); $flds = explode(',', $fields);
foreach($flds as $field) { foreach($flds as $field) {
switch ($field) { switch($field) {
case 'verified': case "verified":
$response[$i]->verified = intval($usr->isVerified()); $response[$i]->verified = intval($usr->isVerified());
break; break;
case 'sex': case "sex":
$response[$i]->sex = $usr->isFemale() ? 1 : 2; $response[$i]->sex = $usr->isFemale() ? 1 : 2;
break; break;
case 'has_photo': case "has_photo":
$response[$i]->has_photo = is_null($usr->getAvatarPhoto()) ? 0 : 1; $response[$i]->has_photo = is_null($usr->getAvatarPhoto()) ? 0 : 1;
break; break;
case 'photo_max_orig': case "photo_max_orig":
$response[$i]->photo_max_orig = $usr->getAvatarURL(); $response[$i]->photo_max_orig = $usr->getAvatarURL();
break; break;
case 'photo_max': case "photo_max":
$response[$i]->photo_max = $usr->getAvatarURL("original"); $response[$i]->photo_max = $usr->getAvatarURL("original");
break; break;
case 'photo_50': case "photo_50":
$response[$i]->photo_50 = $usr->getAvatarURL(); $response[$i]->photo_50 = $usr->getAvatarURL();
break; break;
case 'photo_100': case "photo_100":
$response[$i]->photo_100 = $usr->getAvatarURL("tiny"); $response[$i]->photo_100 = $usr->getAvatarURL("tiny");
break; break;
case 'photo_200': case "photo_200":
$response[$i]->photo_200 = $usr->getAvatarURL("normal"); $response[$i]->photo_200 = $usr->getAvatarURL("normal");
break; break;
case 'photo_200_orig': # вообще не ебу к чему эта строка ну пусть будет кек case "photo_200_orig": # вообще не ебу к чему эта строка ну пусть будет кек
$response[$i]->photo_200_orig = $usr->getAvatarURL("normal"); $response[$i]->photo_200_orig = $usr->getAvatarURL("normal");
break; break;
case 'photo_400_orig': case "photo_400_orig":
$response[$i]->photo_400_orig = $usr->getAvatarURL("normal"); $response[$i]->photo_400_orig = $usr->getAvatarURL("normal");
break; break;
# Она хочет быть выебанной видя матан # Она хочет быть выебанной видя матан
# Покайфу когда ты Виет а вокруг лишь дискриминант # Покайфу когда ты Виет а вокруг лишь дискриминант
case 'status': case "status":
if($usr->getStatus() != NULL) if($usr->getStatus() != NULL)
$response[$i]->status = $usr->getStatus(); $response[$i]->status = $usr->getStatus();
break; break;
case 'screen_name': case "screen_name":
if($usr->getShortCode() != NULL) if($usr->getShortCode() != NULL)
$response[$i]->screen_name = $usr->getShortCode(); $response[$i]->screen_name = $usr->getShortCode();
break; break;
case 'friend_status': case "friend_status":
switch($usr->getSubscriptionStatus($authuser)) { switch($usr->getSubscriptionStatus($authuser)) {
case 3: case 3:
# NOTICE falling through
case 0: case 0:
$response[$i]->friend_status = $usr->getSubscriptionStatus($authuser); $response[$i]->friend_status = $usr->getSubscriptionStatus($authuser);
break; break;
@ -104,50 +103,43 @@ final class Users extends VKAPIRequestHandler
break; break;
} }
break; break;
case 'last_seen': case "last_seen":
if ($usr->onlineStatus() == 0) { if ($usr->onlineStatus() == 0)
$response[$i]->last_seen = (object) [ $response[$i]->last_seen = (object) [
"platform" => 1, "platform" => 1,
"time" => $usr->getOnline()->timestamp() "time" => $usr->getOnline()->timestamp()
]; ];
} case "music":
case 'music':
$response[$i]->music = $usr->getFavoriteMusic(); $response[$i]->music = $usr->getFavoriteMusic();
break; break;
case 'movies': case "movies":
$response[$i]->movies = $usr->getFavoriteFilms(); $response[$i]->movies = $usr->getFavoriteFilms();
break; break;
case 'tv': case "tv":
$response[$i]->tv = $usr->getFavoriteShows(); $response[$i]->tv = $usr->getFavoriteShows();
break; break;
case 'books': case "books":
$response[$i]->books = $usr->getFavoriteBooks(); $response[$i]->books = $usr->getFavoriteBooks();
break; break;
case 'city': case "city":
$response[$i]->city = $usr->getCity(); $response[$i]->city = $usr->getCity();
break; break;
case 'interests': case "interests":
$response[$i]->interests = $usr->getInterests(); $response[$i]->interests = $usr->getInterests();
break; break;
} }
} }
if($usr->getOnline()->timestamp() + 300 > time()) { if($usr->getOnline()->timestamp() + 300 > time())
$response[$i]->online = 1; $response[$i]->online = 1;
}else{ else
$response[$i]->online = 0; $response[$i]->online = 0;
}
} }
} }
return $response; 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 function getFollowers(int $user_id, string $fields = "", int $offset = 0, int $count = 100): object
{ {
$offset++; $offset++;
@ -157,15 +149,13 @@ final class Users extends VKAPIRequestHandler
$this->requireUser(); $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(); $followers[] = $follower->getId();
}
$response = $followers; $response = $followers;
if (!is_null($fields)) { if(!is_null($fields))
$response = $this->get(implode(',', $followers), $fields, 0, $count); $response = $this->get(implode(',', $followers), $fields, 0, $count);
}
return (object) [ return (object) [
"count" => $users->get($user_id)->getFollowersCount(), "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; $users = new UsersRepo;
$array = []; $array = [];
$find = $users->find($q); $find = $users->find($q);
foreach ($find as $user) { foreach ($find as $user)
$array[] = $user->getId(); $array[] = $user->getId();
}
return (object)[ return (object) [
"count" => $find->size(), "count" => $find->size(),
"items" => $this->get(implode(',', $array), $fields, $offset, $count) "items" => $this->get(implode(',', $array), $fields, $offset, $count)
]; ];

View file

@ -6,21 +6,20 @@ use openvk\Web\Models\Repositories\Users as UsersRepo;
use openvk\Web\Models\Entities\Club; use openvk\Web\Models\Entities\Club;
use openvk\Web\Models\Repositories\Clubs as ClubsRepo; use openvk\Web\Models\Repositories\Clubs as ClubsRepo;
use openvk\Web\Models\Entities\Post; use openvk\Web\Models\Entities\Post;
use openvk\Web\Models\Entities\Postable;
use openvk\Web\Models\Repositories\Posts as PostsRepo; use openvk\Web\Models\Repositories\Posts as PostsRepo;
final class Wall extends VKAPIRequestHandler final class Wall extends VKAPIRequestHandler
{ {
function get(string $owner_id, string $domain = "", int $offset = 0, int $count = 30, int $extended = 0): object 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 = []; $profiles = [];
$groups = []; $groups = [];
$count = $posts->getPostCountOnUserWall((int) $owner_id); $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(); $from_id = get_class($post->getOwner()) == "openvk\Web\Models\Entities\Club" ? $post->getOwner()->getId() * (-1) : $post->getOwner()->getId();
$attachments = []; $attachments = [];
@ -45,32 +44,32 @@ final class Wall extends VKAPIRequestHandler
} }
$items[] = (object)[ $items[] = (object)[
"id" => $post->getVirtualId(), "id" => $post->getVirtualId(),
"from_id" => $from_id, "from_id" => $from_id,
"owner_id" => $post->getTargetWall(), "owner_id" => $post->getTargetWall(),
"date" => $post->getPublicationTime()->timestamp(), "date" => $post->getPublicationTime()->timestamp(),
"post_type" => "post", "post_type" => "post",
"text" => $post->getText(false), "text" => $post->getText(false),
"can_edit" => 0, # TODO "can_edit" => 0, # TODO
"can_delete" => $post->canBeDeletedBy($this->getUser()), "can_delete" => $post->canBeDeletedBy($this->getUser()),
"can_pin" => $post->canBePinnedBy($this->getUser()), "can_pin" => $post->canBePinnedBy($this->getUser()),
"can_archive" => false, # TODO MAYBE "can_archive" => false, # TODO MAYBE
"is_archived" => false, "is_archived" => false,
"is_pinned" => $post->isPinned(), "is_pinned" => $post->isPinned(),
"attachments" => $attachments, "attachments" => $attachments,
"post_source" => (object)["type" => "vk"], "post_source" => (object)["type" => "vk"],
"comments" => (object)[ "comments" => (object)[
"count" => $post->getCommentsCount(), "count" => $post->getCommentsCount(),
"can_post" => 1 "can_post" => 1
], ],
"likes" => (object)[ "likes" => (object)[
"count" => $post->getLikesCount(), "count" => $post->getLikesCount(),
"user_likes" => (int) $post->hasLikeFrom($this->getUser()), "user_likes" => (int) $post->hasLikeFrom($this->getUser()),
"can_like" => 1, "can_like" => 1,
"can_publish" => 1, "can_publish" => 1,
], ],
"reposts" => (object)[ "reposts" => (object)[
"count" => $post->getRepostCount(), "count" => $post->getRepostCount(),
"user_reposted" => 0 "user_reposted" => 0
] ]
]; ];
@ -78,58 +77,56 @@ final class Wall extends VKAPIRequestHandler
if ($from_id > 0) if ($from_id > 0)
$profiles[] = $from_id; $profiles[] = $from_id;
else else
$groups[] = $from_id * -1; $groups[] = $from_id * -1;
$attachments = NULL; # free attachments so it will not clone everythingg $attachments = NULL; # free attachments so it will not clone everythingg
} }
if($extended == 1) if($extended == 1) {
{
$profiles = array_unique($profiles); $profiles = array_unique($profiles);
$groups = array_unique($groups); $groups = array_unique($groups);
$profilesFormatted = []; $profilesFormatted = [];
$groupsFormatted = []; $groupsFormatted = [];
foreach ($profiles as $prof) { foreach($profiles as $prof) {
$user = (new UsersRepo)->get($prof); $user = (new UsersRepo)->get($prof);
$profilesFormatted[] = (object)[ $profilesFormatted[] = (object)[
"first_name" => $user->getFirstName(), "first_name" => $user->getFirstName(),
"id" => $user->getId(), "id" => $user->getId(),
"last_name" => $user->getLastName(), "last_name" => $user->getLastName(),
"can_access_closed" => false, "can_access_closed" => false,
"is_closed" => false, "is_closed" => false,
"sex" => $user->isFemale() ? 1 : 2, "sex" => $user->isFemale() ? 1 : 2,
"screen_name" => $user->getShortCode(), "screen_name" => $user->getShortCode(),
"photo_50" => $user->getAvatarUrl(), "photo_50" => $user->getAvatarUrl(),
"photo_100" => $user->getAvatarUrl(), "photo_100" => $user->getAvatarUrl(),
"online" => $user->isOnline() "online" => $user->isOnline()
]; ];
} }
foreach($groups as $g) { foreach($groups as $g) {
$group = (new ClubsRepo)->get($g); $group = (new ClubsRepo)->get($g);
$groupsFormatted[] = (object)[ $groupsFormatted[] = (object)[
"id" => $group->getId(), "id" => $group->getId(),
"name" => $group->getName(), "name" => $group->getName(),
"screen_name" => $group->getShortCode(), "screen_name" => $group->getShortCode(),
"is_closed" => 0, "is_closed" => 0,
"type" => "group", "type" => "group",
"photo_50" => $group->getAvatarUrl(), "photo_50" => $group->getAvatarUrl(),
"photo_100" => $group->getAvatarUrl(), "photo_100" => $group->getAvatarUrl(),
"photo_200" => $group->getAvatarUrl(), "photo_200" => $group->getAvatarUrl(),
]; ];
} }
return (object)[ return (object) [
"count" => $count, "count" => $count,
"items" => (array)$items, "items" => (array)$items,
"profiles" => (array)$profilesFormatted, "profiles" => (array)$profilesFormatted,
"groups" => (array)$groupsFormatted "groups" => (array)$groupsFormatted
]; ];
} } else
else return (object) [
return (object)[
"count" => $count, "count" => $count,
"items" => (array)$items "items" => (array)$items
]; ];
@ -137,71 +134,68 @@ final class Wall extends VKAPIRequestHandler
function getById(string $posts, int $extended = 0, string $fields = "", User $user = NULL) 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 = []; $profiles = [];
$groups = []; $groups = [];
# $count = $posts->getPostCountOnUserWall((int) $owner_id);
$psts = explode(",", $posts); $psts = explode(',', $posts);
foreach($psts as $pst) foreach($psts as $pst) {
{ $id = explode("_", $pst);
$id = explode("_", $pst);
$post = (new PostsRepo)->getPostById(intval($id[0]), intval($id[1])); $post = (new PostsRepo)->getPostById(intval($id[0]), intval($id[1]));
if($post) { if($post) {
$from_id = get_class($post->getOwner()) == "openvk\Web\Models\Entities\Club" ? $post->getOwner()->getId() * (-1) : $post->getOwner()->getId(); $from_id = get_class($post->getOwner()) == "openvk\Web\Models\Entities\Club" ? $post->getOwner()->getId() * (-1) : $post->getOwner()->getId();
$attachments; $attachments;
foreach($post->getChildren() as $attachment) foreach($post->getChildren() as $attachment) {
{ if($attachment instanceof \openvk\Web\Models\Entities\Photo) {
if($attachment instanceof \openvk\Web\Models\Entities\Photo)
{
$attachments[] = [ $attachments[] = [
"type" => "photo", "type" => "photo",
"photo" => [ "photo" => [
"album_id" => $attachment->getAlbum() ? $attachment->getAlbum()->getId() : NULL, "album_id" => $attachment->getAlbum() ? $attachment->getAlbum()->getId() : NULL,
"date" => $attachment->getPublicationTime()->timestamp(), "date" => $attachment->getPublicationTime()->timestamp(),
"id" => $attachment->getVirtualId(), "id" => $attachment->getVirtualId(),
"owner_id" => $attachment->getOwner()->getId(), "owner_id" => $attachment->getOwner()->getId(),
"sizes" => array( "sizes" => array(
[ [
"height" => 2560, "height" => 2560,
"url" => $attachment->getURLBySizeId("normal"), "url" => $attachment->getURLBySizeId("normal"),
"type" => "m", "type" => "m",
"width" => 2560, "width" => 2560,
], ],
[ [
"height" => 130, "height" => 130,
"url" => $attachment->getURLBySizeId("tiny"), "url" => $attachment->getURLBySizeId("tiny"),
"type" => "o", "type" => "o",
"width" => 130, "width" => 130,
], ],
[ [
"height" => 604, "height" => 604,
"url" => $attachment->getURLBySizeId("normal"), "url" => $attachment->getURLBySizeId("normal"),
"type" => "p", "type" => "p",
"width" => 604, "width" => 604,
], ],
[ [
"height" => 807, "height" => 807,
"url" => $attachment->getURLBySizeId("large"), "url" => $attachment->getURLBySizeId("large"),
"type" => "q", "type" => "q",
"width" => 807, "width" => 807,
], ],
[ [
"height" => 1280, "height" => 1280,
"url" => $attachment->getURLBySizeId("larger"), "url" => $attachment->getURLBySizeId("larger"),
"type" => "r", "type" => "r",
"width" => 1280, "width" => 1280,
], ],
[ [
"height" => 75, # Для временного компросима оставляю статическое число. Если каждый раз обращаться к файлу за количеством пикселов, то наступает пuпuська полная с производительностью, так что пока так "height" => 75, # Для временного компросима оставляю статическое число. Если каждый раз обращаться к файлу за количеством пикселов, то наступает пuпuська полная с производительностью, так что пока так
"url" => $attachment->getURLBySizeId("miniscule"), "url" => $attachment->getURLBySizeId("miniscule"),
"type" => "s", "type" => "s",
"width" => 75, "width" => 75,
]), ]),
"text" => "", "text" => "",
"has_tags" => false "has_tags" => false
] ]
]; ];
@ -209,32 +203,32 @@ final class Wall extends VKAPIRequestHandler
} }
$items[] = (object)[ $items[] = (object)[
"id" => $post->getVirtualId(), "id" => $post->getVirtualId(),
"from_id" => $from_id, "from_id" => $from_id,
"owner_id" => $post->getTargetWall(), "owner_id" => $post->getTargetWall(),
"date" => $post->getPublicationTime()->timestamp(), "date" => $post->getPublicationTime()->timestamp(),
"post_type" => "post", "post_type" => "post",
"text" => $post->getText(false), "text" => $post->getText(false),
"can_edit" => 0, # TODO "can_edit" => 0, # TODO
"can_delete" => $post->canBeDeletedBy($user), "can_delete" => $post->canBeDeletedBy($user),
"can_pin" => $post->canBePinnedBy($user), "can_pin" => $post->canBePinnedBy($user),
"can_archive" => false, # TODO MAYBE "can_archive" => false, # TODO MAYBE
"is_archived" => false, "is_archived" => false,
"is_pinned" => $post->isPinned(), "is_pinned" => $post->isPinned(),
"post_source" => (object)["type" => "vk"], "post_source" => (object)["type" => "vk"],
"attachments" => $attachments, "attachments" => $attachments,
"comments" => (object)[ "comments" => (object)[
"count" => $post->getCommentsCount(), "count" => $post->getCommentsCount(),
"can_post" => 1 "can_post" => 1
], ],
"likes" => (object)[ "likes" => (object)[
"count" => $post->getLikesCount(), "count" => $post->getLikesCount(),
"user_likes" => (int) $post->hasLikeFrom($user), "user_likes" => (int) $post->hasLikeFrom($user),
"can_like" => 1, "can_like" => 1,
"can_publish" => 1, "can_publish" => 1,
], ],
"reposts" => (object)[ "reposts" => (object)[
"count" => $post->getRepostCount(), "count" => $post->getRepostCount(),
"user_reposted" => 0 "user_reposted" => 0
] ]
]; ];
@ -242,58 +236,56 @@ final class Wall extends VKAPIRequestHandler
if ($from_id > 0) if ($from_id > 0)
$profiles[] = $from_id; $profiles[] = $from_id;
else else
$groups[] = $from_id * -1; $groups[] = $from_id * -1;
$attachments = NULL; # free attachments so it will not clone everythingg $attachments = NULL; # free attachments so it will not clone everythingg
} }
} }
if($extended == 1) if($extended == 1) {
{
$profiles = array_unique($profiles); $profiles = array_unique($profiles);
$groups = array_unique($groups); $groups = array_unique($groups);
$profilesFormatted = []; $profilesFormatted = [];
$groupsFormatted = []; $groupsFormatted = [];
foreach ($profiles as $prof) { foreach($profiles as $prof) {
$user = (new UsersRepo)->get($prof); $user = (new UsersRepo)->get($prof);
$profilesFormatted[] = (object)[ $profilesFormatted[] = (object)[
"first_name" => $user->getFirstName(), "first_name" => $user->getFirstName(),
"id" => $user->getId(), "id" => $user->getId(),
"last_name" => $user->getLastName(), "last_name" => $user->getLastName(),
"can_access_closed" => false, "can_access_closed" => false,
"is_closed" => false, "is_closed" => false,
"sex" => $user->isFemale() ? 1 : 2, "sex" => $user->isFemale() ? 1 : 2,
"screen_name" => $user->getShortCode(), "screen_name" => $user->getShortCode(),
"photo_50" => $user->getAvatarUrl(), "photo_50" => $user->getAvatarUrl(),
"photo_100" => $user->getAvatarUrl(), "photo_100" => $user->getAvatarUrl(),
"online" => $user->isOnline() "online" => $user->isOnline()
]; ];
} }
foreach($groups as $g) { foreach($groups as $g) {
$group = (new ClubsRepo)->get($g); $group = (new ClubsRepo)->get($g);
$groupsFormatted[] = (object)[ $groupsFormatted[] = (object)[
"id" => $group->getId(), "id" => $group->getId(),
"name" => $group->getName(), "name" => $group->getName(),
"screen_name" => $group->getShortCode(), "screen_name" => $group->getShortCode(),
"is_closed" => 0, "is_closed" => 0,
"type" => "group", "type" => "group",
"photo_50" => $group->getAvatarUrl(), "photo_50" => $group->getAvatarUrl(),
"photo_100" => $group->getAvatarUrl(), "photo_100" => $group->getAvatarUrl(),
"photo_200" => $group->getAvatarUrl(), "photo_200" => $group->getAvatarUrl(),
]; ];
} }
return (object)[ return (object) [
"items" => (array)$items, "items" => (array)$items,
"profiles" => (array)$profilesFormatted, "profiles" => (array)$profilesFormatted,
"groups" => (array)$groupsFormatted "groups" => (array)$groupsFormatted
]; ];
} } else
else return (object) [
return (object)[
"items" => (array)$items "items" => (array)$items
]; ];
} }
@ -302,7 +294,7 @@ final class Wall extends VKAPIRequestHandler
{ {
$this->requireUser(); $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)) $wallOwner = ($owner_id > 0 ? (new UsersRepo)->get($owner_id) : (new ClubsRepo)->get($owner_id * -1))
?? $this->fail(18, "User was deleted or banned"); ?? $this->fail(18, "User was deleted or banned");