View file room.php

File size: 11.06Kb
<?php
$urls='room.php';
//ERROR REPORTING LEVEL
error_reporting(0);
$ttl='| Комната';
//CONNECTION (MySQL)
include("config.php");
//IS USER BANNED?
include("./includes/".$ver."/banned");

//GET BOTS NAMES
$bots = file("bots/bots.dat");
$bots[0] = trim($bots[0]);
$bots[1] = trim($bots[1]);
$bots[2] = trim($bots[2]);
$bots[3] = trim($bots[3]); //SYSTEM

//CONFIGS
$configs = file("configs.dat");
$adv = $configs[1];
$computer = $configs[2];

//INTERVALS
$intervals = file("bots/intervals.dat");
$intervals[0] = intval($intervals[0]);
$intervals[1] = intval($intervals[1]);
$intervals[2] = intval($intervals[2]);

//VARIABLE FOR NO-CACHE PROTECTION
$nocache = rand(0, 999999999);

list($msec, $sec) = explode(chr(32), microtime()); 
$headtime = $sec + $msec;


//AUTH
include("./template/all.php");
$q = mysql_query("SELECT * FROM `chat_users` WHERE `id` = '".$id."' AND `password` = '".$password."';");

if(mysql_affected_rows() == 0)
{
header ("Content-type: text/html; charset=utf-8");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-cache, must-relative");
include("./template/head.php");
include("./reginc.php");
include("./template/foot.php");
exit();
}
else
{
$user = mysql_fetch_array($q);
$nickname = $user['nickname'];
$smiles = $user['smiles'];
$translit  = $user['translit'];
$msgs  = $user['msgs'];
$refresh = $user['refresh'];
$fsize = $user['fsize'];
$security  = $user['security'];
$level = $user['level'];
$kick = $user['kick'];
$moder = $user['moder'];
$reason = $user['reason'];
}
//END AUTH
header ("Content-type: text/html; charset=utf-8");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-cache, must-relative");
include("./template/room_head.php");

if(((strpos($ua, "Opera") !== false) or (strpos($ua, "Mozilla") !== false) or (strpos($ua, "MSIE") !== false)  or (strpos($ua, "Netscape") !== false)) && $computer == 1 && $level == 0)
{
echo'</div>';
echo "Доступ с компьютера запрещен.<br/>\n";
include("./template/foot.php");
exit();
}

$rid = intval($_GET['rid']);

$sql = mysql_query("SELECT `topic`, `type` FROM `chat_rooms` WHERE `id` = '".$rid."';");

if(mysql_num_rows($sql) == 0)
{
echo'</div>';
echo "Такой комнаты не существует.<br/>\n";
include("./template/foot.php");
exit();
}
else
{
$topic = mysql_result($sql, 0, 'topic');
$type = mysql_result($sql, 0, 'type');
}

if($level == 0 && $type == 1)
{
echo'</div>';
echo "Доступ запрещен.<br/>\n";
include("./template/foot.php");
exit();
}

if($kick > time() && ($rid != $wicked_quiz && $rid != $unlim))
{
echo'</div>';
echo "Вы временно заблокированы модератором <u>$moder</u> на <u>".($kick - time())."</u> сек.<br/>\n";
echo "Причина: $reason<br/>\n";
include("./template/foot.php");
exit();
}

//ONLINE
$online = time() + 90;
$update = mysql_query("UPDATE `chat_users` SET `time` = '".$online."', `place` = '".$rid."', `ip` = '".getenv('REMOTE_ADDR')."', `ua` = '".htmlspecialchars(getenv('HTTP_USER_AGENT'))."' WHERE `id` = '".$id."';");
//END ONLINE

if($fsize == 0)
{
$fsize = "small";
}
if($fsize == 1)
{
$fsize = "normal";
}
if($fsize == 2)
{
$fsize = "large";
}

