示例#1
0
 /**
  * Prepare report message form.
  *
  * @return void
  *
  * @throws KunenaExceptionAuthorise
  */
 protected function before()
 {
     parent::before();
     $id = $this->input->getInt('id');
     $mesid = $this->input->getInt('mesid');
     $me = KunenaUserHelper::getMyself();
     if (!$this->config->reportmsg) {
         // Deny access if report feature has been disabled.
         throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), 404);
     }
     if (!$me->exists()) {
         // Deny access if user is guest.
         throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), 401);
     }
     if (!$mesid) {
         $this->topic = KunenaForumTopicHelper::get($id);
         $this->topic->tryAuthorise();
     } else {
         $this->message = KunenaForumMessageHelper::get($mesid);
         $this->message->tryAuthorise();
         $this->topic = $this->message->getTopic();
     }
     $this->category = $this->topic->getCategory();
     $this->uri = "index.php?option=com_kunena&view=topic&layout=report&catid={$this->category->id}" . "&id={$this->topic->id}" . ($this->message ? "&mesid={$this->message->id}" : '');
 }
示例#2
0
 /**
  * Prepare message actions display.
  *
  * @return void
  */
 protected function before()
 {
     parent::before();
     $catid = $this->input->getInt('id');
     $me = KunenaUserHelper::getMyself();
     $this->category = KunenaForumCategory::getInstance($catid);
     $token = JSession::getFormToken();
     $task = "index.php?option=com_kunena&view=category&task=%s&catid={$catid}&{$token}=1";
     $layout = "index.php?option=com_kunena&view=topic&layout=%s&catid={$catid}";
     $this->template = KunenaFactory::getTemplate();
     $this->categoryButtons = new JObject();
     // Is user allowed to post new topic?
     if ($this->category->getNewTopicCategory()->exists()) {
         $this->categoryButtons->set('create', $this->getButton(sprintf($layout, 'create'), 'create', 'topic', 'communication', true));
     }
     // Is user allowed to mark forums as read?
     if ($me->exists()) {
         $this->categoryButtons->set('markread', $this->getButton(sprintf($task, 'markread'), 'markread', 'category', 'user', true));
     }
     // Is user allowed to subscribe category?
     if ($this->category->isAuthorised('subscribe')) {
         $subscribed = $this->category->getSubscribed($me->userid);
         if (!$subscribed) {
             $this->categoryButtons->set('subscribe', $this->getButton(sprintf($task, 'subscribe'), 'subscribe', 'category', 'user', true));
         } else {
             $this->categoryButtons->set('unsubscribe', $this->getButton(sprintf($task, 'unsubscribe'), 'unsubscribe', 'category', 'user', true));
         }
     }
     JPluginHelper::importPlugin('kunena');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onKunenaGetButtons', array('category.action', $this->categoryButtons, $this));
 }
示例#3
0
 /**
  * Prepare topic moderate display.
  *
  * @return void
  *
  * @throws KunenaExceptionAuthorise
  */
 protected function before()
 {
     parent::before();
     $catid = $this->input->getInt('catid');
     $id = $this->input->getInt('id');
     $mesid = $this->input->getInt('mesid');
     if (!$mesid) {
         $this->topic = KunenaForumTopicHelper::get($id);
         $this->topic->tryAuthorise('move');
     } else {
         $this->message = KunenaForumMessageHelper::get($mesid);
         $this->message->tryAuthorise('move');
         $this->topic = $this->message->getTopic();
     }
     $this->category = $this->topic->getCategory();
     $this->uri = "index.php?option=com_kunena&view=topic&layout=moderate" . "&catid={$this->category->id}&id={$this->topic->id}" . ($this->message ? "&mesid={$this->message->id}" : '');
     $this->title = !$this->message ? JText::_('COM_KUNENA_TITLE_MODERATE_TOPIC') : JText::_('COM_KUNENA_TITLE_MODERATE_MESSAGE');
     // Load topic icons if available.
     if ($this->config->topicicons) {
         $this->template = KunenaTemplate::getInstance();
         $this->template->setCategoryIconset();
         $this->topicIcons = $this->template->getTopicIcons(false);
     }
     // Have a link to moderate user as well.
     if (isset($this->message)) {
         $user = $this->message->getAuthor();
         if ($user->exists()) {
             $username = $user->getName();
             $this->userLink = $this->message->userid ? JHtml::_('kunenaforum.link', 'index.php?option=com_kunena&view=user&layout=moderate&userid=' . $this->message->userid, $username . ' (' . $this->message->userid . ')', $username . ' (' . $this->message->userid . ')') : null;
         }
     }
     if ($this->message) {
         $this->banHistory = KunenaUserBan::getUserHistory($this->message->userid);
         $this->me = KunenaFactory::getUser();
         // Get thread and reply count from current message:
         $db = JFactory::getDbo();
         $query = "SELECT COUNT(mm.id) AS replies FROM #__kunena_messages AS m\r\n\t\t\t\tINNER JOIN #__kunena_messages AS t ON m.thread=t.id\r\n\t\t\t\tLEFT JOIN #__kunena_messages AS mm ON mm.thread=m.thread AND mm.time > m.time\r\n\t\t\t\tWHERE m.id={$db->Quote($this->message->id)}";
         $db->setQuery($query, 0, 1);
         $this->replies = $db->loadResult();
         if (KunenaError::checkDatabaseError()) {
             return;
         }
     }
     $this->banInfo = KunenaUserBan::getInstanceByUserid(JFactory::getUser()->id, true);
 }
 /**
  * Test topic creation
  *
  * @param KunenaForumTopic $topic
  * @return KunenaForumTopic
  * @depends testNew
  */
 public function testCreate(KunenaForumTopic $topic)
 {
     // Creation should fail if there's not enough data
     $this->assertFalse($topic->save());
     $this->assertFalse($topic->exists());
     $this->assertNull($topic->id);
     /*		$topic->category_id = 2;
     		$topic->subject = 'Topic';
     		$this->assertTrue($topic->save());
     		$this->assertTrue($topic->exists());
     		$this->assertGreaterThan(1, $topic->id);
     		$topic2 = KunenaForumTopic::getInstance($topic->id);
     		// TODO: Do we want this?
     		//$this->assertSame($topic, $topic2);
     		$this->assertSame($topic->id, $topic2->id);
     		$this->assertSame($topic->name, $topic2->name);
     		return $topic2;*/
 }
示例#5
0
 /**
  * After render update topic data for the user.
  *
  * @return void
  */
 protected function after()
 {
     parent::after();
     $this->topic->hit();
     $this->topic->markRead();
     // Check if subscriptions have been sent and reset the value.
     if ($this->topic->isAuthorised('subscribe') && $this->userTopic->subscribed == 2) {
         $this->userTopic->subscribed = 1;
         $this->userTopic->save();
     }
 }
示例#6
0
 /**
  * Prepare poll display.
  *
  * @return void
  *
  * @throws KunenaExceptionAuthorise
  */
 protected function before()
 {
     parent::before();
     $this->topic = KunenaForumTopicHelper::get($this->input->getInt('id'));
     $this->category = $this->topic->getCategory();
     $this->config = KunenaFactory::getConfig();
     $this->me = KunenaUserHelper::getMyself();
     // Need to check if poll is allowed in this category.
     $this->topic->tryAuthorise('poll.read');
     $this->poll = $this->topic->getPoll();
     $this->usercount = $this->poll->getUserCount();
     $this->usersvoted = $this->poll->getUsers();
     $this->voted = $this->poll->getMyVotes();
     if (!empty($this->alwaysVote)) {
         // Authorise forced vote.
         $this->topic->tryAuthorise('poll.vote');
         $this->name = 'Topic/Poll/Vote';
     } elseif (!$this->voted && $this->topic->isAuthorised('poll.vote')) {
         $this->name = 'Topic/Poll/Vote';
     } else {
         $this->name = 'Topic/Poll/Results';
         $this->show_title = true;
         $this->users_voted_list = array();
         $this->users_voted_morelist = array();
         if ($this->config->pollresultsuserslist && !empty($this->usersvoted)) {
             $userids_votes = array();
             foreach ($this->usersvoted as $userid => $vote) {
                 $userids_votes[] = $userid;
             }
             $loaded_users = KunenaUserHelper::loadUsers($userids_votes);
             $i = 0;
             foreach ($loaded_users as $userid => $user) {
                 if ($i <= '4') {
                     $this->users_voted_list[] = $loaded_users[$userid]->getLink();
                 } else {
                     $this->users_voted_morelist[] = $loaded_users[$userid]->getLink();
                 }
                 $i++;
             }
         }
     }
     $this->uri = "index.php?option=com_kunena&view=topic&layout=poll&catid={$this->category->id}&id={$this->topic->id}";
 }
