PHP FREE CHAT Integration with phpBB3

Discussion forum for MOD Writers regarding MOD Development.
User avatar
jsebean
Registered User
Posts: 378
Joined: Sat Dec 12, 2009 3:20 pm
Location: Atlantic Canada
Name: Jonah

PHP FREE CHAT Integration with phpBB3

Post by jsebean »

I have had interest in php free chat for some time so decided to make an integration "tutorial" for people who are also interested in it. On the php free chat website (phpfreechat.net) they had a tutorial for integrating it with phpBB v2, but since that's long since outdated I updated the phpfreechat wiki for integrating it with phpbb3. I figured I'd also post it here.

1. First you need a copy of phpfreechat by going to http://www.phpfreechat.net/download/ and download it. When I wrote this, the latest version was v1.3.
2. At the very top of your phpfreechat index.php file, you need to put this code in:

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require($phpbb_root_path . 'common.' . $phpEx);
 
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
 
if ($user->data['user_id'] == ANONYMOUS)
{
    login_box('', $user->lang['LOGIN']);
}
?>

Make sure the variable $phpbb_root_path is correct. So if your forums are at example.com/forums and chat is at example.com/forums/chat, then PHPBB_ROOT_PATH should be ../ because you need to go back one directory. (As shown in the example code above).

If you don't want the script to redirect to the login page if you are not logged in, then take out this part:

Code: Select all

if ($user->data['user_id'] == ANONYMOUS)
{
    login_box('', $user->lang['LOGIN']);
}
Now phpfreechat uses parameters for settings. To integrate php free chat with phpbb nicknames, in the index.php file in the parameters, replace this line:

Code: Select all

$params["nick"] = "guest".rand(1,1000);  // setup the intitial nickname
with:

Code: Select all

$params["nick"] = $user->data['username_clean'];
.

Note: username_clean will take out any “weird” characters, including spaces and replace them with an underscore (_). It will also make capitals, lowercase. I chose username clean because it makes it easier to use the /kick and /ban command in phpfreechat. If you want the regular username to be shown, change:

Code: Select all

$user->data['username_clean']
to

Code: Select all

$user->data['username'];
.

If you also want your boards admins and global moderators to automatically be made a chat operator in chat (so you can kick and ban chat users if needed), then add this to your parameters in the index.php file:

Code: Select all

if ($user->data['group_id'] == 4 OR $user->data['group_id'] == 5) // Admins and Moderators
{
$params["isadmin"] = true; // Do what you want cause a pirate is free, you are a pirate ;)
}
Be sure to change the number 4 and 5 to your boards Admin and moderator group numbers. To find your boards admin and moderator group number, navigate to your Boards index page of phpBB and scroll down to the “Who is Online” area. There is a legend for “Administrators” and “Global Moderators”. Click on Administrators. Once you click it, the url in your browser should look something like this:
http://example.com/forums/memberlist.php?mode=group&g=5
Take note of the &g= number in the url. That number is your admins group number. In this example, our admin group number is 5. Do the same for Global Moderators, in this example, our moderator group is 4.

In the end, this is how my index.php for phpfreechat looks after all the code is included and setup correctly.

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require($phpbb_root_path . 'common.' . $phpEx);
 
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
 
if ($user->data['user_id'] == ANONYMOUS)
{
	login_box('', $user->lang['LOGIN']);
}
?>
<?php
 
require_once dirname(__FILE__)."/src/phpfreechat.class.php";
$params = array();
$params["title"] = "Quick chat";
$params["nick"] = $user->data['username_clean']; 
$params['firstisadmin'] = false;
if ($user->data['group_id'] == 4 OR $user->data['group_id'] == 5) // Admins and Moderators
{
$params["isadmin"] = true; // Do what you want cause a pirate is free, you are a pirate ;)
}
 
$params["serverid"] = md5(__FILE__); // calculate a unique id for this chat
$params["debug"] = false;
$chat = new phpFreeChat( $params );
 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Chicken Talk Chat Room</title>  
 </head>
 <body>
<div class="content">
  <?php $chat->printChat(); ?>
</div>
 
</body></html>
if you also want a chat link in your forums you can add it to your overall_header.html in your style and add the link where you want it.

Hope this helps people who want php free chat integrated with phpBB :D
-Jonah
:lol:
User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 18489
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón

Re: PHP FREE CHAT Integration with phpBB3

Post by DavidIQ »

Just had to do this for a client so here are some additional instructions on how to get the chatroom integrated with the forum style and a few minor tweaks for the above code. Don't want to go into TOO much detail so I'll just say that the index.php file for the chatroom ends up looking like this:

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require($phpbb_root_path . 'common.' . $phpEx);
 
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
 
if ($user->data['user_id'] == ANONYMOUS)
{
    login_box('', $user->lang['LOGIN']);
}

// Output page
page_header('Chatroom');

$template->set_filenames(array(
    'body' => 'chatroom_body.html',
));

require_once dirname(__FILE__)."/src/phpfreechat.class.php";
$params = array();
$params["title"] = "Quick chat";
$params["nick"] = $user->data['username'];
$params['firstisadmin'] = false;
//$params["isadmin"] = true; // makes everybody admin: do not use it on production servers ;)
$params["serverid"] = md5(__FILE__); // calculate a unique id for this chat
$params["debug"] = false;
//Make admins and moderators chatroom operators
if ($auth->acl_get('m_') || $auth->acl_get('a_'))
{
	$params["isadmin"] = true;
}
$chat = new phpFreeChat( $params );

