View file chat_polifonia/ichat.php

File size: 16.8Kb
<?
//list($msec,$sec)=explode(chr(32),microtime());$HeadTime=$sec+$msec;

header('Cache-Control: no-store, no-cache, must-revalidate');	// HTTP/1.1
header ("Content-type:text/vnd.wap.wml; charset=utf-8");
$ref=rand(10000,1000000);
require("inc.php"); 

function getmicrotime()	//Микровремя
{ 
	list($usec, $sec) = explode(" ", microtime());
	return ((float)$usec + (float)$sec); 
}

$link = @mysql_pconnect ($MySQL_Hostname, $MySQL_Username, $MySQL_Password)
					 or die ("<wml><card id=\"error\" title=\"error\">
<do type=\"prev\" label=\"Back\"><prev/></do><p align=\"center\"><small>Can not connect to MySQL</small></p>
</card></wml>");

	@mysql_select_db($MySQLDatabasename) or die ("<wml><card id=\"error\" title=\"error\">
<do type=\"prev\" label=\"Back\"><prev/></do><p align=\"center\"><small>error select the database...</small></p>
</card></wml>");

		$result = @mysql_query ("Select pass,user,posts,avr,max,level,ignor,kik,whokik,whykik,user_ip,user_soft,inv,translit,smiles,safe,credits,fsize from users where id='".$id."' LIMIT 1;");

			if (mysql_affected_rows() == 0) {
			echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.2//EN\" \"http://www.wapforum.org/DTD/wml12.dtd\">";
echo "<wml>";
echo "<card id=\"error\" title=\"&#x041E;&#x0448;&#x0438;&#x0431;&#x043A;&#x0430;\" ontimer=\"index.php?ref=$ref\"><timer value=\"15\"/>";
echo "<p align=\"center\"><small>";
echo "&#x042E;&#x0437;&#x0435;&#x0440; &#x043D;&#x0435; &#x043D;&#x0430;&#x0439;&#x0434;&#x0435;&#x043D;!";
echo "</small></p></card></wml>";
mysql_close($link);
exit;
}

$row = mysql_fetch_array ($result);
if ($ps !== $row["pass"]){
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.2//EN\" \"http://www.wapforum.org/DTD/wml12.dtd\">";
echo "<wml>";
echo "<card id=\"error\" title=\"&#x041E;&#x0448;&#x0438;&#x0431;&#x043A;&#x0430;\" ontimer=\"index.php?ref=$ref\"><timer value=\"15\"/>";
echo "<p align=\"center\"><small>";
echo "&#x041D;&#x0435; &#x0432;&#x0435;&#x0440;&#x043D;&#x043E;&#x0435; &#x0441;&#x043E;&#x0447;&#x0435;&#x0442;&#x0430;&#x043D;&#x0438;&#x0435; &#x043D;&#x0438;&#x043A;&#x0430; &#x0438; &#x043F;&#x0430;&#x0440;&#x043E;&#x043B;&#x044F;!";
echo "</small></p></card></wml>";
mysql_close($link);
exit;
}
$us=$row["user"];
$max = $row["max"];
$smset = $row["smiles"];
if ($rm<0||$rm>9||!isset($rm)) exit;

//Предупреждение о безопасности
$agent = $HTTP_USER_AGENT;
$addr = $REMOTE_ADDR;
if(($row["user_soft"]!==$agent||$row["user_ip"]!==$addr)&&$row["safe"]==1)
{
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.2//EN\" \"http://www.wapforum.org/DTD/wml12.dtd\">";
echo "<wml>";
echo "<card id=\"warning\" title=\"&#x412;&#x43D;&#x438;&#x43C;&#x430;&#x43D;&#x438;&#x435;!\">";
echo "<p align=\"center\"><small>";
echo "<a href=\"ichat.php?id=$id&amp;ps=$ps&amp;pwd=$pwd&amp;ref=$ref\">Продолжить</a><br/>";
echo "<b>Предупреждение о безопасности</b><br/>"; 
$us_ip = $row["user_ip"];
$us_soft = $row["user_soft"];
mysql_query ("Update users set user_soft='".$agent."', user_ip = '".$addr."' WHERE id = '".$id."';");
echo "Внимание! Ваш текущий софт или ip адрес не совпадают с ip+soft последнего захода. Если вы не использовали в последнее время ip $us_ip или софт $us_soft, это может означать, что кто-то заходит с Вашего ника. Рекомендуем сменить ваш пароль. Отключить систему безопасности можно в настройках чата, но это не рекомендуется.";
echo "<br/><a href=\"ichat.php?id=$id&amp;ps=$ps&amp;pwd=$pwd&amp;ref=$ref\">Продолжить</a><br/>";

echo "</small></p></card></wml>";
exit;
}
else
 if ($row["user_soft"]!==$agent||$row["user_ip"]!==$addr) mysql_query ("Update users set user_soft='".$agent."', user_ip = '".$addr."' WHERE id = '".$id."';");

//Бан по ip-soft
mysql_query ("Select `klu4` from bannlist WHERE (ip = '".$addr."')and(soft = '".$agent."') LIMIT 1;");
if (mysql_affected_rows()!=0)
{
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.2//EN\" \"http://www.wapforum.org/DTD/wml12.dtd\">";
echo "<wml>";
echo "<head><meta http-equiv=\"Cache-Control\" content=\"no-cache\" forua=\"true\"/></head>";
echo "<card id=\"ban\" title=\"Стоп!\" ontimer=\"index.php?ref=$ref\"><timer value=\"300\"/>";
echo "<p align=\"center\"><small>";
echo "Вы забанены по связке ip+soft!!!<br/>";
echo "Р? доступ вам разрешен только РІ  <a href=\"chat.php?id=$id&amp;ps=$ps&amp;rm=9&amp;rul=9&amp;ref=$ref\">Сортир</a>";
echo "</small></p></card></wml>";
mysql_close($link);
exit;
}
//End ip-soft

//Пинок
if((time()<$row["kik"])||(time()<$row["kik"]&&$row["whokik"]=="[Система]"))
{
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.2//EN\" \"http://www.wapforum.org/DTD/wml12.dtd\">";
echo "<wml>";
echo "<head><meta http-equiv=\"Cache-Control\" content=\"no-cache\" forua=\"true\"/></head>";
echo "<card id=\"vypnut\" title=\"Стоп!\" ontimer=\"index.php?ref=$ref\"><timer value=\"300\"/>";
echo "<p align=\"center\"><small>";
$tleft = $row["kik"] - time();
$whokik = $row["whokik"];
$whykik = $row["whykik"];
echo "$whokik выпнул вас из чата. Разбан через $tleft (сек)<br/>";
echo "Причина: $whykik<br/>";
//echo "А пока вам разрешен доступ только в <a href=\"chat.php?id=$id&amp;ps=$ps&amp;rm=9&amp;rul=9&amp;ref=$ref\">Сортир</a>";
echo "</small></p></card></wml>";
mysql_close($link);
exit;
}
//End пинок

function trun_to_rus($str)
{
$str=str_replace("ch","С‡",$str);
$str=str_replace("sc","С‰",$str); 
$str=str_replace("ye","СЌ",$str);
$str=str_replace("yu","СЋ",$str);
$str=str_replace("ya","СЏ",$str);
$str=str_replace("CH","Р§",$str);
$str=str_replace("SC","Р©",$str); 
$str=str_replace("\"\"","РЄ",$str);
$str=str_replace("\"","СЉ",$str);
$str=str_replace("''","Р¬",$str);
$str=str_replace("'","СЊ",$str);
$str=str_replace("YE","Р­",$str);
$str=str_replace("YU","Р®",$str);
$str=str_replace("YA","РЇ",$str);
$str=strtr($str,array("a"=>"Р°","b"=>"Р±","v"=>"РІ","g"=>"Рі","d"=>"Рґ","e"=>"Рµ","j"=>"Р¶","z"=>"Р·","i"=>"Рё","y"=>"Р№","k"=>"Рє","l"=>"Р»","m"=>"Рј","n"=>"РЅ","o"=>"Рѕ","p"=>"Рї","r"=>"СЂ","s"=>"СЃ","t"=>"С‚","u"=>"Сѓ","f"=>"С„","h"=>"С…","c"=>"С†","w"=>"С€","x"=>"С‹","A"=>"Рђ","B"=>"Р‘","V"=>"Р’","G"=>"Р“","D"=>"Р”","E"=>"Р•","J"=>"Р–","Z"=>"Р—","I"=>"Р?","Y"=>"Р™","K"=>"Рљ","L"=>"Р›","M"=>"Рњ","N"=>"Рќ","O"=>"Рћ","P"=>"Рџ","R"=>"Р ","S"=>"РЎ","T"=>"Рў","U"=>"РЈ","F"=>"Р¤","H"=>"РҐ","C"=>"Р¦","W"=>"РЁ","X"=>"Р«"));
return $str;
}

//Автоматическая оптимизация и чистка
$optim=0;
$f=fopen("syst/optim.dat","a+");
flock($f,LOCK_EX);
$optimdata=file("syst/optim.dat");
if ($optimdata[0]<time()){ 
ftruncate($f,0);
$optimdata = time() + 3600;
fwrite($f,$optimdata);
fflush($f);
$optim=1;
}
flock($f,LOCK_UN);
fclose($f);
if($optim==1){
for ($num = 0; $num <= 10; $num++)
{
$roptim = "room".$num;
$dt = time() - 3600;
mysql_query ("Delete from $roptim where id<'".$dt."'");
mysql_query("OPTIMIZE TABLE $roptim");
}
}
//Конец чистки 


$smthwr = 0;
$bmax = $max*2;
$res = mysql_query ("Select time,who,message,messagewosm,messagewoasm,id,towhom,hid,usid from room10 WHERE (usid = '".$id."')OR(towhom = '".$id."')OR(towhom = '') order by id desc LIMIT $bmax");
$kol = mysql_affected_rows();

$lines = mysql_fetch_array ($res);

@$topic = $lines["message"];

if($rm==0){
$uid = "2";
$uus = "РЈРјРЅРёРє";
require("syst/umnik1.php");
}
if(@$msg)
{
$msg = trim(" $msg ");
$msg = ereg_replace(" +"," ",$msg);
$msg = substr($msg,0,400);
$msg = str_replace("", " ", $msg);
$msg = str_replace("$", "$$", $msg);
$msg = strtr($msg,array(chr("0")=>"",chr("1")=>"",chr("2")=>"",chr("3")=>"",chr("4")=>"",chr("5")=>"",chr("6")=>"",chr("7")=>"",chr("8")=>"",chr("9")=>"",chr("10")=>"",chr("11")=>"",chr("12")=>"",chr("13")=>"",chr("14")=>"",chr("15")=>"",chr("16")=>"",chr("17")=>"",chr("18")=>"",chr("19")=>"",chr("20")=>"",chr("21")=>"",chr("22")=>"",chr("23")=>"",chr("24")=>"",chr("25")=>"",chr("26")=>"",chr("27")=>"",chr("28")=>"",chr("29")=>"",chr("30")=>"",chr("31")=>""));
$msg = str_replace("к","С‘",$msg);
$msg = htmlspecialchars($msg); 
if (!isset($prvt)) $prvt = 0;

$str1="";
$str2=$msg;

if ($translit==1){
$r = mysql_query("select user from users WHERE id = '".$towhom."' LIMIT 1;");
$a = mysql_fetch_array($r);
if (strpos($msg,$a["user"])===0)
{
$str1 = substr($msg,0,strlen($a["user"]));
$str2 = substr($msg,strlen($a["user"]),strlen($msg)-strlen($a["user"])); 
$msg = $str2;
}
}
if ($prvt == 0) $towhom = "";
if (!isset($towhom)) $towhom = "";
require("syst/smile.php");

$minpos = 500; $nm = 500;
for ($j=0;$j<=count($smiles)-1;$j++)
{
$tmpp = strpos($msg,$smiles[$j]);
if (($tmpp < $minpos)&&($tmpp !== false))
{
$minpos = $tmpp; $nm = $j;
};
};
if ($minpos !=500)
{
if ($translit!=1)
{
$st1 = substr($msg,0,$minpos+strlen($smiles[$nm]));
$st2 = substr($msg,$minpos+strlen($smiles[$nm]),strlen($msg)-strlen($st1));
$st1_wosm = $st1;
$st1 = str_replace($smiles[$nm],$replaces[$nm],$st1);
if (strpos($replaces[$nm],"smilean/")!==false) $st1_woasm = $st1_wosm; else $st1_woasm = $st1;
$msg_woasm = $st1.$st2;
$msg_wosm = $st1_wosm.$st2;
$msg = $st1_woasm.$st2;
} else 
{
$st1 = substr($msg,0,$minpos);
$st2 = substr($msg,$minpos, strlen($smiles[$nm]));
$st3 = substr($msg,$minpos+strlen($smiles[$nm]),strlen($msg)-strlen($st1)-strlen($st2));
if ($room!="room0") $st1 = trun_to_rus($st1);
$st2_wosm = $st2;
$st2 = $replaces[$nm];
if (strpos($replaces[$nm],"smilean/")!==false) $st2_woasm = $st2_wosm; else $st2_woasm = $st2;
if ($room!="room0") $st3 = trun_to_rus($st3);
$msg = $st1.$st2_woasm.$st3;
$msg_wosm = $st1.$st2_wosm.$st3;
$msg_woasm = $st1.$st2.$st3;
}
}
else if ($translit==1) $msg = trun_to_rus($msg);
unset($smiles);
unset($replaces);
if($row["level"]>6)$msg = eregi_replace("((http://))((([a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z;]{2,3}))|(([0-9]{1,3}\.){3}([0-9]{1,3})))((/|\?)[a-z0-9~#%&'_\+=:;\?\.-]*)*)", "<a href=\"\\0\">\\3</a>", $msg);



$msg = $str1.$msg;
if (@$msg_wosm!="") $msg_wosm = $str1.$msg_wosm;
if (@$msg_woasm!="") $msg_woasm = $str1.$msg_woasm;
        if(($row["level"]>=6)  && $bold)
            $msg = '<b>'.$msg.'</b>';

        if (($row["level"]>=4) && $underline)
            $msg = '<u>'.$msg.'</u>';
//Антифлуд
$r = mysql_query("SELECT message FROM room10 WHERE usid = '".$id."' order by id desc LIMIT 1");
$a = mysql_fetch_array($r);
if ($a["message"] !== $msg)
{
//Автоантифлуд
$time = getmicrotime();
$ftime = $time - 30;
$r = mysql_query("SELECT count(*) as sum from room10 WHERE (usid = '".$id."')and(id > '".$ftime."')");
$a = mysql_fetch_array($r);
$sum = $a["sum"];	 
if ($sum>=5&&$row["level"]<4)
{
$ftime = $time + 60;
mysql_query("update users set kik = '".$ftime."', whykik = 'флуд', whokik = '[Система]' WHERE id = '".$id."'");
}

$today=date ("H:i");
$posts =  $row["posts"];
$posts++;
mysql_query ("Update users set posts='".$posts."', onl='".$time."' where id ='".$id."'");
$hid = $row["inv"];
$kol++;
$rnd = rand(0,99999999);

@mysql_query ("Insert into room10 set klu4= '".$rnd."', time='".$today."', who='".$us."', message='".$msg."', messagewosm = '".$msg_wosm."', messagewoasm = '".$msg_woasm."', id='".$time."', towhom='".$towhom."', hid='".$hid."', usid='".$id."'");
$usmes["time"] = $today;
$usmes["who"] = $us;
$usmes["usid"] = $id;
$usmes["message"] = stripslashes($msg);
@$usmes["messagewosm"] = stripslashes($msg_wosm);
@$usmes["messagewoasm"] = stripslashes($msg_woasm);
$usmes["id"] = $time;
$usmes["towhom"] = $towhom;
$smthwr = 1;

}
}

if($row['fsize'] == "small") { $fsize1 = "<small>"; $fsize2 = "</small>"; }
elseif($row['fsize'] == "big") { $fsize1 = "<big>"; $fsize2 = "</big>"; }
else { $fsize1 = ""; $fsize2 = ""; }

$avr = $row["avr"];
$time=date ("H:i");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.2//EN\" \"http://www.wapforum.org/DTD/wml12.dtd\">";
echo "<wml>";
if ($avr!==0) echo "<card id=\"chat\" title=\"&#x418;&#x43D;&#x442;&#x438;&#x43C;-$time\" ontimer=\"ichat.php?id=$id&amp;ps=$ps&amp;pwd=$pwd&amp;ref=$ref\"><timer value=\"$avr\"/>";
else echo "<card id=\"chat\" title=\"&#x418;&#x43D;&#x442;&#x438;&#x43C;-$time\" >";
echo "<do type=\"options\" name=\"refresh\" label=\"Обновить\"><go href=\"ichat.php?id=$id&amp;pwd=$pwd&amp;rm=$rm&amp;ref=$ref\"/></do>";
echo "<do type=\"options\" name=\"add\" label=\"Сказать\"><go href=\"#add\"/></do>";

$r = mysql_query ("select count(readd) as num from zapiski WHERE (idtowhom = '".$id."')and(readd = '0')and(ininc = '1')");
$a = mysql_fetch_array($r);
$inb = $a["num"]; 
echo "<do type=\"options\" name=\"mes\" label=\"Записки($inb)\"><go href=\"chatmail.php?id=$id&amp;ps=$ps&amp;ref=$ref\"/></do>";
echo "<do type=\"options\" name=\"who\" label=\"Кто где?\"><go href=\"who.php?id=$id&amp;ps=$ps&amp;ref=$ref\"/></do>";
echo "<p>";
echo $fsize1;
echo "<a href=\"#add\">Сказать</a><br/>";
echo "<a href=\"chat.php?id=$id&amp;ps=$ps&amp;rm=$rm&amp;ref=$ref\">Обновить</a>";

 @$total=$kol-1;
$ignor = $row["ignor"];
$mread = 0;

if ($smthwr != 0)
{
 $date = $usmes["time"];
 $name = $usmes["who"];
 $usid = $usmes["usid"];
 $msg = $usmes["message"];
 if ($smset==0&&$usmes["messagewosm"]!="") $msg = $usmes["messagewosm"];
 if ($smset==2&&$usmes["messagewoasm"]!="") $msg = $usmes["messagewoasm"];
 $time = $usmes["id"];
 $th = $usmes["towhom"];
 if (strpos($ignor, $name."|") === false)
 {
  if ($th == "")
  {
   $msg = str_replace($us.",", "<u>".$us."</u>,", $msg);
   echo "<br/><b><a href=\"inside.php?id=$id&amp;ps=$ps&amp;rm=$rm&amp;nk=$usid&amp;ref=$ref\">$name</a></b>($date)&gt;<br/>$msg"; $mread++;
  }
  else if (($th == $id)||($id == $usid))
  {
   $msg = str_replace($us.",", "<u>".$us."</u>,", $msg);
   echo "<br/><b><a href=\"inside.php?id=$id&amp;ps=$ps&amp;rm=$rm&amp;nk=$usid&amp;ref=$ref\">$name</a>[P!]</b>($date)&gt;<br/>$msg"; $mread++;
  }
 }
}

while ($mread < $max)
{
$lines = mysql_fetch_array ($res);
if($lines===false)break;
$date = $lines["time"];
$name = $lines["who"];
$usid = $lines["usid"];
$msg = $lines["message"];
if ($smset==0&&$lines["messagewosm"]!="") $msg = $lines["messagewosm"];
if ($smset==2&&$lines["messagewoasm"]!="") $msg = $lines["messagewoasm"];

$time = $lines["id"];
$th = $lines["towhom"];
$hid = $lines["hid"];
if ((strpos($ignor, $name."|") === false)&&(($hid != 2)||($id == $usid)))
{
if ($th == "")
{
 $msg = str_replace($us.",", "<u>".$us."</u>,", $msg);
 echo "<br/><b><a href=\"inside.php?id=$id&amp;ps=$ps&amp;rm=$rm&amp;nk=$usid&amp;ref=$ref\">$name</a></b>($date)&gt;<br/>$msg";$mread++;
} else
{
if (($th == $id)||($id == $usid))
{
 $msg = str_replace($us.",", "<u>".$us."</u>,", $msg);
 echo "<br/><b><a href=\"inside.php?id=$id&amp;ps=$ps&amp;rm=$rm&amp;nk=$usid&amp;ref=$ref\">$name</a>[P!]</b>($date)&gt;<br/>$msg";$mread++;
}
}
}
}
mysql_close ($link);
$page_next = $max;
echo "<br/>---";
if ($max < $total)
{
echo "<br/><a href=\"history.php?id=$id&amp;ps=$ps&amp;rm=$rm&amp;num=$page_next\">Р?стория</a>";
}
echo "<br/><a href=\"enter.php?id=$id&amp;ps=$ps&amp;ref=$ref\">&#x41F;&#x440;&#x438;&#x445;&#x43E;&#x436;&#x430;&#x44F;</a>";

//list($msec,$sec)=explode(chr(32),microtime());echo "<br/>[".round(($sec+$msec)-$HeadTime,4)." sec]";

echo $fsize2;
echo "</p></card>";
echo "<card id=\"add\" title=\"Сказать\">";
echo "<p>";
echo "<input name=\"msg$ref\" maxlength=\"200\" title=\"Text\"/><br/>";
if (($row["translit"]==1)&&($room!="room0")){
echo "<select multiple=\"true\" name=\"translit\">\n";
echo "<option value=\"1\">Translit</option></select><br/>\n";
}
if ($row["level"]>=6) {
echo '<select multiple="true" name="bold"><option value="1">Жирный</option></select><br/>';
}
if ($row["level"]>=4) {
echo '<select multiple="true" name="underline"><option value="1">Подчеркнутый</option></select><br/>';
}
echo "<anchor title=\"send\">Сказать<go href=\"chat.php?id=$id&amp;ps=$ps&amp;rm=$rm&amp;ref=$ref\" method=\"post\">";
echo "<postfield name=\"msg\" value=\"$(msg$ref)\"/>";
echo "<postfield name=\"bold\" value=\"$(bold)\"/>\n";
echo "<postfield name=\"underline\" value=\"$(underline)\"/>\n";
echo "<postfield name=\"translit\" value=\"$(translit)\"/>\n";
echo "</go></anchor><br/>";
echo "<a href=\"chat.php?id=$id&amp;ps=$ps&amp;rm=$rm&amp;ref=$ref\">В чат</a>";
echo "</p></card>";
echo "</wml>";

?>