mirror of
https://github.com/openvk/openvk
synced 2024-11-11 01:19:53 +03:00
parent
4ab9d67718
commit
129d415877
4 changed files with 37 additions and 20 deletions
|
@ -38,27 +38,29 @@ final class CommentPresenter extends OpenVKPresenter
|
||||||
$entity = $repo->get($eId);
|
$entity = $repo->get($eId);
|
||||||
if(!$entity) $this->notFound();
|
if(!$entity) $this->notFound();
|
||||||
|
|
||||||
try {
|
$photo = NULL;
|
||||||
$comment = new Comment;
|
if($_FILES["_pic_attachment"]["error"] === UPLOAD_ERR_OK) {
|
||||||
$comment->setOwner($this->user->id);
|
try {
|
||||||
$comment->setModel(get_class($entity));
|
$photo = Photo::fastMake($this->user->id, $this->postParam("text"), $_FILES["_pic_attachment"]);
|
||||||
$comment->setTarget($entity->getId());
|
} catch(ISE $ex) {
|
||||||
$comment->setContent($this->postParam("text"));
|
$this->flashFail("err", "Не удалось опубликовать пост", "Файл изображения повреждён, слишком велик или одна сторона изображения в разы больше другой.");
|
||||||
$comment->setCreated(time());
|
|
||||||
$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) {
|
|
||||||
$this->flashFail("err", "Не удалось опубликовать комментарий", "Нельзя опубликовать пустой комментарий.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(empty($this->postParam("text")) && is_null($photo))
|
||||||
|
$this->flashFail("err", "Не удалось опубликовать комментарий", "Нельзя опубликовать пустой комментарий.");
|
||||||
|
|
||||||
|
$comment = new Comment;
|
||||||
|
$comment->setOwner($this->user->id);
|
||||||
|
$comment->setModel(get_class($entity));
|
||||||
|
$comment->setTarget($entity->getId());
|
||||||
|
$comment->setContent($this->postParam("text"));
|
||||||
|
$comment->setCreated(time());
|
||||||
|
$comment->save();
|
||||||
|
|
||||||
|
if(!is_null($photo))
|
||||||
|
$comment->attach($photo);
|
||||||
|
|
||||||
if($entity->getOwner()->getId() !== $this->user->identity->getId())
|
if($entity->getOwner()->getId() !== $this->user->identity->getId())
|
||||||
if(($owner = $entity->getOwner()) instanceof User)
|
if(($owner = $entity->getOwner()) instanceof User)
|
||||||
(new CommentNotification($owner, $comment, $entity, $this->user->identity))->emit();
|
(new CommentNotification($owner, $comment, $entity, $this->user->identity))->emit();
|
||||||
|
|
|
@ -34,3 +34,7 @@
|
||||||
<a class="profile_link" style="display:block;width:96%;" href="/report.pl/{$post->getId()}?type=post">{_report}</a>
|
<a class="profile_link" style="display:block;width:96%;" href="/report.pl/{$post->getId()}?type=post">{_report}</a>
|
||||||
</div>
|
</div>
|
||||||
{/block}
|
{/block}
|
||||||
|
|
||||||
|
{block bodyScripts}
|
||||||
|
{script "js/al_comments.js"}
|
||||||
|
{/block}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{var author = $comment->getOwner()}
|
{var author = $comment->getOwner()}
|
||||||
|
|
||||||
<a name="cid={$comment->getId()}"></a>
|
<a name="cid={$comment->getId()}"></a>
|
||||||
<table border="0" style="font-size: 11px;" class="post">
|
<table border="0" style="font-size: 11px;" class="post" data-comment-id="{$comment->getId()}" data-owner-id="{$author->getId()}">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td width="54" valign="top">
|
<td width="54" valign="top">
|
||||||
|
@ -30,9 +30,11 @@
|
||||||
{var canDelete = $comment->getOwner()->getId() == $thisUser->getId()}
|
{var canDelete = $comment->getOwner()->getId() == $thisUser->getId()}
|
||||||
{var canDelete = $canDelete || $comment->getTarget()->getOwner()->getId() == $thisUser->getId()}
|
{var canDelete = $canDelete || $comment->getTarget()->getOwner()->getId() == $thisUser->getId()}
|
||||||
{if $canDelete}
|
{if $canDelete}
|
||||||
<a href="/comment{$comment->getId()}/delete">{_"delete"}</a>
|
<a href="/comment{$comment->getId()}/delete">{_"delete"}</a> |
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
<a class="comment-reply">Ответить</a>
|
||||||
|
|
||||||
<div style="float: right; font-size: .7rem;">
|
<div style="float: right; font-size: .7rem;">
|
||||||
<a href="/comment{$comment->getId()}/like?hash={rawurlencode($csrfToken)}">
|
<a href="/comment{$comment->getId()}/like?hash={rawurlencode($csrfToken)}">
|
||||||
<div class="heart" style="{if $comment->hasLikeFrom($thisUser)}opacity: 1;{else}opacity: 0.4;{/if}"></div>
|
<div class="heart" style="{if $comment->hasLikeFrom($thisUser)}opacity: 1;{else}opacity: 0.4;{/if}"></div>
|
||||||
|
|
9
Web/static/js/al_comments.js
Normal file
9
Web/static/js/al_comments.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
u(".comment-reply").on("click", function(e) {
|
||||||
|
let inputbox = u("#write textarea");
|
||||||
|
let comment = u(e.target).closest(".post");
|
||||||
|
let authorId = comment.data("owner-id");
|
||||||
|
let authorNm = u(".post-author > a > b", comment.first()).text().trim();
|
||||||
|
|
||||||
|
inputbox.text("[id" + authorId + "|" + authorNm + "], ");
|
||||||
|
inputbox.trigger("focusin");
|
||||||
|
});
|
Loading…
Reference in a new issue