2015-07-08 13:09:57 +00:00
|
|
|
<?php
|
2016-02-03 22:22:56 +00:00
|
|
|
/**
|
|
|
|
* Holds the ban manager.
|
2016-03-08 23:07:58 +00:00
|
|
|
*
|
2016-02-03 22:22:56 +00:00
|
|
|
* @package Sakura
|
|
|
|
*/
|
|
|
|
|
2015-07-08 13:09:57 +00:00
|
|
|
namespace Sakura;
|
|
|
|
|
2015-10-18 19:06:30 +00:00
|
|
|
/**
|
2016-02-02 21:04:15 +00:00
|
|
|
* User banishment management.
|
2016-03-08 23:07:58 +00:00
|
|
|
*
|
2015-10-18 19:06:30 +00:00
|
|
|
* @package Sakura
|
2016-02-02 21:04:15 +00:00
|
|
|
* @author Julian van de Groep <me@flash.moe>
|
2015-10-18 19:06:30 +00:00
|
|
|
*/
|
2015-09-14 20:51:23 +00:00
|
|
|
class Bans
|
|
|
|
{
|
2016-02-02 21:04:15 +00:00
|
|
|
/**
|
|
|
|
* Checks if a user is banned.
|
2016-03-08 23:07:58 +00:00
|
|
|
*
|
2016-02-02 21:04:15 +00:00
|
|
|
* @param int $uid The ID of the user that is being checked.
|
2016-03-08 23:07:58 +00:00
|
|
|
*
|
2016-02-02 21:04:15 +00:00
|
|
|
* @return array|bool Either false or an array containing information about the ban.
|
|
|
|
*/
|
2015-09-14 20:51:23 +00:00
|
|
|
public static function checkBan($uid)
|
|
|
|
{
|
2015-07-30 01:12:53 +00:00
|
|
|
|
2015-07-30 17:07:23 +00:00
|
|
|
// Attempt to get a ban from this user
|
2016-02-25 16:06:29 +00:00
|
|
|
$bans = DB::table('bans')
|
|
|
|
->where('user_id', $uid)
|
|
|
|
->get();
|
2015-07-30 17:07:23 +00:00
|
|
|
|
|
|
|
// Reverse the array so new bans are listed first
|
|
|
|
$bans = array_reverse($bans);
|
|
|
|
|
|
|
|
// Go over each ban
|
2015-09-14 20:51:23 +00:00
|
|
|
foreach ($bans as $ban) {
|
2015-07-30 17:07:23 +00:00
|
|
|
// Check if it hasn't expired
|
2016-02-18 23:28:44 +00:00
|
|
|
if ($ban->ban_end != 0 && $ban->ban_end < time()) {
|
2015-07-30 17:07:23 +00:00
|
|
|
// If it has delete the entry and continue
|
2016-02-25 16:06:29 +00:00
|
|
|
DB::table('bans')
|
|
|
|
->where('ban_id', $ban->ban_id)
|
|
|
|
->delete();
|
2015-07-30 17:07:23 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the ban if all checks were passed
|
2015-07-30 01:12:53 +00:00
|
|
|
return [
|
2016-02-18 23:28:44 +00:00
|
|
|
'user' => $ban->user_id,
|
|
|
|
'issuer' => $ban->ban_moderator,
|
|
|
|
'issued' => $ban->ban_begin,
|
|
|
|
'expires' => $ban->ban_end,
|
|
|
|
'reason' => $ban->ban_reason,
|
2015-07-30 01:12:53 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2015-07-30 17:07:23 +00:00
|
|
|
// Else just return false
|
|
|
|
return false;
|
2015-07-30 01:12:53 +00:00
|
|
|
}
|
2015-07-08 13:09:57 +00:00
|
|
|
}
|