Esempio n. 1
0
	/**
	 * Prepare user attachments list.
	 *
	 * @return void
	 */
	protected function before()
	{
		parent::before();

		$userid = $this->input->getInt('userid');
		$params = array('file' => '1', 'image' => '1', 'orderby' => 'desc', 'limit' => '30');

		$this->template = KunenaFactory::getTemplate();
		$this->me = KunenaUserHelper::getMyself();
		$this->profile = KunenaUserHelper::get($userid);
		$this->attachments = KunenaAttachmentHelper::getByUserid($this->profile, $params);

		// Pre-load messages.
		$messageIds = array();

		foreach ($this->attachments as $attachment)
		{
			$messageIds[] = (int) $attachment->mesid;
		}

		$messages = KunenaForumMessageHelper::getMessages($messageIds, 'none');

		// Pre-load topics.
		$topicIds = array();

		foreach ($messages as $message)
		{
			$topicIds[] = $message->thread;
		}

		KunenaForumTopicHelper::getTopics($topicIds, 'none');

		$this->headerText = JText::_('COM_KUNENA_MANAGE_ATTACHMENTS');
	}
	public function check() {
		$user = KunenaUserHelper::get($this->userid);
		$message = KunenaForumMessageHelper::get($this->mesid);
		if ($this->userid != 0 && !$user->exists()) {
			$this->setError(JText::sprintf('COM_KUNENA_LIB_TABLE_ATTACHMENTS_ERROR_USER_INVALID', (int) $user->userid));
		}
		if (!$message->exists()) {
			$this->setError(JText::sprintf('COM_KUNENA_LIB_TABLE_ATTACHMENTS_ERROR_MESSAGE_INVALID', (int) $message->id));
		}
		$this->folder = trim($this->folder, '/');
		if (!$this->folder) {
			$this->setError(JText::_('COM_KUNENA_LIB_TABLE_ATTACHMENTS_ERROR_NO_FOLDER'));
		}
		if (!$this->filename) {
			$this->setError(JText::_('COM_KUNENA_LIB_TABLE_ATTACHMENTS_ERROR_NO_FILENAME'));
		}
		$file = JPATH_ROOT . "/{$this->folder}/{$this->filename}";
		if (!file_exists($file)) {
			$this->setError(JText::sprintf('COM_KUNENA_LIB_TABLE_ATTACHMENTS_ERROR_FILE_MISSING', "{$this->folder}/{$this->filename}"));
		} else {
			if (!$this->hash) $this->hash = md5_file ( $file );
			if (!$this->size) $this->size = filesize ( $file );
		}
		return ($this->getError () == '');
	}
Esempio n. 3
0
	/**
	 * @param bool|array $ids
	 * @param mixed $user
	 *
	 * @return KunenaForumTopicUserRead[]
	 */
	static public function getTopics($ids = false, $user = null)
	{
		$user = KunenaUserHelper::get($user);

		if ($ids === false)
		{
			return isset(self::$_instances[$user->userid]) ? self::$_instances[$user->userid] : array();
		}
		elseif (!is_array ($ids))
		{
			$ids = array($ids);
		}

		// Convert topic objects into ids
		foreach ($ids as $i=>$id)
		{
			if ($id instanceof KunenaForumTopic) $ids[$i] = $id->id;
		}

		$ids = array_unique($ids);
		self::loadTopics($ids, $user);

		$list = array ();
		foreach ( $ids as $id )
		{
			if (!empty(self::$_instances [$user->userid][$id])) {
				$list [$id] = self::$_instances [$user->userid][$id];
			}
		}

		return $list;
	}
Esempio n. 4
0
 /**
  * @param        $user
  * @param string $task
  * @param bool   $xhtml
  *
  * @return bool
  */
 public function getProfileURL($user, $task = '', $xhtml = true)
 {
     if ($user == 0) {
         return false;
     }
     if (!$user instanceof KunenaUser) {
         $user = KunenaUserHelper::get($user);
     }
     if ($user === false) {
         return false;
     }
     $userid = "&userid={$user->userid}";
     if ($task && $task != 'edit') {
         // TODO: remove in the future.
         $do = $task ? '&do=' . $task : '';
         return KunenaRoute::_("index.php?option=com_kunena&func=profile{$do}{$userid}", $xhtml);
     } else {
         $layout = $task ? '&layout=' . $task : '';
         if ($layout) {
             return KunenaRoute::_("index.php?option=com_kunena&view=user{$layout}{$userid}", $xhtml);
         } else {
             return KunenaRoute::getUserUrl($user, $xhtml);
         }
     }
 }
