News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Tutorial: how to COMPLETELY integrate FlashChat into SMF so you have a cool CHAT

Started by marcnyc, October 09, 2004, 07:21:56 AM

Previous topic - Next topic

Xarcell

Quote from: DLD on November 13, 2004, 12:11:20 AM
I got it working :)

Here is my code maybe this will help others that are using the classic template

// Chat Stats
     $chatrequest = db_query("
            SELECT COUNT(*) AS numb
            FROM  smf_fc_connections
            WHERE userid IS NOT NULL", __FILE__, __LINE__);
         list ($chatcount) = mysql_fetch_row($chatrequest);   
         mysql_free_result($chatrequest);
         
if ( @$_GET['action'] != "chat" ) {
if ( $chatcount == "1" ) {
$singularplural1 = " is ";
$singularplural2 = "";
} else {
$singularplural1 = " are ";
$singularplural2 = "s";
}
echo'
<tr>
<td class="catbg" colspan="2">', $txt['chatStats'], '</td>
</tr><tr>
<td class="windowbg" width="20" valign="middle" align="center">
<a href="', $scripturl, '?action=chat">
<img src="', $settings['images_url'], '/chatIcon.gif" alt="', $txt['chatAlt'], '" border="0" /></a>
</td>
<td class="windowbg2" width="100%">


Currently there ' . $singularplural1 . ' <font color="#FF0000">' . $chatcount . ' User'.$singularplural2.' in the Chat!</font><br>';
if ($context['user']['is_logged'])
echo '
<font size="-2">Users in chat:</font> ';
if ($context['user']['is_logged'])
{

readfile("http://www.mysite.com/yabbse/Flashchat/info.php");
}
}


Ok this is what I used to get mine working without the parse error. Now the page displays, but I got a new error. Any help?

2: readfile(): URL file-access is disabled in the server configuration
File: /home/.abigaildryer/xarcell/veoclan.com/forum/Themes/classic/BoardIndex.template.php (eval?)
Line: 366


machinecarbon

Flash Chat is one of the greatest chat rooms you can get  :D  They have a very easy one step intergration for SMF on their site. 

Open index.template.php, and find the following text:

else
     echo '<a href="', $scripturl, '?action=logout;sesc=', $context['session_id'],
     '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url']
     . '/' . $context['user']['language'] . '/logout.gif" alt="' . $txt[108]
     . '" style="margin: 2px 0;" border="0" />' : $txt[108]),    '</a>';

Replace it with:

else {
     echo '<a href="', $GLOBALS['boardurl'], '/chat/flashchat.php">',
     ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url']
     . '/chat_icon.gif" alt="FlashChat" style="margin: 2px 0;"
     border="0" />' : "FlashChat"),'</a>';

    echo '<a href="', $scripturl, '?action=logout;sesc=', $context['session_id'],
    '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url']
    . '/' . $context['user']['language'] . '/logout.gif" alt="' . $txt[108]
    . '" style="margin: 2px 0;" border="0" />' : $txt[108]),'</a>';
}

Then, save your changes and upload the file to your server. If you use other templates besides the default template, you may have to repeat this step for each template that you use.

FlashChat comes with a small GIF file called "chat_icon.gif". Upload this file from the FlashChat root folder to the default template's "images" folder, as shown below. If you get a broken image icon after uploading this, please check the "src=..." path in the template code (above) to ensure that you have the correct path set.
Now, on the Simple Machines homepage, the new FlashChat icon will appear. Clicking on this link will open FlashChat in a new window (because of target="_blank" in the HTML that was added).

This should link to the "flashchat.php" file of FlashChat. When FlashChat loads, you should be automatically logged into the chatroom using your Simple Machines username. If you are an administrator of Simple Machines, then you will be logged into FlashChat as a moderator, which means that you can ban and boot other users.


I took me about 10 mins to intergrate it!  ;D  Versions I did it on: SMF 1.0.5 and FlashChat 4.1.2


The link is: hxxp:www.tufat.com/docs/flashchat/smf.html [nonactive] and hxxp:www.tufat.com/docs/flashchat/integration.html [nonactive]
The difference between genius and insanity -- genius has it's limits.

bjp

is it possible to "limit" the possibility of chat just for members who post more the 50 messages in the forum ?
Thank you.

bjp

Quote from: charlottezweb on October 14, 2004, 09:19:33 AM
I'm worried about server loads, not really bandwidth.  Either way, I've emailed the author -- we'll see what he says.  :)

