<?php
/////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                             //
//  GumChat                                                                                    //
//  Current Version : 2.0                                                                    //
//  Author : GUMSLONE                                                                          //
//  You are not allowed to redistribute or modify this script                                  //
//  Copyright (c) 2008 GumSlone. All rights reserved.                                          //
//  Additional scripts can be found at http://www.wapforum.org.uk                              //
//  15.11.2008                                                                                 //
/////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// CONFIGURATION STARTS HERE
///////////////////////////////////////////////////////////////////////////
if( is_array($_REQUEST) )
{
while( list($k, $v) = each($_REQUEST) )
{
if( is_array($_REQUEST[$k]) )
{
while( list($k2, $v2) = each($_REQUEST[$k]) )
{
$$k[$k2] = addslashes($v2);
}
@reset($_REQUEST[$k]);
}
else
{
$$k = addslashes($v);
}
}
@reset($_REQUEST);
}
//0 means server time
$TimeZone = "0";
// hours* 60 mins* 60secs DONT TOUCH!
$New_Time = time() + ($TimeZone * 60 * 60);
//DONT TOUCH!
$_time = date("H:i", $New_Time);
//chatroom refreshtime
$_refresh = 200;
//means chatroom size of 15 messages
$_room_size = 20;
$home_page_url = "http://adhakg.in";
$home_page_title = "";

//up to which text message should be smilies visible, from this text messages the smilies will be shown as a text not as an image
$smilies_decode = 5;

$waittime_sec = 5;
/* Set this to a minimum wait time between posts (in sec) */

//DONT TOUCH!
$encoding = "ISO-8859-1";
/////////////[Change language or menu]////////////////////////////////
$lang_user_in_chat = "users in chat";
$lang_enter = "- Enter -";
$lang_nickname = "Your Nickname:";
$lang_gender = "Gender:";
$lang_male = "Male";
$lang_female = "Female";
$lang_age = "Age: ";
$lang_show_smilies = "Show smilies? ";
$lang_yes = "YES";
$lang_no = "NO";
$lang_nick_color = "Nickname color:";
$lang_select_chatroom = "Select Chatroom";
$lang_users = "Users in";
$lang_chatrooms = "Chatrooms";
$lang_smilies = "Smilies";
$lang_next = "Next &#187;";
$lang_prev = "&#171; Prev";
$lang_chat = "Back to Chatroom";
$lang_say = "Say";
$lang_refresh = "Refresh";
$lang_message = "Message:";
$lang_ok = "OK";
$lang_jump = "Jump";
$lang_change_chatroom = "Change Chatroom";
$lang_who_is_online = "Who's Inside";
$lang_autorefresh = "Autorefresh mode";
$lang_manual_autorefresh = "Manual refresh mode";
$lang_loading = "Loading...<br/>please wait";
$lang_exit = "Logout";
//$BestTopMobi_id="30357";  //your besttop.mobi id, register your site at http://besttop.mobi to get an id. or just leave 0
$config_keypass = 'gHe'; //change the value to any value you want or just leave this, its not important
///////////////////////////////////////////////////////////////////////////
// CONFIGURATION ENDS HERE
///////////////////////////////////////////////////////////////////////////



/////////////[DO NOT EDIT AFTER THIS LINE]////////////////////////////////
$nick = nick_replace($nick);
$nick = substr(trim($nick), 0, 15);
global $nick;
if(isset($gum_ss)){

$gum_ss_data=xoft_decode($gum_ss, $config_keypass);
list($gum,$nick,$room,$C,$sm,$G,$A,$RF) = explode("|", $gum_ss_data);
}
$link_gum_ss=xoft_encode($gum.'|'.$nick.'|'.$room.'|'.$C.'|'.$sm.'|'.$G.'|'.$A.'|'.$RF, $config_keypass);



///////////IF Nickname is shorter than 3 chars retur an error message and let the user relogin//////////
if ($nick != '' && strlen($nick) < 3) {
$gum = "";
$login_error_message .= '<i>Nickname is to short, it has to be longer than 3 chars, also avoid special chars in nickname. Allowed chars: A-Z, a-z, 0-9, - _ @</i><br/>';
}
$G = nick_replace(substr(trim($G), 0, 1));

$A = nick_replace(substr(trim($A), 0, 2));

$room = replace($room);

header('Content-Type: application/xhtml+xml; charset=iso-8859-1');
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
echo '<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="no-cache" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<link rel="shortcut icon" href="favicon.ico" />';
?>

<!-- GumChat by GumSlone Version 2.0  (c) 2011 All rights reserved. -->
<!-- Additional scripts can be found at http://www.wapforum.org.uk -->
<?php
if ($nick && $room) {
$daten = 'online/on' . $room;
$time = time();
$user = explode('/', $_SERVER['HTTP_USER_AGENT']);
$user[0] = ereg_replace(' ', '_', $user[0]);
$ip = (trim($nick) . ' ' . trim($user[0]) . ' ' . trim($G) . ' ' . trim($A));
$ablaufzeit = $time - 250;
$pruefung = @file($daten);

while (list($line_num, $line) = @each($pruefung)) {
$zeiten = explode(":", $line);

if ($zeiten[0] <= $ablaufzeit) {
$fp = fopen($daten, "r");
$contents = fread($fp, filesize($daten));
fclose($fp);
$line = quotemeta($line);
$string2 = "";
$replace = ereg_replace($line, $string2, $contents);
$fh = fopen($daten, "w");
@flock($fp, 2);
fputs($fh, $replace);
@flock($fp, 3);

fclose($fh);
}
}

$ippruefung = @file($daten);

while (list($line_num, $line) = @each($ippruefung)) {
$ips = explode(":", $line);

if ($ips[1] == $ip) {
$fp = fopen($daten, "r");

$contents = fread($fp, filesize($daten));

fclose($fp);

$line = quotemeta($line);

$string2 = "";

$replace = ereg_replace($line, $string2, $contents);

$fh = fopen($daten, "w");

@flock($fp, 2);

fputs($fh, $replace);

@flock($fp, 3);

fclose($fh);
}
}

$fp = fopen($daten, "a+");

flock($fp, 2);

fputs($fp, "$time:$ip:\n");

flock($fp, 3);

fclose($fp);
}


