diff --git a/config.php b/config.php index 376fad1d..6f8063ae 100644 --- a/config.php +++ b/config.php @@ -199,8 +199,7 @@ $config = array( 'team_display_outfit' => true, // bans page - 'bans_limit' => 50, - 'bans_display_all' => true, // should all bans be displayed? (sorted page by page) + 'bans_per_page' => 20, // highscores page 'highscores_vocation_box' => true, // show 'Choose a vocation' box on the highscores (allowing peoples to sort highscores by vocation)? diff --git a/index.php b/index.php index c2361fd1..b84a3ce8 100644 --- a/index.php +++ b/index.php @@ -97,6 +97,7 @@ else { '/^account\/character\/comment\/[A-Za-z0-9-_%+\']+\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'change_comment', 'name' => '$3'), '/^account\/character\/comment\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'change_comment'), '/^account\/confirm_email\/[A-Za-z0-9-_]+\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'confirm_email', 'v' => '$2'), + '/^bans\/[0-9]+\/?$/' => array('subtopic' => 'bans', 'page' => '$1'), '/^characters\/[A-Za-z0-9-_%+\']+$/' => array('subtopic' => 'characters', 'name' => '$1'), '/^changelog\/[0-9]+\/?$/' => array('subtopic' => 'changelog', 'page' => '$1'), '/^commands\/add\/?$/' => array('subtopic' => 'commands', 'action' => 'add'), diff --git a/system/pages/bans.php b/system/pages/bans.php index c08fdc2f..5e87577a 100644 --- a/system/pages/bans.php +++ b/system/pages/bans.php @@ -11,82 +11,121 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Bans list'; -if($config['otserv_version'] == TFS_02) -{ - echo 'Bans page doesnt work on TFS 0.2/1.0.'; +$configBansPerPage = config('bans_per_page'); +$_page = isset($_GET['page']) ? $_GET['page'] : 1; + +if(!is_numeric($_page) || $_page > PHP_INT_MAX) { + $_page = 1; +} + +if ($_page > 1) { + $offset = ($_page - 1) * $configBansPerPage; +} +else { + $offset = 0; +} + +/** + * @var OTS_DB_MySQL $db + */ +$configBans = []; +$configBans['hasType'] = false; +$configBans['hasReason'] = false; + +$limit = 'LIMIT ' . ($configBansPerPage + 1) . (isset($offset) ? ' OFFSET ' . $offset : ''); +if ($db->hasTable('account_bans')) { + $bansQuery = $db->query('SELECT * FROM `account_bans` ORDER BY `banned_at` DESC ' . $limit); +} +else if ($db->hasTable('bans') && $db->hasColumn('bans', 'active') + && $db->hasColumn('bans', 'type') && $db->hasColumn('bans', 'reason')) { + $bansQuery = $db->query('SELECT * FROM `bans` WHERE `active` = 1 ORDER BY `added` DESC ' . $limit); + $configBans['hasType'] = true; + $configBans['hasReason'] = true; +} +else { + echo 'Bans list is not supported in your distribution.'; return; } -if(!$config['bans_display_all']) - echo 'Last ' . $config['bans_limit'] . ' banishments.

'; - -if($config['bans_display_all']) +if(!$bansQuery->rowCount()) { - $_page = isset($_GET['page']) ? $_GET['page'] : 0; - $offset = $_page * $config['bans_limit'] + 1; -} - -$bans = $db->query('SELECT * FROM ' . $db->tableName('bans') . ' WHERE ' . $db->fieldName('active') . ' = 1 ORDER BY ' . $db->fieldName('added') . ' DESC LIMIT ' . ($config['bans_limit'] + 1) . (isset($offset) ? ' OFFSET ' . $offset : '')); -if(!$bans->rowCount()) -{ -?> - There are no banishments yet. - - - - - - - - - - -fetchAll(); +foreach ($bans as $id => &$ban) { - if($i++ > 100) + if(++$i > $configBansPerPage) { - $next_page = true; + unset($bans[$id]); + $nextPage = true; break; } -?> - - - - - - - - -hasColumn('bans', 'value')) { + $accountId = $ban['value']; + } + else { + // TFS 1.x + $accountId = $ban['account_id']; + } + + $ban['player'] = getPlayerLink(getPlayerNameByAccount($accountId)); + + if ($configBans['hasType']) { + $ban['type'] = getBanType($ban['type']); + } + + $expiresColumn = 'expires_at'; + if ($db->hasColumn('bans', 'expires')) { + $expiresColumn = 'expires'; + } + + if ((int)$ban[$expiresColumn] === -1) { + $ban['expires'] = 'Never'; + } + else { + $ban['expires'] = date('H:i:s', $ban[$expiresColumn]) . '
' . date('d.M.Y', $ban[$expiresColumn]); + } + + if ($configBans['hasReason']) { + $ban['reason'] = getBanReason($ban['reason']); + } + else { + $ban['comment'] = $ban['reason']; + } + + $addedBy = ''; + if ($db->hasColumn('bans', 'admin_id')) { + if ((int)$ban['admin_id'] === 0) { + $addedBy = 'Autoban'; + } + else { + $addedBy = getPlayerLink(getPlayerNameByAccount($ban['admin_id'])); + } + } + else { + $addedBy = getPlayerLink(getPlayerNameByAccount($ban['banned_by'])); + } + + if ($db->hasColumn('bans', 'added')) { + $addedTime = $ban['added']; + } + else { + $addedTime = $ban['banned_at']; + } + + $ban['addedTime'] = date('H:i:s', $addedTime) . '
' . date('d.M.Y', $addedTime); + $ban['addedBy'] = $addedBy; } -?> -
NickTypeExpiresReasonCommentAdded by:
-' . date("d M Y", $ban['expires']); -?> - -' . date("d.m.Y", $ban['added']); -?> -
- - 0) - echo ''; -if($next_page) - echo ''; -?> -
Previous Page
Next Page
+$twig->display('bans.html.twig', [ + 'bans' => $bans, + 'configBans' => $configBans, + 'page' => $_page, + 'nextPage' => $nextPage, +]); diff --git a/system/templates/bans.html.twig b/system/templates/bans.html.twig new file mode 100644 index 00000000..f0ae2611 --- /dev/null +++ b/system/templates/bans.html.twig @@ -0,0 +1,39 @@ + + + + {% if configBans.hasType %} + + {% endif %} + + {% if configBans.hasReason %} + + {% endif %} + + + + {% for ban in bans %} + + + {% if configBans.hasType %} + + {% endif %} + + {% if configBans.hasReason %} + + {% endif %} + + + + {% endfor %} +
NickTypeExpiresReasonCommentAdded by:
{{ ban.player|raw }}{{ ban.type }}{{ ban.expires|raw }}{{ ban.reason }}{{ ban.comment }} + {{ ban.addedBy|raw }}
+ {{ ban.addedTime|raw }} +
+ +{% if page > 1 %} + +{% endif %} +{% if nextPage %} + +{% endif %} +
Previous Page
Next Page