-Jason

Me too. Is it possible to make a restriction. For exemple with catégories poster, or allow the chat for members who already post more than 100 reply ...

Mr. Jinx

I've also installed this great chat engine.

Is it possbile to show the user's alias in FlashChat. Right now it show the user's login ID.
Anyone?

CHwebby

#165
Here is a chat icon I made to use with my SMFone template. Feel free to use it if you want.


eye97

Does this program work in 1.1 Beta 4? Anything special I need to do before I install this in beta 4?

Cheers

RJ

Kindred

yes, this works with 1.1 b4...

and Jinx...  I have no idea why your system would do this... mine uses the display name from SMF.

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

eye97

Ok got it to work just fine. If only I could get a CHAT button for the YABB SE Theme...

Cheers

RJ

bjp

Quote from: Owdy on October 23, 2004, 01:38:12 PM
Quote from: Owdy on October 21, 2004, 01:04:04 PM
It doewsnt allow äö etc in nicknames. How can i fix that?

smfcms.php

find:
function getUserProfile($userid) {

    if ($userid == SPY_USERID) $rv = NULL;

    elseif ($user = $this->getUser($userid)) {
      $rv  = $GLOBALS['boardurl'] . "/index.php?action=profile;u=".$userid;
    }

    return $rv;
  }


  function getUser($userid) {


    $rv = NULL;
    if(($rs = $this->getUserStmt->process($userid)) && ($rec = $rs->next())) {
      $rec['roles'] = $this->getRoles($rec['status']);
      $rv = $rec;
    }

    return $rv;
  }

replace:

function getUserProfile($userid) {

    if ($userid == SPY_USERID) $rv = NULL;

    elseif ($user = $this->getUser($userid)) {
      $rv  = $GLOBALS['boardurl'] . "/index.php?action=profile;u=".$userid;
    }

    return $rv;
  }

function latin12utf8( $latin1 ) {
// translates these characters from latin-1/iso 8859-1 to UTF-8/Unicode

   $replacements = array(      'å' => 'Ã¥',
               'ä' => 'ä',
               'æ' => 'æ',
               'ö' => 'ö',
               'ø' => 'ø',
               'Å' => 'Ã...',
               'Ä' => 'Ã,,',
               'Æ' => 'Æ',
               'Ö' => 'Ö',
               'Ø' => 'Ø',
               'é' => 'é',
               'è' => 'è',
               'ê' => 'ê',
               'â' => 'â',
               'ü' => 'ü',
               'ß' => 'ß');

   return strtr($latin1, $replacements);
}


  function getUser($userid) {
   
   
    $rv = NULL;
    if(($rs = $this->getUserStmt->process($userid)) && ($rec = $rs->next())) {
      $rec['roles'] = $this->getRoles($rec['status']);
      $rec['login'] = $this->latin12utf8( $rec['login'] );
      $rv = $rec;
    }

    return $rv;
  }


That's ok, but is there the same solution for info.php

Quote<?php

   header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
   header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
   header("Cache-Control: no-store, no-cache, must-revalidate");
   header("Cache-Control: post-check=0, pre-check=0", false);
   header("Pragma: no-cache");


/**
If this file is not in the FlashChat root folder, then change this
path to the location of the inc/common.php file.
*/
include_once('inc/common.php');

ChatServer::purgeExpired();

