Compare commits

...

5 commits

Author SHA1 Message Date
Vladimir Barinov
c561b6317e
Merge branch 'master' into post_source 2024-10-25 17:04:36 +03:00
lalka2018
4ee3fcd154
Merge branch 'master' into post_source 2023-10-06 14:32:24 +03:00
lalka2016
95b599e3e2 Newlines 2023-08-07 10:46:07 +03:00
lalka2016
4aa7bedad7 kq 2023-07-30 11:15:54 +03:00
lalka2016
4bcd444f87 Posts: add source param 2023-07-29 08:30:21 +03:00
13 changed files with 143 additions and 3 deletions

View file

@ -176,6 +176,12 @@ final class Wall extends VKAPIRequestHandler
"count" => $post->getCommentsCount(), "count" => $post->getCommentsCount(),
"can_post" => 1 "can_post" => 1
], ],
"copyright" => !is_null($post->getSource(false)) ? (object)[
"id" => 0,
"link" => $post->getSource(false),
"name" => "none",
"type" => "link"
] : NULL,
"likes" => (object)[ "likes" => (object)[
"count" => $post->getLikesCount(), "count" => $post->getLikesCount(),
"user_likes" => (int) $post->hasLikeFrom($this->getUser()), "user_likes" => (int) $post->hasLikeFrom($this->getUser()),
@ -361,6 +367,12 @@ final class Wall extends VKAPIRequestHandler
"count" => $post->getCommentsCount(), "count" => $post->getCommentsCount(),
"can_post" => 1 "can_post" => 1
], ],
"copyright" => !is_null($post->getSource(false)) ? (object)[
"id" => 0,
"link" => $post->getSource(false),
"name" => "none",
"type" => "link"
] : NULL,
"likes" => (object)[ "likes" => (object)[
"count" => $post->getLikesCount(), "count" => $post->getLikesCount(),
"user_likes" => (int) $post->hasLikeFrom($user), "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->requireUser();
$this->willExecuteWriteAction(); $this->willExecuteWriteAction();
@ -543,6 +555,10 @@ final class Wall extends VKAPIRequestHandler
$post->setFlags($flags); $post->setFlags($flags);
$post->setApi_Source_Name($this->getPlatform()); $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) if($owner_id < 0 && !$wallOwner->canBeModifiedBy($this->getUser()) && $wallOwner->getWallType() == 2)
$post->setSuggested(1); $post->setSuggested(1);
@ -1082,6 +1098,54 @@ final class Wall extends VKAPIRequestHandler
return 1; 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) { private function getApiPhoto($attachment) {
return [ return [
"type" => "photo", "type" => "photo",

View file

@ -78,6 +78,31 @@ class Post extends Postable
{ {
return (bool) $this->getRecord()->pinned; 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 function isAd(): bool
{ {

View file

@ -367,6 +367,10 @@ final class WallPresenter extends OpenVKPresenter
$post->setFlags($flags); $post->setFlags($flags);
$post->setNsfw($this->postParam("nsfw") === "on"); $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) if($wall < 0 && !$wallOwner->canBeModifiedBy($this->user->identity) && $wallOwner->getWallType() == 2)
$post->setSuggested(1); $post->setSuggested(1);

View file

@ -18,7 +18,7 @@
</div> </div>
<div n:class="postFeedWrapper, $thisUser->hasMicroblogEnabled() ? postFeedWrapperMicroblog"> <div n:class="postFeedWrapper, $thisUser->hasMicroblogEnabled() ? postFeedWrapperMicroblog">
{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}
</div> </div>
{foreach $posts as $post} {foreach $posts as $post}

View file

@ -95,6 +95,9 @@
<br/> <br/>
&nbsp;! {_post_is_ad} &nbsp;! {_post_is_ad}
</div> </div>
<div n:if="!is_null($post->getSource())" class="sourceDiv">
<span>{_source}: {$post->getSource(true)|noescape}</span>
</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>

View file

@ -93,6 +93,9 @@
<br/> <br/>
&nbsp;! {_post_is_ad} &nbsp;! {_post_is_ad}
</div> </div>
<div n:if="!is_null($post->getSource())" class="sourceDiv" style="margin-top:0px;">
<span>{_source}: {$post->getSource(true)|noescape}</span>
</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>

View file

@ -26,6 +26,16 @@
<div n:if="$postOpts ?? true" class="post-opts"> <div n:if="$postOpts ?? true" class="post-opts">
{var $anonEnabled = OPENVK_ROOT_CONF['openvk']['preferences']['wall']['anonymousPosting']['enable']} {var $anonEnabled = OPENVK_ROOT_CONF['openvk']['preferences']['wall']['anonymousPosting']['enable']}
{if $hasSource}
<label style="user-select:none;">
<input type="checkbox" name="set_source"/> <span style="color: #777777;">{_set_source}</span>
</label>
<div id="sourceSet" style="display:none;">
<input type="text" name="source" placeholder="https://youtu.be/dQw4w9WgXcQ/"/>
</div>
{/if}
{if !is_null($thisUser) && !is_null($club ?? NULL) && $owner < 0} {if !is_null($thisUser) && !is_null($club ?? NULL) && $owner < 0}
{if $club->canBeModifiedBy($thisUser)} {if $club->canBeModifiedBy($thisUser)}
<script> <script>

View file

@ -10,7 +10,7 @@
<div class="insertThere" id="postz"></div> <div class="insertThere" id="postz"></div>
<div id="underHeader"> <div id="underHeader">
<div n:if="$canPost" class="content_subtitle"> <div n:if="$canPost" class="content_subtitle">
{include "../components/textArea.xml", route => "/wall$owner/makePost", graffiti => true, polls => true, notes => true} {include "../components/textArea.xml", route => "/wall$owner/makePost", graffiti => true, polls => true, notes => true, hasSource => true}
</div> </div>
<div class="content"> <div class="content">

View file

@ -3019,6 +3019,16 @@ body.article .floating_sidebar, body.article .page_content {
font-size: 12px; font-size: 12px;
} }
.sourceDiv {
margin-top: 3px;
margin-left: 4px;
}
.sourceDiv span {
color:grey;
font-size: 11px;
}
.sugglist { .sugglist {
padding-bottom: 5px; padding-bottom: 5px;
padding-top: 5px; padding-top: 5px;

View file

@ -525,6 +525,21 @@ async function showArticle(note_id) {
u("body").addClass("article"); u("body").addClass("article");
} }
if(document.querySelector("input[name='set_source']") != null) {
document.querySelector("input[name='set_source']").checked = false
}
$(document).on("change", "input[name='set_source']", (e) => {
if(e.currentTarget.checked) {
document.getElementById("sourceSet").style.display = "block"
e.currentTarget.parentNode.querySelector("span").innerHTML = tr("source") + ":"
} else {
document.getElementById("sourceSet").style.display = "none"
e.currentTarget.parentNode.querySelector("span").innerHTML = tr("set_source")
}
})
// Оконный плеер // Оконный плеер
$(document).on("click", "#videoOpen", async (e) => { $(document).on("click", "#videoOpen", async (e) => {

View file

@ -0,0 +1,2 @@
ALTER TABLE `posts`
ADD COLUMN `source` TEXT NULL DEFAULT NULL AFTER `api_source_name`;

View file

@ -223,6 +223,8 @@
"attachment" = "Attachment"; "attachment" = "Attachment";
"post_as_group" = "Post as group"; "post_as_group" = "Post as group";
"comment_as_group" = "Comment as group"; "comment_as_group" = "Comment as group";
"set_source" = "Set source";
"source" = "Source";
"add_signature" = "Add signature"; "add_signature" = "Add signature";
/* ^ can be translated as "author's signature". ^ */ /* ^ can be translated as "author's signature". ^ */
"contains_nsfw" = "Contains NSFW content"; "contains_nsfw" = "Contains NSFW content";

View file

@ -207,6 +207,8 @@
"attachment" = "Вложение"; "attachment" = "Вложение";
"post_as_group" = "От имени сообщества"; "post_as_group" = "От имени сообщества";
"comment_as_group" = "От имени сообщества"; "comment_as_group" = "От имени сообщества";
"set_source" = "Указать источник";
"source" = "Источник";
"add_signature" = "Подпись автора"; "add_signature" = "Подпись автора";
"contains_nsfw" = "Содержит NSFW-контент"; "contains_nsfw" = "Содержит NSFW-контент";
"nsfw_warning" = "Данный пост может содержать 18+ контент"; "nsfw_warning" = "Данный пост может содержать 18+ контент";