getresultsbykey("SELECT forum,readdate FROM forumread WHERE user=$loguserid", 'forum', 'readdate'); $forumlist=""; $fonline=""; // Add/remove favorites if ($act == 'add' || $act == 'rem') { $meta['noindex'] = true; // prevent search engines from indexing $t = $sql->fetchq("SELECT title,forum FROM threads WHERE id=$thread"); if (!$log) { require_once 'lib/layout.php'; errorpage("You need to be logged in to edit your favorites!",'return to the forum',"forum.php?id=$t[forum]"); } $sql->query("DELETE FROM favorites WHERE user=$loguserid AND thread=$thread"); if ($act == 'add') { $tx = "\"$t[title]\" has been added to your favorites."; $minpower = $sql->resultq("SELECT minpower FROM forums WHERE id=$t[forum]"); if($minpower < 1 || $minpower <= $power) $sql->query("INSERT INTO favorites (user,thread) VALUES ($loguserid,$thread)"); else $tx = "You can't favorite a thread you don't have access to!"; } else $tx = "\"$t[title]\" has been removed from your favorites."; require_once 'lib/layout.php'; errorpage($tx,'return to the forum',"forum.php?id=$t[forum]"); } // Forum Setup if ($fav) { if (!$log) { $meta['noindex'] = true; // prevent search engines from indexing what they can't access require_once 'lib/layout.php'; errorpage("You need to be logged in to view your favorites.",'log in (then try again)','login.php'); } $forum['title'] = 'Favorites'; if ($user && $user != $loguserid && $isadmin) $forum['title'] .= ' of '.$sql->resultq("SELECT name FROM users WHERE id={$user}"); else $user = $loguserid; $threadcount = $sql->resultq("SELECT COUNT(*) FROM favorites where user={$user}"); } elseif ($user) { $user1=$sql->fetchq("SELECT name,sex,powerlevel,aka,birthday FROM users WHERE id={$user}"); if (!$user1) { $meta['noindex'] = true; // prevent search engines from indexing what they can't access require_once 'lib/layout.php'; errorpage("No user with that ID exists.",'the index page','index.php'); } $forum['title']="Threads by $user1[name]"; $threadcount = $sql->resultq("SELECT COUNT(*) FROM threads where user=$user"); } elseif ($id) { # Default case, show forum with id $id = intval($id); $forum = $sql->fetchq("SELECT title,minpower,numthreads,specialscheme,pollstyle FROM forums WHERE id=$id"); if (!$forum) { trigger_error("Attempted to access invalid forum $id", E_USER_NOTICE); $meta['noindex'] = true; // prevent search engines from indexing what they can't access require_once 'lib/layout.php'; notAuthorizedError(); } elseif ($forum['minpower'] > max(0,$power)) { if ($log) trigger_error("Attempted to access level-$forum[minpower] restricted forum $id (user's powerlevel: ".intval($loguser['powerlevel']).")", E_USER_NOTICE); $meta['noindex'] = true; // prevent search engines from indexing what they can't access require_once 'lib/layout.php'; notAuthorizedError(); } else $specialscheme=$forum['specialscheme']; global $fourmid; $forumid=$id; $threadcount = $forum['numthreads']; } else { $meta['noindex'] = true; // prevent search engines from indexing what they can't access require_once 'lib/layout.php'; errorpage("No forum specified.",'the index page',"index.php"); } $windowtitle = "$boardname -- $forum[title]"; require 'lib/layout.php'; $hotcount = $sql->resultq('SELECT hotcount FROM misc',0,0); if ($hotcount <= 0) $hotcount = 0xFFFF; $ppp = (($_GET['ppp']) ? intval($_GET['ppp']) : (($log) ? $loguser['postsperpage'] : 20)); $ppp = max(min($ppp, 500), 1); $tpp = (($_GET['tpp']) ? intval($_GET['tpp']) : (($log) ? $loguser['threadsperpage'] : 50)); $tpp = max(min($tpp, 500), 1); $page = intval($_GET['page']); $min = $page*$tpp; $newthreadbar = $forumlist = ''; if ($id) { $forumlist = doforumlist($id); $fonline = fonlineusers($id); if($log) { $headlinks.=" - Mark forum read"; $header = makeheader($header1,$headlinks,$header2 .(($fonline) ? "$tblstart$tccell1s>$fonline$tblend" : "")); } $newthreadbar = "". (($forum['pollstyle'] != -2) ? "$newpollpic" : "") ." - $newthreadpic"; } $infotable = " $newthreadbar
$boardname - $forum[title]
"; $forumpagelinks = ''; if($threadcount > $tpp){ $query = ($id ? "id=$id" : ($user ? "user=$user" : "fav=1")); if ($_GET['tpp']) $query .= "&tpp=$tpp"; $forumpagelinks = "
Pages:"; for($k=0;$k<($threadcount/$tpp);$k++) $forumpagelinks .= ($k!=$page ? " ".($k+1).'':' '.($k+1)); $forumpagelinks .= "
"; } $threadlist = "{$tblstart}"; // Announcements if ($id) { if($annc = $sql->fetchq('SELECT announcements.id aid,user id,date,announcements.title,name,sex,powerlevel FROM announcements,users WHERE forum=0 AND user=users.id ORDER BY date DESC LIMIT 1')) { $userlink = getuserlink($annc); $threadlist .= " Announcements $tccell2>". ($loguser['lastannouncement'] < $annc['aid'] && $loguser['id'] ? $newpic : " ") ." $tccell1l colspan=6>$annc[title] -- Posted by {$userlink} on ".date($dateformat,$annc['date']+$tzoff)." "; } if($annc = $sql->fetchq("SELECT user id,date,announcements.title,name,sex,powerlevel FROM announcements,users WHERE forum=$id AND user=users.id ORDER BY date DESC LIMIT 1")) { $userlink = getuserlink($annc); $threadlist .= " $tccellhs colspan=7>Forum announcements $tccell2>  $tccell1l colspan=6>$annc[title] -- Posted by {$userlink} on ".date($dateformat,$annc['date']+$tzoff)." "; } } // Forum names else $forumnames = $sql->getresultsbykey("SELECT id,title FROM forums WHERE minpower <= ".intval($loguser['powerlevel']), 'id', 'title'); // Get threads if($fav) $threads = $sql->query("SELECT t.*, minpower,f.id as forumid, " ."u1.name AS name1, u1.sex AS sex1, u1.powerlevel AS pwr1, u1.aka as aka1, u1.birthday as bd1," ."u2.name AS name2, u2.sex AS sex2, u2.powerlevel AS pwr2, u2.aka as aka2, u2.birthday as bd2 " .($log ? ", r.read AS tread, r.time as treadtime " : " ") ."FROM threads t " .($log ? "LEFT JOIN threadsread r ON (t.id=r.tid AND r.uid=$loguserid) " : "") .",users u1,users u2,forums f,favorites fav " ."WHERE u1.id=t.user " ."AND u2.id=t.lastposter " ."AND fav.thread=t.id " ."AND fav.user={$user} " ."AND f.id=t.forum " ."ORDER BY sticky DESC,lastpostdate DESC " ."LIMIT $min,$tpp"); elseif($user) $threads = $sql->query("SELECT t.*, minpower, f.id as forumid, " ."'".addslashes($user1['name'])."' AS name1, {$user1['sex']} AS sex1, {$user1['powerlevel']} AS pwr1, '" .addslashes($user1['aka'])."' as aka1, {$user1['birthday']} as bd1, " ."name AS name2, sex AS sex2, powerlevel AS pwr2, aka as aka2, birthday as bd2" .($log ? ", r.read AS tread, r.time as treadtime " : " ") ."FROM threads t " .($log ? "LEFT JOIN threadsread r ON (t.id=r.tid AND r.uid=$loguserid) " : "") .",users u,forums f " ."WHERE t.user=$user " ."AND u.id=t.lastposter " ."AND f.id=t.forum " ."ORDER BY sticky DESC,lastpostdate DESC " ."LIMIT $min,$tpp"); else $threads = $sql->query("SELECT t.*," ."u1.name AS name1, u1.sex AS sex1, u1.powerlevel AS pwr1, u1.aka as aka1, u1.birthday as bd1," ."u2.name AS name2, u2.sex AS sex2, u2.powerlevel AS pwr2, u2.aka as aka2, u2.birthday as bd2 " .($log ? ", r.read AS tread, r.time as treadtime " : " ") ."FROM threads t " .($log ? "LEFT JOIN threadsread r ON (t.id=r.tid AND r.uid=$loguserid) " : "") .",users u1,users u2 " ."WHERE forum=$id " ."AND u1.id=t.user " ."AND u2.id=t.lastposter " ."ORDER BY sticky DESC,lastpostdate DESC " ."LIMIT $min,$tpp"); $threadlist .= " $tccellh width=30> $tccellh colspan=2 width=*> Thread $tccellh width=14%>Started by $tccellh width=60> Replies $tccellh width=60> Views $tccellh width=150> Last post "; $sticklast = 0; if (mysql_num_rows($threads) <= 0) { $threadlist .= " $tccell1 style='font-style:italic;' colspan=7>There are no threads to display. "; } else for($i=1; $thread=@$sql->fetch($threads, MYSQL_ASSOC); ++$i) { if($sticklast && !$thread['sticky']) $threadlist .= "$tccellh colspan=7>"; $sticklast = $thread['sticky']; if(!$id && $thread['minpower'] > max(0,$power)) { $threadlist .= "$tccell2s colspan=7>(restricted)"; continue; } // Disabled polls if ($forum['pollstyle'] == -2) $thread['poll'] = 0; $new = " "; $newpost = false; $threadstatus = ""; // Forum, logged in if ($log && $id && $thread['lastpostdate']>$postread[$id] && !$thread['tread']) { $threadstatus .= "new"; $newpost = true; $newpostt = ($thread['treadtime'] ? $thread['treadtime'] : $postread[$id]); } // User's thread list / Favorites, logged in elseif ($log && !$id && $thread['lastpostdate']>$postread[$thread['forumid']] && !$thread['tread']) { $threadstatus .= "new"; $newpost = true; $newpostt = ($thread['treadtime'] ? $thread['treadtime'] : $postread[$thread['forumid']]); } // Not logged in elseif (!$log && $thread['lastpostdate']>ctime()-3600) { $threadstatus .= "new"; $newpost = true; $newpostt = ctime() - 3600; } if ($thread['replies'] >= $hotcount) $threadstatus .= "hot"; if ($thread['closed']) $threadstatus .= "off"; if ($threadstatus) $new = $statusicons[$threadstatus]; $posticon=""; if (trim($thread['title']) == "") $thread['title'] = "hurr durr i'm an idiot who made a blank thread"; else $thread['title'] = str_replace(array('<', '>'), array('<', '>'), trim($thread['title'])); $threadtitle = "$thread[title]"; $belowtitle = array(); // An extra line below the title in certain circumstances $sicon = ""; if ($thread['sticky']) { $threadtitle = "". $threadtitle .""; $sicon .= "sticky"; } if ($thread['poll']) $sicon .= "poll"; if ($sicon) $threadtitle = $statusicons[$sicon] ." ". $threadtitle; // Show forum name if not in a forum if (!$id) $belowtitle[] = "In ".$forumnames[$thread['forumid']].""; // Extra pages if($thread['replies']>=$ppp) { $pagelinks=''; $maxfromstart = (($loguser['pagestyle']) ? 9 : 4); $maxfromend = (($loguser['pagestyle']) ? 20 : 10); $totalpages = ceil(($thread['replies']+1)/$ppp); for($k=0; $k < $totalpages; $k++) { if ($totalpages >= ($maxfromstart+$maxfromend+1) && $k > $maxfromstart && $k < ($totalpages - $maxfromend)) { $k = ($totalpages - $maxfromend); $pagelinks .= " ..."; } $pagelinks.=" ".($k+1).''; } if ($loguser['pagestyle']) $belowtitle[] = "Page:{$pagelinks}"; else $threadtitle .= " {$smallfont}(Pages:{$pagelinks})"; } if (!empty($belowtitle)) $secondline = '
   ' . implode(' - ', $belowtitle) . ''; else $secondline = ''; if(!$thread['icon']) $posticon=' '; $userlink1 = getuserlink($thread, array('sex'=>'sex1', 'powerlevel'=>'pwr1', 'id'=>'user', 'aka'=>'aka1', 'name'=>'name1', 'birthday'=>'bd1')); $userlink2 = getuserlink($thread, array('sex'=>'sex2', 'powerlevel'=>'pwr2', 'id'=>'lastposter', 'aka'=>'aka2', 'name'=>'name2', 'birthday'=>'bd2')); $threadlist .= " $tccell1>$new $tccell2 width=40px>
$posticon
$tccell2l>". ($newpost ? "". $statusicons['getnew'] ." " : "") ."$threadtitle$secondline $tccell2>{$userlink1} $tccell1>$thread[replies] $tccell1>$thread[views] $tccell2>
".date($dateformat,$thread['lastpostdate']+$tzoff)."
by {$userlink2} $statusicons[getlast]
"; } $threadlist .= "{$tblend}"; print " {$header} {$infotable} {$forumpagelinks} {$threadlist} {$forumpagelinks} {$infotable} {$forumlist} {$footer} "; printtimedif($startingtime); function notAuthorizedError() { global $log; $rreason = (($log) ? 'don\'t have access to it' : 'are not logged in'); $redir = (($log) ? 'index.php' : 'login.php'); $rtext = (($log) ? 'the index page' : 'log in (then try again)'); errorpage("Couldn't enter this restricted forum, as you {$rreason}.", $rtext, $redir); }