diff --git a/Web/Models/Entities/Video.php b/Web/Models/Entities/Video.php index ccb63f13..7b35153f 100644 --- a/Web/Models/Entities/Video.php +++ b/Web/Models/Entities/Video.php @@ -93,10 +93,10 @@ class Video extends Media function isDeleted(): bool { - if ($this->getRecord()->deleted == 1) - return TRUE; - else - return FALSE; + if ($this->getRecord()->deleted == 1) + return TRUE; + else + return FALSE; } function deleteVideo(): void @@ -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; + } } diff --git a/Web/Models/Repositories/Videos.php b/Web/Models/Repositories/Videos.php index 8d99dd84..2bb459d8 100644 --- a/Web/Models/Repositories/Videos.php +++ b/Web/Models/Repositories/Videos.php @@ -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); } diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index 49470646..05a844b4 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -1,6 +1,6 @@ postParam("force_sign") === "on") $flags |= 0b01000000; - - if($_FILES["_pic_attachment"]["error"] === UPLOAD_ERR_OK) { - try { + 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", "Не удалось опубликовать пост", "Файл изображения повреждён, слишком велик или одна сторона изображения в разы больше другой."); } - $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(); - $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", "Не удалось опубликовать пост", "Пост пустой или слишком большой."); + if($_FILES["_vid_attachment"]["error"] === UPLOAD_ERR_OK) { + $video = Video::fastMake($this->user->id, $this->postParam("text"), $_FILES["_vid_attachment"]); } - } else { - $this->flashFail("err", "Не удалось опубликовать пост", "Пост пустой или слишком большой."); + } 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); + $post->setCreated(time()); + $post->setContent($this->postParam("text")); + $post->setFlags($flags); + $post->setNsfw($this->postParam("nsfw") === "on"); + $post->save(); + + if(!is_null($photo)) + $post->attach($photo); + + if(!is_null($video)) + $post->attach($video); + if($wall > 0 && $wall !== $this->user->identity->getId()) (new WallPostNotification($wallOwner, $post, $this->user->identity))->emit(); diff --git a/Web/Presenters/templates/components/attachment.xml b/Web/Presenters/templates/components/attachment.xml index 4621a6f9..35f1901a 100644 --- a/Web/Presenters/templates/components/attachment.xml +++ b/Web/Presenters/templates/components/attachment.xml @@ -8,6 +8,8 @@ {_ {/if} +{elseif $attachment instanceof \openvk\Web\Models\Entities\Video} + {elseif $attachment instanceof \openvk\Web\Models\Entities\Post} {php $GLOBALS["_nesAttGloCou"] = (isset($GLOBALS["_nesAttGloCou"]) ? $GLOBALS["_nesAttGloCou"] : 0) + 1} {if $GLOBALS["_nesAttGloCou"] > 2} diff --git a/Web/Presenters/templates/components/textArea.xml b/Web/Presenters/templates/components/textArea.xml index 6f55b579..89b564da 100644 --- a/Web/Presenters/templates/components/textArea.xml +++ b/Web/Presenters/templates/components/textArea.xml @@ -31,7 +31,8 @@ {_"contains_nsfw"} - + +
@@ -46,6 +47,10 @@ {_attach_photo} + + + Прикрепить видео + Нарисовать граффити diff --git a/Web/static/css/nsfw-posts.css b/Web/static/css/nsfw-posts.css index c0bd27be..ed9841ca 100644 --- a/Web/static/css/nsfw-posts.css +++ b/Web/static/css/nsfw-posts.css @@ -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; } diff --git a/Web/static/css/style.css b/Web/static/css/style.css index e3126c3b..b9e90c3e 100644 --- a/Web/static/css/style.css +++ b/Web/static/css/style.css @@ -513,7 +513,7 @@ h4 { width: 102%; } -.post-content img.media { +.post-content .media { max-width: 100%; image-rendering: -webkit-optimize-contrast; } diff --git a/Web/static/js/al_wall.js b/Web/static/js/al_wall.js index 9e70ea77..552d9c92 100644 --- a/Web/static/js/al_wall.js +++ b/Web/static/js/al_wall.js @@ -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); diff --git a/install/sqls/00001-unlisted-videos.sql b/install/sqls/00001-unlisted-videos.sql new file mode 100644 index 00000000..0eb57d62 --- /dev/null +++ b/install/sqls/00001-unlisted-videos.sql @@ -0,0 +1 @@ +ALTER TABLE `videos` ADD `unlisted` BOOLEAN NOT NULL DEFAULT FALSE AFTER `link`, ADD INDEX (`unlisted`); \ No newline at end of file