User Tools

Avatar integration

Pre-requisite The avatar(image) url , if not the complete url , atleast the name must be stored in the database/session/cookie

General idea

Please read the General idea before moving further.

Fetching the avatar

You need to modify the query of any of the three functions get_guests() , get_users() or get_buddies() according to your needs so that it fecthes the avatar url or atleast the avatar image name from the database The function you edit depends on your backend settings .

for eg. if you choose to show users in the backend , you must edit get_users() and not any other function.

An eg is given below [Below is query of get_guests()]

SELECT DISTINCT status_mesg,username,session_id,STATUS,guest,X.avatar 
FROM frei_session , TABLE_NAME AS X 
WHERE time>" . $this->online_time2 . " AND session_id!=" . $_SESSION[$this->uid . 'usr_ses_id'] . "
      AND STATUS!=2 AND STATUS!=0 AND X.userid = session_id

in the above example $_SESSION[$this→uid . 'usr_ses_id'] is the userid of the current user in your website. If you want to use X.somethingelse instead of X.avatar , there will be a problem . because FreiChat by default retrieves the url from X.avatar . So you will need to make the following change Go to ~/freichat/hardcode.php Replace $this→avatar_field_name = 'avatar'; by $this→avatar_field_name = 'somethingelse'; Now the get_guests() will be returning the avatar url correctly.


If you are not storing the avatar url in the database , you can even use session/cookie I assume the avatar url is stored in $_SESSION['avatar']; Now you need to make following changes, in the necessary function i.e get_guests() or get_users() or get_buddies() Replace

$list = $this->db->query($query)->fetchAll();


$list = $this->db->query($query)->fetchAll(); 
foreach($list as $temp) 
  $list[$i]['avatar'] = $_SESSION['avatar']; //update the original array

That should do the job . Note : if you use somethingelse instead of avatar in $list[$i]['avatar'] you need to follow the same steps as given above in case of X.somethingelse . Now comes the last bit of work .

The avatar_url() in ~/freichat/server/drivers/Custom.php This function returns the url you fetched from the database/session/cookie to freichat .

The parameter $avatar in avatar_url() is actually the avatar url that you return from get_guests() or get_users() or get_buddies() This function was made so that you can modify the avatar url .

For eg . Assume following folder structure

1. A/B/freichat [freichat folder]

2. A/D/E/avatar [avatar folder]

if you had made an SQL query in get_guests() which returned avatar url as /E/avatar/XYZ.png , FreiChat would fail to get the avatar image because the url is incomplete So the solution is as follows [as per avatar_url()]

public function avatar_url($avatar) 
      $murl = "A/D"; $avatar_url = $murl . $avatar; 
      return $avatar_url; 

Now the url returned would be A/D/E/avatar/XYZ.png And thats what we wanted .