1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Module: SmartFAQ |
||
5 | * Author: The SmartFactory <www.smartfactory.ca> |
||
6 | * Licence: GNU |
||
7 | */ |
||
8 | |||
9 | use XoopsModules\Smartfaq; |
||
10 | use XoopsModules\Smartfaq\Constants; |
||
11 | |||
12 | require_once __DIR__ . '/header.php'; |
||
13 | |||
14 | // At which record shall we start for the Categories |
||
15 | $catstart = isset($_GET['catstart']) ? (int)$_GET['catstart'] : 0; |
||
16 | |||
17 | // At which record shall we start for the FAQ |
||
18 | $start = isset($_GET['start']) ? (int)$_GET['start'] : 0; |
||
19 | |||
20 | // Creating the category handler object |
||
21 | /** @var \XoopsModules\Smartfaq\CategoryHandler $categoryHandler */ |
||
22 | $categoryHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Category'); |
||
23 | |||
24 | // Creating the faq handler object |
||
25 | /** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */ |
||
26 | $faqHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Faq'); |
||
27 | |||
28 | $totalCategories = $categoryHandler->getCategoriesCount(0); |
||
29 | |||
30 | // Total number of published FAQ in the module |
||
31 | $totalFaqs = $faqHandler->getFaqsCount(-1, [Constants::SF_STATUS_PUBLISHED, Constants::SF_STATUS_NEW_ANSWER]); |
||
32 | |||
33 | if (0 == $totalFaqs) { |
||
34 | if (($totalCategories > 0) |
||
35 | && ($xoopsModuleConfig['allowrequest'] && $xoopsModuleConfig['anonpost'] |
||
36 | || is_object($xoopsUser))) { |
||
37 | redirect_header('request.php', 2, _AM_SF_NO_TOP_PERMISSIONS); |
||
38 | } else { |
||
39 | redirect_header('../../index.php', 2, _AM_SF_NO_TOP_PERMISSIONS); |
||
40 | } |
||
41 | } |
||
42 | |||
43 | $GLOBALS['xoopsOption']['template_main'] = 'smartfaq_index.tpl'; |
||
44 | |||
45 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||
46 | require_once __DIR__ . '/footer.php'; |
||
47 | |||
48 | // Creating the categories objects |
||
49 | $categoriesObj =& $categoryHandler->getCategories($xoopsModuleConfig['catperpage'], $catstart); |
||
50 | // If no categories are found, exit |
||
51 | $totalCategoriesOnPage = count($categoriesObj); |
||
52 | if (0 == $totalCategoriesOnPage) { |
||
53 | redirect_header('javascript:history.go(-1)', 2, _AM_SF_NO_CAT_EXISTS); |
||
54 | } |
||
55 | // Arrays that will hold the informations passed on to smarty variables |
||
56 | |||
57 | $qnas = []; |
||
58 | |||
59 | //if ($xoopsModuleConfig['displaysubcatonindex']) { |
||
0 ignored issues
–
show
|
|||
60 | $subcats = $categoryHandler->getSubCats($categoriesObj); |
||
61 | //} |
||
62 | $totalQnas = $categoryHandler->publishedFaqsCount(); |
||
63 | $faqHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Faq'); |
||
64 | |||
65 | if (1 == $xoopsModuleConfig['displaylastfaq']) { |
||
66 | // Get the last smartfaq in each category |
||
67 | $last_qnaObj = $faqHandler->getLastPublishedByCat(); |
||
68 | } |
||
69 | $lastfaqsize = (int)$xoopsModuleConfig['lastfaqsize']; |
||
70 | $categories = []; |
||
71 | foreach ($categoriesObj as $cat_id => $category) { |
||
72 | $total = 0; |
||
73 | if (isset($subcats[$cat_id])) { |
||
74 | foreach ($subcats[$cat_id] as $key => $subcat) { |
||
75 | $subcat_id = $subcat->getVar('categoryid'); |
||
76 | if (isset($totalQnas[$subcat_id]) && $totalQnas[$subcat_id] > 0) { |
||
77 | if (isset($last_qnaObj[$subcat_id])) { |
||
78 | $subcat->setVar('last_faqid', $last_qnaObj[$subcat_id]->getVar('faqid')); |
||
79 | $subcat->setVar('last_question_link', "<a href='faq.php?faqid=" . $last_qnaObj[$subcat_id]->getVar('faqid') . "'>" . $last_qnaObj[$subcat_id]->question($lastfaqsize) . '</a>'); |
||
80 | } |
||
81 | $subcat->setVar('faqcount', $totalQnas[$subcat_id]); |
||
82 | if ($xoopsModuleConfig['displaysubcatonindex']) { |
||
83 | $categories[$cat_id]['subcats'][$subcat_id] = $subcat->toArray(); |
||
84 | } |
||
85 | } |
||
86 | $total += $totalQnas[$subcat_id]; |
||
87 | //}replac� ligne 80 |
||
88 | } |
||
89 | } |
||
90 | |||
91 | if (isset($totalQnas[$cat_id]) && $totalQnas[$cat_id] > 0) { |
||
92 | $total += $totalQnas[$cat_id]; |
||
93 | } |
||
94 | if ($total > 0) { |
||
95 | if (isset($last_qnaObj[$cat_id])) { |
||
96 | $category->setVar('last_faqid', $last_qnaObj[$cat_id]->getVar('faqid')); |
||
97 | $category->setVar('last_question_link', "<a href='faq.php?faqid=" . $last_qnaObj[$cat_id]->getVar('faqid') . "'>" . $last_qnaObj[$cat_id]->question($lastfaqsize) . '</a>'); |
||
98 | } |
||
99 | $category->setVar('faqcount', $total); |
||
100 | if (!isset($categories[$cat_id])) { |
||
101 | $categories[$cat_id] = []; |
||
102 | } |
||
103 | } |
||
104 | |||
105 | $categories[$cat_id] = $category->toArray(@$categories[$cat_id]); |
||
106 | $categories[$cat_id]['categoryPath'] = $category->getCategoryPath(); |
||
107 | //}replac� ligne 97 |
||
108 | } |
||
109 | /*echo count($categories); |
||
110 | echo "<br>"; |
||
111 | var_dump($categories); |
||
112 | exit;*/ |
||
113 | $xoopsTpl->assign('categories', $categories); |
||
114 | |||
115 | $displaylastfaqs = $xoopsModuleConfig['displaylastfaqs']; |
||
116 | if ($displaylastfaqs) { |
||
117 | // Creating the last FAQs |
||
118 | $faqsObj = $faqHandler->getAllPublished($xoopsModuleConfig['indexperpage'], $start); |
||
119 | $totalQnasOnPage = count($faqsObj); |
||
120 | $allcategories = $categoryHandler->getObjects(null, true); |
||
121 | if ($faqsObj) { |
||
122 | $userids = []; |
||
123 | foreach ($faqsObj as $key => $thisfaq) { |
||
124 | $faqids[] = $thisfaq->getVar('faqid'); |
||
125 | $userids[$thisfaq->uid()] = 1; |
||
126 | } |
||
127 | /** @var \XoopsModules\Smartfaq\AnswerHandler $answerHandler */ |
||
128 | $answerHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Answer'); |
||
129 | $allanswers = $answerHandler->getLastPublishedByFaq($faqids); |
||
130 | |||
131 | foreach ($allanswers as $key => $thisanswer) { |
||
132 | $userids[$thisanswer->uid()] = 1; |
||
133 | } |
||
134 | |||
135 | $memberHandler = xoops_getHandler('member'); |
||
136 | $users = $memberHandler->getUsers(new \Criteria('uid', '(' . implode(',', array_keys($userids)) . ')', 'IN'), true); |
||
137 | for ($i = 0; $i < $totalQnasOnPage; ++$i) { |
||
138 | $faq = $faqsObj[$i]->toArray(null, $allcategories); |
||
139 | |||
140 | // Creating the answer object |
||
141 | $answerObj = $allanswers[$faqsObj[$i]->faqid()]; |
||
142 | |||
143 | $answerObj->setVar('dohtml', $faqsObj[$i]->getVar('html')); |
||
144 | $answerObj->setVar('doxcode', $faqsObj[$i]->getVar('xcodes')); |
||
145 | $answerObj->setVar('dosmiley', $faqsObj[$i]->getVar('smiley')); |
||
146 | $answerObj->setVar('doimage', $faqsObj[$i]->getVar('image')); |
||
147 | $answerObj->setVar('dobr', $faqsObj[$i]->getVar('linebreak')); |
||
148 | |||
149 | $faq['answer'] = $answerObj->answer(); |
||
150 | $faq['answerid'] = $answerObj->answerid(); |
||
151 | $faq['datesub'] = $faqsObj[$i]->datesub(); |
||
152 | $faq['adminlink'] = Smartfaq\Utility::getAdminLinks($faqsObj[$i]->faqid()); |
||
153 | |||
154 | $faq['who_when'] = $faqsObj[$i]->getWhoAndWhen($answerObj, $users); |
||
155 | |||
156 | $xoopsTpl->append('faqs', $faq); |
||
157 | } |
||
158 | } |
||
159 | } |
||
160 | |||
161 | // Language constants |
||
162 | $moduleName =& $myts->displayTarea($xoopsModule->getVar('name')); |
||
163 | $xoopsTpl->assign('whereInSection', $moduleName); |
||
164 | $xoopsTpl->assign('displaysubcatonindex', $xoopsModuleConfig['displaysubcatonindex']); |
||
165 | $xoopsTpl->assign('displaylastfaqs', $xoopsModuleConfig['displaylastfaqs']); |
||
166 | $xoopsTpl->assign('display_categoryname', true); |
||
167 | $xoopsTpl->assign('displayFull', 'full' === $xoopsModuleConfig['displaytype']); |
||
168 | |||
169 | $xoopsTpl->assign('lang_mainhead', _MD_SF_MAINHEAD . ' ' . $moduleName); |
||
170 | $xoopsTpl->assign('lang_mainintro', $myts->displayTarea($xoopsModuleConfig['indexwelcomemsg'], 1)); |
||
171 | $xoopsTpl->assign('lang_total', _MD_SF_TOTAL_SMARTFAQS); |
||
172 | $xoopsTpl->assign('lang_home', _MD_SF_HOME); |
||
173 | $xoopsTpl->assign('lang_description', _MD_SF_DESCRIPTION); |
||
174 | $xoopsTpl->assign('lang_category', _MD_SF_CATEGORY); |
||
175 | |||
176 | $xoopsTpl->assign('lang_reads', _MD_SF_READS); |
||
177 | $xoopsTpl->assign('lang_smartfaqs', _MD_SF_SMARTFAQS); |
||
178 | $xoopsTpl->assign('lang_last_smartfaq', _MD_SF_LAST_SMARTFAQ); |
||
179 | $xoopsTpl->assign('lang_categories_summary', _MD_SF_INDEX_CATEGORIES_SUMMARY); |
||
180 | $xoopsTpl->assign('lang_categories_summary_info', _MD_SF_INDEX_CATEGORIES_SUMMARY_INFO); |
||
181 | $xoopsTpl->assign('lang_index_faqs', _MD_SF_INDEX_FAQS); |
||
182 | $xoopsTpl->assign('lang_index_faqs_info', _MD_SF_INDEX_FAQS_INFO); |
||
183 | $xoopsTpl->assign('lang_category', _MD_SF_CATEGORY); |
||
184 | $xoopsTpl->assign('lang_editcategory', _MD_SF_CATEGORY_EDIT); |
||
185 | $xoopsTpl->assign('lang_comments', _MD_SF_COMMENTS); |
||
186 | |||
187 | // Category Navigation Bar |
||
188 | require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||
189 | $pagenav = new \XoopsPageNav($totalCategories, $xoopsModuleConfig['catperpage'], $catstart, 'catstart', ''); |
||
190 | if (1 == $xoopsModuleConfig['useimagenavpage']) { |
||
191 | $xoopsTpl->assign('catnavbar', '<div style="text-align:right;">' . $pagenav->renderImageNav() . '</div>'); |
||
192 | } else { |
||
193 | $xoopsTpl->assign('catnavbar', '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>'); |
||
194 | } |
||
195 | |||
196 | // FAQ Navigation Bar |
||
197 | $pagenav = new \XoopsPageNav($totalFaqs, $xoopsModuleConfig['indexperpage'], $start, 'start', ''); |
||
198 | if (1 == $xoopsModuleConfig['useimagenavpage']) { |
||
199 | $xoopsTpl->assign('navbar', '<div style="text-align:right;">' . $pagenav->renderImageNav() . '</div>'); |
||
200 | } else { |
||
201 | $xoopsTpl->assign('navbar', '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>'); |
||
202 | } |
||
203 | |||
204 | // Page Title Hack by marcan |
||
205 | $module_name = $myts->htmlSpecialChars($xoopsModule->getVar('name')); |
||
206 | $xoopsTpl->assign('xoops_pagetitle', $module_name); |
||
207 | // End Page Title Hack by marcan |
||
208 | |||
209 | require_once XOOPS_ROOT_PATH . '/footer.php'; |
||
210 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.