Перенос ветки posts-edit (#958)

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

* Log posts changes

* Fixes

* Features

* Совместимость с логами
This commit is contained in:
n1rwana 2023-08-21 12:45:55 +03:00 committed by GitHub
parent ee2e5e8d1c
commit 37fc460b25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 69 additions and 22 deletions

View file

@ -17,7 +17,7 @@ final class WallPresenter extends OpenVKPresenter
function __construct(Posts $posts) function __construct(Posts $posts)
{ {
$this->posts = $posts; $this->posts = $posts;
parent::__construct(); parent::__construct();
} }
@ -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();
@ -298,17 +298,28 @@ final class WallPresenter extends OpenVKPresenter
if(empty($this->postParam("text")) && !$photo && !$video && !$poll && !$note) if(empty($this->postParam("text")) && !$photo && !$video && !$poll && !$note)
$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 {
$post = new Post; if ($editTarget) {
$post->setOwner($this->user->id); $post = $this->posts->getPostById($this->user->id, $editTarget);
$post->setWall($wall);
$post->setCreated(time()); $post->setEdited(time());
$post->setContent($this->postParam("text")); $post->setContent($this->postParam("text"));
$post->setAnonymous($anon); $post->setFlags($flags);
$post->setFlags($flags); $post->setNsfw($this->postParam("nsfw") === "on");
$post->setNsfw($this->postParam("nsfw") === "on"); $post->save();
$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) { } 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

@ -34,6 +34,14 @@
{/if} {/if}
<a n:if="$canDelete ?? false" class="profile_link" style="display:block;width:96%;" href="/wall{$post->getPrettyId()}/delete">{_delete}</a> <a n:if="$canDelete ?? false" class="profile_link" style="display:block;width:96%;" href="/wall{$post->getPrettyId()}/delete">{_delete}</a>
<a
n:if="$thisUser->getChandlerUser()->can('access')->model('admin')->whichBelongsTo(NULL) AND $post->getEditTime()"
style="display:block;width:96%;"
class="profile_link"
href="/admin/logs?type=1&obj_type=Post&obj_id={$post->getId()}"
>
История изменений
</a>
<a n:if="$canReport ?? false" class="profile_link" style="display:block;width:96%;" href="javascript:reportPost()">{_report}</a> <a n:if="$canReport ?? false" class="profile_link" style="display:block;width:96%;" href="javascript:reportPost()">{_report}</a>
</div> </div>
<script n:if="$canReport ?? false"> <script n:if="$canReport ?? false">

View file

@ -64,9 +64,13 @@
{/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()}", value => $post->getText()}
</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}">
{include "../attachment.xml", attachment => $attachment} {include "../attachment.xml", attachment => $attachment}
@ -77,6 +81,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>
@ -94,7 +101,11 @@
</a> </a>
{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

@ -7,6 +7,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>
@ -58,9 +60,15 @@
</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()}", value => $post->getText()}
</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}">
{include "../attachment.xml", attachment => $attachment} {include "../attachment.xml", attachment => $attachment}
@ -71,6 +79,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>
@ -87,6 +98,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

@ -3,7 +3,7 @@
<div id="write" style="padding: 5px 0;" onfocusin="expand_wall_textarea({$textAreaId});"> <div id="write" style="padding: 5px 0;" onfocusin="expand_wall_textarea({$textAreaId});">
<form action="{$route}" method="post" enctype="multipart/form-data" style="margin:0;"> <form action="{$route}" method="post" enctype="multipart/form-data" style="margin:0;">
<textarea id="wall-post-input{$textAreaId}" placeholder="{_write}" name="text" style="width: 100%;resize: none;" class="small-textarea"></textarea> <textarea id="wall-post-input{$textAreaId}" placeholder="{_write}" name="text" style="width: 100%;resize: none;" class="small-textarea">{$value|noescape}</textarea>
<div> <div>
<!-- padding to fix <br/> bug --> <!-- padding to fix <br/> bug -->
</div> </div>

View file

@ -129,6 +129,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

@ -14,8 +14,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";