Пример #1
0
 /**
  * Prepare topics by pre-loading needed information.
  *
  * @param   array  $userIds  List of additional user Ids to be loaded.
  * @param   array  $mesIds   List of additional message Ids to be loaded.
  *
  * @return  void
  */
 protected function prepareTopics(array $userIds = array(), array $mesIds = array())
 {
     // Collect user Ids for avatar prefetch when integrated.
     $lastIds = array();
     foreach ($this->topics as $topic) {
         $userIds[(int) $topic->first_post_userid] = (int) $topic->first_post_userid;
         $userIds[(int) $topic->last_post_userid] = (int) $topic->last_post_userid;
         $lastIds[(int) $topic->last_post_id] = (int) $topic->last_post_id;
     }
     // Prefetch all users/avatars to avoid user by user queries during template iterations.
     if (!empty($userIds)) {
         KunenaUserHelper::loadUsers($userIds);
     }
     $topicIds = array_keys($this->topics);
     KunenaForumTopicHelper::getUserTopics($topicIds);
     /* KunenaForumTopicHelper::getKeywords($topicIds); */
     $mesIds += KunenaForumTopicHelper::fetchNewStatus($this->topics);
     // Fetch also last post positions when user can see unapproved or deleted posts.
     // TODO: Optimize? Take account of configuration option...
     if ($this->me->isAdmin() || KunenaAccess::getInstance()->getModeratorStatus()) {
         $mesIds += $lastIds;
     }
     // Load position information for all selected messages.
     if ($mesIds) {
         KunenaForumMessageHelper::loadLocation($mesIds);
     }
 }
Пример #2
0
 /**
  * Prepare reply history display.
  *
  * @return void
  */
 protected function before()
 {
     parent::before();
     $id = $this->input->getInt('id');
     $this->topic = KunenaForumTopicHelper::get($id);
     $this->history = KunenaForumMessageHelper::getMessagesByTopic($this->topic, 0, (int) $this->config->historylimit, 'DESC');
     $this->replycount = $this->topic->getReplies();
     $this->historycount = count($this->history);
     KunenaAttachmentHelper::getByMessage($this->history);
     $userlist = array();
     foreach ($this->history as $message) {
         $userlist[(int) $message->userid] = (int) $message->userid;
     }
     KunenaUserHelper::loadUsers($userlist);
     // Run events
     $params = new JRegistry();
     $params->set('ksource', 'kunena');
     $params->set('kunena_view', 'topic');
     $params->set('kunena_layout', 'history');
     $dispatcher = JEventDispatcher::getInstance();
     JPluginHelper::importPlugin('kunena');
     $dispatcher->trigger('onKunenaPrepare', array('kunena.messages', &$this->history, &$params, 0));
     // FIXME: need to improve BBCode class on this...
     $this->attachments = KunenaAttachmentHelper::getByMessage($this->history);
     $this->inline_attachments = array();
     $this->headerText = JText::_('COM_KUNENA_POST_EDIT') . ' ' . $this->topic->subject;
 }
Пример #3
0
 /**
  * Gets the users avatars from Kunena
  *
  * @param   array  $userIds  - array with user ids
  *
  * @return array
  */
 public static function getAvatars($userIds)
 {
     $avatars = array();
     $users = KunenaUserHelper::loadUsers($userIds);
     foreach ($users as $user) {
         $avatars[$user->userid] = $user->getAvatarURL();
     }
     return $avatars;
 }
Пример #4
0
 /**
  * Prepare ban manager.
  *
  * @return void
  */
 protected function before()
 {
     parent::before();
     $this->me = KunenaUserHelper::getMyself();
     // TODO: add authorisation
     // TODO: add pagination
     $this->userBans = KunenaUserBan::getBannedUsers(0, 50);
     if (!empty($this->userBans)) {
         KunenaUserHelper::loadUsers(array_keys($this->userBans));
     }
     $this->headerText = JText::_('COM_KUNENA_BAN_BANMANAGER');
 }
Пример #5
0
 function displaySubscriptions()
 {
     $id = $this->app->input->get('id', 0, 'int');
     $topic = KunenaForumTopicHelper::get($id);
     $acl = KunenaAccess::getInstance();
     $cat_subscribers = $acl->loadSubscribers($topic, KunenaAccess::CATEGORY_SUBSCRIPTION);
     $this->cat_subscribers_users = KunenaUserHelper::loadUsers($cat_subscribers);
     $topic_subscribers = $acl->loadSubscribers($topic, KunenaAccess::TOPIC_SUBSCRIPTION);
     $this->topic_subscribers_users = KunenaUserHelper::loadUsers($topic_subscribers);
     $this->cat_topic_subscribers = $acl->getSubscribers($topic->getCategory()->id, $id, KunenaAccess::CATEGORY_SUBSCRIPTION | KunenaAccess::TOPIC_SUBSCRIPTION, 1, 1);
     $this->display();
 }
