Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // TODO:
- // title gen
- // age redirect to page
- // merge reply form into current page
- // serparate cookie domain for security
- if ( !defined("ALLOWED") ) exit();
- error_reporting(5);
- global $db;
- global $error;
- global $page;
- class database {
- var $link; var $conn; var $res; var $numRows; var $numAffected; var $error;
- function database($hostname = '127.0.0.1', $username = "db1", $password = "wot.", $db = "wx") {
- $this->conn = mysql_connect($hostname, $username, $password);
- if (!$this->conn) die(mysql_error());
- mysql_select_db( $db );
- return $this->conn;
- }
- function query($sql) {
- if (!$this->conn) { echo "not connected"; return false; }
- $this->res = mysql_query($sql, $this->conn);
- if (!$this->res) { return false; }
- }
- function clean($query) { $nQ = mysql_real_escape_string( $query ); return $nQ; }
- function getNext() { $res = mysql_fetch_assoc($this->res); return $res; }
- function getRow() { $res = mysql_fetch_row($this->res); return $res; }
- function getNumRows() { $res = ($this->numRows ? $this->numRows : mysql_num_rows($this->res)); return $res; }
- function getNumAffected() { $res = ($this->numAffected ? $this->numAffected : mysql_affected_rows($this->conn)); return $res;}
- }
- class ImageBoard {
- function __construct() {
- $db = new database("localhost","db1","wot.","wx");
- if ( !isset($_SESSION['permission'] ) ) session_start();
- ini_set("sendmail_from", "boss@p0x.us");}
- function display ( $element ) {
- switch ( $element ) {
- case "style":
- // grab from $_SESSION (!!!)
- echo "/includes/css/base.css";
- break;
- case "nav":
- // determine permissions
- if ( !isset($_SESSION['permission']) ) { $level = 0; } else { $level = $_SESSION['permission']; }
- if ( $level == 0 ) { include("/views/nav/guest.php"); }
- elseif ( $level >= 1 && $level <= 6 ) { include("/views/nav/user.php"); }
- elseif ( $level >= 7 && $level <= 8 ) { include("/views/nav/mod.php"); }
- elseif ( $level == 9 ) { include("/views/nav/admin.php"); }
- break;
- }
- }
- function action ( $main, $sub ) {
- $main = strtolower($main); $sub = strtolower($sub);
- switch ( $main ) {
- case "":
- // list boards
- $this->ListBoards();
- break;
- case "login":
- // if already logged in
- if ( isset($_SESSION['user']) && $_SESSION['user'] != "" ) $this->ThrowError("logged_in");
- // if submitting
- if ( $_GET['b'] == "submit" ) {
- $this->UserLogin( $_POST['email'], $_POST['password'] );
- } else {
- require_once("/views/login.inc.php");
- }
- break;
- case "register":
- // if already logged in
- if ( isset($_SESSION['user']) && $_SESSION['user'] != "" ) $this->ThrowError("logged_in");
- if ( $sub == "submit" ) {
- $this->UserRegister( $_POST['username'], $_POST['email'], $_POST['captcha'] );
- } else {
- require_once("/views/register.inc.php");
- }
- break;
- case "board":
- $this->ViewBoard( $sub );
- break;
- case "topic":
- $this->ViewTopic( $sub );
- break;
- case "reply":
- if ( !isset( $_POST['process'] ) && $this->regex($sub,"id") ) {
- require_once("/views/reply.inc.php");
- } elseif ( isset( $_POST['process'] ) && $this->regex($sub,"id") ){
- $this->TopicReply ($_POST['id'],$_POST['content'],$_POST['who'], null);
- } else { die("wait, what?"); }
- break;
- case "post":
- if ( !isset( $_POST['process'] ) ) {
- require_once("/views/new_topic.inc.php");
- } else { $this->PostTopic( $_POST['board'], $_POST['title'], $_POST['content'], $_POST['who'] ); }
- break;
- case "sample":
- require_once("/views/sample3.inc.php");
- break;
- case "error":
- $this->ShowError( $sub );
- break;
- case "logout":
- unset($_COOKIE['token'], $_COOKIE['user'], $_SESSION['user'], $_SESSION['permission']);
- echo "<meta http-equiv=\"refresh\" content=\"0;url=/\" />";
- break;
- case "settings":
- if ( $_GET['b'] == "submit" ) ) {
- $this->UserChangeSettings( $_POST['pwd_unlock'], $_POST['chg_pwd1'], $_POST['chg_pwd2'],
- $_POST['bio'], $_POST['style'], $_POST['rcvMsg'], $_POST['ntfMsg'] );
- } else {
- // pull infos to match!
- $uP = $this->PullUserSettings();
- require("/views/settings.inc.php");
- }
- break;
- case "captcha":
- ShowCaptcha();
- break;
- case "faq":
- switch ($sub) {
- case "": require_once("/views/faq/faq.inc.php"); break;
- case "rules": require_once("/views/faq/rules.inc.php"); break;
- case "wat": require_once("/views/faq/wat.inc.php"); break;
- case "privacy": require_once("/views/faq/privacy.inc.php"); break;
- }
- break;
- case "nsfw":
- if ( $sub == "yes" ) $_SESSION['nsfw'] = "yes";
- if ( isset($_SESSION['redirect'] ) ) { $rPath = $_SESSION['redirect']; } else { $rPath = "/"; }
- if ( isset($_SESSION['nsfw'])) { header("Location: $rPath"); } else { require_once("/views/nsfw.inc.php"); }
- break;
- case "file":
- $this->FileBank( $sub );
- break;
- }
- }
- function ListBoards() {
- // set variables
- // require template
- $db = new database();
- $permission = $this->GetPermissionLevel();
- $boards = $db->query("SELECT ID, NAME, DESCRIPTION, THREAD_COUNT FROM `boards` WHERE LOCKED = 0 AND ACCESSLEVEL <= $permission ORDER BY THREAD_COUNT DESC");
- // pull board data
- $x = array();
- while ( $row = $db->getRow() ) {
- $id = $row[0];
- $x[$id] = array( "id" => $id, "name" => $row[1], "desc" => $row[2], "topics" => $row[3], );
- }
- include("/views/index.inc.php");
- unset($db, $aLevel, $boards, $x);
- }
- function ViewBoard( $board ) {
- // check that board exists, it's not locked, and you can access it
- $db = new database();
- $permission = $this->GetPermissionLevel();
- $boards = $db->query("SELECT NAME, DESCRIPTION, BULLETIN, THREAD_COUNT, SFW FROM `boards` WHERE LOCKED = 0 AND ACCESSLEVEL <= $permission AND NAME = '$board' LIMIT 1");
- if ( $db->getNumRows() == 1 ) {
- // pull board data
- $b = $db->getNext($boards);
- //Array ( [NAME] => b [DESCRIPTION] => Random discussion, ala 4chan. [BULLETIN] => [THREAD_COUNT] => 0 )
- // check SWF
- $_SESSION['redirect'] = "/board/$board";
- if ( $_SESSION['nsfw'] != "yes" && $b['SFW'] == 0 ) $this->ThrowError("nsfw_flag");
- // pull TOPICS
- //$posts = $db->query(""); //ID BOARD TITLE AUTHOR OP REPLIES LAST_BUMP
- $topics = mysql_query("SELECT * FROM `topics` WHERE BOARD='$board' ORDER BY LAST_BUMP ASC LIMIT 40");
- while ($i = mysql_fetch_assoc($topics)) {
- $id = $i["ID"];
- $x[$id] = $i;
- }
- require_once("/views/board.inc.php");
- } else {
- $this->ThrowError("bad_board");
- }
- unset($db, $aLevel, $boards, $x);
- }
- function ViewTopic( $id ) {
- // regex input
- if ( !$this->regex( $id, "id" ) ) { $this->ThrowError("bad_id"); }
- // pull topic
- $db = new database;
- $topic = $db->query("SELECT * FROM `topics` WHERE ID=$id LIMIT 1");
- if ( $db->getNumRows($topic) != 1 ) { $this->ThrowError("bad_topic"); }
- // store topic
- $topic = $db->getNext($topic);
- // pull posts
- $posts = $db->query("SELECT * FROM `posts` WHERE TOPIC=$id ORDER BY TIMESTAMP LIMIT 25");
- $count = $db->getNumRows($posts);
- if ( $count <= 0 ) { $this->ThrowError("empty_topic"); }
- // store posts
- while ( $i = $db->getNext($posts) ) {
- $pID = $i['ID'];
- $p[$pID] = $i;
- }
- //echo "<h1>topic</h1>"; print_r($topic); echo "<hr/>";echo "<h1>OP</h1>";print_r($OP); echo "<hr/>";echo "<h1>posts</h1>";print_r($p); echo "<hr/>";
- require_once("/views/topic.inc.php");
- }
- function PostTopic ( $board, $title, $content, $who ) {
- $db = new database;
- // sanitize
- $board = mysql_real_escape_string($board);
- $res = mysql_query("SELECT ACCESSLEVEL, LOCKED FROM `boards` WHERE NAME = '$board' LIMIT 1");
- if ( mysql_num_rows($res) != 1 ) $this->ThrowError("bad_board");
- $res = mysql_fetch_row( $res );
- // do you have permission to post in this board? ( !locked, perm <= mine, does exist)
- if ( $res["ACCESSLEVEL"] > $_SESSION['permission'] || $res['LOCKED'] == 1 ) $this->ThrowError("bad_board");
- if ( !$this->Regex($title, "title") ) $this->ThrowError("bad_title");
- if ( empty($title) ) $this->ThrowError("empty_title");
- $title = mysql_real_escape_string($title);
- // are you opting for anonymity?
- // set you for "anon", no for ("" || "me")
- if ( $who == "me" ) { $who = $_SESSION['user']; } elseif ( $who != "anon" ) { $this->ThrowError("form_tamper"); }
- // gather values
- $time = time();
- // insert topic, get ID
- $tINS = mysql_query("INSERT INTO `topics` (BOARD, TITLE, AUTHOR, LAST_BUMP, REPLIES ) VALUES ( '$board', '$title', '$who', $time, -1 )") or die("INSERT INTO `topics` (BOARD, TITLE, AUTHOR) VALUES ('$board', '$title', '$who')");
- $tINS = mysql_fetch_row(mysql_query("SELECT ID FROM `topics` WHERE BOARD = '$board' AND TITLE = '$title' AND AUTHOR = '$who' AND LAST_BUMP=$time LIMIT 1"));
- // increment board counter
- $inc = mysql_query("UPDATE `boards` SET THREAD_COUNT=THREAD_COUNT+1 WHERE NAME='$board'");
- // make OP
- $this->TopicReply( $tINS[0], $content, $who, $_FILES );
- }
- function TopicReply( $id, $content, $who, $filedata ) {
- // validate input
- if ( !$this->regex( $id, "id" ) ) { $this->ThrowError("bad_id"); }
- if ( strlen($content) == 0 ) $this->ThrowError("empty_post");
- if ( strlen($content) > 25000 ) $this->ThrowError("long_post");
- // pull topic, make sure it exists! ( ### DOES NOT CHECK IF YOU HAVE PERMISSION TO ### )
- $db = new database;
- $topic = mysql_query("SELECT ID, REPLIES FROM `topics` WHERE ID=$id LIMIT 1");
- if ( mysql_num_rows($topic) != 1 ) { $this->ThrowError("bad_topic"); }
- // time! other necessary info?
- $time = time();
- // OH GUTEN TAG, STURMBANFUHRER!
- $ip = $_SERVER['REMOTE_ADDR'];
- // capcode content
- $content = $this->gmCode($content);
- // nl2br content
- $content = nl2br($content);
- // who's posting?
- if ( $who == "me" ) { $who = $_SESSION['user']; } else { $who = "anon"; }
- if ( !isset($filedata) ) $filedata = $_FILES;
- // determine if file was uploaded, check for other errors
- if ($filedata["attach"]["error"] == 1) {
- $this->ThrowError("file_big");
- } elseif ($filedata["attach"]["error"] == 3) {
- $this->ThrowError("file_part");
- } elseif ($filedata["attach"]["error"] == 6) {
- $this->ThrowError("file_tmp");
- } elseif ($filedata["attach"]["error"] == 0) {
- // check filesize and type
- $size = $filedata["attach"]["size"];
- if ( $size > $this->UploadQuota() ) { $this->ThrowError("file_too_big"); }
- if ( $size == 0 ) { $this->ThrowError("empty_upload"); }
- $mime = $this->FindMime($filedata["attach"]["name"] );
- // generate a random id for the attachment
- $key = "";
- $pool = "abcdefghkpmnqrtuvwxyz1234567890";
- for ( $i = 0; $i < 8; $i++ ) { $key = $key . substr( $pool, rand(1, strlen($pool)), 1); }
- // copy file to permanence, get filename and INSERT
- $filename = $filedata["attach"]["name"];
- $ext = substr($filename, strrpos($filename, '.') + 1);
- $whole_file = $key . "." . substr($filename, strrpos($filename, '.') + 1);
- $size = $filedata["attach"]["size"];
- move_uploaded_file ( $filedata["attach"]["tmp_name"] , "./attachments/$key.$ext");
- mysql_query("INSERT INTO `wx`.`files` (`KEY`, `FILENAME`, `SIZE`, `MIMETYPE`) VALUES ('$key', '$whole_file', $size, '$mime');") or $this->ThrowError("bad_file_insert");
- mysql_query("INSERT INTO `wx`.`posts` (`AUTHOR` ,`TOPIC` ,`CONTENT` ,`FILE` ,`TIMESTAMP`, `IP` ) VALUES ('$who', '$id', '$content', '$key.$ext', '$time', '$ip');") or $this->ThrowError("post_fail2");
- } else {
- $db->query("INSERT INTO `wx`.`posts` (`AUTHOR` ,`TOPIC` ,`CONTENT` ,`FILE` ,`TIMESTAMP`, `IP`) VALUES ('$who', '$id', '$content', '', '$time', '$ip');");
- }
- // increment post counter for topic
- $inc = mysql_query("UPDATE `topics` SET REPLIES=REPLIES+1 WHERE ID='$id'");
- // redirect
- $_SESSION['redirect'] = "/topic/$id";
- $this->ThrowError("reply_success");
- }
- function FileBank( $file ) {
- $db = new database;
- $file = mysql_real_escape_string( $file );
- $x = mysql_query("SELECT FILENAME, MIMETYPE FROM `files` WHERE `KEY` = '$file' LIMIT 1") or die("#FNF#");
- if ( mysql_num_rows ( $x ) == 1 ) {
- error_reporting(0);
- $x = mysql_fetch_assoc( $x );
- if ( $x['MIMETYPE'] == "" || !isset($x['MIMETYPE'] ) ) $x['MIMETYPE'] = "text/plain";
- header("Content-type: {$x['MIMETYPE']}");
- require_once("/attachments/{$x['FILENAME']}");
- } else { die("#FNF0#"); }
- // #TODO: add a "if this file doesn't exist" clause
- }
- function UserRegister ( $user, $email, $captcha ) {
- $wx = new ImageBoard;
- $email = strtolower($email);
- if ( $captcha != $_SESSION['captcha'] ) $this->ThrowError("bad_captcha");
- unset($_SESSION['captcha']);
- // regex
- if ( !$this->Regex( $user, "username") ) $this->ThrowError("bad_user");
- if ( !$this->Regex( $email, "email") ) $this->ThrowError("bad_email");
- // check to see if there's already a user there, fail if so
- $db = new database;
- if ($db->getNumRows($db->query("SELECT USERNAME FROM `users` WHERE USERNAME='$user'")) != 0) $this->ThrowError("uname_taken");
- // unset CAPTCHA, so as to prevent refresh flooding
- $_SESSION['captcha'] = "00000";
- // insert new info, using random password
- $temp_pwd = rand(10000,99999);
- $temp_hash = substr(md5( $temp_pwd ),0,16);
- echo "INSERT INTO `users` ( USERNAME, PASSWORD, EMAIL, PERMISSION, POSTCOUNT ) VALUES ( '$user', '$temp_hash', '$email', 1, 0 )";
- $reg = $db->query("INSERT INTO `users` ( USERNAME, PASSWORD, EMAIL, PERMISSION, POSTCOUNT ) VALUES ( '$user', '$temp_hash', '$email', 1, 0 )");
- // mail info
- //mail( $email, "p0x registration", "Thanks for registering with p0x! Here's your account info:\n\nusername:$user\n
- //password: $password \n\n You can change your password form within the 'Panel' section of the board.\n\n
- //(If this message was delivered in error, please disregard it.)") or die("mail_fail");
- die("in lieu of registration, here's your password: $temp_pwd");
- }
- function PullUserSettings() {
- // who are you?
- if ( !isset($_SESSION['user'] ) ) { $this->ThrowError("not_logged_in"); } else { $user = $_SESSION['user']; }
- $db = new database;
- $uP = $db->query("SELECT * FROM `users` WHERE USERNAME = '$user' LIMIT 1");
- $uP = $db->getNext($uP);
- return array( $uP['EMAIL'], $uP['BIO'], $uP['THEME'], $uP['MSG_RCV'], $uP['MSG_NTF'] );
- }
- function UserChangeSettings( $unlock, $change1, $change2, $bio, $style, $rcvMsg, $ntfMsg ) {
- echo "unlock: $unlock<br/>change1: $change1<br/>change2: $change2<br/>bio: $bio<br/>style: $style<br/>
- rcvMsg: $rcvMsg<br/>ntfMsg: $nsfMsg<br/>";
- }
- function GetPermissionLevel() {
- // check session
- if ( isset( $_SESSION['permission']) ) {
- return $_SESSION['permission'];
- } else {
- return 0;
- }
- }
- function UserLogin( $email, $pass ) {
- // user-called function: assume it's a malicious input
- $db = new database;
- $email = mysql_real_escape_string(strtolower($email));
- $pass = substr( md5( $pass ), 0, 16);
- $uInfo = $db->query("SELECT USERNAME, PASSWORD, PERMISSION FROM `users` WHERE EMAIL = '$email' LIMIT 1");
- if ( $db->getNumRows($uInfo) != 1) $this->ThrowError("bad_login");
- $uInfo = $db->getRow($uInfo);
- if ( $uInfo[1] == $pass ) {
- $this->Login( $uInfo[0], $uInfo[2] );
- header("Location: /"); //$this->ThrowError("good_login");
- } else {
- die("bad login. input $pass != stored {$uInfo[2]}");
- }
- }
- function Login( $user, $permission ) {
- // the internal function
- $this->CreateCookie( $user );
- $this->CreateSession ( $user, $permission );
- }
- function VerifyCookie () {
- // match _COOKIE token with `sessions`
- if ( isset( $_COOKIE['token'] ) && strlen( $_COOKIE['token'] ) == 16 ) {
- // match up
- $db = new database;
- $uInfo = $db->query("SELECT * FROM `sessions` WHERE TOKEN = {$_COOKIE['token']}");
- if ( $db->getNumRows($uInfo) != null && substr(md5($_COOKIE['token']), 0, 16 ) == $uInfo['TOKEN'] ) {
- CreateSession($uInfo['USERNAME']);
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
- function CreateCookie ( $user ) {
- // create a token, store in _COOKIE and `sessions`
- // generate randomness, hash and store
- $key = substr(md5( rand() . "!bReakDanCE!" . time() ), 0, 16);
- $ip = $_SERVER['REMOTE_ADDR'];
- $time = time();
- $db = new database;
- // look for an existing session
- $r = $db->query("SELECT * FROM `sessions` WHERE USERNAME='$user' LIMIT 1");
- if ($db->getNumRows($r) == 1) {
- // if one exists, update it
- $r = $db->query("UPDATE `sessions` SET TOKEN='$key', DATE='$time' WHERE USERNAME = '$user' LIMIT 1");
- } else {
- // if not, create a new one
- $db->query("INSERT INTO `sessions` (USERNAME, TOKEN, DATE) VALUES ( '$user', '$key', $time )");
- }
- // store
- setcookie( "user" , $user );
- setcookie( "token" , $key );
- }
- function CreateSession ( $user, $permission ) {
- $_SESSION['user'] = $user;
- $_SESSION['permission'] = $permission;
- }
- function SetBan( $who, $ip, $host, $howLong ) {
- $db = new database;
- $ip = mysql_real_escape_string( $ip );
- $who = mysql_real_escape_string( $who );
- $host = mysql_real_escape_string( $host );
- $howLong = $howLong + time();
- // search for an existing ban
- $ban = $db->query("SELECT * FROM `bans` WHERE IP = '$ip' OR HOSTNAME = '$host' OR USERNAME = '$user' LIMIT 1");
- if ( $db->getNumRows($ban) != 0 ) {
- $ban = $db->getNext($ban);
- $db->query("UPDATE `bans` SET EXPIRES = $howLong WHERE ID = {$ban['ID']} LIMIT 1");
- } else {
- $db->query("INSERT INTO `bans` (IP, USERNAME, HOSTNAME, EXPIRES) VALUES ( '$ip', '$who', '$host', $howLong )");
- }
- }
- function BanMe( $length ) {
- if ( $_SESSION != "admin" ) {
- $this->SetBan( $_SESSION["user"], $_SERVER["REMOTE_ADDR"], $_SERVER["REMOTE_HOST"], $length );
- }
- }
- function CheckBan() {
- $db = new database;
- // my info
- $ip = $_SERVER['REMOTE_ADDR']; $hostname = $_SERVER['REMOTE_HOST']; $user = $_SESSION['user']; $time = time();
- $ban = $db->query("SELECT * FROM `bans` WHERE IP = '$ip' OR HOSTNAME = '$hostname' OR USERNAME = '$user' LIMIT 1");
- if ( $db->getNumRows($ban) != 0 ) {
- $ban = $db->getRow($ban);
- if ( ($ban[4] > time()) ) {
- $banLeftover = $this->nicetime( $ban[4] );
- die("<h1 style=\"font-size:256px; font-family: georgia; text-align: center;\">b&</h1><h1 style=\"font-family: monospace; font-size: 12px; position: absolute; left: 10px; bottom: 3px; \">You've been banned!<br/>It's set to expire in $banLeftover.</h1>");
- } else {
- // ban has already expired. leave it in there, so I can see it later. :P
- }
- }
- }
- /*function Identify() {
- // basically, make a dictionary of everybody who's ever used the imageboard,
- // so that we'll have an IP to provide, in case the FBI ever knocks on our door...
- // gather user info
- $ip = $_SERVER['REMOTE_ADDR'];
- $hostname = $_SERVER['REMOTE_HOST'];
- $timestamp = time();
- $user = $_SESSION['user'];
- // search by IP
- $db = new database;
- $r = mysql_query("SELECT ID FROM `sessions` WHERE (IP = '$ip' AND HOSTNAME = '$hostname') OR (USERNAME = '$user') LIMIT 1");
- $rNum = mysql_num_rows($r);
- // if an entry exists, update // if it doesn't, create it // otherwise crash and burn
- if ( $rNum == 1 ) { $r = mysql_query("UPDATE `sessions` SET TIMESTAMP = '$timestamp', HOSTNAME = '$hostname' WHERE IP = '$ip' LIMIT 1");}
- elseif ( $rNum == 0 ) { $r = mysql_query("INSERT INTO `sessions` ( IP, HOSTNAME, TIMESTAMP, USER ) VALUES ( '$ip', '$hostname', $timestamp, '$user')"); }
- else { die("wot."); }
- // TSEELEKT AUF TSESCHUN WORR TAIMSTAMP ES TAIMSTAMP UND
- $r = mysql_fetch_array(mysql_query("SELECT ID FROM `sessions` WHERE TIMESTAMP = $timestamp AND HOSTNAME = '$hostname' AND IP = '$ip' LIMIT 1"));
- $r = $r[0];
- }*/
- function ShowCaptcha() {
- error_reporting(0);
- // generate random string and set it in $_SESSION
- $pool = "abcdefghlkpmnqrtuvwxyz1234567890";
- for ( $i = 0; $i < 5; $i++ ) { $pass = $pass . substr( $pool, rand(1, strlen($pool)), 1); }
- $_SESSION['captcha'] = $pass;
- // Create image
- $im = imagecreatetruecolor(150, 25);
- $bg = imagecolorallocate($im, 0x14, 0x14, 0x14);
- $fg = imagecolorallocate($im, 0x33, 0xcc, 0xcc);
- imagefilledrectangle($im, 0, 0, 149, 24, $bg);
- imagecolortransparent($im, $bg);
- imagefttext ( $im, 18, rand(-10,10), rand(0,90), 20, $fg, './harabara.ttf', $pass);
- for ( $r = 0; $r < 2; $r++) { imageline( $im, 0, rand(0,24), 149, rand(0,24), $fg ); }
- header('Content-Type: image/png');
- imagepng($im);
- }
- function ShowError ($code) {
- unset($error);
- $error_list = array(
- "bad_board" => array("Board Unavailable", "This board is locked, above your permission level, non-existant or otherwise unavailable."),
- "bad_login" => array("Wrong Username/Password", "The username or password you entered is incorrect."),
- "bad_email" => array("Bad Email", "I'm not so sure that's a real e-mail address. Don't try to hustle me. :|"),
- "bad_captcha" => array("Invalid CAPTCHA", "Are you a bot? (Maybe you just don't have cookies enabled.)"),
- "bad_password" => array("Password did not match defined pattern", "C'mon now, don't be ridiculous."),
- "uname_taken" => array("Username is taken.", "Pick another."),
- "mail_fail" => array("can't mail this, yo", "I JUST CAN'T DO IT! D:"),
- "bad_user" => array("Bad username", "Let's not be ridiculous. :|"),
- "banned" => array("B&!", ""),
- "nsfw_flag" => array("Age not verified for adult content","hey now. <meta http-equiv=\"refresh\" content=\"0;url=/nsfw\" />"),
- "connect_fail" => array("DB MISSING", "WHO BALEETED IT. CMON GUISE. :("),
- "token_fail" => array("ERROR NO. TK731", "HALP! PUT OUT THE FIRE! :O"),
- "bad_id" => array("Topic ID failed regex", "Stop tryin' to h4x0r."),
- "bad_topic" => array("Topic doesn't exist", "What you were looking for has probably already been pruned."),
- "empty_post" => array("Empty post", "C'mon guy, you can't post nothing. That's just waste."),
- "file_big" => array("Filesize exceeds limit", "YOUR FILE IS TOO BIG."),
- "file_part" => array("Upload interrupted","I didn't catch that. What were you saying?"),
- "file_tmp" => array("ERROR NO. MT994","THIS FIRE IS GETTING HUGE! HALP! :O"),
- "long_post" => array("Loooong post is loooong.", "Cut back, slim. Cut way back."),
- "fkey_in_use" => array("File key already in use", "Go back and try it again."),
- "tampering" => array("Form tampering", "Your request has been squelched because you are a dirty hacker, hacker."),
- "reply_success" => array("Successfully posted a reply", "Your reply has been made. <a href=\"{$_SESSION['redirect']}\" class=\"button\">Return to topic</a><a href=\"/\" class=\"button\">Return to index</a>"),
- "reply_failure" => array("Reply failed", "Something broke. <a href=\"{$_SESSION['redirect']}\" class=\"button\">Return to topic</a><a href=\"/\" class=\"button\">Return to index</a>"),
- "file_too_big" => array("Upload filesize exceeds limit", "That's too big. Refer to the FAQ for more information.<a href=\"{$_SESSION['redirect']}\" class=\"button\">Return to topic</a>"),
- "bad_file_insert" => array("Generic database error", "Failed to update database with file information."),
- "empty_upload" => array("Empty file uploaded", "C'mon, dude. Get your life together."),
- "bad_title" => array("Title failed pattern matching", "...and we were pretty liberal here. You must've done something very wrong to get here."),
- "form_tamper" => array("Form tampering", "You keep this up and I'mma ban you. :|"),
- "empty_topic" => array("Topic empty", "OH SHIT YOU BROKE IT. >:O"),
- "logged_in" => array("User trying non-user action", "You don't need to be here. :|"),
- "not_logged_in" => array("Non-user trying user action", "You need to be logged in to do that. :|"),
- "good_login" => array("Logged in!", "Welcome back, {$_SESSION['user']}! Click <a href=\"/\">here</a> if you are not forwarded.</p><meta http-equiv=\"refresh\" content=\"0;url=/\" />")
- );
- $error = $error_list[$code];
- include("/views/error.inc.php");
- }
- function ThrowError ( $code ) {
- die("<p>Click <a href=\"/error/$code\">here</a> if you are not forwarded.</p><meta http-equiv=\"refresh\" content=\"0;url=/error/$code\" />");
- }
- function UploadQuota() {
- $lvl = $_SESSION['permission'];
- if ( !isset($lvl) || $lvl == "" ) return 1048576;
- switch ( $lvl ) {
- case 0: return 1048576; break; // 1MB guest
- case 1: return 2097152; break; // 2MB user
- case 2: return 5242880; break; // 5MB preferred user
- case 3: return 10485760; break; // 10MB contributing user
- case 4: return 10485760; break; // 10MB regular
- case 5: return 10485760; break; // 10MB regular++
- case 6: return 10485760; break; // 10MB regular+++
- case 7: return -1; break; // unlimited mod
- case 8: return -1; break; // unlimited mod
- case 9: return -1; break; // unlimited me! :D
- }
- }
- function Regex ( $expr, $pattern ) {
- $patterns = array(
- "username" => "/^[\w\_\~\!\@\#\$\%\^\&\*\(\)\"\;\:\[\{\]\}\/\.\,\?\x20]{3,16}$/",
- "title" => "/^[\w\n\~\!\@\#\$\%\^\&\*\(\)\"\;\:\[\{\]}\/\.\,\?\x20]{1,64}$/",
- "password" => "/^(.{4,64})$/",
- "email" => "/^[A-Za-z0-9._%+-]*\@[A-Za-z0-9._%+-]*\.[A-Za-z]{2,4}$/",
- "id" => "/^[0-9]{1,6}$/"
- );
- if ( preg_match( $patterns[$pattern], $expr ) ) { return true; } else { return false; }
- }
- function gmCode ( $content ) {
- return preg_replace(
- "/\[b\](.*)\[\/b\]/Usi", "<b>\\1</b>", $content);
- }
- function FindMime ( $filename ) {
- $e = substr($filename, strrpos($filename, '.') + 1);
- switch ($e) {
- case "": return "text/plain"; break;
- case "txt": return "text/plain"; break;
- case "doc": return "application/msword"; break;
- case "docx": return "application/msword"; break;
- case "rtf": return "application/rtf"; break;
- case "gz": return "application/x-gzip"; break;
- case "zip": return "application/zip"; break;
- case "mid": return "audio/mid"; break;
- case "mp3": return "audio/mpeg"; break;
- case "bmp": return "image/bmp"; break;
- case "gif": return "image/gif"; break;
- case "jpg": return "image/jpeg"; break;
- case "jpeg": return "image/jpeg"; break;
- case "tif": return "image/tiff"; break;
- case "tiff": return "image/tiff"; break;
- case "htm": return "text/html"; break;
- case "html": return "text/html"; break;
- }
- }
- function nicetime ( $then ) {
- $then = abs($then);
- $now = time(); $i = 0;
- $interval = array( array( 31104000, 2592000, 86400, 3600, 60, 1 ), array( "year", "month", "day", "hour", "minute", "second" ) );
- if ( $then > $now ) {
- foreach ( $interval[0] as $unit ) {
- $value = floor(($then - $now) / $unit);
- $i++;
- if ( $value > 1 ) return "{$value} {$interval[1][$i-1]}s";
- if ( $value == 1 ) return "{$value} {$interval[1][$i-1]}";
- }
- } elseif ( $now > $then ) {
- foreach ( $interval[0] as $unit ) {
- $value = floor(($now - $then) / $unit);
- $i++;
- if ( $value > 1 ) return "{$value} {$interval[1][$i-1]}s";
- if ( $value == 1 ) return "{$value} {$interval[1][$i-1]}";
- }
- } else {
- return "now";
- }
- }
- function nicesize($size) {
- // REWRITE THIS, so you can say you did 100% of everything. :D
- $filesizename = array(" bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
- return $size ? round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $filesizename[$i] : '0 bytes'; }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement