Advertisement:

Author Topic: [TUTORIAL] Step-By-Step chat (Buyer to seller) integration in osclass  (Read 16519 times)

nektm

  • Newbie
  • *
  • Posts: 15
I think there are many who may wants to integrate Chat option in Osclass, if not interested then just ignore this tutorial :)

1) First of all download friechat from https://bitbucket.org/evnix/freichat-free-chat-script/downloads/FreiChat.V.9.6.zip

2) Extract friechat folder in osclass root directory

3) Open main.php from current theme folder and place the below code between <head></head>

NOTE: DON'T FORGET TO CHANGE "YOURDOMAINNAME.COM" IN BELOW CODE

Code: [Select]
            <?php

       if(
osc_is_web_user_logged_in())
      
{
      
    $ses osc_logged_user_id() ; //tell freichat the userid of the current user

      
    setcookie("freichat_user""LOGGED_IN"time() 3600"/"); // *do not change -> freichat code
      
}
      
else {
      
    $ses null//tell freichat that the current user is a guest

      
    setcookie("freichat_user"nulltime() 3600"/"); // *do not change -> freichat code
      
}


      
if(!function_exists("freichatx_get_hash")){
      
function freichatx_get_hash($ses){

      
       if(is_file("/home/www/YOURDOMAINNAME.COM/freichat/hardcode.php")){

      
               require "/home/www/YOURDOMAINNAME.COM/freichat/hardcode.php";

      
               $temp_id =  $ses $uid;

      
               return md5($temp_id);

      
       }
      
       else
      
       {
      
        echo "<script>alert('module freichatx says: hardcode.php file not found!');</script>";
      
       }

      
return 0;
      
}
      
}

      
?>


<script type="text/javascript" language="javascipt" src="http://www.YOURDOMAINNAME.com/freichat/client/main.php?id=<?php echo $ses;?>&xhash=<?php echo freichatx_get_hash($ses); ?>"></script>
<link rel="stylesheet" href="http://www.YOURDOMAINNAME.com/freichat/client/jquery/freichat_themes/freichatcss.php" type="text/css">



4) Place the below code where you want the online/offline icon to be shown, i place this inside description DIV

Code: [Select]
<div class="onlineuser">
        <?php $user User::newInstance()->findByPrimaryKey(osc_item_user_id()); ?>
         <?php if(useronline_show_user_status() == 1) { ?>
                  <a class="chat_online_inline" id="onlineuser" href="javascript:void(0)" onClick="FreiChat.create_chat_window(<?php echo "'".$user['s_name']."'" ?>, <?php echo osc_item_user_id(); ?>)"></a>
          <?php } else { ?>
                  <a class="chat_offline_inline" href="javascript:void(0)"></a>
           <?php ?>
</div>


Now its time to install friechat in order to integrate with osclass

5) Open browser and install friechat by http://YOURDOMAINNAME.COM/FRIECHAT/ and follow the instruction, You must select "CUSTOMIZED" option from dropdown during installtion, remember you should be logged in to your site using any user before you install friechat, because friechat will search if any user is logged in to your site.

Note: you don't need to copy the code during friechat installation and paste in osclass, because we already did it in <head></head> section. If you didn't then do it before you start installation

6) Download Useronline plugin from http://forums.osclass.org/plugins/(new-plugin)-user-online/?action=dlattach;attach=16512 install and activate it from admin panel.

7) Go to the ../oc-content/plugins/useronline foder and open index.php file

Find and replace this

function useronline_show_user_status() {
   $itemUserId = osc_item_user_id();
   $conn   = getConnection();
   $userOnline=$conn->osc_dbFetchResult("SELECT * FROM %st_useronline WHERE userid = '%s'",DB_TABLE_PREFIX, $itemUserId);
   if($userOnline !=''){
      echo '<img src="'.osc_base_url().'oc-content/plugins/useronline/images/online.png" />' ;
   } else {
      echo '<img src="'.osc_base_url().'oc-content/plugins/useronline/images/offline.png" />' ;
      }
}

