123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- namespace ForkBB\Models\Pages;
- use ForkBB\Models\Page;
- class Topic extends Page
- {
- use CrumbTrait;
- use PostFormTrait;
- /**
- * Переход к первому новому сообщению темы (или в конец)
- *
- * @param array $args
- *
- * @return Page
- */
- public function viewNew(array $args)
- {
- return $this->view('new', $args);
- }
- /**
- * Переход к первому непрочитанному сообщению (или в конец)
- *
- * @param array $args
- *
- * @return Page
- */
- public function viewUnread(array $args)
- {
- return $this->view('unread', $args);
- }
- /**
- * Переход к последнему сообщению темы
- *
- * @param array $args
- *
- * @return Page
- */
- public function viewLast(array $args)
- {
- return $this->view('last', $args);
- }
- /**
- * Просмотр темы по номеру сообщения
- *
- * @param array $args
- *
- * @return Page
- */
- public function viewPost(array $args)
- {
- return $this->view('post', $args);
- }
- /**
- * Просмотр темы по ее номеру
- *
- * @param array $args
- *
- * @return Page
- */
- public function viewTopic(array $args)
- {
- return $this->view('topic', $args);
- }
- /**
- * @param string $type
- * @param Models\Topic $topic
- *
- * @param Page
- */
- protected function go($type, $topic)
- {
- switch ($type) {
- case 'new':
- $pid = $topic->firstNew;
- break;
- case 'unread':
- $pid = $topic->firstUnread;
- break;
- case 'last':
- $pid = $topic->last_post_id;
- break;
- default:
- return $this->c->Message->message('Bad request');
- }
- return $this->c->Redirect->page('ViewPost', ['id' => $pid ?: $topic->last_post_id]);
- }
- /**
- * Подготовка данных для шаблона
- *
- * @param string $type
- * @param array $args
- *
- * @return Page
- */
- protected function view($type, array $args)
- {
- $topic = $this->c->ModelTopic->load((int) $args['id'], $type === 'post');
- if (empty($topic) || ! $topic->last_post_id) {
- return $this->c->Message->message('Bad request');
- }
- if ($topic->moved_to) {
- return $this->c->Redirect->page('Topic', ['id' => $topic->moved_to]);
- }
- switch ($type) {
- case 'topic':
- $topic->page = isset($args['page']) ? (int) $args['page'] : 1;
- break;
- case 'post':
- $topic->calcPage((int) $args['id']);
- break;
- default:
- return $this->go($type, $topic);
- }
- if (! $topic->hasPage()) {
- return $this->c->Message->message('Bad request');
- }
- if (! $posts = $topic->posts()) {
- return $this->go('last', $topic);
- }
- $this->c->Lang->load('topic');
- $this->nameTpl = 'topic';
- $this->onlinePos = 'topic-' . $topic->id;
- $this->onlineDetail = true;
- $this->canonical = $this->c->Router->link('Topic', ['id' => $topic->id, 'name' => $topic->cens()->subject, 'page' => $topic->page]);
- $this->topic = $topic;
- $this->posts = $posts;
- $this->crumbs = $this->crumbs($topic);
- $this->online = $this->c->Online->calc($this)->info();
- $this->stats = null;
- $this->form = $topic->canReply && $this->c->config->o_quickpost == '1'
- ? $this->messageForm($topic, 'NewReply', ['id' => $topic->id], false, true)
- : null;
- if ($topic->showViews) {
- $topic->incViews();
- }
- $topic->updateVisits();
- return $this;
- }
- }
|