<?php
/*
		[FuShow.cn] (C) 2013-2014 HXWY Inc.
		FuShow Friend V3.0				Id: function_userapp.php
		Email <service@fushow.cn>		http://fushow.cn/
*/

if(!defined('IN_FUSHOW')) {
	exit('Access Denied');
}

//获取当前环境信息
function _my_env_get($var) {
	global $_SGLOBAL, $space;
	
	if($var == 'owner') {
		return $space['uid'];
	} elseif($var == 'viewer') {
		return $_SGLOBAL['supe_uid'];
	} elseif($var == 'prefix_url') {
		if(!isset($_SGLOBAL['prefix_url'])) {
			$_SGLOBAL['prefix_url'] = getsiteurl();
		}
		return $_SGLOBAL['prefix_url'];
	} else {
		return '';
	}
}

//获取指定用户的好友的uid列表
function _my_get_friends($uid) {
	global $_SGLOBAL, $space;
	
	$var = "my_get_friends_$uid";
	if(!isset($_SGLOBAL[$var])) {
		$_SGLOBAL[$var] = array();
		if($uid == $space['uid']) {
			$_SGLOBAL[$var] = $space['friends'];
		} elseif ($uid == $_SGLOBAL['member']['uid']) {
			$_SGLOBAL[$var] = $_SGLOBAL['member']['friends'];
		} else {
			$query = $_SGLOBAL['db']->query("SELECT fuid FROM ".tname('friend')." WHERE uid='$uid' AND status='1' ORDER BY dateline DESC");
			while ($value = $_SGLOBAL['db']->fetch_array($query)) {
				$_SGLOBAL[$var][] = $value['fuid'];
			}
		}
	}
	return $_SGLOBAL[$var];
}

//获取指定用户显示的名字
function _my_get_name($uid) {
	global $_SGLOBAL, $space, $_SCONFIG;
	
	$var = "my_get_name_$uid";
	if(!isset($_SGLOBAL[$var])) {
		$_SGLOBAL[$var] = '';
		if($uid == $space['uid']) {
			$_SGLOBAL[$var] = $_SCONFIG['realname'] && $space['name'] && $space['namestatus'] ?$space['name']:$space['username'];
		} elseif ($uid == $_SGLOBAL['member']['uid']) {
			$_SGLOBAL[$var] = $_SCONFIG['realname'] && $_SGLOBAL['member']['name'] && $_SGLOBAL['member']['namestatus']?$_SGLOBAL['member']['name']:$_SGLOBAL['member']['username'];
		} else {
			$query = $_SGLOBAL['db']->query("SELECT username,name,namestatus FROM ".tname('space')." WHERE uid='$uid'");
			if($value = $_SGLOBAL['db']->fetch_array($query)) {
				$_SGLOBAL[$var] = $_SCONFIG['realname'] && $value['name'] && $value['namestatus']?$value['name']:$value['username'];
			}
		}
	}
	return $_SGLOBAL[$var];
}

//获取指定用户头像的url
function _my_get_profilepic($uid, $size='small') {
	return UC_API.'/avatar.php?uid='.$uid.'&size='.$size;
}

//判断uid1和uid2是否为好友
function _my_are_friends($uid1, $uid2) {
	global $_SGLOBAL, $space, $_SCONFIG;
	
	$var = "my_are_friends_{$uid1}_{$uid2}";
	if(!isset($_SGLOBAL[$var])) {
		$_SGLOBAL[$var] = false;
		if($uid1 == $space['uid']) {
			if($space['friends'] && in_array($uid2, $space['friends'])) {
				$_SGLOBAL[$var] = true;
			}
		} elseif($uid2 == $space['uid']) {
			if($space['friends'] && in_array($uid1, $space['friends'])) {
				$_SGLOBAL[$var] = true;
			}
		} else {
			$query = $_SGLOBAL['db']->query("SELECT uid FROM ".tname('friend')." WHERE uid='$uid1' AND fuid='$uid2' AND status='1' LIMIT 1");
			if($value = $_SGLOBAL['db']->fetch_array($query)) {
				$_SGLOBAL[$var] = true;
			}
		}
	}
	return $_SGLOBAL[$var];
}


?>