FreiChat related discussions
Help needed on custom setup (2 problems)

I have two issues. I will deal with the easy one first.

Problem 1

My custom setup is using the gravatar system to obtain member images as opposed to storing them in the database. Unfortunately, although you have integrated your default system with gravatar, you don't connect it to the members email column in the database and return gravatar images by default. Instead its either - connect to a database that stores user images, or use random gravatars.

So what I want to know is how can I pass an email variable to server/freichat.php so we can correctly call the images. I have tried with my limited php knowledge to call the database directly from freichat.php but it seems doing so, causes the script to stop working (simple mysql_query statement).

So that is problem one.

Problem 2:

Problem two is more complex, because I am not sure how easily your system can integrate with what I have. I want to integrate the chat with our custom friend list. The friend list uses the following table setup:

username, friendname, friend-status

username is matched to $_SESSION[user] and if the friend-status is 2 the users are connected as friends, 1 and 0 are pending statuses.

$_SESSION[user] is not the same as $_SESSION[userid] wihich $ses is set to.

So I am not sure how to go about making this work... if I can at all.

I have two issues. I will deal with the easy one first. **Problem 1** My custom setup is using the gravatar system to obtain member images as opposed to storing them in the database. Unfortunately, although you have integrated your default system with gravatar, you don't connect it to the members email column in the database and return gravatar images by default. Instead its either - connect to a database that stores user images, or use random gravatars. So what I want to know is how can I pass an email variable to server/freichat.php so we can correctly call the images. I have tried with my limited php knowledge to call the database directly from freichat.php but it seems doing so, causes the script to stop working (simple mysql_query statement). So that is problem one. **Problem 2:** Problem two is more complex, because I am not sure how easily your system can integrate with what I have. I want to integrate the chat with our custom friend list. The friend list uses the following table setup: username, friendname, friend-status username is matched to $_SESSION[user] and if the friend-status is 2 the users are connected as friends, 1 and 0 are pending statuses. $_SESSION[user] is not the same as $_SESSION[userid] wihich $ses is set to. So I am not sure how to go about making this work... if I can at all.

I am assuming you are using Custom driver in freichat.

For the 1st problem you need the email address of the user.

Open the file freichat/server/drivers/Custom.php

Edit the query in the method getDBdata() so that it selects the email of the user along with the userid and username.

From the result, save the email in a session like this:

$_SESSION['user_email'] = $result['mail'];

Then, open freichat.php
You can now use the email id stored in the SESSION and modify the url around line 441

$avatar_url = "http://www.gravatar.com/avatar/" . md5($guest) . "?s=24&d=wavatar"; //$this->url . "/client/jquery/user.jpeg";

For your second problem, what is $_SESSION[user] ?
What is stored in it ?

As for how to integrate with your friend system, you need to modify the queries defined in the methods get_guests(), get_users(), get_buddies() in the file freichat/server/drivers/Custom.php

For reference, you can check the method get_buddies() in the files JCB.php and JSocial.php in the drivers folder

I am assuming you are using Custom driver in freichat. For the 1st problem you need the email address of the user. Open the file freichat/server/drivers/Custom.php Edit the query in the method getDBdata() so that it selects the email of the user along with the userid and username. From the result, save the email in a session like this: ``` $_SESSION['user_email'] = $result['mail']; ``` Then, open freichat.php You can now use the email id stored in the SESSION and modify the url around line 441 ``` $avatar_url = "http://www.gravatar.com/avatar/" . md5($guest) . "?s=24&d=wavatar"; //$this->url . "/client/jquery/user.jpeg"; ``` --- For your second problem, what is $_SESSION[user] ? What is stored in it ? As for how to integrate with your friend system, you need to modify the queries defined in the methods get_guests(), get_users(), get_buddies() in the file freichat/server/drivers/Custom.php For reference, you can check the method get_buddies() in the files JCB.php and JSocial.php in the drivers folder

I am guessing we both had similar thoughts about how easy this should be but it doesn't seem to be as easy as I hoped.

So I modified as suggested. At line 441 I changed the original avatar call to:

$avatar_url = "http://www.gravatar.com/avatar/" . md5($_SESSION['user_email']) . "?s=24&d=wavatar";

It worked, and exactly as it should have, however the outcome was not as expected. Instead of returning images from gravatar based on various users emails, it turned everyones avatar into the logged in users image. So for example if I was logged in, to me it would appear as every other member had my photo.

The question is, where is the actual avatar image being set for active logged in users and how. It seems its all being done through a check system to see if variables are set, which won't work as those variables are not set.

As for my second problem - I will come back to that after the first problem is working.

I am guessing we both had similar thoughts about how easy this should be but it doesn't seem to be as easy as I hoped. So I modified as suggested. At line 441 I changed the original avatar call to: ```` $avatar_url = "http://www.gravatar.com/avatar/" . md5($_SESSION['user_email']) . "?s=24&d=wavatar"; ```` It worked, and exactly as it should have, however the outcome was not as expected. Instead of returning images from gravatar based on various users emails, it turned everyones avatar into the logged in users image. So for example if I was logged in, to me it would appear as every other member had my photo. The question is, where is the actual avatar image being set for active logged in users and how. It seems its all being done through a check system to see if variables are set, which won't work as those variables are not set. As for my second problem - I will come back to that after the first problem is working.

Sorry about that.

The correct solution is to fetch the email id in the query get_guests(), get_users(), get_buddies() in Custom.php file.

Fo example, you can modify the query

            $query = "SELECT DISTINCT f.status_mesg,f.username,f.session_id,f.status,f.guest,f.in_room
                   FROM frei_session AS f 
                  WHERE f.time>" . $this->online_time2 . "
                   AND f.session_id!=" . $_SESSION[$this->uid . 'usr_ses_id'] . "
                   AND f.status!=2
                   AND f.status!=0";

to

            $query = "SELECT DISTINCT f.status_mesg,f.username,f.session_id,f.status,f.guest,f.in_room,
u.email
                   FROM frei_session AS f
                  INNER JOIN users AS u ON f.session_id=u.userid 
                  WHERE f.time>" . $this->online_time2 . "
                   AND f.session_id!=" . $_SESSION[$this->uid . 'usr_ses_id'] . "
                   AND f.status!=2
                   AND f.status!=0";

Above, I selected email column from users table by joining on userid column of users table with session_id column of frei_session table.

Modify the query as per your database.

After that

You can modify the line, in freichat.php

            $avatar_url = "http://www.gravatar.com/avatar/" . md5($guest) . "?s=24&d=wavatar"; //$this->url . "/client/jquery/user.jpeg";

by using the email id which will be available in the variable $res['email'].

Sorry about that. The correct solution is to fetch the email id in the query get_guests(), get_users(), get_buddies() in Custom.php file. Fo example, you can modify the query ``` $query = "SELECT DISTINCT f.status_mesg,f.username,f.session_id,f.status,f.guest,f.in_room FROM frei_session AS f WHERE f.time>" . $this->online_time2 . " AND f.session_id!=" . $_SESSION[$this->uid . 'usr_ses_id'] . " AND f.status!=2 AND f.status!=0"; ``` to ``` $query = "SELECT DISTINCT f.status_mesg,f.username,f.session_id,f.status,f.guest,f.in_room, u.email FROM frei_session AS f INNER JOIN users AS u ON f.session_id=u.userid WHERE f.time>" . $this->online_time2 . " AND f.session_id!=" . $_SESSION[$this->uid . 'usr_ses_id'] . " AND f.status!=2 AND f.status!=0"; ``` Above, I selected email column from users table by joining on userid column of users table with session_id column of frei_session table. Modify the query as per your database. After that You can modify the line, in freichat.php ``` $avatar_url = "http://www.gravatar.com/avatar/" . md5($guest) . "?s=24&d=wavatar"; //$this->url . "/client/jquery/user.jpeg"; ``` by using the email id which will be available in the variable `$res['email']`.

Now this is outside the scope of simple helping, but I am curious...... What is "DISTINCT" for in the sql query?

Now this is outside the scope of simple helping, but I am curious...... What is "DISTINCT" for in the sql query?

It is used to select only the unique results.

But, it is not required, its like an old piece of code that still exists.

It is used to select only the unique results. But, it is not required, its like an old piece of code that still exists.
edited Nov 10 '15 at 7:47 pm

Once again, works perfect, but not entirely as expected.

I did a join on all three queries, guest, friend, and buddy.....

That makes the user list work perfectly..... at the expense of guests. Meaning guests can see logged in users, but logged in users cannot see guests.

I have tried all sorts of variations, only setting on guest, only on user, only on buddy, on combinations.... my guess is I am going to require some sort of a loop on the $list so

if (u.email>'0') {
        $list = $this->db->query($query)->fetchAll();
} else {

        $list = $list = $this->db->query($query)->....(I dont know how to do this part)....;
}
Once again, works perfect, but not entirely as expected. I did a join on all three queries, guest, friend, and buddy..... That makes the user list work perfectly..... at the expense of guests. Meaning guests can see logged in users, but logged in users cannot see guests. I have tried all sorts of variations, only setting on guest, only on user, only on buddy, on combinations.... my guess is I am going to require some sort of a loop on the $list so ```` if (u.email>'0') { $list = $this->db->query($query)->fetchAll(); } else { $list = $list = $this->db->query($query)->....(I dont know how to do this part)....; } ````

I figured out this issue, I will make a new thread about the next one instead of continuing here.

My solution is as follows - so hopefully you can incorporate it in future releases for those systems that don't store user photo's by default. I only needed to modify the get_guests function as that is the only function where viewing guests gravatar was a problem:

I changed it in the following ways:

    public function get_guests() {

        //do not delete below comment
        //CUSTOM_GUESTS_QUERY_START
            $query = "SELECT DISTINCT f.status_mesg,f.username,f.session_id,f.status,f.guest,f.in_room,u.email
                   FROM frei_session AS f
                   INNER JOIN oto_members AS u ON f.session_id=u.Id
                   WHERE f.time>" . $this->online_time2 . "
                   AND f.session_id!=" . $_SESSION[$this->uid . 'usr_ses_id'] . "
                   AND f.status!=2
                   AND f.status!=0
                   AND u.Id>0";
            $query2 = "SELECT DISTINCT f.status_mesg,f.username,f.session_id,f.status,f.guest,f.in_room
                   FROM frei_session AS f
                   WHERE f.time>" . $this->online_time2 . "
                   AND f.session_id!=" . $_SESSION[$this->uid . 'usr_ses_id'] . "
                   AND f.status!=2
                   AND f.status!=0";
        //CUSTOM_GUESTS_QUERY_END
        //do not delete above comment
        $array1=$this->db->query($query)->fetchAll();
        $array2=$this->db->query($query2)->fetchAll();
        $list=array_merge($array1, $array2);
        return $list;
}

I did an array join because guests were not properly being returned when no email was found. So this does two queries, one for users, the other for guests. Then it joins the arrays as $list.

In the freichat.php file I changed the gravatar call to the following:

if (!isset($res['email'])) {
 $avatar_url = "http://www.gravatar.com/avatar/" . md5($guest) . "?s=24&d=wavatar";
} else {
$avatar_url = "http://www.gravatar.com/avatar/" . md5($res['email']) . "?s=24&d=wavatar"; //$this->url . "/client/jquery/user.jpeg";
}

Hope this helps the future of freichat integration. smile

I figured out this issue, I will make a new thread about the next one instead of continuing here. My solution is as follows - so hopefully you can incorporate it in future releases for those systems that don't store user photo's by default. I only needed to modify the get_guests function as that is the only function where viewing guests gravatar was a problem: I changed it in the following ways: ```` public function get_guests() { //do not delete below comment //CUSTOM_GUESTS_QUERY_START $query = "SELECT DISTINCT f.status_mesg,f.username,f.session_id,f.status,f.guest,f.in_room,u.email FROM frei_session AS f INNER JOIN oto_members AS u ON f.session_id=u.Id WHERE f.time>" . $this->online_time2 . " AND f.session_id!=" . $_SESSION[$this->uid . 'usr_ses_id'] . " AND f.status!=2 AND f.status!=0 AND u.Id>0"; $query2 = "SELECT DISTINCT f.status_mesg,f.username,f.session_id,f.status,f.guest,f.in_room FROM frei_session AS f WHERE f.time>" . $this->online_time2 . " AND f.session_id!=" . $_SESSION[$this->uid . 'usr_ses_id'] . " AND f.status!=2 AND f.status!=0"; //CUSTOM_GUESTS_QUERY_END //do not delete above comment $array1=$this->db->query($query)->fetchAll(); $array2=$this->db->query($query2)->fetchAll(); $list=array_merge($array1, $array2); return $list; } ```` I did an array join because guests were not properly being returned when no email was found. So this does two queries, one for users, the other for guests. Then it joins the arrays as $list. In the freichat.php file I changed the gravatar call to the following: ```` if (!isset($res['email'])) { $avatar_url = "http://www.gravatar.com/avatar/" . md5($guest) . "?s=24&d=wavatar"; } else { $avatar_url = "http://www.gravatar.com/avatar/" . md5($res['email']) . "?s=24&d=wavatar"; //$this->url . "/client/jquery/user.jpeg"; } ```` Hope this helps the future of freichat integration. :)
280
8
2
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
With selected deselect posts show selected posts
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft