/**
	 * Test new KunenaForumCategory()
	 *
	 * @return KunenaForumCategory
	 */
	public function testNew() {
		$category = new KunenaForumCategory();
		$this->assertNull($category->id, 'Test that new category id is null');
		$this->assertFalse($category->exists(), 'Test that new category does not exist');
		$this->assertEmpty($category->getChannels(), 'Test that new category has no channels');
		$this->assertTrue($category->isSection(), 'Test that new category is section');
		$this->assertFalse($category->checkout(JFactory::getUser()), 'Test that new category checkout always fails');
		$this->assertFalse($category->isCheckedOut(JFactory::getUser()), 'Test that new category is not checked out after last action');
		$this->assertTrue($category->checkin(), 'Test that new category check in always succeeds');
		$this->assertTrue($category->delete(), 'Test that deleting new category succeeds');
		return $category;
	}
Ejemplo n.º 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'));
 }
Ejemplo n.º 3
0
 /**
  * Method to get the last post link
  *
  * @param   KunenaForumCategory $category The KunenaCategory object
  * @param   string              $content  The content of last topic subject
  * @param   string              $title    The title of the link
  * @param   string              $class    The class attribute of the link
  *
  * @see KunenaLayout::getLastPostLink()
  *
  * @return string
  */
 public function getLastPostLink($category, $content = null, $title = null, $class = null, $length = 20)
 {
     $lastTopic = $category->getLastTopic();
     $channels = $category->getChannels();
     if (!isset($channels[$lastTopic->category_id])) {
         $category = $lastTopic->getCategory();
     }
     $uri = $lastTopic->getUri($category, 'last');
     if (!$content) {
         $content = KunenaHtmlParser::parseText($category->getLastTopic()->subject, $length);
     }
     if ($title === null) {
         $title = JText::sprintf('COM_KUNENA_TOPIC_LAST_LINK_TITLE', $this->escape($category->getLastTopic()->subject));
     }
     return JHtml::_('kunenaforum.link', $uri, $content, $title, $class, 'nofollow');
 }