Repository navigation
Expand file tree
/
Copy pathindex.php
More file actions
596 lines (509 loc) · 27.4 KB
/
Copy pathindex.php
File metadata and controls
596 lines (509 loc) · 27.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
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
<?php
session_start();
require_once 'include/connect.php';
require_once("include/utils.php");
require_once("include/post_utils.php");
$user_login = $_SESSION['user']['user-login'];
$user_query = mysqli_query($connect, "SELECT `user-name` FROM `users` WHERE `user-login` = '$user_login'");
if ($user_query) {
$user_data = getUserData($user_login);
$user_name = $user_data['user-name'];
$user_id = $user_data['id'];
} else {
echo "Ошибка в запросе: " . mysqli_error($connect);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Главная</title>
<style>
<?php echo getThemeStyles(); ?>
</style>
<style>
<?php echo getMainStyles();?>
</style>
<script>
document.querySelector('style').textContent += '?v=2';
</script>
<link rel="stylesheet" type="text/css" href="styles/style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@600&family=Noto+Sans+KR:wght@700&display=swap" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<script src="https://kit.fontawesome.com/0ba382eac4.js" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2132450451885667"
crossorigin="anonymous"></script>
<?php
if ($user_login == NULL) {
echo'<style>.err1{display: block;}</style>';
echo'<style>.err2{display: none;}</style>';
}
?>
<style>
.other-post-panel {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: absolute;
gap: 5px;
transform: translate(-80%, 0%);
width: 128px;
height: auto;
border-radius: 15px;
opacity: 0; /* Начальная прозрачность */
transition: opacity 0.2s ease; /* Анимация изменения opacity */
}
.other-post-panel.show {
opacity: 1; /* Прозрачность при отображении */
}
.other-post-panel a {
display: flex;
align-items: center;
justify-content: center;
gap: 5px;
background-color: var(--button-color);
border-radius: 15px;
height: 32px;
width: 90%;
}
</style>
</head>
<body>
<?php
require_once('include/notification/include_notification.php');
echo getNotificationCode();
?>
<style>
.max-size-error{
position: fixed;
top: 35%;
left: 50%;
transform: translate(-50%, -50%);
width: 440px;
height: 180px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 15px;
background-color: var(--panel-on-panel-color);
scale: 0;
z-index: 1;
}
.max-size-error-show{
scale: 1;
transition: 0.2s;
}
@media screen and (max-width: 768px) {
.max-size-error{
width: 90%;
}
}
</style>
<div class="max-size-error ui-column" id="max-size-error">
<span>Вес файла не должен превышать 2mb!</span>
<button class="ui-button" onclick="maxSizeError.classList.remove('max-size-error-show');">Закрыть</button>
</div>
<div class="container">
<div class="nav-block">
<button title="Главная">
<i class="fa-solid fa-house icon"></i>
<a>Главная</a>
</button>
<div class="err2">
<button onclick="window.location.href='pages/profile?login=<?=$_SESSION['user']['user-login']?>'" title="Профиль">
<i class="fa-solid fa-user icon"></i>
<a>Профиль</a>
</button>
</div>
<button onclick="window.location.href='pages/anime'" title="Anime">
<i class="fa-solid fa-magnifying-glass icon"></i>
<a>Аниме</a>
</button>
<button onclick="window.location.href='pages/user-list'" title="Users">
<i class="fa-solid fa-users icon"></i>
<a>Люди</a>
</button>
<button onclick="window.location.href='pages/friends'" title="Users">
<i class="fa-solid fa-user-group icon"></i>
<a>Друзья</a>
</button>
<button onclick="window.location.href='pages/chat'" title="Users">
<i class="fa-solid fa-comments icon"></i>
<a>Чат</a>
</button>
<button onclick="window.location.href='pages/settings'" title="Settings">
<i id="notification-icon" class="fa-solid fa-gear fa-spin icon"></i>
<a>Настройки</a>
</button>
<?php
$userData = getUserData($user_login);
if ($userData["is-admin"] == 1){
echo '
<button onclick="window.location.href=`pages/admin`" title="Admin panel">
<i class="fa-solid fa-grip"></i>
<a>Админ панель</a>
</button>
';
}
?>
</div>
<div class="main-block">
<div class="add-post ui-block">
<p class="error err1">Вы не можете отправлять посты, <a href="pages/login">войдите в аккаунт</a></p>
<div class="ui-title err2" >Добавить пост</div>
<form id="add-post" action="include/add_post" method="post" enctype="multipart/form-data">
<textarea name="title" class="ui-input line err2" maxlength="16" placeholder="Заголовок поста..."></textarea>
<textarea name="text" class="ui-input err2" maxlength="256" placeholder="Текст поста..."></textarea>
<div class="buttons err2">
<div class="add-file">
<input name="post-image" type="file" class="add-image" id="file-input">
<i class="fa-solid fa-image icon"></i>
</div>
<div id="progress-container">
<div id="progress-bar"></div>
<script src="scripts/progressbar.js" type="text/javascript"></script>
</div>
<button id="" class="ui-button send aqua-gradient" type="submit">Отправить</button>
</div>
</form>
</div>
<!-- <div class="ui-block post-block">
<div class="ui-user">
<div class="ui-row">
<div class="avatar">
<img src="">
</div>
<div class="ui-column">
<div>user-name</div>
<div>Post date</div>
</div>
</div>
</div>
<div class="ui-title">Post title</div>
<pre>Post text</pre>
<div class="ui-row">
<button id="like-button" class="lime-gradient"><i class="fa-solid fa-heart" style="color: #213454;" id="like"></i></button>
</div>
</div>
<div class="ui-block post-block">
<div class="ui-user">
<div class="ui-row">
### Аватарка
<a href="pages/profile?login=root">
<div class="avatar">
<img src="root" alt="User Avatar">
</div>
</a>
<div class="ui-column">
###Юзернейм и галочка
<div class="ui-row">
<a href="pages/profile?login=root">User name</a>
<svg style="fill: #ffffff;" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 448 512">
<path d="m21.5609 10.7386-1.36-1.58001c-.26-.3-.47-.86-.47-1.26v-1.7c0-1.06-.87-1.93-1.93-1.93h-1.7c-.39 0-.96-.21-1.26-.47l-1.58-1.36c-.69-.59-1.82-.59-2.52 0l-1.57004 1.37c-.3.25-.87.46-1.26.46h-1.73c-1.06 0-1.93.87-1.93 1.93v1.71c0 .39-.21.95-.46 1.25l-1.35 1.59001c-.58.69-.58 1.81 0 2.5l1.35 1.59c.25.3.46.86.46 1.25v1.71c0 1.06.87 1.93 1.93 1.93h1.73c.39 0 .96.21 1.26.47l1.58004 1.36c.69.59 1.82.59 2.52 0l1.58-1.36c.3-.26.86-.47 1.26-.47h1.7c1.06 0 1.93-.87 1.93-1.93v-1.7c0-.39.21-.96.47-1.26l1.36-1.58c.58-.69.58-1.83-.01-2.52zm-5.4-.63-4.83 4.83c-.14.14-.33.22-.53.22s-.39-.08-.53-.22l-2.42004-2.42c-.29-.29-.29-.77 0-1.06s.77-.29 1.06 0l1.89004 1.89 4.3-4.30001c.29-.29.77-.29 1.06 0s.29.77 0 1.06001z"/>
</svg>
</div>
###Дата
5 минут назад
<br>
</div>
### Кнопка "other"
<div style="margin-left: auto;">
<button class="ui-button" onclick="toggleOtherPanel()">
<i class="fa-solid fa-ellipsis-vertical icon"></i>
</button>
<div class="other-post-panel">
<a href="#" style="background-color: #ed6464;">
<i class="fa-solid fa-trash icon"></i>
Удалить пост
</a>
</div>
</div>
<script>
function toggleOtherPanel() {
const otherPanel = document.querySelector('.other-post-panel');
otherPanel.classList.toggle('show');
}
</script>
</div>
</div>
### Заголовок
<div class="ui-title">Заголовок</div>
### Текст
<pre>Текст</pre>
### Картинка
<img src="#" alt="Post Image">
### Определение стиля для лайка, в зависимости от того поставлен он или нет
<div class="ui-row" style="padding-top: 10px;">
### Кнопка лайка
<button id="like-button" class="like-button" data-post-id="" data-user-id="">
<i class="fa-solid fa-heart icon" id="like">5</i>
</button>
<button class="ui-button" onclick="window.location.href='pages/post?postId='">
<i class="fa-regular fa-message icon"></i>
</button>
</div>
</div> -->
<?php
require_once('include/utils.php');
$sql = "SELECT * FROM posts ORDER BY date DESC";
$result = $connect->query($sql);
if ($result->num_rows > 0) {
// Реклама
echo '
<div class="ui-block post-block ad-block">
</div>
';
// Вывод данных каждого поста
$postCount = 0;
while ($row = $result->fetch_assoc()) {
$postCount++;
$userData = getUserData($row["author-login"]);
echo '<div class="ui-block post-block">';
echo'<div class="ui-user">';
echo'<div class="ui-row">';
// Аватарка
if ($userData["user-avatar"] != ""){
echo "<a href='pages/profile?login=".$row["author-login"]."'>";
echo'<div class="avatar">';
echo "<img src=" . $userData["user-avatar"] . ">";
echo'</div>';
echo "</a>";
} else { // Аватарка если ее нету
echo'<div class="non-avatar" onclick="window.location.href=`pages/profile?login='.$row["author-login"].'`">';
echo '<span class="initials">' . strtoupper($userData['user-name'][0]). '</span>';
echo'</div>';
}
echo'<div class="ui-column">';
// Юзернейм и галочка
echo'<div class="ui-row">';
echo "<a href='pages/profile?login=".$row["author-login"]."'>" . $userData['user-name'] . "</a>";
if($userData['is-verified'] == 1){
echo'<svg style="fill: #ffffff;" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 448 512"><path d="m21.5609 10.7386-1.36-1.58001c-.26-.3-.47-.86-.47-1.26v-1.7c0-1.06-.87-1.93-1.93-1.93h-1.7c-.39 0-.96-.21-1.26-.47l-1.58-1.36c-.69-.59-1.82-.59-2.52 0l-1.57004 1.37c-.3.25-.87.46-1.26.46h-1.73c-1.06 0-1.93.87-1.93 1.93v1.71c0 .39-.21.95-.46 1.25l-1.35 1.59001c-.58.69-.58 1.81 0 2.5l1.35 1.59c.25.3.46.86.46 1.25v1.71c0 1.06.87 1.93 1.93 1.93h1.73c.39 0 .96.21 1.26.47l1.58004 1.36c.69.59 1.82.59 2.52 0l1.58-1.36c.3-.26.86-.47 1.26-.47h1.7c1.06 0 1.93-.87 1.93-1.93v-1.7c0-.39.21-.96.47-1.26l1.36-1.58c.58-.69.58-1.83-.01-2.52zm-5.4-.63-4.83 4.83c-.14.14-.33.22-.53.22s-.39-.08-.53-.22l-2.42004-2.42c-.29-.29-.29-.77 0-1.06s.77-.29 1.06 0l1.89004 1.89 4.3-4.30001c.29-.29.77-.29 1.06 0s.29.77 0 1.06001z"/></svg>';
}
echo'</div>';
// Дата
echo "" . formatDate($row['date']) . "<br>";
echo'</div>';
if ($row["author-login"] == $user_login){
// Кнопка "other"
echo '<div style="margin-left: auto;">
<button class="ui-button" onclick="toggleOtherPanel('.$row['id'].')">
<i class="fa-solid fa-ellipsis-vertical icon"></i>
</button>
<div class="other-post-panel" id="other-panel-'.$row['id'].'">
<a href="include/remove_post?id='.$row['id'].'" style="background-color: #ed6464;">
<i class="fa-solid fa-trash icon"></i>
Удалить пост
</a>
</div>
</div>';
}
echo'</div>';
echo'</div>';
// Заголовок
echo '<div class="ui-title">' . $row["title"] . '</div>';
// Текст
echo '<pre>' . htmlspecialchars($row["text"], ENT_QUOTES, 'UTF-8') .'</pre>';
// Картинка
echo "<img src=". $row["image"]." >";
// Определие стиля для лайка, в зависимости от того поставлен он или нет
$postId = $row['id'];
if ($user_id != null) {
$likeClass = (mysqli_num_rows(mysqli_query($connect, "SELECT `id` FROM `post_likes` WHERE `user_id` = $user_id AND post_id = $postId ")) > 0) ? "like-button" : "liked-button";
echo '
<div class="ui-row" style="padding-top: 10px;">
<!-- Кнопка лайка -->
<button id="like-button" class="like-button '.$likeClass.'" data-post-id="' . $row["id"] . '" data-user-id="' . getUserData($_SESSION['user']["user-login"])["id"] . '">
<i class="fa-solid fa-heart icon" id="like">'.getPostLikesData($row['id'])['like_count'] .'</i>
</button>
<button class="ui-button" onclick="window.location.href=\'pages/post?postId=' . $row["id"] . '\'">
<i class="fa-regular fa-message icon"></i>
(' .mysqli_num_rows(mysqli_query($connect, "SELECT `id` FROM `post_comments` WHERE `post-id` = " . $row["id"])) . ')
</button>
</div>
';
} else {
echo '<p class="error err1">Вы не можете лайкать посты, <a href="pages/login">войдите в аккаунт</a></p>';
}
echo '</div>';
if ($postCount % 6 == 0) {
// Реклама
echo '
<div class="ui-block post-block ad-block">
</div>
';
}
}
echo '
<div class="">
<pre>
</pre>
</div>
';
} else {
echo "Постов не найдено.";
// Реклама
echo '
<div class="ui-block post-block">
</div>
';
}
?>
<!-- Скрипт открытия доп. панели у постов -->
<script>
function toggleOtherPanel(postId) {
const otherPanel = document.getElementById("other-panel-" + postId);
otherPanel.classList.toggle("show");
}
</script>
</div>
<div class="right-block">
<div class="ui-block">
</div>
</div>
</div>
<!-- Нижние кнопки -->
<div class="bottom-nav-block ui-row">
<!-- Панель с остальными кнопками -->
<div id="bottom-nav-other-panel" class="ui-block bottom-nav-other-panel" style="display: none;">
<ul>
<li>
<i class="fa-solid fa-comments icon"></i>
<a href="/pages/chat">Чат</a>
</li>
<br>
<li>
<i class="fa-solid fa-gear fa-spin icon"></i>
<a href="/pages/settings">Настройки</a>
</li>
<br>
<li>
<i class="fa-solid fa-users icon"></i>
<a href="/pages/user-list">Пользователи</a>
</li>
<br>
<li>
<?php
$userData = getUserData($user_login);
if ($userData["is-admin"] == 1){
echo '
<i class="fa-solid fa-grip"></i>
<a href="/pages/admin">Админ панель</a>
';
}
?>
</li>
</ul>
</div>
<button onclick="window.location.href='index'" title="Main">
<i class="fa-solid fa-house icon"></i>
</button>
<button class="err2" onclick="window.location.href='pages/profile?login=<?=$_SESSION['user']['user-login']?>'" title="Profile">
<i class="fa-solid fa-user icon"></i>
</button>
<button onclick="window.location.href='pages/anime'" title="Anime">
<i class="fa-solid fa-magnifying-glass icon"></i>
<a>Аниме</a>
</button>
<button onclick="window.location.href='pages/friends'" title="Users">
<i class="fa-solid fa-user-group icon"></i>
</button>
<button id="other-button" onclick="window.location.href=" title="Other">
<i class="fa-solid fa-bars icon"></i>
</button>
<script>
// Получаем элементы кнопки и блока
var otherButton = document.getElementById('other-button');
var otherPanel = document.getElementById('bottom-nav-other-panel');
// Назначаем обработчик события на кнопку
otherButton.addEventListener('click', function() {
// Переключаем видимость блока при каждом клике
if (otherPanel.style.display === 'block') {
otherPanel.style.display = 'none';
} else {
otherPanel.style.display = 'block';
}
});
</script>
<!-- <button onclick="window.location.href='pages/user-list'" title="Users">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path d="M144 0a80 80 0 1 1 0 160A80 80 0 1 1 144 0zM512 0a80 80 0 1 1 0 160A80 80 0 1 1 512 0zM0 298.7C0 239.8 47.8 192 106.7 192h42.7c15.9 0 31 3.5 44.6 9.7c-1.3 7.2-1.9 14.7-1.9 22.3c0 38.2 16.8 72.5 43.3 96c-.2 0-.4 0-.7 0H21.3C9.6 320 0 310.4 0 298.7zM405.3 320c-.2 0-.4 0-.7 0c26.6-23.5 43.3-57.8 43.3-96c0-7.6-.7-15-1.9-22.3c13.6-6.3 28.7-9.7 44.6-9.7h42.7C592.2 192 640 239.8 640 298.7c0 11.8-9.6 21.3-21.3 21.3H405.3zM224 224a96 96 0 1 1 192 0 96 96 0 1 1 -192 0zM128 485.3C128 411.7 187.7 352 261.3 352H378.7C452.3 352 512 411.7 512 485.3c0 14.7-11.9 26.7-26.7 26.7H154.7c-14.7 0-26.7-11.9-26.7-26.7z"/></svg>
</button> -->
</div>
<!-- <script>
const like = document.getElementById('like');
const dislike = document.getElementById('dislike');
const like_button = document.getElementById('like-button');
const dislike_button = document.getElementById('dislike-button');
// Анимации для лайка
// Добавляем обработчик события "mouseover" (наведение)
like_button.addEventListener('mouseover', function() {
// При наведении добавляем класс "fa-bounce"
like.classList.add('fa-bounce');
});
// Добавляем обработчик события "mouseout" (уход мыши с элемента)
like_button.addEventListener('mouseout', function() {
// При уходе мыши удаляем класс "fa-bounce"
like.classList.remove('fa-bounce');
});
</script> -->
<script> // Скрипт для отправки лайка к посту
$(document).ready(function() {
$(".like-button").on("click", function() {
var postId = $(this).data("post-id");
var userId = $(this).data("user-id");
var button = $(this);
// Отправка AJAX-запроса на сервер
$.ajax({
type: "POST",
url: "include/post_like",
data: {
post_id: postId,
user_id: userId
},
success: function(response) {
// Обработка успешного ответа от сервера
if (response === "liked") {
// Получаем текущее значение like_count и увеличиваем его на 1
var currentLikeCount = parseInt(button.find("i").text());
var newLikeCount = currentLikeCount + 1;
// Обновляем текст на кнопке
button.find("i").text(newLikeCount);
button.removeClass("liked-button");
} else {
button.addClass("liked-button");
// Получаем текущее значение like_count и уменьшаем его на 1
var currentLikeCount = parseInt(button.find("i").text());
var newLikeCount = currentLikeCount - 1;
// Обновляем текст на кнопке
button.find("i").text(newLikeCount);
}
},
error: function() {
// Обработка ошибки
alert("Произошла ошибка при лайке поста.");
}
});
});
});
</script>
<script>
//Првоерка веса изоображения
const fileInput = document.getElementById('file-input');
const maxSizeError = document.getElementById('max-size-error');
fileInput.addEventListener('change', () => {
var fileSize = fileInput.files[0].size; // размер файла в байтах
console.log(fileInput.files[0].size* 1024 * 1024);
var maxSize = 2 * 1024 * 1024; // 2 MB
if (fileSize > maxSize) {
maxSizeError.classList.add('max-size-error-show');
fileInput.value = '';
return;
}
});
</script>
</body>
</html>