Редактирование постов

This commit is contained in:
n1rwana 2022-08-28 04:22:11 +03:00
parent 4891030ed0
commit 504cedfb1f
5 changed files with 59 additions and 21 deletions

View file

@ -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"));
}

View file

@ -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/>
&nbsp;! Этот пост был размещён за взятку.
</div>
<div n:if="$post->getEditTime()" style="color:grey;">
&nbsp; ред. {$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)}
&nbsp;
{if !($forceNoEditLink ?? false) && $post->canBePinnedBy($thisUser)}
<a onClick="edit_post({$author->getId()}, {$post->getVirtualId()})">Редактировать</a> &nbsp;|&nbsp;
{/if}
<a n:if="!($forceNoCommentsLink ?? false) && $commentsCount == 0" href="javascript:expand_comment_textarea({$commentTextAreaId})">{_comment}</a>
<div class="like_wrap">

View file

@ -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/>
&nbsp;! Этот пост был размещён за взятку.
</div>
<div n:if="$post->getEditTime()" style="color:grey;">
&nbsp; ред. {$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> &nbsp;|&nbsp;
{/if}
{if !($forceNoDeleteLink ?? false) && $post->canBeDeletedBy($thisUser)}
<a href="/wall{$post->getPrettyId()}/delete">{_delete}</a> &nbsp;|&nbsp;
{/if}

View file

@ -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"

View file

@ -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);
}
})
})