Skip to content

Commit

Permalink
api: add some fields and 2 new methods и jsonp
Browse files Browse the repository at this point in the history
- Изменения коснулись методов account.getProfileInfo, account.getBalance, account.getOvkSettings, gifts.get, gifts.getCategories, groups.get, groups.getById, users.get, wall.get, wall.getById, wall.getComments, wall.getComment.
- Добавлена поддержка JSONP
  • Loading branch information
mrilyew committed Oct 15, 2024
1 parent 2795e1e commit b3e5714
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 112 deletions.
62 changes: 50 additions & 12 deletions VKAPI/Handlers/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
24 changes: 14 additions & 10 deletions VKAPI/Handlers/Gifts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
];
Expand Down Expand Up @@ -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");
Expand All @@ -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"] = [];
Expand Down Expand Up @@ -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()
];
}
Expand Down
8 changes: 8 additions & 0 deletions VKAPI/Handlers/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
36 changes: 25 additions & 11 deletions VKAPI/Handlers/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,87 +151,76 @@ function get(string $user_ids = "0", string $fields = "", int $offset = 0, int $
}
case "music":
if(!$canView) {
$response[$i]->music = "secret";
break;
}

$response[$i]->music = $usr->getFavoriteMusic();
break;
case "movies":
if(!$canView) {
$response[$i]->movies = "secret";
break;
}

$response[$i]->movies = $usr->getFavoriteFilms();
break;
case "tv":
if(!$canView) {
$response[$i]->tv = "secret";
break;
}

$response[$i]->tv = $usr->getFavoriteShows();
break;
case "books":
if(!$canView) {
$response[$i]->books = "secret";
break;
}

$response[$i]->books = $usr->getFavoriteBooks();
break;
case "city":
if(!$canView) {
$response[$i]->city = "Воскресенск";
break;
}

$response[$i]->city = $usr->getCity();
break;
case "interests":
if(!$canView) {
$response[$i]->interests = "secret";
break;
}

$response[$i]->interests = $usr->getInterests();
break;
case "quotes":
if(!$canView) {
$response[$i]->quotes = "secret";
break;
}

$response[$i]->quotes = $usr->getFavoriteQuote();
break;
case "email":
if(!$canView) {
$response[$i]->email = "[email protected]";
break;
}

$response[$i]->email = $usr->getContactEmail();
break;
case "telegram":
if(!$canView) {
$response[$i]->telegram = "@secret";
break;
}

$response[$i]->telegram = $usr->getTelegram();
break;
case "about":
if(!$canView) {
$response[$i]->about = "secret";
break;
}

$response[$i]->about = $usr->getDescription();
break;
case "rating":
if(!$canView) {
$response[$i]->rating = 22;
break;
}

Expand All @@ -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;
}
}

Expand Down
Loading

0 comments on commit b3e5714

Please sign in to comment.