Beispiel #1
0
/**
* Fetches an array containing info for the specified user, or false if user is not found
*
* Values for Option parameter:
* 1 - Nothing ...
* 2 - Get avatar
* 4 - Process user's online location
* 8 - Join the customprofilpic table to get the userid just to check if we have a picture
* 16 - Join the administrator table to get various admin options
* 32 - Join the sigpic table to get the userid just to check if we have a picture
* 64 - Get user's custom CSS
* 128 - Is the logged in User a friend of this person?
* Therefore: Option = 6 means 'Get avatar' and 'Process online location'
* See fetch_userinfo() in the do=getinfo section of member.php if you are still confused
*
* @param	integer	(ref) User ID
* @param	integer	Bitfield Option (see description)
*
* @return	array	The information for the requested user
*/
function fetch_userinfo(&$userid, $option = 0, $languageid = 0)
{
	global $vbulletin, $usercache, $vbphrase;

	if ($userid == $vbulletin->userinfo['userid'] AND $option != 0 AND isset($usercache["$userid"]))
	{
		// clear the cache if we are looking at ourself and need to add one of the JOINS to our information.
		unset($usercache["$userid"]);
	}

	$userid = intval($userid);

	// return the cached result if it exists
	if (isset($usercache["$userid"]))
	{
		return $usercache["$userid"];
	}

	$hook_query_fields = $hook_query_joins = '';
	($hook = vBulletinHook::fetch_hook('fetch_userinfo_query')) ? eval($hook) : false;

	// no cache available - query the user
	$user = $vbulletin->db->query_first_slave("
		SELECT " .
			iif(($option & FETCH_USERINFO_ADMIN), ' administrator.*, ') . "
			userfield.*, usertextfield.*, user.*, UNIX_TIMESTAMP(passworddate) AS passworddate, user.languageid AS saved_languageid,
			IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid" .
			iif(($option & FETCH_USERINFO_AVATAR) AND $vbulletin->options['avatarenabled'], ', avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline, customavatar.width AS avwidth, customavatar.height AS avheight, customavatar.height_thumb AS avheight_thumb, customavatar.width_thumb AS avwidth_thumb, customavatar.filedata_thumb').
			iif(($option & FETCH_USERINFO_PROFILEPIC), ', customprofilepic.userid AS profilepic, customprofilepic.dateline AS profilepicdateline, customprofilepic.width AS ppwidth, customprofilepic.height AS ppheight') .
			iif(($option & FETCH_USERINFO_SIGPIC), ', sigpic.userid AS sigpic, sigpic.dateline AS sigpicdateline, sigpic.width AS sigpicwidth, sigpic.height AS sigpicheight') .
			(($option & FETCH_USERINFO_USERCSS) ? ', usercsscache.cachedcss, IF(usercsscache.cachedcss IS NULL, 0, 1) AS hascachedcss, usercsscache.buildpermissions AS cssbuildpermissions' : '') .
			(isset($vbphrase) ? '' : fetch_language_fields_sql()) .
			(($vbulletin->userinfo['userid'] AND ($option & FETCH_USERINFO_ISFRIEND)) ?
				", IF(userlist1.friend = 'yes', 1, 0) AS isfriend, IF (userlist1.friend = 'pending' OR userlist1.friend = 'denied', 1, 0) AS ispendingfriend" .
				", IF(userlist1.userid IS NOT NULL, 1, 0) AS u_iscontact_of_bbuser, IF (userlist2.friend = 'pending', 1, 0) AS requestedfriend" .
				", IF(userlist2.userid IS NOT NULL, 1, 0) AS bbuser_iscontact_of_user" : "") . "
			$hook_query_fields
		FROM " . TABLE_PREFIX . "user AS user
		LEFT JOIN " . TABLE_PREFIX . "userfield AS userfield ON (user.userid = userfield.userid)
		LEFT JOIN " . TABLE_PREFIX . "usertextfield AS usertextfield ON (usertextfield.userid = user.userid) " .
		iif(($option & FETCH_USERINFO_AVATAR) AND $vbulletin->options['avatarenabled'], "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON (avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON (customavatar.userid = user.userid) ") .
		iif(($option & FETCH_USERINFO_PROFILEPIC), "LEFT JOIN " . TABLE_PREFIX . "customprofilepic AS customprofilepic ON (user.userid = customprofilepic.userid) ") .
		iif(($option & FETCH_USERINFO_ADMIN), "LEFT JOIN " . TABLE_PREFIX . "administrator AS administrator ON (administrator.userid = user.userid) ") .
		iif(($option & FETCH_USERINFO_SIGPIC), "LEFT JOIN " . TABLE_PREFIX . "sigpic AS sigpic ON (user.userid = sigpic.userid) ") .
		(($option & FETCH_USERINFO_USERCSS) ? 'LEFT JOIN ' . TABLE_PREFIX . 'usercsscache AS usercsscache ON (user.userid = usercsscache.userid)' : '') .
		iif(!isset($vbphrase), "LEFT JOIN " . TABLE_PREFIX . "language AS language ON (language.languageid = " . (!empty($languageid) ? $languageid : "IF(user.languageid = 0, " . intval($vbulletin->options['languageid']) . ", user.languageid)") . ") ") .
		(($vbulletin->userinfo['userid'] AND ($option & FETCH_USERINFO_ISFRIEND)) ?
			"LEFT JOIN " . TABLE_PREFIX . "userlist AS userlist1 ON (userlist1.relationid = user.userid AND userlist1.type = 'buddy' AND userlist1.userid = " . $vbulletin->userinfo['userid'] . ")" .
			"LEFT JOIN " . TABLE_PREFIX . "userlist AS userlist2 ON (userlist2.userid = user.userid AND userlist2.type = 'buddy' AND userlist2.relationid = " . $vbulletin->userinfo['userid'] . ")" : "") . "
		$hook_query_joins
		WHERE user.userid = $userid
	");
	if (!$user)
	{
		return false;
	}

	if (!isset($vbphrase) AND $user['lang_options'] === null)
	{
		trigger_error('The requested language does not exist, reset via tools.php.', E_USER_ERROR);
	}

	$user['languageid'] = (!empty($languageid) ? $languageid : $user['languageid']);

	// decipher 'options' bitfield
	$user['options'] = intval($user['options']);

	foreach ($vbulletin->bf_misc_useroptions AS $optionname => $optionval)
	{
		$user["$optionname"] = ($user['options'] & $optionval ? 1 : 0);
		//DEVDEBUG("$optionname = $user[$optionname]");
	}

	foreach($vbulletin->bf_misc_adminoptions AS $optionname => $optionval)
	{
		$user["$optionname"] = ($user['adminoptions'] & $optionval ? 1 : 0);
	}

	// make a username variable that is safe to pass through URL links
	$user['urlusername'] = urlencode(unhtmlspecialchars($user['username']));

	fetch_musername($user);

	// get the user's real styleid (not the cookie value)
	$user['realstyleid'] = $user['styleid'];

	$user['securitytoken_raw'] = sha1($user['userid'] . sha1($user['salt']) . sha1(COOKIE_SALT));
	$user['securitytoken'] = TIMENOW . '-' . sha1(TIMENOW . $user['securitytoken_raw']);

	$user['logouthash'] =& $user['securitytoken'];

	if ($option & FETCH_USERINFO_LOCATION)
	{ // Process Location info for this user
		require_once(DIR . '/includes/functions_online.php');
		$user = fetch_user_location_array($user);
	}

	($hook = vBulletinHook::fetch_hook('fetch_userinfo')) ? eval($hook) : false;

	$usercache["$userid"] = $user;
	return $usercache["$userid"];
}
Beispiel #2
0
 /**
  * Fetches an array containing info for the specified user, or false if user is not found
  *
  * Values for Option parameter:
  * avatar - Get avatar
  * location - Process user's online location
  * profilepic - Join the customprofilpic table to get the userid just to check if we have a picture
  * admin - Join the administrator table to get various admin options
  * signpic - Join the sigpic table to get the userid just to check if we have a picture
  * usercss - Get user's custom CSS
  * isfriend - Is the logged in User a friend of this person?
  * Therefore: array('avatar', 'location') means 'Get avatar' and 'Process online location'
  *
  * @param integer User ID
  * @param array Fetch Option (see description)
  * @param integer Language ID. If set to 0, it will use user-set languageid (if exists) or default languageid
  * @param boolean If true, the method won't use user cache but fetch information from DB.
  *
  * @return array The information for the requested user
  */
 public static function fetchUserinfo($userid = 0, $option = array(), $languageid = false, $nocache = false)
 {
     sort($option);
     if (!empty($option)) {
         $optionKey = implode('-', $option);
     } else {
         $optionKey = '#';
     }
     if ($session = vB::getCurrentSession() and $currentUserId = $session->get('userid')) {
         if (!$userid) {
             $userid = $currentUserId;
         }
     }
     $userid = intval($userid);
     if (!$userid and $session) {
         // return guest user info
         return $session->fetch_userinfo();
     }
     if ($languageid === false) {
         $session = vB::getCurrentSession();
         if (!empty($session)) {
             $languageid = $session->get('languageid');
         } else {
             $languageid = vB::getDatastore()->getOption('languageid');
         }
     }
     if ($nocache and isset(self::$users["{$userid}"][$optionKey])) {
         // clear the cache if we are looking at ourself and need to add one of the JOINS to our information.
         unset(self::$users["{$userid}"][$optionKey]);
     }
     // return the cached result if it exists
     if (isset(self::$users[$userid][$optionKey])) {
         return self::$users[$userid][$optionKey];
     }
     $cache = vB_Cache::instance(vB_Cache::CACHE_FAST);
     $hashKey = 'vb_UserInfo_' . $userid;
     if (!empty($languageid)) {
         $hashKey .= '_' . $languageid;
     }
     if (!empty($option)) {
         $hashKey .= '_' . md5(serialize($option));
     }
     if (!$nocache) {
         $user = $cache->read($hashKey);
     }
     if (empty($user)) {
         $user = vB::getDbAssertor()->getRow('fetchUserinfo', array('userid' => $userid, 'option' => $option, 'languageid' => $languageid));
         if (empty($user)) {
             return false;
         }
     }
     $cache->write($hashKey, $user, 1440, 'userChg_' . $userid);
     $user['languageid'] = !empty($languageid) ? $languageid : $user['languageid'];
     // decipher 'options' bitfield
     $user['options'] = intval($user['options']);
     $bf_misc_useroptions = vB::getDatastore()->get_value('bf_misc_useroptions');
     $bf_misc_adminoptions = vB::getDatastore()->get_value('bf_misc_adminoptions');
     if (!empty($bf_misc_useroptions)) {
         foreach ($bf_misc_useroptions as $optionname => $optionval) {
             $user["{$optionname}"] = $user['options'] & $optionval ? 1 : 0;
         }
     }
     if (!empty($bf_misc_adminoptions)) {
         foreach ($bf_misc_adminoptions as $optionname => $optionval) {
             $user["{$optionname}"] = $user['adminoptions'] & $optionval ? 1 : 0;
         }
     }
     // make a username variable that is safe to pass through URL links
     $user['urlusername'] = urlencode(unhtmlspecialchars($user['username']));
     self::fetchMusername($user);
     // get the user's real styleid (not the cookie value)
     $user['realstyleid'] = $user['styleid'];
     $request = vB::getRequest();
     if ($request) {
         $timenow = vB::getRequest()->getTimeNow();
     } else {
         $timenow = time();
     }
     $user['securitytoken_raw'] = sha1($user['userid'] . sha1($user['secret']) . sha1(vB_Request_Web::$COOKIE_SALT));
     $user['securitytoken'] = $timenow . '-' . sha1($timenow . $user['securitytoken_raw']);
     $user['logouthash'] =& $user['securitytoken'];
     if (in_array('location', $option)) {
         // Process Location info for this user
         require_once DIR . '/includes/functions_online.php';
         $user = fetch_user_location_array($user);
     }
     // privacy_options
     if (isset($user['privacy_options']) and $user['privacy_options']) {
         $user['privacy_options'] = unserialize($user['privacy_options']);
     }
     if (!isset(self::$users[$userid])) {
         self::$users[$userid] = array();
     }
     // VBV-11898 - Ignore secondary usergroups if allowmembergroups is set to "No." If any page requires the full membergroupids
     // regardless of the usergroup option (ex. adminCP user profile), they should call vB_Library_User->fetchUserGroups()
     $bf_ugp_genericoptions = vB::getDatastore()->get_value('bf_ugp_genericoptions');
     $usergroupCache = vB::getDatastore()->getValue('usergroupcache');
     if (!($usergroupCache[$user['usergroupid']]['genericoptions'] & $bf_ugp_genericoptions['allowmembergroups'])) {
         $user['membergroupids'] = '';
     }
     self::$users[$userid][$optionKey] = $user;
     return $user;
 }