-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.php
225 lines (187 loc) · 8.79 KB
/
index.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<?php declare(strict_types=1);
/**
* Module: SmartFAQ
* Author: The SmartFactory <www.smartfactory.ca>
* Licence: GNU
*/
use Xmf\Request;
use XoopsModules\Smartfaq\{
AnswerHandler,
CategoryHandler,
Constants,
FaqHandler,
Helper,
Utility
};
/** @var Helper $helper */
/** @var Utility $utility */
/** @var CategoryHandler $categoryHandler */
/** @var FaqHandler $faqHandler */
/** @var AnswerHandler $answerHandler */
$GLOBALS['xoopsOption']['template_main'] = 'smartfaq_index.tpl';
require_once __DIR__ . '/header.php';
$helper = Helper::getInstance();
// At which record shall we start for the Categories
$catstart = Request::getInt('catstart', 0, 'GET');
// At which record shall we start for the FAQ
$start = Request::getInt('start', 0, 'GET');
// Creating the category handler object
$categoryHandler = Helper::getInstance()->getHandler('Category');
// Creating the faq handler object
$faqHandler = Helper::getInstance()->getHandler('Faq');
$totalCategories = $categoryHandler->getCategoriesCount(0);
// Total number of published FAQ in the module
$totalFaqs = $faqHandler->getFaqsCount(-1, [Constants::SF_STATUS_PUBLISHED, Constants::SF_STATUS_NEW_ANSWER]);
if (0 == $totalFaqs) {
if (($totalCategories > 0)
&& ($helper->getConfig('allowrequest') && $helper->getConfig('anonpost')
|| is_object($xoopsUser))) {
redirect_header('request.php', 2, _AM_SF_NO_TOP_PERMISSIONS);
} else {
redirect_header('../../index.php', 2, _AM_SF_NO_TOP_PERMISSIONS);
}
}
require_once XOOPS_ROOT_PATH . '/header.php';
require_once __DIR__ . '/footer.php';
// Creating the categories objects
$categoriesObj = &$categoryHandler->getCategories($helper->getConfig('catperpage'), $catstart);
// If no categories are found, exit
$totalCategoriesOnPage = count($categoriesObj);
if (0 == $totalCategoriesOnPage) {
redirect_header('<script>javascript:history.go(-1)</script>', 2, _AM_SF_NO_CAT_EXISTS);
}
// Arrays that will hold the information passed on to smarty variables
$qnas = [];
//if ($helper->getConfig('displaysubcatonindex')) {
$subcats = $categoryHandler->getSubCats($categoriesObj);
//}
$totalQnas = $categoryHandler->publishedFaqsCount();
$faqHandler = Helper::getInstance()->getHandler('Faq');
if (1 == $helper->getConfig('displaylastfaq')) {
// Get the last smartfaq in each category
$last_qnaObj = $faqHandler->getLastPublishedByCat();
}
$lastfaqsize = (int)$helper->getConfig('lastfaqsize');
$categories = [];
foreach ($categoriesObj as $cat_id => $category) {
$total = 0;
if (isset($subcats[$cat_id])) {
foreach ($subcats[$cat_id] as $key => $subcat) {
$subcat_id = $subcat->getVar('categoryid');
if (isset($totalQnas[$subcat_id]) && $totalQnas[$subcat_id] > 0) {
if (isset($last_qnaObj[$subcat_id])) {
$subcat->setVar('last_faqid', $last_qnaObj[$subcat_id]->getVar('faqid'));
$subcat->setVar('last_question_link', "<a href='faq.php?faqid=" . $last_qnaObj[$subcat_id]->getVar('faqid') . "'>" . $last_qnaObj[$subcat_id]->question($lastfaqsize) . '</a>');
}
$subcat->setVar('faqcount', $totalQnas[$subcat_id]);
if ($helper->getConfig('displaysubcatonindex')) {
$categories[$cat_id]['subcats'][$subcat_id] = $subcat->toArray();
}
}
$total += $totalQnas[$subcat_id];
//}replac� ligne 80
}
}
if (isset($totalQnas[$cat_id]) && $totalQnas[$cat_id] > 0) {
$total += $totalQnas[$cat_id];
}
if ($total > 0) {
if (isset($last_qnaObj[$cat_id])) {
$category->setVar('last_faqid', $last_qnaObj[$cat_id]->getVar('faqid'));
$category->setVar('last_question_link', "<a href='faq.php?faqid=" . $last_qnaObj[$cat_id]->getVar('faqid') . "'>" . $last_qnaObj[$cat_id]->question($lastfaqsize) . '</a>');
}
$category->setVar('faqcount', $total);
if (!isset($categories[$cat_id])) {
$categories[$cat_id] = [];
}
}
$categories[$cat_id] = $category->toArray(@$categories[$cat_id]);
$categories[$cat_id]['categoryPath'] = $category->getCategoryPath();
//}replac� ligne 97
}
/*echo count($categories);
echo "<br>";
var_dump($categories);
exit;*/
$xoopsTpl->assign('categories', $categories);
$displaylastfaqs = $helper->getConfig('displaylastfaqs');
if ($displaylastfaqs) {
// Creating the last FAQs
$faqsObj = $faqHandler->getAllPublished($helper->getConfig('indexperpage'), $start);
$totalQnasOnPage = count($faqsObj);
$allcategories = $categoryHandler->getObjects(null, true);
if ($faqsObj) {
$userids = [];
foreach ($faqsObj as $key => $thisfaq) {
$faqids[] = $thisfaq->getVar('faqid');
$userids[$thisfaq->uid()] = 1;
}
$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);
for ($i = 0; $i < $totalQnasOnPage; ++$i) {
$faq = $faqsObj[$i]->toArray(null, $allcategories);
// Creating the answer object
$answerObj = $allanswers[$faqsObj[$i]->faqid()];
$answerObj->setVar('dohtml', $faqsObj[$i]->getVar('html'));
$answerObj->setVar('doxcode', $faqsObj[$i]->getVar('xcodes'));
$answerObj->setVar('dosmiley', $faqsObj[$i]->getVar('smiley'));
$answerObj->setVar('doimage', $faqsObj[$i]->getVar('image'));
$answerObj->setVar('dobr', $faqsObj[$i]->getVar('linebreak'));
$faq['answer'] = $answerObj->answer();
$faq['answerid'] = $answerObj->answerid();
$faq['datesub'] = $faqsObj[$i]->datesub();
$faq['adminlink'] = Utility::getAdminLinks($faqsObj[$i]->faqid());
$faq['who_when'] = $faqsObj[$i]->getWhoAndWhen($answerObj, $users);
$xoopsTpl->append('faqs', $faq);
}
}
}
// Language constants
$moduleName = &$myts->displayTarea($xoopsModule->getVar('name'));
$xoopsTpl->assign('whereInSection', $moduleName);
$xoopsTpl->assign('displaysubcatonindex', $helper->getConfig('displaysubcatonindex'));
$xoopsTpl->assign('displaylastfaqs', $helper->getConfig('displaylastfaqs'));
$xoopsTpl->assign('display_categoryname', true);
$xoopsTpl->assign('displayFull', 'full' === $helper->getConfig('displaytype'));
$xoopsTpl->assign('lang_mainhead', _MD_SF_MAINHEAD . ' ' . $moduleName);
$xoopsTpl->assign('lang_mainintro', $myts->displayTarea($helper->getConfig('indexwelcomemsg'), 1));
$xoopsTpl->assign('lang_total', _MD_SF_TOTAL_SMARTFAQS);
$xoopsTpl->assign('lang_home', _MD_SF_HOME);
$xoopsTpl->assign('lang_description', _MD_SF_DESCRIPTION);
$xoopsTpl->assign('lang_category', _MD_SF_CATEGORY);
$xoopsTpl->assign('lang_reads', _MD_SF_READS);
$xoopsTpl->assign('lang_smartfaqs', _MD_SF_SMARTFAQS);
$xoopsTpl->assign('lang_last_smartfaq', _MD_SF_LAST_SMARTFAQ);
$xoopsTpl->assign('lang_categories_summary', _MD_SF_INDEX_CATEGORIES_SUMMARY);
$xoopsTpl->assign('lang_categories_summary_info', _MD_SF_INDEX_CATEGORIES_SUMMARY_INFO);
$xoopsTpl->assign('lang_index_faqs', _MD_SF_INDEX_FAQS);
$xoopsTpl->assign('lang_index_faqs_info', _MD_SF_INDEX_FAQS_INFO);
$xoopsTpl->assign('lang_category', _MD_SF_CATEGORY);
$xoopsTpl->assign('lang_editcategory', _MD_SF_CATEGORY_EDIT);
$xoopsTpl->assign('lang_comments', _MD_SF_COMMENTS);
// Category Navigation Bar
require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
$pagenav = new \XoopsPageNav($totalCategories, $helper->getConfig('catperpage'), $catstart, 'catstart', '');
if (1 == $helper->getConfig('useimagenavpage')) {
$xoopsTpl->assign('catnavbar', '<div style="text-align:right;">' . $pagenav->renderImageNav() . '</div>');
} else {
$xoopsTpl->assign('catnavbar', '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>');
}
// FAQ Navigation Bar
$pagenav = new \XoopsPageNav($totalFaqs, $helper->getConfig('indexperpage'), $start, 'start', '');
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>');
}
// Page Title Hack by marcan
$module_name = htmlspecialchars($xoopsModule->getVar('name'), ENT_QUOTES | ENT_HTML5);
$xoopsTpl->assign('xoops_pagetitle', $module_name);
// End Page Title Hack by marcan
require_once XOOPS_ROOT_PATH . '/footer.php';