/** * Fetches 10 threads from the desired page. * @return bool threads_exist */ public function fetchThreads() { if ($this->page_num == 1) { $select = $this->pdo->select()->from('posts_' . $this->board)->whereNull('thread')->orderBy('bumped_at', 'DESC')->limit(10); } try { $stmt = $select->execute(); $threads = $stmt->fetchAll(); if ($threads) { $threads_exist = true; foreach ($threads as $thread) { $thread = new \MIBS\Thread($this->app, $this->pdo, $this->board, $thread['id']); if ($thread->getOriginalPost()) { $data = $thread->getResponses(true)->getThreadArray(); $this->pThreads[] = $data; } else { $threads_exist = false; } } } else { $threads_exist = false; } } catch (\Exception $e) { $this->app->error($e); } return $threads_exist; }
$twig = new Twig_Environment($loader, ['cache' => false]); # ROUTES ## Admin Routes ## Frontend Routes /** * The user wants to go to a specific thread. * @format www.example.com/boards/vg/thread/1 */ $app->get('/boards/:board/thread/:threadId', function ($board, $threadId) use($app, $pdo, $twig) { $boardHandler = new \MIBS\Board($pdo, $board); $board_exists = $boardHandler->fetchBoardData(); $board_data = $boardHandler->getBoardInfo(); if ($board_exists) { $thread = new \MIBS\Thread($app, $pdo, $board, $threadId); if ($thread->getOriginalPost()) { $data = $thread->getResponses()->getThreadArray(); echo $twig->render('thread.html', ['board_info' => $board_data, 'thread_id' => $threadId, 'thread_data' => $data]); } else { $app->notFound(); } } else { $app->notFound(); } }); /** * The user messed with the url, requested no Thread. * Let's 404. */ $app->get('/boards/:board/thread', function ($board) use($app) { $app->notFound(); });