View file wip-site-portal/src/chat_talk.php

File size: 8.09Kb
<?
require('ini.php');
$link=connect();

@$r=intval($_GET['r']);
@$s=intval($_GET['s']);
@$key=trim(htmlspecialchars($_GET['key'],ENT_QUOTES));

$user=login('nick, loc, chat_msgs, chat_ignor, chat_upd, chat_filter, chat_last, trans, chat_quiz_on', 'chat');

if($user['loc']!='chat') mysql_query("update wip_users set loc='chat' where id='$user[id]';");

$select=mysql_query("select topic, type from wip_chat_rooms where id='$r';");
if(mysql_affected_rows()<1){
	head('Ошибка!',15,'chat_rooms.php?sid='.$sid);
	echo '<small><b>Неверная комната!</b></small>';
	foot();
	exit();
}

mysql_query("update wip_users set chat_room='$r', chat_online='".time()."' where id='$user[id]';");

$res_room=mysql_fetch_assoc($select);

header("Content-type:text/vnd.wap.wml");
echo '<?xml version="1.0" encoding="UTF-8"?>'.
'<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml12.dtd">'.
'<wml><head><meta http-equiv="Cache-Control" content="no-cache" forua="true"/></head>';

if($res_room['type']=='privat' and !$key){
	echo '<card id="main" title="Приватная комната"><p>';
	echo '<small>Введите ключ для комнаты:</small><br/>';
	echo '<input name="key'.$ref.'" type="text" maxlength="20"/><br/>';
	echo '<small><a href="chat_talk.php?sid='.$sid.'&amp;r='.$r.'&amp;key=$(key'.$ref.')">Войти</a><br/>';
	echo '---<br/>';
	echo '<a href="chat.php?sid='.$sid.'">Список комнат</a>';
	echo '</small>';
	foot();
	exit();
}

if($res_room['type']=='privat' and $key) $key_link='&amp;key='.$key.'&amp;';
else $key_link=false;

if($user['chat_upd'] and $s<2) echo '<card id="main" title="'.$res_room['topic'].' - '.date('H:i').'" ontimer="chat_talk.php?sid='.$sid.'&amp;r='.$r.$key_link.'"><timer value="'.$user['chat_upd'].'"/>';
else echo '<card id="main" title="'.$res_room['topic'].' - '.date('H:i').'">';

echo '<do type="options" label="Сказать"><go href="chat_say.php?sid='.$sid.'&amp;r='.$r.$key_link.'"/></do>';
echo '<do type="options" label="Обновить"><go href="chat_talk.php?sid='.$sid.'&amp;r='.$r.$key_link.'"/></do>';
echo '<do type="options" label="Кто здесь?"><go href="chat_online.php?sid='.$sid.'&amp;r='.$r.$key_link.'"/></do>';
echo '<do type="options" label="Фильтр"><go href="chat_filter.php?sid='.$sid.'&amp;r='.$r.$key_link.'"/></do>';

echo '<p>';

if($r==1) require('chat_quiz.php');