if ($botson==1)
{
include "bots/joker.php";

if($rid == 1)
{
include "bots/bot.php";
mysql_query("UPDATE `chat_users` SET `time` = '".$online."', `place` = 1 WHERE `id` = 2;");
}

if($rid == 3)
{
include "bots/boor.php";
include "bots/second_bot.php";
mysql_query("UPDATE `chat_users` SET `time` = '".$online."', `place` = 3 WHERE `id` = 4;");
}
}
echo "<a class=\"h\" accesskey=\"1\" href=\"add.php?rid=$rid&amp;nocache=$nocache\">[1]сказать</a> | \n";
echo "<a class=\"h\" accesskey=\"2\" href=\"room.php?rid=$rid&amp;nocache=$nocache\">[2]обновить</a>\n";
//echo "<a class=\"h\" href=\"online.php?id=$id&amp;password=$password&amp;ver=html&amp;nocache=$nocache\">Кто где?</a>\n";
echo'</div>';
if(isset($_POST['msg']))
{
mysql_query("SELECT * FROM `chat".$rid."` WHERE `aid` = '".$id."' AND `seconds` > ".(time() - 20).";");
if(mysql_affected_rows() > 3)
{
$reason = "Вы были автоматически забанены системой за флуд (многократное повторение сообщений).";
mysql_query("UPDATE `chat_users` SET `kick` = ".(time() + 180).", `moder` = '".$bots[3]."', `reason` = '".$reason."' WHERE `id` = '".$id."';");
}

$msg = trim($_POST['msg']);

if(isset($_POST['uid']))
{
$sql = mysql_query("SELECT `nickname` FROM `chat_users` WHERE `id` = ".intval($_POST['uid']).";");
$nick = mysql_result($sql, 0);
}
else
{
$nick = "";
}

$msg = stripslashes($msg);

$msg = stripslashes($msg);

	if($_POST['translit'] == "true")
	{
	$msg = str_replace("\"\"", "Ъ", $msg);
	$msg = str_replace("\"", "ъ", $msg);
	$msg = str_replace("''", "Ь", $msg);
	$msg = str_replace("'", "ь", $msg);

	$lat = array("CH", "ch", "SC", "sc", "YE", "ye", "YU", "yu", "YA", "ya", "YO", "yo");
	$rus = array("Ч", "ч", "Щ", "щ", "Э", "э", "Ю", "ю", "Я", "я", "Ё", "ё");
	$msg = str_replace($lat, $rus, $msg);

	$lat = array("A", "a", "B", "b", "C", "c", "D", "d", "E", "e", "F", "f", "G", "g", "H", "h", "I", "i", "J", "j", "K", "k", "L", "l", "M", "m", "N", "n", "O", "o", "P", "p", "R", "r", "S", "s", "T", "t", "U", "u", "V", "v", "H", "h", "Z", "z", "W", "w", "X", "x", "Y", "y");
	$rus = array("А", "а", "Б", "б", "Ц", "ц", "Д", "д", "Е", "е", "Ф", "ф", "Г", "г", "Х", "х", "И", "и", "Ж", "ж", "К", "к", "Л", "л", "М", "м", "Н", "н", "О", "о", "П", "п", "Р", "р", "С", "с", "Т", "т", "У", "у", "В", "в", "Х", "х", "З", "з", "Ш", "ш", "Ы", "ы", "Й", "й");
	$msg = str_replace($lat, $rus, $msg);
	}

$msg = htmlspecialchars($msg);

$msg = str_replace("[color", '<font color', $msg);
$msg = str_replace("[/color]", '</font>', $msg);
$msg = str_replace("]", ' >', $msg);
$msg = "<font color=$options>".$msg."</font>";

//SMILES
include "smiles.php";
$msg = preg_replace($smiles_array, $smile, $msg, 2);

if(!empty($nick))
{
$msg = "$nick, $msg";
}

$msg = iconv('utf-8', 'windows-1251', $msg);
$msg = substr($msg, 0, 1000);
$msg = iconv('windows-1251', 'utf-8', $msg);
$msg = str_replace("$", "$$", $msg);

$emotions = intval($_POST['emotions']);

switch($emotions)
{
case 1:
$msg = "[Радостно] $msg";
break;

case 2:
$msg = "[Печально] $msg";
break;

case 3:
$msg = "[Удивленно] $msg";
break;

case 4:
$msg = "[Ласково] $msg";
break;

case 5:
$msg = "[Смущенно] $msg";
break;

case 6:
$msg = "[Кокетливо] $msg";
break;

case 7:
$msg = "[Обиженно] $msg";
break;

case 8:
$msg = "[Настойчиво] $msg";
break;

case 9:
$msg = "[Шепотом] $msg";
break;

case 10:
$msg = "[Задумчиво] $msg";
break;

case 11:
$msg = "[Злобно] $msg";
break;
}

	if($level > 0)
	{
	$attributs = $_POST['attributs'];
	$post_fsize = (int)$_POST['fsize'];

	if(substr_count($attributs, "underline") != 0) $msg = "<u>$msg</u>";

		if($level > 2)
		{
		if(substr_count($attributs, "bold") != 0) $msg = "<b>$msg</b>";
		}

		if($level == 4)
		{
		if(substr_count($attributs, "italic") != 0) $msg = "<i>$msg</i>";
		if($post_fsize == 0) $msg = "<small>$msg</small>";
		if($post_fsize == 2) $msg = "<big>$msg</big>";
		}
	}

if($adv == 0)
{
$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=\"out.php?url=\\0\">\\3</a>", $msg);
}
elseif($adv == 1 && $level < 4)
{
$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~#%&'_\+=:;\?\.-]*)*)", "*censored*", $msg);
}
else
{
$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=\"out.php?url=\\0\">\\3</a>", $msg);
}

