diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index 5b6b8d9f..f7c6a9b1 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -794,6 +794,13 @@ final class Wall extends VKAPIRequestHandler foreach($comment->getChildren() as $attachment) { if($attachment instanceof \openvk\Web\Models\Entities\Photo) { $attachments[] = $this->getApiPhoto($attachment); + } elseif($attachment instanceof \openvk\Web\Models\Entities\Video) { + $attachments[] = $attachment->getApiStructure(); + } elseif($attachment instanceof \openvk\Web\Models\Entities\Note) { + $attachments[] = [ + 'type' => 'note', + 'note' => $attachment->toVkApiStruct() + ]; } elseif($attachment instanceof \openvk\Web\Models\Entities\Audio) { $attachments[] = [ "type" => "audio", @@ -942,10 +949,23 @@ final class Wall extends VKAPIRequestHandler } } - function edit(int $owner_id, int $post_id, string $message = "", string $attachments = "", string $copyright = NULL) { + function edit(int $owner_id, int $post_id, string $message = "", string $attachments = "", string $copyright = NULL, int $explicit = -1, int $from_group = 0, int $signed = 0) { $this->requireUser(); $this->willExecuteWriteAction(); + $parsed_attachments = parseAttachments($attachments, ['photo', 'video', 'note', 'audio']); + $final_attachments = []; + foreach($parsed_attachments as $attachment) { + if($attachment && !$attachment->isDeleted() && $attachment->canBeViewedBy($this->getUser()) && + !(method_exists($attachment, 'getVoters') && $attachment->getOwner()->getId() != $this->getUser()->getId())) { + $final_attachments[] = $attachment; + } + } + + if(empty($message) && sizeof($final_attachments) < 1) { + $this->fail(-66, "Post will be empty, don't saving."); + } + $post = (new PostsRepo)->getPostById($owner_id, $post_id); if(!$post || $post->isDeleted()) @@ -954,28 +974,35 @@ final class Wall extends VKAPIRequestHandler if(!$post->canBeEditedBy($this->getUser())) $this->fail(7, "Access to editing denied"); - if(!empty($message)) + if(!empty($message) || (empty($message) && sizeof($final_attachments) > 0)) $post->setContent($message); $post->setEdited(time()); if(!is_null($copyright) && !empty($copyright)) { - try { - $post->setSource($copyright); - } catch(\Throwable) {} - } - - $post->save(true); - - $parsed_attachments = parseAttachments($attachments, ['photo', 'video', 'note', 'audio']); - $final_attachments = []; - foreach($parsed_attachments as $attachment) { - if($attachment && !$attachment->isDeleted() && $attachment->canBeViewedBy($this->getUser()) && - !(method_exists($attachment, 'getVoters') && $attachment->getOwner()->getId() != $this->getUser()->getId())) { - $final_attachments[] = $attachment; + if($copyright == 'remove') { + $post->resetSource(); + } else { + try { + $post->setSource($copyright); + } catch(\Throwable) {} } } - if(sizeof($final_attachments) > 0) { + if($explicit != -1) { + $post->setNsfw($explicit == 1); + } + + $wallOwner = ($owner_id > 0 ? (new UsersRepo)->get($owner_id) : (new ClubsRepo)->get($owner_id * -1)); + $flags = 0; + if($from_group == 1 && $wallOwner instanceof Club && $wallOwner->canBeModifiedBy($this->getUser())) + $flags |= 0b10000000; + /*if($signed == 1) + $flags |= 0b01000000;*/ + + $post->setFlags($flags); + $post->save(true); + + if($attachments == 'remove' || sizeof($final_attachments) > 0) { $post->unwire(); foreach($final_attachments as $attachment) { $post->attach($attachment); @@ -990,6 +1017,14 @@ final class Wall extends VKAPIRequestHandler $this->willExecuteWriteAction(); $comment = (new CommentsRepo)->get($comment_id); + $parsed_attachments = parseAttachments($attachments, ['photo', 'video', 'note', 'audio']); + $final_attachments = []; + foreach($parsed_attachments as $attachment) { + if($attachment && !$attachment->isDeleted() && $attachment->canBeViewedBy($this->getUser()) && + !(method_exists($attachment, 'getVoters') && $attachment->getOwner()->getId() != $this->getUser()->getId())) { + $final_attachments[] = $attachment; + } + } if(empty($message) && empty($attachments)) $this->fail(100, "Required parameter 'message' missing."); @@ -1000,21 +1035,12 @@ final class Wall extends VKAPIRequestHandler if(!$comment->canBeEditedBy($this->getUser())) $this->fail(15, "Access to editing comment denied"); - if(!empty($message)) + if(!empty($message) || (empty($message) && sizeof($final_attachments) > 0)) $comment->setContent($message); $comment->setEdited(time()); $comment->save(true); - $parsed_attachments = parseAttachments($attachments, ['photo', 'video', 'note', 'audio']); - $final_attachments = []; - foreach($parsed_attachments as $attachment) { - if($attachment && !$attachment->isDeleted() && $attachment->canBeViewedBy($this->getUser()) && - !(method_exists($attachment, 'getVoters') && $attachment->getOwner()->getId() != $this->getUser()->getId())) { - $final_attachments[] = $attachment; - } - } - if(sizeof($final_attachments) > 0) { $comment->unwire(); foreach($final_attachments as $attachment) { diff --git a/Web/Models/Entities/Post.php b/Web/Models/Entities/Post.php index 5d5469d4..6aa09889 100644 --- a/Web/Models/Entities/Post.php +++ b/Web/Models/Entities/Post.php @@ -103,6 +103,11 @@ class Post extends Postable $this->stateChanges("source", $source); } + function resetSource() + { + $this->stateChanges("source", NULL); + } + function getVkApiCopyright(): object { return (object)[ diff --git a/Web/Presenters/InternalAPIPresenter.php b/Web/Presenters/InternalAPIPresenter.php index 901d8d0b..efca2807 100644 --- a/Web/Presenters/InternalAPIPresenter.php +++ b/Web/Presenters/InternalAPIPresenter.php @@ -133,4 +133,33 @@ final class InternalAPIPresenter extends OpenVKPresenter ]); } } + + function renderGetPostTemplate(int $owner_id, int $post_id) { + if($_SERVER["REQUEST_METHOD"] !== "POST") { + header("HTTP/1.1 405 Method Not Allowed"); + exit("ты не по адресу"); + } + + $type = $this->queryParam("type", false); + if($type == "post") { + $post = (new Posts)->getPostById($owner_id, $post_id, true); + } else { + $post = (new Comments)->get($post_id); + } + + if(!$post || !$post->canBeEditedBy($this->user->identity)) { + exit(''); + } + + if($type == 'post') { + $this->template->_template = 'components/post.xml'; + $this->template->post = $post; + $this->template->commentSection = false; + } elseif($type == 'comment') { + $this->template->_template = 'components/comment.xml'; + $this->template->comment = $post; + } else { + exit(''); + } + } } diff --git a/Web/Presenters/templates/components/attachment.xml b/Web/Presenters/templates/components/attachment.xml index 19d63a6b..59925f27 100644 --- a/Web/Presenters/templates/components/attachment.xml +++ b/Web/Presenters/templates/components/attachment.xml @@ -44,12 +44,14 @@ {elseif $attachment instanceof \openvk\Web\Models\Entities\Poll} {presenter "openvk!Poll->view", $attachment->getId()} {elseif $attachment instanceof \openvk\Web\Models\Entities\Note} -