forked from GithubBackups/tinyib
minor code cleanup
This commit is contained in:
parent
26410cd6ba
commit
fd87a2e6c1
45
imgboard.php
45
imgboard.php
@ -48,7 +48,7 @@ if (TINYIB_TRIPSEED == '' || TINYIB_ADMINPASS == '') {
|
|||||||
|
|
||||||
$redirect = true;
|
$redirect = true;
|
||||||
// Check if the request is to make a post
|
// 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();
|
list($loggedin, $isadmin) = manageCheckLogIn();
|
||||||
$rawpost = isRawPost();
|
$rawpost = isRawPost();
|
||||||
if (!$loggedin) {
|
if (!$loggedin) {
|
||||||
@ -60,25 +60,19 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
|
|||||||
$post = newPost(setParent());
|
$post = newPost(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']);
|
||||||
|
|
||||||
$post['name'] = cleanString(substr($post['name'], 0, 75));
|
$post['name'] = cleanString(substr($post['name'], 0, 75));
|
||||||
$post['email'] = cleanString(str_replace('"', '"', substr($_POST["email"], 0, 75)));
|
$post['email'] = cleanString(str_replace('"', '"', substr($_POST['email'], 0, 75)));
|
||||||
$post['subject'] = cleanString(substr($_POST["subject"], 0, 75));
|
$post['subject'] = cleanString(substr($_POST['subject'], 0, 75));
|
||||||
if ($rawpost) {
|
if ($rawpost) {
|
||||||
$rawposttext = ($isadmin) ? ' <span style="color: red;">## Admin</span>' : ' <span style="color: purple;">## Mod</span>';
|
$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 {
|
} else {
|
||||||
$rawposttext = '';
|
$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'])) : '';
|
$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);
|
$post['nameblock'] = nameBlock($post['name'], $post['tripcode'], $post['email'], time(), $rawposttext);
|
||||||
|
|
||||||
if (isset($_FILES['file'])) {
|
if (isset($_FILES['file'])) {
|
||||||
@ -153,7 +147,7 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$post['id'] = insertPost($post);
|
$post['id'] = insertPost($post);
|
||||||
if ($noko) {
|
if (strtolower($post['email']) == 'noko') {
|
||||||
$redirect = 'res/' . ($post['parent'] == TINYIB_NEWTHREAD ? $post['id'] : $post['parent']) . '.html#' . $post['id'];
|
$redirect = 'res/' . ($post['parent'] == TINYIB_NEWTHREAD ? $post['id'] : $post['parent']) . '.html#' . $post['id'];
|
||||||
}
|
}
|
||||||
trimThreads();
|
trimThreads();
|
||||||
@ -161,7 +155,7 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
|
|||||||
if ($post['parent'] != TINYIB_NEWTHREAD) {
|
if ($post['parent'] != TINYIB_NEWTHREAD) {
|
||||||
rebuildThread($post['parent']);
|
rebuildThread($post['parent']);
|
||||||
|
|
||||||
if (strtolower($post['email']) != "sage") {
|
if (strtolower($post['email']) != 'sage') {
|
||||||
bumpThreadByID($post['parent']);
|
bumpThreadByID($post['parent']);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -172,7 +166,8 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
|
|||||||
rebuildIndexes();
|
rebuildIndexes();
|
||||||
// Check if the request is to delete a post and/or its associated image
|
// Check if the request is to delete a post and/or its associated image
|
||||||
} elseif (isset($_GET['delete']) && !isset($_GET['manage'])) {
|
} elseif (isset($_GET['delete']) && !isset($_GET['manage'])) {
|
||||||
if (isset($_POST['delete'])) {
|
if (!isset($_POST['delete'])) { fancyDie('Tick the box next to a post and click "Delete" to delete it.'); }
|
||||||
|
|
||||||
$post = postByID($_POST['delete']);
|
$post = postByID($_POST['delete']);
|
||||||
if ($post) {
|
if ($post) {
|
||||||
list($loggedin, $isadmin) = manageCheckLogIn();
|
list($loggedin, $isadmin) = manageCheckLogIn();
|
||||||
@ -190,13 +185,11 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
|
|||||||
} else {
|
} else {
|
||||||
fancyDie('Sorry, an invalid post identifier was sent. Please go back, refresh the page, and try again.');
|
fancyDie('Sorry, an invalid post identifier was sent. Please go back, refresh the page, and try again.');
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
fancyDie('Tick the box next to a post and click "Delete" to delete it.');
|
|
||||||
}
|
|
||||||
$redirect = false;
|
$redirect = false;
|
||||||
// Check if the request is to access the management area
|
// Check if the request is to access the management area
|
||||||
} elseif (isset($_GET["manage"])) {
|
} elseif (isset($_GET['manage'])) {
|
||||||
$text = ""; $onload = ""; $navbar = " ";
|
$text = ''; $onload = ''; $navbar = ' ';
|
||||||
$redirect = false; $loggedin = false; $isadmin = false;
|
$redirect = false; $loggedin = false; $isadmin = false;
|
||||||
$returnlink = basename($_SERVER['PHP_SELF']);
|
$returnlink = basename($_SERVER['PHP_SELF']);
|
||||||
|
|
||||||
@ -204,14 +197,14 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
|
|||||||
|
|
||||||
if ($loggedin) {
|
if ($loggedin) {
|
||||||
if ($isadmin) {
|
if ($isadmin) {
|
||||||
if (isset($_GET["rebuildall"])) {
|
if (isset($_GET['rebuildall'])) {
|
||||||
$allthreads = allThreads();
|
$allthreads = allThreads();
|
||||||
foreach ($allthreads as $thread) {
|
foreach ($allthreads as $thread) {
|
||||||
rebuildThread($thread["id"]);
|
rebuildThread($thread['id']);
|
||||||
}
|
}
|
||||||
rebuildIndexes();
|
rebuildIndexes();
|
||||||
$text .= manageInfo('Rebuilt board.');
|
$text .= manageInfo('Rebuilt board.');
|
||||||
} elseif (isset($_GET["bans"])) {
|
} elseif (isset($_GET['bans'])) {
|
||||||
clearExpiredBans();
|
clearExpiredBans();
|
||||||
|
|
||||||
if (isset($_POST['ip'])) {
|
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']);
|
$post = postByID($_GET['delete']);
|
||||||
if ($post) {
|
if ($post) {
|
||||||
deletePostByID($post['id']);
|
deletePostByID($post['id']);
|
||||||
@ -255,7 +248,7 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
|
|||||||
} else {
|
} else {
|
||||||
fancyDie("Sorry, there doesn't appear to be a post with that ID.");
|
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) {
|
if ($_GET['moderate'] > 0) {
|
||||||
$post = postByID($_GET['moderate']);
|
$post = postByID($_GET['moderate']);
|
||||||
if ($post) {
|
if ($post) {
|
||||||
@ -284,7 +277,7 @@ if (isset($_POST["message"]) || isset($_POST["file"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
echo managePage($text, $onload);
|
echo managePage($text, $onload);
|
||||||
} elseif (!file_exists('index.html') || count(allThreads()) == 0) {
|
} elseif (!file_exists('index.html') || countThreads() == 0) {
|
||||||
rebuildIndexes();
|
rebuildIndexes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ $db->datadir = 'inc/flatfile/';
|
|||||||
|
|
||||||
# Post Functions
|
# Post Functions
|
||||||
function uniquePosts() {
|
function uniquePosts() {
|
||||||
return 0;
|
return 0; // Unsupported by this database option
|
||||||
}
|
}
|
||||||
|
|
||||||
function postByID($id) {
|
function postByID($id) {
|
||||||
|
@ -111,15 +111,15 @@ function nameAndTripcode($name) {
|
|||||||
|
|
||||||
function nameBlock($name, $tripcode, $email, $timestamp, $rawposttext) {
|
function nameBlock($name, $tripcode, $email, $timestamp, $rawposttext) {
|
||||||
$output = '<span class="postername">';
|
$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><span class="postertrip">!' . $tripcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
$output .= '</span>';
|
$output .= '</span>';
|
||||||
|
|
||||||
if ($email != "") {
|
if ($email != '' && strtolower($email) != 'noko') {
|
||||||
$output = '<a href="mailto:' . $email . '">' . $output . '</a>';
|
$output = '<a href="mailto:' . $email . '">' . $output . '</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
35
inc/html.php
35
inc/html.php
@ -64,8 +64,8 @@ EOF;
|
|||||||
<input type="checkbox" name="delete" value="${post['id']}">
|
<input type="checkbox" name="delete" value="${post['id']}">
|
||||||
EOF;
|
EOF;
|
||||||
|
|
||||||
if ($post["subject"] != "") {
|
if ($post['subject'] != '') {
|
||||||
$return .= " <span class=\"filetitle\">${post["subject"]}</span> ";
|
$return .= ' <span class="filetitle">' . ${post['subject']} . '</span> ';
|
||||||
}
|
}
|
||||||
|
|
||||||
$return .= <<<EOF
|
$return .= <<<EOF
|
||||||
@ -91,8 +91,8 @@ EOF;
|
|||||||
$return .= " [<a href=\"res/${post["id"]}.html\">Reply</a>]";
|
$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
|
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>");
|
$br_offsets = strallpos($post['message'], '<br>');
|
||||||
$post['message'] = substr($post['message'], 0, $br_offsets[TINYIB_TRUNCATE - 1]);
|
$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>';
|
$post['message'] .= '<br><span class="omittedposts">Post truncated. Click Reply to view.</span><br>';
|
||||||
}
|
}
|
||||||
@ -103,8 +103,8 @@ ${post["message"]}
|
|||||||
EOF;
|
EOF;
|
||||||
|
|
||||||
if ($post['parent'] == TINYIB_NEWTHREAD) {
|
if ($post['parent'] == TINYIB_NEWTHREAD) {
|
||||||
if ($res == TINYIB_INDEXPAGE && $post["omitted"] > 0) {
|
if ($res == TINYIB_INDEXPAGE && $post['omitted'] > 0) {
|
||||||
$return .= '<span class="omittedposts">' . $post['omitted'] . ' ' . plural("post", $post["omitted"]) . ' omitted. Click Reply to view.</span>';
|
$return .= '<span class="omittedposts">' . $post['omitted'] . ' ' . plural('post', $post['omitted']) . ' omitted. Click Reply to view.</span>';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$return .= <<<EOF
|
$return .= <<<EOF
|
||||||
@ -272,7 +272,7 @@ EOF;
|
|||||||
}
|
}
|
||||||
|
|
||||||
function rebuildIndexes() {
|
function rebuildIndexes() {
|
||||||
$page = 0; $i = 0; $htmlposts = "";
|
$page = 0; $i = 0; $htmlposts = '';
|
||||||
$pages = ceil(countThreads() / 10) - 1;
|
$pages = ceil(countThreads() / 10) - 1;
|
||||||
$threads = allThreads();
|
$threads = allThreads();
|
||||||
|
|
||||||
@ -284,21 +284,21 @@ function rebuildIndexes() {
|
|||||||
$htmlreplies[] = buildPost($reply, TINYIB_INDEXPAGE);
|
$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;
|
$i += 1;
|
||||||
if ($i == 10) {
|
if ($i == 10) {
|
||||||
$file = ($page == 0) ? "index.html" : $page . ".html";
|
$file = ($page == 0) ? 'index.html' : $page . '.html';
|
||||||
writePage($file, buildPage($htmlposts, 0, $pages, $page));
|
writePage($file, buildPage($htmlposts, 0, $pages, $page));
|
||||||
|
|
||||||
$page += 1; $i = 0; $htmlposts = "";
|
$page += 1; $i = 0; $htmlposts = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($page == 0 || $htmlposts != "") {
|
if ($page == 0 || $htmlposts != '') {
|
||||||
$file = ($page == 0) ? "index.html" : $page . ".html";
|
$file = ($page == 0) ? 'index.html' : $page . '.html';
|
||||||
writePage($file, buildPage($htmlposts, 0, $pages, $page));
|
writePage($file, buildPage($htmlposts, 0, $pages, $page));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -312,19 +312,14 @@ function rebuildThread($id) {
|
|||||||
|
|
||||||
$htmlposts .= "<br clear=\"left\">\n<hr>\n";
|
$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() {
|
function adminBar() {
|
||||||
global $loggedin, $isadmin, $returnlink;
|
global $loggedin, $isadmin, $returnlink;
|
||||||
$return = '[<a href="' . $returnlink . '" style="text-decoration: underline;">Return</a>]';
|
$return = '[<a href="' . $returnlink . '" style="text-decoration: underline;">Return</a>]';
|
||||||
if (!$loggedin) { return $return; }
|
if (!$loggedin) { return $return; }
|
||||||
$text = '[<a href="?manage">Status</a>] [';
|
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;
|
||||||
$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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function managePage($text, $onload='') {
|
function managePage($text, $onload='') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user