1
|
|
|
<?php namespace core\src\Controller; |
2
|
|
|
|
3
|
|
|
use CMSFactory\Events; |
4
|
|
|
use core\src\CoreFactory; |
5
|
|
|
use core\src\Exception\PageNotFoundException; |
6
|
|
|
|
7
|
|
|
class CategoryController extends Controller |
8
|
|
|
{ |
|
|
|
|
9
|
|
|
|
10
|
|
|
public function index($id) { |
11
|
|
|
$category = $this->model->getCategory($id); |
12
|
|
|
|
13
|
|
|
if (!$category) { |
14
|
|
|
throw new PageNotFoundException(); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** Register event 'Core:_displayCategory' */ |
18
|
|
|
Events::create()->registerEvent($category, 'Core:_displayCategory')->runFactory(); |
19
|
|
|
|
20
|
|
|
$paginationPage = $this->ci->input->get('per_page'); |
21
|
|
|
if ($paginationPage) { |
22
|
|
|
$offset = $paginationPage; |
23
|
|
|
$segment = $this->ci->uri->total_segments(); |
24
|
|
|
} else { |
25
|
|
|
$offset = 0; |
26
|
|
|
$segment = $this->ci->uri->total_segments() + 1; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$row_count = $category['per_page']; |
30
|
|
|
$pages = $this->model->getCategoryPages($category, $row_count, $offset); |
31
|
|
|
|
32
|
|
|
if (!$pages && $offset > 0) { |
33
|
|
|
throw new PageNotFoundException(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$category['total_pages'] = $this->model->countCategoryPages($category); |
37
|
|
|
|
38
|
|
|
if ($category['total_pages'] > $category['per_page']) { |
39
|
|
|
$this->ci->load->library('Pagination'); |
40
|
|
|
|
41
|
|
|
$get = $this->ci->input->get(); |
42
|
|
|
if (isset($get['per_page'])) { |
43
|
|
|
unset($get['per_page']); |
44
|
|
|
} |
45
|
|
|
$get = http_build_query($get); |
46
|
|
|
|
47
|
|
|
$get = $get ? '?' . $get : ''; |
48
|
|
|
|
49
|
|
|
$categoryUrl = '/' . CoreFactory::getUrlParser()->getFullUrl(true, true, false) . $get; |
50
|
|
|
$paginationConfig['base_url'] = $categoryUrl; |
|
|
|
|
51
|
|
|
$paginationConfig['first_url'] = $categoryUrl; |
52
|
|
|
$paginationConfig['first_link'] = '1'; |
53
|
|
|
$paginationConfig['num_links'] = 3; |
54
|
|
|
$paginationConfig['total_rows'] = $category['total_pages']; |
55
|
|
|
$paginationConfig['per_page'] = $category['per_page']; |
56
|
|
|
$paginationConfig['uri_segment'] = $segment; |
57
|
|
|
$paginationConfig['page_query_string'] = false; |
58
|
|
|
|
59
|
|
|
include_once './templates/' . config_item('template') . '/paginations.php'; |
60
|
|
|
|
61
|
|
|
$pagination = $this->ci->pagination; |
62
|
|
|
|
63
|
|
|
$pagination->initialize($paginationConfig); |
64
|
|
|
$this->ci->template->assign('pagination', $pagination->create_links()); |
65
|
|
|
} |
66
|
|
|
// End pagination |
67
|
|
|
|
68
|
|
|
$template = $this->ci->template; |
69
|
|
|
$template->assign('category', $category); |
70
|
|
|
|
71
|
|
|
$countPages = count($pages); |
72
|
|
|
|
73
|
|
|
if ($category['tpl'] == '') { |
74
|
|
|
$categoryTemplate = 'category'; |
75
|
|
|
} else { |
76
|
|
|
$categoryTemplate = $category['tpl']; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if ($countPages > 0) { |
80
|
|
|
if (!file_exists($template->template_dir . $categoryTemplate . '.tpl')) { |
81
|
|
|
show_error(lang("Can't locate category template file.")); |
82
|
|
|
} |
83
|
|
|
$content = $template->read($categoryTemplate, ['pages' => $pages]); |
84
|
|
|
|
85
|
|
|
} else { |
86
|
|
|
$content = $template->read($categoryTemplate, ['no_pages' => lang('In the category has no pages.', 'core')]); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$category['title'] == NULL ? $category['title'] = $category['name'] : TRUE; |
90
|
|
|
|
91
|
|
|
$category['description'] = $this->ci->core->_makeDescription($category['description']); |
92
|
|
|
|
93
|
|
|
$category['keywords'] = $this->ci->core->_makeKeywords($category['keywords'], $category['short_desc']); |
94
|
|
|
|
95
|
|
|
// adding page number for pages with pagination (from second page) |
96
|
|
|
$currentPage = $pagination->cur_page; |
97
|
|
|
if ($currentPage > 1) { |
98
|
|
|
$title = $category['title'] . ' - ' . $currentPage; |
99
|
|
|
$description = $category['description'] . ' - ' . $currentPage; |
100
|
|
|
|
101
|
|
|
$this->ci->core->set_meta_tags($title, $category['keywords'], $description); |
102
|
|
|
} else { |
103
|
|
|
$this->ci->core->set_meta_tags($category['title'], $category['keywords'], $category['description']); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$this->ci->core->cat_content = $category; |
107
|
|
|
|
108
|
|
|
$template->assign('content', $content); |
109
|
|
|
|
110
|
|
|
Events::create()->registerEvent($category, 'pageCategory:load'); |
111
|
|
|
Events::runFactory(); |
112
|
|
|
|
113
|
|
|
$category['main_tpl'] ? $template->display($category['main_tpl']) : $template->show(); |
114
|
|
|
|
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
} |