diff options
| author | Savetheinternet <savetheinternet@n0v4.com> | 2011-01-02 01:37:52 +1100 |
|---|---|---|
| committer | Savetheinternet <savetheinternet@n0v4.com> | 2011-01-02 01:37:52 +1100 |
| commit | 3c24ecd412d3b589e4ad5382deec4ffc1656f98f (patch) | |
| tree | 0dfbb8e0b885143aea4d786a72190c1ab552878b | |
| parent | eeb512f54971245dcc7ba63eb616265e0de90902 (diff) | |
Bans
| -rw-r--r-- | inc/functions.php | 74 | ||||
| -rw-r--r-- | post.php | 3 |
2 files changed, 72 insertions, 5 deletions
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 = '<div class="ban"> + <h2>You are banned! ;_;</h2> + <p>You have been banned ' . + ($ban['reason'] ? 'for the following reason:' : 'for an unspecified reason.') . + '</p>' . + ($ban['reason'] ? + '<p class="reason">' . + $ban['reason'] . + '</p>' + : '') . + '<p>Your ban was filed on <strong>' . + formatDate($ban['set']) . + '</strong>, and ' . + ($ban['expires'] ? + 'expires on <strong>' . + formatDate($ban['expires']) . + '</strong>, which is ' . until($ban['expires']) . ' from now' + : '<em>does not expire</em>' ) . + '.</p> + <p>Your IP address is <strong>' . $_SERVER['REMOTE_ADDR'] . '</strong>.</p> + </div>'; + + // Show banned page and exit + die(Element('page.html', Array( + 'index' => ROOT, + 'title' => 'Banned', + 'subtitle' => 'You are banned!', + 'body' => $body + ) + )); + } + } + function threadExists($id) { global $board; @@ -117,7 +181,7 @@ } function index($page, $mod=false) { - global $sql, $board; + global $board; $body = ''; $offset = round($page*THREADS_PER_PAGE-THREADS_PER_PAGE); @@ -162,7 +226,7 @@ } function getPages($mod=false) { - global $sql, $board; + global $board; // Count threads $query = query(sprintf("SELECT COUNT(`id`) as `num` FROM `posts_%s` WHERE `thread` IS NULL", $board['uri'])) or error(db_error()); @@ -179,7 +243,7 @@ } function buildIndex() { - global $sql, $board; + global $board; sql_open(); $pages = getPages(); @@ -206,7 +270,7 @@ } function markup(&$body) { - global $sql, $board; + global $board; if(AUTO_UNICODE) { $body = str_replace('...', '…', $body); @@ -59,6 +59,9 @@ // Open database connection sql_open(); + // Check if banned + checkBan(); + // Check if board exists if(!openBoard($post['board'])) error(ERROR_NOBOARD); |
