forked from htmlacademy-php/1415187-readme-12
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpost.php
62 lines (52 loc) · 1.53 KB
/
post.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
<?php
require_once __DIR__ . '/libs/base.php';
$user = get_user();
if ($user === null) {
header("Location: index.php");
exit();
}
$post_id = $_GET['id'];
$post = get_post($connection, $post_id);
if ($post === null) {
display_404_page($user);
exit();
}
increase_post_views($connection, $user['id'], $post_id);
$comment_errors = [];
$show_all_comments = $_GET['showall'] ?? false;
if (!empty($_SESSION['errors'])) {
$comment_errors = $_SESSION['errors'];
$comment_text = $_SESSION['comment_value'];
unset($_SESSION['errors']);
unset($_SESSION['comment_value']);
}
$author_id = $post['author_id'];
$author = get_post_author($connection, $author_id);
$comments = get_post_comments($connection, $post_id);
$user['subscribed'] = user_subscribe($connection, false, $user['id'], $author_id);
$title = $site_name . ': Публикация "' . $post['heading'] . '"';
$count_comments = count($comments);
$page_content = include_template(
'posts/' . 'post-details.php',
[
'user' => $user,
'post' => $post,
'author' => $author,
'comments' => $comments,
'comment_errors' => $comment_errors,
'now_time' => $now_time,
'show_all' => $show_all_comments,
'count_comments' => $count_comments,
'comment_text' => $comment_text ?? '',
]
);
$layout_content = include_template(
'layout.php',
[
'content' => $page_content,
'user' => $user,
'title' => $title,
'active_section' => $active_section,
]
);
print($layout_content);