From 45d5d258bb2dd386cdf21104d28fbc5756d8b858 Mon Sep 17 00:00:00 2001 From: qwercik Date: Sun, 24 Sep 2017 00:02:44 +0200 Subject: [PATCH 1/4] Add highlighting duplicated IP addresses --- latest-users-page.php | 52 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/latest-users-page.php b/latest-users-page.php index 751f3eb..fcb3d5b 100644 --- a/latest-users-page.php +++ b/latest-users-page.php @@ -31,6 +31,13 @@ public function process_request($request) .lastest-center { text-align: center; } + + .duplicated-ip, + .duplicated-ip:hover, + .duplicated-ip:visited { + color: #FF0000; + } + '; $sql = ''; @@ -51,6 +58,18 @@ public function process_request($request) if (!empty($sql)) { $users = qa_db_read_all_assoc(qa_db_query_sub($sql, $limit)); $usershtml = qa_userids_handles_html($users); + + $duplicated_ips = []; + $user_array_ip_key = ''; + + if ($request === 'users/latest-registered') { + $user_array_ip_key = 'createip'; + } elseif ($request === 'users/latest-logged') { + $user_array_ip_key = 'loginip'; + } + + $duplicated_ips = $this->get_duplicates(array_column($users, $user_array_ip_key)); + $usersrows = ''; foreach ($users as $user) { if (QA_FINAL_EXTERNAL_USERS) { @@ -58,16 +77,22 @@ public function process_request($request) } else { $avatarhtml = qa_get_user_avatar_html($user['flags'], $user['email'], $user['handle'], $user['avatarblobid'], $user['avatarwidth'], $user['avatarheight'], qa_opt('avatar_users_size'), true); } - if ($request === 'users/latest-registered') { - $ip = qa_ip_anchor_html(long2ip($user['createip'])); - } elseif ($request === 'users/latest-logged') { - $ip = qa_ip_anchor_html(long2ip($user['loginip'])); + + $ip_link_style = ''; + + foreach ($duplicated_ips as $duplicate) { + if ($user[$user_array_ip_key] === $duplicate) { + $ip_link_style .= 'duplicated-ip'; + } } + $ip = long2ip($user[$user_array_ip_key]); + $ip_html = $this->get_ip_html($ip, $ip_link_style); + $usersrows .= ' ' . $avatarhtml . $usershtml[$user['userid']] . ' ' . ($request === 'users/latest-registered' ? $user['created'] : $user['loggedin']) . ' - ' . $ip . ' + ' . $ip_html . ' '; } @@ -125,4 +150,21 @@ function admin_form() return $form; } + + private function get_duplicates($array) + { + $unique_values = array_unique($array); + $duplicate_values = array_diff_assoc($array, $unique_values); + + return $duplicate_values; + } + + private function get_ip_html($ip, $link_style = '') + { + $href = qa_path_html('ip/' . $ip); + $title = qa_lang_html_sub('main/ip_address_x', qa_html($ip)); + + $html = '' . $ip . ''; + return $html; + } } From 8c6d6522189b351eee6922e4870dfcf35bdb8b8d Mon Sep 17 00:00:00 2001 From: qwercik Date: Sun, 24 Sep 2017 00:03:11 +0200 Subject: [PATCH 2/4] Add information about IP highlighting feature to README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f7ce870..89f00ed 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Latest users plugin to [Question2Answer](http://question2answer.org/) -Plugin add pages with latest registered and latest logged users with action IP. +Plugin add pages with latest registered and latest logged users with action IP. Plugin highlights duplicated IP addresses, so you can simply detect multi-accounts. ## Installation @@ -19,4 +19,4 @@ After you enable pages, links show in `Users` page in submenu. Addresses to this --- **Important notice about code!** -This code don't respect PHP PSR-2 standard, because Question2Answer unfortunately too don't respect this. Also, I couldn't design classes and functions in my own way, because most of them impose Question2Answer script. \ No newline at end of file +This code don't respect PHP PSR-2 standard, because Question2Answer unfortunately too don't respect this. Also, I couldn't design classes and functions in my own way, because most of them impose Question2Answer script. From 924e8d5a9da45577745e75cd355c4a9b7fca238f Mon Sep 17 00:00:00 2001 From: qwercik Date: Sun, 24 Sep 2017 01:12:40 +0200 Subject: [PATCH 3/4] Remove reduntant code --- latest-users-page.php | 1 - 1 file changed, 1 deletion(-) diff --git a/latest-users-page.php b/latest-users-page.php index fcb3d5b..9ddc83b 100644 --- a/latest-users-page.php +++ b/latest-users-page.php @@ -59,7 +59,6 @@ public function process_request($request) $users = qa_db_read_all_assoc(qa_db_query_sub($sql, $limit)); $usershtml = qa_userids_handles_html($users); - $duplicated_ips = []; $user_array_ip_key = ''; if ($request === 'users/latest-registered') { From ca32c2a406751ea08dcb1e8643fec77cb3c3529c Mon Sep 17 00:00:00 2001 From: qwercik Date: Sun, 24 Sep 2017 01:54:16 +0200 Subject: [PATCH 4/4] Fix bug with no highlighting more than two same IP addresses --- latest-users-page.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/latest-users-page.php b/latest-users-page.php index 9ddc83b..80602a2 100644 --- a/latest-users-page.php +++ b/latest-users-page.php @@ -81,7 +81,7 @@ public function process_request($request) foreach ($duplicated_ips as $duplicate) { if ($user[$user_array_ip_key] === $duplicate) { - $ip_link_style .= 'duplicated-ip'; + $ip_link_style = 'duplicated-ip'; } } @@ -155,7 +155,7 @@ private function get_duplicates($array) $unique_values = array_unique($array); $duplicate_values = array_diff_assoc($array, $unique_values); - return $duplicate_values; + return array_unique($duplicate_values); } private function get_ip_html($ip, $link_style = '')