if ($gum == "") {
echo '<title>Chat.Umpata.CoM ' . $_time . '</title>
<style type="text/css">
body {
font-weight : normal;
font-family : Verdana, Arial, Helvetica, sans-serif;
background-color : #ffffff;
color : #464646;
margin : 1px 2px 1px 2px;
border : 1px dashed #808040;
}
a:active, a:visited, a:link, a.ads:active, a.ads:visited, a.ads:link {
color : #0080FF;
text-decoration: none;
}
a:hover {
color : #ff3e3e;
text-decoration: underline;
}
p {margin: 0px 0px 0px 0px; padding: 2px;}
p.c {
text-align : center;
}
span.nick {
color : #009b00;
font-weight : bold;
}
hr {
background-color: #99cccc;
color: #99cccc;
border: none;
height: 1px;
}
div { padding: 2px; }
div.c {
text-align : center;
}
div.divide {
background-color : #f5f5f5;
}
form {
margin : 2px;
}
form > fieldset {
border : 1px solid #cccccc;
}
input, textarea, select {
margin : 2px;
font-family : Verdana, arial;
font-size : 11px;
}
</style>
</head>
<body>';
echo '<p class="c">';
echo '<img src="logo.gif" alt=""/>';
echo '</p>';
echo $login_error_message;

$n = 0;
$files = '';

if ($handle = opendir('rooms/')) {
while (false !== ($file = readdir($handle))) {
if ($file != '.' && $file != '..' && $file != 'files' && $file != 'cgi-bin' && $file != 'chat') {
if ($n >= 0 && $n < 20) {
$onfile = file('online/on' . $file);

$counts = count($onfile);

if ($counts < 2) {
$gumdata = explode(':', $onfile[0]);

$ablaufzeit = time() - 250;

if ($gumdata[0] <= $ablaufzeit) {
$fp = fopen('online/on' . $file, "w+");

$counts = 0;
}
}

$total = $total + $counts;
$n++;
}
}
}

closedir($handle);
}

echo '<p>' . $total . ' ' . $lang_user_in_chat . '!</p>';
echo "<form action=\"" . $_SERVER["PHP_SELF"] . "\" method=\"get\">
<div>" . $lang_nickname . "<br/>
<input type=\"hidden\" name=\"WLC\" value=\"1\"/>
<input type=\"hidden\" name=\"gum\" value=\"rooms\"/>
<input name=\"nick\" value=\"\"/><br/>";
echo $lang_gender . '
<select name="G">
<option value="m">' . $lang_male . '</option>
<option value="f">' . $lang_female . '</option>
</select><br/>';
echo $lang_age . " <input title=\"age\" name=\"A\" size=\"4\" style=\"-wap-input-format: '*N'\" value=\"\"/><br/>";
echo $lang_show_smilies . '
<select name="sm">
<option value="1">' . $lang_yes . '</option>
<option value="0">' . $lang_no . '</option>
</select><br/>';
echo $lang_nick_color . '<br/><select name="C">
<option value="000000">Black</option>
<option value="ff0000">Red</option>
<option value="00ffff">Turquoise</option>
<option value="808080">Dark Grey</option>
<option value="ff8040">Orange</option>
<option value="804000">Brown</option>
<option value="00ff00">Green</option>
<option value="ffff00">Yellow</option>
<option value="ff00ff">Pink</option>
<option value="408080">Grass Green</option>
<option value="008000">Dark Green</option>
<option value="800000">Burgundy</option>
<option value="0000a0">Dark Blue</option>
</select><br/>';
echo "<input type=\"submit\" value=\"" . $lang_enter . "\"/>
</div>
</form>";

echo '<p>';
include('adtw.php');
//echo '<br/>';
echo '<br/>Script by: <a href="http://gumslone.info"> GumSlone</a><br/>(c) Chat.Umpata.CoM </p>';
}

if ($gum == "rooms") {
echo '<title>' . $lang_chatrooms . ' (' . $_time . ')</title>
<style type="text/css">
body {
font-weight : normal;
font-family : Verdana, Arial, Helvetica, sans-serif;
background-color : #ffffff;
color : #464646;
margin : 1px 2px 1px 2px;
border : 1px dashed #808040;
}
a:active, a:visited, a:link, a.ads:active, a.ads:visited, a.ads:link {
color : #0080FF;
text-decoration: none;
}
a:hover {
color : #ff3e3e;
text-decoration: underline;
}
p {margin: 0px 0px 0px 0px; padding: 2px;}
p.c {
text-align : center;
}
span.nick {
color : #009b00;
font-weight : bold;
}
hr {
background-color: #99cccc;
color: #99cccc;
border: none;
height: 1px;
}
div { padding: 2px; }
div.c {
text-align : center;
}
div.divide {
background-color : #f5f5f5;
}
form {
margin : 2px;
}
form > fieldset {
border : 1px solid #cccccc;
}
input, textarea, select {
margin : 2px;
font-family : Verdana, arial;
font-size : 11px;
}
</style>
</head>
<body>';

$nick = ereg_replace(" ", "_", $nick);
if (preg_match("/[^\da-zA-Z-@_]+/", $nick) || $nick == "")
$error = 'Not suported chars in Nickname!<br/>';
if (empty($error)) {
echo '<p style="c">';
if ($WLC)
echo 'Welcome to chat ' . $nick . '<br/>';
echo $lang_select_chatroom . '<br/>';
echo '</p>';
$n = 0;
$files = '';

if ($handle = opendir('rooms/')) {
$I = 0;
while (false !== ($file = readdir($handle))) {
if ($file != '.' && $file != '..' && $file != 'files' && $file != 'cgi-bin' && $file != 'chat') {
if ($n >= 0 && $n < 20) {
$I++;
$geting_class = ($I / 2) - floor($I / 2);
if ($geting_class == 0) {
$Class = '';
} else {
$Class = ' class="divide"';
}

$onfile = file('online/on' . $file);
$counts = count($onfile);
$total = $total + $counts;
$n++;

echo '<div' . $Class . '><a href="' . $_SERVER["PHP_SELF"] . '?gum_ss='.xoft_encode('croom|'.$nick.'|'.$file.'|'.$C.'|'.$sm.'|'.$G.'|'.$A.'|1', $config_keypass).'">' . $file . ' (' . $counts . ')</a></div>';
}
}
}

closedir($handle);
}
} else
echo '<p>' . $error . 'Press back button!<br/><a href="' . $_SERVER["PHP_SELF"] . '">Login here again</a></p>';

echo '<p>' . $total . ' ' . $lang_users . ' ' . $n . ' ' . $lang_chatrooms . '!<br/>';
echo 'Invite your friends to chat via <a href="sms:?body=Check out on your mobile this great chat site! http://Chat.Umpata.CoM">sms</a> or <a href="mailto:?subject=Check out on your mobile this great chat site!&amp;body=Here\'s the link: http://Chat.Umpata.CoM">email</a><br/>';
echo '<a href="' . $_SERVER["PHP_SELF"] . '">' . $lang_exit . '</a><br/>';
echo '<br/>Script by: <a href="http://gumslone.info">GumSlone</a><br/>(c) Chat.Umpata.CoM</p>';
}


