Поддержка видео с YouTube в API и фикс board.php (#905)

This commit is contained in:
lalka2018 2023-06-22 14:22:07 +03:00 committed by GitHub
parent 2fed1d9fef
commit 59554172d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 9 deletions

View file

@ -291,7 +291,7 @@ final class Board extends VKAPIRequestHandler
$topic = (new TopicsRepo)->getTopicById($group_id, $topic_id);
if(!$topic || !$topic->getClub() || $topic->isDeleted() || !$topic->getClub()->canBeModifiedBy($this->getUser())) {
if(!$topic || !$topic->getClub() || $topic->isDeleted()) {
$this->fail(5, "Invalid topic");
}
@ -325,6 +325,7 @@ final class Board extends VKAPIRequestHandler
$arr = [];
$club = (new ClubsRepo)->get($group_id);
$topics = array_slice(iterator_to_array((new TopicsRepo)->getClubTopics($club, 1, $count + $offset)), $offset);
$arr["count"] = (new TopicsRepo)->getClubTopicsCount($club);
$arr["items"] = [];
@ -335,7 +336,7 @@ final class Board extends VKAPIRequestHandler
if(empty($topic_ids)) {
foreach($topics as $topic) {
if($topic->isDeleted()) continue;
$arr["items"][] = $topic->toVkApiStruct($preview, $preview_length);
$arr["items"][] = $topic->toVkApiStruct($preview, $preview_length > 1 ? $preview_length : 90);
}
} else {
$topics = explode(',', $topic_ids);
@ -343,8 +344,9 @@ final class Board extends VKAPIRequestHandler
foreach($topics as $topic) {
$id = explode("_", $topic);
$topicy = (new TopicsRepo)->getTopicById((int)$id[0], (int)$id[1]);
if($topicy) {
$arr["items"] = $topicy->toVkApiStruct();
if($topicy && !$topicy->isDeleted()) {
$arr["items"][] = $topicy->toVkApiStruct($preview, $preview_length > 1 ? $preview_length : 90);
}
}
}
@ -406,7 +408,7 @@ final class Board extends VKAPIRequestHandler
$res->id = $comment->getId();
$res->from_id = $comment->getOwner()->getId();
$res->date = $comment->getPublicationTime()->timestamp();
$res->text = $comment->getText();
$res->text = $comment->getText(false);
$res->attachments = [];
$res->likes = [];
if($need_likes) {

View file

@ -61,7 +61,7 @@ class Comment extends Post
$res->id = $this->getId();
$res->from_id = $this->getOwner()->getId();
$res->date = $this->getPublicationTime()->timestamp();
$res->text = $this->getText();
$res->text = $this->getText(false);
$res->attachments = [];
$res->parents_stack = [];

View file

@ -68,6 +68,12 @@ class Topic extends Postable
return isset($array[0]) ? $array[0] : NULL;
}
function getFirstComment(): ?Comment
{
$array = iterator_to_array($this->getComments(1));
return $array[0] ?? NULL;
}
function getUpdateTime(): DateTime
{
$lastComment = $this->getLastComment();
@ -83,4 +89,40 @@ class Topic extends Postable
$this->unwire();
$this->save();
}
function toVkApiStruct(int $preview = 0, int $preview_length = 90): object
{
$res = (object)[];
$res->id = $this->getId();
$res->title = $this->getTitle();
$res->created = $this->getPublicationTime()->timestamp();
if($this->getOwner() instanceof User) {
$res->created_by = $this->getOwner()->getId();
} else {
$res->created_by = $this->getOwner()->getId() * -1;
}
$res->updated = $this->getUpdateTime()->timestamp();
if($this->getLastComment()) {
if($this->getLastComment()->getOwner() instanceof User) {
$res->updated_by = $this->getLastComment()->getOwner()->getId();
} else {
$res->updated_by = $this->getLastComment()->getOwner()->getId() * -1;
}
}
$res->is_closed = (int)$this->isClosed();
$res->is_fixed = (int)$this->isPinned();
$res->comments = $this->getCommentsCount();
if($preview == 1) {
$res->first_comment = $this->getFirstComment() ? ovk_proc_strtr($this->getFirstComment()->getText(false), $preview_length) : NULL;
$res->last_comment = $this->getLastComment() ? ovk_proc_strtr($this->getLastComment()->getText(false), $preview_length) : NULL;
}
return $res;
}
}

View file

@ -117,6 +117,7 @@ class Video extends Media
function getApiStructure(): object
{
$fromYoutube = $this->getType() == Video::TYPE_EMBED;
return (object)[
"type" => "video",
"video" => [
@ -145,10 +146,11 @@ class Video extends Media
"user_id" => $this->getOwner()->getId(),
"title" => $this->getName(),
"is_favorite" => false,
"player" => $this->getURL(),
"files" => [
"player" => !$fromYoutube ? $this->getURL() : $this->getVideoDriver()->getURL(),
"files" => !$fromYoutube ? [
"mp4_480" => $this->getURL()
],
] : NULL,
"platform" => $fromYoutube ? "youtube" : NULL,
"added" => 0,
"repeat" => 0,
"type" => "video",