Compare commits

...

2 commits

Author SHA1 Message Date
veselcraft
06b77ebad8
VKAPI: Add support for attachments for comments 2023-01-31 14:49:12 +03:00
veselcraft
43e18a9173
VKAPI: Add support for Videos 2023-01-31 14:23:34 +03:00
2 changed files with 172 additions and 0 deletions

79
VKAPI/Handlers/Video.php Executable file
View file

@ -0,0 +1,79 @@
<?php declare(strict_types=1);
namespace openvk\VKAPI\Handlers;
use openvk\Web\Models\Entities\User;
use openvk\Web\Models\Repositories\Users as UsersRepo;
use openvk\Web\Models\Entities\Club;
use openvk\Web\Models\Repositories\Clubs as ClubsRepo;
use openvk\Web\Models\Entities\Video as VideoEntity;
use openvk\Web\Models\Repositories\Videos as VideosRepo;
use openvk\Web\Models\Entities\Comment;
use openvk\Web\Models\Repositories\Comments as CommentsRepo;
final class Video extends VKAPIRequestHandler
{
function get(string $videos, int $offset = 0, int $count = 30, int $extended = 0): object
{
$this->requireUser();
$vids = explode(',', $videos);
foreach($vids as $vid)
{
$id = explode("_", $vid);
$items = [];
$video = (new VideosRepo)->getByOwnerAndVID(intval($id[0]), intval($id[1]));
if($video) {
$items[] = [
"type" => "video",
"video" => [
"can_comment" => 1,
"can_like" => 0, // we don't h-have wikes in videos
"can_repost" => 0,
"can_subscribe" => 1,
"can_add_to_faves" => 0,
"can_add" => 0,
"comments" => $video->getCommentsCount(),
"date" => $video->getPublicationTime()->timestamp(),
"description" => $video->getDescription(),
"duration" => 0, // я хуй знает как получить длину видео
"image" => [
[
"url" => $video->getThumbnailURL(),
"width" => 320,
"height" => 240,
"with_padding" => 1
]
],
"width" => 640,
"height" => 480,
"id" => $video->getVirtualId(),
"owner_id" => $video->getOwner()->getId(),
"user_id" => $video->getOwner()->getId(),
"title" => $video->getName(),
"is_favorite" => false,
"player" => $video->getURL(),
"added" => 0,
"repeat" => 0,
"type" => "video",
"views" => 0,
"likes" => [
"count" => 0,
"user_likes" => 0
],
"reposts" => [
"count" => 0,
"user_reposted" => 0
]
]
];
}
}
return (object) [
"count" => count($items),
"items" => $items
];
}
}

View file