if ($gum == "croom") {
$rand_key = @rand(53256, 16326239);
if ($RF == 1)
echo '<meta http-equiv="refresh" content="30;url=' . $_SERVER["PHP_SELF"] . '?gum_ss=' . $link_gum_ss . '&amp;r=' . $rand_key . '"/>';
$onxfile = @file('online/on' . $room);

$countonl = count($onxfile);
echo '<title>' . $room . ' in ' . $countonl . ' (' . $_time . ')</title>
<style type="text/css">
body {
font-weight : normal;
font-family : Verdana, Arial, Helvetica, sans-serif;
background-color : #ffffff;
color : #464646;
margin : 1px 2px 1px 2px;
border : 1px dashed #808040;
}
a:active, a:visited, a:link, a.ads:active, a.ads:visited, a.ads:link {
color : #0080FF;
text-decoration: none;
}
a:hover {
color : #ff3e3e;
text-decoration: underline;
}
p {margin: 0px 0px 0px 0px; padding: 2px;}
p.c {
text-align : center;
}
span.nick {
color : #009b00;
font-weight : bold;
}
hr {
background-color: #99cccc;
color: #99cccc;
border: none;
height: 1px;
}
div { padding: 2px; }
div.c {
text-align : center;
}
div.divide {
background-color : #f5f5f5;
}
form {
margin : 2px;
}
form > fieldset {
border : 1px solid #cccccc;
}
textarea, select {
margin : 2px;
font-family : Verdana, arial;
font-size : 11px;
}
input[type="text"] { background:white; color:black; width:100px; margin:2px; border-width:1px; border-color:gray; border-style:solid; margin-left:3px}
input[type="Password"] { background: white; color:black ; width: 90px; margin: 2px; border-width: 1px; border-color: gray; border-style: solid; margin-left: 3px} input[type=submit] {border:2px solid #CCCCCC; color:#FFFFFF; background-color:#006699} textarea { background: white;color: black; margin: 2px; border-width: 1px; border-color: gray; border-style: solid; margin-left: 3px; height: 25px; Width: 95px;} select{background: white; color: #063F4F; margin: 2px; border-width: 1px; border-color: gray; border-style: solid; margin-left: 3px; width:50px; }
</style>
</head>
<body>';
echo "<div style='text-align:center'><form id=\"ms" . $rand_key . "\" action=\"" . $_SERVER["PHP_SELF"] . "\" method=\"post\">
<div>
<input type=\"text\" name=\"mess\"/><br/>
<input type=\"hidden\" name=\"gum_ss\" value=\"$link_gum_ss\"/>
<input type=\"hidden\" name=\"antiflood\" value=\"$rand_key\"/>
<input type=\"submit\" value=\"" . $lang_say . "\"/>
</div>
</form>";
echo '<a id="say"></a>';
echo '<a href="' . $_SERVER["PHP_SELF"] . '?gum_ss=' . $link_gum_ss . '&amp;ckobi=1&amp;r=';
echo $New_Time;
echo '">[- Reload -]</a> ';
echo '<a href="#menu">[- Menu -]</a><br/>----------</div>';
////////////////////////////////////////
if ($_POST["mess"] != "") {
$mess = replace($_POST["mess"]);
$mess = filterFlood($mess);
$mess = filterBadWords($mess);

$C = color_check($C);
$mess = trim(substr($mess, 0, 160));

$_mudata = explode(" ", $mess);
$count_spaces = count($_mudata);
$count_chars = strlen($mess);
if ($count_chars < 3 && !empty($mess)) {
$chat_error_message .= '<i>The message is to short, it has to be longer than 4 chars</i><br/>';
}

$text = $C . "&&$nick $_time&&$mess&&" . $antiflood;
if ($count_spaces < 3 && $count_chars > 30)
$FOUND = 1;
if ($count_spaces < 5 && $count_chars > 40)
$FOUND = 1;
}
//////////////////////////////////////////////
if ($mess != "" && !$chat_error_message) {
$udata = explode("&&", $text);
$udata[2] = htmlspecialchars($udata[2]);
$udata[2] = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '', $udata[2]);
$udata[2] = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '', $udata[2]);
if ($sm == 1)
$udata[2] = ReplaceTextToSmilies($udata[2]);
echo '<div><span style="color : #' . $udata[0] . '; font-weight : bold;">' . htmlspecialchars($udata[1]) . ' &#187;</span> ' . $udata[2] . '</div>';
} else
echo $chat_error_message;

