Discuz avatar 函数 获取头像
/**
* 获取头像
*
* @param int $uid 需要获取的用户UID值
* @param string $size 获取尺寸 'small', 'middle', 'big'
* @param boolean $returnsrc 是否直接返回图片src
* @param boolean $real 是否返回真实图片
* @param boolean $static 是否返回真实路径
* @param string $ucenterurl 强制uc路径
*/
function avatar($uid, $size = 'middle', $returnsrc = FALSE, $real = FALSE, $static = FALSE, $ucenterurl = '') {
global $_G;
static $staticavatar;
if($staticavatar === null) {
$staticavatar = $_G['setting']['avatarmethod'];
}
$ucenterurl = empty($ucenterurl) ? $_G['setting']['ucenterurl'] : $ucenterurl;
$size = in_array($size, array('big', 'middle', 'small')) ? $size : 'middle';
$uid = abs(intval($uid));
if(!$staticavatar && !$static) {
return $returnsrc ? $ucenterurl.'/avatar.php?uid='.$uid.'&size='.$size : '<img src="'.$ucenterurl.'/avatar.php?uid='.$uid.'&size='.$size.($real ? '&type=real' : '').'" />';
} else {
$uid = sprintf("%09d", $uid);
$dir1 = substr($uid, 0, 3);
$dir2 = substr($uid, 3, 2);
$dir3 = substr($uid, 5, 2);
$file = $ucenterurl.'/data/avatar/'.$dir1.'/'.$dir2.'/'.$dir3.'/'.substr($uid, -2).($real ? '_real' : '').'_avatar_'.$size.'.jpg';
return $returnsrc ? $file : '<img src="'.$file.'" οnerrοr="this.οnerrοr=null;this.src=\''.$ucenterurl.'/images/noavatar_'.$size.'.gif\'" />';
}
}
页:
[1]