From 239a12cefefce24d9305198066d61b449d14e7f8 Mon Sep 17 00:00:00 2001 From: tslocum Date: Fri, 31 Dec 2010 15:24:55 -0800 Subject: [PATCH] code clean up --- README | 48 +++++++++++++++++++++++++---------------------- imgboard.php | 42 +++++++---------------------------------- inc/functions.php | 22 ++++++++++++++++++++++ 3 files changed, 55 insertions(+), 57 deletions(-) diff --git a/README b/README index 7e7efbd..96e1a96 100644 --- a/README +++ b/README @@ -1,25 +1,29 @@ -TinyIB by tslocum -http://tslocum.github.com/ +TinyIB +==== -Supports MySQL, SQLite, and flat file database modes. +PHP image board +Supports MySQL, SQLite, and native flat file for post storage. -To install TinyIB: -- CD to the directory you wish to install TinyIB -- Run the following command: ---- git clone git://github.com/tslocum/TinyIB.git ./ -- Rename settings.default.php to settings.php -- Configure settings.php -- CHMOD write permissions to the following directories: ---- / ---- src/ ---- thumb/ ---- res/ ---- inc/flatfile/ (if using flatfile mode) -- Open your browser of choice and navigate to imgboard.php, causing the following to take place: ---- Create database structure based on chosen mode ---- Test appropriate directories are writable ---- Write index.html with a blank image board +Installing +------------ -To update TinyIB: -- Run the following command: ---- git pull \ No newline at end of file + 1. CD to the directory you wish to install TinyIB + 2. Run the following command: + - `git clone git://github.com/tslocum/TinyIB.git ./` + 3. Rename settings.default.php to settings.php + 4. Configure settings.php + 5. CHMOD write permissions to the following directories: + - / + - src/ + - thumb/ + - res/ + - inc/flatfile/ (if you choose to use flat file) + 6. Navigate your browser to imgboard.php, which causes the following to take place: + - Create database structure + - Check necessary directories are writable + - Write index.html containing the new image board + +Updating +------------ + +`git pull` diff --git a/imgboard.php b/imgboard.php index d0307aa..7cd69f8 100644 --- a/imgboard.php +++ b/imgboard.php @@ -53,26 +53,10 @@ if (TINYIB_TRIPSEED == '' || TINYIB_ADMINPASS == '') { $redirect = true; // Check if the request is to make a post if (isset($_POST["message"]) || isset($_POST["file"])) { - $ban = banByIP($_SERVER['REMOTE_ADDR']); - if ($ban) { - if ($ban['expire'] == 0 || $ban['expire'] > time()) { - $expire = ($ban['expire'] > 0) ? ('Your ban will expire ' . date('y/m/d(D)H:i:s', $ban['expire'])) : 'The ban on your IP address is permanent and will not expire.'; - $reason = ($ban['reason'] == '') ? '' : ('
The reason provided was: ' . $ban['reason']); - fancyDie('Sorry, it appears that you have been banned from posting on this image board. ' . $expire . $reason); - } else { - clearExpiredBans(); - } - } - list($loggedin, $isadmin) = manageCheckLogIn(); $modpost = isModPost(); - - $lastpost = lastPostByIP(); - if ($lastpost) { - if ((time() - $lastpost['timestamp']) < 30) { - fancyDie("Please wait a moment before posting again. You will be able to make another post in " . (30 - (time() - $lastpost['timestamp'])) . " " . plural("second", (30 - (time() - $lastpost['timestamp']))) . "."); - } - } + checkBanned(); + checkFlood(); if (strlen($_POST["message"]) > 8000) { fancyDie("Please shorten your message, or post it in multiple parts. Your message is " . strlen($_POST["message"]) . " characters long, and the maximum allowed is 8000."); @@ -88,17 +72,13 @@ if (isset($_POST["message"]) || isset($_POST["file"])) { $post['email'] = cleanString(str_replace('"', '"', substr($_POST["email"], 0, 75))); $post['subject'] = cleanString(substr($_POST["subject"], 0, 75)); if ($modpost) { - if ($isadmin) { - $modposttext = ' ## Admin'; - } else { - $modposttext = ' ## Mod'; - } - $post['message'] = $_POST["message"]; + $modposttext = ($isadmin) ? ' ## Admin' : ' ## Mod'; + $post['message'] = $_POST["message"]; // Treat message as raw HTML } else { $modposttext = ''; $post['message'] = str_replace("\n", "
", colorQuote(cleanString(rtrim($_POST["message"])))); } - if ($_POST['password'] != '') { $post['password'] = md5(md5($_POST['password'])); } else { $post['password'] = ''; } + $post['password'] = ($_POST['password'] != '') ? md5(md5($_POST['password'])) : ''; if (strtolower($post['email']) == "noko") { $post['email'] = ''; $noko = true; @@ -174,11 +154,7 @@ if (isset($_POST["message"]) || isset($_POST["file"])) { $post['id'] = insertPost($post); if ($noko) { - if ($post['parent'] != '0') { - $redirect = 'res/' . $post['parent'] . '.html#' . $post['id']; - } else { - $redirect = 'res/' . $post['id'] . '.html#' . $post['id']; - } + $redirect = ($post['parent'] != '0') ? 'res/' . $post['parent'] . '.html#' . $post['id'] : 'res/' . $post['id'] . '.html#' . $post['id']; } trimThreads(); echo 'Updating thread page...
'; @@ -310,11 +286,7 @@ if (isset($_POST["message"]) || isset($_POST["file"])) { } if ($redirect) { - if (is_string($redirect)) { - echo '--> --> -->'; - } else { - echo '--> --> -->'; - } + echo '--> --> -->'; } ?> \ No newline at end of file diff --git a/inc/functions.php b/inc/functions.php index fa0d88a..222f68e 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -163,6 +163,28 @@ function deletePostImages($post) { if ($post['thumb'] != '') { @unlink('thumb/' . $post['thumb']); } } +function checkBanned() { + $ban = banByIP($_SERVER['REMOTE_ADDR']); + if ($ban) { + if ($ban['expire'] == 0 || $ban['expire'] > time()) { + $expire = ($ban['expire'] > 0) ? ('Your ban will expire ' . date('y/m/d(D)H:i:s', $ban['expire'])) : 'The ban on your IP address is permanent and will not expire.'; + $reason = ($ban['reason'] == '') ? '' : ('
The reason provided was: ' . $ban['reason']); + fancyDie('Sorry, it appears that you have been banned from posting on this image board. ' . $expire . $reason); + } else { + clearExpiredBans(); + } + } +} + +function checkFlood() { + $lastpost = lastPostByIP(); + if ($lastpost) { + if ((time() - $lastpost['timestamp']) < 30) { + fancyDie("Please wait a moment before posting again. You will be able to make another post in " . (30 - (time() - $lastpost['timestamp'])) . " " . plural("second", (30 - (time() - $lastpost['timestamp']))) . "."); + } + } +} + function manageCheckLogIn() { $loggedin = false; $isadmin = false; if (isset($_POST['password'])) {