Пример #6
0
 /**
  * Prepare Who is online display.
  *
  * @return void
  *
  * @throws KunenaExceptionAuthorise
  */
 protected function before()
 {
     parent::before();
     $this->config = KunenaConfig::getInstance();
     if (!$this->config->get('showwhoisonline')) {
         throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), '404');
     }
     $me = KunenaUserHelper::getMyself();
     $moderator = intval($me->isModerator()) + intval($me->isAdmin());
     $users = KunenaUserHelper::getOnlineUsers();
     KunenaUserHelper::loadUsers(array_keys($users));
     $onlineusers = KunenaUserHelper::getOnlineCount();
     $who = '<strong>' . $onlineusers['user'] . ' </strong>';
     if ($onlineusers['user'] == 1) {
         $who .= JText::_('COM_KUNENA_WHO_ONLINE_MEMBER') . '&nbsp;';
     } else {
         $who .= JText::_('COM_KUNENA_WHO_ONLINE_MEMBERS') . '&nbsp;';
     }
     $who .= JText::_('COM_KUNENA_WHO_AND');
     $who .= '<strong> ' . $onlineusers['guest'] . ' </strong>';
     if ($onlineusers['guest'] == 1) {
         $who .= JText::_('COM_KUNENA_WHO_ONLINE_GUEST') . '&nbsp;';
     } else {
         $who .= JText::_('COM_KUNENA_WHO_ONLINE_GUESTS') . '&nbsp;';
     }
     $who .= JText::_('COM_KUNENA_WHO_ONLINE_NOW');
     $this->membersOnline = $who;
     $this->onlineList = array();
     $this->hiddenList = array();
     foreach ($users as $userid => $usertime) {
         $user = KunenaUserHelper::get($userid);
         if (!$user->showOnline) {
             if ($moderator) {
                 $this->hiddenList[$user->getName()] = $user;
             }
         } else {
             $this->onlineList[$user->getName()] = $user;
         }
     }
     ksort($this->onlineList);
     ksort($this->hiddenList);
     $profile = KunenaFactory::getProfile();
     $this->usersUrl = $profile->getUserListURL();
 }
Пример #7
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}";
 }
Пример #8
0
 /**
  * Prepare category subscriptions display.
  *
  * @return void
  *
  * @throws KunenaExceptionAuthorise
  */
 protected function before()
 {
     parent::before();
     $me = KunenaUserHelper::getMyself();
     if (!$me->exists()) {
         throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), 401);
     }
     $limit = $this->input->getInt('limit', 0);
     if ($limit < 1 || $limit > 100) {
         $limit = 20;
     }
     $limitstart = $this->input->getInt('limitstart', 0);
     if ($limitstart < 0) {
         $limitstart = 0;
     }
     list($total, $this->categories) = KunenaForumCategoryHelper::getLatestSubscriptions($me->userid);
     $topicIds = array();
     $userIds = array();
     $postIds = array();
     foreach ($this->categories as $category) {
         // Get list of topics.
         if ($category->last_topic_id) {
             $topicIds[$category->last_topic_id] = $category->last_topic_id;
         }
     }
     // Pre-fetch topics (also display unauthorized topics as they are in allowed categories).
     $topics = KunenaForumTopicHelper::getTopics($topicIds, 'none');
     // Pre-fetch users (and get last post ids for moderators).
     foreach ($topics as $topic) {
         $userIds[$topic->last_post_userid] = $topic->last_post_userid;
         $postIds[$topic->id] = $topic->last_post_id;
     }
     KunenaUserHelper::loadUsers($userIds);
     KunenaForumMessageHelper::getMessages($postIds);
     // Pre-fetch user related stuff.
     if ($me->exists() && !$me->isBanned()) {
         // Load new topic counts.
         KunenaForumCategoryHelper::getNewTopics(array_keys($this->categories));
     }
     $this->actions = $this->getActions();
     $this->pagination = new JPagination($total, $limitstart, $limit);
     $this->headerText = JText::_('COM_KUNENA_CATEGORY_SUBSCRIPTIONS');
 }
Пример #9
0
 /**
  * @param   array $userlist
  * @param   array $postlist
  */
 protected function _common(array $userlist = array(), array $postlist = array())
 {
     if ($this->total > 0) {
         // collect user ids for avatar prefetch when integrated
         $lastpostlist = array();
         foreach ($this->topics as $topic) {
             $userlist[intval($topic->first_post_userid)] = intval($topic->first_post_userid);
             $userlist[intval($topic->last_post_userid)] = intval($topic->last_post_userid);
             $lastpostlist[intval($topic->last_post_id)] = intval($topic->last_post_id);
         }
         // Prefetch all users/avatars to avoid user by user queries during template iterations
         if (!empty($userlist)) {
             KunenaUserHelper::loadUsers($userlist);
         }
         KunenaForumTopicHelper::getUserTopics(array_keys($this->topics));
         KunenaForumTopicHelper::getKeywords(array_keys($this->topics));
         $lastreadlist = KunenaForumTopicHelper::fetchNewStatus($this->topics);
         // Fetch last / new post positions when user can see unapproved or deleted posts
         if ($postlist || $lastreadlist || $this->me->userid && ($this->me->isAdmin() || KunenaAccess::getInstance()->getModeratorStatus())) {
             KunenaForumMessageHelper::loadLocation($postlist + $lastpostlist + $lastreadlist);
         }
     }
 }
Пример #10
0
	function displayThreadHistory() {
		if (! $this->hasThreadHistory())
			return;

		$db = JFactory::getDBO();
		$this->history = KunenaForumMessageHelper::getMessagesByTopic($this->topic, 0, (int) $this->config->historylimit, $ordering='DESC');
		$this->historycount = count ( $this->history );
		KunenaForumMessageAttachmentHelper::getByMessage($this->history);
		$userlist = array();
		foreach ($this->history as $message) {
			$userlist[(int) $message->userid] = (int) $message->userid;
		}
		KunenaUserHelper::loadUsers($userlist);

		echo $this->loadTemplate ( 'history' );
	}
