Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once '../lib/libGlobalVars.php';
- include_once '../lib/libSQL.php';
- include_once '../lib/libFormat.php';
- $gcon = gdb_connect();
- if(isset($_GET['thread'])) {
- $threadid = mysqli_real_escape_string($gcon, $_GET['thread']);
- $query = mysqli_query($gcon, "SELECT * FROM f_Threads WHERE id='" . $threadid . "'");
- $view = mysqli_fetch_array($query);
- if($view !== null) {
- $title = '#PetPonies Forums - ' . $view['title'];
- }
- else {
- $title = '#PetPonies Forums - 404';
- }
- }
- else {
- $boardid = '1';
- if(isset($_GET['board'])) {
- $boardid = mysqli_real_escape_string($gcon, $_GET['board']);
- }
- $query = mysqli_query($gcon, "SELECT * FROM f_Boards WHERE id='" . $boardid . "'");
- $view = mysqli_fetch_array($query);
- if($view !== null) {
- if(!checkPermSet($view['perm_view'])) {
- die('<meta http-equiv="refresh" content="0; url=/forum/">');
- }
- if($boardid !== '1') {
- $title = '#PetPonies Forums - ' . $view['title'];
- }
- else {
- $title = '#PetPonies Forums';
- }
- }
- else {
- $title = '#PetPonies Forum - 404';
- }
- }
- if (session_status() == PHP_SESSION_NONE) { session_start(); }
- mysqli_close($gcon);
- include_once '../lib/libOpen.php';
- ?>
- <div id="content" class="section">
- <?php echo makeForumTree($view); ?>
- <br />
- <div class="contentTitle"><?php echo $view['title']; ?></div>
- <?php
- include_once '../lib/libPaging.php';
- if(isset($_GET['thread'])) {
- if($view !== null) {
- if(isset($_SESSION['account']) and $_SESSION['acctype'] !== 'new') {
- echo '<form action="post.php" method="post" enctype="multipart/form-data">
- <input type="hidden" name="threadid" value="' . $threadid . '">
- <div style="width: 25%"><input type="submit" class="titleBtn" value="New Post"></div>
- </form>';
- }
- $qpost = mysqli_query($gcon, "SELECT * FROM f_Posts WHERE parentid='" . $threadid . "' ORDER BY id ASC");
- $posts = array();
- while($x = mysqli_fetch_array($qpost)) {
- $posts[$x['id']] = $x;
- }
- $posts_sort = array();
- foreach($posts as $y) {
- array_push($posts_sort, $y);
- }
- if(count($posts_sort) > 10) {
- echo makePageSwitcher($posts_sort);
- }
- $post_page = pagify($posts_sort);
- echo formatPost($post_page[0], array_slice($post_page, 1));
- for($i = 1; $i < count($post_page) - 1; $i++) {
- if($post_page[$i]['authorid'] == $post_page[$i - 1]['authorid']) {
- $i++;
- continue;
- }
- echo formatPost($post_page[$i], array_slice($post_page, $i + 1));
- }
- if(count($post_page) > 1) {
- echo formatPost($post_page[count($post_page) - 1]);
- }
- if(count($posts_sort) > 10) {
- echo makePageSwitcher($posts_sort);
- }
- if(isset($_SESSION['account']) and $_SESSION['acctype'] !== 'new') {
- echo '<form action="post.php" method="post" enctype="multipart/form-data">
- <input type="hidden" name="threadid" value="' . $threadid . '">
- <div style="width: 25%"><input type="submit" class="titleBtn" value="New Post"></div>
- </form>';
- }
- else {
- echo '<p>A petponies.com account is required to post. You can register <a href="/usr/register.php">here</a>.</p>';
- }
- }
- else {
- echo '<div class="subTitle">Error 404</div>
- <p>404 - Thread not found. Try to be less terrible at links from now on.</p>';
- }
- }
- else {
- if($view !== null) {
- if($view['type'] == 'normal') {
- $qchildren = mysqli_query($gcon, "SELECT * FROM f_Threads AS t JOIN f_Posts as p ON p.id = t.lastid WHERE t.parentid='" . $boardid . "' ORDER BY p.date_posted DESC");
- echo '<div class="subTitle">Threads</div>';
- $threads = array();
- while($x = mysqli_fetch_array($qchildren)) {
- array_push($threads, $x);
- }
- if(checkPermSet($view['perm_post'])) {
- echo '<form action="/forum/post.php" method="post" enctype="multipart/form-data">
- <input type="hidden" name="boardid" value="' . $boardid . '">
- <div style="width: 25%"><input type="submit" class="titleBtn" value="New Post"></div>
- </form>';
- }
- if(count($threads) > 20) {
- echo makePageSwitcher($threads);
- }
- $thread_page = pagify($threads, 20);
- if(count($threads) == 0) {
- echo '<p>It's so empty in here. I'm scared. Hold me.</p>';
- }
- foreach($thread_page as $cthread) {
- $qlp = mysqli_query($gcon, "SELECT * FROM f_Posts WHERE id='" . $cthread['lastid'] . "'");
- $qop = mysqli_query($gcon, "SELECT * FROM f_Posts WHERE id='" . $cthread['opid'] . "'");
- $qnp = mysqli_query($gcon, "SELECT * FROM f_Posts WHERE parentid='" . $cthread[0] . "'");
- $lp = mysqli_fetch_array($qlp);
- $op = mysqli_fetch_array($qop);
- $qlu = mysqli_query($gcon, "SELECT * FROM Accounts WHERE id='" . $lp['authorid'] . "'");
- $lu = mysqli_fetch_array($qlu);
- $qou = mysqli_query($gcon, "SELECT * FROM Accounts WHERE id='" . $op['authorid'] . "'");
- $ou = mysqli_fetch_array($qou);
- echo '<div class="f_board"><div><a href="/forum?thread=' . $cthread[0] . '">' . $cthread['title'] . '</a>';
- echo '<br />' . stripBBCode($op['text']) . '</div>' . PHP_EOL;
- echo '<div class=f_boardinfo>
- <table>
- <tr>
- <th>Replies</th>
- <th>Started By</th>
- <th>Last Poster</th>
- <th>Last Post</th>
- </tr>
- <tr>
- <td>' . (mysqli_num_rows($qnp) - 1) . '</td>
- <td>' . $ou['name'] . '</td>
- <td>' . $lu['name'] . '</td>
- <td>' . convertLocalTime($lp['date_posted'], $_SESSION['timezone'], true) . '</td>
- </tr>
- </table>
- </div></div>' . PHP_EOL;
- }
- if(count($threads) > 20)
- echo makePageSwitcher($threads);
- if(checkPermSet($view['perm_post'])) {
- echo '<form action="/forum/post.php" method="post" enctype="multipart/form-data">
- <input type="hidden" name="boardid" value="' . $boardid . '">
- <div style="width: 25%"><input type="submit" class="titleBtn" value="New Post"></div>
- </form>';
- }
- }
- else {
- $qchildren = mysqli_query($gcon, "SELECT * FROM f_Boards WHERE parentid='" . $boardid . "'");
- while($cboard = mysqli_fetch_array($qchildren)) {
- if(!checkPermSet($cboard['perm_view'])) {
- continue;
- }
- if($cboard['type'] == 'category') {
- echo '<div class="f_category"><a href="/forum?board=' . $cboard['id'] . '">' . $cboard['title'] . '</a></div>' . PHP_EOL;
- $qsc = mysqli_query($gcon, "SELECT * FROM f_Boards WHERE parentid='" . $cboard['id'] . "'");
- while($csboard = mysqli_fetch_array($qsc)) {
- if(!checkPermSet($csboard['perm_view'])) {
- continue;
- }
- $qnt = mysqli_query($gcon, "SELECT * FROM f_Threads WHERE parentid='" . $csboard['id'] . "'");
- $qlp = mysqli_query($gcon, "SELECT * FROM f_Threads AS t JOIN f_Posts AS p ON t.id=p.parentid WHERE t.parentid='" . $csboard['id'] . "' ORDER BY p.id DESC LIMIT 1");
- $slp = 'Unknown';
- $slu = 'Unknown';
- $lp = mysqli_fetch_array($qlp);
- if($lp !== null) {
- $slp = convertLocalTime($lp['date_posted'], $_SESSION['timezone'], true);
- $qlu = mysqli_query($gcon, "SELECT * FROM Accounts WHERE id='" . $lp['authorid'] . "'");
- $lu = mysqli_fetch_array($qlu);
- if($lu !== null) {
- $slu = $lu['name'];
- }
- }
- echo '<div class="f_board"><div><a href="/forum?board=' . $csboard['id'] . '">' . $csboard['title'] . '</a>';
- echo '<br />' . $csboard['description'] . '</div>' . PHP_EOL;
- echo '<div class=f_boardinfo>
- <table>
- <tr>
- <th>Threads</th>
- <th>Last Poster</th>
- <th>Last Post</th>
- </tr>
- <tr>
- <td>' . mysqli_num_rows($qnt) . '</td>
- <td>' . $slu . '</td>
- <td>' . $slp . '</td>
- </tr>
- </table>
- </div></div>' . PHP_EOL;
- }
- }
- else {
- $qnt = mysqli_query($gcon, "SELECT * FROM f_Threads WHERE parentid='" . $cboard['id'] . "'");
- $qlp = mysqli_query($gcon, "SELECT * FROM f_Threads AS t JOIN f_Posts AS p ON t.id=p.parentid WHERE t.parentid='" . $cboard['id'] . "' ORDER BY p.id DESC LIMIT 1");
- $slp = 'Unknown';
- $slu = 'Unknown';
- $lp = mysqli_fetch_array($qlp);
- if($lp !== null) {
- $slp = convertLocalTime($lp['date_posted'], $_SESSION['timezone'], true);
- $qlu = mysqli_query($gcon, "SELECT * FROM Accounts WHERE id='" . $lp['authorid'] . "'");
- $lu = mysqli_fetch_array($qlu);
- if($lu !== null) {
- $slu = $lu['name'];
- }
- }
- echo '<div class="f_board"><div><a href="/forum?board=' . $cboard['id'] . '">' . $cboard['title'] . '</a>';
- echo '<br />' . $cboard['description'] . '</div>' . PHP_EOL;
- echo '<div class=f_boardinfo>
- <table>
- <tr>
- <th>Threads</th>
- <th>Last Poster</th>
- <th>Last Post</th>
- </tr>
- <tr>
- <td>' . mysqli_num_rows($qnt) . '</td>
- <td>' . $slu . '</td>
- <td>' . $slp . '</td>
- </tr>
- </table>
- </div></div>' . PHP_EOL;
- }
- }
- }
- }
- else {
- echo '<div class="subTitle">Error 404</div>
- <p>404 - Board not found. Try to be less terrible at links from now on.</p>';
- }
- }
- ?>
- </div>
- <?php
- include_once '../lib/libClose.php';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement