diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index a305fde6..a68e0702 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -176,6 +176,12 @@ final class Wall extends VKAPIRequestHandler "count" => $post->getCommentsCount(), "can_post" => 1 ], + "copyright" => !is_null($post->getSource(false)) ? (object)[ + "id" => 0, + "link" => $post->getSource(false), + "name" => "none", + "type" => "link" + ] : NULL, "likes" => (object)[ "count" => $post->getLikesCount(), "user_likes" => (int) $post->hasLikeFrom($this->getUser()), @@ -361,6 +367,12 @@ final class Wall extends VKAPIRequestHandler "count" => $post->getCommentsCount(), "can_post" => 1 ], + "copyright" => !is_null($post->getSource(false)) ? (object)[ + "id" => 0, + "link" => $post->getSource(false), + "name" => "none", + "type" => "link" + ] : NULL, "likes" => (object)[ "count" => $post->getLikesCount(), "user_likes" => (int) $post->hasLikeFrom($user), @@ -453,7 +465,7 @@ final class Wall extends VKAPIRequestHandler ]; } - function post(string $owner_id, string $message = "", int $from_group = 0, int $signed = 0, string $attachments = "", int $post_id = 0): object + function post(string $owner_id, string $message = "", int $from_group = 0, int $signed = 0, string $attachments = "", int $post_id = 0, string $copyright = NULL): object { $this->requireUser(); $this->willExecuteWriteAction(); @@ -543,6 +555,10 @@ final class Wall extends VKAPIRequestHandler $post->setFlags($flags); $post->setApi_Source_Name($this->getPlatform()); + if(!is_null($copyright) && !empty($copyright) && $copyright != "" && preg_match("/^(http:\/\/|https:\/\/)*[а-яА-ЯёЁa-z0-9\-_]+(\.[а-яА-ЯёЁa-z0-9\-_]+)+(\/\S*)*$/iu", $copyright) && iconv_strlen($copyright) < 50) { + $post->setSource($copyright); + } + if($owner_id < 0 && !$wallOwner->canBeModifiedBy($this->getUser()) && $wallOwner->getWallType() == 2) $post->setSuggested(1); @@ -1082,6 +1098,54 @@ final class Wall extends VKAPIRequestHandler return 1; } + function checkCopyrightLink(string $link) { + $res = (int)(!is_null($link) && !empty($link) && preg_match("/^(http:\/\/|https:\/\/)*[а-яА-ЯёЁa-z0-9\-_]+(\.[а-яА-ЯёЁa-z0-9\-_]+)+(\/\S*)*$/iu", $link) && iconv_strlen($link) < 50); + + if($res == 0) { + $this->fail(3102, "Specified link is incorrect"); + } + + return $res; + } + + function pin(int $owner_id, int $post_id) { + $this->requireUser(); + $this->willExecuteWriteAction(); + + $post = (new PostsRepo)->getPostById($owner_id, $post_id); + if(!$post || $post->isDeleted()) + $this->fail(361, "Invalid post"); + + if(!$post->canBePinnedBy($this->getUser())) + $this->fail(14, "Access to pinning post denied"); + + if(!$post->isPinned()) { + $post->pin(); + return 1; + } else { + $this->fail(50, "Post is already pinned"); + } + } + + function unpin(int $owner_id, int $post_id) { + $this->requireUser(); + $this->willExecuteWriteAction(); + + $post = (new PostsRepo)->getPostById($owner_id, $post_id); + if(!$post || $post->isDeleted()) + $this->fail(361, "Invalid post"); + + if(!$post->canBePinnedBy($this->getUser())) + $this->fail(14, "Access to unpinning post denied"); + + if($post->isPinned()) { + $post->unpin(); + return 1; + } else { + $this->fail(50, "Post is not pinned"); + } + } + private function getApiPhoto($attachment) { return [ "type" => "photo", diff --git a/Web/Models/Entities/Post.php b/Web/Models/Entities/Post.php index 5a75d99b..dad44f35 100644 --- a/Web/Models/Entities/Post.php +++ b/Web/Models/Entities/Post.php @@ -78,6 +78,31 @@ class Post extends Postable { return (bool) $this->getRecord()->pinned; } + + function getSource(bool $format = false) + { + if(!$format) { + return $this->getRecord()->source; + } + + return $this->formatLinks($this->getRecord()->source); + } + + function setSource(string $source) + { + $src = $source; + + if(iconv_strlen($source) > 50) + throw new \LengthException("Link is too long."); + + if(!preg_match("/^(http:\/\/|https:\/\/)*[а-яА-ЯёЁa-z0-9\-_]+(\.[а-яА-ЯёЁa-z0-9\-_]+)+(\/\S*)*$/iu", $source)) + throw new \LogicException("Invalid link"); + + if(!str_contains($source, "https://") && !str_contains($source, "http://")) + $src = "https://" . $source; + + $this->stateChanges("source", $src); + } function isAd(): bool { diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index b29968d0..f5bea9e8 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -367,6 +367,10 @@ final class WallPresenter extends OpenVKPresenter $post->setFlags($flags); $post->setNsfw($this->postParam("nsfw") === "on"); + if($this->postParam("set_source") === "on" && !is_null($this->postParam("source")) && !empty($this->postParam("source")) && preg_match("/^(http:\/\/|https:\/\/)*[а-яА-ЯёЁa-z0-9\-_]+(\.[а-яА-ЯёЁa-z0-9\-_]+)+(\/\S*)*$/iu", $this->postParam("source")) && iconv_strlen($this->postParam("set_source")) < 50) { + $post->setSource($this->postParam("source")); + } + if($wall < 0 && !$wallOwner->canBeModifiedBy($this->user->identity) && $wallOwner->getWallType() == 2) $post->setSuggested(1); diff --git a/Web/Presenters/templates/Wall/Feed.xml b/Web/Presenters/templates/Wall/Feed.xml index 44c8cd5b..f4f5e97d 100644 --- a/Web/Presenters/templates/Wall/Feed.xml +++ b/Web/Presenters/templates/Wall/Feed.xml @@ -18,7 +18,7 @@
- {include "../components/textArea.xml", route => "/wall" . $thisUser->getId() . "/makePost", graffiti => true, polls => true, notes => true} + {include "../components/textArea.xml", route => "/wall" . $thisUser->getId() . "/makePost", graffiti => true, polls => true, notes => true, hasSource => true}
{foreach $posts as $post} diff --git a/Web/Presenters/templates/components/post/microblogpost.xml b/Web/Presenters/templates/components/post/microblogpost.xml index 04731619..519892fa 100644 --- a/Web/Presenters/templates/components/post/microblogpost.xml +++ b/Web/Presenters/templates/components/post/microblogpost.xml @@ -95,6 +95,9 @@
 ! {_post_is_ad} +
+ {_source}: {$post->getSource(true)|noescape} +
{var $actualAuthor = $post->getOwner(false)} diff --git a/Web/Presenters/templates/components/post/oldpost.xml b/Web/Presenters/templates/components/post/oldpost.xml index c304657d..d5035907 100644 --- a/Web/Presenters/templates/components/post/oldpost.xml +++ b/Web/Presenters/templates/components/post/oldpost.xml @@ -93,6 +93,9 @@
 ! {_post_is_ad}
+
+ {_source}: {$post->getSource(true)|noescape} +
{var $actualAuthor = $post->getOwner(false)} diff --git a/Web/Presenters/templates/components/textArea.xml b/Web/Presenters/templates/components/textArea.xml index 530174b1..64bfb55b 100644 --- a/Web/Presenters/templates/components/textArea.xml +++ b/Web/Presenters/templates/components/textArea.xml @@ -26,6 +26,16 @@
{var $anonEnabled = OPENVK_ROOT_CONF['openvk']['preferences']['wall']['anonymousPosting']['enable']} + {if $hasSource} + + + + {/if} + {if !is_null($thisUser) && !is_null($club ?? NULL) && $owner < 0} {if $club->canBeModifiedBy($thisUser)}