Note that we added a custom profile field to allow members to customize their nick. Remove that code if you don't do that.
mod_chat.php (in modules folder):
- Code: Select all
<?php
//=====================================
// Define class, this must be the same
// in all modules
//=====================================
class module
{
//=====================================
// Define vars if required
//=====================================
var $ipsclass;
var $class = "";
var $module = "";
var $html = "";
var $result = "";
//=====================================
// Constructer, called and run by IPB
//=====================================
function run_module()
{
//=====================================
// Do any set up here, like load lang
// skin files, etc
//=====================================
$this->ipsclass->load_language('lang_boards');
$this->ipsclass->load_template('skin_boards');
//=====================================
// Set up structure
//=====================================
switch( $this->ipsclass->input['cmd'] )
{
case 'dosomething':
$this->do_something();
break;
default:
$this->do_something();
break;
}
print $this->result;
exit();
}
function do_something()
{
if ($this->ipsclass->vars['phpfreechat_must_login'] == 'Y')
{
//Only allow logged-in members to use this module
if (!($this->ipsclass->member['id']))
{
//Comment this to allow anonymous users
$this->ipsclass->Error(array (LEVEL => 1, MSG => 'no_permission'));
return;
}
}
//Since the Forum and chat use slightly different domain names
//we have to set a cookie for a domain that is accessible to chat
setcookie('ipbSessionId',$_COOKIE['session_id'],time()*60,'/');
header('Location: http://www.objectivismonline.net/chat/chat.php?ipbSessionId='.$this->ipsclass->sess->session_id);
exit();
}
}
?>
This is the top PHP section from chat.php, or the chat page (formerly index.php). Index.php should point to http://FORUMURL/index.php?automodule=chat
- Code: Select all
<?php
require_once dirname(__FILE__)."/src/phpfreechat.class.php";
session_start();
$params = array();
if (isset($_SESSION['ipbMemberName']) && (strtoupper($_SESSION['ipbMemberName']) != "GUEST"))
{
$ipbMemberName = $_SESSION['ipbMemberName'];
$params["nick"] = $ipbMemberName; // setup the initial nickname
}
elseif (isset($_COOKIE['ipbSessionId']) || (isset($_GET['ipbSessionId'])))
{
//Read the cookie that was set by the forum add-on module
if (isset($_COOKIE['ipbSessionId']))
{
$ipbSessionId = $_COOKIE['ipbSessionId'];
}
else
{
$ipbSessionId = $_GET['ipbSessionId'];
}
//----------------------------------------------------------
//Read IPB Global settings, to get DB connection info. Then Connect to DB
require_once ("../forum/conf_global.php");
$dbhost=$INFO['sql_host'];
$dbuser=$INFO['sql_user'];
$dbpasswd=$INFO['sql_pass'];
$dbname=$INFO['sql_database'];
$tblPrefix=$INFO['sql_tbl_prefix'];
$conn = mysql_connect($dbhost,$dbuser,$dbpasswd);
if (!$conn) { echo "Connection impossiblen"; exit; }
@mysql_select_db($dbname) or die( "Unable to select database");
//----------------------------------------------------------
//Use the session id, from the cookie to read IPB's session table
//Read in the Member Id, Name and Group
$query = "select member_id, member_name, member_group from ".$tblPrefix."sessions where id = ";
$query .= "'".$ipbSessionId ."'";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$row = mysql_fetch_array($result, MYSQL_NUM);
mysql_free_result($result);
$ipbMemberId= $row[0];
$ipbMemberName= $row[1];
$ipbMemberGroup= $row[2];
$isadmin = false; // false by default
//For now, I'm hard-coding group=5 (BANNED)
if ($ipbMemberGroup == 4 || $ipbMemberGroup == 6) {
// Is Admin or Moderator
$isadmin = true;
} elseif ($ipbMemberGroup == 5) {
die( "Chat is not available. Try again later. ");
}
if ($ipbMemberId)
{
//----------------------------------------------------------
//Use the member Id to read the 10th custom profile field
//(will vary with installation)
//On our site, this contains the preferred Nick
$query = "select field_10 from ".$tblPrefix."pfields_content where member_id = ";
$query .= $ipbMemberId ;
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$row = mysql_fetch_array($result, MYSQL_NUM);
mysql_free_result($result);
$ipbChatNick= $row[0];
}
//----------------------------------------------------------
//Get the user's IP, to check against the banned list
$userIPaddress = $_SERVER['REMOTE_ADDR'];
$query = "select count(*) from ".$tblPrefix."banfilters ";
$query .= " where ban_type = 'ip' and ban_content = ";
$query .= "'".$userIPaddress ."'";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$row = mysql_fetch_array($result, MYSQL_NUM);
mysql_free_result($result);
if ($row[0] > 0)
{
die( "Chat is not available. Try again later.");
}
//----------------------------------------------------------
//All done with database access.
mysql_close($conn);
//----------------------------------------------------------
if (isset($ipbChatNick) && ($ipbChatNick!=""))
{
$defaultNick = $ipbChatNick;
}
else
{
$defaultNick = $ipbMemberName;
}
}
else
{
//No session variables and no Cookie with session id
//Indicates attempt at direct access. So, re-route via entry-point URL
// disabled by David because of problems
//echo "No session variables found. Please go to http://www.objectivismonline.net/chat";
// header('Location: http://forum.objectivismonline.net/index.php?automodule=chat');
// exit;
}
$params["isadmin"] = $isadmin;
if (isset($defaultNick) && ($defaultNick!=""))
{
//$params["nick"] = $defaultNick;
//The line below allows names with French-like characters
$params["nick"] = iconv("UTF-8", "ISO-8859-1", $defaultNick);
}
else
{
$params["nick"] = "egoist".rand(1,10);
}
//---------------------------------------------------
//SELECT g_is_supmod FROM ibf_groups where g_id = ?
//A value of 1 would mean Moderator or Admin.
if (isset($_GET['anon']) && (strtoupper($_GET['anon']) != "moderator"))
{
$params["nick"] = "egoist".rand(11,15);
}
$params["serverid"] = md5(__FILE__); // calculate a unique id for this chat
//Override the default list of censored words, so that sex is sex, not ***
$params["proxies_cfg"]["censor"]["words"] = array("fuck","bitch");
//$params["theme"] = "blune";
$params["channels"] = array("Lobby");
$params["title"] = "ObjectivismChat";
$params["quit_on_closedwindow"] = true;
//$params["refresh_delay"] = "2000";
$params["showsmileys"] = false;
$chat = new phpFreeChat( $params);
?>