示例#7
0
 /**
  * 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));
 }
示例#8
0
 /**
  * @param array $ids
  */
 protected static function loadTopics(array $ids)
 {
     foreach ($ids as $i => $id) {
         $id = intval($id);
         if (!$id || isset(self::$_instances[$id])) {
             unset($ids[$i]);
         }
     }
     if (empty($ids)) {
         return;
     }
     $idlist = implode(',', $ids);
     $db = JFactory::getDBO();
     $query = "SELECT * FROM #__kunena_topics WHERE id IN ({$idlist})";
     $db->setQuery($query);
     $results = (array) $db->loadAssocList('id');
     KunenaError::checkDatabaseError();
     foreach ($ids as $id) {
         if (isset($results[$id])) {
             $instance = new KunenaForumTopic($results[$id]);
             $instance->exists(true);
             self::$_instances[$id] = $instance;
         } else {
             self::$_instances[$id] = null;
         }
     }
     unset($results);
 }
示例#9
0
 /**
  * Prepare message actions display.
  *
  * @return void
  */
 protected function before()
 {
     parent::before();
     $mesid = $this->input->getInt('mesid');
     $me = KunenaUserHelper::getMyself();
     $this->message = KunenaForumMessage::getInstance($mesid);
     $this->topic = $this->message->getTopic();
     $id = $this->message->thread;
     $catid = $this->message->catid;
     $token = JSession::getFormToken();
     $task = "index.php?option=com_kunena&view=topic&task=%s&catid={$catid}&id={$id}&mesid={$mesid}&{$token}=1";
     $layout = "index.php?option=com_kunena&view=topic&layout=%s&catid={$catid}&id={$id}&mesid={$mesid}";
     $this->template = KunenaFactory::getTemplate();
     $this->messageButtons = new JObject();
     $this->message_closed = null;
     if ($this->message->isAuthorised('reply')) {
         if (version_compare(JVERSION, '3.4', '<') && $me->canDoCaptcha()) {
             $this->quickreply = false;
         } elseif (version_compare(JVERSION, '3.4', '>') && $me->canDoCaptcha()) {
             $this->quickreply = true;
         } else {
             $this->quickreply = true;
         }
     } else {
         $this->quickreply = false;
     }
     // Reply / Quote
     if ($this->message->isAuthorised('reply')) {
         $this->messageButtons->set('reply', $this->getButton(sprintf($layout, 'reply'), 'reply', 'message', 'communication', null, true));
         if ($me->exists() && !KunenaSpamRecaptcha::getInstance()->enabled()) {
             $this->messageButtons->set('quickreply', $this->getButton(sprintf($layout, 'reply'), 'quickreply', 'message', 'communication', "kreply{$mesid}"));
         }
         $this->messageButtons->set('quote', $this->getButton(sprintf($layout, 'reply&quote=1'), 'quote', 'message', 'communication'));
     } elseif (!$me->isModerator($this->topic->getCategory())) {
         // User is not allowed to write a post.
         $this->message_closed = $this->topic->locked ? JText::_('COM_KUNENA_POST_LOCK_SET') : ($me->exists() ? JText::_('COM_KUNENA_REPLY_USER_REPLY_DISABLED') : ' ');
     }
     $login = KunenaLogin::getInstance();
     if (!$this->message->isAuthorised('reply') && !$this->message_closed && $login->enabled() || !$this->message->isAuthorised('reply') && !$this->topic->locked && $login->enabled() && !$me->userid) {
         $logintext = '<a class="btn-link" href="#klogin" rel="nofollow"> ' . JText::_('JLOGIN') . '</a>';
         if ($login->getRegistrationUrl()) {
             $register = ' ' . JText::_('COM_KUNENA_LOGIN_OR') . ' <a class="btn-link" href="' . $login->getRegistrationUrl() . '">' . JText::_('COM_KUNENA_PROFILEBOX_CREATE_ACCOUNT') . '</a>';
         } else {
             $register = '';
         }
         echo '<p>' . JText::sprintf('COM_KUNENA_LOGIN_PLEASE', $logintext, $register) . '</p>';
     }
     // Thank you.
     if (isset($this->message->thankyou)) {
         if ($this->message->isAuthorised('thankyou') && !array_key_exists($me->userid, $this->message->thankyou)) {
             $this->messageButtons->set('thankyou', $this->getButton(sprintf($task, 'thankyou'), 'thankyou', 'message', 'user', null, false));
         }
     }
     // Unthank you
     if ($this->message->isAuthorised('unthankyou') && array_key_exists($me->userid, $this->message->thankyou)) {
         $this->messageButtons->set('unthankyou', $this->getButton(sprintf($task, 'unthankyou&userid=' . $me->userid), 'unthankyou', 'message', 'user', null, false));
     }
     // Report this.
     if (KunenaFactory::getConfig()->reportmsg && $me->exists()) {
         $this->messageButtons->set('report', $this->getButton(sprintf($layout, 'report'), 'report', 'message', 'user'));
     }
     // Moderation and own post actions.
     if ($this->message->isAuthorised('edit')) {
         $this->messageButtons->set('edit', $this->getButton(sprintf($layout, 'edit'), 'edit', 'message', 'moderation'));
     }
     if ($this->message->isAuthorised('move')) {
         $this->messageButtons->set('moderate', $this->getButton(sprintf($layout, 'moderate'), 'moderate', 'message', 'moderation'));
     }
     if ($this->message->hold == 1) {
         if ($this->message->isAuthorised('approve')) {
             $this->messageButtons->set('publish', $this->getButton(sprintf($task, 'approve'), 'approve', 'message', 'moderation'));
         }
         if ($this->message->isAuthorised('delete')) {
             $this->messageButtons->set('delete', $this->getButton(sprintf($task, 'delete'), 'delete', 'message', 'moderation'));
         }
     } elseif ($this->message->hold == 2 || $this->message->hold == 3) {
         if ($this->message->isAuthorised('undelete')) {
             $this->messageButtons->set('undelete', $this->getButton(sprintf($task, 'undelete'), 'undelete', 'message', 'moderation'));
         }
         if ($this->message->isAuthorised('permdelete')) {
             $this->messageButtons->set('permdelete', $this->getButton(sprintf($task, 'permdelete'), 'permdelete', 'message', 'permanent'));
         }
     } elseif ($this->message->isAuthorised('delete')) {
         $this->messageButtons->set('delete', $this->getButton(sprintf($task, 'delete'), 'delete', 'message', 'moderation'));
     }
     JPluginHelper::importPlugin('kunena');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onKunenaGetButtons', array('message.action', $this->messageButtons, $this));
 }
