-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcategory.php
197 lines (160 loc) · 7.66 KB
/
category.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php declare(strict_types=1);
/**
* Module: SmartFAQ
* Author: The SmartFactory <www.smartfactory.ca>
* Licence: GNU
*/
use Xmf\Request;
use XoopsModules\Smartfaq;
use XoopsModules\Smartfaq\Helper;
$GLOBALS['xoopsOption']['template_main'] = 'smartfaq_category.tpl';
require_once __DIR__ . '/header.php';
/** @var Smartfaq\Helper $helper */
$helper = Helper::getInstance();
$categoryid = Request::getInt('categoryid', 0, 'GET');
// Creating the category handler object
/** @var \XoopsModules\Smartfaq\CategoryHandler $categoryHandler */
$categoryHandler = Helper::getInstance()->getHandler('Category');
// Creating the category object for the selected category
$categoryObj = new Smartfaq\Category($categoryid);
// If the selected category was not found, exit
if ($categoryObj->notLoaded()) {
redirect_header('<script>javascript:history.go(-1)</script>', 1, _MD_SF_NOCATEGORYSELECTED);
}
// Check user permissions to access this category
if (!$categoryObj->checkPermission()) {
redirect_header('<script>javascript:history.go(-1)</script>', 1, _NOPERM);
}
$totalQnas = $categoryHandler->publishedFaqsCount($categoryid);
// If there is no FAQ under these categories or the sub-categories, exit
if (!isset($totalQnas[$categoryid]) || 0 == $totalQnas[$categoryid]) {
//redirect_header("index.php", 1, _MD_SF_MAINNOFAQS);
}
require_once XOOPS_ROOT_PATH . '/header.php';
require_once __DIR__ . '/footer.php';
// At which record shall we start
$start = Request::getInt('start', 0, 'GET');
// Creating the faq handler object
/** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */
$faqHandler = Helper::getInstance()->getHandler('Faq');
// creating the FAQ objects that belong to the selected category
if (1 == $helper->getConfig('orderbydate')) {
$sort = 'datesub';
$order = 'DESC';
} else {
$sort = 'weight';
$order = 'ASC';
}
$faqsObj = $faqHandler->getAllPublished($helper->getConfig('indexperpage'), $start, $categoryid, $sort, $order);
$totalQnasOnPage = 0;
if ($faqsObj) {
$totalQnasOnPage = count($faqsObj);
}
// Arrays that will hold the information passed on to smarty variables
$category = [];
$qnas = [];
// Populating the smarty variables with information related to the selected category
$category = $categoryObj->toArray(null, true);
$totalQnas = $categoryHandler->publishedFaqsCount();
$category['categoryPath'] = $categoryObj->getCategoryPath();
if (1 == $helper->getConfig('displaylastfaq')) {
// Get the last smartfaq
$last_qnaObj = $faqHandler->getLastPublishedByCat();
}
$lastfaqsize = (int)$helper->getConfig('lastfaqsize');
// Creating the sub-categories objects that belong to the selected category
$subcatsObj = &$categoryHandler->getCategories(0, 0, $categoryid);
$total_subcats = count($subcatsObj);
$total_faqs = 0;
if (0 != $total_subcats) {
$subcat_keys = array_keys($subcatsObj);
foreach ($subcat_keys as $i) {
$subcat_id = $subcatsObj[$i]->getVar('categoryid');
if (isset($totalQnas[$subcat_id]) && $totalQnas[$subcat_id] > 0) {
if (isset($last_qnaObj[$subcat_id])) {
$subcatsObj[$i]->setVar('last_faqid', $last_qnaObj[$subcat_id]->getVar('faqid'));
$subcatsObj[$i]->setVar('last_question_link', "<a href='faq.php?faqid=" . $last_qnaObj[$subcat_id]->getVar('faqid') . "'>" . $last_qnaObj[$subcat_id]->question($lastfaqsize) . '</a>');
}
}
$subcatsObj[$i]->setVar('faqcount', $totalQnas[$subcat_id]);
$subcats[$subcat_id] = $subcatsObj[$i]->toArray();
$total_faqs += $totalQnas[$subcat_id];
//}replacé ligne 92
}
$xoopsTpl->assign('subcats', $subcats);
}
$thiscategory_faqcount = $totalQnas[$categoryid] ?? 0;
$category['total'] = $thiscategory_faqcount + $total_faqs;
if (is_array($faqsObj) && ($faqsObj) > 0) {
$userids = [];
foreach ($faqsObj as $key => $thisfaq) {
$faqids[] = $thisfaq->getVar('faqid');
$userids[$thisfaq->uid()] = 1;
}
/** @var \XoopsModules\Smartfaq\AnswerHandler $answerHandler */
$answerHandler = Helper::getInstance()->getHandler('Answer');
$allanswers = $answerHandler->getLastPublishedByFaq($faqids);
foreach ($allanswers as $key => $thisanswer) {
$userids[$thisanswer->uid()] = 1;
}
/** @var \XoopsMemberHandler $memberHandler */
$memberHandler = xoops_getHandler('member');
$users = $memberHandler->getUsers(new \Criteria('uid', '(' . implode(',', array_keys($userids)) . ')', 'IN'), true);
// Adding the Q&As of the selected category
foreach ($faqsObj as $iValue) {
$faq = $iValue->toArray(null, $categoryObj);
// Creating the answer object
$answerObj = $allanswers[$iValue->faqid()];
$answerObj->setVar('dohtml', $iValue->getVar('html'));
$answerObj->setVar('doxcode', $iValue->getVar('xcodes'));
$answerObj->setVar('dosmiley', $iValue->getVar('smiley'));
$answerObj->setVar('doimage', $iValue->getVar('image'));
$answerObj->setVar('dobr', $iValue->getVar('linebreak'));
$faq['answer'] = $answerObj->answer();
$faq['answerid'] = $answerObj->answerid();
$faq['datesub'] = $iValue->datesub();
$faq['adminlink'] = Smartfaq\Utility::getAdminLinks($iValue->faqid());
$faq['who_when'] = $iValue->getWhoAndWhen($answerObj, $users);
$xoopsTpl->append('faqs', $faq);
}
if (!empty($last_qnaObj)) {
$category['last_faqid'] = $last_qnaObj[$categoryObj->getVar('categoryid')]->getVar('faqid');
$category['last_question_link'] = "<a href='faq.php?faqid=" . $last_qnaObj[$categoryObj->getVar('categoryid')]->getVar('faqid') . "'>" . $last_qnaObj[$categoryObj->getVar('categoryid')]->question($lastfaqsize) . '</a>';
}
}
$xoopsTpl->assign('whereInSection', $myts->displayTarea($xoopsModule->getVar('name')));
$xoopsTpl->assign('displaylastfaqs', true);
$xoopsTpl->assign('display_categoryname', true);
$xoopsTpl->assign('displayFull', 'full' === $helper->getConfig('displaytype'));
// Language constants
$xoopsTpl->assign('lang_index_faqs', _MD_SF_SMARTFAQS);
$xoopsTpl->assign('lang_index_faqs_info', _MD_SF_SMARTFAQS_INFO);
$xoopsTpl->assign('lang_category', $totalQnasOnPage);
$xoopsTpl->assign('lang_reads', _MD_SF_READS);
$xoopsTpl->assign('lang_home', _MD_SF_HOME);
$xoopsTpl->assign('lang_smartfaqs', _MD_SF_SMARTFAQS);
$xoopsTpl->assign('lang_last_smartfaq', _MD_SF_LAST_SMARTFAQ);
$xoopsTpl->assign('lang_category_summary', _MD_SF_CATEGORY_SUMMARY);
$xoopsTpl->assign('lang_category_summary_info', _MD_SF_CATEGORY_SUMMARY_INFO);
$xoopsTpl->assign('lang_category', _MD_SF_CATEGORY);
$xoopsTpl->assign('lang_comments', _MD_SF_COMMENTS);
// The Navigation Bar
require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
$pagenav = new \XoopsPageNav($thiscategory_faqcount, $helper->getConfig('indexperpage'), $start, 'start', 'categoryid=' . $categoryObj->getVar('categoryid'));
if (1 == $helper->getConfig('useimagenavpage')) {
$xoopsTpl->assign('navbar', '<div style="text-align:right;">' . $pagenav->renderImageNav() . '</div>');
} else {
$xoopsTpl->assign('navbar', '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>');
}
$xoopsTpl->assign('category', $category);
// Page Title Hack by marcan
$module_name = htmlspecialchars($xoopsModule->getVar('name'), ENT_QUOTES | ENT_HTML5);
$xoopsTpl->assign('xoops_pagetitle', $module_name . ' - ' . $category['name']);
// End Page Title Hack by marcan
//code to include smartie
if (file_exists(XOOPS_ROOT_PATH . '/modules/smarttie/smarttie_links.php')) {
require_once XOOPS_ROOT_PATH . '/modules/smarttie/smarttie_links.php';
$xoopsTpl->assign('smarttie', 1);
}
//end code for smarttie
require_once XOOPS_ROOT_PATH . '/footer.php';