This repository has been archived by the owner on Dec 14, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfriends.php
82 lines (65 loc) · 1.99 KB
/
friends.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
session_start();
require_once 'header.php';
require_once 'functions.php';
if (!$loggedin)
die();
if (isset($_GET['view']))
$view = sanitizeString($_GET['view']);
else
$view = $user;
if ($view == $user) {
$name1 = $name2 = "Your";
$name3 = "You are";
} else {
$name1 = "<a href='members.php?view=$view'>$view</a>'s";
$name2 = "$view's";
$name3 = "$view is";
}
echo "<div class='main'>";
//showProfile($view);
$followers = array();
$following = array();
$result = queryMysql("SELECT * FROM friends WHERE user='$view'");
$num = $result->num_rows;
for ($j = 0; $j < $num; ++$j) {
$row = $result->fetch_array(MYSQLI_ASSOC);
$followers[$j] = $row['friend'];
}
$result = queryMysql("SELECT * FROM friends WHERE friend='$view'");
$num = $result->num_rows;
for ($j = 0; $j < $num; ++$j) {
$row = $result->fetch_array(MYSQLI_ASSOC);
$following[$j] = $row['user'];
}
$mutual = array_intersect($followers, $following);
$followers = array_diff($followers, $mutual);
$following = array_diff($following, $mutual);
$friends = FALSE;
if (sizeof($mutual)) {
echo "<h3>$name2 mutual friends</h3><ul>";
foreach ($mutual as $friend)
echo "<li><a class='username' href='members.php?view=$friend'>$friend</a>";
echo "</ul>";
$friends = TRUE;
}
if (sizeof($followers)) {
echo "<h3>$name2 followers</h3><ul>";
foreach ($followers as $friend)
echo "<li><a class='username' href='members.php?view=$friend'>$friend</a>";
echo "</ul>";
$friends = TRUE;
}
if (sizeof($following)) {
echo "<h3>$name3 following</h3><ul>";
foreach ($following as $friend)
echo "<li><a class='username' href='members.php?view=$friend'>$friend</a>";
echo "</ul>";
$friends = TRUE;
}
if (!$friends)
echo "<br>You don't have any friends yet. Why don't you <a href =\"members.php\">add</a> some?<br><br>";
echo "<div class='button'><a href='messages.php?view=$view'>" .
"View $name2 messages</a></div>";
?>
</div></div></div> </div></body></html>