Beispiel #1
0
 /**
  * Filter by user access to the categories.
  *
  * It is very important to use this or category filter. Otherwise topics from unauthorized categories will be
  * included to the search results.
  *
  * @param KunenaUser $user
  *
  * @return $this
  */
 public function filterByUserAccess(KunenaUser $user)
 {
     $categories = $user->getAllowedCategories();
     $list = implode(',', $categories);
     $this->query->where("a.category_id IN ({$list})");
     return $this;
 }
Beispiel #2
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);
     }
 }
Beispiel #3
0
 /**
  * Prepare ban form.
  *
  * @return void
  *
  * @throws KunenaExceptionAuthorise
  */
 protected function before()
 {
     parent::before();
     $userid = $this->input->getInt('userid');
     $this->profile = KunenaUserHelper::get($userid);
     $this->profile->tryAuthorise('ban');
     $this->banInfo = KunenaUserBan::getInstanceByUserid($userid, true);
     $this->headerText = $this->banInfo->exists() ? JText::_('COM_KUNENA_BAN_EDIT') : JText::_('COM_KUNENA_BAN_NEW');
 }
Beispiel #4
0
 /**
  * Prepare document.
  *
  * @return void
  */
 protected function prepareDocument()
 {
     $title = JText::sprintf('COM_KUNENA_VIEW_USER_DEFAULT', $this->profile->getName());
     $this->setTitle($title);
     $keywords = $this->config->board_title . ', ' . $this->profile->getName();
     $this->setKeywords($keywords);
     $description = JText::sprintf('COM_KUNENA_META_PROFILE', $this->profile->getName(), $this->config->board_title, $this->profile->getName(), $this->config->board_title);
     $this->setDescription($description);
 }
Beispiel #5
0
 /**
  * Prepare ban history.
  *
  * @return void
  *
  * @throws KunenaExceptionAuthorise
  */
 protected function before()
 {
     parent::before();
     $userid = $this->input->getInt('userid');
     $this->me = KunenaUserHelper::getMyself();
     $this->profile = KunenaUserHelper::get($userid);
     $this->profile->tryAuthorise('ban');
     $this->banHistory = KunenaUserBan::getUserHistory($this->profile->userid);
     $this->headerText = JText::sprintf('COM_KUNENA_BAN_BANHISTORYFOR', $this->profile->getName());
 }
Beispiel #6
0
 /**
  * Prepare user for editing.
  *
  * @return void
  *
  * @throws KunenaExceptionAuthorise
  */
 protected function before()
 {
     parent::before();
     // If profile integration is disabled, this view doesn't exist.
     $integration = KunenaFactory::getProfile();
     if (get_class($integration) == 'KunenaProfileNone') {
         throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_PROFILE_DISABLED'), 404);
     }
     $userid = $this->input->getInt('userid');
     $this->user = JFactory::getUser($userid);
     $this->profile = KunenaUserHelper::get($userid);
     $this->profile->tryAuthorise('edit');
     $this->headerText = JText::sprintf('COM_KUNENA_VIEW_USER_DEFAULT', $this->profile->getName());
 }
Beispiel #7
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);
 }
Beispiel #8
0
	/**
	 * Prepare document.
	 *
	 * @return void
	 */
	protected function prepareDocument()
	{
		$app       = JFactory::getApplication();
		$menu_item = $app->getMenu()->getActive(); // get the active item

		if ($menu_item)
		{
			$params             = $menu_item->params; // get the params
			$params_title       = $params->get('page_title');
			$params_keywords    = $params->get('menu-meta_keywords');
			$params_description = $params->get('menu-meta_description');

			if (!empty($params_title))
			{
				$title = $params->get('page_title');
				$this->setTitle($title);
			}
			else
			{
				$title = JText::sprintf('COM_KUNENA_VIEW_USER_DEFAULT', $this->profile->getName());
				$this->setTitle($title);
			}

			if (!empty($params_keywords))
			{
				$keywords = $params->get('menu-meta_keywords');
				$this->setKeywords($keywords);
			}
			else
			{
				$keywords = $this->config->board_title . ', ' . $this->profile->getName();
				$this->setKeywords($keywords);
			}

			if (!empty($params_description))
			{
				$description = $params->get('menu-meta_description');
				$this->setDescription($description);
			}
			else
			{
				$description = JText::sprintf('COM_KUNENA_META_PROFILE', $this->profile->getName(), $this->config->board_title, $this->profile->getName(), $this->config->board_title);
				$this->setDescription($description);
			}
		}
	}
Beispiel #9
0
 protected function before()
 {
     KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . get_class($this) . '::' . __FUNCTION__ . '()') : null;
     if (!$this->exists()) {
         KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . get_class($this) . '::' . __FUNCTION__ . '()') : null;
         throw new RuntimeException("Layout '{$this->input->getWord('view')}/{$this->input->getWord('layout', 'default')}' does not exist!", 404);
     }
     // Load language files.
     KunenaFactory::loadLanguage('com_kunena.sys', 'admin');
     KunenaFactory::loadLanguage('com_kunena.templates');
     KunenaFactory::loadLanguage('com_kunena.models');
     KunenaFactory::loadLanguage('com_kunena.views');
     $this->me = KunenaUserHelper::getMyself();
     $this->config = KunenaConfig::getInstance();
     $this->document = JFactory::getDocument();
     $this->template = KunenaFactory::getTemplate();
     $this->template->initialize();
     if ($this->me->isAdmin()) {
         // Display warnings to the administrator if forum is either offline or debug has been turned on.
         if ($this->config->board_offline) {
             $this->app->enqueueMessage(JText::_('COM_KUNENA_FORUM_IS_OFFLINE'), 'notice');
         }
         if ($this->config->debug) {
             $this->app->enqueueMessage(JText::_('COM_KUNENA_WARNING_DEBUG'), 'notice');
         }
     }
     if ($this->me->isBanned()) {
         // Display warnings to the banned users.
         $banned = KunenaUserBan::getInstanceByUserid($this->me->userid, true);
         if (!$banned->isLifetime()) {
             $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_POST_ERROR_USER_BANNED_NOACCESS_EXPIRY', KunenaDate::getInstance($banned->expiration)->toKunena('date_today')), 'notice');
         } else {
             $this->app->enqueueMessage(JText::_('COM_KUNENA_POST_ERROR_USER_BANNED_NOACCESS'), 'notice');
         }
     }
     // Remove base and add canonical link.
     $this->document->setBase('');
     $this->document->addHeadLink(KunenaRoute::_(), 'canonical', 'rel', '');
     // Initialize breadcrumb.
     $this->breadcrumb = $this->app->getPathway();
     KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . get_class($this) . '::' . __FUNCTION__ . '()') : null;
 }
Beispiel #10
0
 /**
  * Check if user has the right to upload file attachment
  *
  * @param KunenaUser $user
  * @return KunenaExceptionAuthorise|NULL
  */
 protected function authoriseAttachmentsFile(KunenaUser $user)
 {
     if (empty(KunenaFactory::getConfig()->file_upload)) {
         return new KunenaExceptionAuthorise(JText::_('COM_KUNENA_POST_ATTACHMENTS_NOT_ALLOWED'), 403);
     }
     if (KunenaFactory::getConfig()->file_upload == 'admin') {
         if (!$user->isAdmin()) {
             return new KunenaExceptionAuthorise(JText::_('COM_KUNENA_POST_ATTACHMENTS_FILE_ONLY_FOR_ADMINISTRATORS'), 403);
         }
     }
     if (KunenaFactory::getConfig()->file_upload == 'registered') {
         if (!$user->userid) {
             return new KunenaExceptionAuthorise(JText::_('COM_KUNENA_POST_ATTACHMENTS_FILE_ONLY_FOR_REGISTERED_USERS'), 403);
         }
     }
     if (KunenaFactory::getConfig()->file_upload == 'moderator') {
         if (!$user->isModerator()) {
             return new KunenaExceptionAuthorise(JText::_('COM_KUNENA_POST_ATTACHMENTS_FILE_ONLY_FOR_MODERATORS'), 403);
         }
     }
     return null;
 }
