/** * 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}" : ''); }
/** * 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); }
/** * 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}"; }
/** * @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; }
/** * 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 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"e=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)); }
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); }
/** * 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')); }
/** * @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; }