/** * Prepare topic display. * * @return void * * @throws KunenaExceptionAuthorise */ protected function before() { parent::before(); $catid = $this->input->getInt('catid', 0); $id = $this->input->getInt('id', 0); $mesid = $this->input->getInt('mesid', 0); $start = $this->input->getInt('limitstart', 0); $limit = $this->input->getInt('limit', 0); if ($limit < 1 || $limit > 100) { $limit = $this->config->messages_per_page; } $this->me = KunenaUserHelper::getMyself(); // Load topic and message. if ($mesid) { // If message was set, use it to find the current topic. $this->message = KunenaForumMessageHelper::get($mesid); $this->topic = $this->message->getTopic(); } else { // Note that redirect loops throw RuntimeException because of we added KunenaForumTopic::getTopic() call! $this->topic = KunenaForumTopicHelper::get($id)->getTopic(); $this->message = KunenaForumMessageHelper::get($this->topic->first_post_id); } // Load also category (prefer the URI variable if available). if ($catid && $catid != $this->topic->category_id) { $this->category = KunenaForumCategoryHelper::get($catid); $this->category->tryAuthorise(); } else { $this->category = $this->topic->getCategory(); } // Access check. $this->message->tryAuthorise(); // Check if we need to redirect (category or topic mismatch, or resolve permanent URL). if ($this->primary) { $channels = $this->category->getChannels(); if ($this->message->thread != $this->topic->id || $this->topic->category_id != $this->category->id && !isset($channels[$this->topic->category_id]) || $mesid && $this->layout != 'threaded') { while (@ob_end_clean()) { } $this->app->redirect($this->message->getUrl(null, false)); } } // Load messages from the current page and set the pagination. $hold = KunenaAccess::getInstance()->getAllowedHold($this->me, $this->category->id, false); $finder = new KunenaForumMessageFinder(); $finder->where('thread', '=', $this->topic->id)->filterByHold($hold); $start = $mesid ? $this->topic->getPostLocation($mesid) : $start; $this->pagination = new KunenaPagination($finder->count(), $start, $limit); $this->messages = $finder->order('time', $this->me->getMessageOrdering() == 'asc' ? 1 : -1)->start($this->pagination->limitstart)->limit($this->pagination->limit)->find(); $this->prepareMessages($mesid); // Run events. $params = new JRegistry(); $params->set('ksource', 'kunena'); $params->set('kunena_view', 'topic'); $params->set('kunena_layout', 'default'); $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('kunena'); $dispatcher->trigger('onKunenaPrepare', array('kunena.topic', &$this->topic, &$params, 0)); $dispatcher->trigger('onKunenaPrepare', array('kunena.messages', &$this->messages, &$params, 0)); // Get user data, captcha & quick reply. $this->userTopic = $this->topic->getUserTopic(); $this->quickReply = $this->topic->isAuthorised('reply') && $this->me->exists(); $this->headerText = JText::_('COM_KUNENA_TOPIC') . ' ' . html_entity_decode($this->topic->displayField('subject')); }