With This

function useronline_show_user_status() {
   $itemUserId = osc_item_user_id();
   $conn   = getConnection();
   $userOnline=$conn->osc_dbFetchResult("SELECT * FROM %st_useronline WHERE userid = '%s'",DB_TABLE_PREFIX, $itemUserId);
   if($userOnline !=''){
      return 1;
   } else {
      return 0;
      }
}

8 ) Copy the oc-content/plugins/useronline/images/online.png and paste in your current theme image folder

9) Copy the oc-content/plugins/useronline/images/offline.png and paste in your current theme image folder


10) Open style.css file of your current theme and place below style code anywhere you want

Code: [Select]
.chat_online_inline{background:url(images/online.png) no-repeat;}
 .chat_offline_inline{background:url(images/offline.png) no-repeat;}
.chat_online_inline,.chat_offline_inline{float:right; display: block; cursor:pointer;}


Thanks to cartagena68 for useronline plugin :)
any better suggestions are welcomed :)
« Last Edit: April 26, 2014, 11:48:45 am by nektm »

creat15

  • Full Member
  • ***
  • Posts: 218
Re: [TUTORIAL] Step-By-Step chat (Buyer to seller) integration in osclass
« Reply #1 on: April 26, 2014, 09:12:58 am »
thanks for tutorial :)

this safe from SPAM or hacker?


creat15

  • Full Member
  • ***
  • Posts: 218
Re: [TUTORIAL] Step-By-Step chat (Buyer to seller) integration in osclass
« Reply #2 on: April 26, 2014, 09:17:14 am »
thanks for tutorial :)

this safe from SPAM or hacker?

nektm

  • Newbie
  • *
  • Posts: 15
Re: [TUTORIAL] Step-By-Step chat (Buyer to seller) integration in osclass
« Reply #3 on: April 26, 2014, 09:36:09 am »
thanks for tutorial :)

this safe from SPAM or hacker?

Yes it's safe.
1) You should disable the public chat module from freichat admin panel after installation.
2) Hide the freichat user list & "powered by" --   Go to ../freichat/client/theme/basic/ folder and open style.css file then replace below:

Code: [Select]
#freichat {
  position: fixed;
  right: 0px;
  bottom: 0px;
  margin-right: 5px;
  font-family: helvetica, arial, sans-serif;
  font-size: 13px;
  visibility: hidden;
}
.freichat {
  position: relative;
  padding: 0px;
  background-color: none;
  color: #000000;
  text-align: justify;
  font-size: 14px;
  width: 200px;
  background-image: none;
  border: none;
  line-height: 1.4em;
  margin: 0px;
  visibility: hidden;
}

above style code will hide the friechat user list in your website. Chat window will open only when clicked by mouse on online user icon.

:):):)

renzols

  • Newbie
  • *
  • Posts: 8
Re: [TUTORIAL] Step-By-Step chat (Buyer to seller) integration in osclass
« Reply #4 on: April 26, 2014, 10:31:50 am »
whre wp-config ?

nektm

  • Newbie
  • *
  • Posts: 15
Re: [TUTORIAL] Step-By-Step chat (Buyer to seller) integration in osclass
« Reply #5 on: April 26, 2014, 11:17:17 am »
whre wp-config ?

Did you installed Wordpress in the same root folder? because Wp-Config.php file is related to the wordpress.

Where did you extracted freichat folder? it should be inside <Yourdomainname.com>

You must select "CUSTOMIZED" OPTION from dropdown during installation
« Last Edit: April 26, 2014, 11:22:05 am by nektm »

renzols

  • Newbie
  • *
  • Posts: 8
Re: [TUTORIAL] Step-By-Step chat (Buyer to seller) integration in osclass
« Reply #6 on: April 26, 2014, 11:39:14 am »
i got this error when i enter this code
Parse error: syntax error, unexpected '3600' (T_LNUMBER) in



Code: [Select]
            <?php

       if(
osc_is_web_user_logged_in())
      