Пример #11
0
 public function getMessages()
 {
     if ($this->messages === false) {
         $layout = $this->getState('layout');
         $threaded = $layout == 'indented' || $layout == 'threaded';
         $this->messages = KunenaForumMessageHelper::getMessagesByTopic($this->getState('item.id'), $this->getState('list.start'), $this->getState('list.limit'), $this->getState('list.direction'), $this->getState('hold'), $threaded);
         // Get thankyous for all messages in the page
         $thankyous = KunenaForumMessageThankyouHelper::getByMessage($this->messages);
         // First collect ids and users
         $userlist = array();
         $this->threaded = array();
         $location = $this->getState('list.start');
         foreach ($this->messages as $message) {
             $message->replynum = ++$location;
             if ($threaded) {
                 // Threaded ordering
                 if (isset($this->messages[$message->parent])) {
                     $this->threaded[$message->parent][] = $message->id;
                 } else {
                     $this->threaded[0][] = $message->id;
                 }
             }
             $userlist[intval($message->userid)] = intval($message->userid);
             $userlist[intval($message->modified_by)] = intval($message->modified_by);
             $thankyou_list = $thankyous[$message->id]->getList();
             $message->thankyou = array();
             if (!empty($thankyou_list)) {
                 $message->thankyou = $thankyou_list;
             }
         }
         if (!isset($this->messages[$this->getState('item.mesid')]) && !empty($this->messages)) {
             $this->setState('item.mesid', reset($this->messages)->id);
         }
         if ($threaded) {
             if (!isset($this->messages[$this->topic->first_post_id])) {
                 $this->messages = $this->getThreadedOrdering(0, array('edge'));
             } else {
                 $this->messages = $this->getThreadedOrdering();
             }
         }
         // Prefetch all users/avatars to avoid user by user queries during template iterations
         KunenaUserHelper::loadUsers($userlist);
         // Get attachments
         KunenaForumMessageAttachmentHelper::getByMessage($this->messages);
     }
     return $this->messages;
 }
Пример #12
0
 public function batch_moderators()
 {
     if (!JSession::checkToken('post')) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
         $this->app->redirect(KunenaRoute::_($this->baseurl, false));
     }
     $cid = JRequest::getVar('cid', array(), 'post', 'array');
     // Array of integers
     JArrayHelper::toInteger($cid);
     $catids = JRequest::getVar('catid', array(), 'post', 'array');
     // Array of integers
     JArrayHelper::toInteger($catids);
     if (empty($cid)) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_USERS_BATCH_NO_USERS_SELECTED'), 'error');
         $this->app->redirect(KunenaRoute::_($this->baseurl, false));
     }
     if (empty($catids)) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_USERS_BATCH_NO_CATEGORIES_SELECTED'), 'error');
         $this->app->redirect(KunenaRoute::_($this->baseurl, false));
     }
     // Update moderator rights
     $categories = KunenaForumCategoryHelper::getCategories(false, false, 'admin');
     $users = KunenaUserHelper::loadUsers($cid);
     foreach ($users as $user) {
         foreach ($categories as $category) {
             if (in_array($category->id, $catids)) {
                 $category->setModerator($user, true);
             }
         }
         // Global moderator is a special case
         if ($this->me->isAdmin() && in_array(0, $catids)) {
             KunenaAccess::getInstance()->setModerator(0, $user, true);
         }
     }
     $this->app->enqueueMessage(JText::_('COM_KUNENA_USERS_SET_MODERATORS_DONE'));
     $this->app->redirect(KunenaRoute::_($this->baseurl, false));
 }
Пример #13
0
 /**
  * Prepare displaying message.
  *
  * @return void
  *
  * @throws KunenaExceptionAuthorise
  */
 protected function before()
 {
     parent::before();
     $mesid = $this->input->getInt('mesid', 0);
     $this->me = KunenaUserHelper::getMyself();
     $this->location = $this->input->getInt('location', 0);
     $this->detail = $this->input->get('detail', false);
     $this->message = KunenaForumMessageHelper::get($mesid);
     $this->message->tryAuthorise();
     $this->topic = $this->message->getTopic();
     $this->category = $this->topic->getCategory();
     $this->profile = $this->message->getAuthor();
     $this->ktemplate = KunenaFactory::getTemplate();
     $this->captchaEnabled = false;
     if ($this->message->isAuthorised('reply') && $this->me->canDoCaptcha()) {
         if (JPluginHelper::isEnabled('captcha')) {
             $plugin = JPluginHelper::getPlugin('captcha');
             $params = new JRegistry($plugin[0]->params);
             $captcha_pubkey = $params->get('public_key');
             $catcha_privkey = $params->get('private_key');
             if (!empty($captcha_pubkey) && !empty($catcha_privkey)) {
                 JPluginHelper::importPlugin('captcha');
                 $dispatcher = JDispatcher::getInstance();
                 $result = $dispatcher->trigger('onInit', "dynamic_recaptcha_{$this->message->id}");
                 $this->captchaEnabled = $result[0];
             }
         }
     }
     // Thank you info and buttons.
     $this->thankyou = array();
     $this->total_thankyou = 0;
     $this->more_thankyou = 0;
     $this->thankyou_delete = array();
     if (isset($this->message->thankyou)) {
         if ($this->config->showthankyou && $this->profile->exists()) {
             $task = "index.php?option=com_kunena&view=topic&task=%s&catid={$this->category->id}" . "&id={$this->topic->id}&mesid={$this->message->id}&" . JSession::getFormToken() . '=1';
             // Ror normal users, show only limited number of thankyou (config->thankyou_max).
             if (!$this->me->isAdmin() && !$this->me->isModerator()) {
                 if (count($this->message->thankyou) > $this->config->thankyou_max) {
                     $this->more_thankyou = count($this->message->thankyou) - $this->config->thankyou_max;
                 }
                 $this->total_thankyou = count($this->message->thankyou);
                 $thankyous = array_slice($this->message->thankyou, 0, $this->config->thankyou_max, true);
             } else {
                 $thankyous = $this->message->thankyou;
             }
             $userids_thankyous = array();
             foreach ($thankyous as $userid => $time) {
                 $userids_thankyous[] = $userid;
             }
             $loaded_users = KunenaUserHelper::loadUsers($userids_thankyous);
             foreach ($loaded_users as $userid => $user) {
                 if ($this->message->authorise('unthankyou') && $this->me->isModerator($this->message->getCategory())) {
                     $this->thankyou_delete[$userid] = KunenaRoute::_(sprintf($task, "unthankyou&userid={$userid}"));
                 }
                 $this->thankyou[$userid] = $loaded_users[$userid]->getLink();
             }
         }
     }
     if ($this->config->reportmsg && $this->me->exists()) {
         if ($this->config->user_report && $this->me->userid == $this->message->userid && !$this->me->isModerator()) {
             $this->reportMessageLink = JHTML::_('kunenaforum.link', 'index.php?option=com_kunena&view=topic&layout=report&catid=' . intval($this->category->id) . '&id=' . intval($this->message->thread) . '&mesid=' . intval($this->message->id), JText::_('COM_KUNENA_REPORT'), JText::_('COM_KUNENA_REPORT'));
         }
     }
     // Show admins the IP address of the user.
     if ($this->category->isAuthorised('admin') || $this->category->isAuthorised('moderate') && !$this->config->hide_ip) {
         if (!empty($this->message->ip)) {
             $this->ipLink = '<a href="http://whois.domaintools.com/' . $this->message->ip . '" target="_blank"> IP: ' . $this->message->ip . '</a>';
         } else {
             $this->ipLink = '&nbsp;';
         }
     }
 }
