Files
Testing/BKPchat/m/refreshChat.php
sean 0e8a8b3028
Some checks are pending
deploy-testing / deploy (push) Waiting to run
Initial testing snapshot
2026-11-17 16:15:01 -05:00

111 lines
4.8 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);
$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();
?>