connect($host,$appName,$port,$data); if(isset($_POST["text"])){ $_SESSION["textMessage"] = $_POST["text"]; $client->distributeTextMessage($_SESSION["roomId"],"all","all",$_POST["text"],""); $theChat = $client->getMessages($_SESSION["roomId"],$_COOKIE["userId"]); } $history = array(); $welcomeMessage = array(); $welcomeMessage["time"] = $_COOKIE["timeOfLastMessage"] + 1; $welcomeMessage["senderusername"] = ""; $welcomeMessage["textmessage"] = $_SESSION["AVC_welcomeMessage"]; foreach($theChat as $j){ if(@strcmp($j["senderusername"],"r") != 0){ array_push($history, $j); } } //adding the welcome message array_push($history, $welcomeMessage); // sorting the array function sortChatOnSend($a, $b){ return $a['time'] - $b['time']; } usort($history, "sortChatOnSend"); $pattern ="#(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$#i"; $ytPattern="#http:\/\/w{0,3}\.youtube[^' '\n\r]+#i"; $ytIDPattern="#(?<=v(\=|\/))([-a-zA-Z0-9_]+)|(?<=youtu\.be\/)([-a-zA-Z0-9_]+)#i"; if(count($history) >= 40){ for ($i=count($history)-40; $i $_COOKIE["timeOfLastMessage"]){ if(preg_match($pattern, $history[$i]["textmessage"]) || preg_match($ytPattern, $history[$i]["textmessage"])){ echo "
".$history[$i]["senderusername"].": ".$history[$i]["textmessage"]."
"; //if(preg_match($ytIDPattern, $history[$i]["textmessage"])){ //echo''; //} }else{ foreach($_SESSION["AVC_emoteIcons"] as $key => $value){ $history[$i]["textmessage"] = str_replace($key, "", $history[$i]["textmessage"]); } if($history[$i]["senderusername"] != ""){ echo "
".$history[$i]["senderusername"].": ".$history[$i]["textmessage"]."
"; }else{ echo "
".$history[$i]["textmessage"]."
"; } } }else{ if(preg_match($pattern, $history[$i]["textmessage"]) || preg_match($ytPattern, $history[$i]["textmessage"])){ echo "
".$history[$i]["senderusername"].": ".$history[$i]["textmessage"]."
"; }else{ foreach($_SESSION["AVC_emoteIcons"] as $key => $value){ $history[$i]["textmessage"] = str_replace($key, "", $history[$i]["textmessage"]); } echo "
".$history[$i]["senderusername"].": ".$history[$i]["textmessage"]."
"; } } } }else{ for ($i=0; $i $_COOKIE["timeOfLastMessage"]){ if(preg_match($pattern, $history[$i]["textmessage"]) || preg_match($ytPattern, $history[$i]["textmessage"])){ echo "
".$history[$i]["senderusername"].": ".$history[$i]["textmessage"]."
"; /*if(preg_match($ytIDPattern, $history[$i]["textmessage"])){ echo''; }*/ }else{ foreach($_SESSION["AVC_emoteIcons"] as $key => $value){ $history[$i]["textmessage"] = str_replace($key, "", $history[$i]["textmessage"]); } if($history[$i]["senderusername"] != ""){ echo "
".$history[$i]["senderusername"].": ".$history[$i]["textmessage"]."
"; }else{ echo "
".$history[$i]["textmessage"]."
"; } } }else{ if(preg_match($pattern, $history[$i]["textmessage"]) || preg_match($ytPattern, $history[$i]["textmessage"])){ echo "
".$history[$i]["senderusername"].": ".$history[$i]["textmessage"]."
"; }else{ foreach($_SESSION["AVC_emoteIcons"] as $key => $value){ $history[$i]["textmessage"] = str_replace($key, "", $history[$i]["textmessage"]); } echo "
".$history[$i]["senderusername"].": ".$history[$i]["textmessage"]."
"; } } } } //$client->close(); ?>