1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package Blogs |
4
|
|
|
* @category modules |
5
|
|
|
* @author Nazar Mokrynskyi <[email protected]> |
6
|
|
|
* @copyright Copyright (c) 2015-2016, Nazar Mokrynskyi |
7
|
|
|
* @license MIT License, see license.txt |
8
|
|
|
*/ |
9
|
|
|
namespace cs\modules\Blogs; |
10
|
|
|
use |
11
|
|
|
cs\Config, |
12
|
|
|
cs\Language\Prefix, |
13
|
|
|
cs\Page, |
14
|
|
|
cs\User, |
15
|
|
|
h; |
16
|
|
|
|
17
|
|
|
class Helpers { |
18
|
|
|
/** |
19
|
|
|
* Return HTML with posts list |
20
|
|
|
* |
21
|
|
|
* @param int[] $posts |
22
|
|
|
* @param int $posts_count |
23
|
|
|
* @param int $page |
24
|
|
|
* @param string $base_url |
25
|
|
|
* |
26
|
|
|
* @return string |
|
|
|
|
27
|
|
|
*/ |
28
|
|
|
static function show_posts_list ($posts, $posts_count, $page, $base_url) { |
29
|
|
|
$module_data = Config::instance()->module('Blogs'); |
30
|
|
|
$L = new Prefix('blogs_'); |
31
|
|
|
$Page = Page::instance(); |
32
|
|
|
$User = User::instance(); |
33
|
|
|
$Page->content( |
34
|
|
|
h::{'cs-blogs-head-actions'}( |
35
|
|
|
[ |
36
|
|
|
'admin' => $User->admin() && $User->get_permission('admin/Blogs', 'index'), |
37
|
|
|
'can_write_post' => $User->user() && ($User->admin() || !$module_data->new_posts_only_from_admins) |
38
|
|
|
] |
39
|
|
|
) |
40
|
|
|
); |
41
|
|
|
if (!$posts) { |
42
|
|
|
$Page->content( |
43
|
|
|
h::{'p.cs-text-center'}($L->no_posts_yet) |
44
|
|
|
); |
45
|
|
|
return; |
46
|
|
|
} |
47
|
|
|
$Page->content( |
48
|
|
|
h::{'section[is=cs-blogs-posts]'}( |
49
|
|
|
h::{'script[type=application/ld+json]'}( |
50
|
|
|
json_encode( |
51
|
|
|
Posts::instance()->get_as_json_ld($posts), |
52
|
|
|
JSON_UNESCAPED_UNICODE |
53
|
|
|
) |
54
|
|
|
), |
55
|
|
|
[ |
56
|
|
|
'comments_enabled' => $module_data->enable_comments && functionality('comments') |
57
|
|
|
] |
58
|
|
|
). |
59
|
|
|
h::{'.cs-block-margin.cs-text-center.cs-margin nav[is=cs-nav-pagination]'}( |
60
|
|
|
pages( |
61
|
|
|
$page, |
62
|
|
|
ceil($posts_count / $module_data->posts_per_page), |
63
|
|
|
function ($page) use ($base_url) { |
64
|
|
|
return $base_url.($page > 1 ? "/$page" : ''); |
65
|
|
|
}, |
66
|
|
|
true |
67
|
|
|
) |
68
|
|
|
) |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.