-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
executable file
·183 lines (145 loc) · 8.21 KB
/
Copy pathindex.php
File metadata and controls
executable file
·183 lines (145 loc) · 8.21 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
include_once "php_files/header.php";
require_once '/var/www/dbhInc.php';
include 'php_files/includes/commentsInc.php';
?>
<head>
<link rel="stylesheet" href="https://webtech-bg2.webtech-uva.nl/php_files/css_files/index_styles.css">
</head>
<section class="scroll-section">
<div class="scroll-part">
<?php if (isset($_SESSION["usersId"])) { ?>
<h2>Post Your Hot Take!</h2>
<form action="php_files/includes/uploadInc.php" class ="discussion-input" method="post">
<input type="text" name ="url" placeholder ="Paste or drag URL here..."><br>
<input type="text" name ="post" maxlength="150" placeholder = "Hot Take..."><br><br>
<input type="hidden" name="table" value="music_posts">
<button type="Submit" name="submit">Submit Hot Take</button>
</form>
<?php }?>
<h2>Hot Takes</h2>
<section class="posts">
<?php
$sql = "SELECT * FROM music_posts ORDER BY postsTIMESTAMP DESC";
$result = mysqli_query($conn, $sql);
$counter = 0;
while ($counter < 10 && $row = mysqli_fetch_assoc($result)) {
$user_id = $row['user_id'];
$sql = "SELECT usersUid FROM users WHERE usersId = $user_id";
$result_user = mysqli_query($conn, $sql);
$user_row = mysqli_fetch_assoc($result_user);
$username = $user_row['usersUid'];
// Output username boven de embed
//echo '@'.$username . "<br>";
echo '<a href="https://webtech-bg2.webtech-uva.nl/php_files/user.php?id='.$username.'">@'.$username.'</a><br>';
if (strpos($row['postsURL'], 'embed') !== true) {
$modifiedURL = str_replace('.com/', '.com/embed/', $row['postsURL']);
} else {
$modifiedURL = $row['postsURL'];
}
// Voorkomen dat er teveel requests naar spotify gaan
echo '<iframe style="border-radius: 12px" src="' . $modifiedURL . '" width="100%" height="100" frameborder="0" allowfullscreen="" allow="autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture" loading="lazy"></iframe><br>';
// echo $row['username'] . ": " . $row['postsPOST'] . "<br>";
// Output de post onder de embed
echo $row['postsPOST'];
// Voeg andere velden toe zoals nodig
echo "<hr>"; // Voeg een scheidingsteken toe tussen records
$counter++;
}
?>
</section>
</div>
<aside class="friends">
<!-- Big Posts -->
<?php if (isset($_SESSION["usersId"])) { ?>
<form action="php_files/includes/uploadInc.php" class ="discussion-input" method="post">
<input type="text" name ="url" placeholder ="Write a title here..."><br>
<input type="text" name ="post" placeholder = "Big post..."><br><br>
<input type="hidden" name="table" value="big_posts">
<button type="Submit" name="submit">Submit your text post!</button>
</form>
<section class="posts">
<?php
$sql = "SELECT * FROM big_posts ORDER BY postsTIMESTAMP DESC";
$result = mysqli_query($conn, $sql);
$counter = 0;
while ($row = mysqli_fetch_assoc($result)) {
$user_id = $row['user_id'];
// check following
$huidige_gebruiker_id = $_SESSION['usersId'];
// Check of de gebruikers elkaar al volgen
$query_follow_check = "SELECT * FROM friends WHERE user_ID_1 = $huidige_gebruiker_id AND user_ID_2 = $user_id";
$result_follow_check = $conn->query($query_follow_check);
$following = $result_follow_check->num_rows > 0;
// laat alleen je eigen posts zien
if ($following || $user_id = $huidige_gebruiker_id) {
$sql = "SELECT usersUid FROM users WHERE usersId = $user_id";
$result_user = mysqli_query($conn, $sql);
$user_row = mysqli_fetch_assoc($result_user);
$username = $user_row['usersUid'];
echo "<div class='bigpost'>";
// Output username boven de embed
echo "<div class=comment></div>";
echo '<a href="https://webtech-bg2.webtech-uva.nl/php_files/user.php?id='.$username.'">@'.$username.'</a><br>';
echo '<h3>'.$row['postsURL'] . "</h3><br>";
// Output de post onder de titel
echo $row['postsPOST'];
echo "</div";
echo "<hr>";
getComments($conn, $row['postsID'],'index.php');
// Voeg andere velden toe zoals nodig
echo"<form method='POST' action='".setComment($conn,$row['postsID'],'index.php')."'>
<input type='hidden' name='usersId' value='".$_SESSION['usersId']."'>
<input type='hidden' name='date' value='".date('Y-m-d H:i:s')."'>
<input type='hidden' name='postId' value='".$row['postsID']."'>
<textarea name='message'></textarea><br>
<button type='submit' name='commentSubmit".$row['postsID']."'>Comment</button>
</form><br><br>";
echo "</div>";
echo "<br><br>";
}
}
?>
</section>
<?php } else {?>
<h3>Log in <a href=/php_files/login.php>here</a> to see your friends' posts!</h3>
<?php }?>
<ul>
<?php
// if (isset($_SESSION['usersId'])){
// $huidige_gebruiker_id = $_SESSION['usersId'];
// $query = "SELECT user_ID_2 FROM friends WHERE user_ID_1 = $huidige_gebruiker_id";
// $result = $conn->query($query);
// // Array om vrienden-ID's op te slaan
// $vrienden_ids = array();
// if ($result->num_rows > 0) {
// while ($row = $result->fetch_assoc()) {
// $vrienden_ids[] = $row['user_ID_2'];
// }
// }
// // Als er vrienden zijn, haal hun gebruikersnaam, naam en profielfoto op
// if (!empty($vrienden_ids)) {
// $vrienden_ids_string = implode(",", $vrienden_ids);
// $query_vrienden_info = "SELECT usersName, usersUid FROM users WHERE usersId IN ($vrienden_ids_string)";
// $result_vrienden_info = $conn->query($query_vrienden_info);
// if (!empty($vrienden_ids) && $result_vrienden_info->num_rows > 0) {
// while ($row_vriend = $result_vrienden_info->fetch_assoc()) {
// echo "<div>";
// echo "<p>Gebruikersnaam: <a href='profile_friend.php?id=" . $row_vriend['usersUid'] . "'>".$row_vriend['usersUid'] . "</a></p>";
// echo "<p>Naam: " . $row_vriend['usersName'] . "</p>";
// echo "</div>";
// }
// } else {
// echo "<div>";
// echo "Je hebt nog geen vrienden.";
// echo "<div>";
// }
// }
// }
?>
</ul>
</aside>
</section>
<?php
include_once("php_files/footer.php");
?>