Numerous feature additions and code re-writes

This commit is contained in:
Trevor Slocum 2011-08-07 00:24:39 -07:00
parent 4be078ff86
commit 26410cd6ba
11 changed files with 262 additions and 114 deletions

View file

@ -27,10 +27,7 @@ a:hover {
text-decoration:underline;
}
.adminbar {
text-align:right;
background:inherit;
clear:both;
float:right;
}
.logo {
clear:both;
@ -45,6 +42,11 @@ a:hover {
color:#FFFFFF;
width:100%;
}
.manageinfo {
background:#00B930;
color:#FFFFFF;
width:100%;
}
.catalogmode {
background:#0040E0;
color:#FFFFFF;

View file

@ -11,11 +11,6 @@ a:hover {
.reflink a:hover{
font-weight: bold;
}
.adminbar {
text-align:right;
clear:both;
float:right;
}
.logo {
clear:both;
text-align:center;
@ -30,6 +25,13 @@ a:hover {
color:#FFFFFF;
width:100%;
}
.manageinfo {
background:#00B930;
text-align:center;
padding:2px;
color:#FFFFFF;
width:100%;
}
.catalogmode {
background:#0040E0;
text-align:center;

View file

@ -99,4 +99,12 @@ form {
.login {
text-align: center;
}
}
.adminbar {
text-align: right;
clear: both;
float: right;
}
.adminbar a:link, .adminbar a:visited, .adminbar a:active, .adminbar a:hover { text-decoration: none; }

View file

@ -14,7 +14,7 @@ if (get_magic_quotes_gpc()) {
if (get_magic_quotes_runtime()) { set_magic_quotes_runtime(0); }
function fancyDie($message) {
die('<body text="#800000" bgcolor="#FFFFEE" align="center"><br><span style="background-color: #F0E0D6;font-size: 1.25em;font-family: Tahoma, Geneva, sans-serif;padding: 7px;border: 1px solid #D9BFB7;border-left: none;border-top: none;">' . $message . '</span><br><br>- <a href="javascript:history.go(-1)">Click here to go back</a> -</body>');
die('<body text="#800000" bgcolor="#FFFFEE" align="center"><br><div style="display: inline-block; background-color: #F0E0D6;font-size: 1.25em;font-family: Tahoma, Geneva, sans-serif;padding: 7px;border: 1px solid #D9BFB7;border-left: none;border-top: none;">' . $message . '</div><br><br>- <a href="javascript:history.go(-1)">Click here to go back</a> -</body>');
}
if (!file_exists('settings.php')) {
@ -27,11 +27,11 @@ $writedirs = array("res", "src", "thumb");
if (TINYIB_DBMODE == 'flatfile') { $writedirs[] = "inc/flatfile"; }
foreach ($writedirs as $dir) {
if (!is_writable($dir)) {
fancyDie("Directory '" . $dir . "' can not be written to! Please modify its permissions.");
fancyDie("Directory '" . $dir . "' can not be written to. Please modify its permissions.");
}
}
$includes = array("inc/functions.php", "inc/html.php");
$includes = array("inc/defines.php", "inc/functions.php", "inc/html.php");
if (in_array(TINYIB_DBMODE, array('flatfile', 'mysql', 'sqlite'))) {
$includes[] = 'inc/database_' . TINYIB_DBMODE . '.php';
} else {
@ -43,22 +43,21 @@ foreach ($includes as $include) {
}
if (TINYIB_TRIPSEED == '' || TINYIB_ADMINPASS == '') {
fancyDie('TINYIB_TRIPSEED and TINYIB_ADMINPASS must be configured!');
fancyDie('TINYIB_TRIPSEED and TINYIB_ADMINPASS must be configured');
}
$redirect = true;
// Check if the request is to make a post
if (isset($_POST["message"]) || isset($_POST["file"])) {
list($loggedin, $isadmin) = manageCheckLogIn();
$modpost = isModPost();
$rawpost = isRawPost();
if (!$loggedin) {
checkBanned();
checkMessageSize();
checkFlood();
}
$post = newPost();
$post['parent'] = setParent();
$post = newPost(setParent());
$post['ip'] = $_SERVER['REMOTE_ADDR'];
list($post['name'], $post['tripcode']) = nameAndTripcode($_POST["name"]);
@ -66,11 +65,11 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
$post['name'] = cleanString(substr($post['name'], 0, 75));
$post['email'] = cleanString(str_replace('"', '&quot;', substr($_POST["email"], 0, 75)));
$post['subject'] = cleanString(substr($_POST["subject"], 0, 75));
if ($modpost) {
$modposttext = ($isadmin) ? ' <span style="color: red;">## Admin</span>' : ' <span style="color: purple;">## Mod</span>';
if ($rawpost) {
$rawposttext = ($isadmin) ? ' <span style="color: red;">## Admin</span>' : ' <span style="color: purple;">## Mod</span>';
$post['message'] = $_POST["message"]; // Treat message as raw HTML
} else {
$modposttext = '';
$rawposttext = '';
$post['message'] = str_replace("\n", "<br>", colorQuote(postLink(cleanString(rtrim($_POST["message"])))));
}
$post['password'] = ($_POST['password'] != '') ? md5(md5($_POST['password'])) : '';
@ -80,7 +79,7 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
} else {
$noko = false;
}
$post['nameblock'] = nameBlock($post['name'], $post['tripcode'], $post['email'], time(), $modposttext);
$post['nameblock'] = nameBlock($post['name'], $post['tripcode'], $post['email'], time(), $rawposttext);
if (isset($_FILES['file'])) {
if ($_FILES['file']['name'] != "") {
@ -90,16 +89,20 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
fancyDie("File transfer failure. Please retry the submission.");
}
$post['file_original'] = substr(htmlentities($_FILES['file']['name'], ENT_QUOTES), 0, 50);
if ((TINYIB_MAXKB > 0) && (filesize($_FILES['file']['tmp_name']) > (TINYIB_MAXKB * 1024))) {
fancyDie("That file is larger than " . TINYIB_MAXKBDESC . ".");
}
$post['file_original'] = htmlentities(substr($_FILES['file']['name'], 0, 50), ENT_QUOTES);
$post['file_hex'] = md5_file($_FILES['file']['tmp_name']);
$post['file_size'] = $_FILES['file']['size'];
$post['file_size_formatted'] = convertBytes($post['file_size']);
$file_type = strtolower(preg_replace('/.*(\..+)/', '\1', $_FILES['file']['name'])); if ($file_type == '.jpeg') { $file_type = '.jpg'; }
$file_name = time() . mt_rand(1, 99);
$post['thumb'] = $file_name . "s" . $file_type;
$file_name = time() . substr(microtime(), 2, 3);
$post['file'] = $file_name . $file_type;
$thumb_location = "thumb/" . $post['thumb'];
$post['thumb'] = $file_name . "s" . $file_type;
$file_location = "src/" . $post['file'];
$thumb_location = "thumb/" . $post['thumb'];
if (!($file_type == '.jpg' || $file_type == '.gif' || $file_type == '.png')) {
fancyDie("Only GIF, JPG, and PNG files are allowed.");
@ -128,7 +131,7 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
$post['image_width'] = $file_info[0]; $post['image_height'] = $file_info[1];
list($thumb_maxwidth, $thumb_maxheight) = thumbnailDimensions($post['image_width'], $post['image_height']);
if (!createThumbnail($file_location, $thumb_location, $thumb_maxwidth, $thumb_maxheight)) {
fancyDie("Could not create thumbnail.");
}
@ -139,21 +142,23 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
}
if ($post['file'] == '') { // No file uploaded
if ($post['parent'] == '0') {
if ($post['parent'] == TINYIB_NEWTHREAD) {
fancyDie("An image is required to start a thread.");
}
if (str_replace('<br>', '', $post['message']) == "") {
fancyDie("Please enter a message and/or upload an image to make a reply.");
}
} else {
echo $post['file_original'] . ' uploaded.<br>';
}
$post['id'] = insertPost($post);
if ($noko) {
$redirect = 'res/' . ($post['parent'] == '0' ? $post['id'] : $post['parent']) . '.html#' . $post['id'];
$redirect = 'res/' . ($post['parent'] == TINYIB_NEWTHREAD ? $post['id'] : $post['parent']) . '.html#' . $post['id'];
}
trimThreads();
echo 'Updating thread page...<br>';
if ($post['parent'] != '0') {
if ($post['parent'] != TINYIB_NEWTHREAD) {
rebuildThread($post['parent']);
if (strtolower($post['email']) != "sage") {
@ -170,10 +175,15 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
if (isset($_POST['delete'])) {
$post = postByID($_POST['delete']);
if ($post) {
if ($post['password'] != '' && md5(md5($_POST['password'])) == $post['password']) {
list($loggedin, $isadmin) = manageCheckLogIn();
if ($loggedin && $_POST['password'] == '') {
// Redirect to post moderation page
echo '--&gt; --&gt; --&gt;<meta http-equiv="refresh" content="0;url=' . basename($_SERVER['PHP_SELF']) . '?manage&moderate=' . $_POST['delete'] . '">';
} elseif ($post['password'] != '' && md5(md5($_POST['password'])) == $post['password']) {
deletePostByID($post['id']);
if ($post['parent'] == 0) { threadUpdated($post['id']); } else { threadUpdated($post['parent']); }
echo 'Post successfully deleted.';
if ($post['parent'] == TINYIB_NEWTHREAD) { threadUpdated($post['id']); } else { threadUpdated($post['parent']); }
fancyDie('Post deleted.');
} else {
fancyDie('Invalid password.');
}
@ -200,7 +210,7 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
rebuildThread($thread["id"]);
}
rebuildIndexes();
$text .= "Rebuilt board.";
$text .= manageInfo('Rebuilt board.');
} elseif (isset($_GET["bans"])) {
clearExpiredBans();
@ -217,13 +227,13 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
$ban['reason'] = $_POST['reason'];
insertBan($ban);
$text .= '<b>Successfully added a ban record for ' . $ban['ip'] . '</b><br>';
$text .= manageInfo('Ban record added for ' . $ban['ip']);
}
} elseif (isset($_GET['lift'])) {
$ban = banByID($_GET['lift']);
if ($ban) {
deleteBanByID($_GET['lift']);
$text .= '<b>Successfully lifted ban on ' . $ban['ip'] . '</b><br>';
$text .= manageInfo('Ban record lifted for ' . $ban['ip']);
}
}
@ -238,10 +248,10 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
if ($post) {
deletePostByID($post['id']);
rebuildIndexes();
if ($post['parent'] > 0) {
if ($post['parent'] != TINYIB_NEWTHREAD) {
rebuildThread($post['parent']);
}
$text .= '<b>Post No.' . $post['id'] . ' successfully deleted.</b>';
$text .= manageInfo('Post No.' . $post['id'] . ' deleted.');
} else {
fancyDie("Sorry, there doesn't appear to be a post with that ID.");
}
@ -257,18 +267,16 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
$onload = manageOnLoad('moderate');
$text .= manageModeratePostForm();
}
} elseif (isset($_GET["modpost"])) {
$onload = manageOnLoad('modpost');
$text .= manageModpostForm();
} elseif (isset($_GET["rawpost"])) {
$onload = manageOnLoad("rawpost");
$text .= manageRawPostForm();
} elseif (isset($_GET["logout"])) {
$_SESSION['tinyib'] = '';
session_destroy();
die('--&gt; --&gt; --&gt;<meta http-equiv="refresh" content="0;url=' . $returnlink . '?manage">');
}
if ($text == '') {
$threads = countThreads();
$bans = count(allBans());
$text = $threads . ' ' . plural('thread', $threads) . ', ' . $bans . ' ' . plural('ban', $bans) . '.';
$text = manageStatus();
}
} else {
$onload = manageOnLoad('login');

View file

@ -127,7 +127,7 @@ function convertPostsToSQLStyle($posts, $singlepost=false) {
$post['thumb_height'] = $oldpost[POST_THUMB_HEIGHT];
if ($post['parent'] == '') {
$post['parent'] = '0';
$post['parent'] = TINYIB_NEWTHREAD;
}
if ($singlepost) { return $post; }
@ -160,6 +160,11 @@ function postsByHex($hex) {
return convertPostsToSQLStyle($rows);
}
function latestPosts() {
$rows = $GLOBALS['db']->selectWhere(POSTS_FILE, NULL, 10, new OrderBy(POST_TIMESTAMP, DESCENDING, INTEGER_COMPARISON));
return convertPostsToSQLStyle($rows);
}
function deletePostByID($id) {
$posts = postsInThreadByID($id);
foreach ($posts as $post) {

View file

@ -130,6 +130,17 @@ function postsByHex($hex) {
return $posts;
}
function latestPosts() {
$posts = array();
$result = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` ORDER BY `timestamp` DESC LIMIT 10");
if ($result) {
while ($post = mysql_fetch_assoc($result)) {
$posts[] = $post;
}
}
return $posts;
}
function deletePostByID($id) {
$posts = postsInThreadByID($id);
foreach ($posts as $post) {
@ -141,7 +152,7 @@ function deletePostByID($id) {
}
}
if (isset($thispost)) {
if ($thispost['parent'] == 0) {
if ($thispost['parent'] == TINYIB_NEWTHREAD) {
@unlink('res/' . $thispost['id'] . '.html');
}
deletePostImages($thispost);

View file

@ -111,6 +111,15 @@ function postsByHex($hex) {
return $posts;
}
function latestPosts() {
$posts = array();
$result = sqlite_fetch_all(sqlite_query($GLOBALS["db"], "SELECT * FROM " . TINYIB_DBPOSTS . " ORDER BY timestamp DESC LIMIT 10"), SQLITE_ASSOC);
foreach ($result as $post) {
$posts[] = $post;
}
return $posts;
}
function deletePostByID($id) {
$posts = postsInThreadByID($id);
foreach ($posts as $post) {
@ -122,7 +131,7 @@ function deletePostByID($id) {
}
}
if (isset($thispost)) {
if ($thispost['parent'] == 0) {
if ($thispost['parent'] == TINYIB_NEWTHREAD) {
@unlink('res/' . $thispost['id'] . '.html');
}
deletePostImages($thispost);

7
inc/defines.php Normal file
View file

@ -0,0 +1,7 @@
<?php
if (!defined('TINYIB_BOARD')) { die(''); }
define('TINYIB_NEWTHREAD', '0');
define('TINYIB_INDEXPAGE', false);
define('TINYIB_RESPAGE', true);
?>

View file

@ -20,8 +20,8 @@ function threadUpdated($id) {
rebuildIndexes();
}
function newPost() {
return array('parent' => '0',
function newPost($parent = TINYIB_NEWTHREAD) {
return array('parent' => $parent,
'timestamp' => '0',
'bumped' => '0',
'ip' => '',
@ -109,7 +109,7 @@ function nameAndTripcode($name) {
return array($name, "");
}
function nameBlock($name, $tripcode, $email, $timestamp, $modposttext) {
function nameBlock($name, $tripcode, $email, $timestamp, $rawposttext) {
$output = '<span class="postername">';
$output .= ($name == "" && $tripcode == "") ? "Anonymous" : $name;
@ -123,7 +123,7 @@ function nameBlock($name, $tripcode, $email, $timestamp, $modposttext) {
$output = '<a href="mailto:' . $email . '">' . $output . '</a>';
}
return $output . $modposttext . ' ' . date('y/m/d(D)H:i:s', $timestamp);
return $output . $rawposttext . ' ' . date('y/m/d(D)H:i:s', $timestamp);
}
function writePage($filename, $contents) {
@ -150,7 +150,7 @@ function fixLinksInRes($html) {
function _postLink($matches) {
$post = postByID($matches[1]);
if ($post) {
return '<a href="res/' . ($post['parent'] == 0 ? $post['id'] : $post['parent']) . '.html#' . $matches[1] . '">' . $matches[0] . '</a>';
return '<a href="res/' . ($post['parent'] == TINYIB_NEWTHREAD ? $post['id'] : $post['parent']) . '.html#' . $matches[1] . '">' . $matches[0] . '</a>';
}
return $matches[0];
}
@ -173,9 +173,9 @@ 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'] == '') ? '' : ('<br>The reason provided was: ' . $ban['reason']);
fancyDie('Sorry, it appears that you have been banned from posting on this image board. ' . $expire . $reason);
$expire = ($ban['expire'] > 0) ? ('<br>This ban will expire ' . date('y/m/d(D)H:i:s', $ban['expire'])) : '<br>This ban is permanent and will not expire.';
$reason = ($ban['reason'] == '') ? '' : ('<br>Reason: ' . $ban['reason']);
fancyDie('Your IP address ' . $ban['ip'] . ' has been banned from posting on this image board. ' . $expire . $reason);
} else {
clearExpiredBans();
}
@ -183,10 +183,12 @@ function checkBanned() {
}
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']))) . ".");
if (TINYIB_DELAY > 0) {
$lastpost = lastPostByIP();
if ($lastpost) {
if ((time() - $lastpost['timestamp']) < TINYIB_DELAY) {
fancyDie("Please wait a moment before posting again. You will be able to make another post in " . (TINYIB_DELAY - (time() - $lastpost['timestamp'])) . " " . plural("second", (TINYIB_DELAY - (time() - $lastpost['timestamp']))) . ".");
}
}
}
}
@ -221,7 +223,7 @@ function manageCheckLogIn() {
function setParent() {
if (isset($_POST["parent"])) {
if ($_POST["parent"] != "0") {
if ($_POST["parent"] != TINYIB_NEWTHREAD) {
if (!threadExistsByID($_POST['parent'])) {
fancyDie("Invalid parent thread ID supplied, unable to create post.");
}
@ -230,11 +232,11 @@ function setParent() {
}
}
return "0";
return TINYIB_NEWTHREAD;
}
function isModPost() {
if (isset($_POST['modpost'])) {
function isRawPost() {
if (isset($_POST['rawpost'])) {
list($loggedin, $isadmin) = manageCheckLogIn();
if ($loggedin) {
return true;
@ -249,7 +251,7 @@ function validateFileUpload() {
case UPLOAD_ERR_OK:
break;
case UPLOAD_ERR_FORM_SIZE:
fancyDie("That file is larger than 2 MB.");
fancyDie("That file is larger than " . TINYIB_MAXKBDESC . ".");
break;
case UPLOAD_ERR_INI_SIZE:
fancyDie("The uploaded file exceeds the upload_max_filesize directive (" . ini_get('upload_max_filesize') . ") in php.ini.");
@ -275,13 +277,13 @@ function checkDuplicateImage($hex) {
$hexmatches = postsByHex($hex);
if (count($hexmatches) > 0) {
foreach ($hexmatches as $hexmatch) {
fancyDie("Duplicate file uploaded. That file has already been posted <a href=\"res/" . (($hexmatch["parent"] == "0") ? $hexmatch["id"] : $hexmatch["parent"]) . ".html#" . $hexmatch["id"] . "\">here</a>.");
fancyDie("Duplicate file uploaded. That file has already been posted <a href=\"res/" . (($hexmatch["parent"] == TINYIB_NEWTHREAD) ? $hexmatch["id"] : $hexmatch["parent"]) . ".html#" . $hexmatch["id"] . "\">here</a>.");
}
}
}
function thumbnailDimensions($width, $height) {
return ($width > 250 || $height > 250) ? array(250, 250) : array($width, $height);
return ($width > TINYIB_MAXW || $height > TINYIB_MAXH) ? array(TINYIB_MAXW, TINYIB_MAXH) : array($width, $height);
}
function createThumbnail($name, $filename, $new_w, $new_h) {
@ -354,4 +356,19 @@ function fastImageCopyResampled(&$dst_image, &$src_image, $dst_x, $dst_y, $src_x
return true;
}
function strallpos($haystack, $needle, $offset = 0) {
$result = array();
for ($i = $offset;$i<strlen($haystack);$i++) {
$pos = strpos($haystack, $needle, $i);
if ($pos !== False) {
$offset = $pos;
if ($offset >= $i) {
$i = $offset;
$result[] = $offset;
}
}
}
return $result;
}
?>

View file

@ -32,12 +32,13 @@ function pageFooter() {
EOF;
}
function buildPost($post, $isrespage) {
function buildPost($post, $res) {
$return = "";
$threadid = ($post['parent'] == 0) ? $post['id'] : $post['parent'];
$postlink = ($isrespage) ? ($threadid . '.html#' . $post['id']) : ('res/' . $threadid . '.html#' . $post['id']);
$threadid = ($post['parent'] == TINYIB_NEWTHREAD) ? $post['id'] : $post['parent'];
$postlink = ($res == TINYIB_RESPAGE) ? ($threadid . '.html#' . $post['id']) : ('res/' . $threadid . '.html#' . $post['id']);
if (!isset($post["omitted"])) { $post["omitted"] = 0; }
if ($post["parent"] != 0) {
if ($post["parent"] != TINYIB_NEWTHREAD) {
$return .= <<<EOF
<table>
<tbody>
@ -75,7 +76,7 @@ ${post["nameblock"]}
</span>
EOF;
if ($post['parent'] != 0 && $post["file"] != "") {
if ($post['parent'] != TINYIB_NEWTHREAD && $post["file"] != "") {
$return .= <<<EOF
<br>
<span class="filesize"><a href="src/${post["file"]}">${post["file"]}</a>&ndash;(${post["file_size_formatted"]}, ${post["image_width"]}x${post["image_height"]}, ${post["file_original"]})</span>
@ -86,18 +87,23 @@ EOF;
EOF;
}
if ($post['parent'] == 0 && !$isrespage) {
if ($post['parent'] == TINYIB_NEWTHREAD && $res == TINYIB_INDEXPAGE) {
$return .= "&nbsp;[<a href=\"res/${post["id"]}.html\">Reply</a>]";
}
if (TINYIB_TRUNCATE > 0 && !$res && substr_count($post['message'], "<br>") > TINYIB_TRUNCATE) { // Truncate messages on board index pages for readability
$br_offsets = strallpos($post['message'], "<br>");
$post['message'] = substr($post['message'], 0, $br_offsets[TINYIB_TRUNCATE - 1]);
$post['message'] .= '<br><span class="omittedposts">Post truncated. Click Reply to view.</span><br>';
}
$return .= <<<EOF
<blockquote>
${post["message"]}
</blockquote>
EOF;
if ($post['parent'] == 0) {
if (!$isrespage && $post["omitted"] > 0) {
if ($post['parent'] == TINYIB_NEWTHREAD) {
if ($res == TINYIB_INDEXPAGE && $post["omitted"] > 0) {
$return .= '<span class="omittedposts">' . $post['omitted'] . ' ' . plural("post", $post["omitted"]) . ' omitted. Click Reply to view.</span>';
}
} else {
@ -114,10 +120,12 @@ EOF;
function buildPage($htmlposts, $parent, $pages=0, $thispage=0) {
$managelink = basename($_SERVER['PHP_SELF']) . "?manage";
$maxdimensions = TINYIB_MAXW . 'x' . TINYIB_MAXH;
$maxfilesize = TINYIB_MAXKB * 1024;
$postingmode = "";
$pagenavigator = "";
if ($parent == 0) {
if ($parent == TINYIB_NEWTHREAD) {
$pages = max($pages, 0);
$previous = ($thispage == 1) ? "index" : $thispage - 1;
$next = $thispage + 1;
@ -153,13 +161,18 @@ EOF;
$unique_posts_html = '';
$unique_posts = uniquePosts();
if ($unique_posts > 0) {
$unique_posts_html = "<li>Currently $unique_posts unique user posts.</li>";
$unique_posts_html = "<li>Currently $unique_posts unique user posts.</li>\n";
}
$max_file_size_html = '';
if (TINYIB_MAXKB > 0) {
$max_file_size_html = "<li>Maximum file size allowed is " . TINYIB_MAXKBDESC . ".</li>\n";
}
$body = <<<EOF
<body>
<div class="adminbar">
[<a href="$managelink">Manage</a>]
[<a href="$managelink" style="text-decoration: underline;">Manage</a>]
</div>
<div class="logo">
EOF;
@ -169,7 +182,7 @@ EOF;
$postingmode
<div class="postarea">
<form name="postform" id="postform" action="imgboard.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="2097152">
<input type="hidden" name="MAX_FILE_SIZE" value="$maxfilesize">
<input type="hidden" name="parent" value="$parent">
<table class="postform">
<tbody>
@ -226,8 +239,8 @@ EOF;
<td colspan="2" class="rules">
<ul>
<li>Supported file types are: GIF, JPG, PNG</li>
<li>Maximum file size allowed is 2 MB.</li>
<li>Images greater than 250x250 pixels will be thumbnailed.</li>
$max_file_size_html
<li>Images greater than $maxdimensions pixels will be thumbnailed.</li>
$unique_posts_html
</ul>
</td>
@ -268,12 +281,12 @@ function rebuildIndexes() {
$htmlreplies = array();
foreach ($replies as $reply) {
$htmlreplies[] = buildPost($reply, False);
$htmlreplies[] = buildPost($reply, TINYIB_INDEXPAGE);
}
$thread["omitted"] = (count($htmlreplies) == 3) ? (count(postsInThreadByID($thread['id'])) - 4) : 0;
$htmlposts .= buildPost($thread, False) . implode("", array_reverse($htmlreplies)) . "<br clear=\"left\">\n<hr>";
$htmlposts .= buildPost($thread, TINYIB_INDEXPAGE) . implode("", array_reverse($htmlreplies)) . "<br clear=\"left\">\n<hr>";
$i += 1;
if ($i == 10) {
@ -294,23 +307,23 @@ function rebuildThread($id) {
$htmlposts = "";
$posts = postsInThreadByID($id);
foreach ($posts as $post) {
$htmlposts .= buildPost($post, True);
$htmlposts .= buildPost($post, TINYIB_RESPAGE);
}
$htmlposts .= "<br clear=\"left\">\n" .
"<hr>";
$htmlposts .= "<br clear=\"left\">\n<hr>\n";
writePage("res/" . $id . ".html", fixLinksInRes(buildPage($htmlposts, $id)));
}
function adminBar() {
global $loggedin, $isadmin, $returnlink;
if (!$loggedin) { return '[<a href="' . $returnlink . '">Return</a>]'; }
$text = '[';
$return = '[<a href="' . $returnlink . '" style="text-decoration: underline;">Return</a>]';
if (!$loggedin) { return $return; }
$text = '[<a href="?manage">Status</a>] [';
$text .= ($isadmin) ? '<a href="?manage&bans">Bans</a>] [' : '';
$text .= '<a href="?manage&moderate">Moderate Post</a>] [<a href="?manage&modpost">Mod Post</a>] [';
$text .= '<a href="?manage&moderate">Moderate Post</a>] [<a href="?manage&rawpost">Raw Post</a>] [';
$text .= ($isadmin) ? '<a href="?manage&rebuildall">Rebuild All</a>] [' : '';
$text .= '<a href="?manage&logout">Log Out</a>] [<a href="' . $returnlink . '">Return</a>]';
$text .= '<a href="?manage&logout">Log Out</a>] &middot; ' . $return;
return $text;
}
@ -339,7 +352,7 @@ function manageOnLoad($page) {
return ' onload="document.tinyib.password.focus();"';
case 'moderate':
return ' onload="document.tinyib.moderate.focus();"';
case 'modpost':
case 'rawpost':
return ' onload="document.tinyib.message.focus();"';
case 'bans':
return ' onload="document.tinyib.ip.focus();"';
@ -350,10 +363,10 @@ function manageLogInForm() {
return <<<EOF
<form id="tinyib" name="tinyib" method="post" action="?manage">
<fieldset>
<legend align="center">Please enter an administrator or moderator password</legend>
<legend align="center">Enter an administrator or moderator password</legend>
<div class="login">
<input type="password" id="password" name="password"><br>
<input type="submit" value="Submit" class="managebutton">
<input type="submit" value="Log In" class="managebutton">
</div>
</fieldset>
</form>
@ -365,10 +378,10 @@ function manageBanForm() {
return <<<EOF
<form id="tinyib" name="tinyib" method="post" action="?manage&bans">
<fieldset>
<legend>Ban an IP address from posting</legend>
<legend>Ban an IP address</legend>
<label for="ip">IP Address:</label> <input type="text" name="ip" id="ip" value="${_GET['bans']}"> <input type="submit" value="Submit" class="managebutton"><br>
<label for="expire">Expire(sec):</label> <input type="text" name="expire" id="expire" value="0">&nbsp;&nbsp;<small><a href="#" onclick="document.tinyib.expire.value='3600';return false;">1hr</a>&nbsp;<a href="#" onclick="document.tinyib.expire.value='86400';return false;">1d</a>&nbsp;<a href="#" onclick="document.tinyib.expire.value='172800';return false;">2d</a>&nbsp;<a href="#" onclick="document.tinyib.expire.value='604800';return false;">1w</a>&nbsp;<a href="#" onclick="document.tinyib.expire.value='1209600';return false;">2w</a>&nbsp;<a href="#" onclick="document.tinyib.expire.value='2592000';return false;">30d</a>&nbsp;<a href="#" onclick="document.tinyib.expire.value='0';return false;">never</a></small><br>
<label for="reason">Reason:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label> <input type="text" name="reason" id="reason">&nbsp;&nbsp;<small>(optional)</small>
<label for="reason">Reason:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label> <input type="text" name="reason" id="reason">&nbsp;&nbsp;<small>optional</small>
<legend>
</fieldset>
</form><br>
@ -381,7 +394,7 @@ function manageBansTable() {
if (count($allbans) > 0) {
$text .= '<table border="1"><tr><th>IP Address</th><th>Set At</th><th>Expires</th><th>Reason Provided</th><th>&nbsp;</th></tr>';
foreach ($allbans as $ban) {
$expire = ($ban['expire'] > 0) ? date('y/m/d(D)H:i:s', $ban['expire']) : 'Never';
$expire = ($ban['expire'] > 0) ? date('y/m/d(D)H:i:s', $ban['expire']) : 'Does not expire';
$reason = ($ban['reason'] == '') ? '&nbsp;' : htmlentities($ban['reason']);
$text .= '<tr><td>' . $ban['ip'] . '</td><td>' . date('y/m/d(D)H:i:s', $ban['timestamp']) . '</td><td>' . $expire . '</td><td>' . $reason . '</td><td><a href="?manage&bans&lift=' . $ban['id'] . '">lift</a></td></tr>';
}
@ -396,18 +409,19 @@ function manageModeratePostForm() {
<input type="hidden" name="manage" value="">
<fieldset>
<legend>Moderate a post</legend>
<label for="moderate">Post ID:</label> <input type="text" name="moderate" id="moderate"> <input type="submit" value="Submit" class="managebutton"><br>
<legend>
<div valign="top"><label for="moderate">Post ID:</label> <input type="text" name="moderate" id="moderate"> <input type="submit" value="Submit" class="managebutton"></div><br>
While browsing the image board, you may moderate a post at any time, provided you are logged in.<br>
Tick the box next to the post, and click "Delete" at the bottom of the page without entering a password.<br>
</fieldset>
</form><br>
EOF;
}
function manageModpostForm() {
function manageRawPostForm() {
return <<<EOF
<div class="postarea">
<form id="tinyib" name="tinyib" method="post" action="?" enctype="multipart/form-data">
<input type="hidden" name="modpost" value="1">
<input type="hidden" name="rawpost" value="1">
<input type="hidden" name="MAX_FILE_SIZE" value="2097152">
<table class="postform">
<tbody>
@ -416,7 +430,7 @@ function manageModpostForm() {
Thread No.
</td>
<td>
<input type="text" name="parent" size="28" maxlength="75" value="0" accesskey="t">&nbsp;(0 for new thread)
<input type="text" name="parent" size="28" maxlength="75" value="0" accesskey="t">&nbsp;0 for new thread
</td>
</tr>
<tr>
@ -487,37 +501,96 @@ function manageModeratePost($post) {
global $isadmin;
$ban = banByIP($post['ip']);
$ban_disabled = (!$ban && $isadmin) ? '' : ' disabled';
$ban_disabled_info = (!$ban) ? '' : (' A ban record already exists for ' . $post['ip']);
$post_html = buildPost($post, false);
$post_or_thread = ($post['parent'] == 0) ? 'Thread' : 'Post';
$ban_info = (!$ban) ? ((!$isadmin) ? 'Only an administrator may ban an IP address.' : ('IP address: ' . $post["ip"])) : (' A ban record already exists for ' . $post['ip']);
$delete_info = ($post['parent'] == TINYIB_NEWTHREAD) ? 'This will delete the entire thread below.' : 'This will delete the post below.';
$post_or_thread = ($post['parent'] == TINYIB_NEWTHREAD) ? 'Thread' : 'Post';
if ($post["parent"] == TINYIB_NEWTHREAD) {
$post_html = "";
$posts = postsInThreadByID($post["id"]);
foreach ($posts as $post_temp) {
$post_html .= buildPost($post_temp, TINYIB_INDEXPAGE);
}
} else {
$post_html = buildPost($post, TINYIB_INDEXPAGE);
}
return <<<EOF
<fieldset>
<legend>Moderating post No.${post['id']}</legend>
<div class="floatpost">
<fieldset>
<legend>$post_or_thread</legend>
$post_html
</fieldset>
</div>
<legend>Moderating No.${post['id']}</legend>
<fieldset>
<legend>Action</legend>
<legend>Action</legend>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr><td align="right" width="50%;">
<form method="get" action="?">
<input type="hidden" name="manage" value="">
<input type="hidden" name="delete" value="${post['id']}">
<input type="submit" value="Delete $post_or_thread" class="managebutton">
<input type="submit" value="Delete $post_or_thread" class="managebutton" style="width: 50%;">
</form>
<br>
</td><td><small>$delete_info</small></td></tr>
<tr><td align="right" width="50%;">
<form method="get" action="?">
<input type="hidden" name="manage" value="">
<input type="hidden" name="bans" value="${post['ip']}">
<input type="submit" value="Ban Poster" class="managebutton"$ban_disabled>$ban_disabled_info
<input type="submit" value="Ban Poster" class="managebutton" style="width: 50%;"$ban_disabled>
</form>
</td><td><small>$ban_info</small></td></tr>
</table>
</fieldset>
<fieldset>
<legend>$post_or_thread</legend>
$post_html
</fieldset>
</fieldset>
<br>
EOF;
}
function manageStatus() {
$threads = countThreads();
$bans = count(allBans());
$info = $threads . ' ' . plural('thread', $threads) . ', ' . $bans . ' ' . plural('ban', $bans);
$post_html = '';
$posts = latestPosts();
$i = 0;
foreach ($posts as $post) {
if ($post_html != '') { $post_html .= '<tr><td colspan="2"><hr></td></tr>'; }
$post_html .= '<tr><td>' . buildPost($post, TINYIB_INDEXPAGE) . '</td><td valign="top"><form method="get" action="?"><input type="hidden" name="manage" value=""><input type="hidden" name="moderate" value="' . $post['id'] . '"><input type="submit" value="Moderate No.' . $post['id'] . '" class="managebutton"></form></td></tr>';
}
return <<<EOF
<fieldset>
<legend>Status</legend>
<fieldset>
<legend>Info</legend>
$info
</fieldset>
<fieldset>
<legend>Latest posts</legend>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
$post_html
</table>
</fieldset>
</fieldset>
<br>
EOF;
}
function manageInfo($text) {
return '<div class="manageinfo">' . $text . '</div>';
}
?>

View file

@ -2,10 +2,16 @@
define('TINYIB_BOARD', "b"); // Unique identifier for this board using only letters and numbers
define('TINYIB_BOARDDESC', "TinyIB"); // Displayed in the logo area
define('TINYIB_MAXTHREADS', 100); // Set this to limit the number of threads allowed before discarding older threads. 0 to disable
define('TINYIB_TRUNCATE', 15); // Truncate messages to this many lines on board index pages. 0 to disable
define('TINYIB_MAXKB', 2048); // Maximum file size. 0 to disable
define('TINYIB_MAXKBDESC', "2 MB"); // Formatted maximum file size
define('TINYIB_MAXW', 250); // Maximum image width. Images exceeding this size will be thumbnailed
define('TINYIB_MAXH', 250); // Maximum image height. Images exceeding this size will be thumbnailed
define('TINYIB_DELAY', 30); // Delay between posts to help control flooding. 0 to disable
define('TINYIB_LOGO', ""); // Logo HTML
define('TINYIB_TRIPSEED', ""); // Text to use when generating secure tripcodes
define('TINYIB_ADMINPASS', ""); // Text entered at the manage prompt to gain administrator access
define('TINYIB_MODPASS', ""); // Same as above, but only has access to delete posts. Blank ("") to disable
define('TINYIB_MODPASS', ""); // Same as above, but only has access to delete posts. Blank ("") to disable
define('TINYIB_DBMODE', "flatfile"); // flatfile / mysql / sqlite
// mysql settings - only edit if using mysql