This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/libraries/Bans.php
2016-02-19 00:28:44 +01:00

64 lines
1.6 KiB
PHP

<?php
/**
* Holds the ban manager.
*
* @package Sakura
*/
namespace Sakura;
/**
* User banishment management.
*
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class Bans
{
/**
* Checks if a user is banned.
*
* @param int $uid The ID of the user that is being checked.
*
* @return array|bool Either false or an array containing information about the ban.
*/
public static function checkBan($uid)
{
// Attempt to get a ban from this user
$bans = DB::prepare('SELECT * FROM `{prefix}bans` WHERE `user_id` = :id');
$bans->execute([
'id' => $uid,
]);
$bans = $bans->fetchAll();
// Reverse the array so new bans are listed first
$bans = array_reverse($bans);
// Go over each ban
foreach ($bans as $ban) {
// Check if it hasn't expired
if ($ban->ban_end != 0 && $ban->ban_end < time()) {
// If it has delete the entry and continue
DB::prepare('DELETE FROM `{prefix}bans` WHERE `ban_id` = :id')
->execute([
'id' => $ban->user_id,
]);
continue;
}
// Return the ban if all checks were passed
return [
'user' => $ban->user_id,
'issuer' => $ban->ban_moderator,
'issued' => $ban->ban_begin,
'expires' => $ban->ban_end,
'reason' => $ban->ban_reason,
];
}
// Else just return false
return false;
}
}