/**
Retrieves the number of users who are chatting in any room.
Leave the $room parameter empty to return the number of users in all room.
*/
function numusers( $room = "" )
{
   if($room) {
      $stmt = new Statement("SELECT COUNT(*) AS numb FROM {$GLOBALS['fc_config']['db']['pref']}connections WHERE userid IS NOT NULL AND userid <> ? AND roomid=?");
      $rs = $stmt->process(SPY_USERID, $room);
   } else {
      $stmt = new Statement("SELECT COUNT(*) AS numb FROM {$GLOBALS['fc_config']['db']['pref']}connections,{$GLOBALS['fc_config']['db']['pref']}rooms
                       WHERE userid IS NOT NULL AND userid <> ? AND ispublic IS NOT NULL
                       AND {$GLOBALS['fc_config']['db']['pref']}connections.roomid = {$GLOBALS['fc_config']['db']['pref']}rooms.id");
      $rs = $stmt->process(SPY_USERID);
   }
   
   $rec = $rs->next();

   return $rec?$rec['numb']:0;
}

/**
Retrieves a list of the users (by login ID) who are in $room.
Leave the $room parameter empty to return a list of all users in all rooms.
*/
function usersinroom( $room = "" )
{
   $cms = $GLOBALS['fc_config']['cms'];
   $list = array();

   if($room) {
      $stmt = new Statement("SELECT userid, state, color, lang, roomid FROM {$GLOBALS['fc_config']['db']['pref']}connections WHERE userid IS NOT NULL AND userid <> ? AND roomid=?");
      $rs = $stmt->process(SPY_USERID, $room);
   } else {
      $stmt = new Statement("SELECT userid, state, color, lang, roomid FROM {$GLOBALS['fc_config']['db']['pref']}connections WHERE userid IS NOT NULL AND userid <> ?");
      $rs = $stmt->process(SPY_USERID);
   }
   
   while($rec = $rs->next())
   {
      $usr = $cms->getUser($rec['userid']);
      if($usr == null && $GLOBALS['fc_config']['enableBots']) $usr = $GLOBALS['fc_config']['bot']->getUser($rec['userid']);   
      $list[] = array_merge($usr, $rec);
   }
   
   return $list;
}

/**
Retrieves a list of all available rooms, as an array.
*/
function roomlist()
{
   $list = array();

   // populate $list with the names of all available rooms
   $stmt = new Statement("SELECT * FROM {$GLOBALS['fc_config']['db']['pref']}rooms WHERE ispublic IS NOT NULL order by ispermanent");
   $rs = $stmt->process();

   while($rec = $rs->next()) $list[] = $rec;

   //result will be an array of arrays like ('id' => <room id>, 'updated' = <timestamp>, 'created' => <timestamp>, 'name' => <room name>, 'ispublic' => <public flag>, 'ispermanent' => <autoclose flag>)
   return $list;
}


$rooms = roomlist();
$roomnumb = sizeof($rooms);
?>

<span style="font-size:xx-small;color:#0232a1">
   <?php

                  $users = usersinroom($room['id']);

                  foreach( $users as $user ) {
                     echo $user['login'] . ",";
                  }

                  ?></span>

permutations

Thanks very much for taking the time to post this tutorial, marcnyc. I installed FlashChat on my site and it works well!

I had just two small problems - one fixed, one not. I didn't like the way the "who's in the chat" box at the bottom of the page was formatted. Besides being different from the SMF forum list, displaying the names vertically is kind of a dumb use of space. So I edited info_embedded.php, and now it looks just like the SMF forum list - much better! I'll append my code below in case anyone is interested. I made changes throughout the file, but the file isn't that long.

The other problem I had is that FlashChat insists on defaulting to white text - regardless of what color my theme says it should be. You have to change the color to something else and then exit for it to stop being white. Since I chose a light background for my theme (to match the rest of my site), white doesn't show up too well. The problem is in both the userlist and the chat text (which use the same color). Since I've never programmed Flash, it would take me a long time to find this bug so I haven't even tried to look. Does anyone know what the problem is? I have Flash (just bought an upgrade to Macromedia Studio 8 ).

One other thing... Does anyone have any idea what the "skins" do? When I change them, I see no difference. The "Select color scheme" works and my theme controls that (except for the white text problem), but I don't see what the skins do. It's not documented, and I can't tell looking at the code, either.

Here's my modified info_embedded.php:

<?php

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0"false);
header("Pragma: no-cache");


/**
If this file is not in the FlashChat root folder, then change this
path to the location of the inc/common.php file.
*/
include_once('inc/common.php');

ChatServer::purgeExpired();

/**
Retrieves the number of users who are chatting in any room.
Leave the $room parameter empty to return the number of users in all room.
*/
function numusers$room "" )
{
if($room) {
$stmt = new Statement("SELECT COUNT(*) AS numb FROM {$GLOBALS['fc_config']['db']['pref']}connections WHERE userid IS NOT NULL AND roomid=?");
$rs $stmt->process($room);
} else {
$stmt = new Statement("SELECT COUNT(*) AS numb FROM {$GLOBALS['fc_config']['db']['pref']}connections,{$GLOBALS['fc_config']['db']['pref']}rooms
  WHERE userid IS NOT NULL AND ispublic IS NOT NULL
  AND 
{$GLOBALS['fc_config']['db']['pref']}connections.roomid = {$GLOBALS['fc_config']['db']['pref']}rooms.id");
$rs $stmt->process();
}

$rec $rs->next();

return $rec?$rec['numb']:0;
}

/**
Retrieves a list of the users (by login ID) who are in $room.
Leave the $room parameter empty to return a list of all users in all rooms.
*/
function usersinroom$room "" )
{
$cms $GLOBALS['fc_config']['cms'];
$list = array();

if($room) {
$stmt = new Statement("SELECT userid, state, color, lang, roomid FROM {$GLOBALS['fc_config']['db']['pref']}connections WHERE userid IS NOT NULL AND roomid=?");
$rs $stmt->process($room);
} else {
$stmt = new Statement("SELECT userid, state, color, lang, roomid FROM {$GLOBALS['fc_config']['db']['pref']}connections WHERE userid IS NOT NULL");
$rs $stmt->process();
}

while($rec $rs->next()) $list[] = array_merge($cms->getUser($rec['userid']), $rec);

return $list;
}

