-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
92 lines (78 loc) · 2.74 KB
/
index.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
declare(strict_types=1);
require_once 'helpers.php';
require_once 'utils.php';
$is_auth = rand(0, 1);
$user_name = 'Дмитрий'; // укажите здесь ваше имя
//функция сокращения текста до 300 символов
function trimtext(string $text, int $limit = 300): string
{
if (strlen($text) <= $limit) {
return '<p>' . $text . '</p>';
} else {
$words = explode(' ', $text);
$totalLength = 0;
$newText = '';
foreach ($words as $word) {
$totalLength += strlen($word);
if ($totalLength > $limit) {
break;
}
$newText .= $word . ' ';
}
$newText .= '...';
return $newText;
}
}
$posts = [
[
"title" => "Цитата",
"type" => "post-quote",
"content" => "Мы в жизни любим только раз, а после ищем лишь похожих",
"username" => "Лариса",
"avatar" => "userpic-larisa-small.jpg"
],
[
"title" => "Игра престолов",
"type" => "post-text",
"content" => "Не могу дождаться начала финального сезона своего любимого сериала!",
"username" => "Владик",
"avatar" => "userpic.jpg"
],
[
"title" => "Наконец, обработал фотки!",
"type" => "post-photo",
"content" => "rock-medium.jpg",
"username" => "Виктор",
"avatar" => "userpic-mark.jpg"
],
[
"title" => "Моя мечта",
"type" => "post-photo",
"content" => "coast-medium.jpg",
"username" => "Лариса",
"avatar" => "userpic-larisa-small.jpg"
],
[
"title" => "Лучшие курсы",
"type" => "post-link",
"content" => "www.htmlacademy.ru",
"username" => "Владик",
"avatar" => "userpic.jpg"
]
];
array_walk_recursive($posts, function(&$value) {
$value = htmlspecialchars($value, ENT_QUOTES);
});
$posts = get_dates($posts); // добавляем в массив новый элемент дата
$pageContent = include_template('main.php',
[
'posts' => $posts
]);
$layout_content = include_template('layout.php',
[
'pageName'=>'Readme',
'user_name' => $user_name,
'pageContent' => $pageContent
]);
print($layout_content);