2020-08-12 14:36:18 +03:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
namespace openvk\VKAPI\Handlers;
|
2022-11-10 16:27:54 +03:00
|
|
|
use openvk\Web\Models\Exceptions\InvalidUserNameException;
|
2020-08-12 14:36:18 +03:00
|
|
|
|
|
|
|
final class Account extends VKAPIRequestHandler
|
|
|
|
{
|
|
|
|
function getProfileInfo(): object
|
|
|
|
{
|
|
|
|
$this->requireUser();
|
api: add some fields and 2 new methods и jsonp
- Изменения коснулись методов 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
2024-10-15 20:42:59 +03:00
|
|
|
$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(),
|
2022-07-21 22:13:09 +03:00
|
|
|
"phone" => "+420 ** *** 228", # TODO
|
api: add some fields and 2 new methods и jsonp
- Изменения коснулись методов 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
2024-10-15 20:42:59 +03:00
|
|
|
"relation" => $user->getMaritalStatus(),
|
|
|
|
"screen_name" => $user->getShortCode(),
|
|
|
|
"sex" => $user->isFemale() ? 1 : 2,
|
|
|
|
#"email" => $user->getEmail(),
|
2020-08-12 14:36:18 +03:00
|
|
|
];
|
api: add some fields and 2 new methods и jsonp
- Изменения коснулись методов 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
2024-10-15 20:42:59 +03:00
|
|
|
|
|
|
|
$audio_status = $user->getCurrentAudioStatus();
|
|
|
|
if(!is_null($audio_status))
|
|
|
|
$return_object->audio_status = $audio_status->toVkApiStruct($user);
|
|
|
|
|
|
|
|
return $return_object;
|
2020-08-12 14:36:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getInfo(): object
|
|
|
|
{
|
|
|
|
$this->requireUser();
|
|
|
|
|
|
|
|
return (object) [
|
2022-08-11 23:20:36 +03:00
|
|
|
"2fa_required" => $this->getUser()->is2faEnabled() ? 1 : 0,
|
2022-07-21 22:13:09 +03:00
|
|
|
"country" => "CZ", # TODO
|
|
|
|
"eu_user" => false, # TODO
|
|
|
|
"https_required" => 1,
|
|
|
|
"intro" => 0,
|
|
|
|
"community_comments" => false,
|
|
|
|
"is_live_streaming_enabled" => false,
|
2020-08-12 14:36:18 +03:00
|
|
|
"is_new_live_streaming_enabled" => false,
|
2022-07-21 22:13:09 +03:00
|
|
|
"lang" => 1,
|
|
|
|
"no_wall_replies" => 0,
|
|
|
|
"own_posts_default" => 0
|
2020-08-12 14:36:18 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-10-08 23:17:45 +03:00
|
|
|
function setOnline(): int
|
2020-08-12 14:36:18 +03:00
|
|
|
{
|
|
|
|
$this->requireUser();
|
|
|
|
|
2023-03-13 17:45:45 +03:00
|
|
|
$this->getUser()->updOnline($this->getPlatform());
|
2022-08-13 05:41:59 +03:00
|
|
|
|
2020-08-12 14:36:18 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-03-09 13:49:36 +03:00
|
|
|
function setOffline(): int
|
2020-08-12 14:36:18 +03:00
|
|
|
{
|
|
|
|
$this->requireUser();
|
|
|
|
|
2022-05-08 13:06:26 +03:00
|
|
|
# Цiй метод є заглушка
|
2020-08-12 14:36:18 +03:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-03-29 12:26:29 +03:00
|
|
|
function getAppPermissions(): int
|
2020-08-12 14:36:18 +03:00
|
|
|
{
|
|
|
|
return 9355263;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCounters(string $filter = ""): object
|
|
|
|
{
|
2023-05-30 11:41:03 +03:00
|
|
|
$this->requireUser();
|
|
|
|
|
2020-08-12 14:36:18 +03:00
|
|
|
return (object) [
|
2022-07-21 22:13:09 +03:00
|
|
|
"friends" => $this->getUser()->getFollowersCount(),
|
2021-01-17 01:11:04 +03:00
|
|
|
"notifications" => $this->getUser()->getNotificationsCount(),
|
2022-07-21 22:13:09 +03:00
|
|
|
"messages" => $this->getUser()->getUnreadMessagesCount()
|
2020-08-12 14:36:18 +03:00
|
|
|
];
|
|
|
|
|
2022-05-08 13:06:26 +03:00
|
|
|
# TODO: Filter
|
2020-08-12 14:36:18 +03:00
|
|
|
}
|
2022-11-10 16:27:54 +03:00
|
|
|
|
|
|
|
function saveProfileInfo(string $first_name = "", string $last_name = "", string $screen_name = "", int $sex = -1, int $relation = -1, string $bdate = "", int $bdate_visibility = -1, string $home_town = "", string $status = ""): object
|
|
|
|
{
|
|
|
|
$this->requireUser();
|
2023-02-08 14:20:50 +03:00
|
|
|
$this->willExecuteWriteAction();
|
|
|
|
|
2022-11-10 16:27:54 +03:00
|
|
|
$user = $this->getUser();
|
|
|
|
|
|
|
|
$output = [
|
|
|
|
"changed" => 0,
|
|
|
|
];
|
|
|
|
|
|
|
|
if(!empty($first_name) || !empty($last_name)) {
|
|
|
|
$output["name_request"] = [
|
|
|
|
"id" => random_int(1, 2048), # For compatibility with original VK API
|
|
|
|
"status" => "success",
|
|
|
|
"first_name" => !empty($first_name) ? $first_name : $user->getFirstName(),
|
|
|
|
"last_name" => !empty($last_name) ? $last_name : $user->getLastName(),
|
|
|
|
];
|
|
|
|
|
|
|
|
try {
|
|
|
|
if(!empty($first_name))
|
|
|
|
$user->setFirst_name($first_name);
|
|
|
|
if(!empty($last_name))
|
|
|
|
$user->setLast_Name($last_name);
|
|
|
|
} catch (InvalidUserNameException $e) {
|
|
|
|
$output["name_request"]["status"] = "declined";
|
|
|
|
return (object) $output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!empty($screen_name))
|
|
|
|
if (!$user->setShortCode($screen_name))
|
|
|
|
$this->fail(1260, "Invalid screen name");
|
|
|
|
|
|
|
|
# For compatibility with original VK API
|
|
|
|
if($sex > 0)
|
|
|
|
$user->setSex($sex == 1 ? 1 : 0);
|
|
|
|
|
|
|
|
if($relation > -1)
|
|
|
|
$user->setMarital_Status($relation);
|
|
|
|
|
|
|
|
if(!empty($bdate)) {
|
|
|
|
$birthday = strtotime($bdate);
|
|
|
|
if (!is_int($birthday))
|
|
|
|
$this->fail(100, "invalid value of bdate.");
|
|
|
|
|
|
|
|
$user->setBirthday($birthday);
|
|
|
|
}
|
|
|
|
|
|
|
|
# For compatibility with original VK API
|
|
|
|
switch($bdate_visibility) {
|
|
|
|
case 0:
|
|
|
|
$this->fail(946, "Hiding date of birth is not implemented.");
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
$user->setBirthday_privacy(0);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
$user->setBirthday_privacy(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!empty($home_town))
|
|
|
|
$user->setHometown($home_town);
|
|
|
|
|
|
|
|
if(!empty($status))
|
|
|
|
$user->setStatus($status);
|
|
|
|
|
|
|
|
if($sex > 0 || $relation > -1 || $bdate_visibility > 1 || !empty("$first_name$last_name$screen_name$bdate$home_town$status")) {
|
|
|
|
$output["changed"] = 1;
|
|
|
|
$user->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
return (object) $output;
|
|
|
|
}
|
api: add some fields and 2 new methods и jsonp
- Изменения коснулись методов 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
2024-10-15 20:42:59 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2024-11-18 19:28:25 +03:00
|
|
|
|
|
|
|
function sendVotes(int $receiver, int $value, string $message = ""): object
|
|
|
|
{
|
|
|
|
$this->requireUser();
|
|
|
|
$this->willExecuteWriteAction();
|
|
|
|
|
|
|
|
if(!OPENVK_ROOT_CONF["openvk"]["preferences"]["commerce"])
|
|
|
|
$this->fail(-105, "Commerce is disabled on this instance");
|
|
|
|
|
|
|
|
if($receiver < 0)
|
|
|
|
$this->fail(-248, "Invalid receiver id");
|
|
|
|
|
|
|
|
if($value < 1)
|
|
|
|
$this->fail(-248, "Invalid value");
|
|
|
|
|
|
|
|
if(iconv_strlen($message) > 255)
|
|
|
|
$this->fail(-249, "Message is too long");
|
|
|
|
|
|
|
|
if($this->getUser()->getCoins() < $value)
|
|
|
|
$this->fail(-252, "Not enough votes");
|
|
|
|
|
|
|
|
$receiver_entity = (new \openvk\Web\Models\Repositories\Users)->get($receiver);
|
|
|
|
if(!$receiver_entity || $receiver_entity->isDeleted())
|
|
|
|
$this->fail(-250, "Invalid receiver");
|
|
|
|
|
|
|
|
if($receiver_entity->getId() === $this->getUser()->getId())
|
|
|
|
$this->fail(-251, "Can't transfer votes to yourself");
|
|
|
|
|
|
|
|
$this->getUser()->setCoins($this->getUser()->getCoins() - $value);
|
|
|
|
$this->getUser()->save();
|
|
|
|
|
|
|
|
$receiver_entity->setCoins($receiver_entity->getCoins() + $value);
|
|
|
|
$receiver_entity->save();
|
|
|
|
|
|
|
|
(new \openvk\Web\Models\Entities\Notifications\CoinsTransferNotification($receiver_entity, $this->getUser(), $value, $message))->emit();
|
|
|
|
|
|
|
|
return (object) ['votes' => $this->getUser()->getCoins()];
|
|
|
|
}
|
2020-08-12 14:36:18 +03:00
|
|
|
}
|