// Send data to template
$template->assign_vars(array(
	'S_CHATROOM'	=> $chat->printChat(true) . $warning)
);

page_footer();

?>
You'll need to have created a very simple chatroom_body.html template file with the following as its contents:

Code: Select all

<!-- INCLUDE overall_header.html -->

{S_CHATROOM}

<!-- INCLUDE overall_footer.html -->
(your mileage may vary...the above might need some tweaking for your particular style).
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.
dp812
Registered User
Posts: 22
Joined: Mon Jan 05, 2009 10:18 am

Re: PHP FREE CHAT Integration with phpBB3

Post by dp812 »

jsebean wrote:if you also want a chat link in your forums you can add it to your overall_header.html in your style and add the link where you want it.
This is definitely something I want. How can I do this? I'm a little baffled by the code in the overall_header.html file.

EDIT: Nevermind, I managed to get it to work. Thanks for the above code, though. Got me off to a great start integrating my chat.
Big_Red_777
Registered User
Posts: 79
Joined: Mon Jul 16, 2012 8:45 pm

Re: PHP FREE CHAT Integration with phpBB3

Post by Big_Red_777 »

Hi, trying to integrate this into my forum. But having a problem getting it to recognize current members. It goes straight to a guest member. Any ideas if maybe the new phpbb 3.0.11 is causing this? I used David's index.php.

Otherwise, it looks great especially with it going right into my template, thank you David!

Edit: Ok, I got everything working except for some reason the ban feature does not work.
Last edited by Big_Red_777 on Sat Nov 24, 2012 7:08 pm, edited 1 time in total.
Big_Red_777
Registered User
Posts: 79
Joined: Mon Jul 16, 2012 8:45 pm

Re: PHP FREE CHAT Integration with phpBB3

Post by Big_Red_777 »

Here is what my index.php looks like:

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require($phpbb_root_path . 'common.' . $phpEx);
 
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
 
if ($user->data['user_id'] == ANONYMOUS)
{
    login_box('', $user->lang['LOGIN']);
}

// Output page
page_header('Chatroom');

$template->set_filenames(array(
    'body' => 'chatroom_body.html',
));

require_once dirname(__FILE__)."/src/phpfreechat.class.php";
$params = array();
$params["title"] = "Ray Peat Forum Chat";
$params["nick"] = $user->data['username_clean'];
$params['firstisadmin'] = false;
if ($user->data['group_id'] == 4 OR $user->data['group_id'] == 5) // Admins and Moderators
{
$params["isadmin"] = true; // Do what you want cause a pirate is free, you are a pirate ;)
}

$params["serverid"] = md5(__FILE__); // calculate a unique id for this chat
$params["debug"] = false;
$chat = new phpFreeChat( $params );

// Send data to template
$template->assign_vars(array(
   'S_CHATROOM'   => $chat->printChat(true) . $warning)
);

page_footer();

?>
Everything works now except I cannot ban or kick people.
peterjend
Registered User
Posts: 2
Joined: Fri Jul 04, 2008 8:42 pm

Re: PHP FREE CHAT Integration with phpBB3

Post by peterjend »

Hello,

does anyone have an idea how can I integrate the whoisonline script?
In the index.php from the chat and also in the html from the forum?

thanks
peter
clight77
Registered User
Posts: 907
Joined: Sun May 11, 2003 11:09 pm

Re: PHP FREE CHAT Integration with phpBB3

Post by clight77 »

How to change phpfreechat online list background color

open:
style.css.php of your theme and add this at the top of page:

/*usernames-onlinelist*/
div.pfc_online {
border-bottom: 1px solid #555;
color: #262626; /* colors can be overriden by js nickname colorization you can also change
these 3 colors to your needs*/
background-color: #262626;
/* borders are drawn by the javascript routines */
}


Add a background image to oneline list:
/*usernames-onlinelist*/
div.pfc_online {
border-bottom: 1px solid #555;
color: #262626;
background-color: #262626;
background-image: url(http://www.xxxxxxxxxx.com/forum/goofy1.png);/* use your board url and your preferred image*/
background-repeat: no-repeat;
}
I Follow Up On My Posts.
So Should Everybody...
lashpashchat
Registered User
Posts: 2
Joined: Tue Apr 07, 2015 6:56 pm

Re: PHP FREE CHAT Integration with phpBB3

Post by lashpashchat »

hello i have some problem in phpfreechat
when some join chat room with space nick like "john 23" or "Alina 30". these nick can't banned why??
how can i remove space in this chat??
User avatar
RMcGirr83
Former Team Member
Posts: 22071
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: PHP FREE CHAT Integration with phpBB3

Post by RMcGirr83 »

jsebean wrote: Now phpfreechat uses parameters for settings. To integrate php free chat with phpbb nicknames, in the index.php file in the parameters, replace this line:

Code: Select all

$params["nick"] = "guest".rand(1,1000);  // setup the intitial nickname
with:

Code: Select all

$params["nick"] = $user->data['username_clean'];
.

Note: username_clean will take out any “weird” characters, including spaces and replace them with an underscore (_). It will also make capitals, lowercase. I chose username clean because it makes it easier to use the /kick and /ban command in phpfreechat. If you want the regular username to be shown, change:

Code: Select all

$user->data['username_clean']
to

Code: Select all

$user->data['username'];
.
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then you can support me by buying a beer 🍺

Return to “[3.0.x] MOD Writers Discussion”