//Отправленное сообщение
if(@$_POST['msg']){
	@$to=intval($_GET['uid']);
	
	mysql_query("select id from wip_users where id='$to';");
	if(mysql_affected_rows()<1) $to=false;
	
	@$msg = $_POST['msg'];
	
	if($user['trans']) $msg=strtr($msg,array('A'=>'А','a'=>'а','B'=>'Б','b'=>'б','V'=>'В','v'=>'в','G'=>'Г','g'=>'г','D'=>'Д','d'=>'д','E'=>'Е','e'=>'е','yo'=>'ё','Zh'=>'Ж','zh'=>'ж','Z'=>'З','z'=>'з','I'=>'И','i'=>'и','J'=>'Й','j'=>'й','K'=>'К','k'=>'к','L'=>'Л','l'=>'л','M'=>'М','m'=>'м','N'=>'Н','n'=>'н','O'=>'О','o'=>'о','P'=>'П','p'=>'п','R'=>'Р','r'=>'р','S'=>'С','s'=>'с','T'=>'Т','t'=>'т','U'=>'У','u'=>'у','F'=>'Ф','f'=>'ф','H'=>'Х','h'=>'х','C'=>'Ц','c'=>'ц','Ch'=>'Ч','ch'=>'ч','Sh'=>'Ш','sh'=>'ш','Sch'=>'Щ','sch'=>'щ',"''"=>'ъ','Y'=>'Ы','y'=>'ы',"'"=>'ь','Ye'=>'Э','ye'=>'э','Yu'=>'Ю','yu'=>'ю','Ya'=>'Я','ya'=>'я','Yo'=>'Ё'));
	
	$msg = mb_substr( htmlspecialchars($msg, ENT_QUOTES), 0, 200, 'UTF-8');
	
	$msg = str_replace ('$','$$',$msg);
	
	# Добавление смайлов
	$msg=strtr($msg,array(':)'=>'<smile.gif>', ';)'=>'<wink.gif>', 'B)'=>'<cool.gif>', ':(('=>'<aaa.gif>', ':!'=>'<be.gif>', ':S'=>'<blin.gif>', '@='=>'<bum.gif>', ':X'=>'<close.gif>', ';('=>'<cry.gif>', ']:)'=>'<devil.gif>', '@-/-'=>'<flow.gif>', ':]'=>'<gaga.gif>', ':D'=>'<green.gif>', '=)'=>'<ha.gif>', '(:'=>'<lol.gif>', '=/'=>'<hm.gif>', '.kiss.'=>'<kiss.gif>', ':o)'=>'<kloun.gif>', '.lips.'=>'<lips.gif>', '.love.'=>'<love.gif>', '8o'=>'<mmm.gif>', '[:)'=>'<music.gif>', '=]'=>'<napolu.gif>', '.ninja.'=>'<ninja.gif>', '.down.'=>'<no.gif>', '%)'=>'<ogo.gif>', '.pirat.'=>'<pirate.gif>', '.beer.'=>'<pivo.gif>', ':['=>'<red.gif>', ':('=>'<sad.gif>', '.woot.'=>'<shok.gif>', '.zz.'=>'<spit.gif>', '=p'=>'<tong.gif>', ':T'=>'<svist.gif>', '.uuu.'=>'<uuu.gif>', '.wow.'=>'<view.gif>', ':?'=>'<vopros.gif>', '.up.'=>'<yes.gif>', ':@'=>'<angry2.gif>', ':O'=>'<angry.gif>'));
	$arr=explode('<',$msg);
	
	$msg=false;
	
	foreach($arr as $k=>$val){
		if($k!=0 and $k<=3) $msg.='<img src="smiles/'.$val; 
		else $msg.=$val;
	}
	
	$msg=preg_replace("/src\=\"smiles\/([a-z]+)\.gif\>/","src=\"smiles/\\1.gif\" alt=\"\\1\"/>",$msg);
	$msg=eregi_replace("([a-z]+)\.gif\>","",$msg);
	####
	
	mysql_query("select id from wip_chat_msgs where rid='$r' and uid='$user[id]' and msg='$msg';");
	if(mysql_affected_rows()<1){
		
		if(@$_POST['privat'] and $to) $privat=$to;
		else $privat=0;
		
		if($res_room['type']=='privat' and $key) $room_key=", `key`='$key'";
		else $room_key=false;
	
		mysql_query("insert into wip_chat_msgs set rid='$r', uid='$user[id]', privat='$privat', time='".time()."', msg='$msg' ".$room_key.";");
		
		
		mysql_query("update wip_users set chat_posts=chat_posts+1 where id='$user[id]';");
	}
}
//////

echo '<small>';
echo '<a href="chat_say.php?sid='.$sid.'&amp;r='.$r.$key_link.'" accesskey="1">Сказать [1]</a> | ';
echo '<a href="chat_talk.php?sid='.$sid.'&amp;r='.$r.$key_link.'" accesskey="2">Обновить [2]</a><br/>';
echo '---<br/>';