Пример #14
0
	/**
	 * Get userids, who can moderate this category
	 **/
	public function getModerators($includeGlobal = true, $objects = true) {
		$access = KunenaFactory::getAccessControl();
		$userlist = array();
		if (!empty($this->id)) {
			$userlist += $access->getModerators($this->id);
		}
		if ($includeGlobal) {
			$userlist += $access->getModerators();
		}
		if (empty($userlist)) return $userlist;
		$userlist = array_keys($userlist);
		return $objects ? KunenaUserHelper::loadUsers($userlist) : array_combine($userlist, $userlist);
	}
Пример #15
0
 public static function load_users($system, $ids)
 {
     if (empty($ids)) {
         return;
     }
     switch ($system) {
         case 'cjforum':
             $api = JPATH_ROOT . '/components/com_cjforum/helpers/api.php';
             if (file_exists($api)) {
                 require_once $api;
                 CjForumApi::load_users($ids);
             }
             break;
         case 'cjblog':
             $api = JPATH_ROOT . DS . 'components' . DS . 'com_cjblog' . DS . 'api.php';
             if (file_exists($api)) {
                 require_once $api;
                 CjBlogApi::load_users($ids);
             }
             break;
         case 'kunena':
             if (CJFunctions::_initialize_kunena()) {
                 KunenaUserHelper::loadUsers($ids);
             }
         case 'cb':
             $api = JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php';
             if (!is_file($api)) {
                 return;
             }
             require_once $api;
             cbimport('cb.database');
             cbimport('cb.tables');
             cbimport('language.front');
             cbimport('cb.tabs');
             cbimport('cb.field');
             global $ueConfig;
             CBuser::advanceNoticeOfUsersNeeded($ids);
             break;
     }
 }
Пример #16
0
 /**
  * Prepare category display.
  *
  * @return void
  *
  * @throws KunenaExceptionAuthorise
  */
 protected function before()
 {
     parent::before();
     require_once KPATH_SITE . '/models/category.php';
     $this->model = new KunenaModelCategory();
     $this->me = KunenaUserHelper::getMyself();
     $catid = $this->input->getInt('catid');
     $limitstart = $this->input->getInt('limitstart', 0);
     $limit = $this->input->getInt('limit', 0);
     if ($limit < 1 || $limit > 100) {
         $limit = $this->config->threads_per_page;
     }
     // TODO:
     $direction = 'DESC';
     $this->category = KunenaForumCategoryHelper::get($catid);
     $this->category->tryAuthorise();
     $this->headerText = JText::_('COM_KUNENA_THREADS_IN_FORUM') . ': ' . $this->category->name;
     $topic_ordering = $this->category->topic_ordering;
     $access = KunenaAccess::getInstance();
     $hold = $access->getAllowedHold($this->me, $catid);
     $moved = 1;
     $params = array('hold' => $hold, 'moved' => $moved);
     switch ($topic_ordering) {
         case 'alpha':
             $params['orderby'] = 'tt.ordering DESC, tt.subject ASC ';
             break;
         case 'creation':
             $params['orderby'] = 'tt.ordering DESC, tt.first_post_time ' . $direction;
             break;
         case 'lastpost':
         default:
             $params['orderby'] = 'tt.ordering DESC, tt.last_post_time ' . $direction;
     }
     list($this->total, $this->topics) = KunenaForumTopicHelper::getLatestTopics($catid, $limitstart, $limit, $params);
     if ($this->total > 0) {
         // Collect user ids for avatar prefetch when integrated.
         $userlist = array();
         $lastpostlist = array();
         foreach ($this->topics as $topic) {
             $userlist[intval($topic->first_post_userid)] = intval($topic->first_post_userid);
             $userlist[intval($topic->last_post_userid)] = intval($topic->last_post_userid);
             $lastpostlist[intval($topic->last_post_id)] = intval($topic->last_post_id);
         }
         // Prefetch all users/avatars to avoid user by user queries during template iterations.
         if (!empty($userlist)) {
             KunenaUserHelper::loadUsers($userlist);
         }
         KunenaForumTopicHelper::getUserTopics(array_keys($this->topics));
         KunenaForumTopicHelper::getKeywords(array_keys($this->topics));
         $lastreadlist = KunenaForumTopicHelper::fetchNewStatus($this->topics);
         // Fetch last / new post positions when user can see unapproved or deleted posts.
         if ($lastreadlist || $this->me->isAdmin() || KunenaAccess::getInstance()->getModeratorStatus()) {
             KunenaForumMessageHelper::loadLocation($lastpostlist + $lastreadlist);
         }
     }
     $this->topicActions = $this->model->getTopicActions();
     $this->actionMove = $this->model->getActionMove();
     $this->pagination = new KunenaPagination($this->total, $limitstart, $limit);
     $this->pagination->setDisplayedPages(5);
 }
Пример #17
0
 /**
  * @param   string $query
  * @param   int    $limitstart
  * @param   int    $limit
  *
  * @return KunenaAttachment[]
  */
 protected function _getList($query, $limitstart = 0, $limit = 0)
 {
     $this->_db->setQuery($query, $limitstart, $limit);
     $ids = $this->_db->loadColumn();
     $results = KunenaAttachmentHelper::getById($ids);
     $userids = array();
     $mesids = array();
     foreach ($results as $result) {
         $userids[$result->userid] = $result->userid;
         $mesids[$result->mesid] = $result->mesid;
     }
     KunenaUserHelper::loadUsers($userids);
     KunenaForumMessageHelper::getMessages($mesids);
     return $results;
 }
Пример #18
0
 function displayThreadHistory()
 {
     if (!$this->hasThreadHistory()) {
         return;
     }
     $db = JFactory::getDBO();
     $this->history = KunenaForumMessageHelper::getMessagesByTopic($this->topic, 0, (int) $this->config->historylimit, $ordering = 'DESC');
     $this->historycount = count($this->history);
     KunenaForumMessageAttachmentHelper::getByMessage($this->history);
     $userlist = array();
     foreach ($this->history as $message) {
         $userlist[(int) $message->userid] = (int) $message->userid;
     }
     KunenaUserHelper::loadUsers($userlist);
     // Run events
     if (version_compare(JVERSION, '1.6', '>')) {
         // Joomla 1.6+
         $params = new JRegistry();
     } else {
         // Joomla 1.5
         $params = new JParameter('');
     }
     $params->set('ksource', 'kunena');
     $params->set('kunena_view', 'topic');
     $params->set('kunena_layout', 'history');
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('kunena');
     $dispatcher->trigger('onKunenaPrepare', array('kunena.messages', &$this->history, &$params, 0));
     echo $this->loadTemplateFile('history');
 }
Пример #19
0
	public function getItems() {
		static $items = false;
		if ($items === false) {
			$db = JFactory::getDBO();
			$where = $this->getQueryWhere();
			$search = $this->getQuerySearch();
			$moderator = intval(KunenaUserHelper::getMyself()->isModerator());
			$query = "SELECT *, IF(ku.hideEmail=0 OR {$moderator},u.email,'') AS email
				FROM #__users AS u
				INNER JOIN #__kunena_users AS ku ON ku.userid = u.id
				WHERE {$where} {$search}";
			$query .= " ORDER BY {$db->nameQuote($this->getState ( 'list.ordering'))} {$this->getState ( 'list.direction')}";

			$db->setQuery ( $query, $this->getState ( 'list.start'), $this->getState ( 'list.limit') );
			$items = $db->loadObjectList ('id');
			KunenaError::checkDatabaseError();

			// Prefetch all users/avatars to avoid user by user queries during template iterations
			KunenaUserHelper::loadUsers(array_keys($items));
		}
		return $items;
	}
