Install phpFreeChat in the modules directory following the install instructions and replace the index.php file with this one.
- Code: Select all
<?php
/*
* PHP-Nuke module for phpFreeChat
*/
if (!defined('MODULE_FILE')) {
die ("You can't access this file directly...");
}
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
$pagetitle = "$module_name";
global $user;
cookiedecode($user);
$username = $cookie[1];
# Because this won't work with "frozen_nick", ensure only registered users
# run chat, even if the module is enabled for all visitors.
#if ($username == "") {
# $params["nick"] = "Guest".rand(1,1000);
#}
if ($username == "")
{
include("header.php");
OpenTable();
echo "<center><strong>You are trying to access a restricted area.</strong><br><br>We are Sorry, but this section of our site is for <i>Registered Users Only.</i><br><br>You can register for free by clicking <a href="modules.php?name=Your_Account&op=new_user">here</a>, then you can<br>access this section without restrictions. Thanks.<br><br>[ <a href="javascript:history.go(-1)">Go Back</a> ]";
CloseTable();
include("footer.php");
}
else
{
require_once dirname(__FILE__)."/src/phpfreechat.class.php";
$params = array();
$params["serverid"] = md5(__FILE__);
# these appear to do nothing
#$params["height"] = "120px";
#$params["width"] = "400px";
$params["title"] = "$pagetitle";
$params["nick"] = "$username";
$params["frozen_nick"] = true;
$params["max_channels"] = 1;
$params["channels"] = array("Main");
$params["refresh_delay"] = 5000;
#$params["debug"] = true;
$chat = new phpFreeChat( $params );
include("header.php");
OpenTable();
$chat->printJavascript();
$chat->printStyle();
$chat->printChat();
CloseTable();
include("footer.php");
}
?>
Next, there are a few problems with pfcclient.js. It sends the nick with quotes around it which are ignored on the server side. This causes it to open without connecting and gives the error "You must be connected to send a message". I got the most recent svn file and modified it to remove the quotes.
It also sends data if the user just keeps hitting enter, causing unnecessary traffic. I added a check to avoid that.
Here are the diffs:
- Code: Select all
$ diff pfcclient.js pfcclient.js.orig
150c150
< this.sendRequest('/nick '+newnick);
---
> this.sendRequest('/nick "'+newnick+'"');
152c152
< this.sendRequest('/connect '+newnick);
---
> this.sendRequest('/connect "'+newnick+'"');
229c229
< if (cmd != "join2" || this.gui.tabs.length == 1) this.gui.setTabById(tabid);
---
> if (cmd != "join2") this.gui.setTabById(tabid);
272c272
< if (cmd != "privmsg2" || this.gui.tabs.length == 1) this.gui.setTabById(tabid);
---
> if (cmd != "privmsg2") this.gui.setTabById(tabid);
456c456
< if (!um) this.sendRequest('/whois2 '+nickid);
---
> if (!um) this.sendRequest('/whois2 "'+nickid+'"');
584c584
< if (wval != '') this.sendRequest('/send '+ wval);
---
> this.sendRequest('/send '+ wval);
1054c1054
< pfc.sendRequest('/privmsg '+nick);
---
> pfc.sendRequest('/privmsg "'+nick+'"');
1460c1460
< this.sendRequest('/connect '+this.nickname);
---
> this.sendRequest('/connect "'+this.nickname+'"');
1788d1787
<
Because of a problem of using "frozen_nick" with $params["nick"] = "Guest".rand(1,1000), we must lock visitors out (we can't have them stealing other people's nicks).
( see http://www.phpfreechat.net/forum/viewto ... 6668#p6668 )
If would be better if vistors could connect. Maybe the programs authors will fix that.
Unfortunately, I won't be using this on my web site because I have a shared hosting account and phpFreeChat is resource intensive on the server side. Because of the terms of agreement, I could end up getting my account cancelled.