117 lines
5.0 KiB
PHP
117 lines
5.0 KiB
PHP
|
|
<?php
|
||
|
|
require "RtmpClient.class.php";
|
||
|
|
require "debug.php";
|
||
|
|
require "connectionDetails.php";
|
||
|
|
require "utils.php";
|
||
|
|
@session_start();
|
||
|
|
|
||
|
|
$host=HOST;
|
||
|
|
$appName=APPNAME;
|
||
|
|
$port=PORT;
|
||
|
|
|
||
|
|
|
||
|
|
if(empty($_SESSION["username"])){
|
||
|
|
echo "Username is mandatory. Connection Rejected";
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
$client = new RtmpClient();
|
||
|
|
$data = array($_SESSION["gender"],$_SESSION["username"],"","","user",0,0,"",$_SESSION["theToken"],"","","",$revision,$_COOKIE["userId"],getRealIpAddr());
|
||
|
|
|
||
|
|
$client->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"] = "Welcome to AVChat 3.0 Mobile Client";
|
||
|
|
|
||
|
|
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
|
||
|
|
usort($history, function($a, $b) {
|
||
|
|
return $a['time'] - $b['time'];
|
||
|
|
});
|
||
|
|
|
||
|
|
$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";
|
||
|
|
|
||
|
|
//loading the emotes
|
||
|
|
$emotes = simplexml_load_file($_SESSION["emoticonsurl"]);
|
||
|
|
|
||
|
|
if(count($history) >= 40){
|
||
|
|
for ($i=count($history)-40; $i<count($history); $i++){
|
||
|
|
if($history[$i]["time"] > $_COOKIE["timeOfLastMessage"]){
|
||
|
|
if(preg_match($pattern, $history[$i]["textmessage"]) || preg_match($ytPattern, $history[$i]["textmessage"])){
|
||
|
|
echo "<div><b>".$history[$i]["senderusername"]."</b>: <a href='".$history[$i]["textmessage"]."' target='_blank'>".$history[$i]["textmessage"]."</a></div>";
|
||
|
|
//if(preg_match($ytIDPattern, $history[$i]["textmessage"])){
|
||
|
|
//echo'<iframe width="560" height="315" src="http://www.youtube.com/embed/UsvgYXtQB48" frameborder="0" allowfullscreen></iframe>';
|
||
|
|
//}
|
||
|
|
}else{
|
||
|
|
foreach($emotes as $e){
|
||
|
|
$history[$i]["textmessage"] = str_replace($e["text"], "<img src='../".$e["url"]."' width='18' height='18'/>", $history[$i]["textmessage"]);
|
||
|
|
}
|
||
|
|
if($history[$i]["senderusername"] != ""){
|
||
|
|
echo "<div><b>".$history[$i]["senderusername"]."</b>: ".$history[$i]["textmessage"]."</div>";
|
||
|
|
}else{
|
||
|
|
echo "<div style='color:#548eba'><b>".$history[$i]["textmessage"]."</b></div>";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
if(preg_match($pattern, $history[$i]["textmessage"]) || preg_match($ytPattern, $history[$i]["textmessage"])){
|
||
|
|
echo "<div style='color:#b4b4b4'><b>".$history[$i]["senderusername"]."</b>: <a href='".$history[$i]["textmessage"]."' target='_blank'>".$history[$i]["textmessage"]."</a></div>";
|
||
|
|
}else{
|
||
|
|
foreach($emotes as $e){
|
||
|
|
$history[$i]["textmessage"] = str_replace($e["text"], "<img src='../".$e["url"]."' width='18' height='18'/>", $history[$i]["textmessage"]);
|
||
|
|
}
|
||
|
|
echo "<div style='color:#b4b4b4'><b>".$history[$i]["senderusername"]."</b>: ".$history[$i]["textmessage"]."</div>";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
for ($i=0; $i<count($history); $i++){
|
||
|
|
if($history[$i]["time"] > $_COOKIE["timeOfLastMessage"]){
|
||
|
|
if(preg_match($pattern, $history[$i]["textmessage"]) || preg_match($ytPattern, $history[$i]["textmessage"])){
|
||
|
|
echo "<div><b>".$history[$i]["senderusername"]."</b>: <a href='".$history[$i]["textmessage"]."' target='_blank'>".$history[$i]["textmessage"]."</a></div>";
|
||
|
|
/*if(preg_match($ytIDPattern, $history[$i]["textmessage"])){
|
||
|
|
echo'<iframe width="560" height="315" src="http://www.youtube.com/embed/UsvgYXtQB48" frameborder="0" allowfullscreen></iframe>';
|
||
|
|
}*/
|
||
|
|
}else{
|
||
|
|
foreach($emotes as $e){
|
||
|
|
$history[$i]["textmessage"] = str_replace($e["text"], "<img src='../".$e["url"]."' width='18' height='18'/>", $history[$i]["textmessage"]);
|
||
|
|
}
|
||
|
|
if($history[$i]["senderusername"] != ""){
|
||
|
|
echo "<div><b>".$history[$i]["senderusername"]."</b>: ".$history[$i]["textmessage"]."</div>";
|
||
|
|
}else{
|
||
|
|
echo "<div style='color:#548eba'><b>".$history[$i]["textmessage"]."</b></div>";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
if(preg_match($pattern, $history[$i]["textmessage"]) || preg_match($ytPattern, $history[$i]["textmessage"])){
|
||
|
|
echo "<div style='color:#b4b4b4'><b>".$history[$i]["senderusername"]."</b>: <a href='".$history[$i]["textmessage"]."' target='_blank'>".$history[$i]["textmessage"]."</a></div>";
|
||
|
|
}else{
|
||
|
|
foreach($emotes as $e){
|
||
|
|
$history[$i]["textmessage"] = str_replace($e["text"], "<img src='../".$e["url"]."' width='18' height='18'/>", $history[$i]["textmessage"]);
|
||
|
|
}
|
||
|
|
echo "<div style='color:#b4b4b4'><b>".$history[$i]["senderusername"]."</b>: ".$history[$i]["textmessage"]."</div>";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//$client->close();
|
||
|
|
?>
|