示例#10
0
 public function getTopicLink(KunenaForumTopic $topic, $action = null, $content = null, $title = null, $class = null, KunenaForumCategory $category = NULL)
 {
     $uri = $topic->getUri($category ? $category : (isset($this->category) ? $this->category : $topic->category_id), $action);
     if (!$content) {
         $content = KunenaHtmlParser::parseText($topic->subject);
     }
     $rel = 'follow';
     if ($title === null) {
         $rel = 'nofollow';
         if ($action instanceof KunenaForumMessage) {
             $title = JText::sprintf('COM_KUNENA_TOPIC_MESSAGE_LINK_TITLE', $this->escape($topic->subject));
         } else {
             switch ($action) {
                 case 'first':
                     $title = JText::sprintf('COM_KUNENA_TOPIC_FIRST_LINK_TITLE', $this->escape($topic->subject));
                     break;
                 case 'last':
                     $title = JText::sprintf('COM_KUNENA_TOPIC_LAST_LINK_TITLE', $this->escape($topic->subject));
                     break;
                 case 'unread':
                     $title = JText::sprintf('COM_KUNENA_TOPIC_UNREAD_LINK_TITLE', $this->escape($topic->subject));
                     break;
                 default:
                     $title = JText::sprintf('COM_KUNENA_TOPIC_LINK_TITLE', $this->escape($topic->subject));
             }
         }
     }
     return JHtml::_('kunenaforum.link', $uri, $content, $title, $class, $rel);
 }
示例#11
0
	public static function getTopicUrl(KunenaForumTopic $topic, $xhtml = true, $action = null, KunenaForumCategory $category = null)
	{
		if (!$category)
		{
			$category = $topic->getCategory();
		}

		return KunenaRoute::_($topic->getUri($category, $action), $xhtml);
	}
