Post linking using >>#### and some minor fixes

This commit is contained in:
tslocum 2011-01-07 00:56:59 -08:00
parent b6204bebf1
commit be532e13b0
3 changed files with 63 additions and 28 deletions

View File

@ -55,15 +55,16 @@ $redirect = true;
if (isset($_POST["message"]) || isset($_POST["file"])) { if (isset($_POST["message"]) || isset($_POST["file"])) {
list($loggedin, $isadmin) = manageCheckLogIn(); list($loggedin, $isadmin) = manageCheckLogIn();
$modpost = isModPost(); $modpost = isModPost();
checkBanned(); if (!$loggedin) {
checkFlood(); checkBanned();
checkFlood();
if (strlen($_POST["message"]) > 8000) { 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."); 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.");
}
} }
$post = newPost(); $post = newPost();
$post['parent'] =setParent(); $post['parent'] = setParent();
$post['ip'] = $_SERVER['REMOTE_ADDR']; $post['ip'] = $_SERVER['REMOTE_ADDR'];
list($post['name'], $post['tripcode']) = nameAndTripcode($_POST["name"]); list($post['name'], $post['tripcode']) = nameAndTripcode($_POST["name"]);
@ -76,7 +77,7 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
$post['message'] = $_POST["message"]; // Treat message as raw HTML $post['message'] = $_POST["message"]; // Treat message as raw HTML
} else { } else {
$modposttext = ''; $modposttext = '';
$post['message'] = str_replace("\n", "<br>", colorQuote(cleanString(rtrim($_POST["message"])))); $post['message'] = str_replace("\n", "<br>", colorQuote(postLink(cleanString(rtrim($_POST["message"])))));
} }
$post['password'] = ($_POST['password'] != '') ? md5(md5($_POST['password'])) : ''; $post['password'] = ($_POST['password'] != '') ? md5(md5($_POST['password'])) : '';
if (strtolower($post['email']) == "noko") { if (strtolower($post['email']) == "noko") {

View File

@ -62,8 +62,10 @@ function uniquePosts() {
function postByID($id) { function postByID($id) {
$result = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE `id` = '" . mysql_real_escape_string($id) . "' LIMIT 1"); $result = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE `id` = '" . mysql_real_escape_string($id) . "' LIMIT 1");
while ($post = mysql_fetch_assoc($result)) { if ($result) {
return $post; while ($post = mysql_fetch_assoc($result)) {
return $post;
}
} }
} }
@ -87,8 +89,10 @@ function countThreads() {
function allThreads() { function allThreads() {
$threads = array(); $threads = array();
$result = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = 0 ORDER BY `bumped` DESC"); $result = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = 0 ORDER BY `bumped` DESC");
while ($thread = mysql_fetch_assoc($result)) { if ($result) {
$threads[] = $thread; while ($thread = mysql_fetch_assoc($result)) {
$threads[] = $thread;
}
} }
return $threads; return $threads;
} }
@ -96,8 +100,10 @@ function allThreads() {
function postsInThreadByID($id) { function postsInThreadByID($id) {
$posts = array(); $posts = array();
$result = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE `id` = " . $id . " OR `parent` = " . $id . " ORDER BY `id` ASC"); $result = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE `id` = " . $id . " OR `parent` = " . $id . " ORDER BY `id` ASC");
while ($post = mysql_fetch_assoc($result)) { if ($result) {
$posts[] = $post; while ($post = mysql_fetch_assoc($result)) {
$posts[] = $post;
}
} }
return $posts; return $posts;
} }
@ -105,8 +111,10 @@ function postsInThreadByID($id) {
function latestRepliesInThreadByID($id) { function latestRepliesInThreadByID($id) {
$posts = array(); $posts = array();
$replies = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = " . $id . " ORDER BY `id` DESC LIMIT 3"); $replies = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = " . $id . " ORDER BY `id` DESC LIMIT 3");
if ($replies) {
while ($post = mysql_fetch_assoc($replies)) { while ($post = mysql_fetch_assoc($replies)) {
$posts[] = $post; $posts[] = $post;
}
} }
return $posts; return $posts;
} }
@ -114,8 +122,10 @@ function latestRepliesInThreadByID($id) {
function postsByHex($hex) { function postsByHex($hex) {
$posts = array(); $posts = array();
$result = mysql_query("SELECT `id`, `parent` FROM `" . TINYIB_DBPOSTS . "` WHERE `file_hex` = '" . mysql_real_escape_string($hex) . "' LIMIT 1"); $result = mysql_query("SELECT `id`, `parent` FROM `" . TINYIB_DBPOSTS . "` WHERE `file_hex` = '" . mysql_real_escape_string($hex) . "' LIMIT 1");
while ($post = mysql_fetch_assoc($result)) { if ($result) {
$posts[] = $post; while ($post = mysql_fetch_assoc($result)) {
$posts[] = $post;
}
} }
return $posts; return $posts;
} }
@ -142,39 +152,49 @@ function deletePostByID($id) {
function trimThreads() { function trimThreads() {
if (TINYIB_MAXTHREADS > 0) { if (TINYIB_MAXTHREADS > 0) {
$result = mysql_query("SELECT `id` FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = 0 ORDER BY `bumped` DESC LIMIT " . TINYIB_MAXTHREADS. ", 10"); $result = mysql_query("SELECT `id` FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = 0 ORDER BY `bumped` DESC LIMIT " . TINYIB_MAXTHREADS. ", 10");
while ($post = mysql_fetch_assoc($result)) { if ($result) {
deletePostByID($post['id']); while ($post = mysql_fetch_assoc($result)) {
deletePostByID($post['id']);
}
} }
} }
} }
function lastPostByIP() { function lastPostByIP() {
$replies = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE `ip` = '" . $_SERVER['REMOTE_ADDR'] . "' ORDER BY `id` DESC LIMIT 1"); $replies = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE `ip` = '" . $_SERVER['REMOTE_ADDR'] . "' ORDER BY `id` DESC LIMIT 1");
while ($post = mysql_fetch_assoc($replies)) { if ($replies) {
return $post; while ($post = mysql_fetch_assoc($replies)) {
return $post;
}
} }
} }
# Ban Functions # Ban Functions
function banByID($id) { function banByID($id) {
$result = mysql_query("SELECT * FROM `" . TINYIB_DBBANS . "` WHERE `id` = '" . mysql_real_escape_string($id) . "' LIMIT 1"); $result = mysql_query("SELECT * FROM `" . TINYIB_DBBANS . "` WHERE `id` = '" . mysql_real_escape_string($id) . "' LIMIT 1");
while ($ban = mysql_fetch_assoc($result)) { if ($result) {
return $ban; while ($ban = mysql_fetch_assoc($result)) {
return $ban;
}
} }
} }
function banByIP($ip) { function banByIP($ip) {
$result = mysql_query("SELECT * FROM `" . TINYIB_DBBANS . "` WHERE `ip` = '" . mysql_real_escape_string($ip) . "' LIMIT 1"); $result = mysql_query("SELECT * FROM `" . TINYIB_DBBANS . "` WHERE `ip` = '" . mysql_real_escape_string($ip) . "' LIMIT 1");
while ($ban = mysql_fetch_assoc($result)) { if ($result) {
return $ban; while ($ban = mysql_fetch_assoc($result)) {
return $ban;
}
} }
} }
function allBans() { function allBans() {
$bans = array(); $bans = array();
$result = mysql_query("SELECT * FROM `" . TINYIB_DBBANS . "` ORDER BY `timestamp` DESC"); $result = mysql_query("SELECT * FROM `" . TINYIB_DBBANS . "` ORDER BY `timestamp` DESC");
while ($ban = mysql_fetch_assoc($result)) { if ($result) {
$bans[] = $ban; while ($ban = mysql_fetch_assoc($result)) {
$bans[] = $ban;
}
} }
return $bans; return $bans;
} }
@ -186,8 +206,10 @@ function insertBan($ban) {
function clearExpiredBans() { function clearExpiredBans() {
$result = mysql_query("SELECT * FROM `" . TINYIB_DBBANS . "` WHERE `expire` > 0 AND `expire` <= " . time()); $result = mysql_query("SELECT * FROM `" . TINYIB_DBBANS . "` WHERE `expire` > 0 AND `expire` <= " . time());
while ($ban = mysql_fetch_assoc($result)) { if ($result) {
mysql_query("DELETE FROM `" . TINYIB_DBBANS . "` WHERE `id` = " . $ban['id'] . " LIMIT 1"); while ($ban = mysql_fetch_assoc($result)) {
mysql_query("DELETE FROM `" . TINYIB_DBBANS . "` WHERE `id` = " . $ban['id'] . " LIMIT 1");
}
} }
} }

View File

@ -153,6 +153,18 @@ function fixLinksInRes($html) {
return str_replace($search, $replace, $html); return str_replace($search, $replace, $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 $matches[0];
}
function postLink($message) {
return preg_replace_callback('/&gt;&gt;([0-9]+)/', '_postLink', $message);
}
function colorQuote($message) { function colorQuote($message) {
if (substr($message, -1, 1) != "\n") { $message .= "\n"; } if (substr($message, -1, 1) != "\n") { $message .= "\n"; }
return preg_replace('/^(&gt;[^\>](.*))\n/m', '<span class="unkfunc">\\1</span>' . "\n", $message); return preg_replace('/^(&gt;[^\>](.*))\n/m', '<span class="unkfunc">\\1</span>' . "\n", $message);