Beispiel #1
0
 /**
  * Prepare category list display.
  *
  * @return void
  */
 protected function before()
 {
     parent::before();
     require_once KPATH_SITE . '/models/topics.php';
     $this->model = new KunenaModelTopics(array(), $this->input);
     $this->model->initialize($this->getOptions(), $this->getOptions()->get('embedded', false));
     $this->state = $this->model->getState();
     $this->me = KunenaUserHelper::getMyself();
     $this->moreUri = null;
     $this->embedded = $this->getOptions()->get('embedded', false);
     if ($this->embedded) {
         $this->moreUri = new JUri('index.php?option=com_kunena&view=topics&layout=posts&mode=' . $this->state->get('list.mode') . '&userid=' . $this->state->get('user') . '&sel=' . $this->state->get('list.time') . '&limit=' . $this->state->get('list.limit'));
         $this->moreUri->setVar('Itemid', KunenaRoute::getItemID($this->moreUri));
     }
     $start = $this->state->get('list.start');
     $limit = $this->state->get('list.limit');
     // Handle &sel=x parameter.
     $time = $this->state->get('list.time');
     if ($time < 0) {
         $time = null;
     } elseif ($time == 0) {
         $time = new JDate(KunenaFactory::getSession()->lasttime);
     } else {
         $time = new JDate(JFactory::getDate()->toUnix() - $time * 3600);
     }
     $userid = $this->state->get('user');
     $user = is_numeric($userid) ? KunenaUserHelper::get($userid) : null;
     // Get categories for the filter.
     $categoryIds = $this->state->get('list.categories');
     $reverse = !$this->state->get('list.categories.in');
     $authorise = 'read';
     $order = 'time';
     $finder = new KunenaForumMessageFinder();
     $finder->filterByTime($time);
     switch ($this->state->get('list.mode')) {
         case 'unapproved':
             $authorise = 'topic.post.approve';
             $finder->filterByUser(null, 'author')->filterByHold(array(1));
             break;
         case 'deleted':
             $authorise = 'topic.post.undelete';
             $finder->filterByUser($user, 'author')->filterByHold(array(2, 3));
             break;
         case 'mythanks':
             $finder->filterByUser($user, 'thanker')->filterByHold(array(0));
             break;
         case 'thankyou':
             $finder->filterByUser($user, 'thankee')->filterByHold(array(0));
             break;
         default:
             $finder->filterByUser($user, 'author')->filterByHold(array(0));
             break;
     }
     $categories = KunenaForumCategoryHelper::getCategories($categoryIds, $reverse, $authorise);
     $finder->filterByCategories($categories);
     $this->pagination = new KunenaPagination($finder->count(), $start, $limit);
     if ($this->moreUri) {
         $this->pagination->setUri($this->moreUri);
     }
     $this->messages = $finder->order($order, -1)->start($this->pagination->limitstart)->limit($this->pagination->limit)->find();
     // Load topics...
     $topicIds = array();
     foreach ($this->messages as $message) {
         $topicIds[(int) $message->thread] = (int) $message->thread;
     }
     $this->topics = KunenaForumTopicHelper::getTopics($topicIds, 'none');
     $userIds = $mesIds = array();
     foreach ($this->messages as $message) {
         $userIds[(int) $message->userid] = (int) $message->userid;
         $mesIds[(int) $message->id] = (int) $message->id;
     }
     if ($this->topics) {
         $this->prepareTopics($userIds, $mesIds);
     }
     switch ($this->state->get('list.mode')) {
         case 'unapproved':
             $this->headerText = JText::_('COM_KUNENA_VIEW_TOPICS_POSTS_MODE_UNAPPROVED');
             $actions = array('approve', 'delete', 'permdelete');
             break;
         case 'deleted':
             $this->headerText = JText::_('COM_KUNENA_VIEW_TOPICS_POSTS_MODE_DELETED');
             $actions = array('undelete', 'delete', 'permdelete');
             break;
         case 'mythanks':
             $this->headerText = JText::_('COM_KUNENA_VIEW_TOPICS_POSTS_MODE_MYTHANKS');
             $actions = array('approve', 'delete', 'permdelete');
             break;
         case 'thankyou':
             $this->headerText = JText::_('COM_KUNENA_VIEW_TOPICS_POSTS_MODE_THANKYOU');
             $actions = array('approve', 'delete', 'permdelete');
             break;
         case 'recent':
         default:
             $this->headerText = JText::_('COM_KUNENA_VIEW_TOPICS_POSTS_MODE_DEFAULT');
             $actions = array('delete', 'permdelete');
     }
     $this->actions = $this->getMessageActions($this->messages, $actions);
 }
Beispiel #2
0
 /**
  * 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'));
 }