示例#12
0
 /**
  * Gets an URL to a post or a category
  *
  * @param  int|null  $forum  Forum category
  * @param  int|null  $post   Forum post
  * @return null|string       URL
  */
 public static function getForumURL($forum = null, $post = null)
 {
     if (!class_exists('KunenaForumTopic') || !class_exists('KunenaForumMessage')) {
         return null;
     }
     if ($post) {
         $url = KunenaForumTopic::getInstance((int) $post)->getUrl();
         if (!$url) {
             $url = KunenaForumMessage::getInstance((int) $post)->getUrl();
         }
     } else {
         $url = cbforumsModel::getCategory((int) $forum)->getUrl();
     }
     return $url;
 }
示例#13
0
 function shKUTopicName($topicid, $option, $shLangIso, $shLangName)
 {
     static $topics = array();
     $sefConfig =& shRouter::shGetConfig();
     if (empty($topicid) || !$sefConfig->shFbInsertMessageSubject) {
         return '';
     }
     if (class_exists('KunenaForum')) {
         // Kunena 2.0 support
         $topic = KunenaForumTopic::getInstance($topicid);
         $topicsubject = $topic->subject;
     } elseif (class_exists('KunenaRouter')) {
         // Kunena 1.6 support
         if (empty(KunenaRouter::$msgidcache[$topicid])) {
             $database =& JFactory::getDBO();
             $query = 'SELECT subject, id FROM #__kunena_messages WHERE id=' . (int) $topicid;
             $database->setQuery($query);
             KunenaRouter::$msgidcache[$topicid] = $database->loadResult();
         }
         $topicsubject = KunenaRouter::$msgidcache[$topicid];
     } else {
         // Kunena 1.0 / 1.5 support
         if (empty($topics[$topicid])) {
             $database =& JFactory::getDBO();
             $query = 'SELECT id, subject FROM #__fb_messages WHERE id = ' . (int) $topicid;
             $database->setQuery($query);
             if (!shTranslateUrl($option, $shLangName)) {
                 $topicDetails = $database->loadObject(false);
             } else {
                 $topicDetails = $database->loadObject();
             }
             $topics[$topicid] = empty($topicDetails) ? '' : $topicDetails->subject;
         }
         $topicsubject = $topics[$topicid];
     }
     // we have a user name
     $topicstring = empty($topicsubject) ? 't' . $sefConfig->replacement . $topicid : ($sefConfig->shFbInsertMessageId ? $topicid . $sefConfig->replacement : '');
     // if name, put ID only if requested
     $topicstring = $topicstring . (empty($topicsubject) ? '' : $topicsubject);
     return $topicstring;
 }
示例#14
0
 /**
  * @param KunenaForumTopic $topic
  * @param int $topicdelta
  * @param int $postdelta
  *
  * @return bool
  */
 public function update($topic, $topicdelta = 0, $postdelta = 0)
 {
     if (!$topic->id) {
         return false;
     }
     $update = false;
     if ($topicdelta || $postdelta) {
         // Update topic and post count
         $this->numTopics += (int) $topicdelta;
         $this->numPosts += (int) $postdelta;
         $update = true;
     }
     if ($topic->exists() && $topic->hold == 0 && $topic->moved_id == 0 && $topic->category_id == $this->id && ($this->last_post_time < $topic->last_post_time || $this->last_post_time == $topic->last_post_time && $this->last_post_id <= $topic->last_post_id)) {
         // If topic has new post or last topic changed, we need to update cache
         $this->last_topic_id = $topic->id;
         $this->last_post_id = $topic->last_post_id;
         $this->last_post_time = $topic->last_post_time;
         $update = true;
     } elseif ($this->last_topic_id == $topic->id) {
         // If last topic/post got moved or deleted, we need to find last post
         $db = JFactory::getDBO();
         $query = "SELECT * FROM #__kunena_topics WHERE category_id={$db->quote($this->id)} AND hold=0 AND moved_id=0 ORDER BY last_post_time DESC, last_post_id DESC";
         $db->setQuery($query, 0, 1);
         $topic = $db->loadObject();
         KunenaError::checkDatabaseError();
         if ($topic) {
             $this->last_topic_id = $topic->id;
             $this->last_post_id = $topic->last_post_id;
             $this->last_post_time = $topic->last_post_time;
             $update = true;
         } else {
             $this->numTopics = 0;
             $this->numPosts = 0;
             $this->last_topic_id = 0;
             $this->last_post_id = 0;
             $this->last_post_time = 0;
             $update = true;
         }
     }
     if (!$update) {
         return true;
     }
     // TODO: remove this hack...
     $this->_noreorder = true;
     return $this->save();
 }
