/** * Prepare topic actions display. * * @return void */ protected function before() { parent::before(); $id = $this->input->getInt('id'); $this->topic = KunenaForumTopic::getInstance($id); $catid = $this->topic->category_id; $token = JSession::getFormToken(); $task = "index.php?option=com_kunena&view=topic&task=%s&catid={$catid}&id={$id}&{$token}=1"; $layout = "index.php?option=com_kunena&view=topic&layout=%s&catid={$catid}&id={$id}"; $userTopic = $this->topic->getUserTopic(); $this->template = KunenaFactory::getTemplate(); $this->topicButtons = new JObject(); if ($this->topic->isAuthorised('reply')) { // Add Reply topic button. $this->topicButtons->set('reply', $this->getButton(sprintf($layout, 'reply'), 'reply', 'topic', 'communication')); } if ($userTopic->subscribed) { // User can always remove existing subscription. $this->topicButtons->set('subscribe', $this->getButton(sprintf($task, 'unsubscribe'), 'unsubscribe', 'topic', 'user')); } elseif ($this->topic->isAuthorised('subscribe')) { // Add subscribe topic button. $this->topicButtons->set('subscribe', $this->getButton(sprintf($task, 'subscribe'), 'subscribe', 'topic', 'user')); } if ($userTopic->favorite) { // User can always remove existing favorite. $this->topicButtons->set('favorite', $this->getButton(sprintf($task, 'unfavorite'), 'unfavorite', 'topic', 'user')); } elseif ($this->topic->isAuthorised('favorite')) { // Add favorite topic button. $this->topicButtons->set('favorite', $this->getButton(sprintf($task, 'favorite'), 'favorite', 'topic', 'user')); } if ($this->topic->getCategory()->isAuthorised('moderate')) { // Add moderator specific buttons. $sticky = $this->topic->ordering ? 'unsticky' : 'sticky'; $lock = $this->topic->locked ? 'unlock' : 'lock'; $this->topicButtons->set('sticky', $this->getButton(sprintf($task, $sticky), $sticky, 'topic', 'moderation')); $this->topicButtons->set('lock', $this->getButton(sprintf($task, $lock), $lock, 'topic', 'moderation')); $this->topicButtons->set('moderate', $this->getButton(sprintf($layout, 'moderate'), 'moderate', 'topic', 'moderation')); if ($this->topic->hold == 1) { $this->topicButtons->set('approve', $this->getButton(sprintf($task, 'approve'), 'moderate', 'topic', 'moderation')); } if ($this->topic->hold == 1 || $this->topic->hold == 0) { $this->topicButtons->set('delete', $this->getButton(sprintf($task, 'delete'), 'delete', 'topic', 'moderation')); } elseif ($this->topic->hold == 2 || $this->topic->hold == 3) { $this->topicButtons->set('undelete', $this->getButton(sprintf($task, 'undelete'), 'undelete', 'topic', 'moderation')); } } // Add buttons for changing between different layout modes. if (KunenaFactory::getConfig()->enable_threaded_layouts) { $url = "index.php?option=com_kunena&view=user&task=change&topic_layout=%s&{$token}=1"; if ($this->layout != 'default') { $this->topicButtons->set('flat', $this->getButton(sprintf($url, 'flat'), 'flat', 'layout', 'user')); } if ($this->layout != 'threaded') { $this->topicButtons->set('threaded', $this->getButton(sprintf($url, 'threaded'), 'threaded', 'layout', 'user')); } if ($this->layout != 'indented') { $this->topicButtons->set('indented', $this->getButton(sprintf($url, 'indented'), 'indented', 'layout', 'user')); } } JPluginHelper::importPlugin('kunena'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onKunenaGetButtons', array('topic.action', $this->topicButtons, $this)); }
/** * 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')); }