various improvements

This commit is contained in:
Michael Save 2012-04-16 16:40:24 +10:00
parent fb3e819132
commit ad55a634bf
7 changed files with 247 additions and 37 deletions

View file

@ -16,44 +16,45 @@ function parse_time($str) {
if (($time = @strtotime($str)) !== false)
return $time;
if (!preg_match('/^((\d+)\s*ye?a?r?s?)?\s*+((\d+)\s*mon?t?h?s?)?\s*((\d+)\s*we?e?k?s?)?\s*((\d+)\s*da?y?s?)?((\d+)\s*ho?u?r?s?)?\s*((\d+)\s*mi?n?u?t?e?s?)?\s*+((\d+)\s*se?c?o?n?d?s?)?$/', $str, $matches))
if (!preg_match('/^((\d+)\s?ye?a?r?s?)?\s?+((\d+)\s?mon?t?h?s?)?\s?+((\d+)\s?we?e?k?s?)?\s?+((\d+)\s?da?y?s?)?((\d+)\s?ho?u?r?s?)?\s?+((\d+)\s?mi?n?u?t?e?s?)?\s?+((\d+)\s?se?c?o?n?d?s?)?$/', $str, $matches))
return false;
$expire = time();
if (isset($m[2])) {
$expire = 0;
if (isset($matches[2])) {
// Years
$expire += $m[2]*60*60*24*365;
$expire += $matches[2]*60*60*24*365;
}
if (isset($m[4])) {
if (isset($matches[4])) {
// Months
$expire += $m[4]*60*60*24*30;
$expire += $matches[4]*60*60*24*30;
}
if (isset($m[6])) {
if (isset($matches[6])) {
// Weeks
$expire += $m[6]*60*60*24*7;
$expire += $matches[6]*60*60*24*7;
}
if (isset($m[8])) {
if (isset($matches[8])) {
// Days
$expire += $m[8]*60*60*24;
$expire += $matches[8]*60*60*24;
}
if (isset($m[10])) {
if (isset($matches[10])) {
// Hours
$expire += $m[10]*60*60;
$expire += $matches[10]*60*60;
}
if (isset($m[12])) {
if (isset($matches[12])) {
// Minutes
$expire += $m[12]*60;
$expire += $matches[12]*60;
}
if (isset($m[14])) {
if (isset($matches[14])) {
// Seconds
$expire += $m[14];
$expire += $matches[14];
}
return $expire;
return time() + $expire;
}
function ban($mask, $reason, $length, $board) {
global $mod;
global $mod, $pdo;
// TODO: permissions
@ -78,6 +79,8 @@ function ban($mask, $reason, $length, $board) {
$query->bindValue(':board', null, PDO::PARAM_NULL);
$query->execute() or error(db_error($query));
modLog('Created a new ban (<small>#' . $pdo->lastInsertId() . '</small>) for <strong>' . utf8tohtml($mask) . '</strong> with ' . ($reason ? 'reason: <small>' . $reason . '</small>' : 'no reason'));
}
function unban($id) {
@ -86,5 +89,7 @@ function unban($id) {
$query = prepare("DELETE FROM `bans` WHERE `id` = :id");
$query->bindValue(':id', $id);
$query->execute() or error(db_error($query));
modLog("Removed ban #{$id}");
}