mirror of
https://github.com/openvk/openvk
synced 2024-12-22 16:42:32 +03:00
Wall [Experimental]: Allow to embed videos in posts
This commit is contained in:
parent
a53826f46d
commit
1c341874a0
9 changed files with 62 additions and 39 deletions
|
@ -105,4 +105,18 @@ class Video extends Media
|
|||
$this->unwire();
|
||||
$this->save();
|
||||
}
|
||||
|
||||
static function fastMake(int $owner, string $description = "", array $file, bool $unlisted = true): Video
|
||||
{
|
||||
$video = new Video;
|
||||
$video->setOwner($owner);
|
||||
$video->setName("Unnamed Video.ogv");
|
||||
$video->setDescription(ovk_proc_strtr($description, 300));
|
||||
$video->setCreated(time());
|
||||
$video->setFile($file);
|
||||
$video->setUnlisted($unlisted);
|
||||
$video->save();
|
||||
|
||||
return $video;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ class Videos
|
|||
function getByUser(User $user, int $page = 1, ?int $perPage = NULL): \Traversable
|
||||
{
|
||||
$perPage = $perPage ?? OPENVK_DEFAULT_PER_PAGE;
|
||||
foreach($this->videos->where("owner", $user->getId())->where("deleted", 0)->page($page, $perPage) as $video)
|
||||
foreach($this->videos->where("owner", $user->getId())->where(["deleted" => 0, "unlisted" => 0])->page($page, $perPage) as $video)
|
||||
yield new Video($video);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace openvk\Web\Presenters;
|
||||
use openvk\Web\Models\Entities\{Post, Photo, Club, User};
|
||||
use openvk\Web\Models\Entities\{Post, Photo, Video, Club, User};
|
||||
use openvk\Web\Models\Entities\Notifications\{LikeNotification, RepostNotification, WallPostNotification};
|
||||
use openvk\Web\Models\Repositories\{Posts, Users, Clubs, Albums};
|
||||
use Chandler\Database\DatabaseConnection;
|
||||
|
@ -186,18 +186,27 @@ final class WallPresenter extends OpenVKPresenter
|
|||
if($this->postParam("force_sign") === "on")
|
||||
$flags |= 0b01000000;
|
||||
|
||||
|
||||
if($_FILES["_pic_attachment"]["error"] === UPLOAD_ERR_OK) {
|
||||
try {
|
||||
$photo = NULL;
|
||||
$video = NULL;
|
||||
if($_FILES["_pic_attachment"]["error"] === UPLOAD_ERR_OK) {
|
||||
$album = NULL;
|
||||
if($wall > 0 && $wall === $this->user->id)
|
||||
$album = (new Albums)->getUserWallAlbum($wallOwner);
|
||||
|
||||
$photo = Photo::fastMake($this->user->id, $this->postParam("text"), $_FILES["_pic_attachment"], $album);
|
||||
} catch(ISE $ex) {
|
||||
$this->flashFail("err", "Не удалось опубликовать пост", "Файл изображения повреждён, слишком велик или одна сторона изображения в разы больше другой.");
|
||||
}
|
||||
|
||||
if($_FILES["_vid_attachment"]["error"] === UPLOAD_ERR_OK) {
|
||||
$video = Video::fastMake($this->user->id, $this->postParam("text"), $_FILES["_vid_attachment"]);
|
||||
}
|
||||
} catch(ISE $ex) {
|
||||
$this->flashFail("err", "Не удалось опубликовать пост", "Файл медиаконтента повреждён или слишком велик.");
|
||||
}
|
||||
|
||||
if(empty($this->postParam("text")) && !$photo && !$video)
|
||||
$this->flashFail("err", "Не удалось опубликовать пост", "Пост пустой или слишком большой.");
|
||||
|
||||
$post = new Post;
|
||||
$post->setOwner($this->user->id);
|
||||
$post->setWall($wall);
|
||||
|
@ -206,23 +215,12 @@ final class WallPresenter extends OpenVKPresenter
|
|||
$post->setFlags($flags);
|
||||
$post->setNsfw($this->postParam("nsfw") === "on");
|
||||
$post->save();
|
||||
|
||||
if(!is_null($photo))
|
||||
$post->attach($photo);
|
||||
} elseif($this->postParam("text")) {
|
||||
try {
|
||||
$post = new Post;
|
||||
$post->setOwner($this->user->id);
|
||||
$post->setWall($wall);
|
||||
$post->setCreated(time());
|
||||
$post->setContent($this->postParam("text"));
|
||||
$post->setFlags($flags);
|
||||
$post->setNsfw($this->postParam("nsfw") === "on");
|
||||
$post->save();
|
||||
} catch(\LogicException $ex) {
|
||||
$this->flashFail("err", "Не удалось опубликовать пост", "Пост пустой или слишком большой.");
|
||||
}
|
||||
} else {
|
||||
$this->flashFail("err", "Не удалось опубликовать пост", "Пост пустой или слишком большой.");
|
||||
}
|
||||
|
||||
if(!is_null($video))
|
||||
$post->attach($video);
|
||||
|
||||
if($wall > 0 && $wall !== $this->user->identity->getId())
|
||||
(new WallPostNotification($wallOwner, $post, $this->user->identity))->emit();
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
<img class="media" src="/assets/packages/static/openvk/img/camera_200.png" alt="{_"attach_no_longer_available"}" />
|
||||
</a>
|
||||
{/if}
|
||||
{elseif $attachment instanceof \openvk\Web\Models\Entities\Video}
|
||||
<video class="media" src="{$attachment->getURL()}" controls="controls"></video>
|
||||
{elseif $attachment instanceof \openvk\Web\Models\Entities\Post}
|
||||
{php $GLOBALS["_nesAttGloCou"] = (isset($GLOBALS["_nesAttGloCou"]) ? $GLOBALS["_nesAttGloCou"] : 0) + 1}
|
||||
{if $GLOBALS["_nesAttGloCou"] > 2}
|
||||
|
|
|
@ -31,7 +31,8 @@
|
|||
<input type="checkbox" name="nsfw" /> {_"contains_nsfw"}
|
||||
</label>
|
||||
</div>
|
||||
<input type="file" name="_pic_attachment" accept="image/*" style="display:none;" />
|
||||
<input type="file" class="postFileSel" id="postFilePic" name="_pic_attachment" accept="image/*" style="display:none;" />
|
||||
<input type="file" class="postFileSel" id="postFileVid" name="_vid_attachment" accept="video/*" style="display:none;" />
|
||||
<input type="hidden" name="type" value="1" />
|
||||
<input type="hidden" name="hash" value="{$csrfToken}" />
|
||||
<br/>
|
||||
|
@ -46,6 +47,10 @@
|
|||
<img src="/assets/packages/static/openvk/img/oxygen-icons/16x16/mimetypes/application-x-egon.png" />
|
||||
{_attach_photo}
|
||||
</a>
|
||||
<a href="javascript:void(document.querySelector('input[name=_vid_attachment]').click());">
|
||||
<img src="/assets/packages/static/openvk/img/oxygen-icons/16x16/mimetypes/application-vnd.rn-realmedia.png" />
|
||||
Прикрепить видео
|
||||
</a>
|
||||
<a n:if="$graffiti ?? false" href="javascript:initGraffiti();">
|
||||
<img src="/assets/packages/static/openvk/img/oxygen-icons/16x16/actions/draw-brush.png" />
|
||||
Нарисовать граффити
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.post-nsfw .post-content img.media {
|
||||
.post-nsfw .post-content .media {
|
||||
filter: saturate(0.8) blur(15px);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
|||
position: relative;
|
||||
}
|
||||
|
||||
.post-nsfw .post-content .attachment:active img.media {
|
||||
.post-nsfw .post-content .attachment:active .media {
|
||||
filter: none;
|
||||
}
|
||||
|
||||
|
|
|
@ -513,7 +513,7 @@ h4 {
|
|||
width: 102%;
|
||||
}
|
||||
|
||||
.post-content img.media {
|
||||
.post-content .media {
|
||||
max-width: 100%;
|
||||
image-rendering: -webkit-optimize-contrast;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,9 @@ function trim(string) {
|
|||
|
||||
function handleUpload() {
|
||||
console.warn("блять...");
|
||||
|
||||
u(".postFileSel").not("#" + this.id).each(input => input.value = null);
|
||||
|
||||
var indicator = u(".post-upload");
|
||||
var file = this.files[0];
|
||||
if(typeof file === "undefined") {
|
||||
|
@ -108,4 +111,4 @@ u("#wall-post-input").on("input", function(e) {
|
|||
// textArea.style.height = (newHeight > originalHeight ? (newHeight + boost) : originalHeight) + "px";
|
||||
});
|
||||
|
||||
u("input[name=_pic_attachment]").on("change", handleUpload);
|
||||
u(".postFileSel").on("change", handleUpload);
|
||||
|
|
1
install/sqls/00001-unlisted-videos.sql
Normal file
1
install/sqls/00001-unlisted-videos.sql
Normal file
|
@ -0,0 +1 @@
|
|||
ALTER TABLE `videos` ADD `unlisted` BOOLEAN NOT NULL DEFAULT FALSE AFTER `link`, ADD INDEX (`unlisted`);
|
Loading…
Reference in a new issue