Files
legacy_rock/chat/inc_form_message.php

53 lines
2.9 KiB
PHP

<?php
function form_message($last_id, $message, $ignored_users) {
global $cu_array, $message_format, $message_fromme, $private_message, $private_message_fromme, $private_hidden,$w_whisper_to,$session,$user_name,$is_regist,$users,$w_unknown_user,$nick_highlight_before,$nick_highlight_after, $room_id,$str_w_n_before,$str_w_n_after, $chat_url;
$to_out = "";
$mesg_array = explode("\t", $message, MESG_TOTALFIELDS);
if ($mesg_array[MESG_ROOM] == $cu_array[USER_ROOM] or $mesg_array[MESG_ROOM] == -1) {
if ($mesg_array[MESG_ID] > $last_id) {
if(!isset($ignored_users[strtolower($mesg_array[MESG_FROMWOTAGS])]) || $mesg_array[MESG_FROMWOTAGS] == "") {
if (strlen($mesg_array[MESG_TO])==0) {
//not private
if (strcmp($mesg_array[MESG_FROMWOTAGS], $cu_array[USER_NICKNAME])==0)
$to_out = str_replace("[HOURS]",date("H",$mesg_array[MESG_TIME]),$message_fromme);
else
$to_out = str_replace("[HOURS]",date("H",$mesg_array[MESG_TIME]),$message_format);
}
else {
//private
if (strcmp($mesg_array[MESG_FROMSESSION], $cu_array[USER_SESSION])==0 ||
(strcmp($mesg_array[MESG_FROMWOTAGS], $cu_array[USER_NICKNAME])==0 && $mesg_array[MESG_FROMID] >0)
) {
$to_out = str_replace("[HOURS]",date("H",$mesg_array[MESG_TIME]),$private_message_fromme);
}else if (strcmp($mesg_array[MESG_TOSESSION], $cu_array[USER_SESSION])==0 ||
(strcmp($mesg_array[MESG_TO],$cu_array[USER_NICKNAME])==0 && $mesg_array[MESG_TOID] >0 )
) {
$to_out = str_replace("[HOURS]",date("H",$mesg_array[MESG_TIME]),$private_message);
}else
$to_out = str_replace("[HOURS]",date("H",$mesg_array[MESG_TIME]),$private_hidden);
}
$to_out = str_replace("[MIN]",date("i",$mesg_array[MESG_TIME]),$to_out);
$to_out = str_replace("[SEC]",date("s",$mesg_array[MESG_TIME]),$to_out);
$to_out = str_replace("[NICK]",$mesg_array[MESG_FROM],$to_out);
$to_out = str_replace("[NICK_WO_TAGS]",$mesg_array[MESG_FROMWOTAGS],$to_out);
$to_out = str_replace("[TO]",$mesg_array[MESG_TO],$to_out);
$to_out = str_replace("[PRIVATE]",$w_whisper_to,$to_out);
$to_out = str_replace("[AVATAR]",
((strlen($mesg_array[MESG_FROMAVATAR])<3) ? "" :
"<img src=\"".$chat_url."photos/".$mesg_array[MESG_FROMAVATAR]."\">"),
$to_out);
$nick_in_str = 0;
if (function_exists('preg_replace')) {
if (preg_match("/".$cu_array[USER_NICKNAME]."([".preg_quote("?&:, !")."])/", $mesg_array[MESG_BODY]))
$nick_in_str = 1;
$mesg_array[MESG_BODY] = preg_replace("/".$cu_array[USER_NICKNAME]."([".preg_quote("?&:, !")."])/", $nick_highlight_before.$user_name.$nick_highlight_after."\\1",$mesg_array[MESG_BODY]);
}
$to_out = str_replace("[MESSAGE]",$mesg_array[MESG_BODY],$to_out);
if ($nick_in_str) $to_out = $str_w_n_before . $to_out . $str_w_n_after;
$to_out = ($to_out == "") ? "":$to_out."<br><script>up()</script>\n";
}
}
}
return array($mesg_array[MESG_ID],$to_out);
}
?>