Contributions by Keith Gable This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. In addition to being restricted by the GNU General Public License, Essence Engine may not be sold, rented, sublicensed, or leased; you are not permitted to generate revenue with the Essence Engine source code. You may, however, use Essence Engine to run a website that generates revenue via other means. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA $Id$ */ // Forums // Views the forums include("mainheader.php"); /* Notes: Simpler coding, multiple tables. Some ideas borrowed from phpBB. if !topic_id && forum_id, it's a topic under forum_id if topic_id && forum_id, it's a reply under topic_id Access control order: if user_type_* if user_disallow -> not allowed else -> allowed else if user_allow -> allowed else -> not allowed user_disallow overrides all other settings (priority 1) user_allow overrides user_type_* (priority 2) user_type_* sets default access requirement (priority 3) user_type_post should never be < 2, as Guest posting is not implemented create table forum_cats ( cat_id tinyint unsigned not null auto_increment, cat_order tinyint unsigned not null default '1', cat_name tinytext not null, primary key (cat_id), unique key cat_id (cat_id) ) type=MyISAM; create table forum_forums ( forum_id tinyint unsigned not null auto_increment, forum_cat tinyint unsigned not null, forum_order tinyint unsigned not null default '1', forum_name tinytext, forum_desc tinytext, user_type_view tinyint(1) unsigned not null default 0, user_type_post tinyint(1) unsigned not null default 2, user_allow text, user_disallow text, primary key (forum_id), unique key forum_id (forum_id) ) type=MyISAM; create table forum_posts ( post_id mediumint(8) unsigned not null auto_increment, topic_id mediumint(8) unsigned not null default '0', forum_id mediumint(8) unsigned not null default '0', post_username varchar(32), post_time int(11) unsigned not null default '0', post_head char(60), post_text text, post_userip char(16), opt_emoticons tinyint(1) unsigned not null default '1', opt_html tinyint(1) unsigned not null default '0', opt_bbcode tinyint(1) unsigned not null default '1', opt_sig tinyint(1) unsigned not null default '1', opt_sticky tinyint(1) unsigned not null default '0', opt_hide tinyint(1) unsigned not null default '0', opt_lock tinyint(1) unsigned not null default '0', opt_lockedit tinyint(1) unsigned not null default '0', user_type_view tinyint(1) unsigned not null default 0, user_type_post tinyint(1) unsigned not null default 2, user_allow text, user_disallow text, primary key (post_id), unique key post_id (post_id) ) type=MyISAM; ------------------------------------------------------------------------------- Advanced coding, single DB Table named "forums": id smallint unsigned not null auto_increment, parent_id smallint unsigned not null default 0, root_id smallint unsigned not null default 0, * flags * is_forum tinyint(1) unsigned not null default 0, hide tinyint(1) unsigned not null default 0, noemote tinyint(1) unsigned not null default 0, sticky tinyint(1) unsigned not null default 0, lockreply tinyint(1) unsigned not null default 0, lockedit tinyint(1) unsigned not null default 0, * access * usertype tinyint(1) unsigned not null default 2, userin text default '', userex text default '', * data * username varchar(32) not null, date int(10) unsigned not null default 0, title varchar(255) not null, content text not null, primary key (id), unique key id (id) parent_id = 0 && root_id = 0 It's a category. Ignore content and is_forum. parent_id = N && root_id = 0 && is_forum = 1 It's a top level forum under cat N. Content is the forum description. parent_id = N && root_id = N && is_forum = 0 It's a post under forum root_id. parent_id = N && root_id = N && is_forum = 1 It's a subforum under forum root_id. */ if ($_GET["forumid"]) { $query = "SELECT * FROM forum_forums WHERE forum_id='" . mysql_escape_string($_GET["forumid"]) . "'"; $result = mysql_query($query, $db); if ($forum = mysql_fetch_array($result)) { if (checkprivs($forum,$userinfo,"view")) { $pagetitle = "Forum: " . safetext($forum["forum_name"]); if (checkprivs($forum,$userinfo,"post")) $postok = true; } else { sysmsg("You do not have permission to view that forum."); sendlocation("forums.php"); } } else { sysmsg("No data found for forum id " . safetext($_GET["forumid"]) . "."); sendlocation("forums.php"); } } else $pagetitle = "Forums"; include("themeheader.php"); if ($_GET["forumid"]) { $forumid = mysql_escape_string($_GET["forumid"]); // Todo: Implement flags echo '

You are here: Forums /'; echo ' ' . safetext($forum["forum_name"]) . "\n"; echo "

