-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
112 lines (91 loc) · 3.48 KB
/
functions.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
function get_post_quote_content($post){
return '<blockquote>
<p> ' . $post['text'] . ' </p>
<cite>' . $post['author'] . '</cite>
</blockquote>';
}
function get_post_link_content($post){
return '<div class="post-link__wrapper">
<a class="post-link__external" href="http://" title="Перейти по ссылке">
<div class="post-link__info-wrapper">
<div class="post-link__icon-wrapper">
<img src="img/logo-vita.jpg" alt="Иконка">
</div>
<div class="post-link__info">
<h3>' . $post['title'] . '</h3>
</div>
</div>
<span>' . $post['link'] . '</span>
</a>
</div>';
}
function get_post_photo_content($post){
return '<div class="post-photo__image-wrapper">
<img src="img/' . $post['photo'] . '" alt="Фото от пользователя" width="360" height="240">
</div>';
}
function get_post_text_content($post){
return break_text($post['text'], 300);
}
function get_post_content_by_type($post, $types){
if ($types[$post['type_id']]['class_name'] === 'post-quote') {
return get_post_quote_content($post);
}
elseif ($types[$post['type_id']]['class_name'] === 'post-photo') {
return get_post_photo_content($post);
}
elseif ($types[$post['type_id']]['class_name'] === 'post-text') {
return get_post_text_content($post);
}
elseif ($types[$post['type_id']]['class_name'] === 'post-link') {
return get_post_link_content($post);
}
else {
return 'Error: File not Found';
}
}
function break_text($str, $value) {
if (mb_strlen($str, 'UTF-8') > $value) {
$str = mb_substr($str, 0, $value, 'UTF-8');
$str = mb_substr($str, 0, mb_strrpos($str, ' ', 'UTF-8'), 'UTF-8');
return '<p>' . $str . '... ' . '</p>' . '<a class="post-text__more-link" href="#">Читать далее</a>';
}
else {
return '<p>' . $str . '</p>';
}
}
/**
* Возвращает время или дату разнецы
*
* Пример использования:
*
*
*
* @param int $time_unix Разница времяни (между датами)
*
* @return string
*/
function get_date_format(int $time_unix): string
{
if (($time_unix / 60) < 60) {
$time_unix_temp = floor($time_unix / 60);
return $time_unix_temp . ' ' . get_noun_plural_form($time_unix_temp, 'минута', 'минуты', 'минут');
}
else if (($time_unix / 60) >= 60 && ($time_unix / 3600) < 24) {
$time_unix_temp = floor($time_unix / 3600);
return $time_unix_temp . ' ' . get_noun_plural_form($time_unix_temp, 'час', 'часа', 'часов');
}
else if (($time_unix / 3600) >= 24 && ($time_unix / 86400) < 7) {
$time_unix_temp = floor($time_unix / 86400);
return $time_unix_temp . ' ' . get_noun_plural_form($time_unix_temp, 'день', 'дня', 'дней');
}
else if (($time_unix / 86400) >= 7 && ($time_unix / 604800) < 5) {
$time_unix_temp = floor($time_unix / 604800);
return $time_unix_temp . ' ' . get_noun_plural_form($time_unix_temp, 'неделя', 'недели', 'недель');
}
else if (($time_unix / 604800) >= 5) {
$time_unix_temp = floor($time_unix / 2629743);
return $time_unix_temp . ' ' . get_noun_plural_form($time_unix_temp, 'месяц', 'месяца', 'месяцев');
}
}