diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index c39a3316..15284688 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -453,25 +453,37 @@ final class Wall extends VKAPIRequestHandler return (object)["post_id" => $post->getVirtualId()]; } - function repost(string $object, string $message = "") { + function repost(string $object, string $message = "", int $group_id = 0) { $this->requireUser(); $this->willExecuteWriteAction(); $postArray; if(preg_match('/wall((?:-?)[0-9]+)_([0-9]+)/', $object, $postArray) == 0) $this->fail(100, "One of the parameters specified was missing or invalid: object is incorrect"); - + $post = (new PostsRepo)->getPostById((int) $postArray[1], (int) $postArray[2]); if(!$post || $post->isDeleted()) $this->fail(100, "One of the parameters specified was missing or invalid"); - + $nPost = new Post; $nPost->setOwner($this->user->getId()); - $nPost->setWall($this->user->getId()); + if($group_id > 0) + { + $club = (new ClubsRepo)->get($group_id); + if(!$club || !$club->canBeModifiedBy($this->user)) + { + $this->fail(42, "Invalid group"); + } + $nPost->setWall($group_id*-1); + } + else + { + $nPost->setWall($this->user->getId()); + } $nPost->setContent($message); $nPost->setApi_Source_Name($this->getPlatform()); $nPost->save(); $nPost->attach($post); - + if($post->getOwner(false)->getId() !== $this->user->getId() && !($post->getOwner() instanceof Club)) (new RepostNotification($post->getOwner(false), $post, $this->user->identity))->emit(); @@ -483,6 +495,7 @@ final class Wall extends VKAPIRequestHandler ]; } + function getComments(int $owner_id, int $post_id, bool $need_likes = true, int $offset = 0, int $count = 10, string $fields = "sex,screen_name,photo_50,photo_100,online_info,online", string $sort = "asc", bool $extended = false) { $this->requireUser(); diff --git a/Web/Models/Repositories/Clubs.php b/Web/Models/Repositories/Clubs.php index edbe75c6..685152f3 100644 --- a/Web/Models/Repositories/Clubs.php +++ b/Web/Models/Repositories/Clubs.php @@ -1,7 +1,7 @@ getConnection()->query("SELECT * FROM `groups` WHERE `owner` = $id ORDER BY `id`"); + + foreach($result as $entry) + yield $this->get($entry->id); + } use \Nette\SmartObject; } diff --git a/Web/Presenters/UserPresenter.php b/Web/Presenters/UserPresenter.php index 3cf68757..5088ecd7 100644 --- a/Web/Presenters/UserPresenter.php +++ b/Web/Presenters/UserPresenter.php @@ -707,4 +707,23 @@ final class UserPresenter extends OpenVKPresenter $this->redirect("/settings"); } } + + function renderOwnedClubs(int $id) + { + if($this->user->id == $id) + { + $this->assertUserLoggedIn(); + $clubs = iterator_to_array((new Clubs)->getOwnedClubs($id)); + $json = array(); + foreach($clubs as $club) + { + $json[]=array("name"=>$club->getName(),"id"=>$club->getId()); + } + $this->returnJson($json); + } + else + { + $this->returnJson(["You are not allowed to see user-created groups"]); + } + } } diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index ffcec2a7..73101d1b 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -301,7 +301,7 @@ final class WallPresenter extends OpenVKPresenter if(!is_null($poll)) $post->attach($poll); - + if($wall > 0 && $wall !== $this->user->identity->getId()) (new WallPostNotification($wallOwner, $post, $this->user->identity))->emit(); @@ -364,20 +364,50 @@ final class WallPresenter extends OpenVKPresenter $post = $this->posts->getPostById($wall, $post_id); if(!$post || $post->isDeleted()) $this->notFound(); - + $where = $this->postParam("type") ?? "wall"; + $groupId = NULL; + $flags = 0; + if($where == "group") + { + $groupId = $this->postParam("groupId"); + } if(!is_null($this->user)) { $nPost = new Post; - $nPost->setOwner($this->user->id); - $nPost->setWall($this->user->id); + if($where == "wall") + { + $nPost->setOwner($this->user->id); + $nPost->setWall($this->user->id); + } + elseif($where == "group") + { + $nPost->setOwner($this->user->id); + + if($this->postParam("asGroup") == 1) + { + $flags |= 0b10000000; + } + if($this->postParam("signed") == 1) + { + $flags |= 0b01000000; + } + $nPost->setWall($groupId*-1); + } $nPost->setContent($this->postParam("text")); + $nPost->setFlags($flags); $nPost->save(); $nPost->attach($post); if($post->getOwner(false)->getId() !== $this->user->identity->getId() && !($post->getOwner() instanceof Club)) (new RepostNotification($post->getOwner(false), $post, $this->user->identity))->emit(); }; - - $this->returnJson(["wall_owner" => $this->user->identity->getId()]); + if($where == "wall") + { + $this->returnJson(["wall_owner" => $this->user->identity->getId()]); + } + else + { + $this->returnJson(["wall_owner" => $groupId*-1]); + } } function renderDelete(int $wall, int $post_id): void diff --git a/Web/Presenters/templates/components/post/microblogpost.xml b/Web/Presenters/templates/components/post/microblogpost.xml index 2f2fc2f1..5fbf07e7 100644 --- a/Web/Presenters/templates/components/post/microblogpost.xml +++ b/Web/Presenters/templates/components/post/microblogpost.xml @@ -96,7 +96,7 @@ {_comment}
- +
{if $post->getRepostCount() > 0}{$post->getRepostCount()}{/if}
diff --git a/Web/Presenters/templates/components/post/oldpost.xml b/Web/Presenters/templates/components/post/oldpost.xml index dcbee4f6..2a4dc252 100644 --- a/Web/Presenters/templates/components/post/oldpost.xml +++ b/Web/Presenters/templates/components/post/oldpost.xml @@ -107,7 +107,7 @@  |  {/if} - + {_share} {if $post->getRepostCount() > 0} ({$post->getRepostCount()}) diff --git a/Web/routes.yml b/Web/routes.yml index 0dffb7bf..30dfdc1a 100644 --- a/Web/routes.yml +++ b/Web/routes.yml @@ -93,6 +93,8 @@ routes: handler: "User->increaseRating" - url: "/id{num}" handler: "User->view" + - url: "/id{num}/getOwnedClubs" + handler: "User->ownedClubs" - url: "/friends{num}" handler: "User->friends" - url: "/edit" diff --git a/Web/static/js/openvk.cls.js b/Web/static/js/openvk.cls.js index 0ecc385e..94f7ffb0 100644 --- a/Web/static/js/openvk.cls.js +++ b/Web/static/js/openvk.cls.js @@ -65,7 +65,6 @@ function toggleMenu(id) { }); } } - document.addEventListener("DOMContentLoaded", function() { //BEGIN u("#_photoDelete").on("click", function(e) { @@ -88,7 +87,6 @@ document.addEventListener("DOMContentLoaded", function() { //BEGIN return e.preventDefault(); }); - /* @rem-pai why this func wasn't named as "#_deleteDialog"? It looks universal IMO */ u("#_noteDelete").on("click", function(e) { @@ -170,12 +168,37 @@ document.addEventListener("DOMContentLoaded", function() { //BEGIN }); //END ONREADY DECLS -function repostPost(id, hash) { - uRepostMsgTxt = tr('your_comment') + ":

"; - +function repostPost(id, hash, owner) { + uRepostMsgTxt = ` + ${tr('auditory')}:
+ ${tr("in_wall")}
+ ${tr("in_group")}
+
+ ${tr('your_comment')}: + + +

`; + let clubs = []; MessageBox(tr('share'), uRepostMsgTxt, [tr('send'), tr('cancel')], [ (function() { text = document.querySelector("#uRepostMsgInput_"+id).value; + type = "user"; + radios = document.querySelectorAll('input[name="type"]') + for(const r of radios) + { + if(r.checked) + { + type = r.value; + break; + } + } + groupId = document.querySelector("#groupId").value; + asGroup = asgroup.value; + signed = signed.value; hash = encodeURIComponent(hash); xhr = new XMLHttpRequest(); xhr.open("POST", "/wall"+id+"/repost?hash="+hash, true); @@ -188,10 +211,21 @@ function repostPost(id, hash) { NewNotification(tr('information_-1'), tr('shared_succ'), null, () => {window.location.href = "/wall" + jsonR.wall_owner}); } }); - xhr.send('text=' + encodeURI(text)); + xhr.send('text=' + encodeURI(text) + '&type=' + encodeURI(type) + '&groupId=' + encodeURI(groupId) + "&asGroup="+encodeURI(asGroup) + "&signed="+encodeURI(signed)); }), Function.noop ]); + let xhrj = new XMLHttpRequest(); + xhrj.open("GET", "id"+owner+"/getOwnedClubs?hash="+hash) + xhrj.send() + xhrj.onload = () => + { + clubs = JSON.parse(xhrj.responseText); + for(const el of clubs) + { + document.getElementById("groupId").insertAdjacentHTML("beforeend", ``) + } + } } function setClubAdminComment(clubId, adminId, hash) { diff --git a/locales/en.strings b/locales/en.strings index 664d0ea5..2b0dd9a9 100644 --- a/locales/en.strings +++ b/locales/en.strings @@ -175,6 +175,9 @@ "pinned" = "pinned"; "comments_tip" = "Be first, who leaves a comment at this post!"; "your_comment" = "Your comment"; +"auditory" = "Auditory"; +"in_wall" = "to user's wall"; +"in_group" = "to group"; "shown" = "Shown"; "x_out_of" = "$1 of"; "wall_zero" = "no posts"; diff --git a/locales/ru.strings b/locales/ru.strings index 578259c8..907a7877 100644 --- a/locales/ru.strings +++ b/locales/ru.strings @@ -157,6 +157,9 @@ "pinned" = "закреплено"; "comments_tip" = "Будьте первым, кто оставит комментарий!"; "your_comment" = "Ваш комментарий"; +"auditory" = "Аудитория"; +"in_wall" = "на стену"; +"in_group" = "в группу"; "shown" = "Показано"; "x_out_of" = "$1 из"; "wall_zero" = "нет записей";