How to display user avatar/photo
toAvatar()
Render a user avatar. If empty, the current user's avatar will be displayed if found or a generic avatar image.
e107::getParser()->toAvatar($data, $parm);
$data - array of user data $parm - array of options
Examples:
$data['user_image'] = $userinfo['image']; $parm = array("w"=>40, "h"=>40); $var['IMAGE'] = e107::getParser()->toAvatar($data, $parm);
echo $tp->toAvatar(USERID); // render avatar of the current user.
$userData = e107::user(5); // Get User data for user-id #5. echo $tp->toAvatar($userData); // requires as a minimum $userData['user_image'].
How to get user data for avatar?
$data = e107::user($id);
Minimal requirements:
$data = array( 'user_image'=>$this->var['user_image'] );
What options are available?
w - width, if not defined, SETIMAGE is used
h - height, if SETIMAGE is used, then it's ignored crop - not used anymore?
shape - either "img-" + shape or "img-rounded rounded"
link - if this is not empty, the result is the mage with link to user settings
class - class for image tag - default: shape-user-avatar Note: if the user is online, then class user-avatar-online is added too.
Examples of using:
Example for comment avatar:
$data = array('user_id'=>$this->var['comment_author_id'], 'user_image'=>$this->var['comment_author_image']);
Example from forum post author avatar:
e107::getParser()->toAvatar($this->postInfo, $parm); e107::getParser()->toAvatar(e107::user($this->var['thread_lastuser']), $opts);
Example from chatbox menu:
e107::getParser()->toAvatar($this->var);
Example from the online plugin:
$userData = array( 'user_image' => $this->currentMember['oimage'], 'user_name' => $this->currentMember['oname'] ); return e107::getParser()->toAvatar($userData, $parm);
Example from Private messages plugin:
return e107::getParser()->toAvatar($this->var, $parm);
Example from Mentions plugin:
/** * Parse and return user avatar image markup ready to be rendered on page. * * @param string $userImage * User image string obtained from db * @return mixed|null|string * Html markup with '<img tag and specified user avatar image>prefs['avatar_size']; $shape = $this->prefs['avatar_border']; return $this->parse->toAvatar( ['user_image' => $userImage], [ 'w' => $measure, 'h' => $measure, 'crop' => 'C', 'shape' => $shape ] ); }
Example from Random Avatar menu plugin:
$user = e107::user($user_id); $parm = array("w"=>150, "h"=>150); $text .= e107::getParser()->toAvatar($user, $parm) .'<br>';
Example from admin area:
$tp->toAvatar(null, array('w'=>30,'h'=>30,'crop'=>1, 'shape'=>'circle'));
Example from news plugin:
e107::getParser()->toAvatar($this->news_item, $parm);
What to check in old plugins:
USERIMAGE USER_AVATAR