$fp = fopen('rooms/' . $room, "r");
$smilies_decode_num = 1;
$I = 0;
$mini_found = 1;
while ($radka = fgets($fp, 512)) {
$udata = explode("&&", $radka);
if ($udata[2] != "") {
$I++;
$geting_class = ($I / 2) - floor($I / 2);
if ($geting_class == 0) {
$Class = '';
} else {
$Class = ' class="divide"';
}
////////////////////////ANTIFLOOOOOOOOOOOOOOOOOD////////////////////
if (isset($mess)) {
if ($udata[3] == $antiflood) {
$FOUND = 1;
}
if (trim($udata[2]) == trim($mess)) {
$FOUND = 1;
}


if($FOUND!=1){



$checktext_1 = preg_replace('/[^[:alnum:]\^]/', '', strtolower($udata[2]));
$checktext_2 = preg_replace('/[^[:alnum:]\^]/', '', strtolower($mess));
$count_checktext_1 = strlen($checktext_1);
$count_checktext_2 = strlen($checktext_2);
$rand_start_1 = rand(1, $count_checktext_1-6);
$rand_start_2 = rand(1, $count_checktext_2-6);
for($n=1;$n<=$count_checktext_1;$n++)
{
if (substr($checktext_1, $rand_start_1, 6) == substr($checktext_2, $n, 6)) {
$FOUND = 1;
break;
}
if (substr($checktext_2, $rand_start_2, 6) == substr($checktext_1, $n, 6)) {
$FOUND = 1;
break;
}


}


if($FOUND!=1){
for($n=$count_checktext_1;$n>=1;$n--)
{
if (substr($checktext_1, $rand_start_1, 6) == substr($checktext_2, $n, 6)) {
$FOUND = 1;
break;
}
if (substr($checktext_2, $rand_start_2, 6) == substr($checktext_1, $n, 6)) {
$FOUND = 1;
break;
}
}
}



}

}
/*
$count_udata_chars = strlen($udata[2]);
if (substr($udata[1], 0, 2) == substr($nick, 0, 2)) {
if(substr(strtolower($udata[2]), 0, 2) == substr(strtolower($mess), 0, 2) && $count_chars < 6)
$mini_found++;
else if(substr(strtolower($udata[2]), $count_chars-2, 2) == substr(strtolower($mess), $count_chars-2, 2)&& $count_chars < 6)
$mini_found++;
else if($count_udata_chars==$count_chars)
$mini_found++;
else if ($count_chars < 8)
$mini_found++;
}

$first_check = substr(trim($udata[2]), 1, 11);
if ($first_check == substr(trim($mess), 1, 11)) {
$FOUND = 1;
}
if ($first_check == substr(trim($mess), 2, 11)) {
$FOUND = 1;
}
if ($first_check == substr(trim($mess), 3, 11)) {
$FOUND = 1;
}
if ($first_check == substr(trim($mess), 4, 11)) {
$FOUND = 1;
}
if ($first_check == substr(trim($mess), 5, 11)) {
$FOUND = 1;
}
if ($first_check == substr(trim($mess), 6, 11)) {
$FOUND = 1;
}
if ($first_check == substr(trim($mess), 7, 11)) {
$FOUND = 1;
}
if ($first_check == substr(trim($mess), 8, 11)) {
$FOUND = 1;
}

if (!isset($FOUND)) {
$count_udata = strlen($udata[2]);
$second_check = substr(trim($udata[2]), ($count_udata - 5), 4);
if ($count_chars > 6 && ( $second_check == substr(trim($mess), ($count_chars - 5), 4))) {
$FOUND = 1;
}
if ($count_chars > 6 && ($second_check == substr(trim($mess), ($count_chars - 6), 4))) {
$FOUND = 1;
}
if ($count_chars > 6 && ($second_check == substr(trim($mess), ($count_chars - 7), 4))) {
$FOUND = 1;
}
if ($count_chars > 6 && ($second_check == substr(trim($mess), ($count_chars - 8), 4))) {
$FOUND = 1;
}
}
if (!isset($FOUND)) {
$message_middle = ceil($count_chars / 2);

if ($count_chars > 10 && !isset($FOUND)) {
$udata_middle = ceil($count_udata / 2);
$third_check = substr(trim($udata[2]), ($udata_middle - 5), 4);
if ($count_chars > 6 && ($third_check == substr(trim($mess), ($message_middle - 5), 4))) {
$FOUND = 1;
}
if ($count_chars > 6 && ($third_check == substr(trim($mess), ($message_middle - 6), 4))) {
$FOUND = 1;
}
if ($count_chars > 6 && ($third_check == substr(trim($mess), ($message_middle - 7), 4))) {
$FOUND = 1;
}
if ($count_chars > 6 && ($third_check == substr(trim($mess), ($message_middle - 8), 4))) {
$FOUND = 1;
}
}
}
}
if ($mini_found > 3)
$FOUND = 1;
*/

/*
if (!isset($FOUND) && $count_chars > 30) {
preg_match_all(substr(trim($mess), ($udata_middle - 5), 4), $udata[2], $treffer);
$matches = count($treffer[0]);
if ($matches > 2)
$FOUND = 1;

if (!isset($FOUND)) {
preg_match_all(substr(trim($mess), ($udata_middle - 7), 4), $udata[2], $treffer);
$matches = count($treffer[0]);
if ($matches > 2)
$FOUND = 1;

if (!isset($FOUND)) {
preg_match_all(substr(trim($mess), ($udata_middle + 1), 4), $udata[2], $treffer);
$matches = count($treffer[0]);
if ($matches > 2)
$FOUND = 1;
}
}
}   */
if (!isset($FOUND) && $count_chars > 30) {

preg_match_all("/".substr(trim($mess), ($message_middle - 5), 4)."/i", $mess, $treffer);
$matches = count($treffer[0]);

if ($matches > 2)
$FOUND = 1;

if (!isset($FOUND)) {
preg_match_all("/".substr(trim($mess), ($message_middle - 7), 4)."/i", $mess, $treffer);
$matches = count($treffer[0]);
if ($matches > 2)
$FOUND = 1;

if (!isset($FOUND)) {
preg_match_all("/".substr(trim($mess), ($message_middle + 1), 4)."/i", $mess, $treffer);
$matches = count($treffer[0]);
if ($matches > 2)
$FOUND = 1;
}
}
}

/////////////////////////END OF ANTIFLOOD CHECK////////////////////

$udata[2] = htmlspecialchars($udata[2]);
$udata[2] = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '', $udata[2]);
$udata[2] = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '', $udata[2]);
// $udata[2] = filterBadWords($udata[2]);
if ($sm == 1 && $smilies_decode_num <= $smilies_decode)
$udata[2] = ReplaceTextToSmilies($udata[2]);

