public function radix_post($num = 0) { try { if ($this->getPost('post') || !Board::isValidPostNumber($num)) { // obtain post number and unset search string preg_match('/(?:^|\\/)(\\d+)(?:[_,]([0-9]*))?/', $this->getPost('post') ?: $num, $post); unset($post[0]); return new RedirectResponse($this->uri->create([$this->radix->shortname, 'post', implode('_', $post)])); } $board = Board::forge($this->getContext())->getPost()->setRadix($this->radix)->setOptions('num', $num); $comments = $board->getComments(); // it always returns an array $comment = current($comments); $redirect = $this->uri->create($this->radix->shortname . '/thread/' . $comment->comment->thread_num . '/'); if (!$comment->comment->op) { $redirect .= '#' . $comment->comment->num . ($comment->comment->subnum ? '_' . $comment->comment->subnum : ''); } $this->builder->createLayout('redirect')->getParamManager()->setParam('url', $redirect); $this->builder->getProps()->addTitle(_i('Redirecting')); } catch (\Foolz\Foolfuuka\Model\BoardMalformedInputException $e) { return $this->error(_i('The post number you submitted is invalid.')); } catch (\Foolz\Foolfuuka\Model\BoardPostNotFoundException $e) { return $this->error(_i('The post you are looking for does not exist.')); } return $this->response->setContent($this->builder->build()); }
public function get_post() { if (!$this->check_board()) { return $this->response->setData(['error' => _i('No board was selected.')])->setStatusCode(422); } $num = $this->getQuery('num'); if (!$num) { return $this->response->setData(['error' => _i('The "num" parameter is missing.')])->setStatusCode(422); } if (!Board::isValidPostNumber($num)) { return $this->response->setData(['error' => _i('The value for "num" is invalid.')])->setStatusCode(422); } try { $board = Board::forge($this->getContext())->getPost($num)->setRadix($this->radix); $comment = current($board->getComments()); $this->apify($comment); $last_modified = $comment->comment->timestamp_expired ?: $comment->comment->timestamp; $this->setLastModified($last_modified); if (!$this->response->isNotModified($this->request)) { $this->response->setData($comment); } } catch (\Foolz\Foolfuuka\Model\BoardPostNotFoundException $e) { return $this->response->setData(['error' => _i('Post not found.')]); } catch (\Foolz\Foolfuuka\Model\BoardException $e) { return $this->response->setData(['error' => $e->getMessage()])->setStatusCode(500); } return $this->response; }