mirror of
https://github.com/openvk/openvk
synced 2024-11-11 01:19:53 +03:00
[WIP] Comments: Allow photo uploads in comments
This commit is contained in:
parent
2e15de74fc
commit
4ab9d67718
4 changed files with 35 additions and 10 deletions
|
@ -41,4 +41,19 @@ class Photo extends Media
|
||||||
|
|
||||||
DB::i()->getContext()->table("album_relations")->where("media", $this->getRecord()->id)->delete();
|
DB::i()->getContext()->table("album_relations")->where("media", $this->getRecord()->id)->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function fastMake(int $owner, string $description = "", array $file, ?Album $album = NULL): Photo
|
||||||
|
{
|
||||||
|
$photo = new static;
|
||||||
|
$photo->setOwner($owner);
|
||||||
|
$photo->setDescription(iconv_substr($description, 0, 36) . "...");
|
||||||
|
$photo->setCreated(time());
|
||||||
|
$photo->setFile($file);
|
||||||
|
$photo->save();
|
||||||
|
|
||||||
|
if(!is_null($album))
|
||||||
|
$album->addPhoto($photo);
|
||||||
|
|
||||||
|
return $photo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php declare(strict_types=1);
|
<?php declare(strict_types=1);
|
||||||
namespace openvk\Web\Presenters;
|
namespace openvk\Web\Presenters;
|
||||||
use openvk\Web\Models\Entities\{Comment, User};
|
use openvk\Web\Models\Entities\{Comment, Photo, User};
|
||||||
use openvk\Web\Models\Entities\Notifications\CommentNotification;
|
use openvk\Web\Models\Entities\Notifications\CommentNotification;
|
||||||
use openvk\Web\Models\Repositories\Comments;
|
use openvk\Web\Models\Repositories\Comments;
|
||||||
|
|
||||||
|
@ -46,6 +46,15 @@ final class CommentPresenter extends OpenVKPresenter
|
||||||
$comment->setContent($this->postParam("text"));
|
$comment->setContent($this->postParam("text"));
|
||||||
$comment->setCreated(time());
|
$comment->setCreated(time());
|
||||||
$comment->save();
|
$comment->save();
|
||||||
|
|
||||||
|
if($_FILES["_pic_attachment"]["error"] === UPLOAD_ERR_OK) {
|
||||||
|
try {
|
||||||
|
$photo = Photo::fastMake($this->user->id, $this->postParam("text"), $_FILES["_pic_attachment"]);
|
||||||
|
$comment->attach($photo);
|
||||||
|
} catch(ISE $ex) {
|
||||||
|
$this->flashFail("err", "Не удалось опубликовать пост", "Файл изображения повреждён, слишком велик или одна сторона изображения в разы больше другой.");
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch(\LogicException $ex) {
|
} catch(\LogicException $ex) {
|
||||||
$this->flashFail("err", "Не удалось опубликовать комментарий", "Нельзя опубликовать пустой комментарий.");
|
$this->flashFail("err", "Не удалось опубликовать комментарий", "Нельзя опубликовать пустой комментарий.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,16 +189,11 @@ final class WallPresenter extends OpenVKPresenter
|
||||||
|
|
||||||
if($_FILES["_pic_attachment"]["error"] === UPLOAD_ERR_OK) {
|
if($_FILES["_pic_attachment"]["error"] === UPLOAD_ERR_OK) {
|
||||||
try {
|
try {
|
||||||
$photo = new Photo;
|
$album = NULL;
|
||||||
$photo->setOwner($this->user->id);
|
if($wall > 0 && $wall === $this->user->id)
|
||||||
$photo->setDescription(iconv_substr($this->postParam("text"), 0, 36) . "...");
|
$album = (new Albums)->getUserWallAlbum($wallOwner);
|
||||||
$photo->setCreated(time());
|
|
||||||
$photo->setFile($_FILES["_pic_attachment"]);
|
|
||||||
$photo->save();
|
|
||||||
|
|
||||||
if($wall > 0 && $wall === $this->user->id) {
|
$photo = Photo::fastMake($this->user->id, $this->postParam("text"), $_FILES["_pic_attachment"], $album);
|
||||||
(new Albums)->getUserWallAlbum($wallOwner)->addPhoto($photo);
|
|
||||||
}
|
|
||||||
} catch(ISE $ex) {
|
} catch(ISE $ex) {
|
||||||
$this->flashFail("err", "Не удалось опубликовать пост", "Файл изображения повреждён, слишком велик или одна сторона изображения в разы больше другой.");
|
$this->flashFail("err", "Не удалось опубликовать пост", "Файл изображения повреждён, слишком велик или одна сторона изображения в разы больше другой.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,12 @@
|
||||||
<div class="post-content" id="{$comment->getId()}">
|
<div class="post-content" id="{$comment->getId()}">
|
||||||
<div class="text" id="text{$comment->getId()}">
|
<div class="text" id="text{$comment->getId()}">
|
||||||
{$comment->getText()|noescape}
|
{$comment->getText()|noescape}
|
||||||
|
|
||||||
|
<div n:ifcontent class="attachments_b">
|
||||||
|
<div class="attachment" n:foreach="$comment->getChildren() as $attachment" data-localized-nsfw-text="{_nsfw_warning}">
|
||||||
|
{include "attachment.xml", attachment => $attachment}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div n:if="isset($thisUser) &&! ($compact ?? false)" class="post-menu">
|
<div n:if="isset($thisUser) &&! ($compact ?? false)" class="post-menu">
|
||||||
{var canDelete = $comment->getOwner()->getId() == $thisUser->getId()}
|
{var canDelete = $comment->getOwner()->getId() == $thisUser->getId()}
|
||||||
|
|
Loading…
Reference in a new issue