$smilies_decode_num++;
$udata[1] = ereg_replace("_", " ", $udata[1]);
echo '<div' . $Class . '><span style="color : #' . $udata[0] . '; font-weight : bold;">' . htmlspecialchars($udata[1]) . ' &#187;</span> ' . $udata[2] . '</div>';
}
}

fclose($fp);

/////////////////////WRITING A TEXT MESSAGE TO the FILE///////////////////////////
if (!$FOUND && $count_chars > 3 && $nick != "" && !$chat_error_message) {
$text = stripslashes($text);
$text = strip_tags($text);
$text = preg_replace("(\r\n|\n|\r)", "", $text);
#$text = ereg_replace("_", " ", $text);

if (file_exists('rooms/' . $room)) {
$zpravy = file('rooms/' . $room);
}

$fp = fopen('rooms/' . $room, "w");

fputs($fp, $text . "\n");
for ($i = 0; $i < $_room_size; $i++) {
fputs($fp, $zpravy[$i]);
}

fclose($fp);
}

/////////////////////END OF WRITING A TEXT MESSAGE TO the FILE///////////////////////////



echo '<div style="text-align:center">----------</div>';
echo '<p><a id="menu"></a>';
if ($RF != 1)
echo '<a href="#say">' . $lang_say . '</a> ';
else
echo '<a href="' . $_SERVER["PHP_SELF"] . '?gum_ss='.xoft_encode('say|'.$nick.'|'.$room.'|'.$C.'|'.$sm.'|'.$G.'|'.$A.'|1', $config_keypass).'">' . $lang_say . '</a> ';
echo '<a href="' . $_SERVER["PHP_SELF"] . '?gum_ss=' . $link_gum_ss . '&amp;r=';
echo $New_Time;
echo '">' . $lang_refresh . '</a><br/>';
echo '<a href="' . $_SERVER["PHP_SELF"] . '?gum_ss='.xoft_encode('online|'.$nick.'|'.$room.'|'.$C.'|'.$sm.'|'.$G.'|'.$A.'|'.$RF, $config_keypass).'">' . $lang_who_is_online . '</a><br/>';
if ($RF == 1)
echo '<a href="' . $_SERVER["PHP_SELF"] . '?gum_ss='.xoft_encode('croom|'.$nick.'|'.$room.'|'.$C.'|'.$sm.'|'.$G.'|'.$A.'|0', $config_keypass).'">' . $lang_manual_autorefresh . '</a><br/>';
else
echo '<a href="' . $_SERVER["PHP_SELF"] . '?gum_ss='.xoft_encode('croom|'.$nick.'|'.$room.'|'.$C.'|'.$sm.'|'.$G.'|'.$A.'|1', $config_keypass).'">' . $lang_autorefresh . '</a><br/>';
echo '<a href="' . $_SERVER["PHP_SELF"] . '?gum_ss='.xoft_encode('rooms|'.$nick.'||'.$C.'|'.$sm.'|'.$G.'|'.$A.'|'.$RF, $config_keypass).'">' . $lang_change_chatroom . '</a><br/>';
echo '<a href="' . $_SERVER["PHP_SELF"] . '?gum_ss='.xoft_encode('smilies|'.$nick.'|'.$room.'|'.$C.'|'.$sm.'|'.$G.'|'.$A.'|'.$RF, $config_keypass).'">' . $lang_smilies . '</a><br/>';
echo '<a href="' . $_SERVER["PHP_SELF"] . '">' . $lang_exit . '</a><br/><div class="bdm">';
include('adtw.php');
echo '</div><br/>(c) Umpata.CoM 2011</p>';
}

if ($gum == "say") {
echo '<title>' . $lang_smilies . ' (' . $_time . ')</title>
<style type="text/css">
body {
font-weight : normal;
font-family : Verdana, Arial, Helvetica, sans-serif;
background-color : #ffffff;
color : #464646;
margin : 1px 2px 1px 2px;
border : 1px dashed #808040;
}
a:active, a:visited, a:link, a.ads:active, a.ads:visited, a.ads:link {
color : #0080FF;
text-decoration: none;
}
a:hover {
color : #ff3e3e;
text-decoration: underline;
}
p {margin: 0px 0px 0px 0px; padding: 2px;}
p.c {
text-align : center;
}
hr {
background-color: #99cccc;
color: #99cccc;
border: none;
height: 1px;
}
div.c {
text-align : center;
}
form {
margin : 2px;
}
form > fieldset {
border : 1px solid #cccccc;
}
input, textarea, select {
margin : 2px;
font-family : Verdana, arial;
font-size : 11px;
}
</style>
</head>
<body>';
echo "<form id=\"ms" . $New_Time . "\" action=\"" . $_SERVER["PHP_SELF"] . "\" method=\"post\">
<div>
<textarea name=\"mess\" rows=\"2\" cols=\"40\"></textarea><br/>
<input type=\"hidden\" name=\"gum_ss\" value=\"".xoft_encode('croom|'.$nick.'|'.$room.'|'.$C.'|'.$sm.'|'.$G.'|'.$A.'|1', $config_keypass)."\"/>
<input type=\"hidden\" name=\"antiflood\" value=\"$rand_key\"/>
<input type=\"submit\" value=\"" . $lang_say . "\"/>
</div>
</form>";
echo '<p>';
echo '<a href="' . $_SERVER["PHP_SELF"] . '?gum_ss=' . xoft_encode('croom|'.$nick.'|'.$room.'|'.$C.'|'.$sm.'|'.$G.'|'.$A.'|1', $config_keypass). '">' . $lang_chat . '</a><br/>';
echo '<a href="' . $_SERVER["PHP_SELF"] . '?gum_ss=' . xoft_encode('rooms|'.$nick.'||'.$C.'|'.$sm.'|'.$G.'|'.$A.'|1', $config_keypass). '">' . $lang_change_chatroom . '</a><br/><div class="bdm">';
include('adtw.php');
echo '</div>(c) Umpata.CoM</p>';
}