示例#15
0
 function shKUTopicName($topicid, $option, $shLangIso, $shLangName)
 {
     static $topics = array();
     $sefConfig =& Sh404sefFactory::getConfig();
     if (empty($topicid) || !$sefConfig->shFbInsertMessageSubject) {
         return '';
     }
     if (class_exists('KunenaForum')) {
         // Kunena 2.0 support
         $topic = KunenaForumTopic::getInstance($topicid);
         $topicsubject = $topic->subject;
     } elseif (class_exists('KunenaRouter')) {
         // Kunena 1.6 support
         if (empty(KunenaRouter::$msgidcache[$topicid])) {
             try {
                 KunenaRouter::$msgidcache[$topicid] = ShlDbHelper::selectResult('#__kunena_messages', array('subject', 'id'), array('id' => $topicid));
             } catch (Exception $e) {
                 ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage());
             }
         }
         $topicsubject = KunenaRouter::$msgidcache[$topicid];
     } else {
         // Kunena 1.0 / 1.5 support
         if (empty($topics[$topicid])) {
             try {
                 $topicDetails = ShlDbHelper::selectObject('#__fb_messages', array('id', 'subject'), array('id' => $topicid));
             } catch (Exception $e) {
                 ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage());
             }
             $topics[$topicid] = empty($topicDetails) ? '' : $topicDetails->subject;
         }
         $topicsubject = $topics[$topicid];
     }
     // we have a user name
     $topicstring = empty($topicsubject) ? 't' . $sefConfig->replacement . $topicid : ($sefConfig->shFbInsertMessageId ? $topicid . $sefConfig->replacement : '');
     // if name, put ID only if requested
     $topicstring = $topicstring . (empty($topicsubject) ? '' : $topicsubject);
     return $topicstring;
 }
示例#16
0
	public function newTopic($fields=array(), $user=null) {
		kimport ('kunena.forum.topic');
		kimport ('kunena.forum.message');

		$catid = $this->getNewTopicCategory()->id;
		$user = KunenaUserHelper::get($user);
		$message = new KunenaForumMessage();
		$message->catid = $catid;
		$message->name = $user->getName('');
		$message->userid = $user->userid;
		$message->ip = $_SERVER ["REMOTE_ADDR"];
		$message->hold = $this->review ? (int)!$this->authorise ('moderate', $user, true) : 0;
		$message->bind($fields, array ('name', 'email', 'subject', 'message'));

		$topic = new KunenaForumTopic();
		$topic->category_id = $catid;
		$topic->hold = $message->hold;
		$topic->bind($fields, array ('subject','icon_id'));

		$message->setTopic($topic);
		return array($topic, $message);
	}
示例#17
0
 /**
  * @param KunenaForumCategory $category
  * @param KunenaForumTopic    $topic
  *
  * @return bool
  */
 protected function canPost(KunenaForumCategory $category, KunenaForumTopic $topic)
 {
     if ($topic->exists()) {
         return $topic->authorise('reply');
     } else {
         return $category->authorise('topic.reply');
     }
 }
示例#18
0
 /**
  * Post to Kunena 3.x
  *
  * @return  void
  */
 protected function post3x()
 {
     // Load front end language file as well
     $lang = $this->lang;
     $lang->load('com_kunena', JPATH_SITE . '/components/com_kunena');
     $params = $this->getParams();
     $app = $this->app;
     $formModel = $this->getModel();
     $input = $app->input;
     $user = $this->user;
     $now = $this->date;
     $w = new FabrikWorker();
     $catid = $params->get('kunena_category', 0);
     // Added action in request
     $msg = $w->parseMessageForPlaceHolder($params->get('kunena_content'), $formModel->fullFormData);
     $subject = $params->get('kunena_title');
     $subject = $w->parseMessageForPlaceHolder($subject, $formModel->fullFormData);
     // Added subject in request
     $origId = $input->get('id');
     $input->set('id', 0);
     $topic = new KunenaForumTopic();
     $topic->category_id = $catid;
     $topic->subject = $subject;
     $topic->first_post_time = $topic->last_post_time = $now->toUnix();
     $topic->first_post_userid = $topic->last_post_userid = $user->get('id');
     $topic->first_post_message = $topic->last_post_message = $msg;
     $topic->posts = 1;
     if ($topic->save()) {
         $message = new KunenaForumMessage();
         $message->setTopic($topic);
         $message->subject = $subject;
         $message->catid = $catid;
         $message->name = $user->get('name');
         $message->time = $now->toUnix();
         $message->message = $msg;
         if (!$message->save()) {
             $app->enqueueMessage(FText::_('PLG_FORM_KUNENA_ERR_DIDNT_SAVE_MESSAGE') . ': ' . $message->getError(), 'error');
         }
     } else {
         $app->enqueueMessage(FText::_('PLG_FORM_KUNENA_ERR_DIDNT_SAVE_TOPIC') . ': ' . $topic->getError(), 'error');
     }
     $input->set('id', $origId);
 }
