mirror of
https://github.com/openvk/openvk
synced 2024-12-23 00:51:03 +03:00
Поддержка видео с YouTube в API и фикс board.php (#905)
This commit is contained in:
parent
2fed1d9fef
commit
59554172d6
4 changed files with 55 additions and 9 deletions
|
@ -291,7 +291,7 @@ final class Board extends VKAPIRequestHandler
|
||||||
|
|
||||||
$topic = (new TopicsRepo)->getTopicById($group_id, $topic_id);
|
$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");
|
$this->fail(5, "Invalid topic");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,6 +325,7 @@ final class Board extends VKAPIRequestHandler
|
||||||
|
|
||||||
$arr = [];
|
$arr = [];
|
||||||
$club = (new ClubsRepo)->get($group_id);
|
$club = (new ClubsRepo)->get($group_id);
|
||||||
|
|
||||||
$topics = array_slice(iterator_to_array((new TopicsRepo)->getClubTopics($club, 1, $count + $offset)), $offset);
|
$topics = array_slice(iterator_to_array((new TopicsRepo)->getClubTopics($club, 1, $count + $offset)), $offset);
|
||||||
$arr["count"] = (new TopicsRepo)->getClubTopicsCount($club);
|
$arr["count"] = (new TopicsRepo)->getClubTopicsCount($club);
|
||||||
$arr["items"] = [];
|
$arr["items"] = [];
|
||||||
|
@ -335,7 +336,7 @@ final class Board extends VKAPIRequestHandler
|
||||||
if(empty($topic_ids)) {
|
if(empty($topic_ids)) {
|
||||||
foreach($topics as $topic) {
|
foreach($topics as $topic) {
|
||||||
if($topic->isDeleted()) continue;
|
if($topic->isDeleted()) continue;
|
||||||
$arr["items"][] = $topic->toVkApiStruct($preview, $preview_length);
|
$arr["items"][] = $topic->toVkApiStruct($preview, $preview_length > 1 ? $preview_length : 90);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$topics = explode(',', $topic_ids);
|
$topics = explode(',', $topic_ids);
|
||||||
|
@ -343,8 +344,9 @@ final class Board extends VKAPIRequestHandler
|
||||||
foreach($topics as $topic) {
|
foreach($topics as $topic) {
|
||||||
$id = explode("_", $topic);
|
$id = explode("_", $topic);
|
||||||
$topicy = (new TopicsRepo)->getTopicById((int)$id[0], (int)$id[1]);
|
$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->id = $comment->getId();
|
||||||
$res->from_id = $comment->getOwner()->getId();
|
$res->from_id = $comment->getOwner()->getId();
|
||||||
$res->date = $comment->getPublicationTime()->timestamp();
|
$res->date = $comment->getPublicationTime()->timestamp();
|
||||||
$res->text = $comment->getText();
|
$res->text = $comment->getText(false);
|
||||||
$res->attachments = [];
|
$res->attachments = [];
|
||||||
$res->likes = [];
|
$res->likes = [];
|
||||||
if($need_likes) {
|
if($need_likes) {
|
||||||
|
|
|
@ -61,7 +61,7 @@ class Comment extends Post
|
||||||
$res->id = $this->getId();
|
$res->id = $this->getId();
|
||||||
$res->from_id = $this->getOwner()->getId();
|
$res->from_id = $this->getOwner()->getId();
|
||||||
$res->date = $this->getPublicationTime()->timestamp();
|
$res->date = $this->getPublicationTime()->timestamp();
|
||||||
$res->text = $this->getText();
|
$res->text = $this->getText(false);
|
||||||
$res->attachments = [];
|
$res->attachments = [];
|
||||||
$res->parents_stack = [];
|
$res->parents_stack = [];
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,12 @@ class Topic extends Postable
|
||||||
return isset($array[0]) ? $array[0] : NULL;
|
return isset($array[0]) ? $array[0] : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getFirstComment(): ?Comment
|
||||||
|
{
|
||||||
|
$array = iterator_to_array($this->getComments(1));
|
||||||
|
return $array[0] ?? NULL;
|
||||||
|
}
|
||||||
|
|
||||||
function getUpdateTime(): DateTime
|
function getUpdateTime(): DateTime
|
||||||
{
|
{
|
||||||
$lastComment = $this->getLastComment();
|
$lastComment = $this->getLastComment();
|
||||||
|
@ -83,4 +89,40 @@ class Topic extends Postable
|
||||||
$this->unwire();
|
$this->unwire();
|
||||||
$this->save();
|
$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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,6 +117,7 @@ class Video extends Media
|
||||||
|
|
||||||
function getApiStructure(): object
|
function getApiStructure(): object
|
||||||
{
|
{
|
||||||
|
$fromYoutube = $this->getType() == Video::TYPE_EMBED;
|
||||||
return (object)[
|
return (object)[
|
||||||
"type" => "video",
|
"type" => "video",
|
||||||
"video" => [
|
"video" => [
|
||||||
|
@ -145,10 +146,11 @@ class Video extends Media
|
||||||
"user_id" => $this->getOwner()->getId(),
|
"user_id" => $this->getOwner()->getId(),
|
||||||
"title" => $this->getName(),
|
"title" => $this->getName(),
|
||||||
"is_favorite" => false,
|
"is_favorite" => false,
|
||||||
"player" => $this->getURL(),
|
"player" => !$fromYoutube ? $this->getURL() : $this->getVideoDriver()->getURL(),
|
||||||
"files" => [
|
"files" => !$fromYoutube ? [
|
||||||
"mp4_480" => $this->getURL()
|
"mp4_480" => $this->getURL()
|
||||||
],
|
] : NULL,
|
||||||
|
"platform" => $fromYoutube ? "youtube" : NULL,
|
||||||
"added" => 0,
|
"added" => 0,
|
||||||
"repeat" => 0,
|
"repeat" => 0,
|
||||||
"type" => "video",
|
"type" => "video",
|
||||||
|
|
Loading…
Reference in a new issue