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

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->assertUserLoggedIn();
$this->willExecuteWriteAction(); $this->willExecuteWriteAction();
@ -272,6 +272,14 @@ final class WallPresenter extends OpenVKPresenter
$this->flashFail("err", tr("failed_to_publish_post"), tr("post_is_empty_or_too_big")); $this->flashFail("err", tr("failed_to_publish_post"), tr("post_is_empty_or_too_big"));
try { try {
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 = new Post;
$post->setOwner($this->user->id); $post->setOwner($this->user->id);
$post->setWall($wall); $post->setWall($wall);
@ -281,6 +289,8 @@ final class WallPresenter extends OpenVKPresenter
$post->setFlags($flags); $post->setFlags($flags);
$post->setNsfw($this->postParam("nsfw") === "on"); $post->setNsfw($this->postParam("nsfw") === "on");
$post->save(); $post->save();
}
} catch (\LengthException $ex) { } catch (\LengthException $ex) {
$this->flashFail("err", tr("failed_to_publish_post"), tr("post_is_too_big")); $this->flashFail("err", tr("failed_to_publish_post"), tr("post_is_too_big"));
} }

View file

@ -60,8 +60,12 @@
{/if} {/if}
</div> </div>
<div class="post-content" id="{$post->getPrettyId()}"> <div class="post-content" id="{$post->getPrettyId()}">
<div class="text" id="text{$post->getPrettyId()}"> <div class="text">
{$post->getText()|noescape} <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 n:ifcontent class="attachments_b">
<div class="attachment" n:foreach="$post->getChildren() as $attachment" data-localized-nsfw-text="{_nsfw_warning}"> <div class="attachment" n:foreach="$post->getChildren() as $attachment" data-localized-nsfw-text="{_nsfw_warning}">
@ -73,6 +77,9 @@
<br/> <br/>
&nbsp;! Этот пост был размещён за взятку. &nbsp;! Этот пост был размещён за взятку.
</div> </div>
<div n:if="$post->getEditTime()" style="color:grey;">
&nbsp; ред. {$post->getEditTime()}
</div>
<div n:if="$post->isSigned()" class="post-signature"> <div n:if="$post->isSigned()" class="post-signature">
{var $actualAuthor = $post->getOwner(false)} {var $actualAuthor = $post->getOwner(false)}
<span> <span>
@ -88,6 +95,10 @@
{if isset($thisUser)} {if isset($thisUser)}
&nbsp; &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> <a n:if="!($forceNoCommentsLink ?? false) && $commentsCount == 0" href="javascript:expand_comment_textarea({$commentTextAreaId})">{_comment}</a>
<div class="like_wrap"> <div class="like_wrap">

View file

@ -5,6 +5,8 @@
{var $deac = "post_deact_silent"} {var $deac = "post_deact_silent"}
{/if} {/if}
<table border="0" style="font-size: 11px;" n:class="post, $post->isExplicit() ? post-nsfw"> <table border="0" style="font-size: 11px;" n:class="post, $post->isExplicit() ? post-nsfw">
<tbody> <tbody>
<tr> <tr>
@ -41,8 +43,14 @@
</a> </a>
</div> </div>
<div class="post-content" id="{$post->getPrettyId()}"> <div class="post-content" id="{$post->getPrettyId()}">
<div class="text" id="text{$post->getPrettyId()}"> <div class="text">
{$post->getText()|noescape} {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 n:ifcontent class="attachments_b">
<div class="attachment" n:foreach="$post->getChildren() as $attachment" data-localized-nsfw-text="{_nsfw_warning}"> <div class="attachment" n:foreach="$post->getChildren() as $attachment" data-localized-nsfw-text="{_nsfw_warning}">
@ -54,6 +62,9 @@
<br/> <br/>
&nbsp;! Этот пост был размещён за взятку. &nbsp;! Этот пост был размещён за взятку.
</div> </div>
<div n:if="$post->getEditTime()" style="color:grey;">
&nbsp; ред. {$post->getEditTime()}
</div>
<div n:if="$post->isSigned()" class="post-signature"> <div n:if="$post->isSigned()" class="post-signature">
{var $actualAuthor = $post->getOwner(false)} {var $actualAuthor = $post->getOwner(false)}
<span> <span>
@ -70,6 +81,10 @@
{var $forceNoPinLink = true} {var $forceNoPinLink = true}
{/if} {/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)} {if !($forceNoDeleteLink ?? false) && $post->canBeDeletedBy($thisUser)}
<a href="/wall{$post->getPrettyId()}/delete">{_delete}</a> &nbsp;|&nbsp; <a href="/wall{$post->getPrettyId()}/delete">{_delete}</a> &nbsp;|&nbsp;
{/if} {/if}

View file

@ -119,6 +119,8 @@ routes:
handler: "Wall->rss" handler: "Wall->rss"
- url: "/wall{num}/makePost" - url: "/wall{num}/makePost"
handler: "Wall->makePost" handler: "Wall->makePost"
- url: "/wall{num}/makePost/{num}"
handler: "Wall->makePost"
- url: "/wall{num}_{num}" - url: "/wall{num}_{num}"
handler: "Wall->post" handler: "Wall->post"
- url: "/wall{num}_{num}/like" - url: "/wall{num}_{num}/like"

View file

@ -13,8 +13,8 @@ function expand_comment_textarea(id) {
} }
function edit_post(id, wid) { function edit_post(id, wid) {
var el = document.getElementById('text'+wid+'_'+id); var el = document.getElementById(`text${id}_${wid}`);
var ed = document.getElementById('text_edit'+wid+'_'+id); var ed = document.getElementById(`text_edit${id}_${wid}`);
if (el.style.display == "none") { if (el.style.display == "none") {
el.style.display = "block"; el.style.display = "block";
ed.style.display = "none"; ed.style.display = "none";