-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.php
More file actions
559 lines (559 loc) Β· 14.4 KB
/
profile.php
File metadata and controls
559 lines (559 loc) Β· 14.4 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
<?php
require_once "db_connect.php";
session_start();
function addOrdinalSuffix(int $day): string
{
$remainder = $day % 100;
if ($remainder >= 11 && $remainder <= 13) {
return $day . "th";
}
return $day .
["th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"][$day % 10];
}
function prettyDate(?string $date): string
{
if (!$date) {
return "";
}
$timestamp = strtotime($date);
return addOrdinalSuffix((int) date("j", $timestamp)) .
" " .
date("F Y", $timestamp);
}
function lastLogin(string $timestamp): string
{
$seconds = time() - strtotime($timestamp);
return $seconds < 600
? "recently"
: ($seconds < 3600
? "today"
: ($seconds < 86400
? "yesterday"
: ($seconds < 604800
? "last week"
: ($seconds < 2_592_000
? "last month"
: ($seconds < 31_536_000
? "last year"
: "since the beginning of time")))));
}
function resolveLabel(?string $raw, array $labels): ?string
{
return $raw === null || $raw === "" ? null : $labels[$raw] ?? ucfirst($raw);
}
$sexOptions = [
"male" => "Male",
"female" => "Female",
"prefer-not" => "Prefer not to say",
"other" => "Other",
"yes" => "Yes, please",
"no" => "No, thanks",
"error" => "Sex not found",
];
$orientationOptions = [
"straight" => "Straight",
"gay" => "Gay",
"lesbian" => "Lesbian",
"bisexual" => "Bisexual",
"asexual" => "Asexual",
"pansexual" => "Pansexual",
"attack" => "Attack helicopter",
"portrait" => "Portrait mode",
];
$pronounsOptions = [
"he-him" => "he/him",
"she-her" => "she/her",
"they-them" => "they/them",
"ze-zir" => "ze/zir",
"any" => "any pronouns",
"burger" => "burger/king",
"sigma" => "sigma/male",
"cringe" => "cringe/based",
"copy" => "copy/paste",
"who" => "who/asked",
];
$grassOptions = [
"today" => "Today",
"week" => "This week",
"month" => "This month",
"year" => "This year",
"never" => "What's grass?",
"yesterday" => "Yesterday (lying)",
"decade" => "Decades ago",
"1000" => "I haven't heard of it in 1,000 years",
"10000" => "I haven't seen it for 10,000 years",
"minecraft" => "In Minecraft",
];
$handle = $_GET["handle"] ?? null;
if (!$handle) {
if (isset($_SESSION["handle"])) {
header(
"Location: profile.php?handle=" . urlencode($_SESSION["handle"])
);
exit();
}
header("Location: login.html");
exit();
}
try {
$pdo = getDbConnection();
$stmt = $pdo->prepare("
SELECT
*,
TIMESTAMPDIFF(YEAR, joined_at, NOW()) AS years_registered,
TIMESTAMPDIFF(DAY, joined_at, NOW()) AS days_registered,
TIMESTAMPDIFF(HOUR, joined_at, NOW()) AS hours_registered
FROM
users
WHERE
handle = ?
");
$stmt->execute([$handle]);
$user = $stmt->fetch();
if (!$user) {
header("Location: 404.php");
exit();
}
$viewerId = $_SESSION["user_id"] ?? null;
$isOwner = $viewerId && (int) $viewerId === (int) $user["user_id"];
$isPrivate = (int) $user["is_private"] === 1 && !$isOwner;
$stmt = $pdo->prepare("
SELECT
COUNT(*) AS meme_count,
COALESCE(SUM(like_count), 0) AS likes,
COALESCE(SUM(dislike_count), 0) AS cringe_count,
COALESCE(SUM(upvote_count), 0) AS based_count,
COALESCE(SUM(comment_count), 0) AS comments,
(
SELECT
COUNT(*)
FROM
follows
WHERE
following_id = ?
) AS followers
FROM
memes
WHERE
user_id = ?
AND status = 'published'
");
$stmt->execute([$user["user_id"], $user["user_id"]]);
$stats = $stmt->fetch();
if ($viewerId) {
$stmt = $pdo->prepare("
SELECT
COUNT(*)
FROM
follows
WHERE
follower_id = ?
AND following_id = ?
");
$stmt->execute([$viewerId, $user["user_id"]]);
$isFollowing = $stmt->fetchColumn() > 0;
} else {
$isFollowing = false;
}
$visibilityFilter = $isOwner ? "" : " AND visibility='public'";
$stmt = $pdo->prepare("
SELECT
AVG(spiciness)
FROM
memes
WHERE
user_id = ?
AND status = 'published' $visibilityFilter
");
$stmt->execute([$user["user_id"]]);
$avgSpiciness = number_format($stmt->fetchColumn() ?? 0, 2);
$stmt = $pdo->prepare("
SELECT
meme_id,
slug,
title,
media_url,
like_count,
comment_count,
spiciness
FROM
memes
WHERE
user_id = ?
AND status = 'published' $visibilityFilter
ORDER BY
created_at DESC
");
$stmt->execute([$user["user_id"]]);
$memes = $stmt->fetchAll();
$stmt = $pdo->prepare("
SELECT
t.name,
t.slug
FROM
tags AS t
JOIN meme_tags AS mt ON mt.tag_id = t.tag_id
WHERE
mt.meme_id = ?
");
foreach ($memes as $i => $meme) {
$stmt->execute([$meme["meme_id"]]);
$memes[$i]["tags"] = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
$badges = [];
date("md", strtotime($user["birthday"])) === date("md") &&
($badges[] = ["icon" => "π", "label" => "Happy Birthday!"]);
strtotime($user["birthday"]) < strtotime("1900-01-01") &&
($badges[] = [
"icon" => "π¦βπ₯",
"label" => "Who the hell are you?",
"description" => "Probably immortal",
]);
if ($user["birthday"]) {
$age = floor((time() - strtotime($user["birthday"])) / 31_536_000);
if ($age > 56) {
$badges[] = [
"icon" => "ε",
"label" => "Who the hell are you?",
"description" => "Adolf Hitler, FBI",
];
} elseif ($age > 42) {
$badges[] = [
"icon" => "βοΈ",
"label" => "Older than Jesus",
"description" => "Jesus Christ it's Jason Bourne",
];
}
}
$user["orientation"] === "attack" &&
($badges[] = ["icon" => "β", "label" => "Call 911"]);
switch (true) {
case $user["pronouns"] == "burger":
$badges[] = [
"icon" => "π",
"label" => [
"Kotleta inside",
"Hamburger",
"I got the burgers in the back",
][array_rand([0, 1, 2])],
"description" => "Trailler is attached",
];
break;
case $user["pronouns"] == "sigma":
$badges[] = [
"icon" => "πΊ",
"label" => "Auf",
"description" =>
"The lion and tiger may be more powerful, but the wolf does not perform in the circus",
];
break;
case $user["pronouns"] == "cringe":
$badges[] = ["icon" => "π€‘", "label" => "Clown"];
break;
case $user["pronouns"] == "who":
$badges[] = ["icon" => "π€", "label" => "Who cares?"];
break;
}
switch (true) {
case in_array(
$user["touch_grass"],
["never", "1000", "10000", "minecraft"],
true
):
$badges[] = ["icon" => "π", "label" => "Needs Vitamin D"];
break;
case in_array(
$user["touch_grass"],
["week", "month", "year", "decade"],
true
):
$badges[] = [
"icon" => "π",
"label" => "Touch Grass Reminder",
"description" => "Seriously, go outside once in a while",
];
break;
}
$user["location"] &&
($badges[] = ["icon" => "π", "label" => "Geoguessed"]);
$user["is_verified"] &&
($badges[] = ["icon" => "β
", "label" => "Verified"]);
switch (true) {
case $user["is_private"]:
$badges[] = [
"icon" => "π",
"label" => "Private",
"description" =>
"This profile is locked. Only memes are public.",
];
break;
default:
$badges[] = ["icon" => "π", "label" => "Public"];
break;
}
$user["is_admin"] && ($badges[] = ["icon" => "π‘οΈ", "label" => "Admin"]);
$user["is_banned"] && ($badges[] = ["icon" => "π«", "label" => "Banned"]);
switch (true) {
case date("md", strtotime($user["joined_at"])) === date("md"):
$badges[] = ["icon" => "π", "label" => "Today is special"];
break;
case $user["years_registered"] > 2:
$badges[] = [
"icon" => "ποΈ",
"label" => $user["years_registered"] . "y Veteran",
"description" => "Veteran memer",
];
break;
case $user["years_registered"] > 1:
$badges[] = [
"icon" => "πΏ",
"label" => "Ancient af",
"description" => "Experienced memer",
];
break;
case $user["days_registered"] >= 180:
$badges[] = [
"icon" => "β’οΈ",
"label" => "Getting rusty",
"description" => "Seasoned memer",
];
break;
case $user["days_registered"] >= 90:
$badges[] = [
"icon" => "π",
"label" => "Internet Historian",
"description" => "Remembers memes from 3 whole months ago",
];
break;
case $user["hours_registered"] >= 1000:
$badges[] = [
"icon" => "β±οΈ",
"label" => "1000h Wasted",
"description" => "Spent way too much time scrolling dank memes",
];
break;
case $user["days_registered"] >= 30:
$badges[] = [
"icon" => "π΄",
"label" => "Oldie but Goldie",
"description" => "Developing memer",
];
break;
case $user["days_registered"] >= 9:
$badges[] = ["icon" => "π
", "label" => "As time goes by"];
break;
case $user["days_registered"] >= 7:
$badges[] = [
"icon" => "π€",
"label" => "First steps",
"description" => "Baby memer",
];
break;
case $user["days_registered"] >= 1:
$badges[] = [
"icon" => "π",
"label" => "Newbie",
"description" => "Fresh meat",
];
break;
}
switch (true) {
case $stats["followers"] >= 1000:
$badges[] = [
"icon" => "πͺ",
"label" => "Dungeon Master",
"description" => "You must be doing something right",
];
break;
case $stats["followers"] >= 1:
$badges[] = [
"icon" => "β οΈ",
"label" => "Welcome to the club",
"description" => "Got your first follower!",
];
break;
}
switch (true) {
case $stats["meme_count"] >= 10000:
$badges[] = [
"icon" => "π",
"label" => "SlotAchieveName_0020: NULL",
];
break;
case $stats["meme_count"] >= 7500:
$badges[] = ["icon" => "π", "label" => "Legend"];
break;
case $stats["meme_count"] >= 5000:
$badges[] = ["icon" => "π‘", "label" => "Enlightened"];
break;
case $stats["meme_count"] >= 3500:
$badges[] = ["icon" => "π§", "label" => "Blue Blood"];
break;
case $stats["meme_count"] >= 2500:
$badges[] = ["icon" => "π¦Έ", "label" => "Hero"];
break;
case $stats["meme_count"] >= 2000:
$badges[] = ["icon" => "π€ͺ", "label" => "Maniac"];
break;
case $stats["meme_count"] >= 1500:
$badges[] = ["icon" => "π½οΈ", "label" => "Gourmet"];
break;
case $stats["meme_count"] >= 1234:
$badges[] = ["icon" => "π’", "label" => "One, Two, Three, Four"];
break;
case $stats["meme_count"] >= 1000:
$badges[] = ["icon" => "π«΅", "label" => "Point of No Return"];
break;
case $stats["meme_count"] >= 888:
$badges[] = ["icon" => "βΎοΈ", "label" => "Endless Journey"];
break;
case $stats["meme_count"] >= 750:
$badges[] = ["icon" => "π¦Ύ", "label" => "Not Even My Final Form"];
break;
case $stats["meme_count"] >= 666:
$badges[] = ["icon" => "π", "label" => "Satanic Limit?"];
break;
case $stats["meme_count"] >= 500:
$badges[] = ["icon" => "β³", "label" => "Lots of Free Time?"];
break;
case $stats["meme_count"] >= 400:
$badges[] = ["icon" => "π©", "label" => "Something to Brag About"];
break;
case $stats["meme_count"] >= 300:
$badges[] = ["icon" => "ποΈ", "label" => "Speedrunner"];
break;
case $stats["meme_count"] >= 200:
$badges[] = ["icon" => "πΆ", "label" => "Easy Stroll"];
break;
case $stats["meme_count"] >= 150:
$badges[] = ["icon" => "π", "label" => "Carefree Memer"];
break;
case $stats["meme_count"] >= 100:
$badges[] = ["icon" => "ποΈ", "label" => "My Powers Grow"];
break;
case $stats["meme_count"] >= 50:
$badges[] = [
"icon" => "π",
"label" => "This Is Just the Beginning",
];
break;
case $stats["meme_count"] >= 15:
$badges[] = ["icon" => "π", "label" => "Welcome!"];
break;
}
switch (true) {
case $stats["likes"] >= 100000:
$badges[] = [
"icon" => "π",
"label" => "Maximum Rizz - 100K+ Likes",
];
break;
case $stats["likes"] >= 50000:
$badges[] = ["icon" => "π€΄", "label" => "Gigachad"];
break;
case $stats["likes"] >= 25000:
$badges[] = ["icon" => "π", "label" => "Celebrity"];
break;
case $stats["likes"] >= 10000:
$badges[] = ["icon" => "π€", "label" => "Adorable"];
break;
case $stats["likes"] >= 5000:
$badges[] = ["icon" => "π", "label" => "Almost Famous"];
break;
case $stats["likes"] >= 1000:
$badges[] = ["icon" => "β", "label" => "Rising Star"];
break;
case $stats["likes"] >= 500:
$badges[] = ["icon" => "π", "label" => "Friendly Face"];
break;
case $stats["likes"] >= 100:
$badges[] = ["icon" => "π", "label" => "A Bit Noticed"];
break;
case $stats["likes"] >= 50:
$badges[] = ["icon" => "π", "label" => "Barely Buzzing"];
break;
case $stats["likes"] >= 10:
$badges[] = ["icon" => "πΆ", "label" => "Just Started"];
break;
}
$stats["cringe_count"] >= 228 &&
($badges[] = [
"icon" => "π©",
"label" => "Professional Shitposter",
"description" => "Quality? Who needs that when you have quantity",
]);
switch (true) {
case $stats["based_count"] >= 9000:
$badges[] = ["icon" => "π₯", "label" => "It's over 9000"];
break;
case $stats["based_count"] >= 1337:
$badges[] = [
"icon" => "π",
"label" => "Based Lord",
"description" =>
"Your content has been deemed acceptably based",
];
break;
case $stats["based_count"] >= 420:
$badges[] = [
"icon" => "πΆβπ«οΈ",
"label" => "Certified Based",
"description" => "Looks from above",
];
break;
case $stats["based_count"] >= 100:
$badges[] = ["icon" => "π―", "label" => "Century Poster"];
break;
default:
$badges[] = [
"icon" => "π±",
"label" => "Sprout",
"description" => "Just born",
];
break;
}
$total = $stats["based_count"] + $stats["cringe_count"];
if (
$total > 84 &&
$stats["based_count"] / $total > 0.42 &&
$stats["cringe_count"] / $total > 0.42
) {
$badges[] = [
"icon" => "π₯",
"label" => "Controversial Creator",
"description" =>
"You either love them or hate them, there is no in-between",
];
}
switch (true) {
case $stats["comments"] >= 50000:
$badges[] = ["icon" => "π΅", "label" => "You bought them"];
break;
case $stats["comments"] >= 500:
$badges[] = [
"icon" => "π«°",
"label" => "Social Squeezer",
"description" => "Pinching out those topβtier replies!",
];
break;
}
if ($avgSpiciness >= 0.84) {
$badges[] = ["icon" => "πΆοΈ", "label" => "Spice Lord"];
}
$fullBio = $user["bio"] ?? "";
$needsToggle = mb_strlen($fullBio) > 69;
$shortBio = $needsToggle ? mb_substr($fullBio, 0, 69) . "β¦" : $fullBio;
$sexLabel = resolveLabel($user["sex"], $sexOptions);
$orientationLabel = resolveLabel($user["orientation"], $orientationOptions);
$pronounsLabel = resolveLabel($user["pronouns"], $pronounsOptions);
$grassLabel = resolveLabel($user["touch_grass"], $grassOptions);
} catch (\PDOException $e) {
throw $e;
header("Location: status.php");
exit();
} catch (\Exception $e) {
throw $e;
exit();
}
include "profile.html";
?>