-
Notifications
You must be signed in to change notification settings - Fork 8
Plugin blokowanie PW #171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Plugin blokowanie PW #171
Changes from all commits
1881da6
5ab5b1b
6ca6122
4d006ce
9d40c1a
14050e2
5cc2b99
0adb957
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
class block_pm_admin | ||
{ | ||
public function init_queries(array $tableslc) | ||
{ | ||
$table = qa_db_add_table_prefix('blockedpw'); | ||
|
||
$sql = 'CREATE TABLE IF NOT EXISTS `qa_blockedpw` ( | ||
`from_user_id` int(10) unsigned NOT NULL, | ||
`to_user_id` int(10) unsigned NOT NULL | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8'; | ||
|
||
return in_array($table, $tableslc, true) ? null : $sql; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
return [ | ||
'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', | ||
'block' => 'Zablokuj użytkownika', | ||
'unblock' => 'Odblokuj użytkownika', | ||
'cannot_send' => 'Nie możesz wysłać wiadomości prywatnej do tego użytkownika' | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
class qa_html_theme_layer extends qa_html_theme_base | ||
{ | ||
public function nav_list($navigation, $class, $level=null) // cannot use `: void` type-hint | ||
{ | ||
$user = qa_request_parts()[1] ?? ''; | ||
$dbUser = qa_db_select_with_pending(qa_db_user_account_selectspec($user, false)); | ||
|
||
if (qa_clicked('douserblock') || qa_clicked('douserunblock')) { | ||
$this->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(?int $loggedInId, int $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(string $class, ?int $loggedInId, ?array $dbUser): void | ||
{ | ||
$allowedToSeeButtons = $dbUser['handle'] !== qa_get_logged_in_handle() && strpos(qa_request(), 'user/') !== false && count(qa_request_parts()) === 2; | ||
|
||
if (!empty($dbUser) | ||
&& ((int) $dbUser['level']) === QA_USER_LEVEL_BASIC | ||
&& $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"' | ||
]; | ||
} | ||
} | ||
} | ||
} | ||
|
||
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' => qa_lang_html('block_pm/blocked_list_title'), | ||
'url' => qa_path_html('blocked-users'), | ||
'selected' => 'blocked-users' === qa_request() | ||
]; | ||
} | ||
} | ||
|
||
private function changePrivateMessageButton(?int $loggedInId, ?array $profileUser): void | ||
{ | ||
if (is_null($profileUser)) { | ||
return; | ||
} | ||
|
||
if (strpos(qa_request(), 'user/') !== false && ifUserIsBlocked($loggedInId, $profileUser['userid']) && count(qa_request_parts()) === 2) { | ||
$valueArray = explode('<a href', $this->content['form_profile']['fields']['level']['value']); | ||
|
||
if (qa_get_logged_in_level() > QA_USER_LEVEL_BASIC) { | ||
$value = $valueArray[0] . strtr('^1^2^3', [ | ||
'^1' => '<dfn class="pw-link-admins" data-info="' . qa_lang_html('block_pm/admin_info_blockade') . '"><a href="' . qa_path_html('message/' . $profileUser['handle']) .'">', | ||
'^2' => qa_lang_html('block_pm/see_pm_history_button'), | ||
'^3' => '</a></dfn>', | ||
]); | ||
} else { | ||
$value = $valueArray[0] . strtr('^1^2^3', [ | ||
'^1' => '<a href="' . qa_path_html('message/' . $profileUser['handle']) . '">', | ||
'^2' => qa_lang_html('block_pm/see_pm_history_button'), | ||
'^3' => '</a>', | ||
]); | ||
} | ||
|
||
$this->content['form_profile']['fields']['level']['value'] = $value; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
function qa_get_request_content(): ?array | ||
{ | ||
$requestparts = qa_request_parts(); | ||
$firstlower = strtolower($requestparts[0]); | ||
$routing = qa_page_routing(); | ||
$page = $firstlower . '/'; | ||
|
||
if (isset($routing[$page]) && $requestparts[0] === 'message') { | ||
qa_set_template($firstlower !== '' ? $firstlower : 'qa'); | ||
$qa_content = require QA_INCLUDE_DIR . 'pages/default.php'; | ||
|
||
if (isset($qa_content)) { | ||
qa_set_form_security_key(); | ||
} | ||
|
||
return $qa_content; | ||
} | ||
|
||
return qa_get_request_content_base(); | ||
} | ||
|
||
function qa_user_permit_error(string $permitoption=null, string $limitaction=null, string $userlevel=null, bool $checkblocks=true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. przeszło Ci to? mi wywalało forum jak tak zrobiłem There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Działa :v |
||
{ | ||
if (qa_post_text('domessage')) { | ||
$toUserId = qa_request_parts()[1] ?? ''; | ||
$loggedIn = qa_get_logged_in_userid(); | ||
|
||
if (empty($toUserId)) { | ||
return; | ||
} | ||
|
||
if (ifUserIsBlocked($loggedIn, $toUserId)) { | ||
return 'userblock'; // user is blocked so return missing permissions error | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
require_once QA_INCLUDE_DIR . 'db/users.php'; | ||
|
||
class block_pm_page | ||
{ | ||
private $directory; | ||
private $urltoroot; | ||
private $requestParts; | ||
|
||
public function load_module(string $directory, string $urltoroot): void | ||
{ | ||
$this->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(): ?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_pm/logged_in'); | ||
|
||
return $qa_content; | ||
} | ||
|
||
$qa_content = require QA_INCLUDE_DIR . '/pages/message.php'; | ||
|
||
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(): ?array | ||
{ | ||
if (isset($this->requestParts[1])) { | ||
$user = qa_db_user_find_by_handle($this->requestParts[1]); | ||
} else { | ||
$user = null; | ||
} | ||
|
||
return $user; | ||
} | ||
|
||
private function userExists($user): bool | ||
{ | ||
return !empty($user); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
class block_pm_user_list_page | ||
{ | ||
private $directory; | ||
private $urltoroot; | ||
private $requestParts; | ||
|
||
public function load_module(string $directory, string $urltoroot): void | ||
{ | ||
$this->directory = $directory; | ||
$this->urltoroot = $urltoroot; | ||
} | ||
|
||
public function match_request(string $request): bool | ||
{ | ||
return $request === 'blocked-users'; | ||
} | ||
|
||
public function process_request(): ?array | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. czyli nie czujesz potrzeby weryfikacji, czy przychodzi poprawny request? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jeśli dobrze rozumiem filozofię q2a, linijkę wyżej sprawdzam czy to jest request który mnie interesuje - |
||
{ | ||
$qa_content = qa_content_prepare(); | ||
$qa_content['title'] = qa_lang_html('block_pm/blocked_list_title'); | ||
|
||
// logged in user id | ||
$loggedIn = qa_get_logged_in_userid(); | ||
|
||
if (empty($loggedIn)) { | ||
$qa_content['error'] = qa_lang_html('block_pm/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')); | ||
} | ||
|
||
$this->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', | ||
'arguments' => [$loggedIn], | ||
'arraykey' => 'userid', | ||
]); | ||
|
||
$pageContent = ''; | ||
|
||
if (0 === count($blockedUsers)) { | ||
$pageContent = qa_lang_html('block_pm/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(); | ||
|
||
$qa_content['ranking']['items'][] = [ | ||
'avatar' => $avatar, | ||
'label' => $userHtml[$user['userid']], | ||
'score' => '<form method="post" style="margin: 0; padding: 0;"><input type="hidden" style="display: none;" name="userid" value="' . $user['userid'] . '"><input type="submit" style="margin: 0; cursor: pointer; background-color: rgba(0,0,0,0); border: none; color: white;" value="' . qa_lang_html('block_pm/block') . '"></form>', | ||
'raw' => $label, | ||
]; | ||
} | ||
|
||
$qa_content['custom_head'] = '<style>.qam-user-score-icon::before { display: none; } .qam-user-score-icon { padding: 2px 6px 2px 6px; }</style>'; | ||
} | ||
|
||
if ('' !== $pageContent) { | ||
$qa_content['custom'] = $pageContent; | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "Block pm", | ||
"uri": "https://forum.pasja-informatyki.pl", | ||
"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_php_ver": "7.1" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
podałem Ci rozwiązanie - czemu nie chcesz z niego skoryzstać?
Dostałeś rozwiązanie z qa_opt(), które pozwala na weryfikację czy plugin jest w ogóle włączony. Przecież powinna być opcja wygodnego włączenia czy wyłączenia pluginu, bez usuwania go z serwera.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wydaje mi się że nie ma sensu włączania/wyłączania pluginu który służy tylko do blokowania użytkowników co też wyjaśniliśmy na Discordzie.