forked from htmlacademy-php/71680-readme-12
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.php
74 lines (63 loc) · 1.8 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
63
64
65
66
67
68
69
70
71
72
73
74
<?php
require('helpers.php');
require('utils.php');
require('models/post.php');
if (empty($_GET['id'])) {
header("HTTP/1.0 404 Not Found");
return;
}
$templates = [
'video' => 'video.php',
'text' => 'text.php',
'link' => 'link.php',
'quote' => 'quote.php',
'photo' => 'image.php'
];
function addRelativeTime($comments) {
$result = Array();
foreach ($comments as $comment) {
if (is_array($comment)) {
$comment['relative_time'] = getRelativeDate($comment['date_create']);
$result[] = $comment;
}
}
return $result;
}
function getCountViews($count)
{
$frase = get_noun_plural_form($count, 'просмотр', 'просмотра', 'просмотров');
return "{$count} {$frase}";
}
$mysqli = connect();
$post = new Post($_GET['id'], $mysqli);
$data = $post->getPostContent();
if (empty($data)) {
header("HTTP/1.0 404 Not Found");
return;
}
$template = $templates[$data->post_type];
$safe_data = prepearingPost($data);
$comments = $post->getPostComments();
$comments = addRelativeTime($comments);
$comments_count = count($comments);
$likes_count = $post->getCountPostLikes();
$safe_data['duration_on_site'] = getRelativeDate($safe_data['date_registration'], 'на сайте');
$safe_data['view_number'] = getCountViews($safe_data['view_number']);
$post = include_template($template, ['post' => $safe_data]);
$post_details = include_template('post-details.php',
[
'post' => $post,
'info' => $safe_data,
'comments' => $comments,
'comments_count' => $comments_count,
'likes_count' => $likes_count,
]
);
$data = [
'content' => $post_details,
'user_name' => 'Alex',
'page_name' => $safe_data['title'],
'is_auth' => 1,
];
print(include_template('layout.php', $data));
?>