/**
Retrieves a list of all available rooms, as an array.
*/
function roomlist()
{
$list = array();

// populate $list with the names of all available rooms
$stmt = new Statement("SELECT * FROM {$GLOBALS['fc_config']['db']['pref']}rooms WHERE ispublic IS NOT NULL order by ispermanent");
$rs $stmt->process();

while($rec $rs->next()) $list[] = $rec;

//result will be an array of arrays like ('id' => <room id>, 'updated' = <timestamp>, 'created' => <timestamp>, 'name' => <room name>, 'ispublic' => <public flag>, 'ispermanent' => <autoclose flag>)
return $list;
}


$rooms roomlist();
$roomnumb sizeof($rooms);
$usernumb numusers();
?>


<html>
<title>Who's in the chat?</title>
<meta http-equiv=Content-Type content="text/html;  charset=UTF-8">
<head>
<style type="text/css">
<!--

body { background-color: transparent; margin: 0; padding: 0; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: normal; font-size: 10px;}
...normalCenter {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: normal;
margin: 0; padding: 0;
        text-align: center;
}

...normal {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: normal;
margin: 0; padding: 0;
        text-align: left;
}

#roomList { margin: 0; padding: 0; }
#roomList a { color: black; text-decoration: none; } #roomList a:hover { text-decoration: underline; }
...userList { margin-left: 7px; margin-right: 0; margin-bottom: 0; margin-top: 0;  padding: 0; }

-->
</style>
<script type="text/javascript">
function toggleUserList(id) {
   if (l = document.getElementById(id)) {
      if (l.style.display == '' || l.style.display == 'block') l.style.display = 'none';
      else l.style.display = 'block';
   }
   return false;
}