Esempio n. 5
0
	/**
	 * Load user profile.
	 *
	 * @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');

		require_once KPATH_SITE . '/models/user.php';
		$this->model = new KunenaModelUser(array(), $this->input);
		$this->model->initialize($this->getOptions(), $this->getOptions()->get('embedded', false));
		$this->state = $this->model->getState();

		$this->me = KunenaUserHelper::getMyself();
		$this->user = JFactory::getUser($userid);
		$this->profile = KunenaUserHelper::get($userid);
		$this->profile->tryAuthorise('read');

		// Update profile hits.
		if (!$this->profile->exists() || !$this->profile->isMyself())
		{
			$this->profile->uhits++;
			$this->profile->save();
		}

		$this->headerText = JText::sprintf('COM_KUNENA_VIEW_USER_DEFAULT', $this->profile->getName());
	}
Esempio n. 6
0
 public static function markRead(array $ids, $user = null)
 {
     $user = KunenaUserHelper::get($user);
     $items = self::getCategories($ids, $user);
     $updateList = array();
     $insertList = array();
     $db = JFactory::getDbo();
     $time = JFactory::getDate()->toUnix();
     foreach ($items as $item) {
         if ($item->exists()) {
             $updateList[] = (int) $item->category_id;
         } else {
             $insertList[] = "{$db->quote($user->userid)}, {$db->quote($item->category_id)}, {$db->quote($time)}";
         }
     }
     if ($updateList) {
         $idlist = implode(',', $updateList);
         $query = $db->getQuery(true);
         $query->update('#__kunena_user_categories')->set("allreadtime={$db->quote($time)}")->where("user_id={$db->quote($user->userid)}")->where("category_id IN ({$idlist})");
         $db->setQuery($query);
         $db->execute();
     }
     if ($insertList) {
         $query = $db->getQuery(true);
         $query->insert('#__kunena_user_categories')->columns('user_id, category_id, allreadtime')->values($insertList);
         $db->setQuery($query);
         $db->execute();
     }
 }
Esempio n. 7
0
	protected function populateState() {
		$layout = $this->getCmd ( 'layout', 'default' );
		$this->setState ( 'layout', $layout );

		// Administrator state
		if ($layout == 'manage' || $layout == 'create' || $layout == 'edit') {
			return parent::populateState();
		}

		$app = JFactory::getApplication ();
		$this->config = KunenaFactory::getConfig ();
		$this->me = KunenaUserHelper::get();

		$active = $app->getMenu ()->getActive ();
		$active = $active ? (int) $active->id : 0;
		$catid = $this->getInt ( 'catid', 0 );
		$this->setState ( 'item.id', $catid );

		// List state information
		$value = $this->getUserStateFromRequest ( "com_kunena.category{$catid}_list_limit", 'limit', 0, 'int' );
		if ($value < 1) $value = $this->config->threads_per_page;
		$this->setState ( 'list.limit', $value );

		$value = $this->getUserStateFromRequest ( "com_kunena.category{$catid}_{$active}_list_ordering", 'filter_order', 'time', 'cmd' );
		//$this->setState ( 'list.ordering', $value );

		$value = $this->getUserStateFromRequest ( "com_kunena.category{$catid}_list_start", 'limitstart', 0, 'int' );
		$this->setState ( 'list.start', $value );

		$value = $this->getUserStateFromRequest ( "com_kunena.category{$catid}_{$active}_list_direction", 'filter_order_Dir', 'desc', 'word' );
		if ($value != 'asc')
			$value = 'desc';
		$this->setState ( 'list.direction', $value );
	}
Esempio n. 8
0
	function check() {
		$user = KunenaUserHelper::get($this->userid);
		if (!$user->exists()) {
			$this->setError ( JText::sprintf ( 'COM_KUNENA_LIB_TABLE_SESSIONS_ERROR_USER_INVALID', (int) $user->userid ) );
		}
		return ($this->getError () == '');
	}
Esempio n. 9
0
 /**
  * Get categories for a specific user.
  *
  * @param bool|array|int	$ids		The category ids to load.
  * @param mixed				$user		The user id to load.
  *
  * @return KunenaForumCategoryUser[]
  */
 public static function getCategories($ids = false, $user = null)
 {
     $user = KunenaUserHelper::get($user);
     if ($ids === false) {
         // Get categories which are seen by current user
         $ids = KunenaForumCategoryHelper::getCategories();
     } elseif (!is_array($ids)) {
         $ids = array($ids);
     }
     // Convert category objects into ids
     foreach ($ids as $i => $id) {
         if ($id instanceof KunenaForumCategory) {
             $ids[$i] = $id->id;
         }
     }
     $ids = array_unique($ids);
     self::loadCategories($ids, $user);
     $list = array();
     foreach ($ids as $id) {
         if (!empty(self::$_instances[$user->userid][$id])) {
             $list[$id] = self::$_instances[$user->userid][$id];
         }
     }
     return $list;
 }
Esempio n. 10
0
	public function getUser()
	{
		$userid = $this->getState($this->getName() . '.id');

		$user = KunenaUserHelper::get($userid);

		return $user;
	}
Esempio n. 11
0
	static public function getSubscriptions($user = null) {
		$user = KunenaUserHelper::get($user);
		$db = JFactory::getDBO ();
		$query = "SELECT category_id FROM #__kunena_user_categories WHERE user_id={$db->Quote($user->userid)} AND subscribed=1";
		$db->setQuery ( $query );
		$subscribed = (array) $db->loadResultArray ();
		if (KunenaError::checkDatabaseError()) return;
		return KunenaForumCategoryHelper::getCategories($subscribed);
	}
Esempio n. 12
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');
 }
Esempio n. 13
0
	function check() {
		$user = KunenaUserHelper::get($this->user_id);
		if (!$user->exists()) {
			$this->setError ( JText::sprintf ( 'COM_KUNENA_LIB_TABLE_USERCATEGORIES_ERROR_USER_INVALID', (int) $user->userid ) );
		}
		if ($this->category_id && !KunenaForumCategoryHelper::get($this->category_id)->exists()) {
			$this->setError ( JText::sprintf ( 'COM_KUNENA_LIB_TABLE_USERCATEGORIES_ERROR_CATEGORY_INVALID', (int) $category->id ) );
		}
		return ($this->getError () == '');
	}
Esempio n. 14
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());
 }
Esempio n. 15
0
	protected function populateState() {
		$app = JFactory::getApplication ();
		$this->me = KunenaUserHelper::get();
		$config = KunenaFactory::getConfig ();
		$active = $app->getMenu ()->getActive ();
		$active = $active ? (int) $active->id : 0;

		$layout = $this->getWord ( 'layout', 'default' );
		$layout = $this->me->getTopicLayout ();
		$this->setState ( 'layout', $layout );

		$template = KunenaFactory::getTemplate();
		$profile_location = $template->params->get('avatarPosition', 'left');
		$profile_direction = $profile_location == 'left' || $profile_location == 'right' ? 'vertical' : 'horizontal';
		$this->setState ( 'profile.location', $profile_location );
		$this->setState ( 'profile.direction', $profile_direction );

		$catid = $this->getInt ( 'catid', 0 );
		$this->setState ( 'item.catid', $catid );

		$id = $this->getInt ( 'id', 0 );
		$this->setState ( 'item.id', $id );

		$id = $this->getInt ( 'mesid', 0 );
		$this->setState ( 'item.mesid', $id );

		$access = KunenaFactory::getAccessControl();
		$value = $access->getAllowedHold($this->me, $catid);
		$this->setState ( 'hold', $value );

		$value = $this->getInt ( 'limit', 0 );
		if ($value < 1) $value = $config->messages_per_page;
		$this->setState ( 'list.limit', $value );

		$value = $this->getUserStateFromRequest ( "com_kunena.topic_{$active}_{$layout}_list_ordering", 'filter_order', 'time', 'cmd' );
		//$this->setState ( 'list.ordering', $value );

		$value = $this->getInt ( 'limitstart', 0 );
		if ($value < 0) $value = 0;
		$this->setState ( 'list.start', $value );

		$value = $this->getUserStateFromRequest ( "com_kunena.topic_{$active}_{$layout}_list_direction", 'filter_order_Dir', '', 'word' );
		if (!$value) {
			if ($this->me->ordering != '0') {
				$value = $this->me->ordering == '1' ? 'desc' : 'asc';
			} else {
				$value = $config->default_sort == 'asc' ? 'asc' : 'desc';
			}
		}
		if ($value != 'asc')
			$value = 'desc';
		$this->setState ( 'list.direction', $value );
	}
 public function check()
 {
     $user = KunenaUserHelper::get($this->user_id);
     $topic = KunenaForumTopicHelper::get($this->topic_id);
     if (!$user->exists()) {
         $this->setError(JText::sprintf('COM_KUNENA_LIB_TABLE_USERTOPICS_ERROR_USER_INVALID', (int) $user->userid));
     }
     if (!$topic->exists()) {
         $this->setError(JText::sprintf('COM_KUNENA_LIB_TABLE_USERTOPICS_ERROR_TOPIC_INVALID', (int) $topic->id));
     }
     $this->category_id = $topic->category_id;
     return $this->getError() == '';
 }
Esempio n. 17
0
 /**
  * Prepare statistics box display.
  *
  * @return boolean
  */
 protected function before()
 {
     parent::before();
     $this->config = KunenaConfig::getInstance();
     if (!$this->config->get('showstats') || !$this->config->statslink_allowed && !KunenaUserHelper::get()->exists()) {
         throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), '404');
     }
     $statistics = KunenaForumStatistics::getInstance();
     $statistics->loadGeneral();
     $this->setProperties($statistics);
     $this->latestMemberLink = KunenaFactory::getUser(intval($this->lastUserId))->getLink();
     $this->statisticsUrl = KunenaFactory::getProfile()->getStatisticsURL();
     return true;
 }
Esempio n. 18
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());
 }
Esempio n. 19
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();
 }
Esempio n. 20
0
	static public function getTopics($ids = false, $user=null) {
		$user = KunenaUserHelper::get($user);
		if ($ids === false) {
			return self::$_instances[$user->userid];
		} elseif (is_array ($ids) ) {
			$ids = array_unique($ids);
		} else {
			$ids = array($ids);
		}
		self::loadTopics($ids, $user);

		$list = array ();
		foreach ( $ids as $id ) {
			if (!empty(self::$_instances [$user->userid][$id])) {
				$list [$id] = self::$_instances [$user->userid][$id];
			}
		}

		return $list;
	}
	public function check() {
		if ($this->created_by) {
			$user = KunenaUserHelper::get($this->created_by);
			if (!$user->exists()) {
				$this->setError(JText::sprintf('COM_KUNENA_LIB_TABLE_ANNOUNCEMENTS_ERROR_USER_INVALID', (int) $user->userid));
			}
		} else {
			$this->created_by = KunenaUserHelper::getMyself()->userid;
		}
		if (!$this->created) $this->created = JFactory::getDate()->toSql();
		$this->title = trim($this->title);
		if (!$this->title) {
			$this->setError ( JText::_ ( 'COM_KUNENA_LIB_TABLE_ANNOUNCEMENTS_ERROR_NO_TITLE' ) );
		}
		$this->sdescription = trim($this->sdescription);
		$this->description = trim($this->description);
		if (!$this->sdescription) {
			$this->setError ( JText::_ ( 'COM_KUNENA_LIB_TABLE_ANNOUNCEMENTS_ERROR_NO_DESCRIPTION' ) );
		}
		return ($this->getError () == '');
	}
Esempio n. 22
0
 public function display($userId = null, $docType = null)
 {
     if (!KunenaHelper::exists()) {
         return;
     }
     // Load language file from Kunena
     KunenaFactory::loadLanguage('com_kunena.libraries', 'admin');
     // Load Kunena's language file
     JFactory::getLanguage()->load('com_kunena.libraries', JPATH_ADMINISTRATOR);
     // Get the current user
     $user = FD::user($userId);
     // Get the user params
     $params = $this->getUserParams($user->id);
     // Get the app params
     $appParams = $this->app->getParams();
     // Get the total items to display
     $total = (int) $params->get('total', $appParams->get('total', 5));
     // Get the posts created by the user.
     $model = $this->getModel('Posts');
     $posts = $model->getPosts($user->id, $total);
     // Get the replies
     $replies = $model->getReplies($user->id);
     // Get stats
     $stats = $model->getStats($user->id);
     // Get total replies
     $totalReplies = $model->getTotalReplies($user->id);
     // Get Kunena's template
     $kTemplate = KunenaFactory::getTemplate();
     $kUser = KunenaUserHelper::get($userId);
     $this->set('totalReplies', $totalReplies);
     $this->set('stats', $stats);
     $this->set('thanks', $kUser->thankyou);
     $this->set('totalPosts', $kUser->posts);
     $this->set('kTemplate', $kTemplate);
     $this->set('user', $user);
     $this->set('params', $params);
     $this->set('posts', $posts);
     $this->set('replies', $replies);
     echo parent::display('profile/default');
 }
Esempio n. 23
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();
	}
Esempio n. 24
0
 public function getUser()
 {
     $userid = $this->app->getUserState('kunena.user.userid');
     $user = KunenaUserHelper::get($userid);
     return $user;
 }
Esempio n. 25
0
	public function getTopicUrl($topic, $action = null, $object=false) {
		if ($action instanceof StdClass || $action instanceof KunenaForumMessage) {
			$message = $action;
			$action = 'm'.$message->id;
		}
		$uri = JURI::getInstance("index.php?option=com_kunena&view=topic&id={$topic->id}&action={$action}");
		if ($uri->getVar('action') !== null) {
			$uri->delVar('action');
			$uri->setVar('catid', isset($this->category) ? $this->category->id : $topic->catid);
			$limit = max(1, $this->config->messages_per_page);
			$mesid = 0;
			if (is_numeric($action)) {
				if ($action) $uri->setVar('limitstart', $action * $limit);
			} elseif (isset($message)) {
				$mesid = $message->id;
				$position = $topic->getPostLocation($mesid, $this->message_ordering);
			} else {
				switch ($action) {
					case 'first':
						$mesid = $topic->first_post_id;
						$position = $topic->getPostLocation($mesid, $this->message_ordering);
						break;
					case 'last':
						$mesid = $topic->last_post_id;
						$position = $topic->getPostLocation($mesid, $this->message_ordering);
						break;
					case 'unread':
						$mesid = $topic->lastread ? $topic->lastread : $topic->last_post_id;
						$position = $topic->getPostLocation($mesid, $this->message_ordering);
						break;
				}
			}
			if ($mesid) {
				if (KunenaUserHelper::get()->getTopicLayout() != 'threaded') {
					$uri->setFragment($mesid);
				} else {
					$uri->setVar('mesid', $mesid);
				}
			}
			if (isset($position)) {
				$limitstart = intval($position / $limit) * $limit;
				if ($limitstart) $uri->setVar('limitstart', $limitstart);
			}
		}
		return $object ? $uri : KunenaRoute::_($uri);
	}
Esempio n. 26
0
 /**
  * @param int $limit
  *
  * @return array
  */
 public function loadTopThankyous($limit = 0)
 {
     $limit = $limit ? $limit : $this->_config->popthankscount;
     if (count($this->topThanks) < $limit) {
         $query = "SELECT t.targetuserid AS id, COUNT(t.targetuserid) AS count\n\t\t\t\tFROM `#__kunena_thankyou` AS t\n\t\t\t\tINNER JOIN `#__users` AS u ON u.id=t.targetuserid\n\t\t\t\tGROUP BY t.targetuserid\n\t\t\t\tORDER BY count DESC";
         $this->_db->setQuery($query, 0, $limit);
         $this->topThanks = (array) $this->_db->loadObjectList();
         KunenaError::checkDatabaseError();
         $top = reset($this->topThanks);
         if (!$top) {
             return array();
         }
         $top->title = JText::_('COM_KUNENA_LIB_STAT_TOP_THANKS');
         $top->titleName = JText::_('COM_KUNENA_USERNAME');
         $top->titleCount = JText::_('COM_KUNENA_STAT_THANKS_YOU_RECEIVED');
         foreach ($this->topThanks as &$item) {
             $item = clone $item;
             $item->link = KunenaUserHelper::get($item->id)->getLink();
             $item->percent = round(100 * $item->count / $top->count);
         }
     }
     return array_slice($this->topThanks, 0, $limit);
 }
Esempio n. 27
0
 /**
  * @param string $action
  * @param mixed $user
  * @param bool $silent
  *
  * @return bool
  * @deprecated K4.0
  */
 public function authorise($action = 'read', $user = null, $silent = false)
 {
     if ($user === null) {
         $user = KunenaUserHelper::getMyself();
     } elseif (!$user instanceof KunenaUser) {
         $user = KunenaUserHelper::get($user);
     }
     $exception = $this->tryAuthorise($action, $user, false);
     if ($silent === false && $exception) {
         $this->setError($exception->getMessage());
     }
     if ($silent !== null) {
         return !$exception;
     }
     return $exception ? $exception->getMessage() : null;
 }
Esempio n. 28
0
	/**
	 * Change user moderator status
	 **/
	public function setModerator($user, $status = 1) {
		// Do not allow this action if current user isn't admin in this category
		if (!$this->_me->isAdmin($this->id)) {
			$this->setError ( JText::sprintf('COM_KUNENA_ERROR_NOT_CATEGORY_ADMIN', $this->name) );
			return false;
		}

		// Check if category exists
		if (!$this->exists()) return false;

		// Check if user exists
		$user = KunenaUserHelper::get($user);
		if (!$user->exists()) {
			return false;
		}

		$catids = KunenaFactory::getAccessControl ()->getAllowedCategories ( $user, 'moderate');

		// Do not touch global moderators
		if (!empty($catids[0]) && !$user->isAdmin($this->id)) {
			return true;
		}

		// If the user state remains the same, do nothing
		if (empty($catids[$this->catid]) == $status) {
			return true;
		}

		$db = JFactory::getDBO ();
		$success = true;
		if ($status == 1) {
			$query = "INSERT INTO #__kunena_moderation (catid, userid) VALUES  ({$db->quote($this->id)}, {$db->quote($user->userid)})";
			$db->setQuery ( $query );
			$db->query ();
			// Finally set user to be a moderator
			if (!KunenaError::checkDatabaseError () && $user->moderator == 0) {
				$user->moderator = 1;
				$success = $user->save();
			}
		} else {
			$query = "DELETE FROM #__kunena_moderation WHERE catid={$db->Quote($this->id)} AND userid={$db->Quote($user->userid)}";
			$db->setQuery ( $query );
			$db->query ();
			unset($catids[$this->id]);
			// Finally check if user looses his moderator status
			if (!KunenaError::checkDatabaseError () && empty($catids)) {
				$user->moderator = 0;
				$success = $user->save();
			}
		}

		// Clear moderator cache
		$access = KunenaFactory::getAccessControl();
		$access->clearCache();
		return $success;
	}
Esempio n. 29
0
 /**
  * Method to load a KunenaForumCategoryUser object by id.
  *
  * @param null|int	$category_id		The category id to be loaded.
  * @param mixed		$user				The user to be loaded.
  *
  * @return bool
  */
 public function load($category_id = null, $user = null)
 {
     if ($category_id === null) {
         $category_id = $this->category_id;
     }
     if ($user === null && $this->user_id !== null) {
         $user = $this->user_id;
     }
     $user = KunenaUserHelper::get($user);
     // Create the table object
     $table = $this->getTable();
     // Load the KunenaTable object based on id
     $this->_exists = $table->load(array('user_id' => $user->userid, 'category_id' => $category_id));
     // Assuming all is well at this point lets bind the data
     $this->setProperties($table->getProperties());
     return $this->_exists;
 }
Esempio n. 30
0
 /**
  * Returns the global KunenaUser object, only creating it if it doesn't already exist.
  *
  * @param null|int $identifier	The user to load - Can be an integer or string - If string, it is converted to ID automatically.
  * @param bool $reload		Reload user from database.
  *
  * @return KunenaUser
  */
 public static function getInstance($identifier = null, $reload = false)
 {
     return KunenaUserHelper::get($identifier, $reload);
 }