diff --git a/imgboard.php b/imgboard.php index 451628c..f948429 100644 --- a/imgboard.php +++ b/imgboard.php @@ -24,7 +24,7 @@ require 'settings.php'; // Check directories are writable by the script $writedirs = array("res", "src", "thumb"); -if ($tinyib['databasemode'] == 'flatfile') { $writedirs[] = "inc/flatfile"; } +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."); @@ -32,9 +32,9 @@ foreach ($writedirs as $dir) { } $includes = array("inc/functions.php", "inc/html.php"); -if ($tinyib['databasemode'] == 'flatfile') { +if (TINYIB_DBMODE == 'flatfile') { $includes[] = 'inc/database_flatfile.php'; -} elseif ($tinyib['databasemode'] == 'mysql') { +} elseif (TINYIB_DBMODE == 'mysql') { $includes[] = 'inc/database_mysql.php'; } else { fancyDie("Unknown database mode specificed"); @@ -44,8 +44,8 @@ foreach ($includes as $include) { include $include; } -if ($tinyib['tripseed'] == '' || $tinyib['adminpassword'] == '') { - fancyDie('$tinyib[\'tripseed\'] and $tinyib[\'adminpassword\'] still need to be configured!'); +if (TINYIB_TRIPSEED == '' || TINYIB_ADMINPASS == '') { + fancyDie('TINYIB_TRIPSEED and TINYIB_ADMINPASS must be configured!'); } $redirect = true; @@ -96,9 +96,7 @@ if (isset($_POST["message"]) || isset($_POST["file"])) { $post['parent'] = $parent; $post['ip'] = $_SERVER['REMOTE_ADDR']; - $nt = nameAndTripcode($_POST["name"]); - $post['name'] = $nt[0]; - $post['tripcode'] = $nt[1]; + 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))); diff --git a/inc/database_flatfile.php b/inc/database_flatfile.php index 603f8d5..83f4006 100644 --- a/inc/database_flatfile.php +++ b/inc/database_flatfile.php @@ -1,5 +1,5 @@ 0) { + if (TINYIB_MAXTHREADS > 0) { $numthreads = countThreads(); - if ($numthreads > $tinyib['maxthreads']) { + if ($numthreads > TINYIB_MAXTHREADS) { $allthreads = allThreads(); - for ($i=$tinyib['maxthreads'];$i<$numthreads;$i++) { + for ($i=TINYIB_MAXTHREADS;$i<$numthreads;$i++) { deletePostByID($allthreads[$i]['id']); } } diff --git a/inc/database_mysql.php b/inc/database_mysql.php index c46c8c5..a573917 100644 --- a/inc/database_mysql.php +++ b/inc/database_mysql.php @@ -1,5 +1,5 @@ 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; } function insertPost($post) { - mysql_query("INSERT INTO `" . $GLOBALS['mysql_posts_table'] . "` (`parent`, `timestamp`, `bumped`, `ip`, `name`, `tripcode`, `email`, `nameblock`, `subject`, `message`, `password`, `file`, `file_hex`, `file_original`, `file_size`, `file_size_formatted`, `image_width`, `image_height`, `thumb`, `thumb_width`, `thumb_height`) VALUES (" . $post['parent'] . ", " . time() . ", " . time() . ", '" . $_SERVER['REMOTE_ADDR'] . "', '" . mysql_real_escape_string($post['name']) . "', '" . mysql_real_escape_string($post['tripcode']) . "', '" . mysql_real_escape_string($post['email']) . "', '" . mysql_real_escape_string($post['nameblock']) . "', '" . mysql_real_escape_string($post['subject']) . "', '" . mysql_real_escape_string($post['message']) . "', '" . mysql_real_escape_string($post['password']) . "', '" . $post['file'] . "', '" . $post['file_hex'] . "', '" . mysql_real_escape_string($post['file_original']) . "', " . $post['file_size'] . ", '" . $post['file_size_formatted'] . "', " . $post['image_width'] . ", " . $post['image_height'] . ", '" . $post['thumb'] . "', " . $post['thumb_width'] . ", " . $post['thumb_height'] . ")"); + mysql_query("INSERT INTO `" . TINYIB_DBPOSTS . "` (`parent`, `timestamp`, `bumped`, `ip`, `name`, `tripcode`, `email`, `nameblock`, `subject`, `message`, `password`, `file`, `file_hex`, `file_original`, `file_size`, `file_size_formatted`, `image_width`, `image_height`, `thumb`, `thumb_width`, `thumb_height`) VALUES (" . $post['parent'] . ", " . time() . ", " . time() . ", '" . $_SERVER['REMOTE_ADDR'] . "', '" . mysql_real_escape_string($post['name']) . "', '" . mysql_real_escape_string($post['tripcode']) . "', '" . mysql_real_escape_string($post['email']) . "', '" . mysql_real_escape_string($post['nameblock']) . "', '" . mysql_real_escape_string($post['subject']) . "', '" . mysql_real_escape_string($post['message']) . "', '" . mysql_real_escape_string($post['password']) . "', '" . $post['file'] . "', '" . $post['file_hex'] . "', '" . mysql_real_escape_string($post['file_original']) . "', " . $post['file_size'] . ", '" . $post['file_size_formatted'] . "', " . $post['image_width'] . ", " . $post['image_height'] . ", '" . $post['thumb'] . "', " . $post['thumb_width'] . ", " . $post['thumb_height'] . ")"); return mysql_insert_id(); } function bumpThreadByID($id) { - mysql_query("UPDATE `" . $GLOBALS['mysql_posts_table'] . "` SET `bumped` = " . time() . " WHERE `id` = " . $id . " LIMIT 1"); + mysql_query("UPDATE `" . TINYIB_DBPOSTS . "` SET `bumped` = " . time() . " WHERE `id` = " . $id . " LIMIT 1"); } function countThreads() { - return mysql_result(mysql_query("SELECT COUNT(*) FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `parent` = 0"), 0, 0); + return mysql_result(mysql_query("SELECT COUNT(*) FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = 0"), 0, 0); } function allThreads() { $threads = array(); - $result = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_posts_table'] . "` 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)) { $threads[] = $thread; } @@ -95,7 +95,7 @@ function allThreads() { function postsInThreadByID($id) { $posts = array(); - $result = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_posts_table'] . "` 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)) { $posts[] = $post; } @@ -104,7 +104,7 @@ function postsInThreadByID($id) { function latestRepliesInThreadByID($id) { $posts = array(); - $replies = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_posts_table'] . "` 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"); while ($post = mysql_fetch_assoc($replies)) { $posts[] = $post; } @@ -113,7 +113,7 @@ function latestRepliesInThreadByID($id) { function postsByHex($hex) { $posts = array(); - $result = mysql_query("SELECT `id`, `parent` FROM `" . $GLOBALS['mysql_posts_table'] . "` 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)) { $posts[] = $post; } @@ -125,7 +125,7 @@ function deletePostByID($id) { foreach ($posts as $post) { if ($post['id'] != $id) { deletePostImages($post); - mysql_query("DELETE FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `id` = " . $post['id'] . " LIMIT 1"); + mysql_query("DELETE FROM `" . TINYIB_DBPOSTS . "` WHERE `id` = " . $post['id'] . " LIMIT 1"); } else { $thispost = $post; } @@ -135,14 +135,13 @@ function deletePostByID($id) { @unlink('res/' . $thispost['id'] . '.html'); } deletePostImages($thispost); - mysql_query("DELETE FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `id` = " . $thispost['id'] . " LIMIT 1"); + mysql_query("DELETE FROM `" . TINYIB_DBPOSTS . "` WHERE `id` = " . $thispost['id'] . " LIMIT 1"); } } function trimThreads() { - global $tinyib; - if ($tinyib['maxthreads'] > 0) { - $result = mysql_query("SELECT `id` FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `parent` = 0 ORDER BY `bumped` DESC LIMIT " . $tinyib['maxthreads']. ", 10"); + if (TINYIB_MAXTHREADS > 0) { + $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)) { deletePostByID($post['id']); } @@ -150,7 +149,7 @@ function trimThreads() { } function lastPostByIP() { - $replies = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_posts_table'] . "` 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)) { return $post; } @@ -158,14 +157,14 @@ function lastPostByIP() { # Ban Functions function banByID($id) { - $result = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_bans_table'] . "` 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)) { return $ban; } } function banByIP($ip) { - $result = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_bans_table'] . "` 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)) { return $ban; } @@ -173,7 +172,7 @@ function banByIP($ip) { function allBans() { $bans = array(); - $result = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_bans_table'] . "` ORDER BY `timestamp` DESC"); + $result = mysql_query("SELECT * FROM `" . TINYIB_DBBANS . "` ORDER BY `timestamp` DESC"); while ($ban = mysql_fetch_assoc($result)) { $bans[] = $ban; } @@ -181,19 +180,19 @@ function allBans() { } function insertBan($ban) { - mysql_query("INSERT INTO `" . $GLOBALS['mysql_bans_table'] . "` (`ip`, `timestamp`, `expire`, `reason`) VALUES ('" . mysql_real_escape_string($ban['ip']) . "', " . time() . ", '" . mysql_real_escape_string($ban['expire']) . "', '" . mysql_real_escape_string($ban['reason']) . "')"); + mysql_query("INSERT INTO `" . TINYIB_DBBANS . "` (`ip`, `timestamp`, `expire`, `reason`) VALUES ('" . mysql_real_escape_string($ban['ip']) . "', " . time() . ", '" . mysql_real_escape_string($ban['expire']) . "', '" . mysql_real_escape_string($ban['reason']) . "')"); return mysql_insert_id(); } function clearExpiredBans() { - $result = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_bans_table'] . "` 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)) { - mysql_query("DELETE FROM `" . $GLOBALS['mysql_bans_table'] . "` WHERE `id` = " . $ban['id'] . " LIMIT 1"); + mysql_query("DELETE FROM `" . TINYIB_DBBANS . "` WHERE `id` = " . $ban['id'] . " LIMIT 1"); } } function deleteBanByID($id) { - mysql_query("DELETE FROM `" . $GLOBALS['mysql_bans_table'] . "` WHERE `id` = " . mysql_real_escape_string($id) . " LIMIT 1"); + mysql_query("DELETE FROM `" . TINYIB_DBBANS . "` WHERE `id` = " . mysql_real_escape_string($id) . " LIMIT 1"); } ?> \ No newline at end of file diff --git a/inc/functions.php b/inc/functions.php index 7a9d9b0..6aef51f 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1,5 +1,5 @@ "); @@ -58,8 +58,6 @@ function convertBytes($number) { } function nameAndTripcode($name) { - global $tinyib; - if (preg_match("/(#|!)(.*)/", $name, $regs)) { $cap = $regs[2]; $cap_full = '#' . $regs[2]; @@ -103,7 +101,7 @@ function nameAndTripcode($name) { $tripcode .= "!"; } - $tripcode .= "!" . substr(md5($cap_secure . $tinyib['tripseed']), 2, 10); + $tripcode .= "!" . substr(md5($cap_secure . TINYIB_TRIPSEED), 2, 10); } return array(preg_replace("/(" . $cap_delimiter . ")(.*)/", "", $name), $tripcode); @@ -135,9 +133,7 @@ function nameBlock($name, $tripcode, $email, $timestamp, $modposttext) { } function writePage($filename, $contents) { - global $tinyib; - - $tempfile = tempnam('res/', $tinyib['board'] . 'tmp'); /* Create the temporary file */ + $tempfile = tempnam('res/', TINYIB_BOARD . 'tmp'); /* Create the temporary file */ $fp = fopen($tempfile, 'w'); fwrite($fp, $contents); fclose($fp); @@ -168,21 +164,20 @@ function deletePostImages($post) { } function manageCheckLogIn() { - global $tinyib; $loggedin = false; $isadmin = false; if (isset($_POST['password'])) { - if ($_POST['password'] == $tinyib['adminpassword']) { - $_SESSION['tinyib'] = $tinyib['adminpassword']; - } elseif ($tinyib['modpassword'] != '' && $_POST['password'] == $tinyib['modpassword']) { - $_SESSION['tinyib'] = $tinyib['modpassword']; + if ($_POST['password'] == TINYIB_ADMINPASS) { + $_SESSION['tinyib'] = TINYIB_ADMINPASS; + } elseif (TINYIB_MODPASS != '' && $_POST['password'] == TINYIB_MODPASS) { + $_SESSION['tinyib'] = TINYIB_MODPASS; } } if (isset($_SESSION['tinyib'])) { - if ($_SESSION['tinyib'] == $tinyib['adminpassword']) { + if ($_SESSION['tinyib'] == TINYIB_ADMINPASS) { $loggedin = true; $isadmin = true; - } elseif ($tinyib['modpassword'] != '' && $_SESSION['tinyib'] == $tinyib['modpassword']) { + } elseif (TINYIB_MODPASS != '' && $_SESSION['tinyib'] == TINYIB_MODPASS) { $loggedin = true; } } diff --git a/inc/html.php b/inc/html.php index b6afe99..7f163c6 100644 --- a/inc/html.php +++ b/inc/html.php @@ -1,14 +1,14 @@ - ${tinyib['boarddescription']} +EOF; + $return .= TINYIB_BOARDDESC . <<<EOF @@ -19,6 +19,7 @@ function pageHeader() { EOF; + return $return; } function pageFooter() { @@ -112,7 +113,6 @@ EOF; } function buildPage($htmlposts, $parent, $pages=0, $thispage=0) { - global $tinyib; $managelink = basename($_SERVER['PHP_SELF']) . "?manage"; $postingmode = ""; @@ -162,8 +162,8 @@ EOF; [Manage]
- + ' . << @@ -256,9 +258,7 @@ EOF; return pageHeader() . $body . pageFooter(); } -function rebuildIndexes() { - global $mysql_posts_table; - +function rebuildIndexes() { $htmlposts = ""; $page = 0; $i = 0; @@ -300,8 +300,6 @@ function rebuildIndexes() { } function rebuildThread($id) { - global $mysql_posts_table; - $htmlposts = ""; $posts = postsInThreadByID($id); foreach ($posts as $post) { @@ -326,8 +324,6 @@ function adminBar() { } function managePage($text, $onload='') { - global $tinyib; - $adminbar = adminBar(); $body = << @@ -335,8 +331,8 @@ function managePage($text, $onload='') { $adminbar