if ($gum == "smilies") {
echo '<title>' . $lang_smilies . ' (' . $_time . ')</title>
<style type="text/css">
body {
font-weight : normal;
font-family : Verdana, Arial, Helvetica, sans-serif;
background-color : #ffffff;
color : #464646;
margin : 1px 2px 1px 2px;
border : 1px dashed #808040;
}
a:active, a:visited, a:link, a.ads:active, a.ads:visited, a.ads:link {
color : #0080FF;
text-decoration: none;
}
a:hover {
color : #ff3e3e;
text-decoration: underline;
}
p {margin: 0px 0px 0px 0px; padding: 2px;}
p.c {
text-align : center;
}
hr {
background-color: #99cccc;
color: #99cccc;
border: none;
height: 1px;
}
div.c {
text-align : center;
}
form {
margin : 2px;
}
form > fieldset {
border : 1px solid #cccccc;
}
input, textarea, select {
margin : 2px;
font-family : Verdana, arial;
font-size : 11px;
}
</style>
</head>
<body>';
echo '<p>';



$conf["items_per_page"] = 5;

if (isset($npage))
$page = $npage - 1;

if (!isset($page))
$page = 0;

if ($page < 0)
$page = 0;



$total = 0;

if (!($dp = opendir('./smilies/')))
die('Cannot open ./smilies/');

$file_array = array();

while ($file = readdir($dp)) {
if (substr($file, 0, 1) != '.' and $file != '..' and $file != 'index.php') {
$file_array[] = $file;
}
}

$file_count = count($file_array);

sort($file_array);



if ($file_count > 0) {
$first_record = $page * $conf["items_per_page"];

$last_record = $first_record + $conf["items_per_page"];



while (list($fileIndexValue, $file_name) = each($file_array)) {
if (($fileIndexValue >= $first_record) and ($fileIndexValue < $last_record)) {
$smilie = explode('.', $file_name);

echo '<img src="smilies/' . $file_name . '" alt=".' . $user[0] . '."/> .' . $smilie[0] . '.<br/>';
}
}



if (($file_count > 0) and ($last_record < $file_count)) {
// next button
$next_page = $page + 1;
echo '<br/><a href="' . $_SERVER["PHP_SELF"] . '?gum_ss='.$link_gum_ss.'&amp;page=' . $next_page . '">' . $lang_next . '</a><br/>';
}

if (($file_count > 0) and ($page != 0)) {
// previous button
$prev_page = $page - 1;
echo '<br/><a href="' . $_SERVER["PHP_SELF"] . '?gum_ss='.$link_gum_ss.'&amp;page=' . $prev_page . '">' . $lang_prev . '</a><br/>';
}
}

closedir($dp);

echo '<b>' . $file_count . '</b> ' . $lang_smilies . '<br/>';

$pages = ceil($file_count / $conf["items_per_page"]);

echo 'Page <b>' . ($page + 1) . '</b> of ' . $pages . '</p>';
echo "<form action=\"" . $_SERVER["PHP_SELF"] . "\">
<div>Jump to Page:
<input type=\"hidden\" name=\"gum_ss\" value=\"$link_gum_ss\"/>
<input title=\"page\" name=\"npage\" size=\"4\" style=\"-wap-input-format: '*N'\" value=\"\"/>
<input type=\"submit\" value=\"" . $lang_jump . "\"/>
</div>
</form>";

echo '<p><a href="' . $_SERVER["PHP_SELF"] . '?gum_ss=' . xoft_encode('croom|'.$nick.'|'.$room.'|'.$C.'|'.$sm.'|'.$G.'|'.$A.'|1', $config_keypass). '">' . $lang_chat . '</a><br/>';
echo '<a href="' . $_SERVER["PHP_SELF"] . '?gum_ss=' . xoft_encode('rooms|'.$nick.'||'.$C.'|'.$sm.'|'.$G.'|'.$A.'|1', $config_keypass). '">' . $lang_change_chatroom . '</a><br/>';
echo '(c) GumSlone 2010-2011</p>';
}