if($level == 4) 
{
$msg = preg_replace("|\*\((.*)\)\*|isU", "<b>\\1</b>", $msg);
}

$msg = mysql_escape_string($msg);

$sql = mysql_query("SELECT `msg` FROM `chat".$rid."` WHERE `aid` = '".$id."' ORDER BY `id` DESC LIMIT 1;");
$last_msg = mysql_escape_string(mysql_result($sql, 0));

	if($last_msg != $msg && !empty($msg))
	{
	$to = (int)$_POST['to'];
	$sql = mysql_query("INSERT INTO `chat` VALUES(0, '".$id."', '".$nickname."', '".$msg."', '".$rid."', '".$to."', '".date("H:i:s")."',".time().");");
		if(mysql_insert_id() > 4000000000)
		{
		mysql_query("TRUNCATE TABLE `chat".$rid."`;");
		$message = "Комната была очищена системой. Данная операция была важна для снятия нагрузки с базы данных.";
		$sql = mysql_query("SELECT `id` FROM `chat_rooms`;");
			while($room_id = mysql_fetch_array($sql))
			{
			if ($botson==1)
			{
			mysql_query("INSERT INTO `chat".$rid."` VALUES(0, '5', '".$bots[3]."', '".$message."', '0', '".date("H:i:s")."',".time().");");
			}
      }
		}
		if(!$sql)
		{
		$sql = mysql_query("INSERT INTO `chat".$rid."` VALUES(0, '".$id."', '".$nickname."', '".$msg."', '".$to."', '".date("H:i:s")."', ".time().");");
		}
	mysql_query("UPDATE `chat_users` SET `posts` = `posts` + 1 WHERE `id` = '".$id."';");
	if ($botson==1)
	{
	if($rid == 1) include "bots/answer.php";
	if($rid == 3) include "bots/second_answer.php";
	}
	}
}

$sql = mysql_query("SELECT COUNT(*) FROM `chat".$rid."`;");
$all = mysql_result($sql, 0);

if(isset($_GET['s'])) $s = $_GET['s'];
else $s = 0;
if($s < 0) $s = 0;
if($s > $all) $s = 0;

$ignor = "";

$sql = mysql_query("SELECT * FROM `chat_ignor` WHERE `id` = '".$id."';");
while($ignor_arr = mysql_fetch_array($sql))
{
$ignor .= " `aid` != '".$ignor_arr['uid']."' AND ";
}

if($id != 1) $sql = mysql_query("SELECT * FROM `chat".$rid."` WHERE ".$ignor." (`to` = 0 OR `to` = '".$id."' OR `aid` = '".$id."') ORDER BY `id` DESC LIMIT $s, $msgs;");
else $sql = mysql_query("SELECT * FROM `chat".$rid."` WHERE ".$ignor." `aid` != 0 ORDER BY `id` DESC LIMIT $s, $msgs;");

$c = 0;

while($post = mysql_fetch_array($sql))
{
if($c == 0)
{
$div = "<div class=\"form\">\n";
$close = "</div>\n";
$c = 1;
}
else
{
$div = "";
$close = "";
$c = 0;
}
echo $div;
if($post['to'] != 0) echo "<b>[P!]</b>";
echo "<a href=\"addto.php?rid=$rid&amp;nocache=$nocache&amp;uid=".$post['aid']."\">".$post['nickname']."</a>>\n";
$post['msg'] = str_replace('$$', '$', $post['msg']);
$post['msg'] = stripslashes($post['msg']);
if($smiles == 0) $post['msg'] = preg_replace("|<img[^>]+>|isU", "*smile*", $post['msg']); 
echo $post['msg']." (".$post['time'].")<br/>\n";
echo $close;
}

echo '</div><div style="background-color: #d0d0d0">';
if ($all > $s + $msgs)  print "<a href=\"room.php?rid=$rid&amp;nocache=$nocache&amp;s=".($s + $msgs)."\">&gt;&gt;&gt;</a><br/>\n";
if ($s > 0)  print "<a href=\"room.php?rid=$rid&amp;nocache=$nocache&amp;s=".($s - $msgs)."\">&lt;&lt;&lt;</a><br/>\n";

echo "</div><div class=\"h\">";
echo "<a class=\"h\" accesskey=\"3\" href=\"index.php\">[3]комнаты</a> | \n";
echo "<a class=\"h\" accesskey=\"4\" href=\"online.php?nocache=$nocache\">[4]онлайн</a><br/>\n";
echo "<a class=\"h\" href=\"mood.php?nocache=$nocache\">настроение</a>\n";
echo "</div><div>";
include("./template/room_foot.php");
break;
?>