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,12 +55,13 @@ $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();
if (!$loggedin) {
checkBanned(); checkBanned();
checkFlood(); 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();
@ -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,10 +62,12 @@ 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");
if ($result) {
while ($post = mysql_fetch_assoc($result)) { while ($post = mysql_fetch_assoc($result)) {
return $post; return $post;
} }
} }
}
function threadExistsByID($id) { function threadExistsByID($id) {
return mysql_result(mysql_query("SELECT COUNT(*) FROM `" . TINYIB_DBPOSTS . "` WHERE `id` = '" . mysql_real_escape_string($id) . "' AND `parent` = 0 LIMIT 1"), 0, 0) > 0; return mysql_result(mysql_query("SELECT COUNT(*) FROM `" . TINYIB_DBPOSTS . "` WHERE `id` = '" . mysql_real_escape_string($id) . "' AND `parent` = 0 LIMIT 1"), 0, 0) > 0;
@ -87,36 +89,44 @@ 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");
if ($result) {
while ($thread = mysql_fetch_assoc($result)) { while ($thread = mysql_fetch_assoc($result)) {
$threads[] = $thread; $threads[] = $thread;
} }
}
return $threads; return $threads;
} }
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");
if ($result) {
while ($post = mysql_fetch_assoc($result)) { while ($post = mysql_fetch_assoc($result)) {
$posts[] = $post; $posts[] = $post;
} }
}
return $posts; return $posts;
} }
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;
} }
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");
if ($result) {
while ($post = mysql_fetch_assoc($result)) { while ($post = mysql_fetch_assoc($result)) {
$posts[] = $post; $posts[] = $post;
} }
}
return $posts; return $posts;
} }
@ -142,40 +152,50 @@ 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");
if ($result) {
while ($post = mysql_fetch_assoc($result)) { while ($post = mysql_fetch_assoc($result)) {
deletePostByID($post['id']); 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");
if ($replies) {
while ($post = mysql_fetch_assoc($replies)) { while ($post = mysql_fetch_assoc($replies)) {
return $post; 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");
if ($result) {
while ($ban = mysql_fetch_assoc($result)) { while ($ban = mysql_fetch_assoc($result)) {
return $ban; 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");
if ($result) {
while ($ban = mysql_fetch_assoc($result)) { while ($ban = mysql_fetch_assoc($result)) {
return $ban; 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");
if ($result) {
while ($ban = mysql_fetch_assoc($result)) { while ($ban = mysql_fetch_assoc($result)) {
$bans[] = $ban; $bans[] = $ban;
} }
}
return $bans; return $bans;
} }
@ -186,10 +206,12 @@ 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());
if ($result) {
while ($ban = mysql_fetch_assoc($result)) { while ($ban = mysql_fetch_assoc($result)) {
mysql_query("DELETE FROM `" . TINYIB_DBBANS . "` WHERE `id` = " . $ban['id'] . " LIMIT 1"); mysql_query("DELETE FROM `" . TINYIB_DBBANS . "` WHERE `id` = " . $ban['id'] . " LIMIT 1");
} }
} }
}
function deleteBanByID($id) { function deleteBanByID($id) {
mysql_query("DELETE FROM `" . TINYIB_DBBANS . "` WHERE `id` = " . mysql_real_escape_string($id) . " LIMIT 1"); mysql_query("DELETE FROM `" . TINYIB_DBBANS . "` WHERE `id` = " . mysql_real_escape_string($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);