if ($gum == "online") {
echo '<title>' . $lang_who_is_online . ' (' . $_time . ')</title>
<style type="text/css">
body {
font-weight : normal;
font-family : Verdana, Arial, Helvetica, sans-serif;
background-color : #ffffff;
color : #464646;
margin : 1px 2px 1px 2px;
border : 1px dashed #808040;
}
a:active, a:visited, a:link, a.ads:active, a.ads:visited, a.ads:link {
color : #0080FF;
text-decoration: none;
}
a:hover {
color : #ff3e3e;
text-decoration: underline;
}
p {margin: 0px 0px 0px 0px; padding: 2px;}
p.c {
text-align : center;
}
span.nick {
color : #009b00;
font-weight : bold;
}
hr {
background-color: #99cccc;
color: #99cccc;
border: none;
height: 1px;
}
div { padding: 2px; }
div.c {
text-align : center;
}
div.divide {
background-color : #f5f5f5;
}
form {
margin : 2px;
}
form > fieldset {
border : 1px solid #cccccc;
}
input, textarea, select {
margin : 2px;
font-family : Verdana, arial;
font-size : 11px;
}
</style>
</head>
<body>';

echo '<p>' . $lang_who_is_online . '</p>';
$xfile = @file('online/on' . $room);
$xfile = array_reverse($xfile);
$p = 25;
if ($npage == "") {
$npage = 1;
}

$countfile = count($xfile);
$first = $countfile - ($p * ($npage - 1));
$second = $countfile - ($p * $npage) + 1;
if ($second < 1) {
$second = 1;
}
$npages = ceil($countfile / $p);
if ($npage <= $npages and $npage > 1)
$gline_rew = '<a href="' . $_SERVER["PHP_SELF"] . '?gum_ss=' . $link_gum_ss . '&amp;npage=' . ($npage - 1) . '">' . $lang_prev . '</a>';
if ($npages > 1 and $npage < $npages)
$gline_next = '<a href="' . $_SERVER["PHP_SELF"] . '?gum_ss=' . $link_gum_ss . '&amp;npage=' . ($npage + 1) . '">' . $lang_next . '</a>';

if ($npage == 1)
$nn = 1;
else
$nn = (($npage - 1) * $p) + 1;
$I = 0;
for ($i = $first - 1; $i >= $second - 1; $i--) {
$I++;
$geting_class = ($I / 2) - floor($I / 2);
if ($geting_class == 0) {
$Class = '';
} else {
$Class = ' class="divide"';
}

$xdata = explode(':', $xfile[$i]);
$udata = explode(' ', $xdata[1]);
if ($udata[2] == m)
$gender = $lang_male;
if ($udata[2] == f)
$gender = $lang_female;
echo '<div' . $Class . '>' . $nn++ . '. <span class="nick">' . $udata[0] . '</span> ' . $gender . ' (' . $udata[3] . ') ' . $udata[1] . '</div>';
}

echo '<p>';

if ($npages > 1)
echo $gline_rew . '| ' . $gline_next;


echo '<br/><a href="' . $_SERVER["PHP_SELF"] . '?gum_ss=' . xoft_encode('croom|'.$nick.'|'.$room.'|'.$C.'|'.$sm.'|'.$G.'|'.$A.'|1', $config_keypass). '">' . $lang_chat . '</a><br/>';
echo '<a href="' . $_SERVER["PHP_SELF"] . '?gum_ss=' . xoft_encode('rooms|'.$nick.'||'.$C.'|'.$sm.'|'.$G.'|'.$A.'|1', $config_keypass). '">' . $lang_change_chatroom . '</a><br/>';
echo '(c) GumSlone 2010-2011</p>';
}

echo '</body>
</html>';


function filterBadWords($str)
{
// words to filter, you can add here some more
// replace filtered words with
$badwords = array("2-wap", "htp", " dot ", "http", "\.biz", "\.c0m", "\.mobi", "\.net", "\.ru", "\.org", "\.wen", "\.com", "\.web.tr", "dhoomworld", "Chatworld", "Mobichat", "Desiclub", "Friendsgarage", "Friendsgarage", "Loverslane", "Mixit", "Mxit", "Prodigits", "Leeinc", "Eaglesnest", "Wap2chat", "Bdsaint", "Hitler", "Nazi", "Chod", "Wichser");
$replacements = array("???", "***");

for ($i = 0; $i < sizeof($badwords); $i++) {
srand((double)microtime() * 1000000);

$rand_key = (rand() % sizeof($replacements));

$str = eregi_replace($badwords[$i], $replacements[$rand_key], $str);
}

return $str;
}

function filterFlood($str)
{
// words to filter, you can add here some more

$text = str_replace('~~', '', $text);
$text = str_replace('@@', '', $text);
$text = str_replace('-', ' - ', $text);
$text = str_replace('___', '_', $text);
$text = str_replace('__', '_', $text);
$text = str_replace(" . ..", " .", $text);
$text = str_replace(".. . ", ". ", $text);
$text = str_replace(" . . ", " ", $text);
$text = str_replace(" . ", " ", $text);
$text = str_replace("...", "..", $text);
$text = str_replace("   ", " ", $text);
$text = str_replace("  ", " ", $text);
$text = str_replace('??', "", $text);
$text = str_replace('**', "", $text);
$text = str_replace('* *', "", $text);
$text = str_replace('? ?', "", $text);
//[:punct:]
$text = str_replace("\\", "", $text);
// replace filtered words with
$badwords = array("gmg", "tpt", "gjg", "www", "gwg", "pdp", "kmk", "wvw", "gaga", "tjt", "mjm", "wpw", "@@", "momo", "mwm", "mvm", "gmg");
$replacements = array("");

for ($i = 0; $i < sizeof($badwords); $i++) {
srand((double)microtime() * 1000000);

$rand_key = (rand() % sizeof($replacements));

$str = eregi_replace($badwords[$i], $replacements[$rand_key], $str);
}

return $str;
}



function ReplaceTextToSmilies($str)
{
$dir = "smilies/";
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
$smilie_count = 0;
while (($file = readdir($dh)) !== false) {
$smilie = explode(".", $file);

if ($file != '.' && $file != '..') {
if (preg_match("/\." . $smilie[0] . "\./i", $str))
$smilie_count++;
if ($smilie_count < 4) {
$str = preg_replace('(\.' . $smilie[0] . '\.)', '<img src="' . $dir . $file . '" alt="' . $smilie[0] . '" />', $str, 1);
//  $str = str_replace('.'.$smilie[0].'. .'.$smilie[0].'.', '', $str);
//$str = str_replace('.'.$smilie[0].'.', '<img src="'.$dir.$file.'" alt="'.$smilie[0].'" />', $str);
} elseif ($smilie_count > 3)
break;
}
}
closedir($dh);
}
}
return $str;
}




function replace($text)
{
$text = trim($text);
$text = strip_tags($text);
$text = stripslashes($text);
$text = preg_replace("(\r\n|\n|\r)", "", $text);
$text = str_replace('(www)', '', $text);
$text = preg_replace('/[^[:space:][:alnum:]\@\.\:\,\-\+\!\?\'\_\"\(\)\]\[\=\}\{\%\*\~\#\<\>\^]/', '', $text);
$text = str_replace("\$", "*", $text);
return $text;
}

