Bans page working for TFS 1.x + move to Twig (#140)

* Bans page working for TFS 1.x + move to Twig

* Remove some debug code

* Add some protection

* Better check.
This commit is contained in:
slawkens 2020-10-30 06:52:50 +01:00 committed by GitHub
parent 95c2adc02e
commit 5d5875d540
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 146 additions and 68 deletions

View File

@ -199,8 +199,7 @@ $config = array(
'team_display_outfit' => true, 'team_display_outfit' => true,
// bans page // bans page
'bans_limit' => 50, 'bans_per_page' => 20,
'bans_display_all' => true, // should all bans be displayed? (sorted page by page)
// highscores page // highscores page
'highscores_vocation_box' => true, // show 'Choose a vocation' box on the highscores (allowing peoples to sort highscores by vocation)? 'highscores_vocation_box' => true, // show 'Choose a vocation' box on the highscores (allowing peoples to sort highscores by vocation)?

View File

@ -97,6 +97,7 @@ else {
'/^account\/character\/comment\/[A-Za-z0-9-_%+\']+\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'change_comment', 'name' => '$3'), '/^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\/character\/comment\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'change_comment'),
'/^account\/confirm_email\/[A-Za-z0-9-_]+\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'confirm_email', 'v' => '$2'), '/^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'), '/^characters\/[A-Za-z0-9-_%+\']+$/' => array('subtopic' => 'characters', 'name' => '$1'),
'/^changelog\/[0-9]+\/?$/' => array('subtopic' => 'changelog', 'page' => '$1'), '/^changelog\/[0-9]+\/?$/' => array('subtopic' => 'changelog', 'page' => '$1'),
'/^commands\/add\/?$/' => array('subtopic' => 'commands', 'action' => 'add'), '/^commands\/add\/?$/' => array('subtopic' => 'commands', 'action' => 'add'),

View File

@ -11,82 +11,121 @@
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
$title = 'Bans list'; $title = 'Bans list';
if($config['otserv_version'] == TFS_02) $configBansPerPage = config('bans_per_page');
{ $_page = isset($_GET['page']) ? $_GET['page'] : 1;
echo 'Bans page doesnt work on TFS 0.2/1.0.';
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; return;
} }
if(!$config['bans_display_all']) if(!$bansQuery->rowCount())
echo 'Last ' . $config['bans_limit'] . ' banishments.<br/><br/>';
if($config['bans_display_all'])
{ {
$_page = isset($_GET['page']) ? $_GET['page'] : 0; echo 'There are no banishments yet.';
$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.
<?php
return; return;
} }
?>
<table border="0" cellspacing="1" cellpadding="4" width="100%"> $nextPage = false;
<tr align="center" bgcolor="<?php echo $config['vdarkborder']; ?>" class="white"> $i = 0;
<td><span style="color: white"><b>Nick</b></span></td> $bans = $bansQuery->fetchAll();
<td><span style="color: white"><b>Type</b></span></td> foreach ($bans as $id => &$ban)
<td><span style="color: white"><b>Expires</b></span></td>
<td><span style="color: white"><b>Reason</b></span></td>
<td><span style="color: white"><b>Comment</b></span></td>
<td><span style="color: white"><b>Added by:</b></span></td>
</tr>
<?php
foreach($bans as $ban)
{ {
if($i++ > 100) if(++$i > $configBansPerPage)
{ {
$next_page = true; unset($bans[$id]);
$nextPage = true;
break; break;
} }
?>
<tr align="center" bgcolor="<?php echo getStyle($i); ?>">
<td height="50" width="140"><?php echo getPlayerLink(getPlayerNameByAccount($ban['value'])); ?></td>
<td><?php echo getBanType($ban['type']); ?></td>
<td>
<?php
if($ban['expires'] == "-1")
echo 'Never';
else
echo date("H:i:s", $ban['expires']) . '<br/>' . date("d M Y", $ban['expires']);
?>
</td>
<td><?php echo getBanReason($ban['reason']); ?></td>
<td><?php echo $ban['comment']; ?></td>
<td>
<?php
if($ban['admin_id'] == "0")
echo 'Autoban';
else
echo getPlayerLink(getPlayerNameByAccount($ban['admin_id']));
echo '<br/>' . date("d.m.Y", $ban['added']); $ban['i'] = $i;
?> if ($db->hasColumn('bans', 'value')) {
</td> $accountId = $ban['value'];
</tr> }
<?php 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]) . '<br/>' . 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) . '<br/>' . date('d.M.Y', $addedTime);
$ban['addedBy'] = $addedBy;
} }
?>
</table>
<table border="0" cellpadding="4" cellspacing="1" width="100%">
<?php
if($_page > 0)
echo '<tr><td width="100%" align="right" valign="bottom"><a href="?subtopic=bans&page=' . ($_page - 1) . '" class="size_xxs">Previous Page</a></td></tr>';
if($next_page) $twig->display('bans.html.twig', [
echo '<tr><td width="100%" align="right" valign="bottom"><a href="?subtopic=bans&page=' . ($_page + 1) . '" class="size_xxs">Next Page</a></td></tr>'; 'bans' => $bans,
?> 'configBans' => $configBans,
</table> 'page' => $_page,
'nextPage' => $nextPage,
]);

View File

@ -0,0 +1,39 @@
<table border="0" cellspacing="1" cellpadding="4" width="100%">
<tr align="center" bgcolor="{{ config.vdarkborder }}" class="white">
<td><span style="color: white"><b>Nick</b></span></td>
{% if configBans.hasType %}
<td><span style="color: white"><b>Type</b></span></td>
{% endif %}
<td><span style="color: white"><b>Expires</b></span></td>
{% if configBans.hasReason %}
<td><span style="color: white"><b>Reason</b></span></td>
{% endif %}
<td><span style="color: white"><b>Comment</b></span></td>
<td><span style="color: white"><b>Added by:</b></span></td>
</tr>
{% for ban in bans %}
<tr align="center" bgcolor="{{ getStyle(ban.i) }}">
<td height="50" width="140">{{ ban.player|raw }}</td>
{% if configBans.hasType %}
<td>{{ ban.type }}</td>
{% endif %}
<td>{{ ban.expires|raw }}</td>
{% if configBans.hasReason %}
<td>{{ ban.reason }}</td>
{% endif %}
<td>{{ ban.comment }}</td>
<td>
{{ ban.addedBy|raw }}<br/>
{{ ban.addedTime|raw }}
</td>
</tr>
{% endfor %}
</table>
<table border="0" cellpadding="4" cellspacing="1" width="100%">
{% if page > 1 %}
<tr><td width="100%" align="right" valign="bottom"><a href="{{ getLink('bans') }}/{{ (page - 1) }}" class="size_xxs">Previous Page</a></td></tr>
{% endif %}
{% if nextPage %}
<tr><td width="100%" align="right" valign="bottom"><a href="{{ getLink('bans') }}/{{ (page + 1) }}" class="size_xxs">Next Page</a></td></tr>
{% endif %}
</table>