diff --git a/inc/functions.php b/inc/functions.php index 36ee9807..70520334 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -27,7 +27,6 @@ } function openBoard($uri) { - global $sql; sql_open(); $query = prepare("SELECT * FROM `boards` WHERE `uri` = :uri LIMIT 1"); @@ -46,6 +45,71 @@ return $boards; } + function until($timestamp) { + $difference = $timestamp - time(); + if($difference < 60) { + return $difference . ' second' . ($difference != 1 ? 's' : ''); + } elseif($difference < 60*60) { + return ($num = round($difference/(60))) . ' minute' . ($num != 1 ? 's' : ''); + } elseif($difference < 60*60*24) { + return ($num = round($difference/(60*60))) . ' hour' . ($num != 1 ? 's' : ''); + } elseif($difference < 60*60*24*7) { + return ($num = round($difference/(60*60*24))) . ' day' . ($num != 1 ? 's' : ''); + } elseif($difference < 60*60*24*7*52) { + return ($num = round($difference/(60*60*24*7))) . ' week' . ($num != 1 ? 's' : ''); + } else { + return ($num = round($difference/(60*60*24*7*52))) . ' year' . ($num != 1 ? 's' : ''); + } + } + + function formatDate($timestamp) { + return date('jS F, Y', $timestamp); + } + + function checkBan() { + if(!isset($_SERVER['REMOTE_ADDR'])) { + // Server misconfiguration + return; + } + + $query = prepare("SELECT * FROM `bans` WHERE `ip` = :ip LIMIT 1"); + $query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); + $query->execute() or error(db_error($query)); + + if($ban = $query->fetch()) { + $body = '
You have been banned ' . + ($ban['reason'] ? 'for the following reason:' : 'for an unspecified reason.') . + '
' . + ($ban['reason'] ? + '' . + $ban['reason'] . + '
' + : '') . + 'Your ban was filed on ' . + formatDate($ban['set']) . + ', and ' . + ($ban['expires'] ? + 'expires on ' . + formatDate($ban['expires']) . + ', which is ' . until($ban['expires']) . ' from now' + : 'does not expire' ) . + '.
+Your IP address is ' . $_SERVER['REMOTE_ADDR'] . '.
+