function nick_replace($text)
{
$text = trim($text);
$text = str_replace(" ", "_", $text);
$text = str_replace("__", "_", $text);
$text = str_replace("--", "-", $text);
$text = preg_replace("(\r\n|\n|\r)", "", $text);
$text = preg_replace('/[^[:alnum:]\_\@\-\^]/', '', $text);
return $text;
}

function color_check($color)
{
if (!preg_match('/(000000|ff0000|00ffff|808080|ff8040|804000|00ff00|ffff00|ff00ff|408080|008000|800000|0000a0)/i', $color))
return '009b00';
else
return $color;
}
//////////////////DECODE URLS/////////


function xoft_encode($plain_data, $config_keypass)
{
$key_length = 0;
$all_bin_chars = "";
$cipher_data = "";
for ($i = 0; $i < strlen($plain_data); $i++) {
$p = substr($plain_data, $i, 1);
$k = substr($config_keypass, $key_length, 1);
$key_length++;
if ($key_length >= strlen($config_keypass)) {
$key_length = 0;
}
$dec_chars = ord($p) ^ ord($k);
$dec_chars = $dec_chars + strlen($config_keypass);
$bin_chars = decbin($dec_chars);
while (strlen($bin_chars) < 8) {
$bin_chars = "0" . $bin_chars;
}
$all_bin_chars = $all_bin_chars . $bin_chars;
}
$m = 0;
for ($j = 0; $j < strlen($all_bin_chars); $j = $j + 4) {
$four_bit = substr($all_bin_chars, $j, 4);
$four_bit_dec = bindec($four_bit);
$decimal_value = $four_bit_dec * 4 + $m;
$base64_value = dec_to_base64($decimal_value);
$cipher_data = $cipher_data . $base64_value;
$m++;
if ($m > 3) {
$m = 0;
}
}
return $cipher_data;
}
///////////////////////////////////////////////
function xoft_decode($cipher_data, $config_keypass)
{
$m = 0;
$all_bin_chars = "";
for ($i = 0; $i < strlen($cipher_data); $i++) {
$c = substr($cipher_data, $i, 1);
$decimal_value = base64_to_dec($c);
$decimal_value = ($decimal_value - $m) / 4;
$four_bit = decbin($decimal_value);
while (strlen($four_bit) < 4) {
$four_bit = "0" . $four_bit;
}
$all_bin_chars = $all_bin_chars . $four_bit;
$m++;
if ($m > 3) {
$m = 0;
}
}
$key_length = 0;
$plain_data = "";
for ($j = 0; $j < strlen($all_bin_chars); $j = $j + 8) {
$c = substr($all_bin_chars, $j, 8);
$k = substr($config_keypass, $key_length, 1);
$dec_chars = bindec($c);
$dec_chars = $dec_chars - strlen($config_keypass);
$c = chr($dec_chars);
$key_length++;
if ($key_length >= strlen($config_keypass)) {
$key_length = 0;
}
$dec_chars = ord($c) ^ ord($k);
$p = chr($dec_chars);
$plain_data = $plain_data . $p;
}
return $plain_data;
}
/////////////////////////////////////
function base64_to_dec($str)
{
$str = strtr($str, array("=" => "64", "/" => "63", "+" => "62", "9" => "61", "8" => "60", "7" => "59", "6" => "58", "5" => "57", "4" => "56", "3" => "55", "2" => "54", "1" => "53", "0" => "52", "z" => "51", "y" => "50", "x" => "49", "w" => "48", "v" => "47", "u" => "46", "t" => "45", "s" => "44", "r" => "43", "q" => "42", "p" => "41", "o" => "40", "n" => "39", "m" => "38", "l" => "37", "k" => "36", "j" => "35", "i" => "34", "h" => "33", "g" => "32", "f" => "31", "e" => "30", "d" => "29", "c" => "28", "b" => "27", "a" => "26", "Z" => "25", "Y" => "24", "X" => "23", "W" => "22", "V" => "21", "U" => "20", "T" => "19", "S" => "18", "R" => "17", "Q" => "16", "P" => "15", "O" => "14", "N" => "13", "M" => "12", "L" => "11", "K" => "10", "J" => "9", "I" => "8", "H" => "7", "G" => "6", "F" => "5", "E" => "4", "D" => "3", "C" => "2", "B" => "1", "A" => "0"));
return $str;
}
/////////////////////////////////////
function dec_to_base64($str)
{
$str = strtr($str, array("64" => "=", "63" => "/", "62" => "+", "61" => "9", "60" => "8", "59" => "7", "58" => "6", "57" => "5", "56" => "4", "55" => "3", "54" => "2", "53" => "1", "52" => "0", "51" => "z", "50" => "y", "49" => "x", "48" => "w", "47" => "v", "46" => "u", "45" => "t", "44" => "s", "43" => "r", "42" => "q", "41" => "p", "40" => "o", "39" => "n", "38" => "m", "37" => "l", "36" => "k", "35" => "j", "34" => "i", "33" => "h", "32" => "g", "31" => "f", "30" => "e", "29" => "d", "28" => "c", "27" => "b", "26" => "a", "25" => "Z", "24" => "Y", "23" => "X", "22" => "W", "21" => "V", "20" => "U", "19" => "T", "18" => "S", "17" => "R", "16" => "Q", "15" => "P", "14" => "O", "13" => "N", "12" => "M", "11" => "L", "10" => "K", "9" => "J", "8" => "I", "7" => "H", "6" => "G", "5" => "F", "4" => "E", "3" => "D", "2" => "C", "1" => "B", "0" => "A"));
return $str;
}

///////////////////////////////////////////////////////////////////////////

// END OF SCRIPT ENJOY!

///////////////////////////////////////////////////////////////////////////
?>