{
      
    $ses osc_logged_user_id() ; //tell freichat the userid of the current user

      
    setcookie("freichat_user""LOGGED_IN"time() 3600"/"); // *do not change -> freichat code
      
}
      
else {
      
    $ses null//tell freichat that the current user is a guest

      
    setcookie("freichat_user"nulltime() 3600"/"); // *do not change -> freichat code
      
}


      
if(!function_exists("freichatx_get_hash")){
      
function freichatx_get_hash($ses){

      
       if(is_file("/home/www/YOURDOMAINNAME.COM/freichat/hardcode.php")){

      
               require "/home/www/YOURDOMAINNAME.COM/freichat/hardcode.php";

      
               $temp_id =  $ses $uid;

      
               return md5($temp_id);

      
       }
      
       else
      
       {
      
        echo "<script>alert('module freichatx says: hardcode.php file not found!');</script>";
      
       }

      
return 0;
      
}
      
}

      
?>

nektm

  • Newbie
  • *
  • Posts: 15
Re: [TUTORIAL] Step-By-Step chat (Buyer to seller) integration in osclass
« Reply #7 on: April 26, 2014, 11:47:43 am »
i got this error when i enter this code
Parse error: syntax error, unexpected '3600' (T_LNUMBER) in



Code: [Select]
            <?php

       if(
osc_is_web_user_logged_in())
      
{
      
    $ses osc_logged_user_id() ; //tell freichat the userid of the current user

      
    setcookie("freichat_user""LOGGED_IN"time() 3600"/"); // *do not change -> freichat code
      
}
      
else {
      
    $ses null//tell freichat that the current user is a guest

      
    setcookie("freichat_user"nulltime() 3600"/"); // *do not change -> freichat code
      
}


      
if(!function_exists("freichatx_get_hash")){
      
function freichatx_get_hash($ses){

      
       if(is_file("/home/www/YOURDOMAINNAME.COM/freichat/hardcode.php")){

      
               require "/home/www/YOURDOMAINNAME.COM/freichat/hardcode.php";

      
               $temp_id =  $ses $uid;

      
               return md5($temp_id);

      
       }
      
       else
      
       {
      
        echo "<script>alert('module freichatx says: hardcode.php file not found!');</script>";
      
       }

      
return 0;
      
}
      
}

      
?>

paste below code after the ?>
Code: [Select]
<script type="text/javascript" language="javascipt" src="http://www.YOURDOMAINNAME.com/freichat/client/main.php?id=<?php echo $ses;?>&xhash=<?php echo freichatx_get_hash($ses); ?>"></script>
    <link rel="stylesheet" href="http://www.YOURDOMAINNAME.com/freichat/client/jquery/freichat_themes/freichatcss.php" type="text/css">
     

Note: change "YOUDOMAINNAME"

cartagena68

  • issues
  • Hero Member
  • *
  • Posts: 1198
@ nektm

first of all, nice tutorial!  ;)

But, i have to say, there some errors to correct and some improvement to do.
Now is to late, but tomorrow i will replay with the changes you need to make and also i will upload a new version of useronline plugin that include the functions needed to work with freichat, so you don't have to change the plugin code.

cartagena68

  • issues
  • Hero Member
  • *
  • Posts: 1198
THIS  TUTORIAL IS OUT OF DATE.

CHECK OUT THIS PLUGIN



http://forums.osclass.org/plugins/freichat/




Here is useronline plugin freichat integration ready.
the tutorial for integration is in plugin help but i'm posting it also here.

FreiChat Integration

1) Download freichat from https://bitbucket.org/evnix/freichat-free-chat-script/downloads/FreiChat.V.9.6.zip
2) Extract freichat folder in osclass root directory 
3) Place the below code between <head></head>, usually in header.php in your theme folder.
IMPORTANT! in the code below, at the 2 lines saying  time() 3600 should be time()plus sign3600 i don't know why, but posting is deleting the plus sign. DO NOT WRITE "plus sign", JUST THE SYMBOL. Or copy this code from HELP in plugin.

               
Code: [Select]
<!--===========================FreiChat=======START=========================-->
<!-- For uninstalling ME , first remove/comment all FreiChat related code i.e below code
Then remove FreiChat tables frei_session & frei_chat if necessary
         The best/recommended way is using the module for installation                         -->

