From a8dfc9277b363c3dd9a1a2d667b5759bb317751e Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 22 Feb 2019 21:04:09 +0000 Subject: [PATCH] Show logged event IPs on user page --- ext/user/main.php | 19 ++++++++++++++++++- ext/user/theme.php | 14 ++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/ext/user/main.php b/ext/user/main.php index cf75c5cc..5c27e308 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -240,7 +240,9 @@ class UserPage extends Extension { $this->theme->display_ip_list( $page, $this->count_upload_ips($event->display_user), - $this->count_comment_ips($event->display_user)); + $this->count_comment_ips($event->display_user), + $this->count_log_ips($event->display_user) + ); } } @@ -587,6 +589,21 @@ class UserPage extends Extension { return $rows; } + private function count_log_ips(User $duser): array { + if(!class_exists('LogDatabase')) return array(); + global $database; + $rows = $database->get_pairs(" + SELECT + address, + COUNT(id) AS count, + MAX(date_sent) AS most_recent + FROM score_log + WHERE username=:username + GROUP BY address + ORDER BY most_recent DESC", array("username"=>$duser->name)); + return $rows; + } + private function delete_user(Page $page, bool $with_images=false, bool $with_comments=false) { global $user, $config, $database; diff --git a/ext/user/theme.php b/ext/user/theme.php index b261ec08..43b87e2c 100644 --- a/ext/user/theme.php +++ b/ext/user/theme.php @@ -168,7 +168,7 @@ class UserPageTheme extends Themelet { $page->add_block(new Block("Login", $html, "left", 90)); } - public function display_ip_list(Page $page, array $uploads, array $comments) { + public function display_ip_list(Page $page, array $uploads, array $comments, array $events) { $html = ""; $html .= ""; - $html .= "
Uploaded from: "; $n = 0; @@ -190,8 +190,18 @@ class UserPageTheme extends Themelet { } } + $html .= "Logged Events:"; + $n = 0; + foreach($comments as $ip => $count) { + $html .= '
'.$ip.' ('.$count.')'; + if(++$n >= 20) { + $html .= "
..."; + break; + } + } + $html .= "
(Most recent at top)
"; + $html .= "(Most recent at top)"; $page->add_block(new Block("IPs", $html, "main", 70)); }