+ + | ++ |
+ + Подробнее + |
+
+ + |
+
diff --git a/VKAPI/Handlers/Account.php b/VKAPI/Handlers/Account.php index b05e01bd..4b97a266 100644 --- a/VKAPI/Handlers/Account.php +++ b/VKAPI/Handlers/Account.php @@ -46,6 +46,7 @@ final class Account extends VKAPIRequestHandler $this->requireUser(); $this->getUser()->setOnline(time()); + $this->getUser()->setClient_name($this->getPlatform()); $this->getUser()->save(); return 1; diff --git a/VKAPI/Handlers/Users.php b/VKAPI/Handlers/Users.php index 6185a250..acb29469 100644 --- a/VKAPI/Handlers/Users.php +++ b/VKAPI/Handlers/Users.php @@ -108,11 +108,31 @@ final class Users extends VKAPIRequestHandler } break; case "last_seen": - if ($usr->onlineStatus() == 0) + if ($usr->onlineStatus() == 0) { + $platform = $usr->getOnlinePlatform(true); + switch ($platform) { + case 'iphone': + $platform = 2; + break; + + case 'android': + $platform = 4; + break; + + case NULL: + $platform = 7; + break; + + default: + $platform = 1; + break; + } + $response[$i]->last_seen = (object) [ - "platform" => 1, + "platform" => $platform, "time" => $usr->getOnline()->timestamp() ]; + } case "music": $response[$i]->music = $usr->getFavoriteMusic(); break; diff --git a/VKAPI/Handlers/VKAPIRequestHandler.php b/VKAPI/Handlers/VKAPIRequestHandler.php index 79cfb41b..e9413c12 100644 --- a/VKAPI/Handlers/VKAPIRequestHandler.php +++ b/VKAPI/Handlers/VKAPIRequestHandler.php @@ -6,10 +6,12 @@ use openvk\Web\Models\Entities\User; abstract class VKAPIRequestHandler { protected $user; + protected $platform; - function __construct(?User $user = NULL) + function __construct(?User $user = NULL, ?string $platform = NULL) { - $this->user = $user; + $this->user = $user; + $this->platform = $platform; } protected function fail(int $code, string $message): void @@ -22,6 +24,11 @@ abstract class VKAPIRequestHandler return $this->user; } + protected function getPlatform(): ?string + { + return $this->platform; + } + protected function userAuthorized(): bool { return !is_null($this->getUser()); diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index 9297dcbc..f47160f2 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -64,6 +64,17 @@ final class Wall extends VKAPIRequestHandler 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(), @@ -72,13 +83,22 @@ final class Wall extends VKAPIRequestHandler "post_type" => "post", "text" => $attachment->getText(false), "attachments" => $repostAttachments, - "post_source" => [ - "type" => "vk" - ], + "post_source" => $post_source, ]; } } + $post_source = []; + + if($attachment->getPlatform(true) === NULL) { + $post_source = (object)["type" => "vk"]; + } else { + $post_source = (object)[ + "type" => "api", + "platform" => $attachment->getPlatform(true) + ]; + } + $items[] = (object)[ "id" => $post->getVirtualId(), "from_id" => $from_id, @@ -94,7 +114,7 @@ final class Wall extends VKAPIRequestHandler "is_archived" => false, "is_pinned" => $post->isPinned(), "attachments" => $attachments, - "post_source" => (object)["type" => "vk"], + "post_source" => $post_source, "comments" => (object)[ "count" => $post->getCommentsCount(), "can_post" => 1 @@ -212,6 +232,17 @@ final class Wall extends VKAPIRequestHandler 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(), @@ -220,13 +251,22 @@ final class Wall extends VKAPIRequestHandler "post_type" => "post", "text" => $attachment->getText(false), "attachments" => $repostAttachments, - "post_source" => [ - "type" => "vk" - ], + "post_source" => $post_source, ]; } } + $post_source = []; + + if($post->getPlatform(true) === NULL) { + $post_source = (object)["type" => "vk"]; + } else { + $post_source = (object)[ + "type" => "api", + "platform" => $post->getPlatform(true) + ]; + } + $items[] = (object)[ "id" => $post->getVirtualId(), "from_id" => $from_id, @@ -241,7 +281,7 @@ final class Wall extends VKAPIRequestHandler "can_archive" => false, # TODO MAYBE "is_archived" => false, "is_pinned" => $post->isPinned(), - "post_source" => (object)["type" => "vk"], + "post_source" => $post_source, "attachments" => $attachments, "comments" => (object)[ "count" => $post->getCommentsCount(), @@ -384,6 +424,7 @@ final class Wall extends VKAPIRequestHandler $post->setCreated(time()); $post->setContent($message); $post->setFlags($flags); + $post->setApi_Source_Name($this->getPlatform()); $post->save(); } catch(\LogicException $ex) { $this->fail(100, "One of the parameters specified was missing or invalid"); @@ -415,6 +456,7 @@ final class Wall extends VKAPIRequestHandler $nPost->setOwner($this->user->getId()); $nPost->setWall($this->user->getId()); $nPost->setContent($message); + $nPost->setApi_Source_Name($this->getPlatform()); $nPost->save(); $nPost->attach($post); diff --git a/Web/Models/Entities/APIToken.php b/Web/Models/Entities/APIToken.php index 7257c6a8..f5744ec3 100644 --- a/Web/Models/Entities/APIToken.php +++ b/Web/Models/Entities/APIToken.php @@ -22,6 +22,11 @@ class APIToken extends RowModel { return $this->getId() . "-" . chunk_split($this->getSecret(), 8, "-") . "jill"; } + + function getPlatform(): ?string + { + return $this->getRecord()->platform; + } function isRevoked(): bool { diff --git a/Web/Models/Entities/Post.php b/Web/Models/Entities/Post.php index 40769292..7fffb3dd 100644 --- a/Web/Models/Entities/Post.php +++ b/Web/Models/Entities/Post.php @@ -113,6 +113,63 @@ class Post extends Postable { return $this->getOwner(false)->getId(); } + + function getPlatform(bool $forAPI = false): ?string + { + $platform = $this->getRecord()->api_source_name; + if($forAPI) { + switch ($platform) { + case 'openvk_android': + case 'openvk_legacy_android': + return 'android'; + break; + + case 'openvk_ios': + case 'openvk_legacy_ios': + return 'iphone'; + break; + + case 'vika_touch': // кика хохотач ахахахаххахахахахах + case 'vk4me': + return 'mobile'; + break; + + case NULL: + return NULL; + break; + + default: + return 'api'; + break; + } + } else { + return $platform; + } + } + + function getPlatformDetails(): array + { + $clients = simplexml_load_file(OPENVK_ROOT . "/data/clients.xml"); + + foreach($clients as $client) { + if($client['tag'] == $this->getPlatform()) { + return [ + "tag" => $client['tag'], + "name" => $client['name'], + "url" => $client['url'], + "img" => $client['img'] + ]; + break; + } + } + + return [ + "tag" => $this->getPlatform(), + "name" => NULL, + "url" => NULL, + "img" => NULL + ]; + } function pin(): void { diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php index 31d8f4c8..dcdf6ef4 100644 --- a/Web/Models/Entities/User.php +++ b/Web/Models/Entities/User.php @@ -751,6 +751,63 @@ class User extends RowModel return time() - $this->getRecord()->online <= 300; } + function getOnlinePlatform(bool $forAPI = false): ?string + { + $platform = $this->getRecord()->client_name; + if($forAPI) { + switch ($platform) { + case 'openvk_android': + case 'openvk_legacy_android': + return 'android'; + break; + + case 'openvk_ios': + case 'openvk_legacy_ios': + return 'iphone'; + break; + + case 'vika_touch': // кика хохотач ахахахаххахахахахах + case 'vk4me': + return 'mobile'; + break; + + case NULL: + return NULL; + break; + + default: + return 'api'; + break; + } + } else { + return $platform; + } + } + + function getOnlinePlatformDetails(): array + { + $clients = simplexml_load_file(OPENVK_ROOT . "/data/clients.xml"); + + foreach($clients as $client) { + if($client['tag'] == $this->getOnlinePlatform()) { + return [ + "tag" => $client['tag'], + "name" => $client['name'], + "url" => $client['url'], + "img" => $client['img'] + ]; + break; + } + } + + return [ + "tag" => $this->getOnlinePlatform(), + "name" => NULL, + "url" => NULL, + "img" => NULL + ]; + } + function prefersNotToSeeRating(): bool { return !((bool) $this->getRecord()->show_rating); diff --git a/Web/Presenters/OpenVKPresenter.php b/Web/Presenters/OpenVKPresenter.php index 1505df92..710713e5 100755 --- a/Web/Presenters/OpenVKPresenter.php +++ b/Web/Presenters/OpenVKPresenter.php @@ -254,6 +254,7 @@ abstract class OpenVKPresenter extends SimplePresenter $cacheTime = 0; # Force no cache if($this->user->identity->onlineStatus() == 0 && !($this->user->identity->isDeleted() || $this->user->identity->isBanned())) { $this->user->identity->setOnline(time()); + $this->user->identity->setClient_name(NULL); $this->user->identity->save(); } diff --git a/Web/Presenters/VKAPIPresenter.php b/Web/Presenters/VKAPIPresenter.php index a26a25b9..7c8ed39f 100644 --- a/Web/Presenters/VKAPIPresenter.php +++ b/Web/Presenters/VKAPIPresenter.php @@ -195,10 +195,12 @@ final class VKAPIPresenter extends OpenVKPresenter $identity = NULL; } else { $token = (new APITokens)->getByCode($this->requestParam("access_token")); - if(!$token) + if(!$token) { $identity = NULL; - else + } else { $identity = $token->getUser(); + $platform = $token->getPlatform(); + } } } @@ -207,7 +209,7 @@ final class VKAPIPresenter extends OpenVKPresenter if(!class_exists($handlerClass)) $this->badMethod($object, $method); - $handler = new $handlerClass($identity); + $handler = new $handlerClass($identity, $platform); if(!is_callable([$handler, $method])) $this->badMethod($object, $method); @@ -274,8 +276,11 @@ final class VKAPIPresenter extends OpenVKPresenter $this->fail(28, "Invalid 2FA code", "internal", "acquireToken"); } + $platform = $this->requestParam("client_name"); + $token = new APIToken; $token->setUser($user); + $token->setPlatform(is_null($platform) ? "api" : $platform); $token->save(); $payload = json_encode([ diff --git a/Web/Presenters/templates/User/View.xml b/Web/Presenters/templates/User/View.xml index 61acc215..1c2a797b 100644 --- a/Web/Presenters/templates/User/View.xml +++ b/Web/Presenters/templates/User/View.xml @@ -47,6 +47,11 @@ {else} {$user->isFemale() ? tr("was_online_f") : tr("was_online_m")} {$user->getOnline()} {/if} + {var $platform = $user->getOnlinePlatform()} + {var $platformDetails = $user->getOnlinePlatformDetails()} + + +
+ + | ++ |
+ + Подробнее + |
+
+ + |
+