-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.php
More file actions
234 lines (214 loc) · 10.9 KB
/
Copy pathprofile.php
File metadata and controls
234 lines (214 loc) · 10.9 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php
require_once(__DIR__ . "/vendor/autoload.php");
use Promptly\Core\Prompt;
use Promptly\Core\User;
use Promptly\Core\Achievement;
use Promptly\Core\Follow;
use Promptly\Core\Like;
use Promptly\Core\Report;
session_start();
try {
if (!empty($_GET['id'])) {
if (!empty($_GET['order'])) {
$order = $_GET['order'];
} else {
$order = '';
}
$user = User::getUserById($_GET['id']);
$achievements = Achievement::getAchievementsByUserId($_GET['id']);
$prompt = new Prompt();
$prompt->setAuthorId($_GET['id']);
$prompts = $prompt->getPrompts(order: $order, approved: 1, limit: 100); // should use infinite scroll, but not enough time
} else {
throw new Exception("No user id set in the url");
}
} catch (Throwable $err) {
header("location: index");
exit();
}
if(isset($_POST['report-reason']) && isset($_POST['report-description'])){ // zegher, please check if user is logged in. Non logged in users cannot report
$report = new Report();
$report->setUserId($_GET['id']);
$report->setReason($_POST['report-reason']);
$report->setExtraInformation($_POST['report-description']);
$report->setReporterId($_SESSION['userId']);
$report->saveReport();
}
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo htmlspecialchars($user['username']); ?>'s Profile - Promptly</title>
<link rel="stylesheet" href="css/main.css">
<link rel="shortcut icon" href="assets/images/site/promptly-logo.svg" type="image/x-icon">
<link rel="stylesheet" href="css/platform.css">
<script src="assets/js/profile-follow-ajax.js" defer></script>
</head>
<body>
<?php include_once(__DIR__ . "/partials/nav.inc.php"); ?>
<main>
<?php include_once(__DIR__ . "/partials/aside.inc.php"); ?>
<div>
<header id="profile-header">
<div id="profile-header-div" class="center">
<figure style="background-image: url(<?php echo $user['profile_pic'] ?>);"></figure>
<div>
<p style="margin-bottom: -1rem;">Account</p>
<h1 id="profile-header-username"><?php echo htmlspecialchars($user['username']); ?></h1>
<div id="profile-header-information">
<?php if ($user['verified'] == 1) : ?>
<span class="verified-span">
<img src="assets/images/site/white-checkmark.svg" alt="Verified">
<span>Verified</span>
</span>
<?php endif; ?>
<span><?php echo count($prompts); ?> Prompts</span>
<span data-follower-count><?php echo Follow::getFollowerCount($_GET['id']); ?> Followers</span>
<span><?php echo Like::getLikesByUserId($_GET['id']); ?> Likes</span>
</div>
</div>
</div>
</header>
<div class="center-parent">
<div class="center" id="profile-grid">
<section id="profile-prompts">
<div id="profile-prompts-list">
<?php foreach ($prompts as $prompt) : ?>
<?php
$promptTags = json_decode($prompt['tags'], true);
$promptModel = Prompt::GetModelById($prompt['model_id']);
?>
<div>
<a href="prompt?id=<?php echo $prompt['id']; ?>" class="prompt-card-header" style="background-image: url(<?php echo $prompt['header_image']; ?>)">
<div class="prompt-card-header-model">
<img src="<?php echo $promptModel['icon']; ?>" alt="<?php echo $promptModel['name']; ?>">
<span><?php echo $promptModel['name']; ?></span>
</div>
</a>
<div class="prompt-card-body">
<div class="prompt-card-body-left">
<a class="white-a" href="prompt?id=<?php echo $prompt['id']; ?>"><?php echo htmlspecialchars($prompt['title']); ?></a>
<small class="prompt-card-tags">
<?php for ($i = 0; $i < 4 && isset($promptTags[$i]); ++$i) : ?>
<span><?php echo htmlspecialchars($promptTags[$i]); ?></span>
<?php endfor; ?>
</small>
</div>
<a href="prompt?id=<?php echo $prompt['id']; ?>" class="button prompt-card-arrow">
<img src="assets/images/site/arrow-right.svg" alt="Arrow">
</a>
</div>
</div>
<?php endforeach; ?>
</div>
</section>
<div>
<?php if (!isset($_SESSION['userId']) || $_SESSION['userId'] != $_GET['id']) : ?>
<section id="profile-action-section">
<?php if (!isset($_SESSION['loggedIn'])) : ?>
<a href="login.php" class="button">Follow</a>
<a href="login.php" id="profile-report-btn" class="button">
<img id="flag-icon" src="assets/images/site/flag.svg" alt="">
<span>Report</span>
</a>
<?php else : ?>
<?php if (!Follow::isFollowing($_SESSION['userId'], $_GET['id'])) : ?>
<a href="#" data-follow="false" class="button">Follow</a>
<?php else : ?>
<a href="#" data-follow="true" class="button">Unfollow</a>
<?php endif; ?>
<a href="#" class="button" id="profile-report-btn" onclick="showReport()">
<img id="flag-icon" src="assets/images/site/flag.svg" alt="flag">
<span>Report</span>
</a>
<?php endif; ?>
</section>
<?php endif; ?>
<section id="profile-about-section">
<h2>About</h2>
<hr class="grey-hr">
<div>
<h3>Biography</h3>
<p id="biography-container">
<?php
if (!empty($user['biography'])) {
echo nl2br(htmlspecialchars($user['biography']));
} else {
echo '<span class="grey">No biography yet...</span>';
}
?>
</p>
</div>
<div>
<h3>Achievements</h3>
<div id="profile-achievements">
<?php foreach ($achievements as $achievement) : ?>
<div class="achievement">
<img src="<?php echo $achievement['cover'] ?>" alt="<?php echo $achievement['title'] ?>">
<span><?php echo $achievement['title'] ?></span>
</div>
<?php endforeach; ?>
</div>
</div>
</section>
</div>
</div>
</div>
</div>
<?php if (isset($_SESSION['userId']) && $_SESSION['userId'] != $_GET['id']) : ?>
<div id="report-screen" style="display:none">
<h1>Report this user</h1>
<p id="close" onclick="closeReport()">X</p>
<form action="" method="POST">
<label for="report-reason">Reason</label><br>
<select name="report-reason" id="report-reason">
<option value="spam">Spam</option>
<option value="inappropriate">Inappropriate</option>
<option value="other">Other</option>
</select>
<label for="report-description"><br><br>Description</label>
<textarea name="report-description" id="report-description" cols="30" rows="10"></textarea>
<input id="rpt-btn" type="submit" value="Report">
</form>
</div>
<?php endif; ?>
</main>
</body>
<script>
var reportScrn = document.getElementById("report-screen");
var closeBtn = document.getElementById("close");
function showReport() {
reportScrn.style.display = "block";
}
function closeReport(){
reportScrn.style.display = "none";
}
const forms = document.querySelectorAll('.formpost');
forms.forEach(form => {
form.addEventListener('submit', e => {
e.preventDefault();
let id = e.target.dataset.id;
formdata = new FormData();
formdata.append('id', id);
if(e.submitter.name === 'add') {
console.log('added this as mod');
console.log(id);
fetch('ajax/make-mod.ajax.php', {
method: 'POST',
body: formdata
})
.then(
response => response.json()) //.json veranderd json naar string in js die je kan gebruiken.
.then(result => {
console.log(result);
if(result.status === 'success') {
e.target.parentElement.parentElement.remove();
}
})
}
});
});
</script>
</html>