</script>
</head>
<body>
<p class="normal"><?php echo $usernumb ?> user<?php if ($usernumb != 1) echo "s" ?> in <?php echo $roomnumb ?> room<?php if ($roomnumb != 1) echo "s"?>.</p>
<div id="roomList"> <?php 
if ($roomnumb

echo '<br />';
foreach($rooms as $room
?>

<strong><a href="#" onclick="javascript:toggleUserList('room_<?php echo $room['id']?>')"><?php echo $room['name']?> (<?php echo numusers($room['id']) ?>)</a></strong>
<br /><?php
$users usersinroom($room['id']);
if ($users

echo '<div class="userList" id="room_'.$room['id'].'">';
$times_through 0;
foreach( $users as $user 
{
$comma = ($times_through++ == 0) ? '' ', ';
echo $comma$user['login'];
?>

</div> <?php
}
}
?>

</div>

</body>
</html>

Kindred

the white-text issue should be solved in 4.3.3... if not, the solution (described over on the flashchat forum) is to change all of the default text colour values in the setup files for your default theme to something other than #000000. Setting them to #000001 works just peachy.

Skins modify the look of the screen... at least they do on my site...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

permutations

Quote from: Kindred on October 11, 2005, 04:13:04 PM
the white-text issue should be solved in 4.3.3... if not, the solution (described over on the flashchat forum) is to change all of the default text colour values in the setup files for your default theme to something other than #000000. Setting them to #000001 works just peachy.

You know, I tried that when I was playing around with it, trying to get it to work, and at first I thought that fixed it. At least it was fixed when I was "chatting" with myself from two different computers. But twice now when chatting with someone else they came up "white". I'll go back to #000001 - can't hurt. And I'll take a look in the FlashChat forum. Do you know when 4.3.3 is supposed to be released?

Quote from: Kindred on October 11, 2005, 04:13:04 PM
Skins modify the look of the screen... at least they do on my site...

Really? What part of the screen changes, and in what way? Do you have before and after screenshots you can post?

I've wondered if it's a Mac thing. Are you using a Mac?

permutations

I changed every instance of 0x000000 in my theme to 0x000001, and I also watched more closely to see what happened when I changed the skins. The style and color of the controls change (buttons, tabs). I'm so relieved I can finally see it doing something!

Elijah Bliss

Quote from: Mr. Jinx on September 13, 2005, 03:26:39 PM
I've also installed this great chat engine.

Is it possbile to show the user's alias in FlashChat. Right now it show the user's login ID.
Anyone?

It's possible but not without screwing up the bots.

Quote from: permutations on October 11, 2005, 04:24:25 PM
I've wondered if it's a Mac thing. Are you using a Mac?

FlashChat renders just fine in Safari and Camino.

permutations

Quote from: Elijah Bliss on October 11, 2005, 04:47:21 PM
Quote from: Mr. Jinx on September 13, 2005, 03:26:39 PM
I've also installed this great chat engine.
Is it possbile to show the user's alias in FlashChat. Right now it show the user's login ID.
Anyone?
It's possible but not without screwing up the bots.

The fix for the name bug was posted earlier in this thread here. It's a small error in the smfCMF files (smfCMF.php and smfCMF2.php).

I discovered that 4.3.3 has already been released. I downloaded it and I'm installing it now.

Elijah Bliss

Quote from: permutations on October 11, 2005, 05:13:43 PM
Quote from: Elijah Bliss on October 11, 2005, 04:47:21 PM
Quote from: Mr. Jinx on September 13, 2005, 03:26:39 PM
I've also installed this great chat engine.
Is it possbile to show the user's alias in FlashChat. Right now it show the user's login ID.
Anyone?
It's possible but not without screwing up the bots.

The fix for the name bug was posted earlier in this thread here. It's a small error in the smfCMF files (smfCMF.php and smfCMF2.php).

I discovered that 4.3.3 has already been released. I downloaded it and I'm installing it now.


Cool, thanks, I'll try this out.

Elijah Bliss

Quote from: James Woodcock on October 19, 2004, 05:27:14 AM
Ahhh Steve my programmer has done it, if you want it to display the visible name instead of the user name ie:  James Woodcock instead of GlideM then:

In file >>> FlashChat\inc\cmses\smfCMS.php

Find:
function SMFCMS() {

    $this->loginStmt = new Statement("SELECT ID_MEMBER as id, memberName AS login, passwd, is_activated from {$GLOBALS['db_prefix']}members WHERE memberName=? AND passwd=?");
    $this->getUserStmt = new Statement("SELECT ID_MEMBER AS id, memberName AS login, ID_GROUP as status FROM {$GLOBALS['db_prefix']}members WHERE ID_MEMBER=?");
    $this->getUsersStmt = new Statement("SELECT ID_MEMBER as id, memberName as login FROM {$GLOBALS['db_prefix']}members");

Replace:
function SMFCMS() {

    $this->loginStmt = new Statement("SELECT ID_MEMBER as id, memberName AS login, passwd, is_activated from {$GLOBALS['db_prefix']}members WHERE memberName=? AND passwd=?");
    $this->getUserStmt = new Statement("SELECT ID_MEMBER AS id, realName AS login, ID_GROUP as status FROM {$GLOBALS['db_prefix']}members WHERE ID_MEMBER=?");
    $this->getUsersStmt = new Statement("SELECT ID_MEMBER as id, realName as login FROM {$GLOBALS['db_prefix']}members");


Works like a charm.

Ride

I had an idea.  It'd be cool if a member could invite another member into chat.  Basically they'd hit a "chat now" button on the person's profile or next to their username on the board and if that member was online, it'd popup a window saying "john doe would like to chat, do you accept?" and if they accept it would take them to the chat.  I'm guessing a variable could be set that when the member refreshes a page it would check to see if it was set to yes or no and if yet, bring up the window asking to chat.  Sorry if I'm not making sense, kind of hard to explain.  You guys follow me?  I guess it'd be a way to use chat as a live IM system.

Kindred

well, that is something beyond the scope of SMF... and actually, beyond the scope of FlashChat.

You would have to modify the Flash file in FlashChat, as well as some of the php functions and templates...

You'd also have to install a javascript-alert function in SMF and add a continual and regular refresh...  Which would be annoying for users who are trying to read things in the forum and would also increase bandwidth usage 10-fold.

Honestly, if you want IM, use an IM.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Advertisement: