$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 "";*/ //by default, just return img tag to original image return ""; } 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= 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] == 'Ð' || $mesg[$i] == 'ð') { $mouth = "tongue"; $alt .= "P";} elseif ($mesg[$i] == 'O' || $mesg[$i] == 'o' || $mesg[$i] == 'Î' || $mesg[$i] == 'î') { $mouth = "amazed"; $alt .= "o";} if ($total_pics<$max_images) { if (strlen($mouth) != 0) { $ok = 0; $face = $prefix . $mouth . "-" . $brows; $face = "\"$alt\""; /* $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("/(?)((http|https|ftp):\/\/[\w?=&.\/-~#-_]+)/e", "'\\1'", $str); $str2 = preg_replace("/((?)(?<=(>|\s))[\w_-]+@[\w_.-]+[\w]+)/","\\1",$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","
",$m_text); $m_text = str_replace("

","
", $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."
\n"; $error = 1; } if (!$error) { $mesg = " ".$mesg; $mesg = check_uppercase($mesg); $mesg = replace_badwords($mesg); $mesg = htmlspecialchars($mesg); $mesg = addURLS($mesg); $mesg_parts = array(); $mesg_parts = split("<",$mesg); for ($i=0;$i",$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 .= ""; $mesg_postfix = "".$mesg_postfix; } if($style_i != "" && $enabled_i_style) { $mesg_prefix .= ""; $mesg_postfix = "".$mesg_postfix; } if($style_u != "" && $enabled_u_style) { $mesg_prefix .= ""; $mesg_postfix = "".$mesg_postfix; } if ($is_image) $mesg = str_replace("\t|IMG|\t", $my_imtag, $mesg); remove_old_images(); } } if (isset($HTTP_POST_FILES['up_file']['name']) && $HTTP_POST_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($HTTP_POST_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($HTTP_POST_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("\"","",$HTTP_POST_FILES['up_file']['name']), $image_sizes); if (!$allow_priv_pics) $whisper = ""; } } $to_nick = ""; $to_id = 0; $to_session = ""; if ($whisper != "") { for($i=0; $i\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=>"" .$mesg_prefix. $user_name." ". trim(substr($mesg, 5)) .$mesg_postfix. ""); 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) ? "$user_name": $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=>"".$mesg_prefix.trim($mesg).$mesg_postfix.""); $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