From 8a288ceff57d67f1add77f261b4614e712e15696 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Tue, 4 Oct 2022 16:31:08 +0800 Subject: [PATCH] feat: last active at --- db/app_uoj233.sql | 3 +- web/app/locale/basic/en.php | 3 + web/app/locale/basic/zh-cn.php | 3 + web/app/locale/time/en.php | 26 +++++++++ web/app/locale/time/zh-cn.php | 26 +++++++++ web/app/models/UOJLocale.php | 2 +- web/app/views/user-info.php | 104 ++++++++++++++++++++++++++++++--- 7 files changed, 157 insertions(+), 10 deletions(-) create mode 100644 web/app/locale/time/en.php create mode 100644 web/app/locale/time/zh-cn.php diff --git a/db/app_uoj233.sql b/db/app_uoj233.sql index cfe3c41..f49be87 100644 --- a/db/app_uoj233.sql +++ b/db/app_uoj233.sql @@ -813,7 +813,8 @@ CREATE TABLE `user_info` ( `http_x_forwarded_for` varchar(50) NOT NULL, `remember_token` char(60) NOT NULL, `motto` varchar(200) NOT NULL, - `last_login` datetime NOT NULL, + `last_login` timestamp NOT NULL DEFAULT 0, + `last_visited` timestamp NOT NULL DEFAULT 0, PRIMARY KEY (`username`), KEY `ac_num` (`ac_num`,`username`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4; diff --git a/web/app/locale/basic/en.php b/web/app/locale/basic/en.php index ba94d42..edb6731 100644 --- a/web/app/locale/basic/en.php +++ b/web/app/locale/basic/en.php @@ -94,4 +94,7 @@ return [ 'problem manager' => 'Problem Manager', 'contest judger' => 'Contest Judger', 'contest only' => 'Contest Only', + 'last active at' => 'Last active at', + 'online' => 'Online', + 'offline' => 'Offline', ]; diff --git a/web/app/locale/basic/zh-cn.php b/web/app/locale/basic/zh-cn.php index 649ec20..85e9fae 100644 --- a/web/app/locale/basic/zh-cn.php +++ b/web/app/locale/basic/zh-cn.php @@ -94,4 +94,7 @@ return [ 'problem manager' => '题目管理者', 'contest judger' => '比赛评测员', 'contest only' => '仅比赛用户', + 'online' => '在线', + 'offline' => '离线', + 'last active at' => '最后活动于', ]; diff --git a/web/app/locale/time/en.php b/web/app/locale/time/en.php new file mode 100644 index 0000000..35691b0 --- /dev/null +++ b/web/app/locale/time/en.php @@ -0,0 +1,26 @@ + 'ago', + 'left' => 'left', + 'x years' => function($x) { + return $x . ' year' . ($x > 1 ? 's' : ''); + }, + 'x months' => function($x) { + return $x . ' month' . ($x > 1 ? 's' : ''); + }, + 'x weeks' => function($x) { + return $x . ' week' . ($x > 1 ? 's' : ''); + }, + 'x days' => function($x) { + return $x . ' day' . ($x > 1 ? 's' : ''); + }, + 'x hours' => function($x) { + return $x . ' hour' . ($x > 1 ? 's' : ''); + }, + 'x minutes' => function($x) { + return $x . ' minute' . ($x > 1 ? 's' : ''); + }, + 'x seconds' => function($x) { + return $x . ' second' . ($x > 1 ? 's' : ''); + }, +]; diff --git a/web/app/locale/time/zh-cn.php b/web/app/locale/time/zh-cn.php new file mode 100644 index 0000000..89ee4cd --- /dev/null +++ b/web/app/locale/time/zh-cn.php @@ -0,0 +1,26 @@ + '前', + 'left' => '后', + 'x years' => function($x) { + return $x . ' 年'; + }, + 'x months' => function($x) { + return $x . ' 月'; + }, + 'x weeks' => function($x) { + return $x . ' 周'; + }, + 'x days' => function($x) { + return $x . ' 天'; + }, + 'x hours' => function($x) { + return $x . ' 小时'; + }, + 'x minutes' => function($x) { + return $x . ' 分钟'; + }, + 'x seconds' => function($x) { + return $x . '秒'; + }, +]; diff --git a/web/app/models/UOJLocale.php b/web/app/models/UOJLocale.php index 119fa13..4c5509f 100644 --- a/web/app/models/UOJLocale.php +++ b/web/app/models/UOJLocale.php @@ -2,7 +2,7 @@ class UOJLocale { public static $supported_locales = array('zh-cn', 'en'); - public static $supported_modules = array('basic', 'contests', 'problems'); + public static $supported_modules = array('basic', 'contests', 'problems', 'time'); public static $data = array(); public static $required = array(); diff --git a/web/app/views/user-info.php b/web/app/views/user-info.php index 9a84368..8ea54c1 100644 --- a/web/app/views/user-info.php +++ b/web/app/views/user-info.php @@ -1,3 +1,66 @@ + $gran; $i--) { + $w[$i] = intval($secondsLeft / $d[$i][0]); + $secondsLeft -= ($w[$i] * $d[$i][0]); + if ($w[$i] != 0) { + $return .= UOJLocale::get('time::x ' . $d[$i][1], abs($w[$i])) . " "; + switch ($i) { + case 6: // shows years and months + if ($stopat == 0) { + $stopat = 5; + } + break; + case 5: // shows months and weeks + if ($stopat == 0) { + $stopat = 4; + } + break; + case 4: // shows weeks and days + if ($stopat == 0) { + $stopat = 3; + } + break; + case 3: // shows days and hours + if ($stopat == 0) { + $stopat = 2; + } + break; + case 2: // shows hours and minutes + if ($stopat == 0) { + $stopat = 1; + } + break; + case 1: // shows minutes and seconds if granularity is not set higher + break; + } + if ($i === $stopat) { + break; + } + } + } + + $return .= ($diff > 0) ? UOJLocale::get('time::ago') : UOJLocale::get('time::left'); + + return $return; +} +?> +
@@ -73,6 +136,23 @@ +
@@ -107,14 +187,14 @@
+$result = []; +$vis = []; +$cnt = 0; +while ($row = DB::fetch($_result)) { + $cnt++; + $result[$row["date_format(submit_time, '%Y-%m-%d')"]]++; +} +?>

@@ -169,6 +249,14 @@ $_result = DB::query("select date_format(submit_time, '%Y-%m-%d'), problem_id fr
http_x_forwarded_for

+
  • +
    last_login
    +

    +
  • +
  • +
    last_visited
    +

    +