${note.title}
` + note.html); u("body").removeClass("dimmed"); u("body").addClass("article"); -} \ No newline at end of file +} + +$(document).on("click", "#publish_post", async (e) => { + let id = Number(e.currentTarget.dataset.id) + let post; + let body = ` + + + ` + + MessageBox(tr("publishing_suggested_post"), body, [tr("publish"), tr("cancel")], [(async () => { + let id = Number(e.currentTarget.dataset.id) + let post; + + try { + post = await API.Wall.acceptPost(id, document.getElementById("signatr").checked, document.getElementById("pooblish").value) + } catch(ex) { + switch(ex.code) { + case 11: + MessageBox(tr("error"), tr("error_declining_invalid_post"), [tr("ok")], [Function.noop]); + break; + case 19: + MessageBox(tr("error"), tr("error_declining_not_suggested_post"), [tr("ok")], [Function.noop]); + break; + case 10: + MessageBox(tr("error"), tr("error_declining_declined_post"), [tr("ok")], [Function.noop]); + break; + case 22: + MessageBox(tr("error"), "Access denied", [tr("ok")], [Function.noop]); + break; + default: + MessageBox(tr("error"), "Unknown error "+ex.code+": "+ex.message, [tr("ok")], [Function.noop]); + break; + } + + return 0; + } + + NewNotification(tr("suggestion_succefully_published"), tr("suggestion_press_to_go"), null, () => {window.location.assign("/wall" + post.id)}); + document.getElementById("cound").innerHTML = tr("x_suggested_posts_in_group", post.new_count) + e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = "" + }), Function.noop]); + + document.getElementById("pooblish").innerHTML = e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.querySelector(".really_text").innerHTML + document.querySelector(".ovk-diag-body").style.padding = "9px"; +}) + +$(document).on("click", "#decline_post", async (e) => { + let id = Number(e.currentTarget.dataset.id) + let post; + + try { + e.currentTarget.parentNode.parentNode.insertAdjacentHTML("afterbegin", `
`)
+ post = await API.Wall.declinePost(id)
+ } catch(ex) {
+ switch(ex.code) {
+ case 11:
+ MessageBox(tr("error"), tr("error_declining_invalid_post"), [tr("ok")], [Function.noop]);
+ break;
+ case 19:
+ MessageBox(tr("error"), tr("error_declining_not_suggested_post"), [tr("ok")], [Function.noop]);
+ break;
+ case 10:
+ MessageBox(tr("error"), tr("error_declining_declined_post"), [tr("ok")], [Function.noop]);
+ break;
+ case 22:
+ MessageBox(tr("error"), "Access denied", [tr("ok")], [Function.noop]);
+ break;
+ default:
+ MessageBox(tr("error"), "Unknown error "+ex.code+": "+ex.message, [tr("ok")], [Function.noop]);
+ break;
+ }
+
+ return 0;
+ } finally {
+ u("#deleteMe").remove()
+ }
+
+ // а хули
+ NewNotification(tr("suggestion_succefully_declined"), "", null);
+ e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = ""
+ document.getElementById("cound").innerHTML = tr("x_suggested_posts_in_group", post)
+})
\ No newline at end of file
diff --git a/install/sqls/00039-suggest-posts.sql b/install/sqls/00039-suggest-posts.sql
new file mode 100644
index 000000000..321c2a6a9
--- /dev/null
+++ b/install/sqls/00039-suggest-posts.sql
@@ -0,0 +1 @@
+ALTER TABLE `posts` ADD `suggested` TINYINT(2) UNSIGNED NOT NULL DEFAULT '0' AFTER `deleted`;
\ No newline at end of file
diff --git a/locales/en.strings b/locales/en.strings
index 4aaa4483a..020076a95 100644
--- a/locales/en.strings
+++ b/locales/en.strings
@@ -260,6 +260,7 @@
/* Group */
+"group" = "Group";
"name_group" = "Name";
"subscribe" = "Subscribe";
"unsubscribe" = "Unsubscribe";
@@ -297,8 +298,38 @@
"set_comment" = "Set comment";
"hidden_yes" = "Hidden: Yes";
"hidden_no" = "Hidden: No";
-"group_allow_post_for_everyone" = "Allow posting for everyone";
+"group_allow_post_for_everyone" = "Open";
+"group_limited_post" = "Suggestions";
+"group_closed_post" = "Closed";
+"suggest_new" = "Suggest post";
+"show_suggested_posts" = "$1 suggested posts by you";
+"show_suggested_posts_everyone" = "$1 suggested posts";
"group_hide_from_global_feed" = "Don't display posts in the global feed";
+"suggested_posts_by_you" = "Suggested posts by you";
+"suggested_posts_by_everyone" = "Suggested posts";
+"suggested" = "Suggested";
+"suggested_posts_everyone" = "Suggested by users posts";
+"no_suggested_posts_by_you" = "You haven't suggested posts to this group yet.";
+"no_suggested_posts_by_people" = "No posts have been suggested to this group yet.";
+
+"publish_suggested" = "Accept";
+"decline_suggested" = "Decline";
+
+"publishing_suggested_post" = "Publishing suggested post";
+"x_suggested_posts_in_group" = "This group has $1 suggested posts";
+"x_suggested_posts_in_group_by_you" = "You suggested $1 posts to this group";
+
+"suggestion_succefully_published" = "Post successfully published";
+"suggestion_succefully_declined" = "Post successfully declined";
+"suggestion_press_to_go" = "Click to show him";
+
+"error_declining_invalid_post" = "Error when declining post: post does not exists";
+"error_declining_not_suggested_post" = "Error when declining post: post is not suggested";
+"error_declining_declined_post" = "Error when declining post: post is already declined";
+
+"error_accepting_invalid_post" = "Error when accepting post: post does not exists";
+"error_accepting_not_suggested_post" = "Error when accepting post: post is not suggested";
+"error_accepting_declined_post" = "Error when accepting post: cant accept declined post";
"statistics" = "Statistics";
"group_administrators_list" = "Admins list";
"group_display_only_creator" = "Display only group creator";
@@ -331,6 +362,11 @@
"search_by_groups" = "Search by groups";
"search_group_desc" = "Here you can browse through the existing groups and choose a group to suit your needs...";
+"error_suggestions" = "Error accessing to suggestions";
+"error_suggestions_closed" = "This group has closed wall.";
+"error_suggestions_open" = "This group has open wall.";
+"error_suggestions_access" = "Only group's administrators can view all suggested posts.";
+
/* Albums */
"create" = "Create";
@@ -675,6 +711,7 @@
"nt_shared_yours" = "shared your";
"nt_commented_yours" = "commented";
"nt_written_on_your_wall" = "wrote on your wall";
+"nt_accepted_your_post" = "accepted your suggested";
"nt_made_you_admin" = "appointed you in the community";
"nt_from" = "from";
@@ -694,6 +731,8 @@
"nt_mention_in_note" = "in discussion of this note";
"nt_mention_in_topic" = "in the discussion";
+"nt_post_small" = "post";
+
/* Time */
"time_at_sp" = " at ";
diff --git a/locales/ru.strings b/locales/ru.strings
index 6faa5e2e2..a4f06e47d 100644
--- a/locales/ru.strings
+++ b/locales/ru.strings
@@ -245,6 +245,7 @@
/* Group */
+"group" = "Сообщество";
"name_group" = "Название";
"subscribe" = "Подписаться";
"unsubscribe" = "Отписаться";
@@ -281,8 +282,40 @@
"set_comment" = "Изменить комментарий";
"hidden_yes" = "Скрыт: Да";
"hidden_no" = "Скрыт: Нет";
-"group_allow_post_for_everyone" = "Разрешить публиковать записи всем";
+
+"group_allow_post_for_everyone" = "Открытая";
+"group_limited_post" = "Предложка";
+"group_closed_post" = "Закрытая";
+"suggest_new" = "Предложить новость";
+"show_suggested_posts" = "$1 предложенных вами записей";
+"show_suggested_posts_everyone" = "$1 предложенных записей";
"group_hide_from_global_feed" = "Не отображать публикации в глобальной ленте";
+"suggested_posts_by_you" = "Предложенные вами записи";
+"suggested_posts_by_everyone" = "Предложенные записи";
+"suggested" = "Предложено";
+"suggested_posts_everyone" = "Предложенные пользователями записи";
+"no_suggested_posts_by_you" = "Вы ещё не предлагали записей в эту группу.";
+"no_suggested_posts_by_people" = "В эту группу ещё не предлагали записей.";
+
+"publish_suggested" = "Опубликовать запись";
+"decline_suggested" = "Отклонить";
+
+"publishing_suggested_post" = "Публикация предложенной записи";
+"x_suggested_posts_in_group" = "В эту группу предложили $1 записей";
+"x_suggested_posts_in_group_by_you" = "Вы предложили в эту группу $1 записей";
+
+"suggestion_succefully_published" = "Запись успешно опубликована";
+"suggestion_succefully_declined" = "Запись успешно отклонена";
+"suggestion_press_to_go" = "Нажмите, чтобы перейти к ней";
+
+"error_declining_invalid_post" = "Не удалость отклонить пост: поста не существует";
+"error_declining_not_suggested_post" = "Не удалость отклонить пост: пост не из предложки";
+"error_declining_declined_post" = "Не удалость отклонить пост: пост уже отклонён";
+
+"error_accepting_invalid_post" = "Не удалость принять пост: поста не существует";
+"error_accepting_not_suggested_post" = "Не удалость принять пост: пост не из предложки";
+"error_accepting_declined_post" = "Не удалость принять пост: пост отклонён";
+
"statistics" = "Статистика";
"group_administrators_list" = "Список админов";
"group_display_only_creator" = "Отображать только создателя группы";
@@ -315,6 +348,11 @@
"search_by_groups" = "Поиск по группам";
"search_group_desc" = "Здесь Вы можете просмотреть существующие группы и выбрать группу себе по вкусу...";
+"error_suggestions" = "Ошибка доступа к предложенным";
+"error_suggestions_closed" = "У этой группы закрытая стена.";
+"error_suggestions_open" = "У этой группы открытая стена.";
+"error_suggestions_access" = "Просматривать все предложенные записи могут только администраторы группы.";
+
/* Albums */
"create" = "Создать";
@@ -632,6 +670,7 @@
"nt_shared_yours" = "поделился(-ась) вашим";
"nt_commented_yours" = "оставил(а) комментарий под";
"nt_written_on_your_wall" = "написал(а) на вашей стене";
+"nt_accepted_your_post" = "опубликовало вашу предложенную";
"nt_made_you_admin" = "назначил(а) вас руководителем сообщества";
"nt_from" = "от";
"nt_yours_adjective" = "вашим";
@@ -649,6 +688,7 @@
"nt_mention_in_video" = "в обсуждении видеозаписи";
"nt_mention_in_note" = "в обсуждении заметки";
"nt_mention_in_topic" = "в обсуждении";
+"nt_post_small" = "запись";
/* Time */
From eff2b2bba19f0ec32bdf5c60df65090551793de3 Mon Sep 17 00:00:00 2001
From: lalka2016 <99399973+lalka2016@users.noreply.github.com>
Date: Mon, 31 Jul 2023 09:44:49 +0300
Subject: [PATCH 02/34] Fix br
---
Web/static/js/al_wall.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Web/static/js/al_wall.js b/Web/static/js/al_wall.js
index f60a30619..9eff0e15e 100644
--- a/Web/static/js/al_wall.js
+++ b/Web/static/js/al_wall.js
@@ -305,7 +305,7 @@ $(document).on("click", "#publish_post", async (e) => {
e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = ""
}), Function.noop]);
- document.getElementById("pooblish").innerHTML = e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.querySelector(".really_text").innerHTML
+ document.getElementById("pooblish").innerHTML = e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.querySelector(".really_text").innerHTML.replace(//g, '') document.querySelector(".ovk-diag-body").style.padding = "9px"; }) From 213f1e286c6db65a46b1daeec2fc169b7033c3f1 Mon Sep 17 00:00:00 2001 From: lalka2016 <99399973+lalka2016@users.noreply.github.com> Date: Mon, 31 Jul 2023 10:00:55 +0300 Subject: [PATCH 03/34] Fix empty posts --- ServiceAPI/Wall.php | 9 ++++++--- VKAPI/Handlers/Wall.php | 3 ++- Web/Presenters/GroupPresenter.php | 9 +++++++-- Web/static/js/al_wall.js | 3 +-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ServiceAPI/Wall.php b/ServiceAPI/Wall.php index 73eeee36f..62b1fe2cd 100644 --- a/ServiceAPI/Wall.php +++ b/ServiceAPI/Wall.php @@ -110,7 +110,7 @@ function declinePost(int $id, callable $resolve, callable $reject) $reject(10, "Post is already declined"); if(!$post->canBePinnedBy($this->user)) - $reject(22, "Access to post denied :)"); + $reject(22, "Access to post denied"); $post->setSuggested(2); $post->save(); @@ -131,7 +131,7 @@ function acceptPost(int $id, bool $sign, string $content, callable $resolve, cal $reject(10, "Post is declined"); if(!$post->canBePinnedBy($this->user)) - $reject(22, "Access to post denied :)"); + $reject(22, "Access to post denied"); $author = $post->getOwner(); $flags = 0; @@ -144,7 +144,10 @@ function acceptPost(int $id, bool $sign, string $content, callable $resolve, cal $post->setSuggested(0); $post->setCreated(time()); $post->setFlags($flags); - $post->setContent($content); + + if(mb_strlen($content) > 0) { + $post->setContent($content); + } $post->save(); diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index dfe33c24e..38033ea7e 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -57,7 +57,8 @@ function get(int $owner_id, string $domain = "", int $offset = 0, int $count = 3 case "postponed": $this->fail(66666, "Otlojka is not implemented :)"); break; - # В апи, походу, нету метода, который бы публиковал запись из предложки + # В вкапи, походу, нету метода, который бы публиковал запись из предложки. + # Либо он закрыт для неофициальных клиентов, как gifts.send case "suggests": if($owner_id < 0) { if($wallOnwer->canBeModifiedBy($this->getUser())) { diff --git a/Web/Presenters/GroupPresenter.php b/Web/Presenters/GroupPresenter.php index 822582b7a..3ead10b4a 100644 --- a/Web/Presenters/GroupPresenter.php +++ b/Web/Presenters/GroupPresenter.php @@ -200,7 +200,7 @@ function renderEdit(int $id): void $this->willExecuteWriteAction(); $club = $this->clubs->get($id); - if(!$club || !$club->canBeModifiedBy($this->user->identity) || $club->isDeleted()) + if(!$club || !$club->canBeModifiedBy($this->user->identity)) $this->notFound(); else $this->template->club = $club; @@ -211,7 +211,12 @@ function renderEdit(int $id): void $club->setName(empty($this->postParam("name")) ? $club->getName() : $this->postParam("name")); $club->setAbout(empty($this->postParam("about")) ? NULL : $this->postParam("about")); - $club->setWall(empty($this->postParam("wall")) ? 0 : 1); + try { + $club->setWall(empty($this->postParam("wall")) ? 0 : (int)$this->postParam("wall")); + } catch(\Exception $e) { + $this->flashFail("err", "Fuck you", ""); + } + $club->setAdministrators_List_Display(empty($this->postParam("administrators_list_display")) ? 0 : $this->postParam("administrators_list_display")); $club->setEveryone_Can_Create_Topics(empty($this->postParam("everyone_can_create_topics")) ? 0 : 1); $club->setDisplay_Topics_Above_Wall(empty($this->postParam("display_topics_above_wall")) ? 0 : 1); diff --git a/Web/static/js/al_wall.js b/Web/static/js/al_wall.js index 9eff0e15e..51683bd8f 100644 --- a/Web/static/js/al_wall.js +++ b/Web/static/js/al_wall.js @@ -339,8 +339,7 @@ $(document).on("click", "#decline_post", async (e) => { } finally { u("#deleteMe").remove() } - - // а хули + NewNotification(tr("suggestion_succefully_declined"), "", null); e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = "" document.getElementById("cound").innerHTML = tr("x_suggested_posts_in_group", post) From 3809b82cecc17f231d27ff9bc3461f8bb241ef7d Mon Sep 17 00:00:00 2001 From: lalka2016 <99399973+lalka2016@users.noreply.github.com> Date: Mon, 31 Jul 2023 10:48:27 +0300 Subject: [PATCH 04/34] fck --- VKAPI/Handlers/Wall.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index 38033ea7e..3b93be2fe 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -65,8 +65,8 @@ function get(int $owner_id, string $domain = "", int $offset = 0, int $count = 3 $iteratorv = $posts->getSuggestedPosts($owner_id * -1, 1, $count, $offset); $cnt = $posts->getSuggestedPostsCount($owner_id * -1); } else { - $iteratorv = $posts->getSuggestedPosts($owner_id * -1, 1, $count, $offset); - $cnt = $posts->getSuggestedPostsCount($owner_id * -1); + $iteratorv = $posts->getSuggestedPostsByUser($owner_id * -1, $this->getUser()->getId(), 1, $count, $offset); + $cnt = $posts->getSuggestedPostsCountByUser($owner_id * -1, $this->getUser()->getId()); } } else { $this->fail(528, "Suggested posts avaiable only at groups"); From cd546621b351c705ad945f447836ce5e6bbb2fef Mon Sep 17 00:00:00 2001 From: lalka2016 <99399973+lalka2016@users.noreply.github.com> Date: Mon, 31 Jul 2023 15:20:54 +0300 Subject: [PATCH 05/34] Add offset for api --- Web/Models/Repositories/Posts.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Web/Models/Repositories/Posts.php b/Web/Models/Repositories/Posts.php index 1dd2ca273..4cde11a59 100644 --- a/Web/Models/Repositories/Posts.php +++ b/Web/Models/Repositories/Posts.php @@ -149,12 +149,15 @@ function getPostCountOnUserWall(int $user): int function getSuggestedPosts(int $club, int $page = 1, ?int $perPage = NULL, ?int $offset = NULL): \Traversable { + $perPage ??= OPENVK_DEFAULT_PER_PAGE; + $offset ??= $perPage * ($page - 1); + $sel = $this->posts ->where("deleted", 0) ->where("wall", $club * -1) ->order("created DESC") ->where("suggested", 1) - ->page($page, $perPage ?? OPENVK_DEFAULT_PER_PAGE); + ->limit($perPage, $offset); foreach($sel as $post) yield new Post($post); @@ -165,15 +168,18 @@ function getSuggestedPostsCount(int $club) return sizeof($this->posts->where(["wall" => $club * -1, "deleted" => 0, "suggested" => 1])); } - function getSuggestedPostsByUser(int $club, int $user, int $page = 1, ?int $perPage = NULL): \Traversable + function getSuggestedPostsByUser(int $club, int $user, int $page = 1, ?int $perPage = NULL, ?int $offset = NULL): \Traversable { + $perPage ??= OPENVK_DEFAULT_PER_PAGE; + $offset ??= $perPage * ($page - 1); + $sel = $this->posts ->where("deleted", 0) ->where("wall", $club * -1) ->where("owner", $user) ->order("created DESC") ->where("suggested", 1) - ->page($page, $perPage ?? OPENVK_DEFAULT_PER_PAGE); + ->limit($perPage, $offset); foreach($sel as $post) yield new Post($post); From 61205f64d9cf29993f564508f9206cc56ef97850 Mon Sep 17 00:00:00 2001 From: lalka2016 <99399973+lalka2016@users.noreply.github.com> Date: Mon, 31 Jul 2023 19:14:24 +0300 Subject: [PATCH 06/34] Add notifications of new suggestion posts --- VKAPI/Handlers/Wall.php | 14 +++++++++++++- .../NewSuggestedPostsNotification.php | 13 +++++++++++++ Web/Presenters/WallPresenter.php | 16 +++++++++++++++- .../components/notifications/7/_18_5_.xml | 5 +++++ locales/en.strings | 2 ++ locales/ru.strings | 2 ++ 6 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 Web/Models/Entities/Notifications/NewSuggestedPostsNotification.php create mode 100644 Web/Presenters/templates/components/notifications/7/_18_5_.xml diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index 3b93be2fe..74eacb8ec 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -1,7 +1,7 @@ user->identity))->emit(); if($owner_id < 0 && !$wallOwner->canBeModifiedBy($this->getUser()) && $wallOwner->getWallType() == 2) { + $suggsCount = (new PostsRepo)->getSuggestedPostsCount($wallOwner->getId()); + + if($suggsCount % 10 == 0) { + $managers = $wallOwner->getManagers(); + $owner = $wallOwner->getOwner(); + (new NewSuggestedPostsNotification($owner, $wallOwner))->emit(); + + foreach($managers as $manager) { + (new NewSuggestedPostsNotification($manager->getUser(), $wallOwner))->emit(); + } + } + return (object)["post_id" => "on_view"]; } diff --git a/Web/Models/Entities/Notifications/NewSuggestedPostsNotification.php b/Web/Models/Entities/Notifications/NewSuggestedPostsNotification.php new file mode 100644 index 000000000..e1795b08a --- /dev/null +++ b/Web/Models/Entities/Notifications/NewSuggestedPostsNotification.php @@ -0,0 +1,13 @@ +getOwner(), strip_tags($post->getText())))->emit(); if($wall < 0 && !$wallOwner->canBeModifiedBy($this->user->identity) && $wallOwner->getWallType() == 2) { + $suggsCount = $this->posts->getSuggestedPostsCount($wallOwner->getId()); + + # Возможно, это заебёт админов групп, но так они хотя бы про паблик вспомнят + # Мб рандома добавить? + if($suggsCount % 10 == 0) { + $managers = $wallOwner->getManagers(); + $owner = $wallOwner->getOwner(); + (new NewSuggestedPostsNotification($owner, $wallOwner))->emit(); + + foreach($managers as $manager) { + (new NewSuggestedPostsNotification($manager->getUser(), $wallOwner))->emit(); + } + } + $this->redirect("/club".$wallOwner->getId()."/suggested"); } else { $this->redirect($wallOwner->getURL()); diff --git a/Web/Presenters/templates/components/notifications/7/_18_5_.xml b/Web/Presenters/templates/components/notifications/7/_18_5_.xml new file mode 100644 index 000000000..4c012edd6 --- /dev/null +++ b/Web/Presenters/templates/components/notifications/7/_18_5_.xml @@ -0,0 +1,5 @@ +{var $club = $notification->getModel(1)} + +{_nt_in_club} +{$club->getName()} +{_nt_new_suggested_posts} \ No newline at end of file diff --git a/locales/en.strings b/locales/en.strings index 020076a95..e7f616aca 100644 --- a/locales/en.strings +++ b/locales/en.strings @@ -712,6 +712,8 @@ "nt_commented_yours" = "commented"; "nt_written_on_your_wall" = "wrote on your wall"; "nt_accepted_your_post" = "accepted your suggested"; +"nt_in_club" = "In group"; +"nt_new_suggested_posts" = "new posts in suggestions"; "nt_made_you_admin" = "appointed you in the community"; "nt_from" = "from"; diff --git a/locales/ru.strings b/locales/ru.strings index a4f06e47d..47a769422 100644 --- a/locales/ru.strings +++ b/locales/ru.strings @@ -671,6 +671,8 @@ "nt_commented_yours" = "оставил(а) комментарий под"; "nt_written_on_your_wall" = "написал(а) на вашей стене"; "nt_accepted_your_post" = "опубликовало вашу предложенную"; +"nt_in_club" = "В сообществе"; +"nt_new_suggested_posts" = "новые записи в предложке"; "nt_made_you_admin" = "назначил(а) вас руководителем сообщества"; "nt_from" = "от"; "nt_yours_adjective" = "вашим"; From 9a20682e019764094dcb0b86b0791d39cc9e8503 Mon Sep 17 00:00:00 2001 From: lalka2016 <99399973+lalka2016@users.noreply.github.com> Date: Tue, 1 Aug 2023 13:27:53 +0300 Subject: [PATCH 07/34] Fix mentions in suggested posts --- Web/Presenters/WallPresenter.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index f3f939f5e..d189013df 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -335,10 +335,15 @@ function renderMakePost(int $wall): void if($wall > 0) $excludeMentions[] = $wall; - $mentions = iterator_to_array($post->resolveMentions($excludeMentions)); - foreach($mentions as $mentionee) - if($mentionee instanceof User) - (new MentionNotification($mentionee, $post, $post->getOwner(), strip_tags($post->getText())))->emit(); + if($wall < 0 && !$wallOwner->canBeModifiedBy($this->user->identity) && $wallOwner->getWallType() == 2) { + # Чтобы не было упоминаний из предложки + } else { + $mentions = iterator_to_array($post->resolveMentions($excludeMentions)); + + foreach($mentions as $mentionee) + if($mentionee instanceof User) + (new MentionNotification($mentionee, $post, $post->getOwner(), strip_tags($post->getText())))->emit(); + } if($wall < 0 && !$wallOwner->canBeModifiedBy($this->user->identity) && $wallOwner->getWallType() == 2) { $suggsCount = $this->posts->getSuggestedPostsCount($wallOwner->getId()); From 1fcc372f18b51d3085a2624da93dd6314d5767da Mon Sep 17 00:00:00 2001 From: lalka2016 <99399973+lalka2016@users.noreply.github.com> Date: Wed, 2 Aug 2023 12:59:29 +0300 Subject: [PATCH 08/34] =?UTF-8?q?=F0=9F=A4=AE=F0=9F=A4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ServiceAPI/Wall.php | 1 + VKAPI/Handlers/Groups.php | 36 ++++++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/ServiceAPI/Wall.php b/ServiceAPI/Wall.php index 62b1fe2cd..1b9bcabb6 100644 --- a/ServiceAPI/Wall.php +++ b/ServiceAPI/Wall.php @@ -113,6 +113,7 @@ function declinePost(int $id, callable $resolve, callable $reject) $reject(22, "Access to post denied"); $post->setSuggested(2); + $post->setDeleted(1); $post->save(); $resolve($this->posts->getSuggestedPostsCount($post->getWallOwner()->getId())); diff --git a/VKAPI/Handlers/Groups.php b/VKAPI/Handlers/Groups.php index 3123a43f4..2937795a9 100644 --- a/VKAPI/Handlers/Groups.php +++ b/VKAPI/Handlers/Groups.php @@ -288,7 +288,7 @@ function edit( string $description = NULL, string $screen_name = NULL, string $website = NULL, - int $wall = NULL, + int $wall = -1, int $topics = NULL, int $adminlist = NULL, int $topicsAboveWall = NULL, @@ -303,17 +303,29 @@ function edit( if(!$club || !$club->canBeModifiedBy($this->getUser())) $this->fail(15, "You can't modify this group."); if(!empty($screen_name) && !$club->setShortcode($screen_name)) $this->fail(103, "Invalid shortcode."); - !is_null($title) ? $club->setName($title) : NULL; - !is_null($description) ? $club->setAbout($description) : NULL; - !is_null($screen_name) ? $club->setShortcode($screen_name) : NULL; - !is_null($website) ? $club->setWebsite((!parse_url($website, PHP_URL_SCHEME) ? "https://" : "") . $website) : NULL; - !is_null($wall) ? $club->setWall($wall) : NULL; - !is_null($topics) ? $club->setEveryone_Can_Create_Topics($topics) : NULL; - !is_null($adminlist) ? $club->setAdministrators_List_Display($adminlist) : NULL; - !is_null($topicsAboveWall) ? $club->setDisplay_Topics_Above_Wall($topicsAboveWall) : NULL; - !is_null($hideFromGlobalFeed) ? $club->setHide_From_Global_Feed($hideFromGlobalFeed) : NULL; + !empty($title) ? $club->setName($title) : NULL; + !empty($description) ? $club->setAbout($description) : NULL; + !empty($screen_name) ? $club->setShortcode($screen_name) : NULL; + !empty($website) ? $club->setWebsite((!parse_url($website, PHP_URL_SCHEME) ? "https://" : "") . $website) : NULL; + + try { + $wall != -1 ? $club->setWall($wall) : NULL; + } catch(\Exception $e) { + $this->fail(50, "Invalid wall value"); + } - $club->save(); + !empty($topics) ? $club->setEveryone_Can_Create_Topics($topics) : NULL; + !empty($adminlist) ? $club->setAdministrators_List_Display($adminlist) : NULL; + !empty($topicsAboveWall) ? $club->setDisplay_Topics_Above_Wall($topicsAboveWall) : NULL; + !empty($hideFromGlobalFeed) ? $club->setHide_From_Global_Feed($hideFromGlobalFeed) : NULL; + + try { + $club->save(); + } catch(\TypeError $e) { + $this->fail(15, "Nothing changed"); + } catch(\Exception $e) { + $this->fail(18, "An unknown error occurred: maybe you set an incorrect value?"); + } return 1; } @@ -466,7 +478,7 @@ function getSettings(string $group_id) "title" => $club->getName(), "description" => $club->getDescription() != NULL ? $club->getDescription() : "", "address" => $club->getShortcode(), - "wall" => $club->canPost() == true ? 1 : 0, + "wall" => $club->getWallType(), # отличается от вкшных но да ладно "photos" => 1, "video" => 0, "audio" => 0, From 4ee9a0d4bf07327bb96340abfab624f0233c1bdf Mon Sep 17 00:00:00 2001 From: lalka2016 <99399973+lalka2016@users.noreply.github.com> Date: Fri, 4 Aug 2023 10:54:20 +0300 Subject: [PATCH 09/34] Change regex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Теперь оно удаляет все теги а не только
--- Web/static/js/al_wall.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Web/static/js/al_wall.js b/Web/static/js/al_wall.js index 51683bd8f..3f230a288 100644 --- a/Web/static/js/al_wall.js +++ b/Web/static/js/al_wall.js @@ -305,7 +305,7 @@ $(document).on("click", "#publish_post", async (e) => { e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = "" }), Function.noop]); - document.getElementById("pooblish").innerHTML = e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.querySelector(".really_text").innerHTML.replace(/
/g, '') + document.getElementById("pooblish").innerHTML = e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.querySelector(".really_text").innerHTML.replace(/(<([^>]+)>)/gi, '') document.querySelector(".ovk-diag-body").style.padding = "9px"; }) From 9543fb6c6b6a16d4851c1c72d96a2b4429427dda Mon Sep 17 00:00:00 2001 From: lalka2016 <99399973+lalka2016@users.noreply.github.com> Date: Fri, 4 Aug 2023 14:09:38 +0300 Subject: [PATCH 10/34] Add da koroche pohuy --- Web/Models/Entities/Club.php | 9 ++++++++- Web/Presenters/templates/@layout.xml | 11 ++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Web/Models/Entities/Club.php b/Web/Models/Entities/Club.php index 722233b76..f5f64f23f 100644 --- a/Web/Models/Entities/Club.php +++ b/Web/Models/Entities/Club.php @@ -3,7 +3,7 @@ use openvk\Web\Util\DateTime; use openvk\Web\Models\RowModel; use openvk\Web\Models\Entities\{User, Manager}; -use openvk\Web\Models\Repositories\{Users, Clubs, Albums, Managers}; +use openvk\Web\Models\Repositories\{Users, Clubs, Albums, Managers, Posts}; use Nette\Database\Table\{ActiveRow, GroupedSelection}; use Chandler\Database\DatabaseConnection as DB; use Chandler\Security\User as ChandlerUser; @@ -308,6 +308,13 @@ function getFollowers(int $page = 1, int $perPage = 6, string $sort = "follower yield $rel; } } + + function getSuggestedPostsCount() + { + $count = (new Posts)->getSuggestedPostsCount($this->getId()); + + return $count; + } function getManagers(int $page = 1, bool $ignoreHidden = false): \Traversable { diff --git a/Web/Presenters/templates/@layout.xml b/Web/Presenters/templates/@layout.xml index 1718c4990..5c006ea5a 100644 --- a/Web/Presenters/templates/@layout.xml +++ b/Web/Presenters/templates/@layout.xml @@ -214,7 +214,16 @@
{if $type == "my"}{tr("x_suggested_posts_in_group_by_you", $count)}{else}{tr("x_suggested_posts_in_group", $count)}{/if}
+{if $type == "my"}{tr("suggested_posts_in_group_by_you", $count)}{else}{tr("suggested_posts_in_group", $count)}{/if}
{foreach $posts as $post} {include "../components/post/microblogpost.xml", post => $post, commentSection => false, suggestion => true, forceNoCommentsLink => true, forceNoPinLink => true, forceNoLike => true, forceNoShareLink => true} {/foreach} diff --git a/Web/Presenters/templates/Group/View.xml b/Web/Presenters/templates/Group/View.xml index 4a588c135..5d89b1bf9 100644 --- a/Web/Presenters/templates/Group/View.xml +++ b/Web/Presenters/templates/Group/View.xml @@ -92,11 +92,11 @@{if $type == "my"}{tr("suggested_posts_in_group_by_you", $count)}{else}{tr("suggested_posts_in_group", $count)}{/if}
- {foreach $posts as $post} - {include "../components/post/microblogpost.xml", post => $post, commentSection => false, suggestion => true, forceNoCommentsLink => true, forceNoPinLink => true, forceNoLike => true, forceNoShareLink => true} - {/foreach} +
`)
+ e.currentTarget.classList.add("loaded")
+ e.currentTarget.setAttribute("value", "")
+ e.currentTarget.setAttribute("id", "")
post = await API.Wall.declinePost(id)
} catch(ex) {
switch(ex.code) {
@@ -335,6 +347,9 @@ $(document).on("click", "#decline_post", async (e) => {
break;
}
+ e.currentTarget.setAttribute("value", tr("decline_suggested"))
+ e.currentTarget.setAttribute("id", "decline_post")
+ e.currentTarget.classList.remove("loaded")
return 0;
} finally {
u("#deleteMe").remove()
@@ -343,4 +358,31 @@ $(document).on("click", "#decline_post", async (e) => {
NewNotification(tr("suggestion_succefully_declined"), "", null);
e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = ""
document.getElementById("cound").innerHTML = tr("suggested_posts_in_group", post)
+
+ if(document.querySelectorAll(".post.post-divider").length < 1 && post > 0) {
+ loadMoreSuggestedPosts()
+ }
})
+
+function loadMoreSuggestedPosts()
+{
+ let xhr = new XMLHttpRequest
+ xhr.open("GET", location.href)
+
+ xhr.onloadstart = () => {
+ document.getElementById("postz").innerHTML = `
`
+ }
+
+ xhr.onload = () => {
+ let parser = new DOMParser()
+ let body = parser.parseFromString(xhr.responseText, "text/html").getElementById("postz")
+
+ document.getElementById("postz").innerHTML = body.innerHTML
+ }
+
+ xhr.onerror = () => {
+ document.getElementById("postz").innerHTML = tr("error_loading_suggest")
+ }
+
+ xhr.send()
+}
diff --git a/locales/en.strings b/locales/en.strings
index 55290b2a0..2d245a98a 100644
--- a/locales/en.strings
+++ b/locales/en.strings
@@ -326,6 +326,8 @@
"publish_suggested" = "Accept";
"decline_suggested" = "Decline";
+"error_loading_suggest" = "Error when loading new posts";
+
"publishing_suggested_post" = "Publishing suggested post";
"suggested_posts_in_group_zero" = "You've looked at all the suggested posts, congratulations!";
"suggested_posts_in_group_one" = "This group has one suggested post";
diff --git a/locales/ru.strings b/locales/ru.strings
index ae98c60f4..5b033e7c3 100644
--- a/locales/ru.strings
+++ b/locales/ru.strings
@@ -310,6 +310,8 @@
"publish_suggested" = "Опубликовать запись";
"decline_suggested" = "Отклонить";
+"error_loading_suggest" = "Не удалось подгрузить новые посты";
+
"publishing_suggested_post" = "Публикация предложенной записи";
"suggested_posts_in_group_zero" = "Вы посмотрели всю предложку, поздравляю!";
"suggested_posts_in_group_one" = "В эту группу предложили одну запись";
From c4c476ed8b07bd3d0200bc1b21bbf2859cd4562e Mon Sep 17 00:00:00 2001
From: lalka2016 <99399973+lalka2016@users.noreply.github.com>
Date: Sun, 6 Aug 2023 22:49:28 +0300
Subject: [PATCH 17/34] Update JOERGK.strings
---
locales/en.strings | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/locales/en.strings b/locales/en.strings
index 2d245a98a..15681897e 100644
--- a/locales/en.strings
+++ b/locales/en.strings
@@ -343,7 +343,7 @@
"suggestion_succefully_published" = "Post successfully published";
"suggestion_succefully_declined" = "Post successfully declined";
-"suggestion_press_to_go" = "Click to show him";
+"suggestion_press_to_go" = "Click to show it";
"error_declining_invalid_post" = "Error when declining post: post does not exists";
"error_declining_not_suggested_post" = "Error when declining post: post is not suggested";
From 222601383df5b4be287db3e81d08cd5be5f2aa50 Mon Sep 17 00:00:00 2001
From: lalka2016 <99399973+lalka2016@users.noreply.github.com>
Date: Mon, 7 Aug 2023 09:30:57 +0300
Subject: [PATCH 18/34] Blin
---
VKAPI/Handlers/Wall.php | 118 +++++++++++++++++-----------------------
1 file changed, 51 insertions(+), 67 deletions(-)
diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php
index 0f5fa2c3f..a8bf9721d 100644
--- a/VKAPI/Handlers/Wall.php
+++ b/VKAPI/Handlers/Wall.php
@@ -57,8 +57,6 @@ function get(int $owner_id, string $domain = "", int $offset = 0, int $count = 3
case "postponed":
$this->fail(66666, "Otlojka is not implemented :)");
break;
- # В вкапи, походу, нету метода, который бы публиковал запись из предложки.
- # Либо он закрыт для неофициальных клиентов, как gifts.send
case "suggests":
if($owner_id < 0) {
if($wallOnwer->getWallType() != 2)
@@ -419,7 +417,7 @@ function getById(string $posts, int $extended = 0, string $fields = "", User $us
];
}
- function post(string $owner_id, string $message = "", int $from_group = 0, int $signed = 0, string $attachments = ""): object
+ function post(string $owner_id, string $message = "", int $from_group = 0, int $signed = 0, string $attachments = "", int $post_id = 0): object
{
$this->requireUser();
$this->willExecuteWriteAction();
@@ -440,6 +438,45 @@ function post(string $owner_id, string $message = "", int $from_group = 0, int $
if($canPost == false) $this->fail(15, "Access denied");
+ if($post_id > 0) {
+ if($owner_id > 0) {
+ $this->fail(62, "Suggested posts available only at groups");
+ }
+
+ $post = (new PostsRepo)->getPostById($owner_id, $post_id, true);
+
+ if(!$post || $post->isDeleted())
+ $this->fail(32, "Invald post");
+
+ if($post->getSuggestionType() == 0)
+ $this->fail(20, "Post is not suggested");
+
+ if($post->getSuggestionType() == 2)
+ $this->fail(16, "Post is declined");
+
+ if(!$post->canBePinnedBy($this->getUser()))
+ $this->fail(51, "Access denied");
+
+ $author = $post->getOwner();
+ $flags = 0;
+ $flags |= 0b10000000;
+
+ if($signed == 1)
+ $flags |= 0b01000000;
+
+ $post->setSuggested(0);
+ $post->setCreated(time());
+ $post->setFlags($flags);
+
+ if(!empty($message) && iconv_strlen($message) > 0)
+ $post->setContent($message);
+
+ $post->save();
+ (new PostAcceptedNotification($author, $post, $post->getWallOwner()))->emit();
+
+ return (object)["post_id" => $post->getVirtualId()];
+ }
+
$anon = OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["anonymousPosting"]["enable"];
if($wallOwner instanceof Club && $from_group == 1 && $signed != 1 && $anon) {
$manager = $wallOwner->getManager($this->getUser());
@@ -837,78 +874,25 @@ function deleteComment(int $comment_id) {
return 1;
}
- # !!! Нестандартный метод
- function acceptPost(int $club, int $post_id, string $new_message = "", bool $sign = true)
+ function delete(int $owner_id, int $post_id)
{
$this->requireUser();
$this->willExecuteWriteAction();
- if($club < 0) {
- $this->fail(62, "Club's id is negative");
- }
-
- $post = (new PostsRepo)->getPostById($club * -1, $post_id, true);
+ $post = (new PostsRepo)->getPostById($owner_id, $post_id, true);
if(!$post || $post->isDeleted())
- $this->fail(32, "Invald post");
-
- if($post->getSuggestionType() == 0)
- $this->fail(20, "Post is not suggested");
+ $this->fail(583, "Invalid post");
- if($post->getSuggestionType() == 2)
- $this->fail(16, "Post is declined");
-
- if(!$post->canBePinnedBy($this->getUser()))
- $this->fail(51, "Access denied");
-
- $author = $post->getOwner();
- $flags = 0;
- $flags |= 0b10000000;
-
- if($sign)
- $flags |= 0b01000000;
-
- $post->setSuggested(0);
- $post->setCreated(time());
- $post->setFlags($flags);
-
- if(!empty($new_message) && iconv_strlen($new_message) > 0)
- $post->setContent($new_message);
-
- $post->save();
- (new PostAcceptedNotification($author, $post, $post->getWallOwner()))->emit();
-
- return 1;
- }
-
- # !!! Нестандартный метод
- function declinePost(int $club, int $post_id)
- {
- $this->requireUser();
- $this->willExecuteWriteAction();
+ $wallOwner = $post->getWallOwner();
- if($club < 0) {
- $this->fail(62, "Club's id is negative");
- }
-
- $post = (new PostsRepo)->getPostById($club * -1, $post_id, true);
-
- if(!$post || $post->isDeleted())
- $this->fail(32, "Invald post");
-
- if($post->getSuggestionType() == 0)
- $this->fail(20, "Post is not suggested");
-
- if($post->getSuggestionType() == 2)
- $this->fail(16, "Post is already declined");
+ if($post->getOwnerPost() == $this->getUser()->getId() || $post->getTargetWall() == $this->getUser()->getId() || $owner_id < 0 && $wallOwner->canBeModifiedBy($this->getUser())) {
+ $post->unwire();
+ $post->delete();
- if(!$post->canBePinnedBy($this->getUser()))
- $this->fail(51, "Access denied");
-
- $post->setSuggested(2);
- $post->setDeleted(1);
- $post->save();
-
- return 1;
+ return 1;
+ } else {
+ $this->fail(15, "Access denied");
+ }
}
private function getApiPhoto($attachment) {
From ccf618a5ab6d7f5bb5230a89962d76f74b443ab0 Mon Sep 17 00:00:00 2001
From: lalka2016 <99399973+lalka2016@users.noreply.github.com>
Date: Wed, 9 Aug 2023 12:53:36 +0300
Subject: [PATCH 19/34] Remove repeated code, fix loaded buttons on chr...
...ome and fix getting suggested posts via API.Wall.getPost
---
ServiceAPI/Wall.php | 7 ++-
Web/Presenters/GroupPresenter.php | 53 ++++---------------
Web/Presenters/templates/@layout.xml | 2 +-
Web/Presenters/templates/Group/View.xml | 2 +-
.../components/notifications/7/_18_5_.xml | 2 +-
Web/routes.yml | 4 +-
Web/static/css/main.css | 9 +++-
7 files changed, 28 insertions(+), 51 deletions(-)
diff --git a/ServiceAPI/Wall.php b/ServiceAPI/Wall.php
index 1b9bcabb6..69397e2d7 100644
--- a/ServiceAPI/Wall.php
+++ b/ServiceAPI/Wall.php
@@ -2,7 +2,7 @@
namespace openvk\ServiceAPI;
use openvk\Web\Models\Entities\Post;
use openvk\Web\Models\Entities\User;
-use openvk\Web\Models\Entities\Notifications\{PostAcceptedNotification};
+use openvk\Web\Models\Entities\Notifications\PostAcceptedNotification;
use openvk\Web\Models\Repositories\{Posts, Notes};
class Wall implements Handler
@@ -22,7 +22,10 @@ function getPost(int $id, callable $resolve, callable $reject): void
{
$post = $this->posts->get($id);
if(!$post || $post->isDeleted())
- $reject("No post with id=$id");
+ $reject(53, "No post with id=$id");
+
+ if($post->getSuggestionType() != 0)
+ $reject(25, "Can't get suggested post");
$res = (object) [];
$res->id = $post->getId();
diff --git a/Web/Presenters/GroupPresenter.php b/Web/Presenters/GroupPresenter.php
index e1ad1ca06..07c73c183 100644
--- a/Web/Presenters/GroupPresenter.php
+++ b/Web/Presenters/GroupPresenter.php
@@ -410,7 +410,7 @@ function renderChangeOwner(int $id, int $newOwnerId): void
$this->flashFail("succ", tr("information_-1"), tr("group_owner_setted", $newOwner->getCanonicalName(), $club->getName()));
}
- function renderSuggestedThisUser(int $id)
+ function renderSuggested(int $id): void
{
$this->assertUserLoggedIn();
@@ -420,57 +420,26 @@ function renderSuggestedThisUser(int $id)
else
$this->template->club = $club;
- if($club->getWallType() == 1) {
- $this->flash("err", tr("error_suggestions"), tr("error_suggestions_closed"));
- $this->redirect("/club".$club->getId());
- }
-
if($club->getWallType() == 0) {
- $this->flash("err", tr("error_suggestions"), tr("error_suggestions_open"));
- $this->redirect("/club".$club->getId());
- }
-
- if($club->canBeModifiedBy($this->user->identity)) {
- $this->flash("err", tr("error_suggestions"), "No sense");
- $this->redirect("/club".$club->getId());
- }
-
- $this->template->posts = (new Posts)->getSuggestedPostsByUser($club->getId(), $this->user->id, (int) ($this->queryParam("p") ?? 1));
- $this->template->count = (new Posts)->getSuggestedPostsCountByUser($club->getId(), $this->user->id);
- $this->template->type = "my";
- $this->template->page = (int) ($this->queryParam("p") ?? 1);
- $this->template->_template = "Group/Suggested.xml";
- }
-
- function renderSuggestedAll(int $id)
- {
- $this->assertUserLoggedIn();
-
- $club = $this->clubs->get($id);
- if(!$club)
- $this->notFound();
- else
- $this->template->club = $club;
-
- if($club->getWallType() == 1) {
$this->flash("err", tr("error_suggestions"), tr("error_suggestions_closed"));
$this->redirect("/club".$club->getId());
}
-
- if($club->getWallType() == 0) {
+
+ if($club->getWallType() == 1) {
$this->flash("err", tr("error_suggestions"), tr("error_suggestions_open"));
$this->redirect("/club".$club->getId());
}
-
+
if(!$club->canBeModifiedBy($this->user->identity)) {
- $this->flash("err", tr("error_suggestions"), tr("error_suggestions_access"));
- $this->redirect("/club".$club->getId());
+ $this->template->posts = (new Posts)->getSuggestedPostsByUser($club->getId(), $this->user->id, (int) ($this->queryParam("p") ?? 1));
+ $this->template->count = (new Posts)->getSuggestedPostsCountByUser($club->getId(), $this->user->id);
+ $this->template->type = "my";
+ } else {
+ $this->template->posts = (new Posts)->getSuggestedPosts($club->getId(), (int) ($this->queryParam("p") ?? 1));
+ $this->template->count = (new Posts)->getSuggestedPostsCount($club->getId());
+ $this->template->type = "everyone";
}
- $this->template->posts = (new Posts)->getSuggestedPosts($club->getId(), (int) ($this->queryParam("p") ?? 1));
- $this->template->count = (new Posts)->getSuggestedPostsCount($club->getId());
- $this->template->type = "everyone";
$this->template->page = (int) ($this->queryParam("p") ?? 1);
- $this->template->_template = "Group/Suggested.xml";
}
}
diff --git a/Web/Presenters/templates/@layout.xml b/Web/Presenters/templates/@layout.xml
index 5c006ea5a..e9aecafbc 100644
--- a/Web/Presenters/templates/@layout.xml
+++ b/Web/Presenters/templates/@layout.xml
@@ -219,7 +219,7 @@
{$club->getName()}
diff --git a/Web/Presenters/templates/Group/View.xml b/Web/Presenters/templates/Group/View.xml
index 5d89b1bf9..8abfc5ef8 100644
--- a/Web/Presenters/templates/Group/View.xml
+++ b/Web/Presenters/templates/Group/View.xml
@@ -96,7 +96,7 @@
{if $type == "my"}{tr("suggested_posts_in_group_by_you", $count)}{else}{tr("suggested_posts_in_group", $count)}{/if}
- + {$post->getPublicationTime()}{if $post->isPinned()}, {_pinned}{/if}
! Этот пост был размещён за взятку. diff --git a/Web/static/js/al_wall.js b/Web/static/js/al_wall.js index f4f543f8b..1812ac415 100644 --- a/Web/static/js/al_wall.js +++ b/Web/static/js/al_wall.js @@ -308,9 +308,22 @@ $(document).on("click", "#publish_post", async (e) => { NewNotification(tr("suggestion_succefully_published"), tr("suggestion_press_to_go"), null, () => {window.location.assign("/wall" + post.id)}); document.getElementById("cound").innerHTML = tr("suggested_posts_in_group", post.new_count) - e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = "" + + if(document.querySelector("object a[href='"+location.pathname+"'] b") != null) { + document.querySelector("object a[href='"+location.pathname+"'] b").innerHTML = post.new_count + + if(post.new_count < 1) { + u("object a[href='"+location.pathname+"']").remove() + } + } + + if(e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.tagName == "TABLE") { + e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = "" + } else { + e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = "" + } - if(document.querySelectorAll(".post.post-divider").length < 1 && post.new_count > 0) { + if(document.querySelectorAll(".post").length < 1 && post.new_count > 0) { loadMoreSuggestedPosts() } }), Function.noop]); @@ -351,15 +364,27 @@ $(document).on("click", "#decline_post", async (e) => { e.currentTarget.setAttribute("id", "decline_post") e.currentTarget.classList.remove("loaded") return 0; - } finally { - u("#deleteMe").remove() } - NewNotification(tr("suggestion_succefully_declined"), "", null); - e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = "" + //NewNotification(tr("suggestion_succefully_declined"), "", null); + + if(e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.tagName == "TABLE") { + e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = "" + } else { + e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = "" + } + document.getElementById("cound").innerHTML = tr("suggested_posts_in_group", post) - if(document.querySelectorAll(".post.post-divider").length < 1 && post > 0) { + if(document.querySelector("object a[href='"+location.pathname+"'] b") != null) { + document.querySelector("object a[href='"+location.pathname+"'] b").innerHTML = post + + if(post < 1) { + u("object a[href='"+location.pathname+"']").remove() + } + } + + if(document.querySelectorAll(".post").length < 1 && post > 0) { loadMoreSuggestedPosts() } }) @@ -377,6 +402,20 @@ function loadMoreSuggestedPosts() let parser = new DOMParser() let body = parser.parseFromString(xhr.responseText, "text/html").getElementById("postz") + if(body.querySelectorAll(".post").length < 1) { + let url = new URL(location.href) + url.searchParams.set("p", url.searchParams.get("p") - 1) + + if(url.searchParams.get("p") < 1) { + return 0; + } + + // OVK AJAX ROUTING ?????????? + history.pushState({}, "", url) + + loadMoreSuggestedPosts() + } + document.getElementById("postz").innerHTML = body.innerHTML } From adef21d3a93e19413bf1ae8703248523512ad7c3 Mon Sep 17 00:00:00 2001 From: lalka2016 <99399973+lalka2016@users.noreply.github.com> Date: Sat, 12 Aug 2023 12:26:39 +0300 Subject: [PATCH 22/34] Remove ability to delete your accepted psto --- VKAPI/Handlers/Wall.php | 3 +++ Web/Models/Entities/Post.php | 3 +++ Web/Presenters/WallPresenter.php | 3 +++ Web/static/js/al_wall.js | 4 ++-- locales/en.strings | 1 + locales/ru.strings | 1 + 6 files changed, 13 insertions(+), 2 deletions(-) diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index 058b40e60..9d1f0ad5f 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -887,6 +887,9 @@ function delete(int $owner_id, int $post_id) $wallOwner = $post->getWallOwner(); + if($post->getTargetWall() < 0 && !$post->getWallOwner()->canBeModifiedBy($this->getUser()) && $post->getWallOwner()->getWallType() != 1) + $this->fail(12, "Access denied: you can't delete your accepted post."); + if($post->getOwnerPost() == $this->getUser()->getId() || $post->getTargetWall() == $this->getUser()->getId() || $owner_id < 0 && $wallOwner->canBeModifiedBy($this->getUser())) { $post->unwire(); $post->delete(); diff --git a/Web/Models/Entities/Post.php b/Web/Models/Entities/Post.php index 5f2d3d4d2..3374301b1 100644 --- a/Web/Models/Entities/Post.php +++ b/Web/Models/Entities/Post.php @@ -207,6 +207,9 @@ function canBePinnedBy(User $user): bool function canBeDeletedBy(User $user): bool { + if($this->getTargetWall() < 0 && !$this->getWallOwner()->canBeModifiedBy($user) && $this->getWallOwner()->getWallType() != 1) + return false; + return $this->getOwnerPost() === $user->getId() || $this->canBePinnedBy($user); } diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index 39b7e32bc..1dd19349c 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -492,6 +492,9 @@ function renderDelete(int $wall, int $post_id): void else $canBeDeletedByOtherUser = false; if(!is_null($user)) { + if($post->getTargetWall() < 0 && !$post->getWallOwner()->canBeModifiedBy($this->user->identity) && $post->getWallOwner()->getWallType() != 1) + $this->flashFail("err", tr("failed_to_delete_post"), tr("error_deleting_suggested")); + if($post->getOwnerPost() == $user || $post->getTargetWall() == $user || $canBeDeletedByOtherUser) { $post->unwire(); $post->delete(); diff --git a/Web/static/js/al_wall.js b/Web/static/js/al_wall.js index 1812ac415..b1ca61171 100644 --- a/Web/static/js/al_wall.js +++ b/Web/static/js/al_wall.js @@ -323,7 +323,7 @@ $(document).on("click", "#publish_post", async (e) => { e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = "" } - if(document.querySelectorAll(".post").length < 1 && post.new_count > 0) { + if(document.querySelectorAll(".post").length < 1 && post.new_count > 0 && document.querySelector(".paginator") != null) { loadMoreSuggestedPosts() } }), Function.noop]); @@ -384,7 +384,7 @@ $(document).on("click", "#decline_post", async (e) => { } } - if(document.querySelectorAll(".post").length < 1 && post > 0) { + if(document.querySelectorAll(".post").length < 1 && post > 0 && document.querySelector(".paginator") != null) { loadMoreSuggestedPosts() } }) diff --git a/locales/en.strings b/locales/en.strings index ff1460161..f4a2fb56e 100644 --- a/locales/en.strings +++ b/locales/en.strings @@ -1180,6 +1180,7 @@ "media_file_corrupted_or_too_large" = "The media content file is corrupted or too large."; "post_is_empty_or_too_big" = "The post is empty or too big."; "post_is_too_big" = "The post is too big."; +"error_deleting_suggested" = "You can't delete your accepted post"; /* Admin actions */ diff --git a/locales/ru.strings b/locales/ru.strings index 0f37bfe8b..87c966e4a 100644 --- a/locales/ru.strings +++ b/locales/ru.strings @@ -1080,6 +1080,7 @@ "media_file_corrupted_or_too_large" = "Файл медиаконтента повреждён или слишком велик."; "post_is_empty_or_too_big" = "Пост пустой или слишком большой."; "post_is_too_big" = "Пост слишком большой."; +"error_deleting_suggested" = "Вы не можете удалить ваш принятый пост"; /* Admin actions */ From f58518300cd1b323b5de99200e58bb8059e49b8c Mon Sep 17 00:00:00 2001 From: lalka2016 <99399973+lalka2016@users.noreply.github.com> Date: Sun, 13 Aug 2023 19:17:34 +0300 Subject: [PATCH 23/34] oi blin --- VKAPI/Handlers/Wall.php | 2 +- Web/Models/Entities/Post.php | 2 +- Web/Presenters/WallPresenter.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index 9d1f0ad5f..3b8a9d3d4 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -887,7 +887,7 @@ function delete(int $owner_id, int $post_id) $wallOwner = $post->getWallOwner(); - if($post->getTargetWall() < 0 && !$post->getWallOwner()->canBeModifiedBy($this->getUser()) && $post->getWallOwner()->getWallType() != 1) + if($post->getTargetWall() < 0 && !$post->getWallOwner()->canBeModifiedBy($this->getUser()) && $post->getWallOwner()->getWallType() != 1 && $post->getSuggestionType() == 0) $this->fail(12, "Access denied: you can't delete your accepted post."); if($post->getOwnerPost() == $this->getUser()->getId() || $post->getTargetWall() == $this->getUser()->getId() || $owner_id < 0 && $wallOwner->canBeModifiedBy($this->getUser())) { diff --git a/Web/Models/Entities/Post.php b/Web/Models/Entities/Post.php index 3374301b1..cfb86003f 100644 --- a/Web/Models/Entities/Post.php +++ b/Web/Models/Entities/Post.php @@ -207,7 +207,7 @@ function canBePinnedBy(User $user): bool function canBeDeletedBy(User $user): bool { - if($this->getTargetWall() < 0 && !$this->getWallOwner()->canBeModifiedBy($user) && $this->getWallOwner()->getWallType() != 1) + if($this->getTargetWall() < 0 && !$this->getWallOwner()->canBeModifiedBy($user) && $this->getWallOwner()->getWallType() != 1 && $this->getSuggestionType() == 0) return false; return $this->getOwnerPost() === $user->getId() || $this->canBePinnedBy($user); diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index 1dd19349c..384086548 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -492,7 +492,7 @@ function renderDelete(int $wall, int $post_id): void else $canBeDeletedByOtherUser = false; if(!is_null($user)) { - if($post->getTargetWall() < 0 && !$post->getWallOwner()->canBeModifiedBy($this->user->identity) && $post->getWallOwner()->getWallType() != 1) + if($post->getTargetWall() < 0 && !$post->getWallOwner()->canBeModifiedBy($this->user->identity) && $post->getWallOwner()->getWallType() != 1 && $post->getSuggestionType() == 0) $this->flashFail("err", tr("failed_to_delete_post"), tr("error_deleting_suggested")); if($post->getOwnerPost() == $user || $post->getTargetWall() == $user || $canBeDeletedByOtherUser) { From c8ef5ccd6417b28f5dddc8762aa8e70c0593d108 Mon Sep 17 00:00:00 2001 From: lalka2016 <99399973+lalka2016@users.noreply.github.com> Date: Tue, 15 Aug 2023 10:21:06 +0300 Subject: [PATCH 24/34] Improvements 2 api --- VKAPI/Handlers/Groups.php | 35 ++++++++++++++++- VKAPI/Handlers/Newsfeed.php | 2 +- VKAPI/Handlers/Wall.php | 41 +++++++++++++++++--- Web/Presenters/templates/@layout.xml | 2 +- Web/Presenters/templates/Group/Suggested.xml | 14 ++++--- 5 files changed, 80 insertions(+), 14 deletions(-) diff --git a/VKAPI/Handlers/Groups.php b/VKAPI/Handlers/Groups.php index 2937795a9..5a5487da3 100644 --- a/VKAPI/Handlers/Groups.php +++ b/VKAPI/Handlers/Groups.php @@ -2,6 +2,7 @@ namespace openvk\VKAPI\Handlers; use openvk\Web\Models\Repositories\Clubs as ClubsRepo; use openvk\Web\Models\Repositories\Users as UsersRepo; +use openvk\Web\Models\Repositories\Posts as PostsRepo; use openvk\Web\Models\Entities\Club; final class Groups extends VKAPIRequestHandler @@ -81,6 +82,22 @@ function get(int $user_id = 0, string $fields = "", int $offset = 0, int $count case "members_count": $rClubs[$i]->members_count = $usr->getFollowersCount(); break; + case "can_suggest": + $rClubs[$i]->can_suggest = !$usr->canBeModifiedBy($this->getUser()) && $usr->getWallType() == 2; + break; + # unstandard feild + case "suggested_count": + if($usr->getWallType() != 2) { + $rClubs[$i]->suggested_count = NULL; + break; + } + + if($usr->canBeModifiedBy($this->getUser())) + $rClubs[$i]->suggested_count = $usr->getSuggestedPostsCount(); + else + $rClubs[$i]->suggested_count = (new PostsRepo)->getSuggestedPostsCountByUser($usr->getId(), $this->getUser()->getId()); + + break; } } } @@ -188,7 +205,23 @@ function getById(string $group_ids = "", string $group_id = "", string $fields = case "description": $response[$i]->description = $clb->getDescription(); break; - case "contacts": + case "can_suggest": + $response[$i]->can_suggest = !$clb->canBeModifiedBy($this->getUser()) && $clb->getWallType() == 2; + break; + # unstandard feild + case "suggested_count": + if($clb->getWallType() != 2) { + $response[$i]->suggested_count = NULL; + break; + } + + if($clb->canBeModifiedBy($this->getUser())) + $response[$i]->suggested_count = $clb->getSuggestedPostsCount(); + else + $response[$i]->suggested_count = (new PostsRepo)->getSuggestedPostsCountByUser($clb->getId(), $this->getUser()->getId()); + + break; + case "contacts": $contacts; $contactTmp = $clb->getManagers(1, true); diff --git a/VKAPI/Handlers/Newsfeed.php b/VKAPI/Handlers/Newsfeed.php index d99924304..4833e7beb 100644 --- a/VKAPI/Handlers/Newsfeed.php +++ b/VKAPI/Handlers/Newsfeed.php @@ -51,7 +51,7 @@ function getGlobal(string $fields = "", int $start_from = 0, int $start_time = 0 { $this->requireUser(); - $queryBase = "FROM `posts` LEFT JOIN `groups` ON GREATEST(`posts`.`wall`, 0) = 0 AND `groups`.`id` = ABS(`posts`.`wall`) WHERE (`groups`.`hide_from_global_feed` = 0 OR `groups`.`name` IS NULL) AND `posts`.`deleted` = 0"; + $queryBase = "FROM `posts` LEFT JOIN `groups` ON GREATEST(`posts`.`wall`, 0) = 0 AND `groups`.`id` = ABS(`posts`.`wall`) WHERE (`groups`.`hide_from_global_feed` = 0 OR `groups`.`name` IS NULL) AND `posts`.`deleted` = 0 AND `posts`.`suggested` = 0"; if($this->getUser()->getNsfwTolerance() === User::NSFW_INTOLERANT) $queryBase .= " AND `nsfw` = 0"; diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index 3b8a9d3d4..4242d46e7 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -49,13 +49,13 @@ function get(int $owner_id, string $domain = "", int $offset = 0, int $count = 3 $cnt = $posts->getPostCountOnUserWall($owner_id); break; case "owner": - $this->fail(66666, "Not implemented :("); + $this->fail(66666, "Not implemented"); break; case "others": - $this->fail(66666, "Not implemented :("); + $this->fail(66666, "Not implemented"); break; case "postponed": - $this->fail(66666, "Otlojka is not implemented :)"); + $this->fail(66666, "Postponed posts are not implemented."); break; case "suggests": if($owner_id < 0) { @@ -149,12 +149,23 @@ function get(int $owner_id, string $domain = "", int $offset = 0, int $count = 3 ]; } + $postType = "post"; + $signerId = NULL; + if($post->getSuggestionType() != 0) { + $postType = "suggest"; + } + + if($post->isSigned()) { + $actualAuthor = $post->getOwner(false); + $signerId = $actualAuthor->getId(); + } + $items[] = (object)[ "id" => $post->getVirtualId(), "from_id" => $from_id, "owner_id" => $post->getTargetWall(), "date" => $post->getPublicationTime()->timestamp(), - "post_type" => "post", + "post_type" => $postType, "text" => $post->getText(false), "copy_history" => $repost, "can_edit" => 0, # TODO @@ -166,6 +177,7 @@ function get(int $owner_id, string $domain = "", int $offset = 0, int $count = 3 "is_explicit" => $post->isExplicit(), "attachments" => $attachments, "post_source" => $post_source, + "signer_id" => $signerId, "comments" => (object)[ "count" => $post->getCommentsCount(), "can_post" => 1 @@ -187,6 +199,9 @@ function get(int $owner_id, string $domain = "", int $offset = 0, int $count = 3 else $groups[] = $from_id * -1; + /*if($post->isSigned()) + $profiles[] = $post->getOwner(false)->getId();*/ + $attachments = NULL; # free attachments so it will not clone everythingg } @@ -324,12 +339,24 @@ function getById(string $posts, int $extended = 0, string $fields = "", User $us ]; } + # TODO: $post->getVkApiType() + $postType = "post"; + $signerId = NULL; + if($post->getSuggestionType() != 0) { + $postType = "suggest"; + } + + if($post->isSigned()) { + $actualAuthor = $post->getOwner(false); + $signerId = $actualAuthor->getId(); + } + $items[] = (object)[ "id" => $post->getVirtualId(), "from_id" => $from_id, "owner_id" => $post->getTargetWall(), "date" => $post->getPublicationTime()->timestamp(), - "post_type" => "post", + "post_type" => $postType, "text" => $post->getText(false), "copy_history" => $repost, "can_edit" => 0, # TODO @@ -340,6 +367,7 @@ function getById(string $posts, int $extended = 0, string $fields = "", User $us "is_pinned" => $post->isPinned(), "is_explicit" => $post->isExplicit(), "post_source" => $post_source, + "signer_id" => $signerId, "attachments" => $attachments, "comments" => (object)[ "count" => $post->getCommentsCount(), @@ -362,6 +390,9 @@ function getById(string $posts, int $extended = 0, string $fields = "", User $us else $groups[] = $from_id * -1; + /*if($post->isSigned()) + $profiles[] = $post->getOwner(false)->getId();*/ + $attachments = NULL; # free attachments so it will not clone everything $repost = NULL; # same } diff --git a/Web/Presenters/templates/@layout.xml b/Web/Presenters/templates/@layout.xml index ccb6994ae..389415bbc 100644 --- a/Web/Presenters/templates/@layout.xml +++ b/Web/Presenters/templates/@layout.xml @@ -234,7 +234,7 @@ {$club->getName()} diff --git a/Web/Presenters/templates/Group/Suggested.xml b/Web/Presenters/templates/Group/Suggested.xml index 56e836eff..a7c824f68 100644 --- a/Web/Presenters/templates/Group/Suggested.xml +++ b/Web/Presenters/templates/Group/Suggested.xml @@ -12,14 +12,16 @@ {include "../components/error.xml", title => "", description => $type == "my" ? tr("no_suggested_posts_by_you") : tr("no_suggested_posts_by_people")} {else}
{if $type == "my"}{tr("suggested_posts_in_group_by_you", $count)}{else}{tr("suggested_posts_in_group", $count)}{/if}
-{if $type == "my"}{tr("suggested_posts_in_group_by_you", $count)}{else}{tr("suggested_posts_in_group", $count)}{/if}
`
@@ -425,3 +440,65 @@ function loadMoreSuggestedPosts()
xhr.send()
}
+
+// нажатие на "x предложенных записей"
+$(document).on("click", ".sugglist a", (e) => {
+ e.preventDefault()
+
+ if(e.currentTarget.getAttribute("data-toogled") == null || e.currentTarget.getAttribute("data-toogled") == "false") {
+ e.currentTarget.setAttribute("data-toogled", "true")
+ document.getElementById("underHeader").style.display = "none"
+ document.querySelector(".insertThere").style.display = "block"
+ history.pushState({}, "", e.currentTarget.href)
+
+ // если ещё ничего не подгружалось
+ if(document.querySelector(".insertThere").innerHTML == "") {
+ let xhr = new XMLHttpRequest
+ xhr.open("GET", e.currentTarget.href)
+
+ xhr.onloadstart = () => {
+ // лоадер
+ document.querySelector(".insertThere").insertAdjacentHTML("afterbegin", `
`)
+ }
+
+ xhr.onload = () => {
+ let parser = new DOMParser
+ let result = parser.parseFromString(xhr.responseText, 'text/html').querySelector(".infContainer")
+ // парсинг результата и вставка постов
+ document.querySelector(".insertThere").innerHTML = result.innerHTML
+ }
+
+ xhr.send()
+ }
+ } else {
+ // переключение на нормальную стену
+ e.currentTarget.setAttribute("data-toogled", "false")
+ document.getElementById("underHeader").style.display = "block"
+ document.querySelector(".insertThere").style.display = "none"
+ history.pushState({}, "", e.currentTarget.href.replace("/suggested", ""))
+ }
+})
+
+// нажатие на пагинатор у постов пъедложки
+$(document).on("click", "#postz .paginator a", (e) => {
+ e.preventDefault()
+
+ let xhr = new XMLHttpRequest
+ xhr.open("GET", e.currentTarget.href)
+
+ xhr.onloadstart = () => {
+ window.scrollTo({top: 0,behavior: "smooth"})
+ // после того как долистали наверх, добавляем лоадер
+ setTimeout(() => {document.querySelector("#postz").innerHTML = `
`}, 500)
+ }
+
+ xhr.onload = () => {
+ // опять парс
+ let result = (new DOMParser).parseFromString(xhr.responseText, "text/html").querySelector(".infContainer")
+ // опять вставка
+ document.getElementById("postz").innerHTML = result.innerHTML
+ history.pushState({}, "", e.currentTarget.href)
+ }
+
+ xhr.send()
+})
\ No newline at end of file
From ba771625333e80cd22f408e60d306be0e4be869e Mon Sep 17 00:00:00 2001
From: lalka2016 <99399973+lalka2016@users.noreply.github.com>
Date: Mon, 21 Aug 2023 12:37:00 +0300
Subject: [PATCH 28/34] al_wall.js -> al_suggestions.js
---
Web/Presenters/templates/@layout.xml | 1 +
Web/static/css/main.css | 3 +-
Web/static/js/al_suggestions.js | 270 +++++++++++++++++++++++++++
Web/static/js/al_wall.js | 239 ------------------------
4 files changed, 273 insertions(+), 240 deletions(-)
create mode 100644 Web/static/js/al_suggestions.js
diff --git a/Web/Presenters/templates/@layout.xml b/Web/Presenters/templates/@layout.xml
index c8730dde9..577ecddaf 100644
--- a/Web/Presenters/templates/@layout.xml
+++ b/Web/Presenters/templates/@layout.xml
@@ -389,6 +389,7 @@
{script "js/al_api.js"}
{script "js/al_mentions.js"}
{script "js/al_polls.js"}
+ {script "js/al_suggestions.js"}
{ifset $thisUser}
{script "js/al_notifs.js"}
diff --git a/Web/static/css/main.css b/Web/static/css/main.css
index 6ff56e8d7..e7e124c70 100644
--- a/Web/static/css/main.css
+++ b/Web/static/css/main.css
@@ -2733,5 +2733,6 @@ body.article .floating_sidebar, body.article .page_content {
}
.sugglist a[data-toogled="true"] {
- color:black;
+ text-decoration: underline;
+ color:#4a4a4a;
}
diff --git a/Web/static/js/al_suggestions.js b/Web/static/js/al_suggestions.js
new file mode 100644
index 000000000..3d7a2a907
--- /dev/null
+++ b/Web/static/js/al_suggestions.js
@@ -0,0 +1,270 @@
+// "Опубликовать запись"
+$(document).on("click", "#publish_post", async (e) => {
+ let id = Number(e.currentTarget.dataset.id)
+ let post;
+ let body = `
+
+
+ `
+
+ MessageBox(tr("publishing_suggested_post"), body, [tr("publish"), tr("cancel")], [(async () => {
+ let id = Number(e.currentTarget.dataset.id)
+ let post;
+
+ try {
+ e.currentTarget.classList.add("loaded")
+ e.currentTarget.setAttribute("value", "")
+ e.currentTarget.setAttribute("id", "")
+ post = await API.Wall.acceptPost(id, document.getElementById("signatr").checked, document.getElementById("pooblish").value)
+ } catch(ex) {
+ switch(ex.code) {
+ case 11:
+ MessageBox(tr("error"), tr("error_declining_invalid_post"), [tr("ok")], [Function.noop]);
+ break;
+ case 19:
+ MessageBox(tr("error"), tr("error_declining_not_suggested_post"), [tr("ok")], [Function.noop]);
+ break;
+ case 10:
+ MessageBox(tr("error"), tr("error_declining_declined_post"), [tr("ok")], [Function.noop]);
+ break;
+ case 22:
+ MessageBox(tr("error"), "Access denied", [tr("ok")], [Function.noop]);
+ break;
+ default:
+ MessageBox(tr("error"), "Unknown error "+ex.code+": "+ex.message, [tr("ok")], [Function.noop]);
+ break;
+ }
+
+ e.currentTarget.setAttribute("value", tr("publish_suggested"))
+ e.currentTarget.classList.remove("loaded")
+ e.currentTarget.setAttribute("id", "publish_post")
+ return 0;
+ }
+
+ NewNotification(tr("suggestion_succefully_published"), tr("suggestion_press_to_go"), null, () => {window.location.assign("/wall" + post.id)});
+
+ if(document.getElementById("cound") != null) {
+ document.getElementById("cound").innerHTML = tr("suggested_posts_in_group", post.new_count)
+ } else {
+ document.getElementById("cound_r").innerHTML = tr("suggested_by_everyone", post.new_count)
+ }
+
+ if(document.querySelector("object a[href='"+location.pathname+"'] b") != null) {
+ document.querySelector("object a[href='"+location.pathname+"'] b").innerHTML = post.new_count
+
+ if(post.new_count < 1) {
+ u("object a[href='"+location.pathname+"']").remove()
+ }
+ }
+
+ if(post.new_count < 1 && document.querySelector(".sugglist") != null) {
+ $(".sugglist a").click()
+ $(".sugglist").remove()
+ }
+
+ if(e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.tagName == "TABLE") {
+ e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = ""
+ } else {
+ e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = ""
+ }
+
+ if(document.querySelectorAll("#postz .post").length < 1 && post.new_count > 0 && document.querySelector(".paginator") != null) {
+ loadMoreSuggestedPosts()
+ }
+ }), Function.noop]);
+
+ document.getElementById("pooblish").innerHTML = e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.querySelector(".really_text").innerHTML.replace(/(<([^>]+)>)/gi, '')
+ document.querySelector(".ovk-diag-body").style.padding = "9px";
+})
+
+// "Отклонить"
+$(document).on("click", "#decline_post", async (e) => {
+ let id = Number(e.currentTarget.dataset.id)
+ let post;
+
+ try {
+ e.currentTarget.classList.add("loaded")
+ e.currentTarget.setAttribute("value", "")
+ e.currentTarget.setAttribute("id", "")
+ post = await API.Wall.declinePost(id)
+ } catch(ex) {
+ switch(ex.code) {
+ case 11:
+ MessageBox(tr("error"), tr("error_declining_invalid_post"), [tr("ok")], [Function.noop]);
+ break;
+ case 19:
+ MessageBox(tr("error"), tr("error_declining_not_suggested_post"), [tr("ok")], [Function.noop]);
+ break;
+ case 10:
+ MessageBox(tr("error"), tr("error_declining_declined_post"), [tr("ok")], [Function.noop]);
+ break;
+ case 22:
+ MessageBox(tr("error"), "Access denied", [tr("ok")], [Function.noop]);
+ break;
+ default:
+ MessageBox(tr("error"), "Unknown error "+ex.code+": "+ex.message, [tr("ok")], [Function.noop]);
+ break;
+ }
+
+ e.currentTarget.setAttribute("value", tr("decline_suggested"))
+ e.currentTarget.setAttribute("id", "decline_post")
+ e.currentTarget.classList.remove("loaded")
+ return 0;
+ }
+
+ //NewNotification(tr("suggestion_succefully_declined"), "", null);
+
+ if(e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.tagName == "TABLE") {
+ e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = ""
+ } else {
+ e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = ""
+ }
+
+ if(document.getElementById("cound") != null) {
+ document.getElementById("cound").innerHTML = tr("suggested_posts_in_group", post)
+ } else {
+ document.getElementById("cound_r").innerHTML = tr("suggested_by_everyone", post)
+ }
+
+ if(document.querySelector("object a[href='"+location.pathname+"'] b") != null) {
+ document.querySelector("object a[href='"+location.pathname+"'] b").innerHTML = post
+
+ if(post < 1) {
+ u("object a[href='"+location.pathname+"']").remove()
+ }
+ }
+
+ if(post < 1 && document.querySelector(".sugglist") != null) {
+ $(".sugglist a").click()
+ $(".sugglist").remove()
+ }
+
+ if(document.querySelectorAll("#postz .post").length < 1 && post > 0 && document.querySelector(".paginator") != null) {
+ loadMoreSuggestedPosts()
+ }
+})
+
+function loadMoreSuggestedPosts()
+{
+ let xhr = new XMLHttpRequest
+ let link = location.href
+
+ if(!link.includes("/suggested")) {
+ link += "/suggested"
+ }
+
+ xhr.open("GET", link)
+
+ xhr.onloadstart = () => {
+ document.getElementById("postz").innerHTML = `
`
+ }
+
+ xhr.onload = () => {
+ let parser = new DOMParser()
+ let body = parser.parseFromString(xhr.responseText, "text/html").getElementById("postz")
+
+ if(body.querySelectorAll(".post").length < 1) {
+ let url = new URL(location.href)
+ url.searchParams.set("p", url.searchParams.get("p") - 1)
+
+ if(url.searchParams.get("p") < 1) {
+ return 0;
+ }
+
+ // OVK AJAX ROUTING ??????????
+ history.pushState({}, "", url)
+
+ loadMoreSuggestedPosts()
+ }
+
+ document.getElementById("postz").innerHTML = body.innerHTML
+ }
+
+ xhr.onerror = () => {
+ document.getElementById("postz").innerHTML = tr("error_loading_suggest")
+ }
+
+ xhr.send()
+}
+
+// нажатие на "x предложенных записей"
+$(document).on("click", ".sugglist a", (e) => {
+ e.preventDefault()
+
+ if(e.currentTarget.getAttribute("data-toogled") == null || e.currentTarget.getAttribute("data-toogled") == "false") {
+ e.currentTarget.setAttribute("data-toogled", "true")
+ document.getElementById("underHeader").style.display = "none"
+ document.querySelector(".insertThere").style.display = "block"
+ document.querySelector(".insertThere").classList.add("infContainer")
+ history.pushState({}, "", e.currentTarget.href)
+
+ // если ещё ничего не подгружалось
+ if(document.querySelector(".insertThere").innerHTML == "") {
+ let xhr = new XMLHttpRequest
+ xhr.open("GET", e.currentTarget.href)
+
+ xhr.onloadstart = () => {
+ // лоадер
+ document.querySelector(".insertThere").insertAdjacentHTML("afterbegin", `
`)
+ }
+
+ xhr.onload = () => {
+ let parser = new DOMParser
+ let result = parser.parseFromString(xhr.responseText, 'text/html').querySelector(".infContainer")
+ // парсинг результата и вставка постов
+ document.querySelector(".insertThere").innerHTML = result.innerHTML
+ }
+
+ function errorl() {
+ document.getElementById("postz").innerHTML = tr("error_loading_suggest")
+ }
+
+ xhr.onerror = () => {errorl()}
+ xhr.ontimeout = () => {errorl()}
+
+ xhr.send()
+ }
+ } else {
+ // переключение на нормальную стену
+ e.currentTarget.setAttribute("data-toogled", "false")
+ document.getElementById("underHeader").style.display = "block"
+ document.querySelector(".insertThere").style.display = "none"
+ document.querySelector(".insertThere").classList.remove("infContainer")
+ history.pushState({}, "", e.currentTarget.href.replace("/suggested", ""))
+ }
+})
+
+// нажатие на пагинатор у постов пъедложки
+$(document).on("click", "#postz .paginator a", (e) => {
+ e.preventDefault()
+
+ let xhr = new XMLHttpRequest
+ xhr.open("GET", e.currentTarget.href)
+
+ xhr.onloadstart = () => {
+ if(document.querySelector(".sugglist") != null) {
+ document.querySelector(".sugglist").scrollIntoView({behavior: "smooth"})
+ } else {
+ document.querySelector(".infContainer").scrollIntoView({behavior: "smooth"})
+ }
+ // после того как долистали наверх, добавляем лоадер
+ setTimeout(() => {document.getElementById("postz").innerHTML = `
`}, 500)
+ }
+
+ xhr.onload = () => {
+ // опять парс
+ let result = (new DOMParser).parseFromString(xhr.responseText, "text/html").querySelector(".infContainer")
+ // опять вставка
+ document.getElementById("postz").innerHTML = result.innerHTML
+ history.pushState({}, "", e.currentTarget.href)
+ }
+
+ function errorl() {
+ document.getElementById("postz").innerHTML = tr("error_loading_suggest")
+ }
+
+ xhr.onerror = () => {errorl()}
+ xhr.ontimeout = () => {errorl()}
+
+ xhr.send()
+})
diff --git a/Web/static/js/al_wall.js b/Web/static/js/al_wall.js
index 639603d1a..50e9f4b44 100644
--- a/Web/static/js/al_wall.js
+++ b/Web/static/js/al_wall.js
@@ -263,242 +263,3 @@ async function showArticle(note_id) {
u("body").removeClass("dimmed");
u("body").addClass("article");
}
-
-$(document).on("click", "#publish_post", async (e) => {
- let id = Number(e.currentTarget.dataset.id)
- let post;
- let body = `
-
-
- `
-
- MessageBox(tr("publishing_suggested_post"), body, [tr("publish"), tr("cancel")], [(async () => {
- let id = Number(e.currentTarget.dataset.id)
- let post;
-
- try {
- e.currentTarget.classList.add("loaded")
- e.currentTarget.setAttribute("value", "")
- e.currentTarget.setAttribute("id", "")
- post = await API.Wall.acceptPost(id, document.getElementById("signatr").checked, document.getElementById("pooblish").value)
- } catch(ex) {
- switch(ex.code) {
- case 11:
- MessageBox(tr("error"), tr("error_declining_invalid_post"), [tr("ok")], [Function.noop]);
- break;
- case 19:
- MessageBox(tr("error"), tr("error_declining_not_suggested_post"), [tr("ok")], [Function.noop]);
- break;
- case 10:
- MessageBox(tr("error"), tr("error_declining_declined_post"), [tr("ok")], [Function.noop]);
- break;
- case 22:
- MessageBox(tr("error"), "Access denied", [tr("ok")], [Function.noop]);
- break;
- default:
- MessageBox(tr("error"), "Unknown error "+ex.code+": "+ex.message, [tr("ok")], [Function.noop]);
- break;
- }
-
- e.currentTarget.setAttribute("value", tr("publish_suggested"))
- e.currentTarget.classList.remove("loaded")
- e.currentTarget.setAttribute("id", "publish_post")
- return 0;
- }
-
- NewNotification(tr("suggestion_succefully_published"), tr("suggestion_press_to_go"), null, () => {window.location.assign("/wall" + post.id)});
-
- if(document.getElementById("cound") != null) {
- document.getElementById("cound").innerHTML = tr("suggested_posts_in_group", post.new_count)
- } else {
- document.getElementById("cound_r").innerHTML = tr("suggested_by_everyone", post.new_count)
- }
-
- if(document.querySelector("object a[href='"+location.pathname+"'] b") != null) {
- document.querySelector("object a[href='"+location.pathname+"'] b").innerHTML = post.new_count
-
- if(post.new_count < 1) {
- u("object a[href='"+location.pathname+"']").remove()
- }
- }
-
- if(e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.tagName == "TABLE") {
- e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = ""
- } else {
- e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = ""
- }
-
- if(document.querySelectorAll("#postz .post").length < 1 && post.new_count > 0 && document.querySelector(".paginator") != null) {
- loadMoreSuggestedPosts()
- }
- }), Function.noop]);
-
- document.getElementById("pooblish").innerHTML = e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.querySelector(".really_text").innerHTML.replace(/(<([^>]+)>)/gi, '')
- document.querySelector(".ovk-diag-body").style.padding = "9px";
-})
-
-$(document).on("click", "#decline_post", async (e) => {
- let id = Number(e.currentTarget.dataset.id)
- let post;
-
- try {
- e.currentTarget.classList.add("loaded")
- e.currentTarget.setAttribute("value", "")
- e.currentTarget.setAttribute("id", "")
- post = await API.Wall.declinePost(id)
- } catch(ex) {
- switch(ex.code) {
- case 11:
- MessageBox(tr("error"), tr("error_declining_invalid_post"), [tr("ok")], [Function.noop]);
- break;
- case 19:
- MessageBox(tr("error"), tr("error_declining_not_suggested_post"), [tr("ok")], [Function.noop]);
- break;
- case 10:
- MessageBox(tr("error"), tr("error_declining_declined_post"), [tr("ok")], [Function.noop]);
- break;
- case 22:
- MessageBox(tr("error"), "Access denied", [tr("ok")], [Function.noop]);
- break;
- default:
- MessageBox(tr("error"), "Unknown error "+ex.code+": "+ex.message, [tr("ok")], [Function.noop]);
- break;
- }
-
- e.currentTarget.setAttribute("value", tr("decline_suggested"))
- e.currentTarget.setAttribute("id", "decline_post")
- e.currentTarget.classList.remove("loaded")
- return 0;
- }
-
- //NewNotification(tr("suggestion_succefully_declined"), "", null);
-
- if(e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.tagName == "TABLE") {
- e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = ""
- } else {
- e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = ""
- }
-
- if(document.getElementById("cound") != null) {
- document.getElementById("cound").innerHTML = tr("suggested_posts_in_group", post)
- } else {
- document.getElementById("cound_r").innerHTML = tr("suggested_by_everyone", post)
- }
-
- if(document.querySelector("object a[href='"+location.pathname+"'] b") != null) {
- document.querySelector("object a[href='"+location.pathname+"'] b").innerHTML = post
-
- if(post < 1) {
- u("object a[href='"+location.pathname+"']").remove()
- }
- }
-
- if(document.querySelectorAll("#postz .post").length < 1 && post > 0 && document.querySelector(".paginator") != null) {
- loadMoreSuggestedPosts()
- }
-})
-
-function loadMoreSuggestedPosts()
-{
- let xhr = new XMLHttpRequest
- let link = location.href
-
- if(!link.includes("/suggested")) {
- link += "/suggested"
- }
-
- xhr.open("GET", link)
-
- xhr.onloadstart = () => {
- document.getElementById("postz").innerHTML = `
`
- }
-
- xhr.onload = () => {
- let parser = new DOMParser()
- let body = parser.parseFromString(xhr.responseText, "text/html").getElementById("postz")
-
- if(body.querySelectorAll(".post").length < 1) {
- let url = new URL(location.href)
- url.searchParams.set("p", url.searchParams.get("p") - 1)
-
- if(url.searchParams.get("p") < 1) {
- return 0;
- }
-
- // OVK AJAX ROUTING ??????????
- history.pushState({}, "", url)
-
- loadMoreSuggestedPosts()
- }
-
- document.getElementById("postz").innerHTML = body.innerHTML
- }
-
- xhr.onerror = () => {
- document.getElementById("postz").innerHTML = tr("error_loading_suggest")
- }
-
- xhr.send()
-}
-
-// нажатие на "x предложенных записей"
-$(document).on("click", ".sugglist a", (e) => {
- e.preventDefault()
-
- if(e.currentTarget.getAttribute("data-toogled") == null || e.currentTarget.getAttribute("data-toogled") == "false") {
- e.currentTarget.setAttribute("data-toogled", "true")
- document.getElementById("underHeader").style.display = "none"
- document.querySelector(".insertThere").style.display = "block"
- history.pushState({}, "", e.currentTarget.href)
-
- // если ещё ничего не подгружалось
- if(document.querySelector(".insertThere").innerHTML == "") {
- let xhr = new XMLHttpRequest
- xhr.open("GET", e.currentTarget.href)
-
- xhr.onloadstart = () => {
- // лоадер
- document.querySelector(".insertThere").insertAdjacentHTML("afterbegin", `
`)
- }
-
- xhr.onload = () => {
- let parser = new DOMParser
- let result = parser.parseFromString(xhr.responseText, 'text/html').querySelector(".infContainer")
- // парсинг результата и вставка постов
- document.querySelector(".insertThere").innerHTML = result.innerHTML
- }
-
- xhr.send()
- }
- } else {
- // переключение на нормальную стену
- e.currentTarget.setAttribute("data-toogled", "false")
- document.getElementById("underHeader").style.display = "block"
- document.querySelector(".insertThere").style.display = "none"
- history.pushState({}, "", e.currentTarget.href.replace("/suggested", ""))
- }
-})
-
-// нажатие на пагинатор у постов пъедложки
-$(document).on("click", "#postz .paginator a", (e) => {
- e.preventDefault()
-
- let xhr = new XMLHttpRequest
- xhr.open("GET", e.currentTarget.href)
-
- xhr.onloadstart = () => {
- window.scrollTo({top: 0,behavior: "smooth"})
- // после того как долистали наверх, добавляем лоадер
- setTimeout(() => {document.querySelector("#postz").innerHTML = `
`}, 500)
- }
-
- xhr.onload = () => {
- // опять парс
- let result = (new DOMParser).parseFromString(xhr.responseText, "text/html").querySelector(".infContainer")
- // опять вставка
- document.getElementById("postz").innerHTML = result.innerHTML
- history.pushState({}, "", e.currentTarget.href)
- }
-
- xhr.send()
-})
\ No newline at end of file
From 2ddd4544e8b07f177548a9226cf31003d1de4fa4 Mon Sep 17 00:00:00 2001
From: lalka2016 <99399973+lalka2016@users.noreply.github.com>
Date: Sun, 27 Aug 2023 17:47:10 +0300
Subject: [PATCH 29/34] =?UTF-8?q?=F0=9F=91=A8=E2=80=8D=F0=9F=92=BB=20Add?=
=?UTF-8?q?=20=F0=9F=91=A8=E2=80=8D=F0=9F=92=BB=20fading=20=F0=9F=91=A8?=
=?UTF-8?q?=E2=80=8D=F0=9F=92=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Web/static/js/al_suggestions.js | 52 ++++++++++++++++-----------------
1 file changed, 25 insertions(+), 27 deletions(-)
diff --git a/Web/static/js/al_suggestions.js b/Web/static/js/al_suggestions.js
index 3d7a2a907..4b702cb54 100644
--- a/Web/static/js/al_suggestions.js
+++ b/Web/static/js/al_suggestions.js
@@ -19,13 +19,13 @@ $(document).on("click", "#publish_post", async (e) => {
} catch(ex) {
switch(ex.code) {
case 11:
- MessageBox(tr("error"), tr("error_declining_invalid_post"), [tr("ok")], [Function.noop]);
+ MessageBox(tr("error"), tr("error_accepting_invalid_post"), [tr("ok")], [Function.noop]);
break;
case 19:
- MessageBox(tr("error"), tr("error_declining_not_suggested_post"), [tr("ok")], [Function.noop]);
+ MessageBox(tr("error"), tr("error_accepting_not_suggested_post"), [tr("ok")], [Function.noop]);
break;
case 10:
- MessageBox(tr("error"), tr("error_declining_declined_post"), [tr("ok")], [Function.noop]);
+ MessageBox(tr("error"), tr("error_accepting_declined_post"), [tr("ok")], [Function.noop]);
break;
case 22:
MessageBox(tr("error"), "Access denied", [tr("ok")], [Function.noop]);
@@ -43,11 +43,10 @@ $(document).on("click", "#publish_post", async (e) => {
NewNotification(tr("suggestion_succefully_published"), tr("suggestion_press_to_go"), null, () => {window.location.assign("/wall" + post.id)});
- if(document.getElementById("cound") != null) {
+ if(document.getElementById("cound") != null)
document.getElementById("cound").innerHTML = tr("suggested_posts_in_group", post.new_count)
- } else {
+ else
document.getElementById("cound_r").innerHTML = tr("suggested_by_everyone", post.new_count)
- }
if(document.querySelector("object a[href='"+location.pathname+"'] b") != null) {
document.querySelector("object a[href='"+location.pathname+"'] b").innerHTML = post.new_count
@@ -62,18 +61,18 @@ $(document).on("click", "#publish_post", async (e) => {
$(".sugglist").remove()
}
- if(e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.tagName == "TABLE") {
- e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = ""
- } else {
- e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = ""
- }
-
- if(document.querySelectorAll("#postz .post").length < 1 && post.new_count > 0 && document.querySelector(".paginator") != null) {
+ let post_node = e.currentTarget.closest("table")
+ post_node.style.transition = "opacity 300ms ease-in-out";
+ post_node.style.opacity = "0";
+ post_node.classList.remove("post")
+
+ setTimeout(() => {post_node.outerHTML = ""}, 300)
+
+ if(document.querySelectorAll("#postz .post").length < 1 && post.new_count > 0 && document.querySelector(".paginator") != null)
loadMoreSuggestedPosts()
- }
}), Function.noop]);
- document.getElementById("pooblish").innerHTML = e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.querySelector(".really_text").innerHTML.replace(/(<([^>]+)>)/gi, '')
+ document.getElementById("pooblish").innerHTML = e.currentTarget.closest("table").querySelector(".really_text").innerHTML.replace(/(<([^>]+)>)/gi, '')
document.querySelector(".ovk-diag-body").style.padding = "9px";
})
@@ -114,18 +113,18 @@ $(document).on("click", "#decline_post", async (e) => {
//NewNotification(tr("suggestion_succefully_declined"), "", null);
- if(e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.tagName == "TABLE") {
- e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = ""
- } else {
- e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.outerHTML = ""
- }
+ let post_node = e.currentTarget.closest("table")
+ post_node.style.transition = "opacity 300ms ease-in-out";
+ post_node.style.opacity = "0";
+ post_node.classList.remove("post")
+
+ setTimeout(() => {post_node.outerHTML = ""}, 300)
- if(document.getElementById("cound") != null) {
+ if(document.getElementById("cound") != null)
document.getElementById("cound").innerHTML = tr("suggested_posts_in_group", post)
- } else {
+ else
document.getElementById("cound_r").innerHTML = tr("suggested_by_everyone", post)
- }
-
+
if(document.querySelector("object a[href='"+location.pathname+"'] b") != null) {
document.querySelector("object a[href='"+location.pathname+"'] b").innerHTML = post
@@ -138,10 +137,9 @@ $(document).on("click", "#decline_post", async (e) => {
$(".sugglist a").click()
$(".sugglist").remove()
}
-
- if(document.querySelectorAll("#postz .post").length < 1 && post > 0 && document.querySelector(".paginator") != null) {
+
+ if(document.querySelectorAll("#postz .post").length < 1 && post > 0 && document.querySelector(".paginator") != null)
loadMoreSuggestedPosts()
- }
})
function loadMoreSuggestedPosts()
From e1f10353e0cc979aa4dd53bdbb9dc0872707b6ac Mon Sep 17 00:00:00 2001
From: lalka2016 <99399973+lalka2016@users.noreply.github.com>
Date: Mon, 28 Aug 2023 18:08:38 +0300
Subject: [PATCH 30/34] Add "owner's posts' and "other's posts"
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Давайте рофлить👨💻👨💻👨💻
---
VKAPI/Handlers/Wall.php | 6 ++-
Web/Models/Repositories/Posts.php | 60 ++++++++++++++++++++++++++
Web/Presenters/WallPresenter.php | 25 ++++++++++-
Web/Presenters/templates/Wall/Wall.xml | 14 +++++-
locales/en.strings | 5 +++
locales/ru.strings | 5 +++
6 files changed, 110 insertions(+), 5 deletions(-)
diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php
index b90ebeac2..cf8e8fcf4 100644
--- a/VKAPI/Handlers/Wall.php
+++ b/VKAPI/Handlers/Wall.php
@@ -49,10 +49,12 @@ function get(int $owner_id, string $domain = "", int $offset = 0, int $count = 3
$cnt = $posts->getPostCountOnUserWall($owner_id);
break;
case "owner":
- $this->fail(42, "Not implemented");
+ $iteratorv = $posts->getOwnersPostsFromWall($owner_id, 1, $count, $offset);
+ $cnt = $posts->getOwnersCountOnUserWall($owner_id);
break;
case "others":
- $this->fail(42, "Not implemented");
+ $iteratorv = $posts->getOthersPostsFromWall($owner_id, 1, $count, $offset);
+ $cnt = $posts->getOthersCountOnUserWall($owner_id);
break;
case "postponed":
$this->fail(42, "Postponed posts are not implemented.");
diff --git a/Web/Models/Repositories/Posts.php b/Web/Models/Repositories/Posts.php
index 4cde11a59..89ee58eaa 100644
--- a/Web/Models/Repositories/Posts.php
+++ b/Web/Models/Repositories/Posts.php
@@ -67,6 +67,50 @@ function getPostsFromUsersWall(int $user, int $page = 1, ?int $perPage = NULL, ?
foreach($sel as $post)
yield new Post($post);
}
+
+ function getOwnersPostsFromWall(int $user, int $page = 1, ?int $perPage = NULL, ?int $offset = NULL): \Traversable
+ {
+ $perPage ??= OPENVK_DEFAULT_PER_PAGE;
+ $offset ??= $perPage * ($page - 1);
+
+ $sel = $this->posts->where([
+ "wall" => $user,
+ "deleted" => false,
+ "suggested" => 0,
+ ]);
+
+ if($user > 0)
+ $sel->where("owner", $user);
+ else
+ $sel->where("flags !=", 0);
+
+ $sel->order("created DESC")->limit($perPage, $offset);
+
+ foreach($sel as $post)
+ yield new Post($post);
+ }
+
+ function getOthersPostsFromWall(int $user, int $page = 1, ?int $perPage = NULL, ?int $offset = NULL): \Traversable
+ {
+ $perPage ??= OPENVK_DEFAULT_PER_PAGE;
+ $offset ??= $perPage * ($page - 1);
+
+ $sel = $this->posts->where([
+ "wall" => $user,
+ "deleted" => false,
+ "suggested" => 0,
+ ]);
+
+ if($user > 0)
+ $sel->where("owner !=", $user);
+ else
+ $sel->where("flags", 0);
+
+ $sel->order("created DESC")->limit($perPage, $offset);
+
+ foreach($sel as $post)
+ yield new Post($post);
+ }
function getPostsByHashtag(string $hashtag, int $page = 1, ?int $perPage = NULL): \Traversable
{
@@ -147,6 +191,22 @@ function getPostCountOnUserWall(int $user): int
return sizeof($this->posts->where(["wall" => $user, "deleted" => 0, "suggested" => 0]));
}
+ function getOwnersCountOnUserWall(int $user): int
+ {
+ if($user > 0)
+ return sizeof($this->posts->where(["wall" => $user, "deleted" => 0, "owner" => $user]));
+ else
+ return sizeof($this->posts->where(["wall" => $user, "deleted" => 0, "suggested" => 0])->where("flags !=", 0));
+ }
+
+ function getOthersCountOnUserWall(int $user): int
+ {
+ if($user > 0)
+ return sizeof($this->posts->where(["wall" => $user, "deleted" => 0])->where("owner !=", $user));
+ else
+ return sizeof($this->posts->where(["wall" => $user, "deleted" => 0, "suggested" => 0])->where("flags", 0));
+ }
+
function getSuggestedPosts(int $club, int $page = 1, ?int $perPage = NULL, ?int $offset = NULL): \Traversable
{
$perPage ??= OPENVK_DEFAULT_PER_PAGE;
diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php
index b8e94298a..9ea184530 100644
--- a/Web/Presenters/WallPresenter.php
+++ b/Web/Presenters/WallPresenter.php
@@ -66,11 +66,32 @@ function renderWall(int $user, bool $embedded = false): void
$this->template->oObj = $owner;
if($user < 0)
$this->template->club = $owner;
+
+ $iterator = NULL;
+ $count = 0;
+ $type = $this->queryParam("type") ?? "all";
+
+ switch($type) {
+ default:
+ case "all":
+ $iterator = $this->posts->getPostsFromUsersWall($user, (int) ($_GET["p"] ?? 1));
+ $count = $this->posts->getPostCountOnUserWall($user);
+ break;
+ case "owners":
+ $iterator = $this->posts->getOwnersPostsFromWall($user, (int) ($_GET["p"] ?? 1));
+ $count = $this->posts->getOwnersCountOnUserWall($user);
+ break;
+ case "others":
+ $iterator = $this->posts->getOthersPostsFromWall($user, (int) ($_GET["p"] ?? 1));
+ $count = $this->posts->getOthersCountOnUserWall($user);
+ break;
+ }
$this->template->owner = $user;
$this->template->canPost = $canPost;
- $this->template->count = $this->posts->getPostCountOnUserWall($user);
- $this->template->posts = iterator_to_array($this->posts->getPostsFromUsersWall($user, (int) ($_GET["p"] ?? 1)));
+ $this->template->count = $count;
+ $this->template->type = $type;
+ $this->template->posts = iterator_to_array($iterator);
$this->template->paginatorConf = (object) [
"count" => $this->template->count,
"page" => (int) ($_GET["p"] ?? 1),
diff --git a/Web/Presenters/templates/Wall/Wall.xml b/Web/Presenters/templates/Wall/Wall.xml
index a9f8845fe..516d5b8f3 100644
--- a/Web/Presenters/templates/Wall/Wall.xml
+++ b/Web/Presenters/templates/Wall/Wall.xml
@@ -15,7 +15,19 @@
{block content}
`
- }
-
- xhr.onload = () => {
- let parser = new DOMParser()
- let body = parser.parseFromString(xhr.responseText, "text/html").getElementById("postz")
-
- if(body.querySelectorAll(".post").length < 1) {
- let url = new URL(location.href)
- url.searchParams.set("p", url.searchParams.get("p") - 1)
-
- if(url.searchParams.get("p") < 1) {
- return 0;
- }
+ ky.get(link, {
+ hooks: {
+ beforeRequest: [
+ (_request) => {
+ document.getElementById("postz").innerHTML = `
`
+ }
+ ],
+ afterResponse: [
+ async (_request, _options, response) => {
+ let text = await response.text()
+ let parser = new DOMParser()
+ let body = parser.parseFromString(text, "text/html")
+
+ if(body.querySelectorAll(".post").length < 1) {
+ let url = new URL(location.href)
+ url.searchParams.set("p", url.searchParams.get("p") - 1)
+
+ if(url.searchParams.get("p") < 1) {
+ return 0;
+ }
- // OVK AJAX ROUTING ??????????
- history.pushState({}, "", url)
+ history.pushState({}, "", url)
+
+ loadMoreSuggestedPosts()
+ }
- loadMoreSuggestedPosts()
+ body.querySelectorAll(".bsdn").forEach(bsdnInitElement)
+ document.getElementById("postz").innerHTML = body.getElementById("postz").innerHTML
+ }
+ ]
}
-
- document.getElementById("postz").innerHTML = body.innerHTML
- }
-
- xhr.onerror = () => {
- document.getElementById("postz").innerHTML = tr("error_loading_suggest")
- }
-
- xhr.send()
+ })
}
// нажатие на "x предложенных записей"
@@ -198,29 +171,24 @@ $(document).on("click", ".sugglist a", (e) => {
// если ещё ничего не подгружалось
if(document.querySelector(".insertThere").innerHTML == "") {
- let xhr = new XMLHttpRequest
- xhr.open("GET", e.currentTarget.href)
-
- xhr.onloadstart = () => {
- // лоадер
- document.querySelector(".insertThere").insertAdjacentHTML("afterbegin", `
`)
- }
-
- xhr.onload = () => {
- let parser = new DOMParser
- let result = parser.parseFromString(xhr.responseText, 'text/html').querySelector(".infContainer")
- // парсинг результата и вставка постов
- document.querySelector(".insertThere").innerHTML = result.innerHTML
- }
-
- function errorl() {
- document.getElementById("postz").innerHTML = tr("error_loading_suggest")
- }
-
- xhr.onerror = () => {errorl()}
- xhr.ontimeout = () => {errorl()}
-
- xhr.send()
+ ky(e.currentTarget.href, {
+ hooks: {
+ beforeRequest: [
+ (_request) => {
+ document.querySelector(".insertThere").insertAdjacentHTML("afterbegin", `
`)
+ }
+ ],
+ afterResponse: [
+ async (_request, _options, response) => {
+ let parser = new DOMParser
+ let result = parser.parseFromString(await response.text(), 'text/html').querySelector(".infContainer")
+
+ result.querySelectorAll(".bsdn").forEach(bsdnInitElement)
+ document.querySelector(".insertThere").innerHTML = result.innerHTML
+ }
+ ]
+ }
+ })
}
} else {
// переключение на нормальную стену
@@ -232,37 +200,32 @@ $(document).on("click", ".sugglist a", (e) => {
}
})
-// нажатие на пагинатор у постов пъедложки
+// нажатие на пагинатор у постов предложки
$(document).on("click", "#postz .paginator a", (e) => {
e.preventDefault()
- let xhr = new XMLHttpRequest
- xhr.open("GET", e.currentTarget.href)
-
- xhr.onloadstart = () => {
- if(document.querySelector(".sugglist") != null) {
- document.querySelector(".sugglist").scrollIntoView({behavior: "smooth"})
- } else {
- document.querySelector(".infContainer").scrollIntoView({behavior: "smooth"})
+ ky(e.currentTarget.href, {
+ hooks: {
+ beforeRequest: [
+ (_request) => {
+ if(document.querySelector(".sugglist") != null) {
+ document.querySelector(".sugglist").scrollIntoView({behavior: "smooth"})
+ } else {
+ document.querySelector(".infContainer").scrollIntoView({behavior: "smooth"})
+ }
+
+ setTimeout(() => {document.getElementById("postz").innerHTML = `
`}, 500)
+ }
+ ],
+ afterResponse: [
+ async (_request, _options, response) => {
+ let result = (new DOMParser).parseFromString(await response.text(), "text/html").querySelector(".infContainer")
+ result.querySelectorAll(".bsdn").forEach(bsdnInitElement)
+
+ document.getElementById("postz").innerHTML = result.innerHTML
+ history.pushState({}, "", e.currentTarget.href)
+ }
+ ]
}
- // после того как долистали наверх, добавляем лоадер
- setTimeout(() => {document.getElementById("postz").innerHTML = `
`}, 500)
- }
-
- xhr.onload = () => {
- // опять парс
- let result = (new DOMParser).parseFromString(xhr.responseText, "text/html").querySelector(".infContainer")
- // опять вставка
- document.getElementById("postz").innerHTML = result.innerHTML
- history.pushState({}, "", e.currentTarget.href)
- }
-
- function errorl() {
- document.getElementById("postz").innerHTML = tr("error_loading_suggest")
- }
-
- xhr.onerror = () => {errorl()}
- xhr.ontimeout = () => {errorl()}
-
- xhr.send()
+ })
})
From 029ce27e419c6badb80b30ac497765915e5dad37 Mon Sep 17 00:00:00 2001
From: lalka2018 <99399973+lalka2016@users.noreply.github.com>
Date: Wed, 15 Nov 2023 22:41:18 +0300
Subject: [PATCH 33/34] PHP 8 FIX WATAFAK
---
ServiceAPI/Wall.php | 2 +-
Web/Presenters/GroupPresenter.php | 4 ++--
.../sqls/{00039-suggest-posts.sql => 00043-suggest-posts.sql} | 0
3 files changed, 3 insertions(+), 3 deletions(-)
rename install/sqls/{00039-suggest-posts.sql => 00043-suggest-posts.sql} (100%)
diff --git a/ServiceAPI/Wall.php b/ServiceAPI/Wall.php
index f8d9fca2a..06d7353ce 100644
--- a/ServiceAPI/Wall.php
+++ b/ServiceAPI/Wall.php
@@ -132,7 +132,7 @@ function searchVideos(int $page = 1, string $query, callable $resolve, callable
];
foreach($videos as $video) {
- $res = json_decode(json_encode($video->toVkApiStruct()), true);
+ $res = json_decode(json_encode($video->toVkApiStruct($this->user)), true);
$res["video"]["author_name"] = $video->getOwner()->getCanonicalName();
$arr["items"][] = $res;
diff --git a/Web/Presenters/GroupPresenter.php b/Web/Presenters/GroupPresenter.php
index 6c89ea259..beeede139 100644
--- a/Web/Presenters/GroupPresenter.php
+++ b/Web/Presenters/GroupPresenter.php
@@ -448,11 +448,11 @@ function renderSuggested(int $id): void
}
if(!$club->canBeModifiedBy($this->user->identity)) {
- $this->template->posts = (new Posts)->getSuggestedPostsByUser($club->getId(), $this->user->id, (int) ($this->queryParam("p") ?? 1));
+ $this->template->posts = iterator_to_array((new Posts)->getSuggestedPostsByUser($club->getId(), $this->user->id, (int) ($this->queryParam("p") ?? 1)));
$this->template->count = (new Posts)->getSuggestedPostsCountByUser($club->getId(), $this->user->id);
$this->template->type = "my";
} else {
- $this->template->posts = (new Posts)->getSuggestedPosts($club->getId(), (int) ($this->queryParam("p") ?? 1));
+ $this->template->posts = iterator_to_array((new Posts)->getSuggestedPosts($club->getId(), (int) ($this->queryParam("p") ?? 1)));
$this->template->count = (new Posts)->getSuggestedPostsCount($club->getId());
$this->template->type = "everyone";
}
diff --git a/install/sqls/00039-suggest-posts.sql b/install/sqls/00043-suggest-posts.sql
similarity index 100%
rename from install/sqls/00039-suggest-posts.sql
rename to install/sqls/00043-suggest-posts.sql
From 2cc1b03cd1748516b70d55d3ba63ddbfb010c75b Mon Sep 17 00:00:00 2001
From: lalka2018 <99399973+lalka2016@users.noreply.github.com>
Date: Thu, 16 Nov 2023 16:07:13 +0300
Subject: [PATCH 34/34] Add indesk
---
install/sqls/00043-suggest-posts.sql | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/install/sqls/00043-suggest-posts.sql b/install/sqls/00043-suggest-posts.sql
index 2437c5e2a..1188f5599 100644
--- a/install/sqls/00043-suggest-posts.sql
+++ b/install/sqls/00043-suggest-posts.sql
@@ -1 +1 @@
-ALTER TABLE `posts` ADD `suggested` TINYINT(2) UNSIGNED NOT NULL DEFAULT '0' AFTER `deleted`;
+ALTER TABLE `posts` ADD `suggested` TINYINT(2) UNSIGNED NOT NULL DEFAULT '0' AFTER `deleted`, ADD INDEX (`suggested`);