-
Notifications
You must be signed in to change notification settings - Fork 2
/
functions.php
1017 lines (902 loc) · 35.5 KB
/
functions.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
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
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Handy and frequently used functions for WYDRN
*
* @version PHP 8.0.12
* @since March 2022
* @author AtharvaShah
*/
/*
Checks if a user is logged in and is valid. If yes, redirects to the login page. Important to start the session in order to perform the check_login function. Use session_start(); in pages that you wish to use this function.
*/
function check_login($con)
{
if (isset($_SESSION['user_id'])) {
$id = $_SESSION['user_id'];
$query = "select * from `users` where `user_id` = '$id' limit 1";
$result = mysqli_query($con, $query);
if ($result && mysqli_num_rows($result) > 0) {
$user_data = mysqli_fetch_assoc($result);
return $user_data;
}
}
}
/*
Generates a random 5 to 20-digit number that is to be used to generate dynamic userIDs
*/
function random_num($length)
{
$text = "";
if ($length < 5) {
$length = 5;
}
$len = rand(4, $length);
for ($i = 0; $i < $len; $i++) {
$text .= rand(0, 9);
}
return $text;
}
/*
Sends an Email requesting verification of the account to the recipient.
*/
function mailer_verify_email($recipient)
{
require "connection.php";
require "PHPMailer/Exception.php";
require "PHPMailer/PHPMailer.php";
require "PHPMailer/SMTP.php";
$user_data = check_login($con);
$username = $user_data['user_name'];
$hashed_verify = md5($username);
$mail = new PHPMailer\PHPMailer\PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 0 = messages only, 1 = errors + messages
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "REPLACE_THIS_WITH_YOUR_MAIL";
$mail->Password = "REPLACE_THIS_WITH_YOUR_PASS"; //Google Account -> Security -> App Passwords
$mail->SetFrom("REPLACE_THIS_WITH_YOUR_MAIL");
$mail->Subject = "WYDRN - Verify Your Email";
//mailer body start
$mailerbody = "<button style='padding:20px;'>";
$mailerbody .= "<a style='text-decoration: none;' href='localhost/WYDRN/verify.php?link=$hashed_verify'>Click the link below to verify your Account and get access to all the features.</a>";
$mailerbody .= '</button>';
//mailer body end
$mail->Body = $mailerbody;
$mail->AddAddress($recipient);
if (!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
return 0;
} else {
// echo "Message has been sent";
return 1;
}
}
/*
Sends an Email with Reset Password Link.
*/
function send_reset_link($recipient, $link)
{
require "PHPMailer/Exception.php";
require "PHPMailer/PHPMailer.php";
require "PHPMailer/SMTP.php";
$mail = new PHPMailer\PHPMailer\PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 0 = messages only, 1 = errors + messages
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "REPLACE_THIS_WITH_YOUR_MAIL";
$mail->Password = "REPLACE_THIS_WITH_YOUR_PASS"; //Google Account -> Security -> App Passwords
$mail->SetFrom("REPLACE_THIS_WITH_YOUR_MAIL");
$mail->Subject = "WYDRN - Reset Password";
$mail->Body = $link;
$mail->AddAddress($recipient);
if (!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
return 0;
} else {
// echo "Message has been sent";
return 1;
}
}
/*
Sends an Email notifying the user that their password has been changed.
*/
function send_password_reset_notif($recipient, $link)
{
require "PHPMailer/Exception.php";
require "PHPMailer/PHPMailer.php";
require "PHPMailer/SMTP.php";
$mail = new PHPMailer\PHPMailer\PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 0 = messages only, 1 = errors + messages
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "REPLACE_THIS_WITH_YOUR_MAIL";
$mail->Password = "REPLACE_THIS_WITH_YOUR_PASS"; //Google Account -> Security -> App Passwords
$mail->SetFrom("REPLACE_THIS_WITH_YOUR_MAIL");
$mail->Subject = "WYDRN - Your Password has been reset";
$mail->Body = $link;
$mail->AddAddress($recipient);
if (!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
return 0;
} else {
// echo "Message has been sent";
return 1;
}
}
/*
Returns whether a user account is verified or not (1 - Verified || 0 - Not Verified)
Used in Edit Profile page to determine
*/
function check_verified_status($username)
{
require "connection.php";
$sql = "SELECT `verified` FROM users WHERE `user_name`='$username'";
if ($query = mysqli_query($con, $sql)) {
if (mysqli_num_rows($query) == 1) {
$row = mysqli_fetch_array($query);
return $row['verified'];
} else {
die('That user does not exist' . mysqli_error($con));
}
}
mysqli_close($con);
}
/*
Sets a user account is verified or not (1 - Verified || 0 - Not Verified).
*/
function set_verified($username)
{
require "connection.php";
$sql = "UPDATE users SET verified=1 WHERE user_name='$username'";
if (mysqli_query($con, $sql)) {
return 1;
} else {
echo "User does not exist";
return 0;
}
}
/*
Checks whether a user is active or not (1 - Active || 0 - Inactive)
*/
function check_active_status($username)
{
require "connection.php";
$sql = "SELECT active FROM users WHERE user_name='$username'";
if ($query = mysqli_query($con, $sql)) {
if (mysqli_num_rows($query) == 1) {
$row = mysqli_fetch_array($query);
return $row['active'];
} else {
die('That user does not exist' . mysqli_error($con));
}
}
mysqli_close($con);
}
/*
Sets a user account status as active (Returns 1 - Set Active Successfully || 0 - Error in Setting Active)
Called when user logins
*/
function set_active($username)
{
require "connection.php";
$sql = "UPDATE users SET active=1 WHERE user_name='$username'";
if (mysqli_query($con, $sql)) {
return 1;
} else {
echo "User does not exist";
return 0;
}
}
/*
Sets a user account status as inactive (Returns 1 - Set inactive Successfully || 0 - Error in Setting inactive)
Called when user logouts
*/
function set_inactive($username)
{
require "connection.php";
$sql = "UPDATE users SET active=0 WHERE user_name='$username'";
if (mysqli_query($con, $sql)) {
return 1;
} else {
echo "User does not exist";
return 0;
}
}
/*
Used to pass the datetime and return a printable and user-friendly datetime format D:M:Y H:M:AM/PM
*/
function printable_datetime($datetime)
{
$datetime = date("F j Y | g:i A", strtotime($datetime));
return $datetime;
}
function printable_date($date)
{
$date = date("F j, Y", strtotime($date));
return $date;
}
/*
Get total mutual media count between two users
*/
function get_mutual_media_count($user1, $user2)
{
require "connection.php";
$array = array();
// mutual video game count
$sql = "SELECT count(*) FROM(SELECT videogame FROM data WHERE username='$user1' AND videogame != ''
INTERSECT
SELECT videogame FROM data WHERE username='$user2' AND videogame != '') I";
if ($query = mysqli_query($con, $sql)) {
if (mysqli_num_rows($query) > 0) {
$row = mysqli_fetch_array($query);
$mutual_videogame_count = $row[0];
} else {
die('Could not get the records' . mysqli_error($con));
}
}
// mutual album count
$sql = "SELECT COUNT(*) FROM(SELECT album, artist FROM data WHERE username='$user1' AND album!='' AND artist!=''
INTERSECT
SELECT album, artist FROM data WHERE username='$user2' AND album!='' AND artist!='') I";
if ($query = mysqli_query($con, $sql)) {
if (mysqli_num_rows($query) > 0) {
$row = mysqli_fetch_array($query);
$mutual_album_count = $row[0];
} else {
die('Could not get the records' . mysqli_error($con));
}
}
// mutual book count
$sql = "SELECT COUNT(*) FROM(SELECT book, author FROM data WHERE username='$user1' AND book!='' AND author!=''
INTERSECT
SELECT book, author FROM data WHERE username='$user2' AND book!='' AND author!='') I";
if ($query = mysqli_query($con, $sql)) {
if (mysqli_num_rows($query) > 0) {
$row = mysqli_fetch_array($query);
$mutual_book_count = $row[0];
} else {
die('Could not get the records' . mysqli_error($con));
}
}
// mutual movie count
$sql = "SELECT COUNT(*) FROM(SELECT movie, year FROM data WHERE username='$user1' AND movie!='' AND year!=''
INTERSECT
SELECT movie, year FROM data WHERE username='$user2' AND movie!='' AND year!='') I";
if ($query = mysqli_query($con, $sql)) {
if (mysqli_num_rows($query) > 0) {
$row = mysqli_fetch_array($query);
$mutual_movie_count = $row[0];
} else {
die('Could not get the records' . mysqli_error($con));
}
}
// mutual tv show count
$sql = "SELECT count(*) FROM(SELECT tv FROM data WHERE username='$user1' AND tv != ''
INTERSECT
SELECT tv FROM data WHERE username='$user2' AND tv != '') I";
if ($query = mysqli_query($con, $sql)) {
if (mysqli_num_rows($query) > 0) {
$row = mysqli_fetch_array($query);
$mutual_tvshow_count = $row[0];
} else {
die('Could not get the records' . mysqli_error($con));
}
}
mysqli_close($con);
$total_mutual_count = $mutual_videogame_count + $mutual_album_count + $mutual_book_count + $mutual_movie_count + $mutual_tvshow_count;
// push videogame count
array_push($array, $mutual_videogame_count, $mutual_album_count, $mutual_book_count, $mutual_movie_count, $mutual_tvshow_count, $total_mutual_count);
/*$array will look like
[0]=>videogame count,
[1]=>album count,
[2]=>book count,
[3]=>movie count,
[4]=>tvshow count,
[5]=>total mutual count
*/
return $array;
}
/*executes any given SQL query and returns the first row of the result set.*/
function executeSQL($con, $sql)
{
if ($query = mysqli_query($con, $sql)) {
$row = mysqli_fetch_array($query);
if (isset($row[0])) {
return $row[0];
} else {
return '--';
}
} else {
echo mysqli_error($con);
}
}
/*Return a random image from the assets/abstract folder - to be used in feed.php*/
function randomImage()
{
$images = [
"images/website/assets/abstract/1.jpg",
"images/website/assets/abstract/3.jpg",
"images/website/assets/abstract/4.jpg",
"images/website/assets/abstract/7.jpg",
"images/website/assets/abstract/9.jpg",
"images/website/assets/abstract/10.jpg",
"images/website/assets/abstract/11.jpg",
"images/website/assets/abstract/12.jpg",
"images/website/assets/abstract/15.jpg",
"images/website/assets/abstract/17.jpg",
"images/website/assets/abstract/18.jpg",
"images/website/assets/abstract/19.jpg",
"images/website/assets/abstract/20.jpg",
"images/website/assets/abstract/21.jpg",
"images/website/assets/abstract/22.jpg",
"images/website/assets/abstract/23.jpg",
"images/website/assets/abstract/24.jpg",
"images/website/assets/abstract/25.jpg",
"images/website/assets/abstract/25.jpg",
"images/website/assets/abstract/25.jpg",
"images/website/assets/abstract/25.jpg",
"images/website/assets/abstract/25.jpg",
"images/website/assets/abstract/26.jpg",
"images/website/assets/abstract/27.jpg",
"images/website/assets/abstract/28.jpg",
"images/website/assets/abstract/29.jpg",
"images/website/assets/abstract/30.jpg",
"images/website/assets/abstract/31.jpg",
"images/website/assets/abstract/32.jpg",
"images/website/assets/abstract/33.jpg",
"images/website/assets/abstract/34.jpg",
"images/website/assets/abstract/35.jpg",
"images/website/assets/abstract/36.jpg",
"images/website/assets/abstract/37.jpg",
"images/website/assets/abstract/38.jpg",
"images/website/assets/abstract/39.jpg",
"images/website/assets/abstract/40.jpg",
"images/website/assets/abstract/41.jpg",
"images/website/assets/abstract/42.jpg",
"images/website/assets/abstract/43.jpg",
"images/website/assets/abstract/44.jpg",
"images/website/assets/abstract/47.jpg",
"images/website/assets/abstract/48.jpg",
"images/website/assets/abstract/49.jpg",
"images/website/assets/abstract/51.jpg",
"images/website/assets/abstract/52.jpg",
"images/website/assets/abstract/53.jpg",
"images/website/assets/abstract/54.jpg",
"images/website/assets/abstract/56.jpg",
"images/website/assets/abstract/57.jpg",
"images/website/assets/abstract/58.jpg",
];
$rand_keys = array_rand($images, 1);
return $images[$rand_keys];
}
/*Return a random video that will be used on login page as background*/
function randomVideo()
{
$videos = [
"images/website/assets/videos/1.mp4",
"images/website/assets/videos/2.mp4",
"images/website/assets/videos/3.mp4",
"images/website/assets/videos/4.mp4",
"images/website/assets/videos/5.mp4",
"images/website/assets/videos/6.mp4",
"images/website/assets/videos/7.mp4",
"images/website/assets/videos/8.mp4",
"images/website/assets/videos/9.mp4",
"images/website/assets/videos/10.mp4",
"images/website/assets/videos/11.mp4",
"images/website/assets/videos/12.mp4",
];
$rand_keys = array_rand($videos, 1);
return $videos[$rand_keys];
}
function getRandomGradient()
{
$gradients = [
"linear-gradient(90deg, #1CB5E0 0%, #000851 100%);",
"linear-gradient(90deg, #00C9FF 0%, #92FE9D 100%)",
"linear-gradient(90deg, #FC466B 0%, #3F5EFB 100%)",
"linear-gradient(90deg, #FDBB2D 0%, #22C1C3 100%)",
"linear-gradient(90deg, #9ebd13 0%, #008552 100%)",
"linear-gradient(90deg, #0700b8 0%, #00ff88 100%)",
"linear-gradient(90deg, #d53369 0%, #daae51 100%)",
"linear-gradient(90deg, #efd5ff 0%, #515ada 100%)",
"linear-gradient(90deg, #00d2ff 0%, #3a47d5 100%)",
"linear-gradient(90deg, #f8ff00 0%, #3ad59f 100%)",
"linear-gradient(90deg, #fcff9e 0%, #c67700 100%)",
"linear-gradient(90deg, #00DBDE 0%, #FC00FF 100%)",
"linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%)",
"linear-gradient(147deg, #FFE53B 0%, #FF2525 74%)",
"linear-gradient(0deg, #08AEEA 0%, #2AF598 100%)",
"linear-gradient(45deg, #FA8BFF 0%, #2BD2FF 52%, #2BFF88 90%)",
"linear-gradient(45deg, #FA8BFF 0%, #2BD2FF 52%, #2BFF88 90%)",
];
return $gradients[array_rand($gradients)];
}
/*Return a random quote to be used on media_book.php*/
function getRandomBookQuote()
{
$bookquotes = [
"Nothing is insoluble. Nothing is hopeless. Not while there's life. - Alan Moore",
"So many books, so little time.- Frank Zappa",
"Not all those who wander are lost. - J.R.R. Tolkein",
"Those who don’t believe in magic will never find it. — Roald Dahl",
"The worst enemy to creativity is self-doubt. - Sylvia Plath",
"Even the darkest night will end and the sun will rise. - Victor Hugo",
"If a book is well written, I always find it too short. ― Jane Austen",
"There is no Friend as Loyal as a Book – Ernest Hemingway",
];
return $bookquotes[array_rand($bookquotes)];
}
/*Return a random quote to be used on media_movie.php*/
function getRandomMovieQuote()
{
$moviequotes = [
"Every man dies, but not every man really lives. – William Wallace",
"Great men are not born great, they grow great. – Mario Puzo",
"It’s what you do right now that makes a difference. – Struecker",
"Our lives are defined by opportunities, even the ones we miss. – Benjamin Button",
"I figure life's a gift and I don't intend on wasting it. - Titanic",
"The very things that hold you down are going to lift you up. - Timothy Mouse",
"All we have to decide is what to do with the time that is given to us. - Gandalf",
"Carpe diem. Seize the day, boys. Make your lives extraordinary. - John Keating",
];
return $moviequotes[array_rand($moviequotes)];
}
/*Return a random quote to be used on media_tv.php*/
function getRandomTvQuote()
{
$tvquotes = [
"You aim at the king, you best not miss. — The Wire",
"Don’t be sorry, be fierce. - Ru Paul's Drag Race",
"Treat yo’self. - Parks and Recreation",
"Learning requires failure. - Atlanta",
"You don't win alone. That's how it is. - Haikyuu",
"All the angels are gone, son. There's only devils left. - Yellowstone",
"You can’t play God without being acquainted with the devil. - Westworld",
"Evil is evil. Lesser, greater, middling, it’s all the same. - The Witcher",
"Sometimes we are what we are, and we should embrace that. - Lucifer",
"He who fights by the sword, dies by it. - Peaky Blinders",
"It might be stormy now, but it can’t rain forever. - Outer Banks",
];
return $tvquotes[array_rand($tvquotes)];
}
/*Return a random quote to be used on media_videogame.php*/
function getRandomVideoGameQuote()
{
$videogamequotes = [
"No gods or kings. Only man. - BioShock",
"Don't wish it were easier, wish you were better. - Animal Crossing",
"Good men mean well. We just don't always end up doing well. - Dead Space 3",
"War. War never changes. - Fallout 3",
"Endure and survive. - The Last Of Us",
"Life is all about resolve. Outcome is secondary. - Okami",
];
return $videogamequotes[array_rand($videogamequotes)];
}
/*Return a random quote to be used on media_music.php*/
function getRandomAlbumQuote()
{
$albumquotes = [
"Lose your dreams and you might lose your mind. - Mick Jagger",
"One good thing about music, when it hits you, you feel no pain. - Bob Marley",
"Life is what happens when you’re making other plans. - John Lennon",
"Music can change the world because it can change people. - Bono",
"Too many pieces of music finish too long after the end. - Igor Stravinsky",
"Without deviation from the norm, progress is not possible. - Frank Zappa",
"Imagination creates reality. - Richard Wagner",
"Dare to wear the foolish clown face. - Frank Sinatra",
"I close my eyes and seize it, I light my torch and burn it - Death Grips",
];
return $albumquotes[array_rand($albumquotes)];
}
/*Return a prinatable date of member joining to display it on their respective profiles*/
function getDateofJoining($con, $username)
{
$date_joined = executeSQL($con, "SELECT `date` FROM `users` where `user_name`='$username'");
$date_joined = strtotime($date_joined);
return date("M jS, Y", $date_joined);
}
/*************
TOTAL MEDIA COUNT
*************/
function getTotalMediaCount($con, $username)
{
$sql = "SELECT sum(allcount) AS Total_Count FROM(
(SELECT count(`videogame`) as allcount FROM `data` where `username`='$username' AND videogame!='')
UNION ALL
(SELECT count(album) AS allcount FROM `data` where `username`='$username' AND album!='')
UNION ALL
(SELECT count(book) AS allcount FROM `data` where `username`='$username' AND book!='')
UNION ALL
(SELECT count(movie) AS allcount FROM `data` where `username`='$username' AND movie!='')
UNION ALL
(SELECT count(tv) AS allcount FROM `data` where `username`='$username' AND tv!='')
)t";
return executeSQL($con, $sql);
}
/*************
TOTAL MEDIA COUNT UNIQUE
*************/
function getTotalMediaCountUnique($con, $username)
{
$sql = "SELECT sum(allcount) AS Total_Count FROM(
(SELECT count(DISTINCT `videogame`) as allcount FROM `data` where `username`='$username' AND videogame!='')
UNION ALL
(SELECT count(DISTINCT `album`) AS allcount FROM `data` where `username`='$username' AND album!='')
UNION ALL
(SELECT count(DISTINCT `book`) AS allcount FROM `data` where `username`='$username' AND book!='')
UNION ALL
(SELECT count(DISTINCT `movie`) AS allcount FROM `data` where `username`='$username' AND movie!='')
UNION ALL
(SELECT count(DISTINCT `tv`) AS allcount FROM `data` where `username`='$username' AND tv!='')
)t";
return executeSQL($con, $sql);
}
/*************
TOTAL MEDIA ADDED LAST WEEK
*************/
function getTotalMediaAddedLastWeek($con, $username)
{
$sql = "SELECT sum(allcount) AS Total_Count FROM(
(SELECT count(`videogame`) as allcount FROM `data` where `username`='$username' AND videogame!='' AND DATE(date) >= CURDATE() - INTERVAL 7 DAY)
UNION ALL
(SELECT count(album) AS allcount FROM `data` where `username`='$username' AND album!='' AND DATE(date) >= CURDATE() - INTERVAL 7 DAY)
UNION ALL
(SELECT count(book) AS allcount FROM `data` where `username`='$username' AND book!='' AND DATE(date) >= CURDATE() - INTERVAL 7 DAY)
UNION ALL
(SELECT count(movie) AS allcount FROM `data` where `username`='$username' AND movie!='' AND DATE(date) >= CURDATE() - INTERVAL 7 DAY)
UNION ALL
(SELECT count(tv) AS allcount FROM `data` where `username`='$username' AND tv!='' AND DATE(date) >= CURDATE() - INTERVAL 7 DAY)
)t ";
return executeSQL($con, $sql);
}
/*************
TOTAL MEDIA ADDED LAST MONTH
*************/
function getTotalMediaAddedLastMonth($con, $username)
{
$sql = "SELECT sum(allcount) AS Total_Count FROM(
(SELECT count(`videogame`) as allcount FROM `data` where `username`='$username' AND videogame!='' AND DATE(date) >= CURDATE() - INTERVAL 30 DAY)
UNION ALL
(SELECT count(album) AS allcount FROM `data` where `username`='$username' AND album!='' AND DATE(date) >= CURDATE() - INTERVAL 30 DAY)
UNION ALL
(SELECT count(book) AS allcount FROM `data` where `username`='$username' AND book!='' AND DATE(date) >= CURDATE() - INTERVAL 30 DAY)
UNION ALL
(SELECT count(movie) AS allcount FROM `data` where `username`='$username' AND movie!='' AND DATE(date) >= CURDATE() - INTERVAL 30 DAY)
UNION ALL
(SELECT count(tv) AS allcount FROM `data` where `username`='$username' AND tv!='' AND DATE(date) >= CURDATE() - INTERVAL 30 DAY)
)t ";
return executeSQL($con, $sql);
}
/*************
TOTAL MEDIA ADDED LAST 3 MONTHS
*************/
function getTotalMediaAddedLast3Months($con, $username)
{
$sql = "SELECT sum(allcount) AS Total_Count FROM(
(SELECT count(`videogame`) as allcount FROM `data` where `username`='$username' AND videogame!='' AND DATE(date) >= CURDATE() - INTERVAL 90 DAY)
UNION ALL
(SELECT count(album) AS allcount FROM `data` where `username`='$username' AND album!='' AND DATE(date) >= CURDATE() - INTERVAL 90 DAY)
UNION ALL
(SELECT count(book) AS allcount FROM `data` where `username`='$username' AND book!='' AND DATE(date) >= CURDATE() - INTERVAL 90 DAY)
UNION ALL
(SELECT count(movie) AS allcount FROM `data` where `username`='$username' AND movie!='' AND DATE(date) >= CURDATE() - INTERVAL 90 DAY)
UNION ALL
(SELECT count(tv) AS allcount FROM `data` where `username`='$username' AND tv!='' AND DATE(date) >= CURDATE() - INTERVAL 90 DAY)
)t ";
return executeSQL($con, $sql);
}
/*************
TOTAL MEDIA ADDED LAST 6 MONTHS
*************/
function getTotalMediaAddedLast6Months($con, $username)
{
$sql = "SELECT sum(allcount) AS Total_Count FROM(
(SELECT count(`videogame`) as allcount FROM `data` where `username`='$username' AND videogame!='' AND DATE(date) >= CURDATE() - INTERVAL 180 DAY)
UNION ALL
(SELECT count(album) AS allcount FROM `data` where `username`='$username' AND album!='' AND DATE(date) >= CURDATE() - INTERVAL 180 DAY)
UNION ALL
(SELECT count(book) AS allcount FROM `data` where `username`='$username' AND book!='' AND DATE(date) >= CURDATE() - INTERVAL 180 DAY)
UNION ALL
(SELECT count(movie) AS allcount FROM `data` where `username`='$username' AND movie!='' AND DATE(date) >= CURDATE() - INTERVAL 180 DAY)
UNION ALL
(SELECT count(tv) AS allcount FROM `data` where `username`='$username' AND tv!='' AND DATE(date) >= CURDATE() - INTERVAL 180 DAY)
)t ";
return executeSQL($con, $sql);
}
/*************
TOTAL MEDIA ADDED LAST YEAR
*************/
function getTotalMediaAddedLastYear($con, $username)
{
$sql = "SELECT sum(allcount) AS Total_Count FROM(
(SELECT count(`videogame`) as allcount FROM `data` where `username`='$username' AND videogame!='' AND DATE(date) >= CURDATE() - INTERVAL 365 DAY)
UNION ALL
(SELECT count(album) AS allcount FROM `data` where `username`='$username' AND album!='' AND DATE(date) >= CURDATE() - INTERVAL 365 DAY)
UNION ALL
(SELECT count(book) AS allcount FROM `data` where `username`='$username' AND book!='' AND DATE(date) >= CURDATE() - INTERVAL 365 DAY)
UNION ALL
(SELECT count(movie) AS allcount FROM `data` where `username`='$username' AND movie!='' AND DATE(date) >= CURDATE() - INTERVAL 365 DAY)
UNION ALL
(SELECT count(tv) AS allcount FROM `data` where `username`='$username' AND tv!='' AND DATE(date) >= CURDATE() - INTERVAL 365 DAY)
)t ";
return executeSQL($con, $sql);
}
/*************
TOTAL BOOKS COUNT
*************/
function getTotalBooksCount($con, $username)
{
$sql = "SELECT count(book) AS Total_Count FROM `data` where `username`='$username' AND book!=''";
return executeSQL($con, $sql);
}
/*************
TOTAL BOOKS COUNT UNIQUE
*************/
function getTotalBooksCountUnique($con, $username)
{
$sql = "SELECT count(DISTINCT `book`) AS Total_Count FROM `data` where `username`='$username' AND book!=''";
return executeSQL($con, $sql);
}
/*************
Favorite BOOK -> MOST REPEATEDLY LOGGED (IF NO DUPLICATES AT ALL, THEN SAY 'NONE')
*************/
function getFavoriteBook($con, $username)
{
$sql = "SELECT book, count(book) as favorites FROM `data` where username='$username' and book!='' GROUP BY book HAVING count(book)>1 ORDER BY count(book) DESC LIMIT 5";
return executeSQL($con, $sql);
}
/*************
Favorite AUTHOR -> MOST REPEATEDLY LOGGED (IF NO DUPLICATES AT ALL, THEN SAY 'NONE')
*************/
function getFavoriteAuthor($con, $username)
{
$sql = "SELECT author, count(author) as favorites FROM `data` where username='$username' and author!='' GROUP BY book HAVING count(author)>1 ORDER BY count(author) DESC LIMIT 5";
return executeSQL($con, $sql);
}
/*************
TOTAL MOVIE COUNT
*************/
function getTotalMoviesCount($con, $username)
{
$sql = "SELECT count(`movie`) AS Total_Count FROM `data` where `username`='$username' AND movie!=''";
return executeSQL($con, $sql);
}
/*************
TOTAL MOVIE COUNT UNIQUE
*************/
function getTotalMoviesCountUnique($con, $username)
{
$sql = "SELECT count(DISTINCT `movie`) AS Total_Count FROM `data` where `username`='$username' AND movie!=''";
return executeSQL($con, $sql);
}
/*************
Favorite MOVIE
*************/
function getFavoriteMovie($con, $username)
{
$sql = "SELECT movie, count(movie) as favorites FROM `data` where username='$username' and movie!='' GROUP BY movie HAVING count(movie)>1 ORDER BY count(movie) DESC LIMIT 5";
return executeSQL($con, $sql);
}
/*************
TOTAL TV SHOW COUNT
*************/
function getTotalTVCount($con, $username)
{
$sql = "SELECT count(`tv`) AS Total_Count FROM `data` where `username`='$username' AND tv!=''";
return executeSQL($con, $sql);
}
/*************
TOTAL TV SHOW COUNT UNIQUE
*************/
function getTotalTVCountUnique($con, $username)
{
$sql = "SELECT count(DISTINCT `tv`) AS Total_Count FROM `data` where `username`='$username' AND tv!=''";
return executeSQL($con, $sql);
}
/*************
Favorite TV SHOW
*************/
function getFavoriteTV($con, $username)
{
$sql = "SELECT tv, count(tv) as favorites FROM `data` where username='$username' and tv!='' GROUP BY tv HAVING count(tv)>1 ORDER BY count(tv) DESC LIMIT 5";
return executeSQL($con, $sql);
}
/*************
Favorite STREAMING PLATFORM
*************/
function getFavoriteStreamingPlatform($con, $username)
{
$sql = "SELECT streaming, count(streaming) as favorites FROM `data` where username='$username' and streaming!='' GROUP BY streaming HAVING count(streaming)>1 ORDER BY count(streaming) DESC LIMIT 5";
return executeSQL($con, $sql);
}
/*************
TOTAL VIDEOGAME COUNT
*************/
function getTotalVideoGameCount($con, $username)
{
$sql = "SELECT count(`videogame`) AS Total_Count FROM `data` where `username`='$username' AND videogame!=''";
return executeSQL($con, $sql);
}
/*************
TOTAL VIDEOGAME COUNT UNIQUE
*************/
function getTotalVideoGameCountUnique($con, $username)
{
$sql = "SELECT count(DISTINCT `videogame`) AS Total_Count FROM `data` where `username`='$username' AND videogame!=''";
return executeSQL($con, $sql);
}
/*************
Favorite GAMING PLATFORM -> MOST REPEATEDLY LOGGED
*************/
function getFavoriteGamingPlatform($con, $username)
{
$sql = "SELECT platform, count(platform) as favorites FROM `data` where username='$username' and platform!='' GROUP BY platform HAVING count(platform)>1 ORDER BY count(platform) DESC LIMIT 5";
return executeSQL($con, $sql);
}
/*************
Favorite VIDEOGAME -> MOST REPEATEDLY LOGGED
*************/
function getFavoriteVideoGame($con, $username)
{
$sql = "SELECT videogame, count(videogame) as favorites FROM `data` where username='$username' and videogame!='' GROUP BY videogame HAVING count(videogame)>1 ORDER BY count(videogame) DESC LIMIT 5";
return executeSQL($con, $sql);
}
/*************
TOTAL ALBUM COUNT
*************/
function getTotalAlbumCount($con, $username)
{
$sql = "SELECT count(`album`) AS Total_Count FROM `data` where `username`='$username' AND album!=''";
return executeSQL($con, $sql);
}
/*************
TOTAL ALBUM COUNT UNIQUE
*************/
function getTotalAlbumCountUnique($con, $username)
{
$sql = "SELECT count(DISTINCT `album`) AS Total_Count FROM `data` where `username`='$username' AND album!=''";
return executeSQL($con, $sql);
}
/*************
Favorite ALBUM -> MOST REPEATEDLY LOGGED (IF NO DUPLICATES AT ALL, THEN SAY 'NONE')
*************/
function getFavoriteAlbum($con, $username)
{
$sql = "SELECT album, count(album) as favorites FROM `data` where username='$username' and album!='' GROUP BY album HAVING count(album)>1 ORDER BY count(album) DESC LIMIT 5";
return executeSQL($con, $sql);
}
/*************
Favorite ARTIST/SINGER/SONGWRITER -> MOST REPEATEDLY LOGGED (IF NO DUPLICATES AT ALL, THEN SAY 'NONE')
*************/
function getFavoriteArtist($con, $username)
{
$sql = "SELECT artist, count(artist) as favorites FROM `data` where username='$username' and artist!='' GROUP BY artist HAVING count(artist)>1 ORDER BY count(artist) DESC LIMIT 5";
return executeSQL($con, $sql);
}
/********************
GET THE MOVIE POSTER PATH USING AN API REQUEST
******************/
function MoviePosterPath($name, $year)
{
$api_key = "e446bc89015229cf337e16b0849d506c";
$url = 'https://api.themoviedb.org/3/search/movie?api_key=' . $api_key . '&query=' . $name . '&year=' . $year . '&include_adult=false';
// echo $url . "<br>";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
]);
$response = curl_exec($curl);
$response = json_decode($response, true);
curl_close($curl);
if (empty($response['results'][0]['poster_path'])) {
$response = "images/API/WYDRNmovie.png";
} else {
$response = "https://image.tmdb.org/t/p/w300" . $response['results'][0]['poster_path'];
}
return $response;
}
/********************
GET THE BOOK POSTER PATH USING AN API REQUEST
******************/
function BookPosterPath($name, $author)
{
$merge = $name . "+" . $author;
$url = 'https://www.googleapis.com/books/v1/volumes?q=' . $merge . '&orderBy=relevance';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
]);
$response = curl_exec($curl);
$response = json_decode($response, true);
curl_close($curl);
if (empty($response['items'][0]['volumeInfo']['imageLinks']['thumbnail'])) {
$response = "images/API/WYDRNbook.png";
} else {
$response = $response['items'][0]['volumeInfo']['imageLinks']['thumbnail'];
}
// print_r ($response['items'][0]['volumeInfo']['imageLinks']['thumbnail']);
return $response;
}
/********************
GET THE TV POSTER PATH USING AN API REQUEST
******************/
function TvPosterPath($name)
{
$api_key = "e446bc89015229cf337e16b0849d506c";
$url = 'https://api.themoviedb.org/3/search/tv?api_key=' . $api_key . '&query=' . $name . '&include_adult=false';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
]);
$response = curl_exec($curl);
$response = json_decode($response, true);
curl_close($curl);
if (empty($response['results'][0]['poster_path'])) {
$response = "images/API/WYDRNtv.png";
} else {
$response = "https://image.tmdb.org/t/p/w300" . $response['results'][0]['poster_path'];
}
return $response;
}
/********************
GET THE MUSIC POSTER PATH USING AN API REQUEST
******************/
function MusicPosterPath($name, $artist)
{
$api_key = "6a4eb1d0536cfe3583784a65332ee179";
$url = 'https://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key=' . $api_key . '&artist=' . $artist . '&album=' . $name . '&format=json';
// echo $url . "<br>";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
]);
$response = curl_exec($curl);
$response = json_decode($response, true);
curl_close($curl);
if (empty($response['album']['image'][5]['#text'])) {
$response = "images/API/WYDRNmusic.png";
} else {
$response = $response['album']['image'][5]['#text'];
}
return $response;
}
/********************
GET THE VIDEOGAME POSTER PATH USING AN API REQUEST
******************/
function GamePosterPath($name)
{
$api_key = "fe197746ce494b4791441d9a9161c1be";
$url = 'https://api.rawg.io/api/games?search=' . $name . '&key=' . $api_key;
// echo $url . "<br>";