Пример #20
0
 /**
  * Prepare category index display.
  *
  * @return void
  */
 protected function before()
 {
     parent::before();
     $this->me = KunenaUserHelper::getMyself();
     // Get sections to display.
     $catid = $this->input->getInt('catid', 0);
     if ($catid) {
         $sections = KunenaForumCategoryHelper::getCategories($catid);
     } else {
         $sections = KunenaForumCategoryHelper::getChildren();
     }
     $sectionIds = array();
     $this->more[$catid] = 0;
     foreach ($sections as $key => $category) {
         $this->categories[$category->id] = array();
         $this->more[$category->id] = 0;
         // Display only categories which are supposed to show up.
         if ($catid || $category->params->get('display.index.parent', 3) > 0) {
             if ($catid || $category->params->get('display.index.children', 3) > 1) {
                 $sectionIds[] = $category->id;
             } else {
                 $this->more[$category->id]++;
             }
         } else {
             $this->more[$category->parent_id]++;
             unset($sections[$key]);
             continue;
         }
     }
     // Get categories and subcategories.
     if (empty($sections)) {
         return;
     }
     $this->sections = $sections;
     $categories = KunenaForumCategoryHelper::getChildren($sectionIds);
     if (empty($categories)) {
         return;
     }
     $categoryIds = array();
     $topicIds = array();
     $userIds = array();
     $postIds = array();
     foreach ($categories as $key => $category) {
         $this->more[$category->id] = 0;
         // Display only categories which are supposed to show up.
         if ($catid || $category->params->get('display.index.parent', 3) > 1) {
             if ($catid || $category->getParent()->params->get('display.index.children', 3) > 2 && $category->params->get('display.index.children', 3) > 2) {
                 $categoryIds[] = $category->id;
             } else {
                 $this->more[$category->id]++;
             }
         } else {
             $this->more[$category->parent_id]++;
             unset($categories[$key]);
             continue;
         }
         // Get list of topics.
         $last = $category->getLastCategory();
         if ($last->last_topic_id) {
             $topicIds[$last->last_topic_id] = $last->last_topic_id;
         }
         $this->categories[$category->parent_id][] = $category;
         $rssURL = $category->getRSSUrl();
         if (!empty($rssURL)) {
             $category->rssURL = $category->getRSSUrl();
         }
     }
     $subcategories = KunenaForumCategoryHelper::getChildren($categoryIds);
     foreach ($subcategories as $category) {
         // Display only categories which are supposed to show up.
         if ($catid || $category->params->get('display.index.parent', 3) > 2) {
             $this->categories[$category->parent_id][] = $category;
         } else {
             $this->more[$category->parent_id]++;
         }
     }
     // Pre-fetch topics (also display unauthorized topics as they are in allowed categories).
     $topics = KunenaForumTopicHelper::getTopics($topicIds, 'none');
     // Pre-fetch users (and get last post ids for moderators).
     foreach ($topics as $topic) {
         $userIds[$topic->last_post_userid] = $topic->last_post_userid;
         $postIds[$topic->id] = $topic->last_post_id;
     }
     KunenaUserHelper::loadUsers($userIds);
     KunenaForumMessageHelper::getMessages($postIds);
     // Pre-fetch user related stuff.
     $this->pending = array();
     if ($this->me->exists() && !$this->me->isBanned()) {
         // Load new topic counts.
         KunenaForumCategoryHelper::getNewTopics(array_keys($categories + $subcategories));
         // Get categories which are moderated by current user.
         $access = KunenaAccess::getInstance();
         $moderate = $access->getAdminStatus($this->me) + $access->getModeratorStatus($this->me);
         if (!empty($moderate[0])) {
             // Global moderators.
             $moderate = $categories;
         } else {
             // Category moderators.
             $moderate = array_intersect_key($categories, $moderate);
         }
         if (!empty($moderate)) {
             // Get pending messages.
             $catlist = implode(',', array_keys($moderate));
             $db = JFactory::getDbo();
             $db->setQuery("SELECT catid, COUNT(*) AS count\n\t\t\t\t\tFROM #__kunena_messages\n\t\t\t\t\tWHERE catid IN ({$catlist}) AND hold=1\n\t\t\t\t\tGROUP BY catid");
             $pending = $db->loadAssocList();
             KunenaError::checkDatabaseError();
             foreach ($pending as $item) {
                 if ($item['count']) {
                     $this->pending[$item['catid']] = $item['count'];
                 }
             }
             if ($this->me->ordering != 0) {
                 $topic_ordering = $this->me->ordering == 1 ? true : false;
             } else {
                 $topic_ordering = $this->config->default_sort == 'asc' ? false : true;
             }
             // Fix last post position when user can see unapproved or deleted posts.
             if (!$topic_ordering) {
                 KunenaForumMessageHelper::loadLocation($postIds);
             }
         }
     }
 }
Пример #21
0
 public function getItems()
 {
     // FIXME: use pagination object and redirect on illegal page (maybe in the view)
     // TODO: should we reset to page 1 when user makes a new search?
     static $items = false;
     if ($items === false) {
         $limitstart = $this->getState('list.start');
         $limit = $this->getState('list.limit');
         $count = $this->getCount();
         if ($count < $limitstart) {
             $limitstart = $count - $count % $limit;
             $this->setState('list.start', $limitstart);
         }
         $db = JFactory::getDBO();
         $where = $this->getQueryWhere();
         $search = $this->getQuerySearch();
         $moderator = intval($this->me->isModerator());
         $query = "SELECT *, IF(ku.hideEmail=0 OR {$moderator},u.email,'') AS email\n\t\t\t\tFROM #__users AS u\n\t\t\t\tINNER JOIN #__kunena_users AS ku ON ku.userid = u.id\n\t\t\t\tWHERE {$where} {$search}";
         $query .= " ORDER BY {$db->nameQuote($this->getState('list.ordering'))} {$this->getState('list.direction')}";
         $db->setQuery($query, $limitstart, $limit);
         $items = $db->loadObjectList('id');
         KunenaError::checkDatabaseError();
         // Prefetch all users/avatars to avoid user by user queries during template iterations
         KunenaUserHelper::loadUsers(array_keys($items));
     }
     return $items;
 }
Пример #22
0
 /**
  * Prepare messages for display.
  *
  * @param   int  $mesid  Selected message Id.
  *
  * @return  void
  */
 protected function prepareMessages($mesid)
 {
     // Get thank yous for all messages in the page
     $thankyous = KunenaForumMessageThankyouHelper::getByMessage($this->messages);
     // First collect ids and users.
     $threaded = $this->layout == 'indented' || $this->layout == 'threaded';
     $userlist = array();
     $this->threaded = array();
     $location = $this->pagination->limitstart;
     foreach ($this->messages as $message) {
         $message->replynum = ++$location;
         if ($threaded) {
             // Threaded ordering
             if (isset($this->messages[$message->parent])) {
                 $this->threaded[$message->parent][] = $message->id;
             } else {
                 $this->threaded[0][] = $message->id;
             }
         }
         $userlist[(int) $message->userid] = (int) $message->userid;
         $userlist[(int) $message->modified_by] = (int) $message->modified_by;
         $thankyou_list = $thankyous[$message->id]->getList();
         $message->thankyou = array();
         if (!empty($thankyou_list)) {
             $message->thankyou = $thankyou_list;
         }
     }
     if (!isset($this->messages[$mesid]) && !empty($this->messages)) {
         $this->message = reset($this->messages);
     }
     if ($threaded) {
         if (!isset($this->messages[$this->topic->first_post_id])) {
             $this->messages = $this->getThreadedOrdering(0, array('edge'));
         } else {
             $this->messages = $this->getThreadedOrdering();
         }
     }
     // Prefetch all users/avatars to avoid user by user queries during template iterations
     KunenaUserHelper::loadUsers($userlist);
     // Prefetch attachments.
     KunenaAttachmentHelper::getByMessage($this->messages);
 }
Пример #23
0
	protected function _common() {
		if ($this->total > 0) {
			$config = KunenaFactory::getConfig ();

			// collect user ids for avatar prefetch when integrated
			$userlist = array();
			$lastpostlist = array();
			foreach ( $this->topics as $topic ) {
				$userlist[intval($topic->first_post_userid)] = intval($topic->first_post_userid);
				$userlist[intval($topic->last_post_userid)] = intval($topic->last_post_userid);
				$lastpostlist[intval($topic->last_post_id)] = intval($topic->last_post_id);
			}

			// Prefetch all users/avatars to avoid user by user queries during template iterations
			if ( !empty($userlist) ) KunenaUserHelper::loadUsers($userlist);

			KunenaForumTopicHelper::getUserTopics(array_keys($this->topics));
			KunenaForumTopicHelper::getKeywords(array_keys($this->topics));
			$lastreadlist = KunenaForumTopicHelper::fetchNewStatus($this->topics);
			// Fetch last / new post positions when user can see unapproved or deleted posts
			$me = KunenaUserHelper::get();
			if (($lastpostlist || $lastreadlist) && $me->userid && $me->isModerator()) {
				KunenaForumMessageHelper::loadLocation($lastpostlist + $lastreadlist);
			}
		}
	}
Пример #24
0
 function displayThreadHistory()
 {
     if (!$this->hasThreadHistory()) {
         return;
     }
     $this->history = KunenaForumMessageHelper::getMessagesByTopic($this->topic, 0, (int) $this->config->historylimit, $ordering = 'DESC');
     $this->historycount = count($this->history);
     $this->replycount = $this->topic->getReplies();
     KunenaAttachmentHelper::getByMessage($this->history);
     $userlist = array();
     foreach ($this->history as $message) {
         $userlist[(int) $message->userid] = (int) $message->userid;
     }
     KunenaUserHelper::loadUsers($userlist);
     // Run events
     $params = new JRegistry();
     $params->set('ksource', 'kunena');
     $params->set('kunena_view', 'topic');
     $params->set('kunena_layout', 'history');
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('kunena');
     $dispatcher->trigger('onKunenaPrepare', array('kunena.messages', &$this->history, &$params, 0));
     echo $this->loadTemplateFile('history');
 }
Пример #25
0
 public function getItems()
 {
     // FIXME: use pagination object and redirect on illegal page (maybe in the view)
     // TODO: should we reset to page 1 when user makes a new search?
     static $items = false;
     if ($items === false) {
         $limitstart = $this->getState('list.start');
         $limit = $this->getState('list.limit');
         $count = $this->getCount();
         if ($count < $limitstart) {
             $limitstart = $count - $count % $limit;
             $this->setState('list.start', $limitstart);
         }
         $db = JFactory::getDBO();
         $where = $this->getQueryWhere();
         $search = $this->getQuerySearch();
         $query = "SELECT u.id\n\t\t\t\tFROM #__users AS u\n\t\t\t\tLEFT JOIN #__kunena_users AS ku ON ku.userid = u.id\n\t\t\t\tWHERE {$where} {$search}";
         $query .= " ORDER BY {$db->quoteName($this->getState('list.ordering'))} {$this->getState('list.direction')}";
         $db->setQuery($query, $limitstart, $limit);
         $items = $db->loadColumn();
         KunenaError::checkDatabaseError();
         // Prefetch all users/avatars to avoid user by user queries during template iterations
         $items = KunenaUserHelper::loadUsers($items);
     }
     return $items;
 }
Пример #26
0
 public function getResults()
 {
     if ($this->messages !== false) {
         return $this->messages;
     }
     $q = $this->getState('searchwords');
     if (!$q && !$this->getState('query.searchuser')) {
         $this->setError(JText::_('COM_KUNENA_SEARCH_ERR_SHORTKEYWORD'));
         return array();
     }
     /* get results */
     $hold = $this->getState('query.show');
     if ($hold == 1) {
         $mode = 'unapproved';
     } elseif ($hold >= 2) {
         $mode = 'deleted';
     } else {
         $mode = 'recent';
     }
     $params = array('mode' => $mode, 'childforums' => $this->getState('query.childforums'), 'where' => $this->buildWhere(), 'orderby' => $this->buildOrderBy(), 'starttime' => -1);
     $limitstart = $this->getState('list.start');
     $limit = $this->getState('list.limit');
     list($this->total, $this->messages) = KunenaForumMessageHelper::getLatestMessages($this->getState('query.catids'), $limitstart, $limit, $params);
     if ($this->total < $limitstart) {
         $this->setState('list.start', intval($this->total / $limit) * $limit);
     }
     $topicids = array();
     $userids = array();
     foreach ($this->messages as $message) {
         $topicids[$message->thread] = $message->thread;
         $userids[$message->userid] = $message->userid;
     }
     if ($topicids) {
         $topics = KunenaForumTopicHelper::getTopics($topicids);
         foreach ($topics as $topic) {
             $userids[$topic->first_post_userid] = $topic->first_post_userid;
         }
     }
     KunenaUserHelper::loadUsers($userids);
     KunenaForumMessageHelper::loadLocation($this->messages);
     if (empty($this->messages)) {
         $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_SEARCH_NORESULTS_FOUND', $q));
     }
     return $this->messages;
 }