\n"; if ($postok) echo "
Post a new topic
\n"; if (!$userinfo["showhidden"]) $hide = "AND opt_hide=0"; // Make configurable $perpage = 25; if (is_numeric($_GET["page"])) $pagenum = mysql_escape_string($_GET["page"]); else $pagenum = 1; // Generate page count $result = mysql_query("SELECT count(*) FROM forum_posts WHERE forum_id='$forumid' AND topic_id=0 $hide", $db); $totalposts = mysql_fetch_array($result); $totalposts = $totalposts["count(*)"]; $totalpages = ceil($totalposts / $perpage); if ($totalpages > 1) { $pagecount = "
Go to page: \n"; for ($curpage = 1; $curpage <= $totalpages; ++$curpage) { if ($curpage == $pagenum) $pagecount .= $curpage; else $pagecount .= '' . $curpage . "\n"; if ($curpage != $totalpages) $pagecount .= " - "; } $pagecount .= "\n
\n
\n"; } echo $pagecount; $result_posts = mysql_query("SELECT * FROM forum_posts WHERE forum_id='$forumid' AND topic_id=0 $hide ORDER BY opt_sticky DESC, post_lastreply DESC, post_time DESC LIMIT " . $perpage . " OFFSET " . (($pagenum - 1) * $perpage), $db); if (mysql_affected_rows()) { echo "\n"; echo "\n"; while ($posts = mysql_fetch_array($result_posts)) { echo "\n"; echo " \n"; $post_user = mysql_fetch_array(mysql_query("SELECT dispname FROM users WHERE username='" . $posts["post_username"] . "'", $db)); if ($post_user["dispname"]) echo ' \n"; else echo ' \n"; $post_replies = mysql_fetch_array(mysql_query("SELECT count(*) FROM forum_posts WHERE topic_id=" . $posts["post_id"], $db)); echo ' \n"; $post_last = mysql_fetch_array(mysql_query("SELECT * FROM forum_posts WHERE topic_id=" . $posts["post_id"] . " ORDER BY post_time DESC LIMIT 1", $db)); if ($post_last) { echo ' \n"; } else echo " \n"; echo ""; } echo "
TitleStartedRepliesLast Reply
\n
"; if ($posts["opt_sticky"]) echo "*STICKY* "; if ($posts["opt_hide"]) echo "*HIDDEN* "; echo "' . safetext($posts["post_head"]) . "
\n"; echo '
' . safetext(trunctext(strip_post($posts["post_text"],$posts["opt_html"],$posts["opt_bbcode"]))) . "
\n
' . safetext(date("M j, Y \@ g:i A",$posts["post_time"])) . '
By: ' . safetext($post_user["dispname"]) . "
' . safetext(date("M j, Y \@ g:i A",$posts["post_time"])) . "
By a deleted user
' . $post_replies["count(*)"] . "' . safetext(date("M j, Y \@ g:i A",$post_last["post_time"])) . "
By: "; $post_user = mysql_fetch_array(mysql_query("SELECT dispname FROM users WHERE username='" . $post_last["post_username"] . "'", $db)); if ($post_user["dispname"]) echo '' . safetext($post_user["dispname"]) . ""; else echo "a deleted user"; echo "
No replies yet
\n"; echo $pagecount; } else { echo "
There are no posts under this forum.
"; } } else { // Todo: Implement flags $result_cats = mysql_query("SELECT * FROM forum_cats ORDER BY cat_order ASC, cat_name ASC", $db); echo "\n"; echo "\n"; if (mysql_affected_rows()) { while ($forum_cats = mysql_fetch_array($result_cats)) { if (checkprivs($forum_cats,$userinfo,"view")) { echo ""; $result_forums = mysql_query("SELECT * FROM forum_forums WHERE forum_cat='" . $forum_cats["cat_id"] . "' ORDER BY forum_order ASC", $db); if (mysql_affected_rows()) { while ($forum_forums = mysql_fetch_array($result_forums)) { if (checkprivs($forum_forums,$userinfo,"view")) { if (!$userinfo["showhidden"]) $hide = " AND opt_hide=0"; echo "\n"; echo " \n"; $forum_topics = mysql_fetch_array(mysql_query("SELECT count(*) FROM forum_posts WHERE forum_id=" . $forum_forums["forum_id"] . " AND topic_id=0 $hide", $db)); echo ' \n"; $forum_posts = mysql_fetch_array(mysql_query("SELECT count(*) FROM forum_posts WHERE forum_id=" . $forum_forums["forum_id"] . $hide, $db)); echo ' \n"; $forum_last = mysql_fetch_array(mysql_query("SELECT * FROM forum_posts WHERE forum_id=" . $forum_forums["forum_id"] . "$hide ORDER BY post_time DESC LIMIT 1", $db)); if ($forum_last) { echo ' \n"; } else echo " \n"; echo "\n"; $forumdisplayed = true; } } if (!$forumdisplayed) echo ""; } else echo ""; $catdisplayed = true; } if (!$catdisplayed) echo ""; } } else echo ""; echo "
TitleTopicsPostsLast Post
" . $forum_cats["cat_name"] . "
\n \n
" . $forum_forums["forum_desc"] . "
\n
' . $forum_topics["count(*)"] . "' . $forum_posts["count(*)"] . "' . safetext(date("F j, Y \@ g:i A",$forum_last["post_time"])) . "
By"; $post_user = mysql_fetch_array(mysql_query("SELECT dispname FROM users WHERE username='" . $forum_last["post_username"] . "'", $db)); if ($post_user["dispname"]) echo ': ' . safetext($post_user["dispname"]) . ""; else echo " a deleted user"; echo "
No posts yet
There are no forums under this category
There are no forums under this category
There are no forum categories.
There are no forum categories.
\n"; } include("themefooter.php"); ?>