minor code cleanup
This commit is contained in:
parent
26410cd6ba
commit
fd87a2e6c1
4 changed files with 55 additions and 67 deletions
73
imgboard.php
73
imgboard.php
|
@ -48,7 +48,7 @@ if (TINYIB_TRIPSEED == '' || TINYIB_ADMINPASS == '') {
|
|||
|
||||
$redirect = true;
|
||||
// Check if the request is to make a post
|
||||
if (isset($_POST["message"]) || isset($_POST["file"])) {
|
||||
if (isset($_POST['message']) || isset($_POST['file'])) {
|
||||
list($loggedin, $isadmin) = manageCheckLogIn();
|
||||
$rawpost = isRawPost();
|
||||
if (!$loggedin) {
|
||||
|
@ -60,25 +60,19 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
|
|||
$post = newPost(setParent());
|
||||
$post['ip'] = $_SERVER['REMOTE_ADDR'];
|
||||
|
||||
list($post['name'], $post['tripcode']) = nameAndTripcode($_POST["name"]);
|
||||
list($post['name'], $post['tripcode']) = nameAndTripcode($_POST['name']);
|
||||
|
||||
$post['name'] = cleanString(substr($post['name'], 0, 75));
|
||||
$post['email'] = cleanString(str_replace('"', '"', substr($_POST["email"], 0, 75)));
|
||||
$post['subject'] = cleanString(substr($_POST["subject"], 0, 75));
|
||||
$post['email'] = cleanString(str_replace('"', '"', substr($_POST['email'], 0, 75)));
|
||||
$post['subject'] = cleanString(substr($_POST['subject'], 0, 75));
|
||||
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
|
||||
$post['message'] = $_POST['message']; // Treat message as raw HTML
|
||||
} else {
|
||||
$rawposttext = '';
|
||||
$post['message'] = str_replace("\n", "<br>", colorQuote(postLink(cleanString(rtrim($_POST["message"])))));
|
||||
$post['message'] = str_replace("\n", '<br>', colorQuote(postLink(cleanString(rtrim($_POST['message'])))));
|
||||
}
|
||||
$post['password'] = ($_POST['password'] != '') ? md5(md5($_POST['password'])) : '';
|
||||
if (strtolower($post['email']) == "noko") {
|
||||
$post['email'] = '';
|
||||
$noko = true;
|
||||
} else {
|
||||
$noko = false;
|
||||
}
|
||||
$post['nameblock'] = nameBlock($post['name'], $post['tripcode'], $post['email'], time(), $rawposttext);
|
||||
|
||||
if (isset($_FILES['file'])) {
|
||||
|
@ -153,7 +147,7 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
|
|||
}
|
||||
|
||||
$post['id'] = insertPost($post);
|
||||
if ($noko) {
|
||||
if (strtolower($post['email']) == 'noko') {
|
||||
$redirect = 'res/' . ($post['parent'] == TINYIB_NEWTHREAD ? $post['id'] : $post['parent']) . '.html#' . $post['id'];
|
||||
}
|
||||
trimThreads();
|
||||
|
@ -161,7 +155,7 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
|
|||
if ($post['parent'] != TINYIB_NEWTHREAD) {
|
||||
rebuildThread($post['parent']);
|
||||
|
||||
if (strtolower($post['email']) != "sage") {
|
||||
if (strtolower($post['email']) != 'sage') {
|
||||
bumpThreadByID($post['parent']);
|
||||
}
|
||||
} else {
|
||||
|
@ -172,31 +166,30 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
|
|||
rebuildIndexes();
|
||||
// Check if the request is to delete a post and/or its associated image
|
||||
} elseif (isset($_GET['delete']) && !isset($_GET['manage'])) {
|
||||
if (isset($_POST['delete'])) {
|
||||
$post = postByID($_POST['delete']);
|
||||
if ($post) {
|
||||
list($loggedin, $isadmin) = manageCheckLogIn();
|
||||
|
||||
if ($loggedin && $_POST['password'] == '') {
|
||||
// Redirect to post moderation page
|
||||
echo '--> --> --><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'] == TINYIB_NEWTHREAD) { threadUpdated($post['id']); } else { threadUpdated($post['parent']); }
|
||||
fancyDie('Post deleted.');
|
||||
} else {
|
||||
fancyDie('Invalid password.');
|
||||
}
|
||||
if (!isset($_POST['delete'])) { fancyDie('Tick the box next to a post and click "Delete" to delete it.'); }
|
||||
|
||||
$post = postByID($_POST['delete']);
|
||||
if ($post) {
|
||||
list($loggedin, $isadmin) = manageCheckLogIn();
|
||||
|
||||
if ($loggedin && $_POST['password'] == '') {
|
||||
// Redirect to post moderation page
|
||||
echo '--> --> --><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'] == TINYIB_NEWTHREAD) { threadUpdated($post['id']); } else { threadUpdated($post['parent']); }
|
||||
fancyDie('Post deleted.');
|
||||
} else {
|
||||
fancyDie('Sorry, an invalid post identifier was sent. Please go back, refresh the page, and try again.');
|
||||
fancyDie('Invalid password.');
|
||||
}
|
||||
} else {
|
||||
fancyDie('Tick the box next to a post and click "Delete" to delete it.');
|
||||
fancyDie('Sorry, an invalid post identifier was sent. Please go back, refresh the page, and try again.');
|
||||
}
|
||||
|
||||
$redirect = false;
|
||||
// Check if the request is to access the management area
|
||||
} elseif (isset($_GET["manage"])) {
|
||||
$text = ""; $onload = ""; $navbar = " ";
|
||||
} elseif (isset($_GET['manage'])) {
|
||||
$text = ''; $onload = ''; $navbar = ' ';
|
||||
$redirect = false; $loggedin = false; $isadmin = false;
|
||||
$returnlink = basename($_SERVER['PHP_SELF']);
|
||||
|
||||
|
@ -204,14 +197,14 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
|
|||
|
||||
if ($loggedin) {
|
||||
if ($isadmin) {
|
||||
if (isset($_GET["rebuildall"])) {
|
||||
if (isset($_GET['rebuildall'])) {
|
||||
$allthreads = allThreads();
|
||||
foreach ($allthreads as $thread) {
|
||||
rebuildThread($thread["id"]);
|
||||
rebuildThread($thread['id']);
|
||||
}
|
||||
rebuildIndexes();
|
||||
$text .= manageInfo('Rebuilt board.');
|
||||
} elseif (isset($_GET["bans"])) {
|
||||
} elseif (isset($_GET['bans'])) {
|
||||
clearExpiredBans();
|
||||
|
||||
if (isset($_POST['ip'])) {
|
||||
|
@ -243,7 +236,7 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
|
|||
}
|
||||
}
|
||||
|
||||
if (isset($_GET["delete"])) {
|
||||
if (isset($_GET['delete'])) {
|
||||
$post = postByID($_GET['delete']);
|
||||
if ($post) {
|
||||
deletePostByID($post['id']);
|
||||
|
@ -255,7 +248,7 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
|
|||
} else {
|
||||
fancyDie("Sorry, there doesn't appear to be a post with that ID.");
|
||||
}
|
||||
} elseif (isset($_GET["moderate"])) {
|
||||
} elseif (isset($_GET['moderate'])) {
|
||||
if ($_GET['moderate'] > 0) {
|
||||
$post = postByID($_GET['moderate']);
|
||||
if ($post) {
|
||||
|
@ -284,7 +277,7 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
|
|||
}
|
||||
|
||||
echo managePage($text, $onload);
|
||||
} elseif (!file_exists('index.html') || count(allThreads()) == 0) {
|
||||
} elseif (!file_exists('index.html') || countThreads() == 0) {
|
||||
rebuildIndexes();
|
||||
}
|
||||
|
||||
|
@ -292,4 +285,4 @@ if ($redirect) {
|
|||
echo '--> --> --><meta http-equiv="refresh" content="0;url=' . (is_string($redirect) ? $redirect : 'index.html') . '">';
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
@ -40,7 +40,7 @@ $db->datadir = 'inc/flatfile/';
|
|||
|
||||
# Post Functions
|
||||
function uniquePosts() {
|
||||
return 0;
|
||||
return 0; // Unsupported by this database option
|
||||
}
|
||||
|
||||
function postByID($id) {
|
||||
|
@ -258,4 +258,4 @@ function deleteBanByID($id) {
|
|||
$GLOBALS['db']->deleteWhere(BANS_FILE, new SimpleWhereClause(BAN_ID, '=', $id, INTEGER_COMPARISON));
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
@ -111,15 +111,15 @@ function nameAndTripcode($name) {
|
|||
|
||||
function nameBlock($name, $tripcode, $email, $timestamp, $rawposttext) {
|
||||
$output = '<span class="postername">';
|
||||
$output .= ($name == "" && $tripcode == "") ? "Anonymous" : $name;
|
||||
$output .= ($name == '' && $tripcode == '') ? 'Anonymous' : $name;
|
||||
|
||||
if ($tripcode != "") {
|
||||
if ($tripcode != '') {
|
||||
$output .= '</span><span class="postertrip">!' . $tripcode;
|
||||
}
|
||||
|
||||
$output .= '</span>';
|
||||
|
||||
if ($email != "") {
|
||||
if ($email != '' && strtolower($email) != 'noko') {
|
||||
$output = '<a href="mailto:' . $email . '">' . $output . '</a>';
|
||||
}
|
||||
|
||||
|
@ -371,4 +371,4 @@ function strallpos($haystack, $needle, $offset = 0) {
|
|||
return $result;
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
37
inc/html.php
37
inc/html.php
|
@ -64,8 +64,8 @@ EOF;
|
|||
<input type="checkbox" name="delete" value="${post['id']}">
|
||||
EOF;
|
||||
|
||||
if ($post["subject"] != "") {
|
||||
$return .= " <span class=\"filetitle\">${post["subject"]}</span> ";
|
||||
if ($post['subject'] != '') {
|
||||
$return .= ' <span class="filetitle">' . ${post['subject']} . '</span> ';
|
||||
}
|
||||
|
||||
$return .= <<<EOF
|
||||
|
@ -91,8 +91,8 @@ EOF;
|
|||
$return .= " [<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>");
|
||||
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>';
|
||||
}
|
||||
|
@ -103,8 +103,8 @@ ${post["message"]}
|
|||
EOF;
|
||||
|
||||
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>';
|
||||
if ($res == TINYIB_INDEXPAGE && $post['omitted'] > 0) {
|
||||
$return .= '<span class="omittedposts">' . $post['omitted'] . ' ' . plural('post', $post['omitted']) . ' omitted. Click Reply to view.</span>';
|
||||
}
|
||||
} else {
|
||||
$return .= <<<EOF
|
||||
|
@ -272,7 +272,7 @@ EOF;
|
|||
}
|
||||
|
||||
function rebuildIndexes() {
|
||||
$page = 0; $i = 0; $htmlposts = "";
|
||||
$page = 0; $i = 0; $htmlposts = '';
|
||||
$pages = ceil(countThreads() / 10) - 1;
|
||||
$threads = allThreads();
|
||||
|
||||
|
@ -284,21 +284,21 @@ function rebuildIndexes() {
|
|||
$htmlreplies[] = buildPost($reply, TINYIB_INDEXPAGE);
|
||||
}
|
||||
|
||||
$thread["omitted"] = (count($htmlreplies) == 3) ? (count(postsInThreadByID($thread['id'])) - 4) : 0;
|
||||
$thread['omitted'] = (count($htmlreplies) == 3) ? (count(postsInThreadByID($thread['id'])) - 4) : 0;
|
||||
|
||||
$htmlposts .= buildPost($thread, TINYIB_INDEXPAGE) . 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) {
|
||||
$file = ($page == 0) ? "index.html" : $page . ".html";
|
||||
$file = ($page == 0) ? 'index.html' : $page . '.html';
|
||||
writePage($file, buildPage($htmlposts, 0, $pages, $page));
|
||||
|
||||
$page += 1; $i = 0; $htmlposts = "";
|
||||
$page += 1; $i = 0; $htmlposts = '';
|
||||
}
|
||||
}
|
||||
|
||||
if ($page == 0 || $htmlposts != "") {
|
||||
$file = ($page == 0) ? "index.html" : $page . ".html";
|
||||
if ($page == 0 || $htmlposts != '') {
|
||||
$file = ($page == 0) ? 'index.html' : $page . '.html';
|
||||
writePage($file, buildPage($htmlposts, 0, $pages, $page));
|
||||
}
|
||||
}
|
||||
|
@ -312,19 +312,14 @@ function rebuildThread($id) {
|
|||
|
||||
$htmlposts .= "<br clear=\"left\">\n<hr>\n";
|
||||
|
||||
writePage("res/" . $id . ".html", fixLinksInRes(buildPage($htmlposts, $id)));
|
||||
writePage('res/' . $id . '.html', fixLinksInRes(buildPage($htmlposts, $id)));
|
||||
}
|
||||
|
||||
function adminBar() {
|
||||
global $loggedin, $isadmin, $returnlink;
|
||||
$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&rawpost">Raw Post</a>] [';
|
||||
$text .= ($isadmin) ? '<a href="?manage&rebuildall">Rebuild All</a>] [' : '';
|
||||
$text .= '<a href="?manage&logout">Log Out</a>] · ' . $return;
|
||||
return $text;
|
||||
return '[<a href="?manage">Status</a>] [' . (($isadmin) ? '<a href="?manage&bans">Bans</a>] [' : '') . '<a href="?manage&moderate">Moderate Post</a>] [<a href="?manage&rawpost">Raw Post</a>] [' . (($isadmin) ? '<a href="?manage&rebuildall">Rebuild All</a>] [' : '') . '<a href="?manage&logout">Log Out</a>] · ' . $return;
|
||||
}
|
||||
|
||||
function managePage($text, $onload='') {
|
||||
|
@ -593,4 +588,4 @@ EOF;
|
|||
function manageInfo($text) {
|
||||
return '<div class="manageinfo">' . $text . '</div>';
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
Loading…
Reference in a new issue