Kết hợp PhpMyChat v0.145 và PhpBB v2.0x
Chúng ta có thể kết hợp PhpMyChat và PhpBB để bất kỳ người nào đã đăng ký vào PhpBB cũng sẽ là thành viên của PhpMyChat.
Chú ý: Hướng dẫn này dựa trên cải tiết của Nathan_Anderson - http://www.phpbb.com/mods/downloads/ - và chỉ áp dụng với bộ nguồn PhpMyChat v0.145 do Lê Hoàn Việt hoá - đã đổi file có phần tên mở rộng từ php3 thành php.
A. Cài đặt PhpMyChat
Bạn chép bộ PhpMyChat v0.145 Việt hoá vào thư mục con trong PhpBB, thí dụ: Forum/Chat/ rồi cài đặt với các xác lập sau:
1. Sửa file chat/config/config.lib.php
* Bạn tạo các table CSDL cho Chat trong cùng 1
CSDL với Forum và điều chỉnh phần tên mở đầu của các bảng này giống với phần tên
mở đầu của các bảng CSDL trong forum. Thí dụ với phpbb_ là tên mở đầu của các
table trong forum.
define("C_MSG_TBL", 'phpbb_c_messages');
define("C_USR_TBL", 'phpbb_c_users');
define("C_REG_TBL", 'phpbb_c_reg_users');
define("C_BAN_TBL", 'phpbb_c_ban_users');
* Bạn bổ sung thêm 2 dòng tiếp theo
define("C_FORUM_NAME", 'YOUR FORUM NAME'); // YOUR FORUM NAME là tên forum của
bạn.
define("C_SMILES_TABLE", 'phpbb_smilies');
* Sửa dòng
$DefaultChatRooms = array('Default', 'MyRoom1', 'MyRoom2');
thành
$DefaultChatRooms = array('General');
* Sửa dòng
define("C_REQUIRE_REGISTER", '0');
thành
define("C_REQUIRE_REGISTER", '1');
* Sửa dòng
define("C_SHOW_DEL_PROF", '1');
thành
define("C_SHOW_DEL_PROF", '0');
2. Xác lập Người Quản trị Chat
Trong khi cài đặt Chat bạn phải xác lập người
quản trị Chat cũng là người Quản trị forum, bằng cách nhập tên truy cập và mật
khẩu của người Quản trị forum khi khai báo.
Chú ý: Nếu không làm đúng như vậy sẽ không ai có quyền quản trị PhpMyChat sau
khi cài đặt.
B. Sửa các file nguồn của PhpMyChat
1. Mở file chat/chat/link.htm
* Tìm dòng
<A HREF="http://www.phpheaven.net/" TARGET="_blank"><IMG SRC="images/icon.gif"
WIDTH=88 HEIGHT=31 BORDER=0></A>
Sửa thành
<A HREF="../index.php" target="_top">YOUR FORUM NAME</A>
2. Mở file chat/lib/index.lib.php
* Tìm dòng
function layout($Err, $U, $R, $T)
Sửa thành
function layout($Err, $U, $R, $T)
{
global $E, $EN;
echo "<center><font size=+3><b>".C_FORUM_NAME." Chat</b></font>
<br><br><br>";
if (isset($E)) {
echo "<br><br><br>Your have left the chat room.<br>To re-enter click <a
href=\"../chatlink.php\">here</a>.";
} else {
echo "<br><br><br>Your <b>session</b> in the chat room has expired.<br>To log
back in click <a href=\"../chatlink.php\">here</a>.";
}
echo "<br><br>To return to the forum click <a
href=\"../index.php\">here</a>.</center>";
}
function oldlayout($Err, $U, $R, $T)
3. Mở file chat/edituser.php
* Tìm và xoá bỏ dòng
require("./lib/login.lib.php");
* Tìm dòng
$DbLink = new DB;
Thêm vào bên dưới đoạn mã
if (!isset($PWD_Hash) || !isset($AUTH_USERNAME))
{
include "./lib/login.lib.php";
}
else
{
$U = $AUTH_USERNAME;
$DbLink->query("select username from ".C_REG_TBL." where username='$U' and
password='$PWD_Hash'");
$Rows = $DbLink->num_rows();
if ($Rows != 1)
{
include "./lib/login.lib.php";
}
}
* Tìm đoạn
else if ($PASSWORD == "")
{
$Error = L_ERR_USR_6;
}
else if (trim($FIRSTNAME) == "" || trim($LASTNAME) == "")
thay bằng
else if (trim($FIRSTNAME) == "")
* Tìm đoạn
if (!isset($Error))
{
$Latin1 = ($Charset == "iso-8859-1");
$PWD_Hash = md5(stripslashes($PASSWORD));
if (!isset($GENDER)) $GENDER = "";
$showemail = (isset($SHOWEMAIL) && $SHOWEMAIL)? 1:0;
include("./lib/get_IP.lib.php"); // Set the $IP var
$DbLink->query("UPDATE ".C_REG_TBL." SET username='$U', latin1='$Latin1',
password='$PWD_Hash', firstname='$FIRSTNAME', lastname='$LASTNAME',
country='$COUNTRY', website='$WEBSITE', email='$EMAIL', showemail=$showemail,
reg_time=".time().", ip='$IP', gender='$GENDER' WHERE
username='$AUTH_USERNAME'");
if ($AUTH_USERNAME != $U) $AUTH_USERNAME = $U;
if ($AUTH_PASSWORD != $PASSWORD) $AUTH_PASSWORD = $PASSWORD;
$Message = L_REG_17;
}
Thay bằng
if (!isset($Error))
{
$Latin1 = ($Charset == "iso-8859-1");
if (!isset($GENDER)) $GENDER = "";
$showemail = (isset($SHOWEMAIL) && $SHOWEMAIL)? 1:0;
include("./lib/get_IP.lib.php"); // Set the $IP var
$DbLink->query("UPDATE ".C_REG_TBL." SET username='$U', latin1='$Latin1',
firstname='$FIRSTNAME', lastname='$LASTNAME', country='$COUNTRY',
website='$WEBSITE', email='$EMAIL', showemail=$showemail, reg_time=".time().",
ip='$IP', gender='$GENDER' WHERE username='$AUTH_USERNAME'");
if ($AUTH_USERNAME != $U) $AUTH_USERNAME = $U;
$Message = L_REG_17;
}
* Tìm và xoá dòng
$PASSWORD = $AUTH_PASSWORD;
* Tìm dòng
<INPUT type="hidden" name="AUTH_PASSWORD" value="<?php
echo(htmlspecialchars(stripslashes($AUTH_PASSWORD))); ?>">
Thay bằng
<INPUT type="hidden" name="PWD_Hash" value="<?php
echo(htmlspecialchars(stripslashes($PWD_Hash))); ?>">
* Tìm và xoá đoạn mã
<TD ALIGN="RIGHT" VALIGN="TOP" NOWRAP><?php echo(L_REG_7); ?> :</TD>
<TD VALIGN="TOP">
<!-- Password can not be modified via the profile command -->
<INPUT TYPE="password" NAME="PASSWORD" SIZE=11 MAXLENGTH=16 VALUE="<?php
echo(htmlspecialchars(stripslashes($PASSWORD))); ?>"<?php if ($done) echo("
READONLY"); if (isset($LIMIT) && $LIMIT) echo(" DISABLED"); ?>>
<?php
if (isset($LIMIT) && $LIMIT)
{
?>
<INPUT TYPE="hidden" NAME="PASSWORD" VALUE="<?php
echo(htmlspecialchars(stripslashes($PASSWORD))); ?>">
<?php
};
if (!$done)
{
?>
<SPAN CLASS="error">*</SPAN>
<?php
};
?>
</TD>
</TR>
<TR>
4. Mở file chat/lib/commands/profile.cmd.php
* Tìm dòng
"window.open(\"edituser.php?L=$L&AUTH_USERNAME=$U&LIMIT=1\",\"edituser_popup\",\"width=350,height=470,resizable=yes,scrollbars=yes\");",
Thay bằng
"window.open(\"edituser.php?L=$L&AUTH_USERNAME=$U&LIMIT=1&PWD_Hash=$PWD_Hash\",\"edituser_popup\",\"width=350,height=470,resizable=yes,scrollbars=yes\");",
5. Mở file chat/handle_inputH.php
* Tìm đoạn
function AddMessage($M, $T, $R, $U, $C, $Private)
{
global $DbLink;
global $Latin1;
global $status;
Thêm vào bên dưới
global $SmiliesTbl;
6. Mở file chat/input.php
* Tìm đoạn
function AddMessage($M, $T, $R, $U, $C, $Private)
{
global $DbLink;
global $Latin1;
global $status;
Thêm vào bên dưới
global $SmiliesTbl;
7. Mở file chat/help_popup.php
* Tìm đoạn
<?php
if (C_USE_SMILIES == "1")
{
Thêm vào bên đưới
include("./lib/database/".C_DB_TYPE.".lib.php");
8. Tạo file smilies.lib.php để thay thế cho Chat/lib/smilies.lib.php
<?
$SmiliesTbl = Array();
function Create_Smiles()
{
global $SmiliesTbl;
$DbLink = new DB;
$DbLink->query("select code, smile_url from ".C_SMILES_TABLE);
$SmileRowCount = $DbLink->num_rows();
for ($i=0;$i<$SmileRowCount;$i++) {
list($Code, $Smile) = $DbLink->next_record();
$SmiliesTbl[trim($Code)] = trim($Smile);
}
reset($SmiliesTbl);
$DbLink->clean_results();
// Do not use DBLink - Close
}
Create_Smiles();
$MaxWidth = "100"; // Set the maximum width among similes
$MaxHeight = "0"; // Set the maximum height among similes
// ---- DO NOT MODIFY BELOW ----
// Slashes ' and " characters
function SpecialSlash(&$Str)
{
return str_replace("\"",""",str_replace("'","\\'",$Str));
}
// Replace smilies code by gif URLs in messages
function Check4Smilies(&$string,&$Table)
{
$tmp_tbl = split("<a href|</a>", " ".$string." ");
$i = "0";
reset($Table);
for (reset($tmp_tbl); $substring=current($tmp_tbl); next($tmp_tbl))
{
// $substring is one of the trailing spaces added above -> do nothing
if($substring == " ")
{
}
// $substring is not an HTTP link -> do the work for smilies
elseif (($i % 2) == "0")
{
while(list($key, $prop) = each($Table))
{
$substring = str_replace($key, " <IMG SRC=\"../images/smiles/$prop\"> ",
$substring);
// $substring = ereg_replace($key, " <IMG SRC=\"../images/smilies/$prop\"
ALT=\"".str_replace("\"",""", stripslashes($key))."\"> ", $substring);
};
$tmp_tbl[$i] = $substring;
}
// $substring is an HTTP link -> just restore HTML tags for links
else
{
$tmp_tbl[$i] = "<a href".$substring."</a>";
}
$i++;
};
$string = trim(join("",$tmp_tbl));
unset($tmp_tbl);
}
// Display smilies in the help popup and in the tutorials
function DisplaySmilies(&$ToDisplay,&$Table,&$TblSize,$Target)
{
global $MaxWidth, $MaxHeight;
$i = 0;
$Str1 = "";
$Str2 = "";
$PerLines = floor(600/$MaxWidth);
reset($Table);
while(list($key, $prop) = each($Table))
{
$i++;
if ($Target == "help") $Str1 .= "\t\t<TD ALIGN=\"CENTER\" WIDTH=$MaxWidth
HEIGHT=$MaxHeight><A HREF=\"#\"
onClick=\"smiley2Input('".SpecialSlash($key)."'); return false\"><IMG
SRC=\"../images/smiles/$prop\" BORDER=0 ALT=\"".str_replace("\"",""",
stripslashes($key))."\"></A></TD>\n";
else $Str1 .= "\t\t<TD ALIGN=CENTER WIDTH=$MaxWidth HEIGHT=$MaxHeight><IMG
SRC=\"../images/smiles/$prop\" BORDER=0 ALT=\"".str_replace("\"",""",
stripslashes($key))."\"></TD>\n";
$Str2 .= "\t\t<TD ALIGN=\"CENTER\" NOWRAP>".stripslashes($key)."</TD>\n";
if (is_integer($i/$PerLines) || $i == $TblSize)
{
$ToDisplay[] = $Str1;
$ToDisplay[] = $Str2;
$Str1 = "";
$Str2 = "";
};
};
};
?>
C. Sửa các file nguồn của PhpBB
1. Mở file Forum/includes/page_header.php
* Tìm đoạn mã
$l_online_users = sprintf($l_t_user_s, $total_online_users);
$l_online_users .= sprintf($l_r_user_s, $logged_visible_online);
$l_online_users .= sprintf($l_h_user_s, $logged_hidden_online);
$l_online_users .= sprintf($l_g_user_s, $guests_online);
Thêm vào bên dưới
if( $userdata['session_logged_in'] ) {
// Do Cleanup on Users in Chat mode.
if (!defined("C_USR_DEL")) define("C_USR_DEL", '4');
$sql = "DELETE FROM ".$table_prefix."c_users WHERE u_time < ".(time() -
C_USR_DEL * 60)." OR (status = 'k' AND u_time < ".(time() - 20).")";
$status = $db->sql_query($sql);
$sql = "SELECT DISTINCT username FROM ".$table_prefix."c_users";
$status = $db->sql_query($sql);
if ($status) {
$l_chatting_users = $db->sql_numrows();
} else {
$l_chatting_users = 0;
}
}
* Tìm dòng
'PRIVATE_MESSAGE_NEW_FLAG' => $s_privmsg_new,
Thêm vào bên dưới
'TOTAL_USERS_CHATTING' => $l_chatting_users,
'U_CHATLINK' => append_sid('chatlink.'.$phpEx),
2. Mở file Forum/Portal_body.tpl hay index_body.tpl hay….
Bổ sung đoạn mã dưới đây vào vị trí bạn muốn cho
hiển thị hộp thoại Chat.
<table cellSpacing="1" cellPadding="3" width="100%" align="center" border="0"
class="forumline">
<tr>
<td class="catHead" height="28" colspan="2" align="center"><SPAN
class=gen><b><font color="#000080"><img
src="templates/subSilver/images/server.gif" border="0" alt="Chat" /> Tán gẫu
(Chat)</font></b></SPAN></td>
</tr>
<tr>
<td class="row1" align="left"><span class="gensmall">Tất cả các thành viên sau
khi đăng nhập đều có quyền tham gia chat với account của Diễn đàn mà không cần
phải đăng ký lại.</span></td>
</tr>
<!-- BEGIN switch_user_logged_in -->
<tr>
<td class="row2" align="left"><span class="gensmall">- Hiện có
<b>{TOTAL_USERS_CHATTING}</b> người đang chat</a></span></td>
</tr>
<tr>
<td class="catHead" height="28" align="center"><a href="{U_CHATLINK}"
target="apchat" class="mainmenu" alt="Chat"><SPAN class=cattitle> Tham gia
Chat</span></td>
</tr>
<!-- END switch_user_logged_in -->
</table>
3. Tạo file chatlink.php vào thư mục gốc của Forum
<?php
define('IN_PHPBB', true);
$ChatPath = "./chat/";
require("./chat/config/config.lib.php");
require("./chat/lib/database/".C_DB_TYPE.".lib.php");
$phpbb_root_path = "./";
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
if( !$userdata['session_logged_in'] )
{
header("Location: " . append_sid("login.$phpEx?redirect=chatlink.$phpEx",
true));
}
set_magic_quotes_runtime(0);
$U = trim($userdata['username']);
$PASSWORD = $userdata['user_password'];
$PWD_Hash = md5(stripslashes($PASSWORD));
$Latin1 = 0;
$COUNTRY = $userdata['user_lang'];
$FIRSTNAME = $userdata['username'];
$LASTNAME = ''; $WEBSITE = '';
$EMAIL = $userdata['user_email'];
$showemail = $userdata['user_viewemail'];
$IP = $user_ip;
$GENDER = 1; // Default to Male
// Update or Add user to database.
$SQL = "select * from ".C_REG_TBL." where username='$U'";
$Query_Result = $db->sql_query($SQL);
if (!$Query_Result) {
message_die(CRITICAL_ERROR, "Could not query chat users", "", __LINE__,
__FILE__, $SQL);
}
$Count = $db->sql_numrows();
if ($Count == 0) {
$SQL = "INSERT INTO ".C_REG_TBL." VALUES ('$U', '$Latin1', '$PWD_Hash',
'$FIRSTNAME', '$LASTNAME', '$COUNTRY', '$WEBSITE', '$EMAIL', $showemail, 'user',
'',".time().", '$IP', '$GENDER')";
} else {
$SQL = "update ".C_REG_TBL." set password='$PWD_Hash', email='$EMAIL',
showemail='$showemail' where username='$U'";
}
if (!($Query_Result = $db->sql_query($SQL))) {
message_die(CRITICAL_ERROR, "Could not update chat users", "", __LINE__,
__FILE__, $SQL);
}
$R = "General";
$CookieRoom = urlencode(stripslashes($R));
setcookie("CookieRoom", $CookieRoom, time() + 60*60*24*365); // cookie expires
in one year
setcookie("CookieRoomType", 1, time() + 60*60*24*365); // cookie expires in one
year
if (!defined("C_USR_DEL")) define("C_USR_DEL", '4');
$SQL = "DELETE FROM ".C_USR_TBL." WHERE u_time < ".(time() - C_USR_DEL * 60)."
OR (status = 'k' AND u_time < ".(time() - 20).")";
if (!($Query_Result = $db->sql_query($SQL))) {
message_die(CRITICAL_ERROR, "Could not cleanup chat users", "", __LINE__,
__FILE__, $SQL);
}
$UserInChat = "";
$SQL = "SELECT DISTINCT username FROM ".C_USR_TBL;
if (!($Query_Result = $db->sql_query($SQL))) {
message_die(CRITICAL_ERROR, "Could not cleanup chat users", "", __LINE__,
__FILE__, $SQL);
}
for ($i=0;$i< $db->sql_numrows(); $i++) {
if ($UserInChat != "") $UserInChat .= ", ";
$UserInChat .= $db->sql_fetchfield(0, $i, $Query_Result);
}
include ($phpbb_root_path . "includes/page_header.php");
?>
<SCRIPT TYPE="text/javascript" LANGUAGE="javascript">
<!--
var NS4 = (document.layers) ? 1 : 0;
var IE4 = ((document.all) && (parseInt(navigator.appVersion)>=4)) ? 1 : 0;
var ver4 = (NS4 || IE4) ? "H" : "L";
// Will update the "Ver" field in the form below according to the javascript
abilities of the browser the users surf with
function defineVerField()
{
if (document.images && ver4 == 'L')
document.forms['Params'].elements['Ver'].value = 'M'; // js1.1 enabled browser
else document.forms['Params'].elements['Ver'].value = ver4;
}
---></SCRIPT>
<hr>
<FORM ACTION="./chat/index.php" METHOD="POST" NAME="Params"
onSubmit="defineVerField();">
<table width="97%" align="center"><th>
<center><font size=+2><b><?php echo C_FORUM_NAME; ?> Chat</b></font>
</th>
<tr><td class="row1">
<br>
<center><font size=2> Chào mừng <b><?php echo $U ?></b> tham gia
chat.<br><br>Hiện <?php
if ($l_chatting_users == 0) echo "<b>không có</b> ai ";
else if ($l_chatting_users == 1) echo "có <b>1</b> người ";
else echo "<b>".$l_chatting_users."</b> người ";
echo "đang chat.<br><br></font>";
if ($l_chatting_users > 0) {
echo "<font size=2>Thành viên đang chat: <b>".$UserInChat."</b>";
}
?><br><br>
<INPUT TYPE="hidden" NAME="Ver" VALUE="L">
<INPUT TYPE="hidden" NAME="Form_Send" VALUE="1">
<INPUT TYPE="hidden" NAME="L" VALUE="english">
<INPUT TYPE="hidden" NAME="N" VALUE="<?php echo(C_MSG_NB); ?>">
<INPUT TYPE="hidden" NAME="D" VALUE="<?php echo(C_MSG_REFRESH); ?>">
<INPUT TYPE="hidden" NAME="U" VALUE="<?php echo($U); ?>">
<input type="hidden" NAME="PASSWORD" VALUE="<?php echo ($PASSWORD) ?>">
<input type="hidden" NAME="R0" VALUE="General">
<INPUT TYPE="submit" VALUE="Tham gia chat"><br><br>
</td></tr>
<tr><td class="row2" align="center"><font size=1><b>Chú ý</b>: Thông điệp sẽ bị
xoá sau 24 giờ và tên người chat sẽ bị xoá sau 4 phút không hoạt
động.</font></td></tr>
</table></FORM>
<?php
if( $userdata['user_level'] == ADMIN ) {
?>
<center>
<FORM ACTION="./chat/admin.php" METHOD="POST">
<INPUT TYPE="hidden" NAME="L" VALUE="english">
<input type="hidden" NAME="Link" value="1">
<INPUT TYPE="hidden" NAME="user" VALUE="<?php echo($U); ?>">
<input type="hidden" NAME="pswd" VALUE="<?php echo ($PASSWORD) ?>">
<INPUT TYPE="submit" VALUE="phpMyChat Admin"><br><br>
</form>
</center>
<?php
}
include_once($phpbb_root_path . 'includes/page_tail.php');
if ($config_footer == YES) include ("$footer");
?>
"<?php echo($U); ?>">
<input type="hidden" NAME="PASSWORD" VALUE="<?php echo ($PASSWORD) ?>">
<input type="hidden" NAME="R0" VALUE="General">
<INPUT TYPE="submit" VALUE="chat"><br><br>
</td></tr></table></FORM>
<?php
include_once($phpbb_root_path . 'includes/page_tail.php');
if ($config_footer == YES) include ("$footer");
?>ES) include ("$footer");
?>
Bạn có thể xem Demo và tải các file nguồn trong diễn đàn PCLEHOAN
http://www.weblh.info/forum/
PcLeHoan
1996 - 2002
Mirror :
http://www.pclehoan.com
Mirror :
http://www.lehoanpc.net
Mirror :
http://www.ktlehoan.com