Frontend\Modules\Profiles\Engine\Model::getAvatar PHP Method

getAvatar() public static method

Get avatar
public static getAvatar ( integer $id, string $email = null, string $size = '240x240' ) : string
$id integer The id for the profile we want to get the avatar from.
$email string The email from the user we can use for gravatar.
$size string The resolution you want to use. Default: 240x240 pixels.
return string $avatar The absolute path to the avatar.
    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;
    }