From b06ec101ec77674b97e23c57357be4792805c60b Mon Sep 17 00:00:00 2001 From: Elson Costa Date: Wed, 3 Apr 2024 14:53:46 -0300 Subject: [PATCH] improvement: serverinfo page (#89) --- common.php | 2 ++ index.php | 1 + system/status.php | 21 ++++++++++++--------- system/templates/serverinfo.html.twig | 7 +++++-- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/common.php b/common.php index c181966f3d..ca3f134726 100644 --- a/common.php +++ b/common.php @@ -106,6 +106,8 @@ $basedir = str_replace(array('/admin', '/install', '/tools'), '', $basedir); define('BASE_DIR', $basedir); +$TABLE_PREFIX = TABLE_PREFIX; + if (file_exists(BASE . 'config.local.php') && !defined('MYAAC_INSTALL')) { require BASE . 'config.local.php'; } diff --git a/index.php b/index.php index ff88b33c54..65a64c69c8 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,5 @@ query( - 'SELECT `name`, `value` FROM `' . - TABLE_PREFIX . - 'config` WHERE ' . - $db->fieldName('name') . - ' LIKE "%status%"' + "SELECT `name`, `value` FROM `{$TABLE_PREFIX}config` WHERE {$db->fieldName( + 'name' + )} LIKE '%status%'" ); if ($status_query->rowCount() <= 0) { // empty, just insert it @@ -135,10 +134,14 @@ function updateStatus() } } - $status['uptime'] = $serverStatus->getUptime(); - $h = floor($status['uptime'] / 3600); - $m = floor(($status['uptime'] - $h * 3600) / 60); - $status['uptimeReadable'] = $h . 'h ' . $m . 'm'; + $uptime = $status['uptime'] = $serverStatus->getUptime(); + $m = date('m', $uptime); + $m = $m > 1 ? "$m months, " : ($m == 1 ? 'month, ' : ''); + $d = date('d', $uptime); + $d = $d > 1 ? "$d days, " : ($d == 1 ? 'day, ' : ''); + $h = date('H', $uptime); + $min = date('i', $uptime); + $status['uptimeReadable'] = "{$m}{$d}{$h}h {$min}m"; $status['monsters'] = $serverStatus->getMonstersCount(); $status['motd'] = $serverStatus->getMOTD(); diff --git a/system/templates/serverinfo.html.twig b/system/templates/serverinfo.html.twig index 41fe953fbf..38383037ce 100644 --- a/system/templates/serverinfo.html.twig +++ b/system/templates/serverinfo.html.twig @@ -1,6 +1,6 @@