';
$toid = $db->intcast($_REQUEST['toid']);
// login check
if(isset($_SESSION['loggedin']) || $_SESSION['loggedin'] != '') {
$uid = $db->intcast($_SESSION['uid']);
} else {
header("Location: ../");
exit;
}
// get and set a proper token for our instance.
if(!isset($_SESSION['token']) || empty($_SESSION['token']) ) {
$csrf = $db->getToken();
$_SESSION['token'] = $csrf;
} else {
$csrf = $db->clean($_SESSION['token'],'encode');
}
$alreadyfriends = [];
$friend_list = '';
$selectfriends = $db->query("SELECT * FROM friends WHERE uid = '".$db->intcast($uid)."' and blk != '1' LIMIT 50");
$countfriends = count($selectfriends);
if($countfriends >=1) {
for($j=0; $j<$countfriends; $j++) {
array_push($alreadyfriends,$selectfriends[$j]['fid']);
$userprofiles = $db->query("SELECT id,username,photo FROM profile WHERE id = '".$db->intcast($selectfriends[$j]['fid'])."'");
$count = count($userprofiles);
if($count >=1) {
for($i=0;$i<$count;$i++) {
$active = '';
if($toid == $userprofiles[$i]['id']) {
$active = '-active';
}
$showbubblealert = 'messenger-image-follow-list';
$messages = [];
$stmt = $mysqli->prepare("SELECT COUNT(message) FROM messenger where toid = ? AND uid = ? AND readit != ?");
$uid = $db->intcast($_SESSION['uid']);
$readit = 1;
$fromid = $userprofiles[$i]['id'];
$stmt->bind_param("iii", $uid, $fromid, $readit);
$stmt->execute();
$query = $stmt->get_result();
while($row = $query->fetch_array(MYSQLI_ASSOC)) {
$messages[] = $row;
}
if($messages[0]["COUNT(message)"] >=1) {
$showbubblealert = 'messenger-image-follow-list-new';
}
$friend_list .= "