示例#19
0
 /**
  * @param KunenaForumTopic $topic
  * @param bool             $type
  *
  * @return array
  */
 public function loadSubscribers(KunenaForumTopic $topic, $type)
 {
     $category = $topic->getCategory();
     $db = JFactory::getDBO();
     $query = array();
     if ($type & self::TOPIC_SUBSCRIPTION) {
         // Get topic subscriptions
         $query[] = "SELECT user_id FROM #__kunena_user_topics WHERE topic_id={$topic->id} AND subscribed=1";
     }
     if ($type & self::CATEGORY_SUBSCRIPTION) {
         // Get category subscriptions
         $query[] = "SELECT user_id FROM #__kunena_user_categories WHERE category_id={$category->id} AND subscribed=1";
     }
     $query = implode(' UNION ', $query);
     $db->setQuery($query);
     $userids = (array) $db->loadColumn();
     KunenaError::checkDatabaseError();
     return $userids;
 }
示例#20
0
 /**
  * @param   KunenaForumTopic    $topic
  * @param   null                $action
  * @param   null                $content
  * @param   null                $title
  * @param   null                $class
  * @param   KunenaForumCategory $category
  *
  * @return mixed
  */
 public function getTopicLink(KunenaForumTopic $topic, $action = null, $content = null, $title = null, $class = null, KunenaForumCategory $category = null)
 {
     KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
     $url = $topic->getUrl($category ? $category : (isset($this->category) ? $this->category : $topic->getCategory()), true, $action);
     if (!$content) {
         $content = KunenaHtmlParser::parseText($topic->subject);
     }
     if ($title === null) {
         if ($action instanceof KunenaForumMessage) {
             $title = JText::sprintf('COM_KUNENA_TOPIC_MESSAGE_LINK_TITLE', $this->escape($topic->subject));
         } else {
             switch ($action) {
                 case 'first':
                     $title = JText::sprintf('COM_KUNENA_TOPIC_FIRST_LINK_TITLE', $this->escape($topic->subject));
                     break;
                 case 'last':
                     $title = JText::sprintf('COM_KUNENA_TOPIC_LAST_LINK_TITLE', $this->escape($topic->subject));
                     break;
                 case 'unread':
                     $title = JText::sprintf('COM_KUNENA_TOPIC_UNREAD_LINK_TITLE', $this->escape($topic->subject));
                     break;
                 default:
                     $title = JText::sprintf('COM_KUNENA_TOPIC_LINK_TITLE', $this->escape($topic->subject));
             }
         }
     }
     $link = JHtml::_('kunenaforum.link', $url, $content, $title, $class, 'nofollow');
     KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
     return $link;
 }
示例#21
0
 public function newTopic(array $fields = null, $user = null, $safefields = null)
 {
     $catid = isset($safefields['category_id']) ? $safefields['category_id'] : $this->getNewTopicCategory()->id;
     $user = KunenaUserHelper::get($user);
     $message = new KunenaForumMessage();
     $message->catid = $catid;
     $message->name = $user->getName('');
     $message->userid = $user->userid;
     $message->ip = !empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
     $message->hold = $this->review ? (int) (!$this->authorise('moderate', $user, true)) : 0;
     if ($safefields) {
         $message->bind($safefields);
     }
     if ($fields) {
         $message->bind($fields, array('name', 'email', 'subject', 'message'), true);
     }
     $topic = new KunenaForumTopic();
     $topic->category_id = $catid;
     $topic->hold = $message->hold;
     if ($safefields) {
         $topic->bind($safefields);
     }
     if ($fields) {
         $topic->bind($fields, array('subject', 'icon_id'), true);
     }
     $message->setTopic($topic);
     return array($topic, $message);
 }