Файл: monst/chat.php
Строк: 153
<?php
$start_time = microtime();
$start_array = explode(" ", $start_time);
$start_time = $start_array[1] + $start_array[0];
$headmod = 'chat';
include('files/db.php');
include('files/auth.php');
$tpl->assign('TITLE', 'Чат');
include('files/zag.php');
switch ($_GET['mod']) {
default:
if ($_GET['note'] == 'add')
$tpl->assign('ERROR', 'Сообщение добавлено!');
if ($_GET['note'] == 'ban')
$tpl->assign('ERROR', 'Вы в бане!');
if ($_GET['note'] == 'double')
$tpl->assign('ERROR', 'Не нужно флудить!');
if ($_GET['note'] == 'limit')
$tpl->assign('ERROR', 'Нельзя писать более 5 сообщений в минуту!');
if ($_GET['note'] == 'ROLLlimit')
$tpl->assign('ERROR', 'Нельзя так часто бросать кубики!');
$tpl->assign('rand', mt_rand(111, 999));
$tpl->assign('nick', isset($_GET['nick']) ? clean($_GET['nick']) . ', ' : '');
$tpl->assign('smile', isset($_GET['smile']) ? clean($_GET['smile']) . '' : '');
$tpl->assign('smiley', isset($_GET['smiley']) ? clean($_GET['smiley']) . '' : '');
$tpl->assign('ismoder', ismoder());
$count = result(q("SELECT count(*) FROM `chat` WHERE `p` = 0 OR (`p` = 1 AND (`to` = '" . $udata['usr'] . "' OR `nick` = '" . $udata['usr'] . "'));"));
$allpage = ceil($count / $onpage);
if ($allpage > 20)
$allpage = 20;
if ($page > $allpage)
$page = $allpage;
$start = ($page - 1) * $onpage;
$q = q("SELECT users.vip, users.vipIco, users.selectedTit, users.nickCol, chat.* FROM `chat` LEFT JOIN users ON users.id = chat.uid WHERE chat.p = 0 OR (chat.p = 1 AND (chat.to = '" . $udata['usr'] . "' OR chat.nick = '" . $udata['usr'] . "')) ORDER BY chat.time DESC LIMIT $start, $onpage");
$data = array();
if (@num_rows($q)) {
while ($row = assoc($q)) {
$info = assoc(q("SELECT `sex`, `name`, `age` FROM `anks` WHERE `uid` = '" . $row['uid'] . "';"));
$row['sex'] = $info['sex'];
$row['name'] = $info['name'];
$row['age'] = $info['age'];
$row['komentaras'] = str_replace($udata['usr'] . ',', $udata['usr'] . ',', $row['komentaras']);
if (eregi($udata['usr'] . ',', $row['komentaras'])) {
if ($row['p']) {
$row['komentaras'] = str_replace($udata['usr'] . ',', '<b>' . nickName($udata['usr']) . '</b>, <span style="color: red;">', $row['komentaras']);
} else {
$row['komentaras'] = str_replace($udata['usr'] . ',', '<b>' . nickName($udata['usr']) . '</b>, <span style="color: lightgreen;">', $row['komentaras']);
}
$row['komentaras'] .= '</span>';
}
/* if($row['p'] AND ($row['to'] == $udata['usr'] OR $row['nick'] == $udata['usr'])) {
$row['komentaras'] = '<div style="background: #333;">'.$row['komentaras'].'</div>';
}
*/
if (in_array($row['uid'], $admin_arr) OR in_array($row['uid'], $moder_arr))
$row['komentaras'] = bbcode($row['komentaras']);
$data[] = $row;
}
$tpl->assign('data', $data);
}
pagenavig($allpage, $page, '');
$tpl->assign('isadmin', isadmin());
$whoInChat = array();
$query = @mysql_query("SELECT `usr`, `lvisit` FROM `users` WHERE `place` = 'chat' AND `lvisit` > '" . (CURR_TIME - 1800) . "' ORDER BY `lvisit` DESC;");
while ($array = @mysql_fetch_array($query)) {
$whoInChat[$array['usr']] = CURR_TIME - $array['lvisit'];
}
$tpl->assign('inChat', count($whoInChat));
$tpl->assign('whoInChat', $whoInChat);
$tpl->display('chat.tpl');
break;
case 'del_post':
if ($_GET['p'] != 1) {
if (!ismoder())
go();
q("DELETE FROM `chat` WHERE `id`='" . int($_GET['p']) . "' LIMIT 1");
go('chat.php');
} else {
go('chat.php');
}
break;
case 'writes':
if ($udata['lvl'] < WRITE_LVL)
go('/?note=write_lvl');
$in_ban = q("SELECT `id` FROM `ban` WHERE `uid`='" . $udata['id'] . "' AND `ban_time`>'" . time() . "' LIMIT 1");
if (num_rows($in_ban))
go('chat.php?note=ban');
$msg = mb_substr(clean($_POST['zin']), 0, 256, 'UTF-8');
$msg = trim($msg);
if (ismoder())
$msg = preg_replace('#b(http|https)://[^s'"><]+#i', '<a href="$0">$0</a>', $msg);
if (!$msg)
go('chat.php');
$lastMsg = result(q("SELECT `komentaras` FROM `chat` WHERE `nick` = '$log' ORDER BY `id` DESC LIMIT 1;"));
if ($lastMsg == $msg)
go('chat.php?note=double');
$countMsg = result(q("SELECT COUNT(*) FROM `chat` WHERE `nick` = '$log' AND `time` = '" . date('H:i') . "';"));
if ($countMsg > 5)
go('chat.php?note=limit');
$to = trim($_POST['to']);
$to = clean($to);
$to = str_replace(',', '', $to);
$p = 0;
if ($_POST['p'] == 'on')
$p = 1;
$msg = smileys($msg);
q("INSERT INTO `chat` SET `to` = '$to', `p` = '$p', `nick` = '$log', `komentaras` = '$msg', `kada` = '" . date("H:i") . "', `time` = '" . time() . "', `uid` = '" . $udata['id'] . "';");
if (!$p)
q("UPDATE `users` SET `ld_chat` = `ld_chat` + 1 WHERE `id` = '" . $udata['id'] . "';");
q("UPDATE `users` SET `place` = 'chat', `lvisit` = '" . time() . "' WHERE `id` = '" . $udata['id'] . "';");
// titS:
refreshTitS();
q("UPDATE `user_tits` SET `msgs` = `msgs` + 1 WHERE `uid` = '" . $udata['id'] . "';");
// Шутки:
if (time() - $_SESSION['jokes'] > 300) {
if ($msg == '!шутка' OR $msg == '!joke') {
$jokes = file('files/jokes.dat');
$joke = trim($jokes[array_rand($jokes)]);
q("INSERT INTO `chat` SET `nick` = 'Шутник', `komentaras` = '$joke', `kada` = '" . date("H:i") . "', `time` = '" . (time() + 1) . "'");
$_SESSION['jokes'] = time();
}
}
// ;
//Бутылочка
if ($msg == '!бутылочка' OR $msg == '!БУТЫЛОЧКА') {
$i = 0;
$q = q("SELECT * FROM `chat` WHERE `time` > '" . (time() - 3600) . "' GROUP BY `nick`;");
$data = array();
while ($arr = assoc($q)) {
$data[] = $arr['nick'];
$i++;
}
$msg = "<b>" . nickname($udata['usr']) . "</b>, крутит бутылочку! Крутится-крутится. МГНОВЕНЬЕ! Бутылочка показывает на " . nickname($data[rand(0, $i)]);
q("INSERT INTO `chat` SET `nick` = 'БУТЫЛОЧКА', `komentaras` = '" . $msg . "', `kada` = '" . date("H:i") . "', `time` = '" . (time() + 1) . "'");
}
if ($msg == '!правда' OR $msg == '!ПРАВДА') {
$q = result(q("SELECT `chat` FROM `smile` LIMIT 1"));
include('files/arraychat.php');
$md = nickname($udata['usr']) . ", " . $use[$q];
if ($use[$q] != '') {
q("INSERT INTO `chat` SET `nick` = 'БУТЫЛОЧКА', `komentaras` = '" . $md . "', `kada` = '" . date("H:i") . "', `time` = '" . (time() + 1) . "'");
q("UPDATE `smile` SET `chat` = `chat` + 1;");
}
}
go('chat.php?note=add');
break;
case 'trinti':
if (!isadmin())
go();
q("TRUNCATE `chat`");
q("INSERT INTO `chat` SET `nick` = '<b style='color:lime'>Система</b>', `komentaras` = 'Чат очищен администратором " . nickName($udata['usr']) . "', `kada` = '" . date("H:i") . "', `time` = '" . (time() + 1) . "'");
go('chat.php');
break;
}
/*function smiles($string){
$dir = opendir ("tpl/default/pic/smiles");
while ($file = readdir ($dir)) {
if (pathinfo($file,PATHINFO_EXTENSION)=='gif'){
$file2=basename($file,'.gif');
$string=str_replace(":$file2",'<img src="tpl/default/pic/smiles/'.$file.'" alt=""/>',$string);
}}
closedir ($dir);
return $string;
}*/
$end_time = microtime();
$end_array = explode(" ", $end_time);
$end_time = $end_array[1] + $end_array[0];
$generation_time = round($end_time - $start_time, 5);
echo '<!-- ' . $generation_time . ' сек. -->';
?>