@ -48,6 +48,41 @@ final class Wall extends VKAPIRequestHandler
$attachments[] = $this->getApiPhoto($attachment);
} else if($attachment instanceof \openvk\Web\Models\Entities\Poll) {
$attachments[] = $this->getApiPoll($attachment, $this->getUser());
} else if ($attachment instanceof \openvk\Web\Models\Entities\Video) {
$video = [
"type" => "video",
"video" => [
"can_comment" => 1,
"can_like" => 0, // we don't h-have wikes in videos
"can_repost" => 0,
"can_subscribe" => 1,
"can_add_to_faves" => 0,
"can_add" => 0,
"comments" => $attachment->getCommentsCount(),
"date" => $attachment->getPublicationTime()->timestamp(),
"description" => $attachment->getDescription(),
"duration" => 0, // я хуй знает как получить длину видео
"image" => [
[
"url" => $attachment->getThumbnailURL(),
"width" => 320,
"height" => 240,
"with_padding" => 1
]
],
"width" => 640,
"height" => 480,
"id" => $attachment->getVirtualId(),
"owner_id" => $attachment->getOwner()->getId(),
"user_id" => $attachment->getOwner()->getId(),
"title" => $attachment->getName(),
"is_favorite" => false,
"repeat" => 0,
"type" => "video",
"views" => 0, // у нас просмотров нет)
]
];
$attachments[] = $video;
} else if ($attachment instanceof \openvk\Web\Models\Entities\Post) {
$repostAttachments = [];
@ -216,6 +251,41 @@ final class Wall extends VKAPIRequestHandler
$attachments[] = $this->getApiPhoto($attachment);
} else if($attachment instanceof \openvk\Web\Models\Entities\Poll) {
$attachments[] = $this->getApiPoll($attachment, $user);
} else if ($attachment instanceof \openvk\Web\Models\Entities\Video) {
$video = [
"type" => "video",
"video" => [
"can_comment" => 1,
"can_like" => 0, // we don't h-have wikes in videos
"can_repost" => 0,
"can_subscribe" => 1,
"can_add_to_faves" => 0,
"can_add" => 0,
"comments" => $attachment->getCommentsCount(),
"date" => $attachment->getPublicationTime()->timestamp(),
"description" => $attachment->getDescription(),
"duration" => 0, // я хуй знает как получить длину видео
"image" => [
[
"url" => $attachment->getThumbnailURL(),
"width" => 320,
"height" => 240,
"with_padding" => 1
]
],
"width" => 640,
"height" => 480,
"id" => $attachment->getVirtualId(),
"owner_id" => $attachment->getOwner()->getId(),
"user_id" => $attachment->getOwner()->getId(),
"title" => $attachment->getName(),
"is_favorite" => false,
"repeat" => 0,
"type" => "video",
"views" => 0, // у нас просмотров нет)
]
];
$attachments[] = $video;
} else if ($attachment instanceof \openvk\Web\Models\Entities\Post) {
$repostAttachments = [];
@ -489,6 +559,14 @@ final class Wall extends VKAPIRequestHandler
$oid = $owner->getId();
if($owner instanceof Club)
$oid *= -1;
$attachments = [];
foreach($comment->getChildren() as $attachment) {
if($attachment instanceof \openvk\Web\Models\Entities\Photo) {
$attachments[] = $this->getApiPhoto($attachment);
}
}
$item = [
"id" => $comment->getId(),
@ -498,6 +576,7 @@ final class Wall extends VKAPIRequestHandler
"post_id" => $post->getVirtualId(),
"owner_id" => $post->isPostedOnBehalfOfGroup() ? $post->getOwner()->getId() * -1 : $post->getOwner()->getId(),
"parents_stack" => [],
"attachments" => $attachments,
"thread" => [
"count" => 0,
"items" => [],
@ -518,6 +597,9 @@ final class Wall extends VKAPIRequestHandler
$items[] = $item;
if($extended == true)
$profiles[] = $comment->getOwner()->getId();
$attachments = null;
// Reset $attachments to not duplicate prikols
}
$response = [
@ -544,6 +626,14 @@ final class Wall extends VKAPIRequestHandler
$profiles = [];
$attachments = [];
foreach($comment->getChildren() as $attachment) {
if($attachment instanceof \openvk\Web\Models\Entities\Photo) {
$attachments[] = $this->getApiPhoto($attachment);
}
}
$item = [
"id" => $comment->getId(),
"from_id" => $comment->getOwner()->getId(),
@ -552,6 +642,7 @@ final class Wall extends VKAPIRequestHandler
"post_id" => $comment->getTarget()->getVirtualId(),
"owner_id" => $comment->getTarget()->isPostedOnBehalfOfGroup() ? $comment->getTarget()->getOwner()->getId() * -1 : $comment->getTarget()->getOwner()->getId(),
"parents_stack" => [],
"attachments" => $attachments,
"likes" => [
"can_like" => 1,
"count" => $comment->getLikesCount(),
@ -582,6 +673,8 @@ final class Wall extends VKAPIRequestHandler
$response['profiles'] = (!empty($profiles) ? (new Users)->get(implode(',', $profiles), $fields) : []);
}
return $response;
}