I have to do this after the above step:-
Update user information fetching mechanism
Your getUserDetails() will look like:
function getUserDetails($userid){
$sql = ("select userid, username, link, avatar, cometchat_status.lastactivity, cometchat_status.status, cometchat_status.message, cometchat_status.isdevice from left join cometchat_status on userid = cometchat_status.userid where userid = '" . mysqli_real_escape_string($GLOBALS['dbh'], $userid) . "'");
return $sql;
}
Update status message, avatar and links functionality
The getUserStatus() function returns the current status message as well as the state of the user (available, busy, invisible, offline). If your site already has a status updates feature, then you will have to modify the first field- cometchat_status.message which is returned to pull the status message from your table.
Finally, we modify fetchLink() and getAvatar() function
When the getFriendsList() function is executed, avatar and link contain the user id by default (you can change this if you store the avatar/link location in your table). fetchLink() and getAvatar() functions are used to post-process the data obtained from the getFriendsList() function.
For example:
function fetchLink($link) {
return BASE_URL.'../users.php?id='.$link;
}
function getAvatar($image) {
if (is_file(dirname(dirname(__FILE__)).'/images/'.$image.'.gif')) {
return BASE_URL.'../images/'.$image.'.gif';
} else {
return BASE_URL.'images/noavatar.png';
}
}
The hooks_statusupdate() function is called when a user updates his/her status via CometChat. If your site already has a status updates feature, you can update that using this hook.
Adding compatibility with Mobile apps and Desktop Messenger (Optional)
Your chatLogin() will look like:
function chatLogin($userName,$userPass) {
$userid = 0;
$sql = ("SELECT * FROM users WHERE username='".$userName."'");
$result = mysqli_query($GLOBALS['dbh'],$sql);
$row = mysqli_fetch_assoc($result);
$check = md5(md5($userPass));
if ($check==$row['password']) {
$userid = $row['user_id'];
if (isset($_REQUEST['callbackfn']) && $_REQUEST['callbackfn'] == 'mobileapp') {
$sql = ("insert into cometchat_status (userid,isdevice) values ('".mysqli_real_escape_string($GLOBALS['dbh'],$userid)."','1') on duplicate key update isdevice = '1'");
mysqli_query($GLOBALS['dbh'], $sql);
}
}
if (function_exists('mcrypt_encrypt') && defined('ENCRYPT_USERID') && ENCRYPT_USERID == '1') {
$key = KEY_A.KEY_B.KEY_C;
$userid = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $userid, MCRYPT_MODE_CBC, md5(md5($key))));
}
return $userid;
}
The chatLogin() returns user id of logged in user if the username and password are authenticated successfully.
In your getUserID(), add the following code after $userid = 0;
if (!empty($_SESSION['basedata']) && $_SESSION['basedata'] != 'null') {
$_REQUEST['basedata'] = $_SESSION['basedata'];
}
if (!empty($_REQUEST['basedata'])) {
if (function_exists('mcrypt_encrypt')) {
$key = KEY_A.KEY_B.KEY_C;
$uid = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($_REQUEST['basedata']), MCRYPT_MODE_CBC, md5(md5($key))), "");
if (intval($uid) > 0) {
$userid = $uid;
}
} else {
$userid = $_REQUEST['basedata'];
}
}
So, your getUserID() will look like:
function getUserID() {
$userid = 0;
if (!empty($_SESSION['basedata']) && $_SESSION['basedata'] != 'null') {
$_REQUEST['basedata'] = $_SESSION['basedata'];
}
if (!empty($_REQUEST['basedata'])) {
if (function_exists('mcrypt_encrypt')) {
$key = KEY_A.KEY_B.KEY_C;
$uid = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($_REQUEST['basedata']), MCRYPT_MODE_CBC, md5(md5($key))), "");
if (intval($uid) > 0) {
$userid = $uid;
}
} else {
$userid = $_REQUEST['basedata'];
}
}
if (!empty($_SESSION['userid'])){
$userid = $_SESSION['userid'];
}
return $userid;
}
Installation
* Step 1
You should now run the installer file through your web browser by entering the URL into your browser address bar (if you have followed our example, type in
http://www.domain.com/cometchat/install.php, naturally substituting ‘domain.com’ for your web address).
If the installation was completed successfully, then two codes will be displayed on your screen. The first code is for docked themes like Glass, Hangout, Facebook etc. and the second is for embedded theme i.e. Synergy. Please copy the appropriate lines of code depending on whether you wish to use docked themes or embedded theme.
* Step 2
To use docked theme:
Edit your template header. Immediately after the opening head tag add the code copied in step 1.
To embed CometChat in your site:
Add the code copied for embedded theme from step 1 in your site’s HTML code to embed the chat.
Now delete install.php file from the cometchat folder.
Adding Cache support
Before you begin with this step, please enable one of the caching options from CometChat Admin Panel.
Then you need to modify the getFriendsList() and getFriendsIds() in integration.php file.
a. Show all online users with caching enabled
To use caching for all online users, no change is required; simply use the getFriendsList function from above (Update Who’s Online list fetching mechanism).
b. Show online friends with caching enabled
When using caching and wanting to show only online friends, you still need to modify the getFriendsList function to show all online users as follows.
function getFriendsList($userid, $time){
$sql = ("select userid, username, link, avatar, cometchat_status.lastactivity, cometchat_status.status, cometchat_status.message, cometchat_status.isdevice from left join cometchat_status on = cometchat_status.userid where (('" . mysqli_real_escape_string($GLOBALS['dbh'], $time) . "' - cometchat_status.lastactivity < '".((ONLINE_TIMEOUT)*2)."') OR cometchat_status.isdevice = 1) and (cometchat_status.status IS NULL OR cometchat_status.status <> 'invisible' OR cometchat_status.status <> 'offline') order by username asc");
return $sql;
}
Then you need to modify getFriendsIds to return friends for the logged in user. The getFriendsIds() function should return SQL query which retrieves userids of friends.
function getFriendsIds($userid) {
$sql = ("select toid friendid from friends where fromid ='".mysqli_real_escape_string($GLOBALS['dbh'],$userid)."' and status = 1 union select fromid friendid from friends where toid='".mysqli_real_escape_string($GLOBALS['dbh'],$userid)."' and status=1");
return $sql;
}