diff --git a/VKAPI/Handlers/Account.php b/VKAPI/Handlers/Account.php index 16308b97e..8c0cb3430 100644 --- a/VKAPI/Handlers/Account.php +++ b/VKAPI/Handlers/Account.php @@ -7,20 +7,32 @@ final class Account extends VKAPIRequestHandler function getProfileInfo(): object { $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(), - "audio_status" => is_null($this->getUser()->getCurrentAudioStatus()) ? NULL : $this->getUser()->getCurrentAudioStatus()->toVkApiStruct($this->getUser()), - "bdate" => is_null($this->getUser()->getBirthday()) ? '01.01.1970' : $this->getUser()->getBirthday()->format('%e.%m.%Y'), - "bdate_visibility" => $this->getUser()->getBirthdayPrivacy(), + $user = $this->getUser(); + $return_object = (object) [ + "first_name" => $user->getFirstName(), + "photo_200" => $user->getAvatarURL("normal"), + "nickname" => $user->getPseudo(), + "is_service_account" => false, + "id" => $user->getId(), + "is_verified" => $user->isVerified(), + "verification_status" => $user->isVerified() ? 'verified' : 'unverified', + "last_name" => $user->getLastName(), + "home_town" => $user->getHometown(), + "status" => $user->getStatus(), + "bdate" => is_null($user->getBirthday()) ? '01.01.1970' : $user->getBirthday()->format('%e.%m.%Y'), + "bdate_visibility" => $user->getBirthdayPrivacy(), "phone" => "+420 ** *** 228", # TODO - "relation" => $this->getUser()->getMaritalStatus(), - "sex" => $this->getUser()->isFemale() ? 1 : 2 + "relation" => $user->getMaritalStatus(), + "screen_name" => $user->getShortCode(), + "sex" => $user->isFemale() ? 1 : 2, + #"email" => $user->getEmail(), ]; + + $audio_status = $user->getCurrentAudioStatus(); + if(!is_null($audio_status)) + $return_object->audio_status = $audio_status->toVkApiStruct($user); + + return $return_object; } function getInfo(): object @@ -152,4 +164,30 @@ function saveProfileInfo(string $first_name = "", string $last_name = "", string return (object) $output; } + + function getBalance(): object + { + $this->requireUser(); + if(!OPENVK_ROOT_CONF['openvk']['preferences']['commerce']) + $this->fail(105, "Commerce is disabled on this instance"); + + return (object) ['votes' => $this->getUser()->getCoins()]; + } + + function getOvkSettings(): object + { + $this->requireUser(); + $user = $this->getUser(); + + $settings_list = (object)[ + 'avatar_style' => $user->getStyleAvatar(), + 'style' => $user->getStyle(), + 'show_rating' => !$user->prefersNotToSeeRating(), + 'nsfw_tolerance' => $user->getNsfwTolerance(), + 'post_view' => $user->hasMicroblogEnabled() ? 'microblog' : 'old', + 'main_page' => $user->getMainPage() == 0 ? 'my_page' : 'news', + ]; + + return $settings_list; + } } diff --git a/VKAPI/Handlers/Gifts.php b/VKAPI/Handlers/Gifts.php index dd6fa07a7..0d1fc5982 100644 --- a/VKAPI/Handlers/Gifts.php +++ b/VKAPI/Handlers/Gifts.php @@ -6,15 +6,18 @@ final class Gifts extends VKAPIRequestHandler { - function get(int $user_id, int $count = 10, int $offset = 0) + function get(int $user_id = NULL, int $count = 10, int $offset = 0) { $this->requireUser(); $i = 0; - $i += $offset; + $server_url = ovk_scheme(true) . $_SERVER["HTTP_HOST"]; - $user = (new UsersRepo)->get($user_id); + if($user_id) + $user = (new UsersRepo)->get($user_id); + else + $user = $this->getUser(); if(!$user || $user->isDeleted()) $this->fail(177, "Invalid user"); @@ -47,9 +50,9 @@ function get(int $user_id, int $count = 10, int $offset = 0) "date" => $gift->sent->timestamp(), "gift" => [ "id" => $gift->gift->getId(), - "thumb_256" => $gift->gift->getImage(2), - "thumb_96" => $gift->gift->getImage(2), - "thumb_48" => $gift->gift->getImage(2) + "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 ]; @@ -125,12 +128,13 @@ function delete() $this->fail(501, "Not implemented"); } - # этих методов не было в ВК, но я их добавил чтобы можно было отобразить список подарков + # в vk кстати называется gifts.getCatalog function getCategories(bool $extended = false, int $page = 1) { $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"); @@ -140,8 +144,8 @@ function getCategories(bool $extended = false, int $page = 1) "name" => $cat->getName(), "description" => $cat->getDescription(), "id" => $cat->getId(), - "thumbnail" => $cat->getThumbnailURL(), - ]; + "thumbnail" => $server_url . $cat->getThumbnailURL(), + ]; if($extended == true) { $categ[$i]["localizations"] = []; @@ -178,7 +182,7 @@ function getGiftsInCategory(int $id, int $page = 1) "name" => $gift->getName(), "image" => $gift->getImage(2), "usages_left" => (int)$gift->getUsagesLeft($this->getUser()), - "price" => $gift->getPrice(), # голосов + "price" => $gift->getPrice(), "is_free" => $gift->isFree() ]; } diff --git a/VKAPI/Handlers/Groups.php b/VKAPI/Handlers/Groups.php index f83079ecb..ca67e7b76 100644 --- a/VKAPI/Handlers/Groups.php +++ b/VKAPI/Handlers/Groups.php @@ -88,6 +88,10 @@ function get(int $user_id = 0, string $fields = "", int $offset = 0, int $count case "can_suggest": $rClubs[$i]->can_suggest = !$usr->canBeModifiedBy($this->getUser()) && $usr->getWallType() == 2; break; + case "background": + $backgrounds = $usr->getBackDropPictureURLs(); + $rClubs[$i]->background = $backgrounds; + break; # unstandard feild case "suggested_count": if($usr->getWallType() != 2) { @@ -208,6 +212,10 @@ function getById(string $group_ids = "", string $group_id = "", string $fields = case "can_suggest": $response[$i]->can_suggest = !$clb->canBeModifiedBy($this->getUser()) && $clb->getWallType() == 2; break; + case "background": + $backgrounds = $clb->getBackDropPictureURLs(); + $response[$i]->background = $backgrounds; + break; # unstandard feild case "suggested_count": if($clb->getWallType() != 2) { diff --git a/VKAPI/Handlers/Users.php b/VKAPI/Handlers/Users.php index f6e5823f0..132b62044 100644 --- a/VKAPI/Handlers/Users.php +++ b/VKAPI/Handlers/Users.php @@ -151,7 +151,6 @@ function get(string $user_ids = "0", string $fields = "", int $offset = 0, int $ } case "music": if(!$canView) { - $response[$i]->music = "secret"; break; } @@ -159,7 +158,6 @@ function get(string $user_ids = "0", string $fields = "", int $offset = 0, int $ break; case "movies": if(!$canView) { - $response[$i]->movies = "secret"; break; } @@ -167,7 +165,6 @@ function get(string $user_ids = "0", string $fields = "", int $offset = 0, int $ break; case "tv": if(!$canView) { - $response[$i]->tv = "secret"; break; } @@ -175,7 +172,6 @@ function get(string $user_ids = "0", string $fields = "", int $offset = 0, int $ break; case "books": if(!$canView) { - $response[$i]->books = "secret"; break; } @@ -183,7 +179,6 @@ function get(string $user_ids = "0", string $fields = "", int $offset = 0, int $ break; case "city": if(!$canView) { - $response[$i]->city = "Воскресенск"; break; } @@ -191,7 +186,6 @@ function get(string $user_ids = "0", string $fields = "", int $offset = 0, int $ break; case "interests": if(!$canView) { - $response[$i]->interests = "secret"; break; } @@ -199,7 +193,6 @@ function get(string $user_ids = "0", string $fields = "", int $offset = 0, int $ break; case "quotes": if(!$canView) { - $response[$i]->quotes = "secret"; break; } @@ -207,7 +200,6 @@ function get(string $user_ids = "0", string $fields = "", int $offset = 0, int $ break; case "email": if(!$canView) { - $response[$i]->email = "secret@gmail.com"; break; } @@ -215,7 +207,6 @@ function get(string $user_ids = "0", string $fields = "", int $offset = 0, int $ break; case "telegram": if(!$canView) { - $response[$i]->telegram = "@secret"; break; } @@ -223,7 +214,6 @@ function get(string $user_ids = "0", string $fields = "", int $offset = 0, int $ break; case "about": if(!$canView) { - $response[$i]->about = "secret"; break; } @@ -231,7 +221,6 @@ function get(string $user_ids = "0", string $fields = "", int $offset = 0, int $ break; case "rating": if(!$canView) { - $response[$i]->rating = 22; break; } @@ -246,9 +235,34 @@ function get(string $user_ids = "0", string $fields = "", int $offset = 0, int $ "notes_count" => (new Notes)->getUserNotesCount($usr) ]; break; + case "correct_counters": + $response[$i]->counters = (object) [ + "friends" => $usr->getFriendsCount(), + "photos" => (new Photos)->getUserPhotosCount($usr), + "videos" => (new Videos)->getUserVideosCount($usr), + "audios" => (new Audios)->getUserCollectionSize($usr), + "notes" => (new Notes)->getUserNotesCount($usr), + "groups" => $usr->getClubCount(), + "online_friends" => $usr->getFriendsOnlineCount(), + ]; + break; case "guid": $response[$i]->guid = $usr->getChandlerGUID(); break; + case 'background': + $backgrounds = $usr->getBackDropPictureURLs(); + $response[$i]->background = $backgrounds; + break; + case 'reg_date': + if(!$canView) { + break; + } + + $response[$i]->reg_date = $usr->getRegistrationTime()->timestamp(); + break; + case 'is_dead': + $response[$i]->is_dead = $usr->isDead(); + break; } } diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index 3cbc76489..a305fde68 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -126,65 +126,41 @@ function get(int $owner_id, string $domain = "", int $offset = 0, int $count = 3 else $profiles[] = $attachment->getOwner()->getId(); - $post_source = []; - - if($attachment->getPlatform(true) === NULL) { - $post_source = (object)["type" => "vk"]; - } else { - $post_source = (object)[ - "type" => "api", - "platform" => $attachment->getPlatform(true) - ]; - } - $repost[] = [ "id" => $attachment->getVirtualId(), "owner_id" => $attachment->isPostedOnBehalfOfGroup() ? $attachment->getOwner()->getId() * -1 : $attachment->getOwner()->getId(), "from_id" => $attachment->isPostedOnBehalfOfGroup() ? $attachment->getOwner()->getId() * -1 : $attachment->getOwner()->getId(), "date" => $attachment->getPublicationTime()->timestamp(), - "post_type" => "post", + "post_type" => $attachment->getVkApiType(), "text" => $attachment->getText(false), "attachments" => $repostAttachments, - "post_source" => $post_source, + "post_source" => $attachment->getPostSourceInfo(), ]; - if ($attachment->getVirtualId() > 0) - $profiles[] = $attachment->getVirtualId(); + if ($attachment->getTargetWall() > 0) + $profiles[] = $attachment->getTargetWall(); else - $groups[] = $attachment->getVirtualId(); + $groups[] = abs($attachment->getTargetWall()); if($post->isSigned()) $profiles[] = $attachment->getOwner()->getId(); } } - $post_source = []; - - if($post->getPlatform(true) === NULL) { - $post_source = (object)["type" => "vk"]; - } else { - $post_source = (object)[ - "type" => "api", - "platform" => $post->getPlatform(true) - ]; - } - - $postType = "post"; $signerId = NULL; - if($post->getSuggestionType() != 0) - $postType = "suggest"; - - if($post->isSigned()) { $actualAuthor = $post->getOwner(false); $signerId = $actualAuthor->getId(); } - $items[] = (object)[ + # TODO "can_pin", "copy_history" и прочее не должны возвращаться, если равны null или false + # Ну и ещё всё надо перенести в toVkApiStruct, а то слишком много дублированного кода + + $post_temp_obj = (object)[ "id" => $post->getVirtualId(), "from_id" => $from_id, "owner_id" => $post->getTargetWall(), "date" => $post->getPublicationTime()->timestamp(), - "post_type" => $postType, + "post_type" => $post->getVkApiType(), "text" => $post->getText(false), "copy_history" => $repost, "can_edit" => $post->canBeEditedBy($this->getUser()), @@ -195,8 +171,7 @@ function get(int $owner_id, string $domain = "", int $offset = 0, int $count = 3 "is_pinned" => $post->isPinned(), "is_explicit" => $post->isExplicit(), "attachments" => $attachments, - "post_source" => $post_source, - "signer_id" => $signerId, + "post_source" => $post->getPostSourceInfo(), "comments" => (object)[ "count" => $post->getCommentsCount(), "can_post" => 1 @@ -213,6 +188,14 @@ function get(int $owner_id, string $domain = "", int $offset = 0, int $count = 3 ] ]; + if($signerId) + $post_temp_obj->signer_id = $signerId; + + if($post->isDeactivationMessage()) + $post_temp_obj->final_post = 1; + + $items[] = $post_temp_obj; + if ($from_id > 0) $profiles[] = $from_id; else @@ -332,17 +315,6 @@ function getById(string $posts, int $extended = 0, string $fields = "", User $us else $profiles[] = $attachment->getOwner()->getId(); - $post_source = []; - - if($attachment->getPlatform(true) === NULL) { - $post_source = (object)["type" => "vk"]; - } else { - $post_source = (object)[ - "type" => "api", - "platform" => $attachment->getPlatform(true) - ]; - } - $repost[] = [ "id" => $attachment->getVirtualId(), "owner_id" => $attachment->isPostedOnBehalfOfGroup() ? $attachment->getOwner()->getId() * -1 : $attachment->getOwner()->getId(), @@ -351,47 +323,29 @@ function getById(string $posts, int $extended = 0, string $fields = "", User $us "post_type" => "post", "text" => $attachment->getText(false), "attachments" => $repostAttachments, - "post_source" => $post_source, + "post_source" => $attachment->getPostSourceInfo(), ]; - if ($attachment->getVirtualId() > 0) - $profiles[] = $attachment->getVirtualId(); + if ($attachment->getTargetWall() > 0) + $profiles[] = $attachment->getTargetWall(); else - $groups[] = $attachment->getVirtualId(); + $groups[] = abs($attachment->getTargetWall()); if($post->isSigned()) $profiles[] = $attachment->getOwner()->getId(); } } - $post_source = []; - - if($post->getPlatform(true) === NULL) { - $post_source = (object)["type" => "vk"]; - } else { - $post_source = (object)[ - "type" => "api", - "platform" => $post->getPlatform(true) - ]; - } - - # TODO: $post->getVkApiType() - $postType = "post"; - $signerId = NULL; - if($post->getSuggestionType() != 0) - $postType = "suggest"; - - if($post->isSigned()) { $actualAuthor = $post->getOwner(false); $signerId = $actualAuthor->getId(); } - $items[] = (object)[ + $post_temp_obj = (object)[ "id" => $post->getVirtualId(), "from_id" => $from_id, "owner_id" => $post->getTargetWall(), "date" => $post->getPublicationTime()->timestamp(), - "post_type" => $postType, + "post_type" => $post->getVkApiType(), "text" => $post->getText(false), "copy_history" => $repost, "can_edit" => $post->canBeEditedBy($this->getUser()), @@ -401,8 +355,7 @@ function getById(string $posts, int $extended = 0, string $fields = "", User $us "is_archived" => false, "is_pinned" => $post->isPinned(), "is_explicit" => $post->isExplicit(), - "post_source" => $post_source, - "signer_id" => $signerId, + "post_source" => $post->getPostSourceInfo(), "attachments" => $attachments, "comments" => (object)[ "count" => $post->getCommentsCount(), @@ -420,6 +373,14 @@ function getById(string $posts, int $extended = 0, string $fields = "", User $us ] ]; + if($signerId) + $post_temp_obj->signer_id = $signerId; + + if($post->isDeactivationMessage()) + $post_temp_obj->final_post = 1; + + $items[] = $post_temp_obj; + if ($from_id > 0) $profiles[] = $from_id; else @@ -792,6 +753,9 @@ function getComments(int $owner_id, int $post_id, bool $need_likes = true, int $ ] ]; + if($comment->isFromPostAuthor($post)) + $item['is_from_post_author'] = true; + if($need_likes == true) $item['likes'] = [ "can_like" => 1, @@ -875,6 +839,9 @@ function getComment(int $owner_id, int $comment_id, bool $extended = false, stri ] ]; + if($comment->isFromPostAuthor()) + $item['is_from_post_author'] = true; + if($extended == true) $profiles[] = $comment->getOwner()->getId(); @@ -890,8 +857,6 @@ function getComment(int $owner_id, int $comment_id, bool $extended = false, stri $response['profiles'] = (!empty($profiles) ? (new Users)->get(implode(',', $profiles), $fields) : []); } - - return $response; } diff --git a/Web/Models/Entities/Comment.php b/Web/Models/Entities/Comment.php index 24fb2c1b2..200d7a168 100644 --- a/Web/Models/Entities/Comment.php +++ b/Web/Models/Entities/Comment.php @@ -103,6 +103,22 @@ function canBeViewedBy(?User $user = NULL): bool return $this->getTarget()->canBeViewedBy($user); } + + function isFromPostAuthor($target = NULL) + { + if(!$target) + $target = $this->getTarget(); + + $target_owner = $target->getOwner(); + $comment_owner = $this->getOwner(); + + if($target_owner->getRealId() === $comment_owner->getRealId()) + return true; + + # TODO: make it work with signer_id + + return false; + } function toNotifApiStruct() { diff --git a/Web/Models/Entities/Post.php b/Web/Models/Entities/Post.php index 4e0386a7a..5a75d99b5 100644 --- a/Web/Models/Entities/Post.php +++ b/Web/Models/Entities/Post.php @@ -179,6 +179,31 @@ function getPlatformDetails(): array "img" => NULL ]; } + + function getPostSourceInfo(): array + { + $post_source = ["type" => "vk"]; + if($this->getPlatform(true) !== NULL) { + $post_source = [ + "type" => "api", + "platform" => $this->getPlatform(true) + ]; + } + + if($this->isUpdateAvatarMessage()) + $post_source['data'] = 'profile_photo'; + + return $post_source; + } + + function getVkApiType(): string + { + $type = 'post'; + if($this->getSuggestionType() != 0) + $type = 'suggest'; + + return $type; + } function pin(): void { diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php index 933ab486f..e8756550c 100644 --- a/Web/Models/Entities/User.php +++ b/Web/Models/Entities/User.php @@ -1224,6 +1224,11 @@ function isActivated(): bool return (bool) $this->getRecord()->activated; } + function isDead(): bool + { + return $this->onlineStatus() == 2; + } + function getUnbanTime(): ?string { $ban = (new Bans)->get((int) $this->getRecord()->block_reason); @@ -1338,13 +1343,14 @@ function toVkApiStruct(?User $user = NULL): object $res->photo_100 = $this->getAvatarURL("tiny"); $res->photo_200 = $this->getAvatarURL("normal"); $res->photo_id = !is_null($this->getAvatarPhoto()) ? $this->getAvatarPhoto()->getPrettyId() : NULL; - # TODO: Perenesti syuda vsyo ostalnoyie $res->is_closed = $this->isClosed(); - if(!is_null($user)) { + if(!is_null($user)) $res->can_access_closed = (bool)$this->canBeViewedBy($user); - } + + if($user->isDead()) + $res->is_dead = 1; return $res; } diff --git a/Web/Presenters/VKAPIPresenter.php b/Web/Presenters/VKAPIPresenter.php index d82194cf2..9eb4565af 100644 --- a/Web/Presenters/VKAPIPresenter.php +++ b/Web/Presenters/VKAPIPresenter.php @@ -186,8 +186,12 @@ function renderPhotoUpload(string $signature): void function renderRoute(string $object, string $method): void { + $callback = $this->queryParam("callback"); $authMechanism = $this->queryParam("auth_mechanism") ?? "token"; if($authMechanism === "roaming") { + if($callback) + $this->fail(-1, "User authorization failed: roaming mechanism is unavailable with jsonp.", $object, $method); + if(!$this->user->identity) $this->fail(5, "User authorization failed: roaming mechanism is selected, but user is not logged in.", $object, $method); else @@ -259,10 +263,16 @@ function renderRoute(string $object, string $method): void $result = json_encode([ "response" => $res, ]); + + if($callback) { + $result = $callback . '(' . $result . ')'; + header('Content-Type: application/javascript'); + } else + header("Content-Type: application/json"); $size = strlen($result); - header("Content-Type: application/json"); header("Content-Length: $size"); + exit($result); }