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