-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshow.php
131 lines (117 loc) · 4.14 KB
/
show.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/**
* Frontend for categories or list of records.
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/.
*
* @package phpMyFAQ
* @author Thorsten Rinne <[email protected]>
* @copyright 2002-2022 phpMyFAQ Team
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
* @link https://www.phpmyfaq.de
* @since 2002-08-27
*/
use phpMyFAQ\Category;
use phpMyFAQ\Filter;
use phpMyFAQ\Helper\CategoryHelper;
use phpMyFAQ\Link;
if (!defined('IS_VALID_PHPMYFAQ')) {
http_response_code(400);
exit();
}
$selectedCategoryId = Filter::filterInput(INPUT_GET, 'cat', FILTER_VALIDATE_INT);
$subCategoryContent = '';
if (!is_null($selectedCategoryId) && !isset($category->categoryName[$selectedCategoryId])) {
$http->setStatus(404);
}
$categoryHelper = new CategoryHelper();
if (!is_null($selectedCategoryId) && isset($category->categoryName[$selectedCategoryId])) {
try {
$faqSession->userTracking('show_category', $selectedCategoryId);
} catch (Exception $e) {
// @todo handle the exception
}
$categoryData = $category->getCategoryData($selectedCategoryId);
$records = $faq->renderRecordsByCategoryId(
$selectedCategoryId,
$faqConfig->get('records.orderby'),
$faqConfig->get('records.sortby')
);
if (empty($records) || $category->getChildNodes((int) $selectedCategoryId)) {
$subCategory = new Category($faqConfig, $currentGroups, true);
$subCategory->setUser($currentUser);
$subCategory->transform($selectedCategoryId);
$categoryHelper
->setConfiguration($faqConfig)
->setCategory($subCategory);
if (empty($records)) {
$records = $categoryHelper->renderCategoryTree();
}
if (count($category->getChildNodes((int) $selectedCategoryId))) {
$categoryFaqsHeader = $PMF_LANG['msgSubCategories'];
$subCategoryContent = $categoryHelper->renderCategoryTree();
$template->parseBlock(
'mainPageContent',
'subCategories',
[
'categorySubsHeader' => $categoryFaqsHeader
]
);
}
}
$up = '';
if ($categoryData->getParentId() !== 0) {
$url = sprintf(
'%sindex.php?%saction=show&cat=%d',
$faqConfig->getDefaultUrl(),
$sids,
$categoryData->getParentId()
);
$oLink = new Link($url, $faqConfig);
$oLink->itemTitle = $category->categoryName[$categoryData->getParentId()]['name'];
$oLink->text = $PMF_LANG['msgCategoryUp'];
$up = $oLink->toHtmlAnchor();
}
if (!is_null($categoryData->getImage()) && strlen($categoryData->getImage()) > 0) {
$template->parseBlock(
'mainPageContent',
'categoryImage',
[
'categoryImage' => $faqConfig->getDefaultUrl() . '/images/' . $categoryData->getImage(),
]
);
}
$template->parse(
'mainPageContent',
[
'categoryHeader' => $PMF_LANG['msgEntriesIn'] . $categoryData->getName(),
'categoryDescription' => $categoryData->getDescription(),
'categoryFaqsHeader' => $PMF_LANG['msgEntries'],
'categoryContent' => $records,
'subCategoryContent' => $subCategoryContent,
'categoryLevelUp' => $up
]
);
} else {
try {
$faqSession->userTracking('show_all_categories', 0);
} catch (Exception $e) {
// @todo handle the exception
}
$categoryHelper
->setConfiguration($faqConfig)
->setCategory($category);
$template->parse(
'mainPageContent',
[
'categoryHeader' => $PMF_LANG['msgFullCategories'],
'categoryDescription' => '',
'categoryFaqsHeader' => '',
'categoryContent' => $categoryHelper->renderCategoryTree(),
'subCategoryContent' => $subCategoryContent,
'categoryLevelUp' => '',
]
);
}