mirror of
https://github.com/openvk/openvk
synced 2025-03-14 21:45:22 +03:00
Редактирование постов
This commit is contained in:
parent
4891030ed0
commit
504cedfb1f
5 changed files with 59 additions and 21 deletions
|
@ -207,7 +207,7 @@ final class WallPresenter extends OpenVKPresenter
|
|||
];
|
||||
}
|
||||
|
||||
function renderMakePost(int $wall): void
|
||||
function renderMakePost(int $wall, ?int $editTarget = 0): void
|
||||
{
|
||||
$this->assertUserLoggedIn();
|
||||
$this->willExecuteWriteAction();
|
||||
|
@ -270,17 +270,27 @@ final class WallPresenter extends OpenVKPresenter
|
|||
|
||||
if(empty($this->postParam("text")) && !$photo && !$video)
|
||||
$this->flashFail("err", tr("failed_to_publish_post"), tr("post_is_empty_or_too_big"));
|
||||
|
||||
|
||||
try {
|
||||
$post = new Post;
|
||||
$post->setOwner($this->user->id);
|
||||
$post->setWall($wall);
|
||||
$post->setCreated(time());
|
||||
$post->setContent($this->postParam("text"));
|
||||
$post->setAnonymous($anon);
|
||||
$post->setFlags($flags);
|
||||
$post->setNsfw($this->postParam("nsfw") === "on");
|
||||
$post->save();
|
||||
if ($editTarget) {
|
||||
$post = $this->posts->getPostById($this->user->id, $editTarget);
|
||||
$post->setEdited(time());
|
||||
$post->setContent($this->postParam("text"));
|
||||
$post->setFlags($flags);
|
||||
$post->setNsfw($this->postParam("nsfw") === "on");
|
||||
$post->save();
|
||||
} else {
|
||||
$post = new Post;
|
||||
$post->setOwner($this->user->id);
|
||||
$post->setWall($wall);
|
||||
$post->setCreated(time());
|
||||
$post->setContent($this->postParam("text"));
|
||||
$post->setAnonymous($anon);
|
||||
$post->setFlags($flags);
|
||||
$post->setNsfw($this->postParam("nsfw") === "on");
|
||||
$post->save();
|
||||
}
|
||||
|
||||
} catch (\LengthException $ex) {
|
||||
$this->flashFail("err", tr("failed_to_publish_post"), tr("post_is_too_big"));
|
||||
}
|
||||
|
|
|
@ -60,9 +60,13 @@
|
|||
{/if}
|
||||
</div>
|
||||
<div class="post-content" id="{$post->getPrettyId()}">
|
||||
<div class="text" id="text{$post->getPrettyId()}">
|
||||
{$post->getText()|noescape}
|
||||
|
||||
<div class="text">
|
||||
<span id="text{$post->getPrettyId()}">{$post->getText()|noescape}</span>
|
||||
|
||||
<div class="edit" id="text_edit{$post->getPrettyId()}" style="display: none;">
|
||||
{include "../textArea.xml", route => "/wall$owner/makePost/{$post->getVirtualId()}"}
|
||||
</div>
|
||||
|
||||
<div n:ifcontent class="attachments_b">
|
||||
<div class="attachment" n:foreach="$post->getChildren() as $attachment" data-localized-nsfw-text="{_nsfw_warning}">
|
||||
{include "../attachment.xml", attachment => $attachment}
|
||||
|
@ -73,6 +77,9 @@
|
|||
<br/>
|
||||
! Этот пост был размещён за взятку.
|
||||
</div>
|
||||
<div n:if="$post->getEditTime()" style="color:grey;">
|
||||
ред. {$post->getEditTime()}
|
||||
</div>
|
||||
<div n:if="$post->isSigned()" class="post-signature">
|
||||
{var $actualAuthor = $post->getOwner(false)}
|
||||
<span>
|
||||
|
@ -87,7 +94,11 @@
|
|||
<a href="/wall{$post->getPrettyId()}" class="date">{$post->getPublicationTime()}</a>
|
||||
{if isset($thisUser)}
|
||||
|
||||
|
||||
|
||||
{if !($forceNoEditLink ?? false) && $post->canBePinnedBy($thisUser)}
|
||||
<a onClick="edit_post({$author->getId()}, {$post->getVirtualId()})">Редактировать</a> |
|
||||
{/if}
|
||||
|
||||
<a n:if="!($forceNoCommentsLink ?? false) && $commentsCount == 0" href="javascript:expand_comment_textarea({$commentTextAreaId})">{_comment}</a>
|
||||
|
||||
<div class="like_wrap">
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
{var $deac = "post_deact_silent"}
|
||||
{/if}
|
||||
|
||||
|
||||
|
||||
<table border="0" style="font-size: 11px;" n:class="post, $post->isExplicit() ? post-nsfw">
|
||||
<tbody>
|
||||
<tr>
|
||||
|
@ -41,9 +43,15 @@
|
|||
</a>
|
||||
</div>
|
||||
<div class="post-content" id="{$post->getPrettyId()}">
|
||||
<div class="text" id="text{$post->getPrettyId()}">
|
||||
{$post->getText()|noescape}
|
||||
|
||||
<div class="text">
|
||||
{var $owner = $author->getId()}
|
||||
|
||||
<span id="text{$post->getPrettyId()}">{$post->getText()|noescape}</span>
|
||||
|
||||
<div class="edit" id="text_edit{$post->getPrettyId()}" style="display: none;">
|
||||
{include "../textArea.xml", route => "/wall$owner/makePost/{$post->getVirtualId()}"}
|
||||
</div>
|
||||
|
||||
<div n:ifcontent class="attachments_b">
|
||||
<div class="attachment" n:foreach="$post->getChildren() as $attachment" data-localized-nsfw-text="{_nsfw_warning}">
|
||||
{include "../attachment.xml", attachment => $attachment}
|
||||
|
@ -54,6 +62,9 @@
|
|||
<br/>
|
||||
! Этот пост был размещён за взятку.
|
||||
</div>
|
||||
<div n:if="$post->getEditTime()" style="color:grey;">
|
||||
ред. {$post->getEditTime()}
|
||||
</div>
|
||||
<div n:if="$post->isSigned()" class="post-signature">
|
||||
{var $actualAuthor = $post->getOwner(false)}
|
||||
<span>
|
||||
|
@ -70,6 +81,10 @@
|
|||
{var $forceNoPinLink = true}
|
||||
{/if}
|
||||
|
||||
{if !($forceNoEditLink ?? false) && $post->canBePinnedBy($thisUser)}
|
||||
<a onClick="edit_post({$author->getId()}, {$post->getVirtualId()})">Редактировать</a> |
|
||||
{/if}
|
||||
|
||||
{if !($forceNoDeleteLink ?? false) && $post->canBeDeletedBy($thisUser)}
|
||||
<a href="/wall{$post->getPrettyId()}/delete">{_delete}</a> |
|
||||
{/if}
|
||||
|
|
|
@ -119,6 +119,8 @@ routes:
|
|||
handler: "Wall->rss"
|
||||
- url: "/wall{num}/makePost"
|
||||
handler: "Wall->makePost"
|
||||
- url: "/wall{num}/makePost/{num}"
|
||||
handler: "Wall->makePost"
|
||||
- url: "/wall{num}_{num}"
|
||||
handler: "Wall->post"
|
||||
- url: "/wall{num}_{num}/like"
|
||||
|
|
|
@ -13,8 +13,8 @@ function expand_comment_textarea(id) {
|
|||
}
|
||||
|
||||
function edit_post(id, wid) {
|
||||
var el = document.getElementById('text'+wid+'_'+id);
|
||||
var ed = document.getElementById('text_edit'+wid+'_'+id);
|
||||
var el = document.getElementById(`text${id}_${wid}`);
|
||||
var ed = document.getElementById(`text_edit${id}_${wid}`);
|
||||
if (el.style.display == "none") {
|
||||
el.style.display = "block";
|
||||
ed.style.display = "none";
|
||||
|
@ -438,4 +438,4 @@ $(document).on("scroll", () => {
|
|||
$(".floating_sidebar")[0].classList.remove("hide_anim");
|
||||
}, 250);
|
||||
}
|
||||
})
|
||||
})
|
Loading…
Reference in a new issue