Beispiel #11
0
 protected function authoriseOwn(KunenaUser $user)
 {
     // Checks if attachment is users own or user is moderator in the category (or global)
     if ($user->userid && $this->userid != $user->userid && !$user->isModerator($this->getMessage()->getCategory())) {
         $this->setError(JText::_('COM_KUNENA_NO_ACCESS'));
         return false;
     }
     return true;
 }
Beispiel #12
0
 /**
  * @param array $userids
  *
  * @return array
  */
 public static function loadUsers(array $userids = array())
 {
     KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
     // Make sure that userids are unique and that indexes are correct
     $e_userids = array();
     foreach ($userids as $userid) {
         // Ignore guests and imported users, which haven't been mapped to Joomla (id<0).
         if ($userid > 0 && empty(self::$_instances[$userid])) {
             $e_userids[(int) $userid] = (int) $userid;
         }
     }
     if (!empty($e_userids)) {
         $userlist = implode(',', $e_userids);
         $db = JFactory::getDBO();
         $query = "SELECT u.name, u.username, u.email, u.block as blocked, u.registerDate, u.lastvisitDate, ku.*, u.id AS userid\n\t\t\t\tFROM #__users AS u\n\t\t\t\tLEFT JOIN #__kunena_users AS ku ON u.id = ku.userid\n\t\t\t\tWHERE u.id IN ({$userlist})";
         $db->setQuery($query);
         $results = $db->loadAssocList();
         KunenaError::checkDatabaseError();
         foreach ($results as $user) {
             $instance = new KunenaUser(false);
             $instance->setProperties($user);
             $instance->exists(isset($user['posts']));
             self::$_instances[$instance->userid] = $instance;
         }
         // Preload avatars if configured
         $avatars = KunenaFactory::getAvatarIntegration();
         $avatars->load($e_userids);
     }
     $list = array();
     foreach ($userids as $userid) {
         if (isset(self::$_instances[$userid])) {
             $list[$userid] = self::$_instances[$userid];
         }
     }
     KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
     return $list;
 }
Beispiel #13
0
 /**
  * @param KunenaUser $user
  *
  * @return KunenaExceptionAuthorise|null
  */
 protected function authoriseAdmin(KunenaUser $user)
 {
     // Check that user is admin
     if (!$user->userid) {
         return new KunenaExceptionAuthorise(JText::_('COM_KUNENA_MODERATION_ERROR_NOT_ADMIN'), 401);
     }
     if (!$user->isAdmin($this)) {
         return new KunenaExceptionAuthorise(JText::_('COM_KUNENA_MODERATION_ERROR_NOT_ADMIN'), 403);
     }
     return null;
 }
Beispiel #14
0
	/**
	 * @param KunenaUser $user
	 *
	 * @return bool
	 */
	protected function authoriseDelete(KunenaUser $user) {
		$config = KunenaFactory::getConfig();
		if (!$user->isModerator($this->getCategory())
				&& $config->userdeletetmessage != '2' && ($config->userdeletetmessage == '0' || $this->getTopic()->last_post_id != $this->id)) {
			$this->setError (JText::_ ( 'COM_KUNENA_POST_ERROR_DELETE_REPLY_AFTER' ) );
			return false;
		}
		return true;
	}
Beispiel #15
0
 /**
  * @param KunenaUser $user
  *
  * @return KunenaExceptionAuthorise|null
  *
  * @since  K4.0
  */
 protected function authoriseOwn(KunenaUser $user)
 {
     // Checks if attachment is users own or user is moderator in the category (or global)
     if ($user->userid && $this->userid != $user->userid && !$user->isModerator($this->getMessage()->getCategory())) {
         return new KunenaExceptionAuthorise(JText::_('COM_KUNENA_ATTACHMENT_NO_ACCESS'), 403);
     }
     return null;
 }
Beispiel #16
0
 public static function loadUsers(array $userids = array())
 {
     // Make sure that userids are unique and that indexes are correct
     $e_userids = array();
     foreach ($userids as &$userid) {
         if (!$userid || $userid != intval($userid)) {
             unset($userid);
         } elseif (empty(self::$_instances[$userid])) {
             $e_userids[$userid] = $userid;
         }
     }
     if (!empty($e_userids)) {
         $userlist = implode(',', $e_userids);
         $db = JFactory::getDBO();
         $query = "SELECT u.name, u.username, u.email, u.block as blocked, u.registerDate, u.lastvisitDate, ku.*\n\t\t\t\tFROM #__users AS u\n\t\t\t\tLEFT JOIN #__kunena_users AS ku ON u.id = ku.userid\n\t\t\t\tWHERE u.id IN ({$userlist})";
         $db->setQuery($query);
         $results = $db->loadAssocList();
         KunenaError::checkDatabaseError();
         foreach ($results as $user) {
             $instance = new KunenaUser(false);
             $instance->setProperties($user);
             $instance->exists(true);
             self::$_instances[$instance->userid] = $instance;
         }
         // Preload avatars if configured
         $avatars = KunenaFactory::getAvatarIntegration();
         $avatars->load($e_userids);
     }
     $list = array();
     foreach ($userids as $userid) {
         if (isset(self::$_instances[$userid])) {
             $list[$userid] = self::$_instances[$userid];
         }
     }
     return $list;
 }
Beispiel #17
0
 protected function _common()
 {
     $this->totalpages = ceil($this->total / $this->threads_per_page);
     if (!empty($this->threadids)) {
         $idstr = implode(",", $this->threadids);
         if (empty($this->loadids)) {
             $loadstr = '';
         } else {
             $loadstr = 'OR a.id IN (' . implode(",", $this->loadids) . ')';
         }
         $query = "SELECT a.*, j.id AS userid, t.message, l.myfavorite, l.favcount, l.threadhits, l.lasttime, l.threadattachments, COUNT(aa.id) AS attachments,\n\t\t\t\tl.msgcount, l.mycount, l.lastid, l.mylastid, l.lastid AS lastread, 0 AS unread, u.avatar, j.username, j.name AS uname, c.name AS catname, c.class_sfx\n\t\t\tFROM (\n\t\t\t\tSELECT m.thread, MAX(m.hits) AS threadhits, MAX(f.userid IS NOT null AND f.userid={$this->db->Quote($this->my->id)}) AS myfavorite, COUNT(DISTINCT f.userid) AS favcount,\n\t\t\t\t\tCOUNT(DISTINCT a.id) AS threadattachments, COUNT(DISTINCT m.id) AS msgcount, COUNT(DISTINCT IF(m.userid={$this->db->Quote($this->user->id)}, m.id, NULL)) AS mycount,\n\t\t\t\t\tMAX(m.id) AS lastid, MAX(IF(m.userid={$this->db->Quote($this->user->id)}, m.id, 0)) AS mylastid, MAX(m.time) AS lasttime\n\t\t\t\tFROM #__kunena_messages AS m";
         if ($this->config->allowfavorites) {
             $query .= " LEFT JOIN #__kunena_favorites AS f ON f.thread = m.thread";
         } else {
             $query .= " LEFT JOIN #__kunena_favorites AS f ON f.thread = 0";
         }
         $query .= "\n\t\t\t\tLEFT JOIN #__kunena_attachments AS a ON a.mesid = m.id\n\t\t\t\tWHERE m.hold IN ({$this->hold}) AND m.moved='0' AND m.thread IN ({$idstr})\n\t\t\t\tGROUP BY thread\n\t\t\t) AS l\n\t\t\tINNER JOIN #__kunena_messages AS a ON a.thread = l.thread\n\t\t\tINNER JOIN #__kunena_messages_text AS t ON a.id = t.mesid\n\t\t\tLEFT JOIN #__users AS j ON j.id = a.userid\n\t\t\tLEFT JOIN #__kunena_users AS u ON u.userid = j.id\n\t\t\tLEFT JOIN #__kunena_categories AS c ON c.id = a.catid\n\t\t\tLEFT JOIN #__kunena_attachments AS aa ON aa.mesid = a.id\n\t\t\tWHERE (a.parent='0' OR a.id=l.lastid {$loadstr})\n\t\t\tGROUP BY a.id\n\t\t\tORDER BY {$this->order}";
         $this->db->setQuery($query);
         $this->messages = $this->db->loadObjectList('id');
         KunenaError::checkDatabaseError();
         // collect user ids for avatar prefetch when integrated
         $userlist = array();
         foreach ($this->messages as $message) {
             if ($message->parent == 0) {
                 $this->threads[$message->thread] = $message;
                 $routerlist[$message->id] = $message->subject;
                 if ($this->func == 'mylatest' && $message->myfavorite) {
                     $this->highlight++;
                 }
             }
             if ($message->id == $message->lastid) {
                 $this->lastreply[$message->thread] = $message;
             }
             if (isset($this->loadids) && in_array($message->id, $this->loadids)) {
                 $this->customreply[$message->id] = $message;
             }
             $userlist[intval($message->userid)] = intval($message->userid);
             $userlist[intval($message->modified_by)] = intval($message->modified_by);
         }
         // Load threads to Kunena router to avoid extra SQL queries
         if (!empty($routerlist)) {
             include_once KUNENA_PATH . '/router.php';
             KunenaRouter::loadMessages($routerlist);
         }
         // Prefetch all users/avatars to avoid user by user queries during template iterations
         KunenaUser::loadUsers($userlist);
         if ($this->config->shownew && $this->my->id) {
             $readlist = $this->session->readtopics;
             $this->db->setQuery("SELECT thread, MIN(id) AS lastread, SUM(1) AS unread FROM #__kunena_messages " . "WHERE hold IN ({$this->hold}) AND moved='0' AND thread NOT IN ({$readlist}) AND thread IN ({$idstr}) AND time>{$this->db->Quote($this->prevCheck)} GROUP BY thread");
             // TODO: check input
             $msgidlist = $this->db->loadObjectList();
             KunenaError::checkDatabaseError();
             foreach ($msgidlist as $msgid) {
                 $this->messages[$msgid->thread]->lastread = $msgid->lastread;
                 $this->messages[$msgid->thread]->unread = $msgid->unread;
             }
         }
     }
 }
 /**
  * Puts user forum settings into object
  *
  * @param moscomprofilerUser $user
  * @param object             $forum
  * @param mixed              $additional
  * @return object
  */
 function getUserSettings($user, $forum, $additional = null)
 {
     global $_CB_database;
     static $cache = array();
     if (!isset($cache[$user->id])) {
         if ($forum->prefix != 'kunena' || $forum->prefix == 'kunena' && !class_exists('KunenaForum')) {
             $query = 'SELECT f.*' . $additional . "\n FROM " . $_CB_database->NameQuote('#__' . $forum->prefix . '_users') . 'AS f' . ', ' . $_CB_database->NameQuote('#__users') . 'AS u' . "\n WHERE f." . $_CB_database->NameQuote('userid') . " = u." . $_CB_database->NameQuote('id') . "\n AND f." . $_CB_database->NameQuote('userid') . " = " . (int) $user->id;
             $_CB_database->setQuery($query, 0, 1);
             $settings = null;
             $_CB_database->loadObject($settings);
         } elseif (class_exists('KunenaUser')) {
             $settings = KunenaUser::getInstance((int) $user->id);
         } else {
             $settings = null;
         }
         $cache[$user->id] = $settings ? $settings : null;
     }
     return $cache[$user->id];
 }
 public function getTotalGuestUsers()
 {
     if (!$this->config->regonly) {
         $count = KunenaUser::getOnlineCount();
         return $count['guest'];
     }
     return 0;
 }
Beispiel #20
0
	static public function loadUsers($userids = array()) {
		if (!is_array($userids)) {
			JError::raiseError ( 500, __CLASS__ . '::' . __FUNCTION__.'(): Parameter $userids is not array' );
		}

		// Make sure that userids are unique and that indexes are correct
		$e_userids = array();
		foreach($userids as $userid){
			if (empty ( self::$_instances [intval($userid)] )) $e_userids[intval($userid)] = intval($userid);
		}
		unset($e_userids[0]);
		if (empty($e_userids)) return array();

		$userlist = implode ( ',', $e_userids );

		$db = JFactory::getDBO ();
		$query = "SELECT u.name, u.username, u.email, u.block as blocked, u.registerDate, u.lastvisitDate, ku.*
			FROM #__users AS u
			LEFT JOIN #__kunena_users AS ku ON u.id = ku.userid
			WHERE u.id IN ({$userlist})";
		$db->setQuery ( $query );
		$results = $db->loadAssocList ();
		KunenaError::checkDatabaseError ();

		$list = array ();
		foreach ( $results as $user ) {
			$instance = new KunenaUser (false);
			$instance->setProperties ( $user );
			$instance->exists(true);
			self::$_instances [$instance->userid] = $instance;
		}

		// Finally call integration preload as well
		// Preload avatars if configured
		$avatars = KunenaFactory::getAvatarIntegration();
		$avatars->load($userids);

		foreach ($userids as $userid) {
			if (isset(self::$_instances [$userid])) $list [$userid] = self::$_instances [$userid];
		}
		return $list;
	}
Beispiel #21
0
 /**
  * @param KunenaUser $user
  *
  * @return null|string
  */
 protected function authoriseUnlocked(KunenaUser $user)
 {
     // Check that topic is not locked or user is a moderator
     if ($this->locked && !$user->isModerator($this->getCategory())) {
         return JText::_('COM_KUNENA_POST_ERROR_TOPIC_LOCKED');
     }
     return null;
 }
Beispiel #22
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);
             }
         }
     }
 }
