-
Notifications
You must be signed in to change notification settings - Fork 1
/
feed.php
90 lines (81 loc) · 2.93 KB
/
feed.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
<?php
require_once 'functions.php';
require_once 'helpers.php';
require_once 'data.php';
require_once 'session.php';
$navigation_link = 'feed';
$sql = 'SELECT id, name, type
FROM content_type;';
$result = mysqli_query($connection, $sql);
$content_types = mysqli_fetch_all($result, MYSQLI_ASSOC);
$tab = filter_input(INPUT_GET, 'tab');
$is_type = null;
foreach ($content_types as $content_type) { //проверка на тип контента
if ($content_type['type'] === $tab) {
$is_type = 'Есть тип';
}
}
if (!$is_type && !empty($tab)) {
header('Location: error.php?code=404');
exit;
}
if ($tab) {
$sql = 'SELECT p.id, title, text, quote_auth, img, video, title, text, quote_auth, img, video, link, views, user_id, type, p.dt_add, login, avatar,' .
' (SELECT COUNT(post_id)' .
' FROM likes' .
' WHERE likes.post_id = p.id)' .
' AS likes,' .
' (SELECT COUNT(content) ' .
' FROM comments' .
' WHERE post_id = p.id)' .
' AS comment_sum,' .
' (SELECT COUNT(original_id) ' .
' FROM posts' .
' WHERE original_id = p.id)' .
' AS reposts_sum' .
' FROM posts p' .
' JOIN subscribes s ON p.user_id = s.follow_id' .
' JOIN users u ON p.user_id = u.id' .
' JOIN content_type ct ON p.content_type_id = ct.id' .
' WHERE follower_id = ? && type = ?' .
' ORDER BY dt_add ASC;';
$stmt = db_get_prepare_stmt($connection, $sql, [$user['user_id'], $tab]);
} else {
$sql = 'SELECT p.id, title, text, quote_auth, img, video, title, text, quote_auth, img, video, link, views, user_id, type, p.dt_add, login, avatar,' .
' (SELECT COUNT(post_id)' .
' FROM likes' .
' WHERE likes.post_id = p.id)' .
' AS likes,' .
' (SELECT COUNT(content)' .
' FROM comments' .
' WHERE post_id = p.id)' .
' AS comment_sum,' .
' (SELECT COUNT(original_id)' .
' FROM posts' .
' WHERE original_id = p.id)' .
' AS reposts_sum' .
' FROM posts p' .
' JOIN subscribes s ON p.user_id = s.follow_id' .
' JOIN users u ON p.user_id = u.id' .
' JOIN content_type ct ON p.content_type_id = ct.id' .
' WHERE follower_id = ?' .
' ORDER BY dt_add ASC;';
$stmt = db_get_prepare_stmt($connection, $sql, [$user['user_id']]);
}
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($result) {
$posts = mysqli_fetch_all($result, MYSQLI_ASSOC);
}
$page_content = include_template(
'feed_templates/strip.php',
['posts' => $posts, 'content_types' => $content_types, 'tab' => $tab]
);
$layout_content = include_template('layout.php', [
'content' => $page_content,
'title' => 'readme: блог, каким он должен быть',
'user' => $user,
'navigation_link' => $navigation_link,
'message_notification' => $message_notification
]);
print($layout_content);