From 1881da6d62a3118578fdab7f68ad16c7626394d1 Mon Sep 17 00:00:00 2001 From: Mariusz08 <> Date: Tue, 17 Mar 2020 20:40:52 +0100 Subject: [PATCH 1/6] Preview --- .../block-pw/block-pw-lang-default.php | 17 ++++ forum/qa-plugin/block-pw/block-pw-layer.php | 93 +++++++++++++++++++ .../qa-plugin/block-pw/block-pw-override.php | 43 +++++++++ forum/qa-plugin/block-pw/block-pw-page.php | 63 +++++++++++++ .../block-pw/block-pw-user-list-page.php | 85 +++++++++++++++++ forum/qa-plugin/block-pw/metadata.json | 11 +++ forum/qa-plugin/block-pw/qa-plugin.php | 54 +++++++++++ 7 files changed, 366 insertions(+) create mode 100644 forum/qa-plugin/block-pw/block-pw-lang-default.php create mode 100644 forum/qa-plugin/block-pw/block-pw-layer.php create mode 100644 forum/qa-plugin/block-pw/block-pw-override.php create mode 100644 forum/qa-plugin/block-pw/block-pw-page.php create mode 100644 forum/qa-plugin/block-pw/block-pw-user-list-page.php create mode 100644 forum/qa-plugin/block-pw/metadata.json create mode 100644 forum/qa-plugin/block-pw/qa-plugin.php diff --git a/forum/qa-plugin/block-pw/block-pw-lang-default.php b/forum/qa-plugin/block-pw/block-pw-lang-default.php new file mode 100644 index 00000000..729da71a --- /dev/null +++ b/forum/qa-plugin/block-pw/block-pw-lang-default.php @@ -0,0 +1,17 @@ + 'Musisz być zalogowany', + 'blocked_list_title' => 'Lista zablokowanych', + 'empty_blocklist' => 'Nikogo jeszcze nie zablokowałeś, ale gdy zajdzie taka potrzeba, nie wahaj się', + 'admin_info_blockade' => 'Użytkownik ma wyłączone otrzymywanie wiadomości od innych użytkowników lub po prostu Ciebie zablokował, ale korzystając z uprawnień administracyjnych możesz się z nim skontaktować', + 'see_pm_history_button' => 'Zobacz historię wiadomości', + 'not_found' => 'Strona nie została znaleziona', + 'reason_migrate' => 'Inne', + 'reason_close' => 'Niepoprawna kategoria', + 'reason_other' => 'Inne', + 'note' => 'Notatka:', + 'enter_details' => 'Wpisz notatkę', + 'send' => 'Wyślij', + 'flaglist_head' => 'Flagi:' +]; diff --git a/forum/qa-plugin/block-pw/block-pw-layer.php b/forum/qa-plugin/block-pw/block-pw-layer.php new file mode 100644 index 00000000..0b724a5b --- /dev/null +++ b/forum/qa-plugin/block-pw/block-pw-layer.php @@ -0,0 +1,93 @@ +performFormAction(qa_get_logged_in_userid(), $dbUser['userid']); + } + + $this->prepareNavigation($class, $dbUser['handle'], $navigation); + $this->prepareProfileButtons($class, qa_get_logged_in_userid(), $dbUser); + $this->changePrivateMessageButton(qa_get_logged_in_userid(), $dbUser); + + parent::nav_list($navigation, $class, $level); + } + + private function performFormAction($loggedInId, $profileUserId): void + { + if (qa_clicked('douserblock')) { + qa_db_query_sub('INSERT INTO `^blockedpw` VALUES (#, #)', $loggedInId, $profileUserId); + } else if (qa_clicked('douserunblock')) { + qa_db_query_sub('DELETE FROM `^blockedpw` WHERE `from_user_id` = # AND `to_user_id` = #', $loggedInId, $profileUserId); + } + } + + private function prepareProfileButtons($class, $loggedInId, $dbUser): void + { + $allowedToSeeButtons = $dbUser !== qa_get_logged_in_handle() && strpos(qa_request(), 'user/') !== false; + + if (!empty($dbUser) && $dbUser['level'] == QA_USER_LEVEL_BASIC) { + if ($class === 'nav-sub' && $allowedToSeeButtons) { + if (!checkIfUserIsBlocked($dbUser['userid'], qa_get_logged_in_userid())) { + $this->content['form_profile']['buttons']['douserblock'] = [ + 'label' => 'Zablokuj użytkownika', + 'tags' => 'name="douserblock"' + ]; + } else { + $isBlocker = qa_db_query_sub('SELECT `from_user_id`, `to_user_id` FROM ^blockedpw WHERE from_user_id = # AND to_user_id = #', $loggedInId, $dbUser['userid']); + if ($isBlocker->num_rows != 0) { + $this->content['form_profile']['buttons']['douserunblock'] = [ + 'label' => 'Odblokuj użytkownika', + 'tags' => 'name="douserunblock"' + ]; + } + } + } + } + } + + private function prepareNavigation($class, $userHandle, &$navigation): void + { + if ( + ($class === 'nav-sub' || $class === 'nav-sub') && + ((!empty($userHandle) && $userHandle === qa_get_logged_in_handle()) || qa_request() === 'blocked-users') + ) { + $navigation[] = [ + 'label' => 'Zablokowani użytkownicy', + 'url' => qa_path_html('blocked-users'), + 'selected' => 'blocked-users' === qa_request() + ]; + } + } + + private function changePrivateMessageButton($loggedInId, $profileUser): void + { + if (checkIfUserIsBlocked($loggedInId, $profileUser['userid']) && strpos(qa_request(), 'user/') !== false) { + $valueArray = explode('content['form_profile']['fields']['level']['value']); + $value = ''; + + if (qa_get_logged_in_level() > QA_USER_LEVEL_BASIC) { + $value = $valueArray[0] . strtr('^1^2^3', [ + '^1' => '', + '^2' => qa_lang_html('block_pw/see_pm_history_button'), + '^3' => '', + ]); + } else { + $value = $valueArray[0] . strtr('^1^2^3', [ + '^1' => '', + '^2' => qa_lang_html('block_pw/see_pm_history_button'), + '^2' => '', + ]); + } + + $this->content['form_profile']['fields']['level']['value'] = $value; + } + } +} diff --git a/forum/qa-plugin/block-pw/block-pw-override.php b/forum/qa-plugin/block-pw/block-pw-override.php new file mode 100644 index 00000000..4ca48fe7 --- /dev/null +++ b/forum/qa-plugin/block-pw/block-pw-override.php @@ -0,0 +1,43 @@ +num_rows; + + if (checkIfUserIsBlocked($loggedIn, $toUserId)) { + return 'userblock'; // user is blocked so return missing permissions error + } + } +} \ No newline at end of file diff --git a/forum/qa-plugin/block-pw/block-pw-page.php b/forum/qa-plugin/block-pw/block-pw-page.php new file mode 100644 index 00000000..1cb1c519 --- /dev/null +++ b/forum/qa-plugin/block-pw/block-pw-page.php @@ -0,0 +1,63 @@ +directory = $directory; + $this->urltoroot = $urltoroot; + } + + public function match_request(string $request): bool + { + $this->requestParts = explode('/', $request); + + return $this->requestParts[0] === 'message'; + } + + public function process_request(string $request): ?array + { + // logged in user id + $loggedIn = qa_get_logged_in_userid(); + // to message user id + $user = $this->getUser(); + + if (!$this->userExists($user)) { + return include QA_INCLUDE_DIR.'qa-page-not-found.php'; + } + + if (empty($loggedIn)) { + $qa_content = qa_content_prepare(); + $qa_content['error'] = qa_lang_html('block_pw/logged_in'); + + return $qa_content; + } + + $qa_content = require QA_INCLUDE_DIR . '/pages/message.php'; + + if (checkIfUserIsBlocked($loggedIn, $user) && qa_get_logged_in_level() == QA_USER_LEVEL_BASIC) { + $qa_content['custom'] = 'Nie możesz wysłać wiadomości prywatnej do tego użytkownika.'; + unset($qa_content['form_message']); + } + + return $qa_content; + } + + private function getUser() + { + $user = qa_db_user_find_by_handle($this->requestParts[1]); + + return $user; + } + + private function userExists($user): bool + { + return !empty($user); + } +} diff --git a/forum/qa-plugin/block-pw/block-pw-user-list-page.php b/forum/qa-plugin/block-pw/block-pw-user-list-page.php new file mode 100644 index 00000000..224b33c9 --- /dev/null +++ b/forum/qa-plugin/block-pw/block-pw-user-list-page.php @@ -0,0 +1,85 @@ +directory = $directory; + $this->urltoroot = $urltoroot; + } + + public function match_request(string $request): bool + { + return $request === 'blocked-users'; + } + + public function process_request(string $request): ?array + { + $qa_content = qa_content_prepare(); + $qa_content['title'] = qa_lang_html('block_pw/blocked_list_title'); + + // logged in user id + $loggedIn = qa_get_logged_in_userid(); + + if (empty($loggedIn)) { + $qa_content['error'] = qa_lang_html('block_pw/logged_in'); + + return $qa_content; + } + + if (qa_post_text('userid')) { + qa_db_query_sub('DELETE FROM `^blockedpw` WHERE `from_user_id` = # AND `to_user_id` = #', $loggedIn, (int) qa_post_text('userid')); + } + + $blockedUsers = qa_db_select_with_pending([ + 'columns' => ['^users.userid', '^users.handle', '^users.flags', '^users.email', 'avatarblobid' => 'BINARY avatarblobid', '^users.avatarwidth', '^users.avatarheight'], + 'source' => '^users JOIN (SELECT to_user_id FROM ^blockedpw WHERE from_user_id = #) s ON ^users.userid=s.to_user_id', + 'arguments' => [$loggedIn], + 'arraykey' => 'userid', + ]); + + $pageContent = ''; + + if (0 === count($blockedUsers)) { + $pageContent = qa_lang_html('block_pw/empty_blocklist'); + } else { + $qa_content['ranking'] = [ + 'items' => [], + 'rows' => 2, + 'type' => 'users' + ]; + + $userHtml = qa_userids_handles_html($blockedUsers); + + foreach ($blockedUsers as $user) { + $avatar = qa_get_user_avatar_html($user['flags'], $user['email'], $user['handle'], $user['avatarblobid'], $user['avatarwidth'], $user['avatarheight'], qa_opt('avatar_users_size'), true); + $label = $user['handle']; + $points = qa_db_query_sub('SELECT `points` FROM ^userpoints WHERE userid = #', $user['userid']); + $pointsArray = $points->fetch_assoc(); + $score = $pointsArray['points']; + $raw = $label; + + $qa_content['ranking']['items'][] = [ + 'avatar' => $avatar, + 'label' => $userHtml[$user['userid']], + 'score' => '
', + 'raw' => $raw, + ]; + } + + $qa_content['custom_head'] = ''; + } + + if ('' !== $pageContent) { + $qa_content['custom'] = $pageContent; + } + + $qa_content['navigation']['sub'] = qa_user_sub_navigation(qa_get_logged_in_handle(), 'blocklist', true); + + return $qa_content; + } +} diff --git a/forum/qa-plugin/block-pw/metadata.json b/forum/qa-plugin/block-pw/metadata.json new file mode 100644 index 00000000..c8e6757e --- /dev/null +++ b/forum/qa-plugin/block-pw/metadata.json @@ -0,0 +1,11 @@ +{ + "name": "Block pw", + "uri": "https://forum.pasja-informatyki.pl", + "description": "Very powerful and useful plugin for blocking pw from unpleasant users :)", + "version": "1.0", + "date": "2020-03-16", + "author": "Mariusz08", + "author_uri": "https://forum.pasja-informatyki.pl/user/Mariusz08", + "license": "GPLv3+", + "min_q2a": "1.5" +} \ No newline at end of file diff --git a/forum/qa-plugin/block-pw/qa-plugin.php b/forum/qa-plugin/block-pw/qa-plugin.php new file mode 100644 index 00000000..69886078 --- /dev/null +++ b/forum/qa-plugin/block-pw/qa-plugin.php @@ -0,0 +1,54 @@ +num_rows; + $userLevel = qa_get_logged_in_level(); + $toUserDb = qa_db_select_with_pending(qa_db_user_account_selectspec($toUserId, false)); + + if (($blockedPrivateMessageBool || !$allowedPrivateMessages) && $toUserDb['level'] < QA_USER_LEVEL_EDITOR) { + return true; + } + + return false; +} From 5ab5b1bddb5dbe7d64f279bb024583ad7d2e215f Mon Sep 17 00:00:00 2001 From: Mariusz08 <> Date: Tue, 17 Mar 2020 20:43:56 +0100 Subject: [PATCH 2/6] Fix bad file --- .../block-pw/block-pw-lang-default.php | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/forum/qa-plugin/block-pw/block-pw-lang-default.php b/forum/qa-plugin/block-pw/block-pw-lang-default.php index 729da71a..eeeae925 100644 --- a/forum/qa-plugin/block-pw/block-pw-lang-default.php +++ b/forum/qa-plugin/block-pw/block-pw-lang-default.php @@ -1,17 +1,10 @@ 'Musisz być zalogowany', - 'blocked_list_title' => 'Lista zablokowanych', - 'empty_blocklist' => 'Nikogo jeszcze nie zablokowałeś, ale gdy zajdzie taka potrzeba, nie wahaj się', - 'admin_info_blockade' => 'Użytkownik ma wyłączone otrzymywanie wiadomości od innych użytkowników lub po prostu Ciebie zablokował, ale korzystając z uprawnień administracyjnych możesz się z nim skontaktować', - 'see_pm_history_button' => 'Zobacz historię wiadomości', - 'not_found' => 'Strona nie została znaleziona', - 'reason_migrate' => 'Inne', - 'reason_close' => 'Niepoprawna kategoria', - 'reason_other' => 'Inne', - 'note' => 'Notatka:', - 'enter_details' => 'Wpisz notatkę', - 'send' => 'Wyślij', - 'flaglist_head' => 'Flagi:' + 'logged_in' => 'Musisz być zalogowany', + 'blocked_list_title' => 'Lista zablokowanych', + 'empty_blocklist' => 'Nikogo jeszcze nie zablokowałeś, ale gdy zajdzie taka potrzeba, nie wahaj się', + 'admin_info_blockade' => 'Użytkownik ma wyłączone otrzymywanie wiadomości od innych użytkowników lub po prostu Ciebie zablokował, ale korzystając z uprawnień administracyjnych możesz się z nim skontaktować', + 'see_pm_history_button' => 'Zobacz historię wiadomości', + 'not_found' => 'Strona nie została znaleziona' ]; From 6ca61227a44ac3c50ec025458db5d2a2a83a56de Mon Sep 17 00:00:00 2001 From: Mariusz08 <> Date: Wed, 18 Mar 2020 14:45:25 +0100 Subject: [PATCH 3/6] Add wall posts block --- forum/qa-plugin/block-pw/block-pm-admin.php | 17 +++++ ...-default.php => block-pm-lang-default.php} | 5 +- ...{block-pw-layer.php => block-pm-layer.php} | 69 ++++++++++--------- ...-pw-override.php => block-pm-override.php} | 13 ++-- .../{block-pw-page.php => block-pm-page.php} | 19 +++-- ...t-page.php => block-pm-user-list-page.php} | 33 +++++---- forum/qa-plugin/block-pw/metadata.json | 7 +- forum/qa-plugin/block-pw/qa-plugin.php | 23 ++++--- 8 files changed, 110 insertions(+), 76 deletions(-) create mode 100644 forum/qa-plugin/block-pw/block-pm-admin.php rename forum/qa-plugin/block-pw/{block-pw-lang-default.php => block-pm-lang-default.php} (73%) rename forum/qa-plugin/block-pw/{block-pw-layer.php => block-pm-layer.php} (54%) rename forum/qa-plugin/block-pw/{block-pw-override.php => block-pm-override.php} (58%) rename forum/qa-plugin/block-pw/{block-pw-page.php => block-pm-page.php} (69%) rename forum/qa-plugin/block-pw/{block-pw-user-list-page.php => block-pm-user-list-page.php} (82%) diff --git a/forum/qa-plugin/block-pw/block-pm-admin.php b/forum/qa-plugin/block-pw/block-pm-admin.php new file mode 100644 index 00000000..f8bc8c20 --- /dev/null +++ b/forum/qa-plugin/block-pw/block-pm-admin.php @@ -0,0 +1,17 @@ + 'Nikogo jeszcze nie zablokowałeś, ale gdy zajdzie taka potrzeba, nie wahaj się', 'admin_info_blockade' => 'Użytkownik ma wyłączone otrzymywanie wiadomości od innych użytkowników lub po prostu Ciebie zablokował, ale korzystając z uprawnień administracyjnych możesz się z nim skontaktować', 'see_pm_history_button' => 'Zobacz historię wiadomości', - 'not_found' => 'Strona nie została znaleziona' + 'not_found' => 'Strona nie została znaleziona', + 'block' => 'Zablokuj użytkownika', + 'unblock' => 'Odblokuj użytkownika', + 'cannot_send' => 'Nie możesz wysłać wiadomości prywatnej do tego użytkownika' ]; diff --git a/forum/qa-plugin/block-pw/block-pw-layer.php b/forum/qa-plugin/block-pw/block-pm-layer.php similarity index 54% rename from forum/qa-plugin/block-pw/block-pw-layer.php rename to forum/qa-plugin/block-pw/block-pm-layer.php index 0b724a5b..a199b904 100644 --- a/forum/qa-plugin/block-pw/block-pw-layer.php +++ b/forum/qa-plugin/block-pw/block-pm-layer.php @@ -1,14 +1,12 @@ performFormAction(qa_get_logged_in_userid(), $dbUser['userid']); } @@ -20,7 +18,7 @@ public function nav_list($navigation, $class, $level=null) // cannot use `: void parent::nav_list($navigation, $class, $level); } - private function performFormAction($loggedInId, $profileUserId): void + private function performFormAction(int $loggedInId, int $profileUserId): void { if (qa_clicked('douserblock')) { qa_db_query_sub('INSERT INTO `^blockedpw` VALUES (#, #)', $loggedInId, $profileUserId); @@ -29,61 +27,68 @@ private function performFormAction($loggedInId, $profileUserId): void } } - private function prepareProfileButtons($class, $loggedInId, $dbUser): void + private function prepareProfileButtons(string $class, int $loggedInId, ?array $dbUser): void { - $allowedToSeeButtons = $dbUser !== qa_get_logged_in_handle() && strpos(qa_request(), 'user/') !== false; - - if (!empty($dbUser) && $dbUser['level'] == QA_USER_LEVEL_BASIC) { - if ($class === 'nav-sub' && $allowedToSeeButtons) { - if (!checkIfUserIsBlocked($dbUser['userid'], qa_get_logged_in_userid())) { - $this->content['form_profile']['buttons']['douserblock'] = [ - 'label' => 'Zablokuj użytkownika', - 'tags' => 'name="douserblock"' + $allowedToSeeButtons = $dbUser['handle'] !== qa_get_logged_in_handle() && strpos(qa_request(), 'user/') !== false && count(qa_request_parts()) === 2; + + if (!empty($dbUser) + && $dbUser['level'] == QA_USER_LEVEL_BASIC // cannot use `===` - $dbUser['level'] is string, const is int + && $class === 'nav-sub' + && $allowedToSeeButtons + ) { + if (!ifUserIsBlocked($dbUser['userid'], qa_get_logged_in_userid())) { + $this->content['form_profile']['buttons']['douserblock'] = [ + 'label' => qa_lang_html('block_pm/block'), + 'tags' => 'name="douserblock"' + ]; + } else { + unset($this->content['message_list']['form']); + + $isBlocker = qa_db_query_sub('SELECT `from_user_id`, `to_user_id` FROM ^blockedpw WHERE from_user_id = # AND to_user_id = #', $loggedInId, $dbUser['userid']); + if ($isBlocker->num_rows !== 0) { + $this->content['form_profile']['buttons']['douserunblock'] = [ + 'label' => qa_lang_html('block_pm/unblock'), + 'tags' => 'name="douserunblock"' ]; - } else { - $isBlocker = qa_db_query_sub('SELECT `from_user_id`, `to_user_id` FROM ^blockedpw WHERE from_user_id = # AND to_user_id = #', $loggedInId, $dbUser['userid']); - if ($isBlocker->num_rows != 0) { - $this->content['form_profile']['buttons']['douserunblock'] = [ - 'label' => 'Odblokuj użytkownika', - 'tags' => 'name="douserunblock"' - ]; - } } } } } - private function prepareNavigation($class, $userHandle, &$navigation): void + private function prepareNavigation(string $class, ?string $userHandle, array &$navigation): void { if ( ($class === 'nav-sub' || $class === 'nav-sub') && ((!empty($userHandle) && $userHandle === qa_get_logged_in_handle()) || qa_request() === 'blocked-users') ) { $navigation[] = [ - 'label' => 'Zablokowani użytkownicy', + 'label' => qa_lang_html('block_pm/blocked_list_title'), 'url' => qa_path_html('blocked-users'), 'selected' => 'blocked-users' === qa_request() ]; } } - private function changePrivateMessageButton($loggedInId, $profileUser): void + private function changePrivateMessageButton(int $loggedInId, ?array $profileUser): void { - if (checkIfUserIsBlocked($loggedInId, $profileUser['userid']) && strpos(qa_request(), 'user/') !== false) { + if (is_null($profileUser)) { + return; + } + + if (strpos(qa_request(), 'user/') !== false && ifUserIsBlocked($loggedInId, $profileUser['userid']) && count(qa_request_parts()) === 2) { $valueArray = explode('content['form_profile']['fields']['level']['value']); - $value = ''; - + if (qa_get_logged_in_level() > QA_USER_LEVEL_BASIC) { $value = $valueArray[0] . strtr('^1^2^3', [ - '^1' => '', - '^2' => qa_lang_html('block_pw/see_pm_history_button'), + '^1' => '', + '^2' => qa_lang_html('block_pm/see_pm_history_button'), '^3' => '', ]); } else { $value = $valueArray[0] . strtr('^1^2^3', [ '^1' => '', - '^2' => qa_lang_html('block_pw/see_pm_history_button'), - '^2' => '', + '^2' => qa_lang_html('block_pm/see_pm_history_button'), + '^3' => '', ]); } diff --git a/forum/qa-plugin/block-pw/block-pw-override.php b/forum/qa-plugin/block-pw/block-pm-override.php similarity index 58% rename from forum/qa-plugin/block-pw/block-pw-override.php rename to forum/qa-plugin/block-pw/block-pm-override.php index 4ca48fe7..416be832 100644 --- a/forum/qa-plugin/block-pw/block-pw-override.php +++ b/forum/qa-plugin/block-pw/block-pm-override.php @@ -7,9 +7,8 @@ function qa_get_request_content(): ?array $routing = qa_page_routing(); $page = $firstlower . '/'; - // todo: to wiadomo, że jest do poprawy, ale tu dalem koncept tylko if (isset($routing[$page]) && $requestparts[0] === 'message') { - qa_set_template($firstlower !== '' ? $firstlower : 'qa'); // will be changed later + qa_set_template($firstlower !== '' ? $firstlower : 'qa'); $qa_content = require QA_INCLUDE_DIR . 'pages/default.php'; if (isset($qa_content)) { @@ -22,7 +21,7 @@ function qa_get_request_content(): ?array return qa_get_request_content_base(); } -function qa_user_permit_error($permitoption=null, $limitaction=null, $userlevel=null, $checkblocks=true) +function qa_user_permit_error(string $permitoption=null, string $limitaction=null, string $userlevel=null, bool $checkblocks=true) { if (qa_post_text('domessage')) { $toUserId = qa_request_parts()[1] ?? ''; @@ -32,12 +31,8 @@ function qa_user_permit_error($permitoption=null, $limitaction=null, $userlevel= return; } - $blockedPrivateMessages = qa_db_query_sub('SELECT `from_user_id`, `to_user_id` FROM ^blockedpw WHERE (from_user_id = # AND to_user_id = #) OR (from_user_id = # AND to_user_id = #)', $loggedIn, $toUserId, $toUserId, $loggedIn); - $allowedPrivateMessages = qa_opt('allow_private_messages'); - $blockedPrivateMessageBool = 0 != $blockedPrivateMessages->num_rows; - - if (checkIfUserIsBlocked($loggedIn, $toUserId)) { + if (ifUserIsBlocked($loggedIn, $toUserId)) { return 'userblock'; // user is blocked so return missing permissions error } } -} \ No newline at end of file +} diff --git a/forum/qa-plugin/block-pw/block-pw-page.php b/forum/qa-plugin/block-pw/block-pm-page.php similarity index 69% rename from forum/qa-plugin/block-pw/block-pw-page.php rename to forum/qa-plugin/block-pw/block-pm-page.php index 1cb1c519..457f6f2a 100644 --- a/forum/qa-plugin/block-pw/block-pw-page.php +++ b/forum/qa-plugin/block-pw/block-pm-page.php @@ -1,8 +1,9 @@ requestParts[0] === 'message'; } - public function process_request(string $request): ?array + public function process_request(): ?array { // logged in user id $loggedIn = qa_get_logged_in_userid(); @@ -34,24 +35,28 @@ public function process_request(string $request): ?array if (empty($loggedIn)) { $qa_content = qa_content_prepare(); - $qa_content['error'] = qa_lang_html('block_pw/logged_in'); + $qa_content['error'] = qa_lang_html('block_pm/logged_in'); return $qa_content; } $qa_content = require QA_INCLUDE_DIR . '/pages/message.php'; - if (checkIfUserIsBlocked($loggedIn, $user) && qa_get_logged_in_level() == QA_USER_LEVEL_BASIC) { - $qa_content['custom'] = 'Nie możesz wysłać wiadomości prywatnej do tego użytkownika.'; + if (ifUserIsBlocked($loggedIn, $user) && qa_get_logged_in_level() === QA_USER_LEVEL_BASIC) { + $qa_content['custom'] = qa_lang_html('block_pm/cannot_send'); unset($qa_content['form_message']); } return $qa_content; } - private function getUser() + private function getUser(): ?array { - $user = qa_db_user_find_by_handle($this->requestParts[1]); + if (isset($this->requestParts[1])) { + $user = qa_db_user_find_by_handle($this->requestParts[1]); + } else { + $user = null; + } return $user; } diff --git a/forum/qa-plugin/block-pw/block-pw-user-list-page.php b/forum/qa-plugin/block-pw/block-pm-user-list-page.php similarity index 82% rename from forum/qa-plugin/block-pw/block-pw-user-list-page.php rename to forum/qa-plugin/block-pw/block-pm-user-list-page.php index 224b33c9..9783e4f2 100644 --- a/forum/qa-plugin/block-pw/block-pw-user-list-page.php +++ b/forum/qa-plugin/block-pw/block-pm-user-list-page.php @@ -1,6 +1,7 @@ prepareBlockedList($loggedIn, $qa_content); + + $qa_content['navigation']['sub'] = qa_user_sub_navigation(qa_get_logged_in_handle(), 'blocklist', true); + + return $qa_content; + } + + private function prepareBlockedList(string $loggedIn, array &$qa_content): void + { $blockedUsers = qa_db_select_with_pending([ 'columns' => ['^users.userid', '^users.handle', '^users.flags', '^users.email', 'avatarblobid' => 'BINARY avatarblobid', '^users.avatarwidth', '^users.avatarheight'], 'source' => '^users JOIN (SELECT to_user_id FROM ^blockedpw WHERE from_user_id = #) s ON ^users.userid=s.to_user_id', @@ -45,7 +55,7 @@ public function process_request(string $request): ?array $pageContent = ''; if (0 === count($blockedUsers)) { - $pageContent = qa_lang_html('block_pw/empty_blocklist'); + $pageContent = qa_lang_html('block_pm/empty_blocklist'); } else { $qa_content['ranking'] = [ 'items' => [], @@ -60,26 +70,21 @@ public function process_request(string $request): ?array $label = $user['handle']; $points = qa_db_query_sub('SELECT `points` FROM ^userpoints WHERE userid = #', $user['userid']); $pointsArray = $points->fetch_assoc(); - $score = $pointsArray['points']; - $raw = $label; $qa_content['ranking']['items'][] = [ 'avatar' => $avatar, 'label' => $userHtml[$user['userid']], - 'score' => '', - 'raw' => $raw, + 'score' => '', + 'raw' => $label, ]; } $qa_content['custom_head'] = ''; - } + } if ('' !== $pageContent) { $qa_content['custom'] = $pageContent; } - - $qa_content['navigation']['sub'] = qa_user_sub_navigation(qa_get_logged_in_handle(), 'blocklist', true); - - return $qa_content; + } } diff --git a/forum/qa-plugin/block-pw/metadata.json b/forum/qa-plugin/block-pw/metadata.json index c8e6757e..a87e968f 100644 --- a/forum/qa-plugin/block-pw/metadata.json +++ b/forum/qa-plugin/block-pw/metadata.json @@ -1,11 +1,12 @@ { - "name": "Block pw", + "name": "Block pm", "uri": "https://forum.pasja-informatyki.pl", - "description": "Very powerful and useful plugin for blocking pw from unpleasant users :)", + "description": "Very powerful and useful plugin for blocking pm from unpleasant users :)", "version": "1.0", "date": "2020-03-16", "author": "Mariusz08", "author_uri": "https://forum.pasja-informatyki.pl/user/Mariusz08", "license": "GPLv3+", - "min_q2a": "1.5" + "min_q2a": "1.5", + "min_php_ver": "7.1" } \ No newline at end of file diff --git a/forum/qa-plugin/block-pw/qa-plugin.php b/forum/qa-plugin/block-pw/qa-plugin.php index 69886078..748dc4ec 100644 --- a/forum/qa-plugin/block-pw/qa-plugin.php +++ b/forum/qa-plugin/block-pw/qa-plugin.php @@ -1,14 +1,15 @@ num_rows; - $userLevel = qa_get_logged_in_level(); + $blockedPrivateMessageBool = 0 !== $blockedPrivateMessages->num_rows; $toUserDb = qa_db_select_with_pending(qa_db_user_account_selectspec($toUserId, false)); if (($blockedPrivateMessageBool || !$allowedPrivateMessages) && $toUserDb['level'] < QA_USER_LEVEL_EDITOR) { From 4d006ced6389da0035f954dc6d950033c2604d69 Mon Sep 17 00:00:00 2001 From: Mateusz