<?php
if(USER_IS_LOGGED_IN)

    
$ses osc_logged_user_id() ; //tell freichat the userid of the current user

    
setcookie("freichat_user""LOGGED_IN"time() 3600"/"); // *do not change -> freichat code
}
else {
    
$ses null//tell freichat that the current user is a guest

    
setcookie("freichat_user"nulltime() 3600"/"); // *do not change -> freichat code


if(!
function_exists("freichatx_get_hash")){
function 
freichatx_get_hash($ses){

       if(
is_file(osc_base_path()."/freichat/hardcode.php")){

               require 
osc_base_path()."/freichat/hardcode.php";

               
$temp_id =  $ses $uid;

               return 
md5($temp_id);

       }
       else
       {
               echo 
"<script>alert('module freichatx says: hardcode.php file not
found!');</script>"
;
       }

       return 
0;
}
}
?>

<script type="text/javascript" language="javascipt" src="<?php echo osc_base_url() ; ?>freichat/client/main.php?id=<?php echo $ses;?>&xhash=<?php echo freichatx_get_hash($ses); ?>"></script>
<link rel="stylesheet" href="<?php echo osc_base_url() ; ?>freichat/client/jquery/freichat_themes/freichatcss.php" type="text/css">
<!--===========================FreiChatX=======END=========================-->   
               
4) Place the below code in item.php where you want the chat icon/text to be shown

                   
Code: [Select]
<?php if(function_exists('useronline_show_chat')) {useronline_show_chat();} ?>
               
Now its time to install freichat in order to integrate with osclass

5) Open browser and install freichat by http://YOURDOMAINNAME.COM/freichat/ and follow exactly the instruction, You must select "CUSTOMIZED" option from dropdown menu regarding integration during installation.
During intallation you will be asked for database information(db name, password etc.) then they will also ask about user information table,
the user table is: YOUR TABLE PREFIX_t_user
the user name row is: s_name
and the user id row is: pk_i_id
Remember you should be logged in to your site (front end) using any user before you install freichat, because freichat will search if any user is logged in to your site.
« Last Edit: May 10, 2014, 07:04:25 am by cartagena68 »

nektm

  • Newbie
  • *
  • Posts: 15


@cartagena68

Thanks you for simplifying tutorial and modifying useronline plugin:)



cartagena68

  • issues
  • Hero Member
  • *
  • Posts: 1198
You are welcome,
is a good tutorial from the beginning.
The error i was talking about is not your fault, is that this forum don't aloud to write the plus symbol, so it just desappear when you post ( that is why he was giving the error to renzols).
The rest was ok, i just include the new functions to the plugin and i use the osclass function for site path and site url.

Thank you for starting this tutorial.

frosticek

  • Hero Member
  • *****
  • Posts: 3948
@nektm
Looks cool, I will need to test it :)

cartagena68

  • issues
  • Hero Member
  • *
  • Posts: 1198
Now is availabe this

http://forums.osclass.org/plugins/freichat/

with this plugin you don't need to copy and paste the freichat code, just follow the instructions.

praveend06

  • Newbie
  • *
  • Posts: 29
Re: [TUTORIAL] Step-By-Step chat (Buyer to seller) integration in osclass
« Reply #14 on: July 15, 2014, 01:31:57 pm »
I have installed freichat with osclass 3.3.2 (twitter theme), and it show chat icon in item page.
BUT I am facing two issues.

1. If I open login with two user different user in different browser and send message from on to other it does not display to other. (for other user chat window should open with message).

2. If I open chat window to send message and close it  and click again on chat icon it give javascript error
ReferenceError: FreiChat is not defined

Please help me to resolve this.