Beispiel #23
0
 /**
  * @param int        $catid    Category Id for the rank (user can have different rank in different categories).
  * @param string     $type     Possible values: 'title' | 'image' | false (for object).
  * @param bool|null  $special  True if special only, false if post count, otherwise combined.
  *
  * @return stdClass|string|null
  */
 public function getRank($catid = 0, $type = null, $special = null)
 {
     $config = KunenaConfig::getInstance();
     if (!$config->showranking) {
         return null;
     }
     // Guests do not have post rank, they only have special rank.
     if ($special === false && !$this->userid) {
         return null;
     }
     // First run? Initialize ranks.
     if (self::$_ranks === null) {
         $this->_db->setQuery("SELECT * FROM #__kunena_ranks");
         self::$_ranks = $this->_db->loadObjectList('rank_id');
         KunenaError::checkDatabaseError();
     }
     $userType = $special !== false ? $this->getType($catid, true) : 'count';
     if (isset(self::$_ranks[$this->rank]) && !in_array($userType, array('guest', 'blocked', 'banned', 'count'))) {
         // Use rank specified to the user.
         $rank = self::$_ranks[$this->rank];
     } else {
         // Generate user rank.
         $rank = new stdClass();
         $rank->rank_id = 0;
         $rank->rank_title = JText::_('COM_KUNENA_RANK_USER');
         $rank->rank_min = 0;
         $rank->rank_special = 0;
         $rank->rank_image = 'rank0.gif';
         switch ($userType) {
             case 'guest':
                 $rank->rank_title = JText::_('COM_KUNENA_RANK_VISITOR');
                 $rank->rank_special = 1;
                 foreach (self::$_ranks as $cur) {
                     if ($cur->rank_special == 1 && strstr($cur->rank_image, 'guest')) {
                         $rank = $cur;
                         break;
                     }
                 }
                 break;
             case 'blocked':
                 $rank->rank_title = JText::_('COM_KUNENA_RANK_BLOCKED');
                 $rank->rank_special = 1;
                 $rank->rank_image = 'rankdisabled.gif';
                 foreach (self::$_ranks as $cur) {
                     if ($cur->rank_special == 1 && strstr($cur->rank_image, 'disabled')) {
                         $rank = $cur;
                         break;
                     }
                 }
                 break;
             case 'banned':
                 $rank->rank_title = JText::_('COM_KUNENA_RANK_BANNED');
                 $rank->rank_special = 1;
                 $rank->rank_image = 'rankbanned.gif';
                 foreach (self::$_ranks as $cur) {
                     if ($cur->rank_special == 1 && strstr($cur->rank_image, 'banned')) {
                         $rank = $cur;
                         break;
                     }
                 }
                 break;
             case 'admin':
             case 'localadmin':
                 $rank->rank_title = JText::_('COM_KUNENA_RANK_ADMINISTRATOR');
                 $rank->rank_special = 1;
                 $rank->rank_image = 'rankadmin.gif';
                 foreach (self::$_ranks as $cur) {
                     if ($cur->rank_special == 1 && strstr($cur->rank_image, 'admin')) {
                         $rank = $cur;
                         break;
                     }
                 }
                 break;
             case 'globalmod':
             case 'moderator':
                 $rank->rank_title = JText::_('COM_KUNENA_RANK_MODERATOR');
                 $rank->rank_special = 1;
                 $rank->rank_image = 'rankmod.gif';
                 foreach (self::$_ranks as $cur) {
                     if ($cur->rank_special == 1 && (strstr($cur->rank_image, 'rankmod') || strstr($cur->rank_image, 'moderator'))) {
                         $rank = $cur;
                         break;
                     }
                 }
                 break;
             case 'user':
             case 'count':
                 foreach (self::$_ranks as $cur) {
                     if ($cur->rank_special == 0 && $cur->rank_min <= $this->posts && $cur->rank_min >= $rank->rank_min) {
                         $rank = $cur;
                     }
                 }
                 break;
         }
     }
     if ($special === true && !$rank->rank_special) {
         return null;
     }
     if ($type == 'title') {
         return $rank->rank_title;
     }
     if (!$config->rankimages) {
         $rank->rank_image = null;
     }
     if ($type == 'image') {
         if (!$rank->rank_image) {
             return null;
         }
         $url = KunenaTemplate::getInstance()->getRankPath($rank->rank_image, true);
         return '<img src="' . $url . '" alt="" />';
     }
     return $rank;
 }
Beispiel #24
0
 /**
  * Prepare topic display.
  *
  * @return void
  *
  * @throws KunenaExceptionAuthorise
  */
 protected function before()
 {
     parent::before();
     $catid = $this->input->getInt('catid', 0);
     $id = $this->input->getInt('id', 0);
     $mesid = $this->input->getInt('mesid', 0);
     $start = $this->input->getInt('limitstart', 0);
     $limit = $this->input->getInt('limit', 0);
     if ($limit < 1 || $limit > 100) {
         $limit = $this->config->messages_per_page;
     }
     $this->me = KunenaUserHelper::getMyself();
     // Load topic and message.
     if ($mesid) {
         // If message was set, use it to find the current topic.
         $this->message = KunenaForumMessageHelper::get($mesid);
         $this->topic = $this->message->getTopic();
     } else {
         // Note that redirect loops throw RuntimeException because of we added KunenaForumTopic::getTopic() call!
         $this->topic = KunenaForumTopicHelper::get($id)->getTopic();
         $this->message = KunenaForumMessageHelper::get($this->topic->first_post_id);
     }
     // Load also category (prefer the URI variable if available).
     if ($catid && $catid != $this->topic->category_id) {
         $this->category = KunenaForumCategoryHelper::get($catid);
         $this->category->tryAuthorise();
     } else {
         $this->category = $this->topic->getCategory();
     }
     // Access check.
     $this->message->tryAuthorise();
     // Check if we need to redirect (category or topic mismatch, or resolve permanent URL).
     if ($this->primary) {
         $channels = $this->category->getChannels();
         if ($this->message->thread != $this->topic->id || $this->topic->category_id != $this->category->id && !isset($channels[$this->topic->category_id]) || $mesid && $this->layout != 'threaded') {
             while (@ob_end_clean()) {
             }
             $this->app->redirect($this->message->getUrl(null, false));
         }
     }
     // Load messages from the current page and set the pagination.
     $hold = KunenaAccess::getInstance()->getAllowedHold($this->me, $this->category->id, false);
     $finder = new KunenaForumMessageFinder();
     $finder->where('thread', '=', $this->topic->id)->filterByHold($hold);
     $start = $mesid ? $this->topic->getPostLocation($mesid) : $start;
     $this->pagination = new KunenaPagination($finder->count(), $start, $limit);
     $this->messages = $finder->order('time', $this->me->getMessageOrdering() == 'asc' ? 1 : -1)->start($this->pagination->limitstart)->limit($this->pagination->limit)->find();
     $this->prepareMessages($mesid);
     // Run events.
     $params = new JRegistry();
     $params->set('ksource', 'kunena');
     $params->set('kunena_view', 'topic');
     $params->set('kunena_layout', 'default');
     $dispatcher = JEventDispatcher::getInstance();
     JPluginHelper::importPlugin('kunena');
     $dispatcher->trigger('onKunenaPrepare', array('kunena.topic', &$this->topic, &$params, 0));
     $dispatcher->trigger('onKunenaPrepare', array('kunena.messages', &$this->messages, &$params, 0));
     // Get user data, captcha & quick reply.
     $this->userTopic = $this->topic->getUserTopic();
     $this->quickReply = $this->topic->isAuthorised('reply') && $this->me->exists();
     $this->headerText = JText::_('COM_KUNENA_TOPIC') . ' ' . html_entity_decode($this->topic->displayField('subject'));
 }
Beispiel #25
0
 /**
  * @param KunenaUser $user
  *
  * @return null|string
  */
 protected function authoriseOwn(KunenaUser $user)
 {
     // Guests cannot own a topic.
     if (!$user->exists()) {
         return new KunenaExceptionAuthorise(JText::_('COM_KUNENA_POST_NOT_MODERATOR'), 401);
     }
     // Check that topic owned by the user or user is a moderator
     $usertopic = $this->getUserTopic($user);
     if (!$usertopic->owner && !$user->isModerator($this->getCategory())) {
         return new KunenaExceptionAuthorise(JText::_('COM_KUNENA_POST_NOT_MODERATOR'), 403);
     }
     return null;
 }
Beispiel #26
0
 function loadCategories()
 {
     if ($this->_loaded) {
         return;
     }
     $this->_loaded = true;
     $catids = array();
     foreach ($this->categories[0] as $cat) {
         $catids[] = $cat->id;
     }
     if (empty($catids)) {
         return;
     }
     $catlist = implode(',', $catids);
     $readlist = $this->session->readtopics;
     if ($this->config->shownew && $this->my->id) {
         $subquery = " (SELECT COUNT(DISTINCT thread) FROM #__kunena_messages AS mmm WHERE c.id=mmm.catid AND mmm.hold='0' AND mmm.time>{$this->db->Quote($this->prevCheck)} AND mmm.thread NOT IN ({$readlist})) AS new";
     } else {
         $subquery = " 0 AS new";
     }
     // TODO: optimize this query (just combined many queries into one)
     $query = "SELECT c.*, m.id AS mesid, m.thread, m.catid, t.subject AS topicsubject, m.subject, m.name AS mname, u.id AS userid, u.username, u.name AS uname,\n\t\t\t(SELECT COUNT(*) FROM #__kunena_messages AS mm WHERE m.thread=mm.thread) AS msgcount, {$subquery}\n\t\t\tFROM #__kunena_categories AS c\n\t\t\tLEFT JOIN #__kunena_messages AS m ON c.id_last_msg=m.id\n\t\t\tLEFT JOIN #__kunena_messages AS t ON m.thread=t.id\n\t\t\tLEFT JOIN #__users AS u ON u.id=m.userid\n\t\t\tWHERE c.parent IN ({$catlist}) AND c.published='1' AND c.id IN({$this->session->allowed}) ORDER BY ordering, name";
     $this->db->setQuery($query);
     $allsubcats = $this->db->loadObjectList();
     if (KunenaError::checkDatabaseError()) {
         return;
     }
     $this->tabclass = array("row1", "row2");
     $subcats = array();
     $routerlist = array();
     $userlist = array();
     $myprofile = KunenaFactory::getUser();
     if ($myprofile->ordering != '0') {
         $topic_ordering = $myprofile->ordering == '1' ? true : false;
     } else {
         $topic_ordering = $this->config->default_sort == 'asc' ? false : true;
     }
     foreach ($allsubcats as $i => $subcat) {
         if ($subcat->mesid) {
             $routerlist[$subcat->thread] = $subcat->subject;
         }
         if ($topic_ordering) {
             $subcat->page = 1;
         } else {
             $subcat->page = ceil($subcat->msgcount / $this->config->messages_per_page);
         }
         if ($this->config->shownew && $this->my->id != 0) {
             if ($subcat->new) {
                 // Check Unread    Cat Images
                 if (is_file(KUNENA_ABSCATIMAGESPATH . $subcat->id . "_on.gif")) {
                     $allsubcats[$i]->htmlCategoryIcon = "<img src=\"" . KUNENA_URLCATIMAGES . $subcat->id . "_on.gif\" border=\"0\" class='kforum-cat-image' alt=\" \" />";
                 } else {
                     $allsubcats[$i]->htmlCategoryIcon = CKunenaTools::showIcon('kunreadforum', JText::_('COM_KUNENA_GEN_FORUM_NEWPOST'));
                 }
             } else {
                 // Check Read Cat Images
                 if (is_file(KUNENA_ABSCATIMAGESPATH . $subcat->id . "_off.gif")) {
                     $allsubcats[$i]->htmlCategoryIcon = "<img src=\"" . KUNENA_URLCATIMAGES . $subcat->id . "_off.gif\" border=\"0\" class='kforum-cat-image' alt=\" \"  />";
                 } else {
                     $allsubcats[$i]->htmlCategoryIcon = CKunenaTools::showIcon('kreadforum', JText::_('COM_KUNENA_GEN_FORUM_NOTNEW'));
                 }
             }
         } else {
             if (is_file(KUNENA_ABSCATIMAGESPATH . $subcat->id . "_notlogin.gif")) {
                 $allsubcats[$i]->htmlCategoryIcon = "<img src=\"" . KUNENA_URLCATIMAGES . $subcat->id . "_notlogin.gif\" border=\"0\" class='kforum-cat-image' alt=\" \" />";
             } else {
                 $allsubcats[$i]->htmlCategoryIcon = CKunenaTools::showIcon('knotloginforum', JText::_('COM_KUNENA_GEN_FORUM_NOTNEW'));
             }
         }
         // collect user ids for avatar prefetch when integrated
         $userlist[intval($subcat->userid)] = intval($subcat->userid);
     }
     require_once KUNENA_PATH . '/router.php';
     KunenaRouter::loadMessages($routerlist);
     $modcats = array();
     foreach ($allsubcats as $subcat) {
         $this->categories[$subcat->parent][] = $subcat;
         $subcats[] = $subcat->id;
         if ($subcat->moderated) {
             $modcats[] = $subcat->id;
         }
     }
     // Get the childforums
     $this->childforums = array();
     if (count($subcats)) {
         $subcatlist = implode(',', $subcats);
         if ($this->config->shownew && $this->my->id) {
             $subquery = " (SELECT COUNT(DISTINCT thread) FROM #__kunena_messages AS m WHERE c.id=m.catid AND m.hold='0' AND m.time>{$this->db->Quote($this->prevCheck)} AND m.thread NOT IN ({$readlist})) AS new";
         } else {
             $subquery = "0 AS new";
         }
         $query = "SELECT c.id, c.name, c.description, c.parent, c.numTopics, c.numPosts, {$subquery}\n\t\t\tFROM #__kunena_categories AS c\n\t\t\tWHERE c.parent IN ({$subcatlist}) AND c.published='1' AND c.id IN({$this->session->allowed}) ORDER BY c.ordering, c.name";
         $this->db->setQuery($query);
         $childforums = $this->db->loadObjectList();
         KunenaError::checkDatabaseError();
         foreach ($childforums as $i => $childforum) {
             //Begin: parent read unread iconset
             if ($this->config->showchildcaticon) {
                 if ($this->config->shownew && $this->my->id != 0) {
                     if ($childforum->new) {
                         // Check Unread    Cat Images
                         if (is_file(KUNENA_ABSCATIMAGESPATH . $childforum->id . "_on_childsmall.gif")) {
                             $childforum->htmlCategoryIcon = "<img src=\"" . KUNENA_URLCATIMAGES . $childforum->id . "_on_childsmall.gif\" border=\"0\" class='kforum-cat-image' alt=\" \" />";
                         } else {
                             $childforum->htmlCategoryIcon = CKunenaTools::showIcon('kunreadforum-sm', JText::_('COM_KUNENA_GEN_FORUM_NEWPOST'));
                         }
                     } else {
                         // Check Read Cat Images
                         if (is_file(KUNENA_ABSCATIMAGESPATH . $childforum->id . "_off_childsmall.gif")) {
                             $childforum->htmlCategoryIcon = "<img src=\"" . KUNENA_URLCATIMAGES . $childforum->id . "_off_childsmall.gif\" border=\"0\" class='kforum-cat-image' alt=\" \" />";
                         } else {
                             $childforum->htmlCategoryIcon = CKunenaTools::showIcon('kreadforum-sm', JText::_('COM_KUNENA_GEN_FORUM_NOTNEW'));
                         }
                     }
                 } else {
                     // Not Login Cat Images
                     if (is_file(KUNENA_ABSCATIMAGESPATH . $childforum->id . "_notlogin_childsmall.gif")) {
                         $childforum->htmlCategoryIcon = "<img src=\"" . KUNENA_URLCATIMAGES . $childforum->id . "_notlogin_childsmall.gif\" border=\"0\" class='kforum-cat-image' alt=\" \" />";
                     } else {
                         $childforum->htmlCategoryIcon = CKunenaTools::showIcon('knotloginforum-sm', JText::_('COM_KUNENA_GEN_FORUM_NOTNEW'));
                     }
                 }
             } else {
                 $childforum->htmlCategoryIcon = '';
             }
             $this->childforums[$childforum->parent][] = $childforum;
         }
     }
     $this->modlist = array();
     $this->pending = array();
     if (count($modcats)) {
         if ($this->config->listcat_show_moderators) {
             $modcatlist = implode(',', $modcats);
             $this->db->setQuery("SELECT * FROM #__kunena_moderation AS m\n\t\t\t\t\tINNER JOIN #__users AS u ON u.id=m.userid\n\t\t\t\t\tWHERE m.catid IN ({$modcatlist}) AND u.block=0");
             $modlist = $this->db->loadObjectList();
             KunenaError::checkDatabaseError();
             foreach ($modlist as $mod) {
                 $this->modlist[$mod->catid][] = $mod;
                 $userlist[intval($mod->userid)] = intval($mod->userid);
             }
         }
         if (CKunenaTools::isModerator($this->my->id)) {
             foreach ($modcats as $i => $catid) {
                 if (!CKunenaTools::isModerator($this->my->id, $catid)) {
                     unset($modcats[$i]);
                 }
             }
             if (count($modcats)) {
                 $modcatlist = implode(',', $modcats);
                 $this->db->setQuery("SELECT catid, COUNT(*) AS count\n\t\t\t\t\tFROM #__kunena_messages\n\t\t\t\t\tWHERE catid IN ({$modcatlist}) AND hold='1'\n\t\t\t\t\tGROUP BY catid");
                 $pending = $this->db->loadAssocList();
                 KunenaError::checkDatabaseError();
                 foreach ($pending as $i) {
                     if ($i['count']) {
                         $this->pending[$i['catid']] = $i['count'];
                     }
                 }
             }
         }
     }
     // Prefetch all users/avatars to avoid user by user queries during template iterations
     kimport('user');
     KunenaUser::loadUsers($userlist);
 }
Beispiel #27
0
 /**
  * @param int  $catid
  * @param bool $type
  *
  * @return stdClass|string
  */
 public function getRank($catid = 0, $type = false)
 {
     // Default rank
     $rank = new stdClass();
     $rank->rank_id = false;
     $rank->rank_title = null;
     $rank->rank_min = 0;
     $rank->rank_special = 0;
     $rank->rank_image = null;
     $config = KunenaFactory::getConfig();
     $category = KunenaForumCategoryHelper::get($catid);
     if (!$config->showranking) {
         return;
     }
     if (self::$_ranks === null) {
         $this->_db->setQuery("SELECT * FROM #__kunena_ranks");
         self::$_ranks = $this->_db->loadObjectList('rank_id');
         KunenaError::checkDatabaseError();
     }
     $rank->rank_title = JText::_('COM_KUNENA_RANK_USER');
     $rank->rank_image = 'rank0.gif';
     if ($this->userid == 0) {
         $rank->rank_id = 0;
         $rank->rank_title = JText::_('COM_KUNENA_RANK_VISITOR');
         $rank->rank_special = 1;
     } else {
         if ($this->isBanned()) {
             $rank->rank_id = 0;
             $rank->rank_title = JText::_('COM_KUNENA_RANK_BANNED');
             $rank->rank_special = 1;
             $rank->rank_image = 'rankbanned.gif';
             foreach (self::$_ranks as $cur) {
                 if ($cur->rank_special == 1 && JFile::stripExt($cur->rank_image) == 'rankbanned') {
                     $rank = $cur;
                     break;
                 }
             }
         } else {
             if ($this->rank != 0 && isset(self::$_ranks[$this->rank])) {
                 $rank = self::$_ranks[$this->rank];
             } else {
                 if ($this->rank == 0 && $this->isAdmin($category)) {
                     $rank->rank_id = 0;
                     $rank->rank_title = JText::_('COM_KUNENA_RANK_ADMINISTRATOR');
                     $rank->rank_special = 1;
                     $rank->rank_image = 'rankadmin.gif';
                     foreach (self::$_ranks as $cur) {
                         if ($cur->rank_special == 1 && JFile::stripExt($cur->rank_image) == 'rankadmin') {
                             $rank = $cur;
                             break;
                         }
                     }
                 } else {
                     if ($this->rank == 0 && $this->isModerator($category)) {
                         $rank->rank_id = 0;
                         $rank->rank_title = JText::_('COM_KUNENA_RANK_MODERATOR');
                         $rank->rank_special = 1;
                         $rank->rank_image = 'rankmod.gif';
                         foreach (self::$_ranks as $cur) {
                             if ($cur->rank_special == 1 && JFile::stripExt($cur->rank_image) == 'rankmod') {
                                 $rank = $cur;
                                 break;
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($rank->rank_id === false) {
         //post count rank
         $rank->rank_id = 0;
         foreach (self::$_ranks as $cur) {
             if ($cur->rank_special == 0 && $cur->rank_min <= $this->posts && $cur->rank_min >= $rank->rank_min) {
                 $rank = $cur;
             }
         }
     }
     if ($type == 'title') {
         return $rank->rank_title;
     }
     if ($type == 'image') {
         $template = KunenaTemplate::getInstance();
         if (!$config->rankimages) {
             return;
         }
         $iconurl = $template->getRankPath($rank->rank_image, true);
         return '<img src="' . $iconurl . '" alt="" />';
     }
     if (!$config->rankimages) {
         $rank->rank_image = null;
     }
     return $rank;
 }
Beispiel #28
0
 public function getAuthor()
 {
     if (!$this->_author) {
         $this->_author = KunenaUser::getInstance((int) $this->created_by);
     }
     return $this->_author;
 }
Beispiel #29
0
 /**
  * @param KunenaUser $user
  *
  * @return null|string
  */
 protected function authoriseWrite(KunenaUser $user)
 {
     // Check that user is global moderator
     if (!$user->userid || !$user->isModerator()) {
         return JText::_('COM_KUNENA_POST_NOT_MODERATOR');
     }
     return null;
 }
Beispiel #30
0
 function getView()
 {
     // Is user allowed to read category from the URL?
     if ($this->catid && !$this->session->canRead($this->catid)) {
         return;
     }
     $this->allow = 1;
     $where[] = "a.hold IN ({$this->hold})";
     $where = implode(' AND ', $where);
     $query = "SELECT a.*, b.*, p.id AS poll_id, modified.name AS modified_name, modified.username AS modified_username\n\t\t\tFROM #__kunena_messages AS a\n\t\t\tLEFT JOIN #__kunena_messages_text AS b ON a.id=b.mesid\n\t\t\tLEFT JOIN #__users AS modified ON a.modified_by = modified.id\n\t\t\tLEFT JOIN #__kunena_polls AS p ON a.id=p.threadid\n\t\t\tWHERE a.id={$this->db->Quote($this->id)} AND {$where}";
     $this->db->setQuery($query);
     $this->first_message = $this->db->loadObject();
     // Invalid message id (deleted, on hold?)
     if (KunenaError::checkDatabaseError() || !$this->first_message) {
         return;
     }
     // Is user allowed to see the forum specified in the message?
     if (!$this->session->canRead($this->first_message->catid)) {
         $this->allow = 0;
         return;
     }
     $this->thread = $this->first_message->thread;
     // Test if this is a valid URL. If not, redirect browser to the right location
     if ($this->first_message->moved || $this->thread != $this->id || $this->catid != $this->first_message->catid) {
         $this->catid = $this->first_message->catid;
         if ($this->first_message->moved) {
             $newurl = array();
             parse_str($this->first_message->message, $newloc);
             $this->id = $newloc['id'];
             $query = "SELECT catid, thread FROM #__kunena_messages AS a WHERE a.id='{$this->id}'";
             $this->db->setQuery($query);
             $newpos = $this->db->loadObject();
             if (!$newpos) {
                 $this->allow = 0;
                 return;
             }
             if (KunenaError::checkDatabaseError()) {
                 return;
             }
             $this->thread = $newpos->thread;
             $this->catid = $newpos->catid;
         }
         // This query to calculate the page this reply is sitting on within this thread
         $query = "SELECT COUNT(*) FROM #__kunena_messages AS a WHERE a.thread={$this->db->Quote($this->thread)} AND {$where} AND a.id<={$this->db->Quote($this->id)}";
         $this->db->setQuery($query);
         $replyCount = $this->db->loadResult();
         if (KunenaError::checkDatabaseError()) {
             return;
         }
         $replyPage = $replyCount > $this->config->messages_per_page ? ceil($replyCount / $this->config->messages_per_page) : 1;
         $this->redirect = CKunenaLink::GetThreadPageURL('view', $this->catid, $this->thread, $replyPage, $this->config->messages_per_page, $this->first_message->id, false);
     }
     //Get the category name for breadcrumb
     $this->db->setQuery("SELECT * FROM #__kunena_categories WHERE id={$this->db->Quote($this->catid)}");
     $this->catinfo = $this->db->loadObject();
     if (KunenaError::checkDatabaseError()) {
         return;
     }
     //Get Parent's cat.name for breadcrumb
     $this->db->setQuery("SELECT id, name FROM #__kunena_categories WHERE id={$this->db->Quote($this->catinfo->parent)}");
     $objCatParentInfo = $this->db->loadObject();
     if (KunenaError::checkDatabaseError()) {
         return;
     }
     // START
     $this->emoticons = smile::getEmoticons(0);
     $this->prevCheck = $this->session->lasttime;
     $this->read_topics = explode(',', $this->session->readtopics);
     $showedEdit = 0;
     $this->kunena_forum_locked = $this->catinfo->locked;
     //check if topic is locked
     $this->topicLocked = $this->first_message->locked;
     if (!$this->topicLocked) {
         //topic not locked; check if forum is locked
         $this->topicLocked = $this->catinfo->locked;
     }
     $this->topicSticky = $this->first_message->ordering;
     CKunenaTools::markTopicRead($this->thread, $this->my->id);
     //update the hits counter for this topic & exclude the owner
     if ($this->my->id == 0 || $this->first_message->userid != $this->my->id) {
         $this->db->setQuery("UPDATE #__kunena_messages SET hits=hits+1 WHERE id={$this->db->Quote($this->thread)} AND parent='0'");
         $this->db->query();
         KunenaError::checkDatabaseError();
     }
     $query = "SELECT COUNT(*) FROM #__kunena_messages AS a WHERE a.thread={$this->db->Quote($this->thread)} AND {$where}";
     $this->db->setQuery($query);
     $this->total_messages = $this->db->loadResult();
     KunenaError::checkDatabaseError();
     // If page does not exist, redirect to the last page
     if ($this->total_messages <= $this->limitstart) {
         $page = ceil($this->total_messages / $this->limit);
         $this->redirect = CKunenaLink::GetThreadPageURL('view', $this->catid, $this->id, $page, $this->limit, '', false);
     }
     $maxpages = 7 - 2;
     // odd number here (show - 2)
     $totalpages = ceil($this->total_messages / $this->limit);
     $page = floor($this->limitstart / $this->limit) + 1;
     $firstpage = 1;
     if ($this->ordering == 'desc') {
         $firstpage = $totalpages;
     }
     // Get replies of current thread
     $query = "SELECT a.*, b.*, modified.name AS modified_name, modified.username AS modified_username\n\t\t\t\t\tFROM #__kunena_messages AS a\n\t\t\t\t\tLEFT JOIN #__kunena_messages_text AS b ON a.id=b.mesid\n\t\t\t\t\tLEFT JOIN #__users AS modified ON a.modified_by = modified.id\n\t\t\t\t\tWHERE a.thread={$this->db->Quote($this->thread)} AND {$where}\n\t\t\t\t\tORDER BY id {$this->ordering}";
     $this->db->setQuery($query, $this->limitstart, $this->limit);
     $this->messages = (array) $this->db->loadObjectList('id');
     KunenaError::checkDatabaseError();
     // First collect the message ids of the first message and all replies
     $messageids = array();
     $this->threaded = array();
     $userlist = array();
     foreach ($this->messages as $message) {
         $messageids[] = $message->id;
         // 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);
     }
     if (!isset($this->messages[$this->mesid])) {
         $this->mesid = reset($messageids);
     }
     if ($this->layout != 'view') {
         if (!isset($this->messages[$this->id])) {
             $this->messages = $this->getThreadedOrdering(0, array('edge'));
         } else {
             $this->messages = $this->getThreadedOrdering();
         }
     }
     // create a list of ids we can use for our sql
     $idstr = @join(",", $messageids);
     // Load attachments
     require_once KUNENA_PATH_LIB . '/kunena.attachments.class.php';
     $attachments = CKunenaAttachments::getInstance();
     if (is_a($attachments, 'CKunenaAttachments')) {
         $message_attachments = $attachments->get($idstr);
         // Now that we have all relevant messages in messages, asign any matching attachments
         foreach ($this->messages as $message) {
             // Mark as new
             if ($this->my->id && $this->prevCheck < $message->time && !in_array($message->thread, $this->read_topics)) {
                 $message->new = true;
             } else {
                 $message->new = false;
             }
             // Assign attachments
             if (isset($message_attachments[$message->id])) {
                 $message->attachments = $message_attachments[$message->id];
             }
         }
         // Done with attachments
     }
     $this->pagination = $this->getPagination($this->catid, $this->thread, $page, $totalpages, $maxpages);
     //meta description and keywords
     $metaKeys = kunena_htmlspecialchars("{$this->first_message->subject}, {$objCatParentInfo->name}, {$this->config->board_title}, " . JText::_('COM_KUNENA_GEN_FORUM') . ', ' . $this->app->getCfg('sitename'));
     // Create Meta Description form the content of the first message
     // better for search results display but NOT for search ranking!
     $metaDesc = KunenaParser::stripBBCode($this->first_message->message);
     $metaDesc = strip_tags($metaDesc);
     // Now remove all tags
     $metaDesc = preg_replace('/\\s+/', ' ', $metaDesc);
     // remove newlines
     $metaDesc = preg_replace('/^[^\\w0-9]+/', '', $metaDesc);
     // remove characters at the beginning that are not letters or numbers
     $metaDesc = trim($metaDesc);
     // Remove trailing spaces and beginning
     // remove multiple spaces
     while (strpos($metaDesc, '  ') !== false) {
         $metaDesc = str_replace('  ', ' ', $metaDesc);
     }
     // limit to 185 characters - google will cut off at ~150
     if (strlen($metaDesc) > 185) {
         $metaDesc = rtrim(JString::substr($metaDesc, 0, 182)) . '...';
     }
     $metaDesc = htmlspecialchars($metaDesc);
     $document =& JFactory::getDocument();
     $document->setMetadata('keywords', $metaKeys);
     $document->setDescription($metaDesc);
     $this->layout_buttons = array();
     if ($this->config->enable_threaded_layouts) {
         if ($this->layout != 'view') {
             $this->layout_buttons[] = CKunenaLink::GetThreadLayoutLink('flat', $this->catid, $this->thread, $this->mesid, CKunenaTools::showButton('layout-flat', JText::_('COM_KUNENA_BUTTON_LAYOUT_FLAT')), $this->limitstart, $this->limit, JText::_('COM_KUNENA_BUTTON_LAYOUT_FLAT_LONG'), 'nofollow', 'kicon-button kbuttonuser btn-left');
         }
         if ($this->layout != 'threaded') {
             $this->layout_buttons[] = CKunenaLink::GetThreadLayoutLink('threaded', $this->catid, $this->thread, $this->mesid, CKunenaTools::showButton('layout-threaded', JText::_('COM_KUNENA_BUTTON_LAYOUT_THREADED')), $this->limitstart, $this->limit, JText::_('COM_KUNENA_BUTTON_LAYOUT_THREADED_LONG'), 'nofollow', 'kicon-button kbuttonuser btn-left');
         }
         if ($this->layout != 'indented') {
             $this->layout_buttons[] = CKunenaLink::GetThreadLayoutLink('indented', $this->catid, $this->thread, $this->mesid, CKunenaTools::showButton('layout-indented', JText::_('COM_KUNENA_BUTTON_LAYOUT_INDENTED')), $this->limitstart, $this->limit, JText::_('COM_KUNENA_BUTTON_LAYOUT_INDENTED_LONG'), 'nofollow', 'kicon-button kbuttonuser btn-left');
         }
     }
     //Perform subscriptions check only once
     $this->cansubscribe = 0;
     if ($this->config->allowsubscriptions && $this->config->topic_subscriptions != 'disabled' && $this->my->id) {
         $this->db->setQuery("SELECT thread, future1 FROM #__kunena_subscriptions WHERE userid={$this->db->Quote($this->my->id)} AND thread={$this->db->Quote($this->thread)}");
         $fb_subscribed = $this->db->loadObject();
         KunenaError::checkDatabaseError();
         if (!$fb_subscribed) {
             $this->cansubscribe = 1;
         } elseif ($fb_subscribed->future1 == 1) {
             $query_thread = "UPDATE #__kunena_subscriptions\n\t\t\t\t\tSET future1=0 WHERE thread={$this->db->Quote($this->thread)} AND userid={$this->db->Quote($this->my->id)}";
             $this->db->setQuery($query_thread);
             $this->db->query();
         }
     }
     //Perform favorites check only once
     $fb_canfavorite = 0;
     $this->db->setQuery("SELECT MAX(userid={$this->db->Quote($this->my->id)}) AS favorited, COUNT(*) AS totalfavorited FROM #__kunena_favorites WHERE thread={$this->db->Quote($this->thread)}");
     list($this->favorited, $this->totalfavorited) = $this->db->loadRow();
     KunenaError::checkDatabaseError();
     if ($this->config->allowfavorites && $this->my->id) {
         if (!$this->favorited) {
             $fb_canfavorite = 1;
         }
     }
     //get the Moderator list for display
     $this->db->setQuery("SELECT m.*, u.* FROM #__kunena_moderation AS m INNER JOIN #__users AS u ON u.id=m.userid WHERE m.catid={$this->db->Quote($this->catid)} AND u.block=0");
     $this->modslist = $this->db->loadObjectList();
     KunenaError::checkDatabaseError();
     $this->catModerators = array();
     foreach ($this->modslist as $mod) {
         $this->catModerators[] = $mod->userid;
         $userlist[intval($mod->userid)] = intval($mod->userid);
     }
     // Prefetch all users/avatars to avoid user by user queries during template iterations
     KunenaUser::loadUsers($userlist);
     //data ready display now
     if (CKunenaTools::isModerator($this->my->id, $this->catid) || $this->topicLocked == 0) {
         //this user is allowed to reply to this topic
         $this->thread_reply = CKunenaLink::GetTopicPostReplyLink('reply', $this->catid, $this->thread, CKunenaTools::showButton('reply', JText::_('COM_KUNENA_BUTTON_REPLY_TOPIC')), 'nofollow', 'kicon-button kbuttoncomm btn-left', JText::_('COM_KUNENA_BUTTON_REPLY_TOPIC_LONG'));
     }
     // Thread Subscription
     if ($this->cansubscribe == 1) {
         // this user is allowed to subscribe - check performed further up to eliminate duplicate checks
         // for top and bottom navigation
         $this->thread_subscribe = CKunenaLink::GetTopicPostLink('subscribe', $this->catid, $this->id, CKunenaTools::showButton('subscribe', JText::_('COM_KUNENA_BUTTON_SUBSCRIBE_TOPIC')), 'nofollow', 'kicon-button kbuttonuser btn-left', JText::_('COM_KUNENA_BUTTON_SUBSCRIBE_TOPIC_LONG'));
     }
     if ($this->my->id != 0 && $this->config->allowsubscriptions && $this->config->topic_subscriptions != 'disabled' && $this->cansubscribe == 0) {
         // this user is allowed to unsubscribe
         $this->thread_subscribe = CKunenaLink::GetTopicPostLink('unsubscribe', $this->catid, $this->id, CKunenaTools::showButton('subscribe', JText::_('COM_KUNENA_BUTTON_UNSUBSCRIBE_TOPIC')), 'nofollow', 'kicon-button kbuttonuser btn-left', JText::_('COM_KUNENA_BUTTON_UNSUBSCRIBE_TOPIC_LONG'));
     }
     //START: FAVORITES
     if ($fb_canfavorite == 1) {
         // this user is allowed to add a favorite - check performed further up to eliminate duplicate checks
         // for top and bottom navigation
         $this->thread_favorite = CKunenaLink::GetTopicPostLink('favorite', $this->catid, $this->id, CKunenaTools::showButton('favorite', JText::_('COM_KUNENA_BUTTON_FAVORITE_TOPIC')), 'nofollow', 'kicon-button kbuttonuser btn-left', JText::_('COM_KUNENA_BUTTON_FAVORITE_TOPIC_LONG'));
     }
     if ($this->my->id != 0 && $this->config->allowfavorites && $fb_canfavorite == 0) {
         // this user is allowed to unfavorite
         $this->thread_favorite = CKunenaLink::GetTopicPostLink('unfavorite', $this->catid, $this->id, CKunenaTools::showButton('favorite', JText::_('COM_KUNENA_BUTTON_UNFAVORITE_TOPIC')), 'nofollow', 'kicon-button kbuttonuser btn-left', JText::_('COM_KUNENA_BUTTON_UNFAVORITE_TOPIC_LONG'));
     }
     // FINISH: FAVORITES
     if (CKunenaTools::isModerator($this->my->id, $this->catid) || !$this->kunena_forum_locked) {
         //this user is allowed to post a new topic
         $this->thread_new = CKunenaLink::GetPostNewTopicLink($this->catid, CKunenaTools::showButton('newtopic', JText::_('COM_KUNENA_BUTTON_NEW_TOPIC')), 'nofollow', 'kicon-button kbuttoncomm btn-left', JText::_('COM_KUNENA_BUTTON_NEW_TOPIC_LONG'));
     }
     if (CKunenaTools::isModerator($this->my->id, $this->catid)) {
         // offer the moderator always the move link to relocate a topic to another forum
         // and the (un)sticky bit links
         // and the (un)lock links
         if ($this->topicSticky == 0) {
             $this->thread_sticky = CKunenaLink::GetTopicPostLink('sticky', $this->catid, $this->id, CKunenaTools::showButton('sticky', JText::_('COM_KUNENA_BUTTON_STICKY_TOPIC')), 'nofollow', 'kicon-button kbuttonmod btn-left', JText::_('COM_KUNENA_BUTTON_STICKY_TOPIC_LONG'));
         } else {
             $this->thread_sticky = CKunenaLink::GetTopicPostLink('unsticky', $this->catid, $this->id, CKunenaTools::showButton('sticky', JText::_('COM_KUNENA_BUTTON_UNSTICKY_TOPIC')), 'nofollow', 'kicon-button kbuttonmod btn-left', JText::_('COM_KUNENA_BUTTON_UNSTICKY_TOPIC_LONG'));
         }
         if ($this->topicLocked == 0) {
             $this->thread_lock = CKunenaLink::GetTopicPostLink('lock', $this->catid, $this->id, CKunenaTools::showButton('lock', JText::_('COM_KUNENA_BUTTON_LOCK_TOPIC')), 'nofollow', 'kicon-button kbuttonmod btn-left', JText::_('COM_KUNENA_BUTTON_LOCK_TOPIC_LONG'));
         } else {
             $this->thread_lock = CKunenaLink::GetTopicPostLink('unlock', $this->catid, $this->id, CKunenaTools::showButton('lock', JText::_('COM_KUNENA_BUTTON_UNLOCK_TOPIC')), 'nofollow', 'kicon-button kbuttonmod btn-left', JText::_('COM_KUNENA_BUTTON_UNLOCK_TOPIC_LONG'));
         }
         $this->thread_delete = CKunenaLink::GetTopicPostLink('deletethread', $this->catid, $this->id, CKunenaTools::showButton('delete', JText::_('COM_KUNENA_BUTTON_DELETE_TOPIC')), 'nofollow', 'kicon-button kbuttonmod btn-left', JText::_('COM_KUNENA_BUTTON_DELETE_TOPIC_LONG'));
         $this->thread_moderate = CKunenaLink::GetTopicPostReplyLink('moderatethread', $this->catid, $this->id, CKunenaTools::showButton('moderate', JText::_('COM_KUNENA_BUTTON_MODERATE_TOPIC')), 'nofollow', 'kicon-button kbuttonmod btn-left', JText::_('COM_KUNENA_BUTTON_MODERATE'));
     }
     $this->headerdesc = nl2br(smile::smileReplace($this->catinfo->headerdesc, 0, $this->config->disemoticons, $this->emoticons));
     $tabclass = array("row1", "row2");
     $this->mmm = 0;
     $this->replydir = $this->ordering == 'DESC' ? -1 : 1;
     if ($this->replydir < 0) {
         $this->replynum = $this->total_messages - $this->limitstart + 1;
     } else {
         $this->replynum = $this->limitstart;
     }
     $this->myname = $this->config->username ? $this->my->username : $this->my->name;
     $this->allow_anonymous = !empty($this->catinfo->allow_anonymous) && $this->my->id;
     $this->anonymous = $this->allow_anonymous && !empty($this->catinfo->post_anonymous);
 }