Пример #27
0
 /**
  * Method to get User objects of data items.
  *
  * @return  KunenaUser  List of KunenaUser objects found.
  *
  * @since   3.0
  */
 public function getItems()
 {
     // Get a storage key.
     $store = $this->getStoreId();
     // Try to load the data from internal storage.
     if (isset($this->cache[$store])) {
         return $this->cache[$store];
     }
     // Load the list items.
     $query = $this->_getListQuery();
     $items = $this->_getList($query, $this->getStart(), $this->getState('list.limit'));
     // Check for a database error.
     if ($this->_db->getErrorNum()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     $ids = array();
     foreach ($items as $item) {
         $ids[] = $item->id;
     }
     $instances = KunenaUserHelper::loadUsers($ids);
     // Add the items to the internal cache.
     $this->cache[$store] = $instances;
     return $this->cache[$store];
 }
Пример #28
0
 /**
  *
  */
 function displayBanManager()
 {
     // TODO: move ban manager somewhere else and add pagination
     $this->bannedusers = KunenaUserBan::getBannedUsers(0, 50);
     if (!empty($this->bannedusers)) {
         KunenaUserHelper::loadUsers(array_keys($this->bannedusers));
     }
     echo $this->loadTemplateFile('banmanager');
 }
Пример #29
0
	function displayWhosonline($tpl = null) {
		$moderator = intval($this->me->isModerator());
		$cache = JFactory::getCache('com_kunena', 'output');
		if ($cache->start("{$this->template->name}.common.whosonline.{$moderator}", "com_kunena.template")) return;

		$this->my = JFactory::getUser();

		$users = KunenaUserHelper::getOnlineUsers();
		KunenaUserHelper::loadUsers(array_keys($users));
		$onlineusers = KunenaUserHelper::getOnlineCount();

		$who = '<strong>'.$onlineusers['user'].' </strong>';
		if($onlineusers['user']==1) {
			$who .= JText::_('COM_KUNENA_WHO_ONLINE_MEMBER').'&nbsp;';
		} else {
			$who .= JText::_('COM_KUNENA_WHO_ONLINE_MEMBERS').'&nbsp;';
		}
		$who .= JText::_('COM_KUNENA_WHO_AND');
		$who .= '<strong> '. $onlineusers['guest'].' </strong>';
		if($onlineusers['guest']==1) {
			$who .= JText::_('COM_KUNENA_WHO_ONLINE_GUEST').'&nbsp;';
		} else {
			$who .= JText::_('COM_KUNENA_WHO_ONLINE_GUESTS').'&nbsp;';
		}
		$who .= JText::_('COM_KUNENA_WHO_ONLINE_NOW');
		$this->membersOnline = $who;

		$this->onlineList = array();
		$this->hiddenList = array();
		foreach ($users as $userid=>$usertime) {
			$user = KunenaUserHelper::get($userid);
			if ( !$user->showOnline ) {
				if ($this->me->isModerator()) $this->hiddenList[$user->getName()] = $user;
			} else {
				$this->onlineList[$user->getName()] = $user;
			}
		}
		ksort($this->onlineList);
		ksort($this->hiddenList);

		$this->usersURL = KunenaRoute::_('index.php?option=com_kunena&view=user&layout=list');

		$result = $this->loadTemplate($tpl);
		if (JError::isError($result)) {
			return $result;
		}
		echo $result;
		$cache->end();
	}
Пример #30
0
 public function getTopics()
 {
     if ($this->topics === false) {
         $catid = $this->getState('item.id');
         $limitstart = $this->getState('list.start');
         $limit = $this->getState('list.limit');
         $format = $this->getState('format');
         $topic_ordering = $this->getCategory()->topic_ordering;
         $access = KunenaAccess::getInstance();
         $hold = $format == 'feed' ? 0 : $access->getAllowedHold($this->me, $catid);
         $moved = $format == 'feed' ? 0 : 1;
         $params = array('hold' => $hold, 'moved' => $moved);
         switch ($topic_ordering) {
             case 'alpha':
                 $params['orderby'] = 'tt.ordering DESC, tt.subject ASC ';
                 break;
             case 'creation':
                 $params['orderby'] = 'tt.ordering DESC, tt.first_post_time ' . strtoupper($this->getState('list.direction'));
                 break;
             case 'lastpost':
             default:
                 $params['orderby'] = 'tt.ordering DESC, tt.last_post_time ' . strtoupper($this->getState('list.direction'));
         }
         if ($format == 'feed') {
             $catid = array_keys(KunenaForumCategoryHelper::getChildren($catid, 100) + array($catid => 1));
         }
         list($this->total, $this->topics) = KunenaForumTopicHelper::getLatestTopics($catid, $limitstart, $limit, $params);
         if ($this->total > 0) {
             // collect user ids for avatar prefetch when integrated
             $userlist = array();
             $lastpostlist = array();
             foreach ($this->topics as $topic) {
                 $userlist[intval($topic->first_post_userid)] = intval($topic->first_post_userid);
                 $userlist[intval($topic->last_post_userid)] = intval($topic->last_post_userid);
                 $lastpostlist[intval($topic->last_post_id)] = intval($topic->last_post_id);
             }
             // Prefetch all users/avatars to avoid user by user queries during template iterations
             if (!empty($userlist)) {
                 KunenaUserHelper::loadUsers($userlist);
             }
             KunenaForumTopicHelper::getUserTopics(array_keys($this->topics));
             KunenaForumTopicHelper::getKeywords(array_keys($this->topics));
             $lastreadlist = KunenaForumTopicHelper::fetchNewStatus($this->topics);
             // Fetch last / new post positions when user can see unapproved or deleted posts
             if (($lastpostlist || $lastreadlist) && ($this->me->isAdmin() || KunenaAccess::getInstance()->getModeratorStatus())) {
                 KunenaForumMessageHelper::loadLocation($lastpostlist + $lastreadlist);
             }
         }
     }
     return $this->topics;
 }