tags with margins space the messages accordingly, thus no markers/bullets will appear beside messages anymore - Automagically adds (n/t) to posts without textVersion 3.1 changes: - Added ability to expand to new pages, thus holding more messages - Cleaned up post form, removed "Reset Form" button - Cleaned up blog main-post displaySetup: 1 - 2 - 3 Simple, no?1. Paste this code in a php file such as "forum.php". Take special care that no white space comes before the first php tag! The start of your HTML goes where you see the tag "Begin your HTML page here", and the forum HTML will begin where your HTML leaves off. Close your HTML page where you see "End your HTML page here".2. Edit the user variables below, including SQL information, styles and setup/admin variables.3. If you've entered the SQL information correctly, the program will automagically generate the database it needs to store the messages and display a confirmation message. Congratulations! Your forum is now ready to use!You can visit this code in action at the following URLs: http://www.greywyvern.com/forum.php http://www.greywyvern.com/blog.phpThanks for choosing the GWForum/Blog!Send comments to: gwforum@greywyvern.com************************************************* /Manual *//* ********************************************** Setup *//* ********************************************** User variables */// ***** SQL information *****$hostname = "localhost"; // Contact your hosting provider if you don't know these variables$username = "username";$password = "password";$database = "database";$sqlType = "mySQL"; // Either mySQL or postgreSQL$tableName = "GWForum";// ***** Reply form styles *****$rfBorderColour = "black"; // Change these styles as you see fit$rfBorderStyle = "solid";$rfBackgroundColour = "transparent";$rfFontColour = "black";$rfTitleBarColour ="slategray";$rfTitleFontColour = "black";$rfInputBackgroundColour = "#c1ccd9";$rfInputFontColour = "black";// ***** Message styles *****$mBordersColour = "lightgrey";$mTitleFontColour = "black";// ***** User variables *****$welcomeMessage = "
Welcome to my forum!"; // Welcome message can be any HTML as long as double quotes (") // are escaped with a backslash like so: "$timezoneacronym = "EST"; // Standard time zone acronym$timezoneoffset = "-5"; // Standard offset from GMT$dateFormat = "M j, Y g:i a"; // PHP date() format. See http://www.php.net/manual/en/function.date.php$verifyDomain = "strict"; // Degree of security against POSTs coming from outside your domain // Any of: "strict", "loose" or "none"$displayIPstyle = "tip"; // Method of author IP display on the tree of messages // Any of: "full", "tip" or "none"$permitHTML = false; // Allow HTML tags in messages (true|false) // If set to true, it *is* possible for a malicious user to insert // code which can upset your layout and even direct the post form // to another site. Use with caution$imageWidthLimit = "250"; // Force an upper limit for images in messages.$maxTopLevelPosts = 10; // The number of top-level posts that can exist before they begin // scrolling off the bottom of the page$maxPages = 3; // Total pages your forum/blog can expand to. The total number of // top level messages retained is equal to $maxPages multiplied by // $maxTopLevelPosts. The default is 10x3 or 30 threads.$spamSeconds = 60; // Time to wait before another message from the same IP will be // accepted. Prevents spamming/flooding.$deletePostsAdmin = "admin"; // Change these values$deletePostsPassword = "password"; // Type your admin name in the Name field, the password in the // Subject field, and the number of the post (the number of each // post can be found in it's URL eg. msg=###) in the email field, // and submit the form to delete that message and all of its // replies. Use this tool to moderate your forum as you desire.// ***** Blogger Setup *****$bloggerSwitch = false; // True = Function as blog, False = Function as forum$bloggerPrivate = true; // True = Password required for top-level posts$bloggerPassword = "password"; // Your blog password if above is true. Enter it in the box which
// appears to the right of the "Post Message!" button before you
// submit a blog entry. Replies to blog entries do not require a
// password.$bloggerWords = 75; // Number of words to display on main page before an ellipsis (...)/* ********************************************** /User variables */// ***** Do not cache this page *****header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");header("Cache-Control: no-store, no-cache, must-revalidate");header("Cache-Control: post-check=0, pre-check=0", false);header("Pragma: no-cache");// ***** PHP Hacks & Initialization *****error_reporting(E_ALL & ~E_NOTICE);$mySQL = ($sqlType == "postgreSQL") ? false : true;$db = db_connect($hostname, $username, $password, $database, $tableName);$offset = (date("I")) ? ($GLOBALS['timezoneoffset'] + 1) * 3600 : $GLOBALS['timezoneoffset'] * 3600;if (isset($_SERVER['QUERY_STRING'])) { if ($_SERVER['QUERY_STRING']) { $aArrSrc = explode("&", $_SERVER['QUERY_STRING']); foreach ($aArrSrc as $pair) { $qryArr = explode("=", $pair); ${$qryArr[0]} = $qryArr[1]; } $event = $aArrSrc[0]; }} if (!isset($event)) $event = ""; if (!isset($start)) $start = 0;if ($_SERVER['REQUEST_METHOD'] == "POST") postMessage();/* ********************************************** /Setup *//* ********************************************** HTML */ php /* **************************************** /HTML *//* ********************************************** Forum display */echo "n
n $welcomeMessagen
nn";if ($event != "View") {$topMsgs = getThreads(-1); $pstd = 0; if ($bloggerSwitch == false) echo forumLinks("02"); if (db_numrows($topMsgs) != 0) { if ($start >= db_numrows($topMsgs)) $start = db_numrows($topMsgs) - 1; if (db_numrows($topMsgs) > $maxTopLevelPosts) pageList(db_numrows($topMsgs) - 1 - $start - $maxTopLevelPosts); for ($num = db_numrows($topMsgs) - 1 - $start; $num > db_numrows($topMsgs) - 1 - $start - $maxTopLevelPosts; $num--) { ($start + $pstd++ < $maxTopLevelPosts * $maxPages) ? dispTree(db_result($topMsgs, $num, "msg_no"), true) : delTree(db_result($topMsgs, $num, "msg_no")); if ($num == 0) break; } if (db_numrows($topMsgs) > $maxTopLevelPosts) pageList($num); } else echo "n
n
Thanks for choosing the GW Forum/Blog!
If you're seeing this message, it means that the program has successfully connected to your SQL server/database and has created the table for storing the forum messages! Congratulations!
Start off your new forum by posting a welcome message using the form below. Once you post your first message, you won't see this message again.
- GreyWyvern
n
nn"; postForm(-1);} else dispMsg($msg);// ***** GWForum Signature *****echo "
All times listed in $timezoneacronym
A
GW Component
nn";/* ********************************************** /Forum display *//* ********************************************** Function list */// ***** Database functions ***** - Adaptation to PostgreSQL by Dragoniade [many thanks! :] *****function db_connect($hostname, $username, $password, $database, $tableName) { if ($GLOBALS['mySQL']) { $db = mysql_connect($hostname, $username, $password) or die("Could not connect to the MySQL server!"); mysql_select_db($database,$db) or die("Could not connect to the database!"); mysql_query("CREATE TABLE IF NOT EXISTS $tableName ( msg_no int(11), subject text, author text, email text, homepage text, ip text, dateStamp text, message longtext, image text, childOf int(11) );") or die("Could not create forum table!"); } else { $str_connect = (($hostname != "") ? $str_connect = "host=$hostname " : "")."dbname=$database user=$username password=$password"; $db = pg_connect($str_connect) or die("Could not connect to the postgreSQL server!"); $createTable = @pg_query("CREATE TABLE $tableName ( msg_no int, subject text, author text, email text, homepage text, ip text, dateStamp text, message text, image text, childOf int );"); } return $db;}function db_query($query) {return ($GLOBALS['mySQL']) ? @mysql_query($query) : @pg_query($query);}function db_numrows($result) {return ($GLOBALS['mySQL']) ? @mysql_numrows($result) : @pg_numrows($result);}function db_result($result,$row,$field) {return ($GLOBALS['mySQL']) ? @mysql_result($result,$row,$field) : @pg_fetch_result($result,$row,$field);}function getMsgs() {return db_query("SELECT * FROM {$GLOBALS['tableName']} ORDER BY msg_no");}function getRow($msg) {return db_query("SELECT * FROM {$GLOBALS['tableName']} WHERE msg_no='$msg'");}function getThreads($msg) {return db_query("SELECT * FROM {$GLOBALS['tableName']} WHERE childOf='$msg' ORDER BY msg_no");}// ***** Display functions *****// Display a full, readable message, the tree of replies and the reply formfunction dispMsg($msg) {echo forumLinks("11"); $message = getRow($msg); $prevMsg = getRow(db_result($message, 0, "childOf")); if (db_numrows($message) != 0) {
php echo db_result($message, 0, "subject").((!db_result($message, 0, "message")) ? " (n/t)" : ""); | By php echo ((db_result($message, 0, "email")) ? "" : "").db_result($message, 0, "author").((db_result($message, 0, "email")) ? "" : ""); |
php if (db_result($message, 0, "image")) { if ($imgAr = @getimagesize(db_result($message, 0, "image"))) { if ($imgAr[0] > $GLOBALS['imageWidthLimit']) {$imgSc = $imgAr[0] / $GLOBALS['imageWidthLimit']; $imgAr[1] /= $imgSc; $imgAr[0] = $GLOBALS['imageWidthLimit'];} } else $imgAr = array($GLOBALS['imageWidthLimit'] * .4, $GLOBALS['imageWidthLimit'] * .4); echo "n "; } echo "nnn".addLinks(db_result($message, 0, "message"))."nnn"; echo (db_result($message, 0, "homepage")) ? " Homepagen n" : ""; |
php echo (db_result($message,0,"childOf") != -1) ? "Above message is a reply to: ".db_result($prevMsg,0,"subject")." | n " : " | "; echo gmdate($GLOBALS['dateFormat'], db_result($message,0,"dateStamp") + $GLOBALS['offset'])." | n
n
nn"; if (db_numrows(getThreads($msg))) { echo "
Replies to this post...nn"; dispTree($msg, false); } postForm($msg); } else echo "Message
$msg does not exist!
n"; echo forumLinks("10");}// Display a tree of replies below message number $msg >> If $selfInc == true then include message $msg in the treefunction dispTree($msg, $selfInc) {static $dntLvl = -1; $message = getRow($msg); $dntLvl++; if (db_numrows($message) != 0) { if ($selfInc) { echo spaces($dntLvl * 2)."
n"; echo spaces($dntLvl * 2)."
".db_result($message, 0, "subject").((!db_result($message, 0, "message")) ? " (n/t)" : "")."".(($GLOBALS['bloggerSwitch'] == false or $dntLvl) ? "
" : "")."n"; echo spaces($dntLvl * 2)." By
".db_result($message, 0, "author")."".(($GLOBALS['displayIPstyle'] == "full") ? "
" .db_result($message, 0, "ip")."" : "")." -
".gmdate($GLOBALS['dateFormat'], db_result($message,0,"dateStamp") + $GLOBALS['offset'])."n"; if ($GLOBALS['bloggerSwitch'] == true && !$dntLvl) { echo spaces($dntLvl * 2)."
n"; $trimArray = explode(" ", preg_replace("/
/i", "
", db_result($message, 0, "message"))); if (count($trimArray) >= $GLOBALS['bloggerWords']) {for ($i = 0; $i < $GLOBALS['bloggerWords']; $i++) $trimArray2[$i] = $trimArray[$i];} else $trimArray2 = $trimArray; $trimMessage = join(" ", $trimArray2).(($i == $GLOBALS['bloggerWords']) ? "...
<More>" : ""); echo spaces($dntLvl * 2)." $trimMessagen"; echo spaces($dntLvl * 2)."
n"; } } if (db_numrows(getThreads($msg))) for ($i = db_numrows(getThreads($msg)) - 1; $i >= 0; $i--) dispTree(db_result(getThreads($msg), $i, "msg_no"), true); if ($selfInc) echo spaces($dntLvl * 2)."
n"; } else echo "Message
$msg does not exist!
n"; $dntLvl--;}// Display the Post/Reply formfunction postForm($replyVal) {$message = getRow($replyVal); $prevPost = unserialize(stripslashes($_COOKIE[$GLOBALS['tableName']])); $inputStyle = "color:{$GLOBALS['rfInputFontColour']};background-color:{$GLOBALS['rfInputBackgroundColour']};";
php echo gmdate($GLOBALS['dateFormat'], time() + $GLOBALS['offset'])." ".$GLOBALS['timezoneacronym']; php if ($replyVal != -1) {echo "Reply..."; $subject = db_result($message, 0, "subject"); if (substr($subject, 0, 4) != "Re: ") $subject = "Re: ".$subject; } else {echo (($GLOBALS['bloggerSwitch'] == true) ? "Add new entry..." : "Post new message..."); $subject = "";} n |
n
nn";}// Post a message to the DB on a page you can't get back to.function postMessage() {extract($_POST, EXTR_PREFIX_SAME, "invalid"); $parseReferrer = parse_url($_SERVER["HTTP_REFERER"]); $lastMsg = db_query("SELECT * FROM {$GLOBALS['tableName']} WHERE ip='{$_SERVER['REMOTE_ADDR']}' ORDER BY msg_no DESC LIMIT 1"); if ($_SERVER['SERVER_ADDR'] != gethostbyname($parseReferrer[host]) && $GLOBALS['verifyDomain'] == "strict") { $rspMessage = "Bad Referrer IP."; } else if (strpos($parseReferrer[host], $_SERVER['SERVER_NAME']) === false && $GLOBALS['verifyDomain'] == "loose") { $rspMessage = "Bad Referrer Domain."; } else if ($author == $GLOBALS['deletePostsAdmin'] && $subject == $GLOBALS['deletePostsPassword']) { $rspMessage = ($email != "" && delTree($email)) ? "Post number $email and all of it's replies have been deleted from the database." : "There is no message number $email in the database."; } else if ($GLOBALS['bloggerSwitch'] == true && $childOf == -1 && $GLOBALS['bloggerPrivate'] == true && $blogpass != $GLOBALS['bloggerPassword']) { $rspMessage = "Incorrect Blogger Password."; } else if (db_result($lastMsg, 0, "dateStamp") + $GLOBALS['spamSeconds'] > time()) { $rspMessage = "You must wait {$GLOBALS['spamSeconds']} seconds between posts."; } else if (!$subject && !$message) { $rspMessage = "Post was disallowed: Missing both subject and message."; } else { $author = (trim($author)) ? prepStr(trim($author), "10") : "Anonymous"; $author = (strlen($author) > 64) ? substr($author, 0, 64) : $author; $subject = (trim($subject)) ? prepStr(trim($subject), "10") : "<No Subject>"; $subject = (strlen($subject) > 64) ? substr($subject, 0, 64) : $subject; $email = prepStr($email, "10"); $homepage = (strtolower($homepage) == "http://") ? "" : prepStr($homepage, "10"); if ((strpos($homepage, "://") === false) && ($homepage)) $homepage = "http://".$homepage; if (preg_match('/.*(jpeg|jpg|png|gif|bmp|php|asp)$/i', $image)) { $image = (strtolower($image) == "http://") ? "" : prepStr($image, "10"); if ((strpos($image, "://") === false) && ($image)) $image = "http://".$image; } else $image = ""; $message = ($GLOBALS['permitHTML']) ? prepStr($message, "01") : prepStr($message, "11"); $pNum = @db_result(getMsgs(), db_numrows(getMsgs()) - 1, "msg_no") + 1; $result = db_query("INSERT INTO {$GLOBALS['tableName']} VALUES ('$pNum', '$subject', '$author', '$email', '$homepage', '{$_SERVER['REMOTE_ADDR']}', '".time()."', '$message', '$image', '$childOf')"); setcookie($GLOBALS['tableName'], serialize($_POST), time() * 2, "/"); $rspMessage = "Success! Your message has been posted."; } echo "nn
$rspMessagen
n"; echo "nn
$rspMessage
nn
Darmowy hosting zapewnia PRV.PL
n"; exit();}// ***** Other functions *****// Display links if forum/blog runs more than one pagefunction pageList($num) {global $start, $maxTopLevelPosts, $topMsgs; if ($num < 0) $num = 0; echo "n
n n "; echo ($start != 0) ? "<< Previous" : " "; echo "n | n Page n"; for ($pglnk = 0; $pglnk < db_numrows($topMsgs); $pglnk += $maxTopLevelPosts) { if ($pglnk == $start) {echo " ".(($pglnk / $maxTopLevelPosts) + 1)."n";} else echo " ".(($pglnk / $maxTopLevelPosts) + 1)."n"; } echo " | n n "; echo ($num != 0) ? "Next >>" : " "; echo "n | n
nn";}// Starting with message $msg, delete it and all replies.function delTree($msg) {$message = getrow($msg); if (db_numrows($message)) { if ($repList = db_numrows(getThreads($msg))) { for ($i = 0; $i < $repList; $i++) delTree(db_result(getThreads($msg), 0, "msg_no")); } return db_query("DELETE FROM {$GLOBALS['tableName']} WHERE msg_no='$msg'"); } else return false;}function addLinks($string) { $string = preg_replace("/(?s]|$))/i", "
$1", $string); return preg_replace("/href="www/i", "href="http://www", $string);}function spaces($num) { for ($i = 0; $i < $num; $i++) $buildStr .= " "; return $buildStr;}function prepStr($strg, $type) { // $type = "##", first 0 or 1 for htmlentities, second 0 or 1 for nl2br $strg = ($type[0]) ? htmlentities($strg) : $strg; $strg = ($type[1]) ? nl2br($strg) : $strg; return (get_magic_quotes_gpc()) ? $strg : addslashes($strg);}function forumLinks($type) { // $type = "##", first digit = Forum home, second digit(if 1) = Post a Reply, (if 2) Post New Message $buildStr = "
n "; $buildStr .= (($type[0]) ? "Main page" : "").(($type[0] && $type[1]) ? " | " : ""); $buildStr .= (($type[1] == "1") ? "Post a reply" : "").(($type[1] == "2") ? "Post new message" : ""); $buildStr .= "n
nn"; return $buildStr;}/* ********************************************** /Function list *//* ********************************************** /GWForum/Blog */