471 lines
14 KiB
PHP
471 lines
14 KiB
PHP
<?php
|
||
require_once("inc_common.php");
|
||
include($engine_path."users_get_list.php");
|
||
include($file_path."inc_badwords_filter.php");
|
||
set_variable("mesg");
|
||
set_variable("whisper");
|
||
set_variable("user_color");
|
||
set_variable("update_status");
|
||
set_variable("style_b");
|
||
set_variable("style_i");
|
||
set_variable("style_u");
|
||
|
||
//anti-bot fix: trying to stop automatic submission
|
||
|
||
if ($_SERVER["REQUEST_METHOD"] == "GET") exit();
|
||
if (!$browser_hash) exit();
|
||
|
||
//oxaber.ru sucks here
|
||
//if(strstr($mesg,"oxaber.ru"))exit();
|
||
if (!$exists) {
|
||
$error_text = $w_no_user;
|
||
include($file_path."designes/".$design."/error_page.php");
|
||
exit;
|
||
}
|
||
if (isset($update_status))
|
||
if($update_status!="") {
|
||
$update_status = intval($update_status);
|
||
$fields_to_update[0][0] = USER_STATUS;
|
||
$fields_to_update[0][1] = $update_status;
|
||
include($engine_path."user_din_data_update.php");
|
||
header("location: session.php?session=$session&".time());
|
||
exit;
|
||
}
|
||
|
||
//functions
|
||
|
||
function get_image_tag($img, $image_params) {
|
||
global $chat_url;
|
||
//just an example:
|
||
//if you want to show picture in the chat always fits to
|
||
//some width & height (and original image when you click on image in the chat),
|
||
//try this code:
|
||
/*$max_x = 500;
|
||
$max_y = 400;
|
||
$width = $image_params[0];
|
||
$height = $image_params[1];
|
||
if ($width > $max_x || $height > $max_y) {
|
||
$prop_x = $width / $max_x;
|
||
$prop_y = $height / $max_y;
|
||
$prop = ($prop_x>$prop_y)? $prop_x: $prop_y;
|
||
$width = round($width/$prop);
|
||
$height = round($height/$prop);
|
||
}
|
||
return "<a href=\"".$chat_url."up/".$img."\" target=\"_blank\"><img src=\"".$chat_url."up/".$img."\" width=\"".$width."\" height=\"".$height."\" border=\"0\"></a>";*/
|
||
|
||
//by default, just return img tag to original image
|
||
return "<img src=\"".$chat_url."up/".$img."\" width=\"".$image_params[0].
|
||
"\" height=\"".$image_params[1]."\" border=\"0\">";
|
||
}
|
||
|
||
function check_image($filename, $image_params) {
|
||
global $pics_maxh, $pics_maxw, $w_too_big_photo_height, $w_too_big_photo_width, $w_invalid_image;
|
||
$error = 0;
|
||
$error_text = "";
|
||
if ($image_params[2] <1 or $image_params[2]>3) {
|
||
//not an image
|
||
$error_text .= $w_invalid_image." code: ".$image_params[2];
|
||
$error = 1;
|
||
@unlink($filename);
|
||
} else if ($image_params[0]<1 or $image_params[0] > $pics_maxw) {
|
||
$error_text .= str_replace("~", $pics_maxw,
|
||
str_replace("*", $image_params[0], $w_too_big_photo_width));
|
||
$error = 1;
|
||
@unlink($filename);
|
||
} else if ($image_params[1]<1 or $image_params[1] > $pics_maxh) {
|
||
$error_text .= str_replace("~", $pics_maxh,
|
||
str_replace("*",$image_params[1], $w_too_big_photo_height));
|
||
$error = 1;
|
||
@unlink($filename);
|
||
}
|
||
return array($error, $error_text);
|
||
}
|
||
|
||
//remove all uploaded images which is older than 2 hours.
|
||
function remove_old_images() {
|
||
global $file_path;
|
||
if ($pic_dir = opendir($file_path."up/")) {
|
||
while (false !== ($file = readdir($pic_dir))) {
|
||
$f_und = strpos($file, "_");
|
||
$s_und = strpos($file, "_", $f_und+1);
|
||
$dot = strpos($file, ".");
|
||
if ($s_und>0 && $dot>$s_und) {
|
||
$creation_time = intval(substr($file, $s_und+1, $dot-$s_und-1));
|
||
if ($creation_time >0 && $creation_time<time()-7200)
|
||
@unlink($file_path."up/".$file);
|
||
}
|
||
}
|
||
closedir($pic_dir);
|
||
}
|
||
}
|
||
|
||
function addFaces($mesg) {
|
||
global $total_pics, $max_images, $chat_url;
|
||
$l = 0;
|
||
$temp = "";
|
||
for ($i = 0; $i < strlen($mesg); $i++) {
|
||
$oi = $i;
|
||
$ok = 1;
|
||
if (($mesg[$i] == ':' || $mesg[$i] == '=' || $mesg[$i] == ';') and !(substr($mesg,$i-3,4)=="<" or substr($mesg,$i-3,4)==">" or (substr($mesg,$i-5,1)=="&" &&$mesg[$i] == ';'&&$mesg[$i-2] != ';' ) )) {
|
||
$alt = "";
|
||
$brows = "normal";
|
||
if ($i >= 4) {
|
||
if ( substr($mesg,$i-4,4) == '>') {
|
||
$brows = "mad";
|
||
$alt = ">"; /*Orig: $alt = "]";*/
|
||
}
|
||
elseif ( substr($mesg,$i-4,4) == '<') {
|
||
$brows = "upset";
|
||
$alt = "<"; /*Orig = $alt="[";*/
|
||
}
|
||
}
|
||
$prefix = "";
|
||
if ($mesg[$i] == ';') {
|
||
$prefix = "wink-";
|
||
$alt .= ";";
|
||
}
|
||
else { $alt .= ":"; }
|
||
$i++;
|
||
if ($mesg[$i] == '^' || $mesg[$i] == '-' || $mesg[$i] == '\'') {
|
||
$i++; $alt.="-"; }
|
||
$mouth = "";
|
||
if ($mesg[$i] == ')' || $mesg[$i] == 'D' || $mesg[$i] == ']') {
|
||
$mouth = "smile"; $alt .= ")"; }
|
||
elseif ($mesg[$i] == '(') {
|
||
$mouth ="frown"; $alt .= "(";}
|
||
elseif ($mesg[$i] == '|') {
|
||
$mouth = "shy"; $alt .= "|";}
|
||
elseif ($mesg[$i] == 'P' || $mesg[$i] == 'p' || $mesg[$i] == '<27>' || $mesg[$i] == '<27>') {
|
||
$mouth = "tongue"; $alt .= "P";}
|
||
elseif ($mesg[$i] == 'O' || $mesg[$i] == 'o' || $mesg[$i] == '<27>' || $mesg[$i] == '<27>') {
|
||
$mouth = "amazed"; $alt .= "o";}
|
||
if ($total_pics<$max_images) {
|
||
if (strlen($mouth) != 0) {
|
||
$ok = 0;
|
||
$face = $prefix . $mouth . "-" . $brows;
|
||
$face = "<img src=\"".$chat_url."faces/$face.gif\" alt=\"$alt\" width=16 height=16>";
|
||
|
||
/* $temp[$l] = '\0'; */
|
||
if (strcmp($brows, "normal") != 0) {
|
||
$l = strlen ($temp) -4;
|
||
$temp = substr($temp,0,$l);
|
||
}
|
||
$temp .= $face;
|
||
$total_pics++;
|
||
$l = strlen($temp);
|
||
}
|
||
else {
|
||
$i = $oi;
|
||
$ok = 1;
|
||
}
|
||
}
|
||
else {$ok = 1;$i = $oi;$l = strlen($temp);}
|
||
}
|
||
if ($ok == 1) {
|
||
$temp .= $mesg[$i];
|
||
$l++;
|
||
}
|
||
}
|
||
return $temp;
|
||
}
|
||
|
||
function addURLS($str) {
|
||
global $chat_url;
|
||
$str2 = $str;
|
||
if (function_exists('preg_replace')){
|
||
$str2 = preg_replace("/(?<!<a href=\")(?<!\")(?<!\">)((http|https|ftp):\/\/[\w?=&.\/-~#-_]+)/e",
|
||
"'<a href=\"".$chat_url."go.php?url='.urlencode('\\1').'\" target=\"_blank\">\\1</a>'",
|
||
$str);
|
||
$str2 = preg_replace("/((?<!<a href=\"mailto:)(?<!\">)(?<=(>|\s))[\w_-]+@[\w_.-]+[\w]+)/","<a href=\"mailto:\\1\">\\1</a>",$str2);
|
||
}
|
||
return $str2;
|
||
}
|
||
|
||
function check_uppercase($mesg) {
|
||
global $max_cap_letters;
|
||
if ($max_cap_letters) {
|
||
$l = strlen($mesg);
|
||
$t_u = 0;
|
||
for ($i=0;$i<$l;$i++) {
|
||
$ch = substr($mesg,$i,1);
|
||
if ($ch == strtoupper($ch) && $ch != strtolower($ch))
|
||
$t_u++;
|
||
if ($t_u > $max_cap_letters) {
|
||
$mesg = strtolower($mesg);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
return $mesg;
|
||
}
|
||
|
||
function mesg2html($m_text) {
|
||
global $imgPhrase,$numOfImgPhrases,$mesg,$total_pics,$imgPhrase,$imgURL,$max_images;
|
||
$m_text = addFaces(wordwrap($m_text, 75," ", 1));
|
||
if ( substr_count($mesg,"**n") <7)
|
||
$m_text = str_replace("**n","<br>",$m_text);
|
||
$m_text = str_replace("<br><br>","<br>", $m_text);
|
||
for ($j=0; $j<$numOfImgPhrases; $j++) {
|
||
$total_pics+=substr_count($mesg,$imgPhrase[$j]);
|
||
if ($max_images >= $total_pics)
|
||
$m_text = str_replace($imgPhrase[$j], $imgURL[$j], $m_text);
|
||
}
|
||
return $m_text;
|
||
}
|
||
|
||
//end of functions
|
||
|
||
|
||
if ($user_color=="") {$user_color=$default_color;}
|
||
$user_color = intval($user_color);
|
||
if (($user_color < 0) or ($user_color >= count($registered_colors))) {$user_color=$default_color;}
|
||
SetCookie("c_user_color", $user_color, time() + 2678400);
|
||
|
||
$error_text = "";
|
||
$error = 0;
|
||
$total_pics = 0;
|
||
$messages_to_show = array();
|
||
if (!isset($mesg)){$mesg = "";}
|
||
$mesg = str_replace("\r"," ",str_replace("\n"," ",str_replace("\t"," ", $mesg)));
|
||
|
||
|
||
|
||
|
||
if ($mesg !="") {
|
||
$converts = file($converts_file);
|
||
$numOfImgPhrases = count($converts);
|
||
for ($i=0;$i<$numOfImgPhrases;$i++)
|
||
if (strpos($converts[$i],"\t"))
|
||
list ($imgPhrase[$i], $imgURL[$i]) = explode("\t",trim($converts[$i]));
|
||
|
||
$is_image = 0;
|
||
$my_imtag = "";
|
||
if (function_exists('preg_replace')){
|
||
$mesg = preg_replace("/[0-9a-f]{32}/", "1234", $mesg);
|
||
|
||
if (preg_match('!http:\/\/[\w?=&.\/-~#-_]+((\.jpg)|(\.jpeg)|(.gif)|(.png))!i',
|
||
trim($mesg), $mmm) &&
|
||
$ar_rooms[intval($room_id)][ROOM_ALLOWPICS] == 1 && $allow_pics) {
|
||
|
||
$image = "";
|
||
$parsed = pathinfo(trim($mmm[0]));
|
||
$img_ext = strtolower($parsed["extension"]);
|
||
if (in_array($img_ext, array("jpg", "jpeg", "jpe", "gif", "png"))) {
|
||
//downloading image
|
||
$im_h = fopen(trim($mmm[0]), "rb");
|
||
if (!$im_h) {
|
||
$error_text = $w_cannot_download;
|
||
$error = 1;
|
||
} else {
|
||
while (!feof($im_h)) {
|
||
$image .= fgets($im_h, 8192);
|
||
if (strlen($image)>$pics_maxsize) {
|
||
$error_text .= str_replace("~", $pics_maxsize,
|
||
str_replace("*", ">".strlen($image),
|
||
$w_too_big_photo));
|
||
$error = 1;
|
||
$image = "";
|
||
break;
|
||
}
|
||
}
|
||
fclose($im_h);
|
||
}
|
||
if ($image!="") {
|
||
$filename = str_replace(" ", "_", str_replace(".", "_", microtime()));
|
||
$fp = fopen($file_path."up/".$filename.".".$img_ext, "wb");
|
||
fwrite($fp, $image);
|
||
fclose($fp);
|
||
@chmod($file_path."up/".$filename.".".$img_ext, 0644);
|
||
$image_params = getImageSize($file_path."up/".$filename.".".$img_ext);
|
||
list ($im_er, $im_ertext) = check_image($file_path."up/".$filename.".".$img_ext, $image_params);
|
||
if ($im_er == 1) {
|
||
$error = 1;
|
||
$error_text .= $im_ertext;
|
||
}else {
|
||
$mesg = preg_replace("!".preg_quote($mmm[0])."!","\t|IMG|\t",$mesg, 1);
|
||
$my_imtag = get_image_tag($filename.".".$img_ext.
|
||
"?".str_replace("\"","",$mmm[0]),
|
||
$image_params);
|
||
if (!$allow_priv_pics) $whisper = "";
|
||
$is_image = 1;
|
||
}
|
||
}
|
||
}
|
||
}//end of PIC-URL in the message
|
||
}//end of preg_ function exist
|
||
|
||
if (strlen($mesg)>512) {
|
||
$error_text .= $w_too_long."<br>\n";
|
||
$error = 1;
|
||
}
|
||
|
||
if (!$error) {
|
||
$mesg = " ".$mesg;
|
||
$mesg = check_uppercase($mesg);
|
||
$mesg = replace_badwords($mesg);
|
||
$mesg = htmlspecialchars($mesg, ENT_COMPAT | ENT_HTML401, 'cp1251');
|
||
file_put_contents('/tmp/chat.log', $mesg);
|
||
$mesg = addURLS($mesg);
|
||
$mesg_parts = array();
|
||
$mesg_parts = explode("<",$mesg);
|
||
for ($i=0;$i<count($mesg_parts);$i++) {
|
||
if ($i%2) {
|
||
list ($m_tag, $m_text) = explode(">",$mesg_parts[$i]);
|
||
$mesg_parts[$i] = $m_tag.">".mesg2html($m_text);
|
||
}
|
||
else {
|
||
$mesg_parts[$i] = mesg2html($mesg_parts[$i]);
|
||
}
|
||
}
|
||
$mesg = implode("<",$mesg_parts);
|
||
|
||
$mesg_prefix = "";
|
||
$mesg_postfix = "";
|
||
if($style_b != "" && $enabled_b_style) {
|
||
$mesg_prefix .= "<b>";
|
||
$mesg_postfix = "</b>".$mesg_postfix;
|
||
}
|
||
if($style_i != "" && $enabled_i_style) {
|
||
$mesg_prefix .= "<i>";
|
||
$mesg_postfix = "</i>".$mesg_postfix;
|
||
}
|
||
if($style_u != "" && $enabled_u_style) {
|
||
$mesg_prefix .= "<u>";
|
||
$mesg_postfix = "</u>".$mesg_postfix;
|
||
}
|
||
|
||
if ($is_image)
|
||
$mesg = str_replace("\t|IMG|\t", $my_imtag, $mesg);
|
||
remove_old_images();
|
||
}
|
||
}
|
||
if (isset($_FILES['up_file']['name']) && $_FILES['up_file']['name'] != "" && $ar_rooms[intval($room_id)][ROOM_ALLOWPICS] == 1 && $allow_pics && !$is_image){
|
||
//picture send -form.
|
||
error_reporting(E_ALL);
|
||
$filename = str_replace(" ", "_", str_replace(".", "_", microtime()));
|
||
//it will require access to /tmp :(
|
||
|
||
$image_sizes = getImageSize($_FILES['up_file']['tmp_name']);
|
||
//by default - png :)
|
||
$img_ext = ($image_sizes[2] == 1)? "gif":
|
||
($image_sizes[2] == 2) ? "jpg":"png";
|
||
list ($im_er, $im_ertext) = check_image($file_path."up/".$filename.".".$img_ext, $image_sizes);
|
||
if ($im_er == 1) {
|
||
$error = 1;
|
||
$error_text .= $im_ertext;
|
||
}else {
|
||
move_uploaded_file($_FILES['up_file']['tmp_name'], $file_path."up/".$filename.".".$img_ext);
|
||
@chmod($file_path."up/".$filename.".".$img_ext, 0644);
|
||
//echo "Image tag: ".htmlspecialchars(get_image_tag($filename.".".$img_ext."?".str_replace("\"","",$HTTP_POST_FILES['up_file']['name']), $image_sizes));
|
||
$mesg = $mesg.get_image_tag($filename.".".$img_ext."?".str_replace("\"","",$_FILES['up_file']['name']), $image_sizes);
|
||
if (!$allow_priv_pics) $whisper = "";
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
$to_nick = "";
|
||
$to_id = 0;
|
||
$to_session = "";
|
||
if ($whisper != "") {
|
||
for($i=0; $i<sizeof($users); $i++) {
|
||
$data = explode("\t", $users[$i]);
|
||
if ($data[USER_NICKNAME] == $whisper) {
|
||
$to_nick = $data[USER_NICKNAME];
|
||
$to_id = $data[USER_REGID];
|
||
$to_session = $data[USER_SESSION];
|
||
}
|
||
}
|
||
if ($to_nick == "") {
|
||
$error_text .= $w_whisper_out."<br>\n";
|
||
$error = 1;
|
||
}
|
||
}
|
||
//check again for empty message --
|
||
//for case message was just image-URL, but we cannot download image
|
||
//or we send a private message to nobody.
|
||
if (!$error && trim($mesg)!="") {
|
||
$t_color = $registered_colors[$user_color][1];
|
||
$def_color = $registered_colors[$default_color][1];
|
||
if (strpos($mesg, "/me ") == 1)
|
||
$messages_to_show[] = array(MESG_TIME=>my_time(),
|
||
MESG_ROOM=>$room_id,
|
||
MESG_FROM=>"",
|
||
MESG_FROMWOTAGS=>$user_name,
|
||
MESG_FROMSESSION=>$session,
|
||
MESG_FROMAVATAR=>$cu_array[USER_AVATAR],
|
||
MESG_FROMID=>$is_regist,
|
||
MESG_TO=>"",
|
||
MESG_TOSESSION=>"",
|
||
MESG_TOID=>0,
|
||
MESG_BODY=>"<font color=\"$def_color\">" .$mesg_prefix. $user_name." ". trim(substr($mesg, 5)) .$mesg_postfix. "</font>");
|
||
else
|
||
$messages_to_show[] = array(MESG_TIME=>my_time(),
|
||
MESG_ROOM=>$room_id,
|
||
MESG_FROM=>(strlen($cu_array[USER_HTMLNICK])>0)?
|
||
$cu_array[USER_HTMLNICK] :
|
||
(($colorize_nicks) ?
|
||
"<font color=\"$t_color\">$user_name</font>":
|
||
$user_name
|
||
),
|
||
MESG_FROMWOTAGS=>$user_name,
|
||
MESG_FROMSESSION=>$session,
|
||
MESG_FROMAVATAR=>$cu_array[USER_AVATAR],
|
||
MESG_FROMID=>$is_regist,
|
||
MESG_TO=>$to_nick,
|
||
MESG_TOSESSION=>$to_session,
|
||
MESG_TOID=>$to_id,
|
||
MESG_BODY=>"<font color=\"$t_color\">".$mesg_prefix.trim($mesg).$mesg_postfix."</font>");
|
||
|
||
$to_robot = strip_tags($mesg);
|
||
$w_rob_name = $rooms[$room_id]["bot"];
|
||
if (!$whisper) {
|
||
include($ld_engine_path."robot_get_answers.php");
|
||
}
|
||
if ($ar_rooms[$room_id][ROOM_PREMODER] && $cu_array[USER_CLASS] == 0 ){
|
||
//waiting for approval from moderators
|
||
//khm.not sure what to use -- 'main engine' or 'long life data engine'
|
||
//put it into 'long data' now, because it might cause problems with shm -- i.e. not enough block size
|
||
//it also has to be stored for a long time
|
||
include_once($ld_engine_path."premoderation.php");
|
||
premoder_add($messages_to_show);
|
||
unset($messages_to_show);
|
||
}else{
|
||
include($engine_path."messages_put.php");
|
||
if ($mess_stat == 1 && !$error) {
|
||
$fp = fopen($data_path."mess_stat.dat", "a+");
|
||
flock($fp, LOCK_EX);
|
||
fseek($fp,0);
|
||
$normal_messages = intval(str_replace("\n","",@fgets($fp,1024)));
|
||
$private_messages = intval(str_replace("\n","",@fgets($fp,1024)));
|
||
if ($whisper)$private_messages++;
|
||
else $normal_messages++;
|
||
ftruncate($fp,0);
|
||
fwrite($fp,$normal_messages."\n".$private_messages);
|
||
fflush($fp);
|
||
flock($fp, LOCK_UN);
|
||
fclose($fp);
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
$out_users = array();
|
||
$who_j = 0;
|
||
for ($i=0;$i<count($users);$i++) {
|
||
$user_array = explode("\t",$users[$i]);
|
||
if ($user_array[USER_ROOM] == $cu_array[USER_ROOM]) {
|
||
$out_users[$who_j]["nickname"] = $user_array[USER_NICKNAME];
|
||
$out_users[$who_j]["sex"] = $user_array[USER_GENDER];
|
||
$out_users[$who_j]["small_photo"] = $user_array[USER_AVATAR];
|
||
$out_users[$who_j]["user_id"] = $user_array[USER_REGID];
|
||
$out_users[$who_j]["status"] = $user_array[USER_STATUS];
|
||
$who_j++;
|
||
}
|
||
}
|
||
$total_users = count($out_users);
|
||
|
||
include($file_path."designes/".$design."/sender.php");
|
||
?>
|