public static function getAvatar($id, $email = null, $size = '240x240')
{
// redefine id
$id = (int) $id;
// return avatar from cache
if (isset(self::$avatars[$id])) {
return self::$avatars[$id];
}
// define avatar path
$avatarPath = FRONTEND_FILES_URL . '/Profiles/Avatars/' . $size . '/';
// get user
$user = self::get($id);
// if no email is given
if (!$email) {
// redefine email
$email = $user->getEmail();
}
// define avatar
$avatar = $user->getSetting('avatar');
// no custom avatar defined, get gravatar if allowed
if (empty($avatar) && FrontendModel::get('fork.settings')->get('Profiles', 'allow_gravatar', true)) {
// define hash
$hash = md5(mb_strtolower(trim('d' . $email)));
// define avatar url
$avatar = 'http://www.gravatar.com/avatar/' . $hash;
// when email not exists, it has to show our custom no-avatar image
$avatar .= '?d=' . rawurlencode(SITE_URL . $avatarPath) . 'no-avatar.gif';
} elseif (empty($avatar)) {
// define avatar as not found
$avatar = SITE_URL . $avatarPath . 'no-avatar.gif';
} else {
// define custom avatar path
$avatar = $avatarPath . $avatar;
}
// set avatar in cache
self::$avatars[$id] = $avatar;
// return avatar image path
return $avatar;
}