if($user['chat_ignor']) $ignor=base64_decode($user['chat_ignor']); //Собираем условие игнора
else $ignor=false;

if($user['chat_quiz_on']==0) $ignor.="AND wip_chat_msgs.uid!=1 ";

if($res_room['type']=='privat' and $key) $privat_key=" and `key`='$key'";
else $privat_key=false;

if($user['chat_filter']==1) $cond_privat=false;
else $cond_privat="or wip_chat_msgs.privat='0'";

if($user['chat_filter']==2) $cond_new="and wip_chat_msgs.id>'$user[chat_last]' ";
else $cond_new=false;

$mlim=$user['chat_msgs'];

if (!$s or $s<=0) $s=1;
$all=mysql_fetch_row(mysql_query("select count(id) from wip_chat_msgs where rid='$r' and (wip_chat_msgs.privat='$user[id]' $cond_privat or wip_chat_msgs.uid='$user[id]') $cond_new $privat_key $ignor;"));

$pgs=ceil($all[0]/$mlim);
if($s>$pgs) $s=$pgs;
$n=($s-1)*$mlim;

$select=mysql_query("SELECT `wip_chat_msgs`.`id`, `wip_chat_msgs`.`time`, `wip_chat_msgs`.`uid`, `wip_chat_msgs`.`privat`, `wip_users`.`nick`, `wip_chat_msgs`.`msg` FROM `wip_chat_msgs`, `wip_users` WHERE `rid`='".$r."' AND `wip_chat_msgs`.`uid`=`wip_users`.`id` AND (`wip_chat_msgs`.`privat`='".$user['id']."' ".$cond_privat." OR `wip_chat_msgs`.`uid`='".$user['id']."') ".$cond_new.' '.$ignor.' '.$privat_key." AND (`wip_users`.`chat_full_ignor`=0 OR (`wip_users`.`chat_full_ignor`=1 AND `wip_users`.`id`='".$user['id']."')) ORDER BY `wip_chat_msgs`.`id` DESC LIMIT ".$n.",".$mlim.";");

$last=false;
$new=false;

if($all[0]>0){
	while($res=mysql_fetch_assoc($select)){
		
		if($res['id']==$user['chat_last'] and $last) echo '---<br/>';
		
		if(!$last){
			mysql_query("update wip_users set chat_last='$res[id]' where id='$user[id]';");
			$last=true;
		}
		
		if($res['uid'] != $user['id'] and $res['uid']!=1) echo '<b><a href="chat_say.php?sid='.$sid.'&amp;r='.$r.'&amp;uid='.$res['uid'].'">'.$res['nick'].'</a></b> ';
		else echo '<b>'.$res['nick'].'</b> ';
		
		if($res['privat']) echo '<b>[приват]</b> ';
		echo '['.date('H:i',$res['time']).'] '.$res['msg'].'<br/>';
	}
}
	
if($all[0]>$mlim){
	echo '---<br/>';
	if($s<$pgs) echo '<a href="chat_talk.php?sid='.$sid.'&amp;r='.$r.'&amp;s='.($s+1).'">Далее</a><br/>';
	if($s!=1) echo '<a href="chat_talk.php?sid='.$sid.'&amp;r='.$r.'&amp;s='.($s-1).'">Назад</a><br/>';
}

echo '---<br/>';
echo '<a href="chat_talk.php?sid='.$sid.'&amp;r='.$r.$key_link.'">Обновить [2]</a><br/>';
if($res_room['type']=='privat' and $key) echo '<a href="chat_talk.php?sid='.$sid.'&amp;r='.$r.'">Сменить ключ</a><br/>';
echo '<a href="chat.php?sid='.$sid.'" accesskey="0">Список комнат [0]</a>';
echo '</small>';
foot();

mysql_close($link);
?>