Advertisement
sindeus

forum/index

Oct 2nd, 2015
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.52 KB | None | 0 0
  1. <?php
  2.     include_once '../lib/libGlobalVars.php';
  3.     include_once '../lib/libSQL.php';
  4.     include_once '../lib/libFormat.php';
  5.     $gcon = gdb_connect();
  6.     if(isset($_GET['thread'])) {
  7.         $threadid = mysqli_real_escape_string($gcon, $_GET['thread']);
  8.         $query = mysqli_query($gcon, "SELECT * FROM f_Threads WHERE id='" . $threadid . "'");
  9.         $view = mysqli_fetch_array($query);
  10.         if($view !== null) {
  11.             $title = '#PetPonies Forums - ' . $view['title'];
  12.         }
  13.         else {
  14.             $title = '#PetPonies Forums - 404';
  15.         }
  16.     }
  17.     else {
  18.         $boardid = '1';
  19.         if(isset($_GET['board'])) {
  20.             $boardid = mysqli_real_escape_string($gcon, $_GET['board']);
  21.         }
  22.         $query = mysqli_query($gcon, "SELECT * FROM f_Boards WHERE id='" . $boardid . "'");
  23.         $view = mysqli_fetch_array($query);
  24.         if($view !== null) {
  25.             if(!checkPermSet($view['perm_view'])) {
  26.                 die('<meta http-equiv="refresh" content="0; url=/forum/">');
  27.             }
  28.             if($boardid !== '1') {
  29.                 $title = '#PetPonies Forums - ' . $view['title'];
  30.             }
  31.             else {
  32.                 $title = '#PetPonies Forums';
  33.             }
  34.         }
  35.         else {
  36.             $title = '#PetPonies Forum - 404';
  37.         }  
  38.     }
  39.     if (session_status() == PHP_SESSION_NONE) { session_start(); }
  40.     mysqli_close($gcon);
  41.     include_once '../lib/libOpen.php';
  42. ?>
  43. <div id="content" class="section">
  44.     <?php echo makeForumTree($view); ?>
  45.     <br />
  46.     <div class="contentTitle"><?php echo $view['title']; ?></div>
  47.     <?php
  48.         include_once '../lib/libPaging.php';
  49.         if(isset($_GET['thread'])) {
  50.             if($view !== null) {
  51.                 if(isset($_SESSION['account']) and $_SESSION['acctype'] !== 'new') {
  52.                     echo '<form action="post.php" method="post" enctype="multipart/form-data">
  53.                            <input type="hidden" name="threadid" value="' . $threadid . '">
  54.                            <div style="width: 25%"><input type="submit" class="titleBtn" value="New Post"></div>
  55.                          </form>';
  56.                 }
  57.                 $qpost = mysqli_query($gcon, "SELECT * FROM f_Posts WHERE parentid='" . $threadid . "' ORDER BY id ASC");
  58.                 $posts = array();
  59.                 while($x = mysqli_fetch_array($qpost)) {
  60.                     $posts[$x['id']] = $x;
  61.                 }
  62.                 $posts_sort = array();
  63.                 foreach($posts as $y) {
  64.                     array_push($posts_sort, $y);
  65.                 }
  66.                 if(count($posts_sort) > 10) {
  67.                     echo makePageSwitcher($posts_sort);
  68.                 }
  69.                 $post_page = pagify($posts_sort);
  70.                 echo formatPost($post_page[0], array_slice($post_page, 1));
  71.                 for($i = 1; $i < count($post_page) - 1; $i++) {
  72.                     if($post_page[$i]['authorid'] == $post_page[$i - 1]['authorid']) {
  73.                         $i++;
  74.                         continue;
  75.                     }
  76.                     echo formatPost($post_page[$i], array_slice($post_page, $i + 1));
  77.                 }
  78.                 if(count($post_page) > 1) {
  79.                     echo formatPost($post_page[count($post_page) - 1]);
  80.                 }
  81.                 if(count($posts_sort) > 10) {
  82.                     echo makePageSwitcher($posts_sort);
  83.                 }
  84.                 if(isset($_SESSION['account']) and $_SESSION['acctype'] !== 'new') {
  85.                     echo '<form action="post.php" method="post" enctype="multipart/form-data">
  86.                            <input type="hidden" name="threadid" value="' . $threadid . '">
  87.                            <div style="width: 25%"><input type="submit" class="titleBtn" value="New Post"></div>
  88.                          </form>';
  89.                 }
  90.                 else {
  91.                     echo '<p>A petponies.com account is required to post.  You can register <a href="/usr/register.php">here</a>.</p>';
  92.                 }
  93.             }
  94.             else {
  95.                 echo '<div class="subTitle">Error 404</div>
  96.                    <p>404 - Thread not found.  Try to be less terrible at links from now on.</p>';
  97.             }
  98.         }
  99.         else {
  100.             if($view !== null) {
  101.                 if($view['type'] == 'normal') {
  102.                     $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");
  103.                     echo '<div class="subTitle">Threads</div>';
  104.                     $threads = array();
  105.                     while($x = mysqli_fetch_array($qchildren)) {
  106.                         array_push($threads, $x);
  107.                     }
  108.                     if(checkPermSet($view['perm_post'])) {
  109.                         echo '<form action="/forum/post.php" method="post" enctype="multipart/form-data">
  110.                                <input type="hidden" name="boardid" value="' . $boardid . '">
  111.                                <div style="width: 25%"><input type="submit" class="titleBtn" value="New Post"></div>
  112.                              </form>';
  113.                     }
  114.                     if(count($threads) > 20) {
  115.                         echo makePageSwitcher($threads);
  116.                     }
  117.                     $thread_page = pagify($threads, 20);
  118.                     if(count($threads) == 0) {
  119.                         echo '<p>It&apos;s so empty in here. I&apos;m scared.  Hold me.</p>';
  120.                     }
  121.                     foreach($thread_page as $cthread) {
  122.                         $qlp = mysqli_query($gcon, "SELECT * FROM f_Posts WHERE id='" . $cthread['lastid'] . "'");
  123.                         $qop = mysqli_query($gcon, "SELECT * FROM f_Posts WHERE id='" . $cthread['opid'] . "'");
  124.                         $qnp = mysqli_query($gcon, "SELECT * FROM f_Posts WHERE parentid='" . $cthread[0] . "'");
  125.                         $lp = mysqli_fetch_array($qlp);
  126.                         $op = mysqli_fetch_array($qop);
  127.                         $qlu = mysqli_query($gcon, "SELECT * FROM Accounts WHERE id='" . $lp['authorid'] . "'");
  128.                         $lu = mysqli_fetch_array($qlu);
  129.                         $qou = mysqli_query($gcon, "SELECT * FROM Accounts WHERE id='" . $op['authorid'] . "'");
  130.                         $ou = mysqli_fetch_array($qou);
  131.                         echo '<div class="f_board"><div><a href="/forum?thread=' . $cthread[0] . '">' . $cthread['title'] . '</a>';
  132.                         echo '<br />' . stripBBCode($op['text']) . '</div>' . PHP_EOL;
  133.                         echo '<div class=f_boardinfo>
  134.                                <table>
  135.                                    <tr>
  136.                                        <th>Replies</th>
  137.                                        <th>Started By</th>
  138.                                        <th>Last Poster</th>
  139.                                        <th>Last Post</th>
  140.                                    </tr>
  141.                                    <tr>
  142.                                        <td>' . (mysqli_num_rows($qnp) - 1) . '</td>
  143.                                        <td>' . $ou['name'] . '</td>
  144.                                        <td>' . $lu['name'] . '</td>
  145.                                        <td>' . convertLocalTime($lp['date_posted'], $_SESSION['timezone'], true) . '</td>
  146.                                    </tr>
  147.                                </table>
  148.                              </div></div>' . PHP_EOL;
  149.                     }
  150.                     if(count($threads) > 20)
  151.                         echo makePageSwitcher($threads);
  152.                     if(checkPermSet($view['perm_post'])) {
  153.                         echo '<form action="/forum/post.php" method="post" enctype="multipart/form-data">
  154.                                <input type="hidden" name="boardid" value="' . $boardid . '">
  155.                                <div style="width: 25%"><input type="submit" class="titleBtn" value="New Post"></div>
  156.                              </form>';
  157.                     }
  158.                 }
  159.                 else {
  160.                     $qchildren = mysqli_query($gcon, "SELECT * FROM f_Boards WHERE parentid='" . $boardid . "'");
  161.                     while($cboard = mysqli_fetch_array($qchildren)) {
  162.                         if(!checkPermSet($cboard['perm_view'])) {
  163.                             continue;
  164.                         }
  165.                         if($cboard['type'] == 'category') {
  166.                             echo '<div class="f_category"><a href="/forum?board=' . $cboard['id'] . '">' . $cboard['title'] . '</a></div>' . PHP_EOL;
  167.                             $qsc = mysqli_query($gcon, "SELECT * FROM f_Boards WHERE parentid='" . $cboard['id'] . "'");
  168.                             while($csboard = mysqli_fetch_array($qsc)) {
  169.                                 if(!checkPermSet($csboard['perm_view'])) {
  170.                                     continue;
  171.                                 }
  172.                                 $qnt = mysqli_query($gcon, "SELECT * FROM f_Threads WHERE parentid='" . $csboard['id'] . "'");
  173.                                 $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");
  174.                                 $slp = 'Unknown';
  175.                                 $slu = 'Unknown';
  176.                                 $lp = mysqli_fetch_array($qlp);
  177.                                 if($lp !== null) {
  178.                                     $slp = convertLocalTime($lp['date_posted'], $_SESSION['timezone'], true);
  179.                                     $qlu = mysqli_query($gcon, "SELECT * FROM Accounts WHERE id='" . $lp['authorid'] . "'");
  180.                                     $lu = mysqli_fetch_array($qlu);
  181.                                     if($lu !== null) {
  182.                                         $slu = $lu['name'];
  183.                                     }
  184.                                 }
  185.                                 echo '<div class="f_board"><div><a href="/forum?board=' . $csboard['id'] . '">' . $csboard['title'] . '</a>';
  186.                                 echo '<br />' . $csboard['description'] . '</div>' . PHP_EOL;
  187.                                 echo '<div class=f_boardinfo>
  188.                                        <table>
  189.                                            <tr>
  190.                                                <th>Threads</th>
  191.                                                <th>Last Poster</th>
  192.                                                <th>Last Post</th>
  193.                                            </tr>
  194.                                            <tr>
  195.                                                <td>' . mysqli_num_rows($qnt) . '</td>
  196.                                                <td>' . $slu . '</td>
  197.                                                <td>' . $slp . '</td>
  198.                                            </tr>
  199.                                        </table>
  200.                                      </div></div>' . PHP_EOL;
  201.                             }
  202.                         }
  203.                         else {
  204.                             $qnt = mysqli_query($gcon, "SELECT * FROM f_Threads WHERE parentid='" . $cboard['id'] . "'");
  205.                             $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");
  206.                             $slp = 'Unknown';
  207.                             $slu = 'Unknown';
  208.                             $lp = mysqli_fetch_array($qlp);
  209.                             if($lp !== null) {
  210.                                 $slp = convertLocalTime($lp['date_posted'], $_SESSION['timezone'], true);
  211.                                 $qlu = mysqli_query($gcon, "SELECT * FROM Accounts WHERE id='" . $lp['authorid'] . "'");
  212.                                 $lu = mysqli_fetch_array($qlu);
  213.                                 if($lu !== null) {
  214.                                     $slu = $lu['name'];
  215.                                 }
  216.                             }
  217.                             echo '<div class="f_board"><div><a href="/forum?board=' . $cboard['id'] . '">' . $cboard['title'] . '</a>';
  218.                             echo '<br />' . $cboard['description'] . '</div>' . PHP_EOL;
  219.                             echo '<div class=f_boardinfo>
  220.                                    <table>
  221.                                        <tr>
  222.                                            <th>Threads</th>
  223.                                            <th>Last Poster</th>
  224.                                            <th>Last Post</th>
  225.                                        </tr>
  226.                                        <tr>
  227.                                            <td>' . mysqli_num_rows($qnt) . '</td>
  228.                                            <td>' . $slu . '</td>
  229.                                            <td>' . $slp . '</td>
  230.                                        </tr>
  231.                                    </table>
  232.                                  </div></div>' . PHP_EOL;
  233.                         }
  234.                     }
  235.                 }
  236.             }
  237.             else {
  238.                 echo '<div class="subTitle">Error 404</div>
  239.                    <p>404 - Board not found.  Try to be less terrible at links from now on.</p>';
  240.             }
  241.         }
  242.     ?>
  243. </div>
  244. <?php
  245.     include_once '../lib/libClose.php';
  246. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement