-
Notifications
You must be signed in to change notification settings - Fork 3
/
whats_hot.php
678 lines (520 loc) · 20.9 KB
/
whats_hot.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
<?php
session_start();
if (!isset($_SESSION["username"])) {
header("Location: ../user/login.php");
exit();
}
include("important/db.php");
$icon = "home";
?>
<?php
if(isset($_GET['trump'])) {
echo '<link rel="stylesheet" href="assets/css/trump.css">';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-4.0.0-beta.2.min.js"></script>
<title>Loogle+</title>
<link rel="stylesheet" href="assets/css/2013isamess.css">
<link rel="stylesheet" href="assets/css/2013indexres.css">
<link rel="stylesheet" href="assets/css/2013notes.css">
<link rel="stylesheet" href="assets/css/univesalcoolstuff.css">
<link rel="stylesheet" href="assets/css/headerfix.css">
<link rel="stylesheet" href="assets/css/whatshotregan.css">
<link rel="icon"
type="image/png"
href="assets/important-images/fav.png" />
</head>
<body>
<?php require_once("inc/topstuffs.php")?>
<div class="banner">
<!-- LOADED IN A SUCH -->
</div>
<div class="write-post-expanded">
</div>
<div class="content">
<div class="container" id="posts-container">
</div>
</div>
<script>
$(document).ready(function () {
var mainHeader = $(".main-header");
var subHeader = $(".sub-header");
var stickyHeader = $(".sticky-header");
var sidebar = $(".sidebar");
var offset = mainHeader.offset().top;
var sidebarTopPosition = 60;
$(window).scroll(function () {
var scrollTop = $(window).scrollTop();
var mainHeaderHeight = mainHeader.height();
var subHeaderHeight = subHeader.height();
var totalHeaderHeight = mainHeaderHeight + subHeaderHeight;
if (scrollTop >= offset + totalHeaderHeight) {
stickyHeader.css('display', 'block');
sidebarTopPosition = 40;
} else {
stickyHeader.css('display', 'none');
sidebarTopPosition = 60;
}
sidebar.css('top', sidebarTopPosition + 'px');
});
});
</script>
<script>
function formatTime(timestamp) {
const date = new Date(timestamp);
const options = { month: 'long', day: 'numeric', year: 'numeric' };
return date.toLocaleString('en-US', options);
}
function fetchPosts() {
fetch('<?php echo $siteurl; ?>/apiv1/whats_hot.php')
.then(response => response.json())
.then(data => {
const postsContainer = document.getElementById('posts-container');
postsContainer.innerHTML = '';
let numColumns = 3;
const screenWidth = window.innerWidth;
const urlParams = new URLSearchParams(window.location.search);
const forceColParam = urlParams.get('forcecol');
if (forceColParam && !isNaN(forceColParam)) {
numColumns = parseInt(forceColParam);
} else {
if (screenWidth <= 1599) {
numColumns = 2;
} else if (screenWidth <= 720) {
numColumns = 1;
}
}
const columns = [];
for (let i = 0; i < numColumns; i++) {
const column = document.createElement('div');
column.className = 'column';
columns.push(column);
postsContainer.appendChild(column);
}
const postCreate = document.createElement('div');
postCreate.className = 'post-create';
postCreate.innerHTML = `
<div id="bob-post-create" class="write-post">
<h2 style="color: #a5a5a5;">What's hot and recommended</h2>
<b style="color: #454545;font-size: 12px;margin-left: 6px; margin-top: 6px; position: relative; top: 7px;">
These posts are popular on Loogle+</b>
</div>
`;
columns[0].appendChild(postCreate);
$(document).ready(function () {
let postCreateMoved = false;
});
const apiEndpoint = '<?php echo $siteurl; ?>/apiv1/fetch_comments.php?id=';
let currentColumnIndex = 0;
for (let i = 0; i < data.length; i++) {
const post = data[i];
const postElement = document.createElement('div');
postElement.className = 'post';
const formattedTime = formatTime(post.created_at);
const plusOneUsernamesString = post.plus_one_usernames || '';
const isLikedByCurrentUser = plusOneUsernamesString.includes('<?php echo $_SESSION["username"];?>');
postElement.innerHTML = `
<div class="post-main">
<div class="hacky-fix">
<img src="<?php echo $siteurl; ?>/apiv1/fetch_pfp_api.php?name=${post.username}" class="post-file-picture">
<div class="aaaaaa">
<div class="post-top">
<a href="<?php echo $siteurl; ?>/profile.php?profile=${post.username}">
<p class="username">${post.username}</p>
</a>
</div>
<div class="post-meta">
<span>Sharing Publicly </span>
<a style="color: inherit; text-decoration: none;" href="view_post.php?id=${post.id}">
<span class="upload-time">- ${formattedTime}</span>
</a>
</div>
</div>
</div>
<div class="post-content-container">
<p class="post-content">${post.content}</p>
<img class="post-image" src="${post.image_url}" alt="">
<div class="link-preview">
</div>
<div class="youtube-emded">
</div>
</div>
</div>
</div>
`;
if (post.post_link && post.post_link.includes("youtube.com/embed")) {
const iframeHTML = '<iframe width="99.75%" height="315" frameborder="0" allowfullscreen></iframe>';
$(postElement).find('.youtube-emded').html(iframeHTML);
const protocol = window.location.protocol;
if (protocol === 'https:' && !post.post_link.startsWith('https:')) {
post.post_link = post.post_link.replace(/^http:/, 'https:');
}
$(postElement).find('.youtube-emded iframe').attr('src', post.post_link);
}
if (post.post_link_url) {
$.getJSON('<?php echo $siteurl; ?>/apiv1/fetch_metadata.php?url=' + encodeURIComponent(post.post_link_url) + '&format=json', function(metadata) {
const linkPreviewContainer = $('<div>', { class: 'link-preview' });
const faviconContainer = $('<div>', { class: 'favicon-container' });
const faviconImg = $('<img>', {
src: metadata.image,
alt: 'Favicon',
class: 'favicon-img'
});
faviconContainer.append(faviconImg);
const contentContainer = $('<div>', { class: 'content-container' });
const title = $('<h2>');
const titleLink = $('<a>', {
href: post.post_link_url,
text: metadata.title,
target: '_blank'
});
title.append(titleLink);
const linkText = $('<p>', {
text: post.post_link_url,
class: 'link-text'
});
contentContainer.append(title, linkText);
linkPreviewContainer.append(faviconContainer, contentContainer);
$(postElement).find('.link-preview').append(linkPreviewContainer);
const containerWidth = linkPreviewContainer.width();
const faviconWidth = containerWidth * 0.3;
const contentWidth = containerWidth * 0.8;
faviconContainer.width(faviconWidth);
contentContainer.width(contentWidth);
const maxFaviconHeight = 50;
const maxFaviconWidth = containerWidth * 0.3;
faviconImg.css({
'max-width': maxFaviconWidth + 'px',
});
if (contentContainer.height() > 200) {
contentContainer.css('height', '200px');
contentContainer.css('overflow', 'hidden');
}
})
.fail(function(jqxhr, textStatus, error) {
const err = textStatus + ", " + error;
console.log("Request Failed: " + err);
});
}
postElement.dataset.postId = post.id;
postElement.dataset.plusOne = post.plus_one;
postElement.dataset.isLikedByCurrentUser = isLikedByCurrentUser;
columns[currentColumnIndex].appendChild(postElement);
const commentArea = document.createElement('div');
commentArea.className = 'comment-main';
const hideShowCommentsLink = document.createElement('a');
hideShowCommentsLink.addEventListener('click', function (e) {
e.preventDefault();
const comments = commentArea.querySelector('.comments');
if (comments.style.display === 'none') {
comments.style.display = 'block';
} else {
comments.style.display = 'none';
}
});
commentArea.appendChild(hideShowCommentsLink);
postElement.appendChild(commentArea);
$.ajax({
url: apiEndpoint + post.id,
dataType: 'json',
success: function (commentsData) {
if (commentsData.status === 'success') {
$.each(commentsData.comments, function (index, comment) {
const commentElement = document.createElement('div');
commentElement.className = 'comment';
commentElement.innerHTML = `
<div class="hacky-fix">
<img src="<?php echo $siteurl; ?>/apiv1/fetch_pfp_api.php?name=${comment.username}" class="comment-picture">
<div class="agony">
<div class="hacky-fix">
<a href="<?php echo $siteurl; ?>/profile.php?profile=${comment.username}" <p class="username">${comment.username}</p></a>
<p class="time">${comment.comment_time}</p>
</div>
<p class="comment-content">${comment.comment_content}</p>
</div>
</div>
`;
commentArea.appendChild(commentElement);
});
} else {
console.log('No comments found for the post with ID ' + post.id);
}
},
error: function (error) {
console.log('Error:', error);
}
});
$(document).ready(function() {
$('.comment-main').each(function() {
if ($(this).next('.comment-input-container').length === 0) {
const postElement = $(this).closest('.post');
const postID = postElement.data('post-id');
const plusOneIs = postElement.data('plus-one');
const isLikedByCurrentUser = Boolean(postElement.data('is-liked-by-current-user'));
console.log(postID);
const commentInputContainer = $('<div>').addClass('comment-input-container');
commentInputContainer.css({
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'column',
height: '50px',
position: 'relative'
});
const plusOneContainer = $('<div>').addClass('plus-one-container');
plusOneContainer.css({
position: 'absolute',
top: '5px',
right: '5px'
});
const plusOneIcon = $('<div>').addClass('plus-one-icon').attr('id', isLikedByCurrentUser ? 'liked-icon' : '');
const plusOneSpan = $('<span>').attr('id', 'georgewallace').text(`+${plusOneIs}`);
plusOneIcon.append(plusOneSpan);
plusOneContainer.append(plusOneIcon);
$(plusOneContainer).find('.plus-one-icon').click(function() {
var username = '<?php echo $_SESSION["username"];?>';
$('#georgewallace').css('color', 'white');
var $closestPlusOneIcon = $(this).closest('.plus-one-icon');
var $closestGeorgeWallace = $closestPlusOneIcon.find('#georgewallace');
var currentValue = parseInt($closestGeorgeWallace.text().replace('+', '')) || 0;
$.ajax({
url: '<?php echo $siteurl; ?>/apiv1/add_plus_one.php',
type: 'POST',
data: {
add_plus_one: true,
id: postID,
username: username
},
success: function(response) {
var responseData = JSON.parse(response);
if (responseData.action === 'added') {
console.log("Plus one added.");
$closestGeorgeWallace.text(`+${currentValue + 1}`);
$closestPlusOneIcon.css('color', '#ffff');
$closestPlusOneIcon.css('background-color', '#cc4331');
$closestGeorgeWallace.css('color', '#ffff');
}
if (responseData.action === 'subtracted') {
console.log("Plus one subtracted.");
$closestGeorgeWallace.text(`+${currentValue - 1}`);
$closestPlusOneIcon.css('background-color', 'white');
$closestPlusOneIcon.css('color', '#333');
$closestGeorgeWallace.css('color', '#333');
}
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
}
});
});
var $closestCommentMain = $(this).closest('.comment-main');
const commentInput = $('<textarea>').attr({
type: 'text',
id: 'comment-input-' + postID,
placeholder: 'Add a comment...'
}).addClass('comment-input');
commentInputContainer.append(commentInput);
commentInputContainer.append(plusOneContainer);
commentInput.css('height', '30px');
commentInput.css('width', '275px');
commentInput.css('background', '#fff');
commentInput.css('border', '1px solid #ccc');
commentInput.css('resize', 'none');
const buttonContainer = $('<div style="margin-right: 250px;">');
const submitButton = $('<button>').text('Post comment').addClass('submit-button').css('display', 'none');
const cancelButton = $('<button>').text('Cancel').addClass('cancel').css('display', 'none');
buttonContainer.append(submitButton, cancelButton);
commentInputContainer.append(buttonContainer);
$(this).after(commentInputContainer);
commentInput.on('click', function() {
submitButton.css('display', 'inline-block');
cancelButton.css('display', 'inline-block');
$(this).closest('.comment-input-container').find('.plus-one-icon').hide();
commentInput.attr('placeholder', '');
commentInput.css({
'height': '60px',
'width': '440px',
'text-indent': '1ch',
'background': '#fff',
'border': '1px solid #ccc',
'padding': '0px',
'resize': 'none',
'overflowY': 'auto',
'padding-top': '3px',
'left': '23px'
});
commentInputContainer.css({
'background': '#f6f6f6',
'height': '125px',
'position': 'relative'
});
let newElement = $('<img id="khamlaharis">')
.attr('src', '<?php echo htmlspecialchars($siteurl, ENT_QUOTES, 'UTF-8'); ?>/apiv1/fetch_pfp_api.php?name=<?php echo htmlspecialchars($_SESSION["username"], ENT_QUOTES, 'UTF-8'); ?>')
.css({
'width': '25px',
'height': '25px',
'position': 'absolute',
'top': '17px',
'left': '18px',
'border-radius': '5%'
});
commentInputContainer.prepend(newElement);
});
submitButton.on('click', function() {
const commentContent = $(this).closest('.comment-input-container').find('.comment-input').val();
console.log(commentContent);
const postID = $(this).closest('.post').data('postId');
const username = '<?php echo $_SESSION["username"]; ?>';
console.log("Data sent in AJAX request:", {
commentContent: commentContent,
postID: postID,
username: username
});
$.ajax({
url: '<?php echo $siteurl; ?>/apiv1-internal/submit_comment.php',
type: 'POST',
dataType: 'json',
data: {
commentContent: commentContent,
postID: postID,
username: username
},
success: function(response) {
console.log(response);
var commentContent = response.commentContent;
var postID = response.postID;
var username = response.username;
var newComment = $('<div>', { class: 'comment' }).append(
$('<div>', { class: 'hacky-fix' }).append(
$('<img>', {
class: 'comment-picture',
src: `<?php echo $siteurl; ?>/apiv1/fetch_pfp_api.php?name=${encodeURIComponent(username)}`
}),
$('<div>', { class: 'agony' }).append(
$('<div>', { class: 'hacky-fix' }).append(
$('<a>', {
href: `<?php echo $siteurl; ?>/profile.php?profile=${encodeURIComponent(username)}`
}).append($('<p>', { class: 'username', text: username })),
$('<p>', { class: 'time', text: new Date().toISOString().slice(0, 19).replace('T', ' ') })
),
$('<p>', { class: 'comment-content', text: commentContent })
)
)
);
$closestCommentMain.append(newComment);
function scrollToBottom(element, duration = 400) {
$(element).animate({
scrollTop: $(element)[0].scrollHeight
}, duration);
}
scrollToBottom($closestCommentMain);
submitButton.css('display', 'none');
cancelButton.css('display', 'none');
commentInputContainer.css('background-color', '#fff');
$('.plus-one-icon').show();
$('#khamlaharis').hide();
commentInput.css({
height: '30px',
width: '275px',
left: '17%'
});
commentInputContainer.css('height', '50px');
commentInput.css({
background: '#fff',
border: '1px solid #ccc'
});
commentInput.attr('placeholder', 'Add a comment..');
commentInput.val('');
commentInput.trigger('blur');
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
}
});
});
cancelButton.on('click', function() {
submitButton.css('display', 'none');
cancelButton.css('display', 'none');
$('#khamlaharis').hide();
commentInput.css({
height: '30px',
width: '275px',
left: '17%'
});
commentInput.attr('placeholder', 'Add a comment..');
commentInput.val('');
commentInputContainer.css('background-color', '#fff');
$('.plus-one-icon').show();
commentInputContainer.css('height', '50px');
commentInput.css({
background: '#fff',
border: '1px solid #ccc'
});
commentInput.trigger('blur');
});
}
});
});
currentColumnIndex = (currentColumnIndex + 1) % numColumns;
}
})
.catch(error => {
console.error('Error fetching posts:', error);
});
$(document).on('click', function (event) {
if (!$(event.target).closest('#fileDrop').length && !$(event.target).is($writePostPhotoRealIcon) && !$(event.target).is($uploadButton) ) {
$("#fileDrop").hide();
$postCreate.css({
height: '300px'
});
$writePostLevel2.css({
height: 'auto',
display: 'block'
});
$photo.show();
$attach.show();
$addPhotostext.hide();
$uploadButton.hide();
$box.hide();
$level4.css({
top: '90px'
});
}
});
}
$('#cancelButton').click(function () {
smoothReload(1000);
});
const commentMain = $('.comment-main');
fetchPosts();
setInterval(fetchPosts, 600000);
function smoothReload(delay) {
$("body").fadeOut(delay, function() {
history.replaceState({}, document.title, window.location.pathname);
location.reload();
});
}
</script>
<script>
$(document).ready(function() {
$(".dropdown-toggle").click(function(e) {
e.preventDefault();
var $dropdownMenu = $(this).next(".dropdown-menu");
$dropdownMenu.toggleClass("show");
});
$(document).click(function(e) {
if (!$(e.target).closest(".dropdown-toggle").length && $(".dropdown-menu").hasClass("show")) {
$(".dropdown-menu").removeClass("show");
}
});
});
</script>
<script src="assets/js/sidebar.js"></script>
</body>
</html>