mambax7 /
smartfaq
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
| 1 | <?php declare(strict_types=1); |
||
| 2 | |||
| 3 | /** |
||
| 4 | * Module: SmartFAQ |
||
| 5 | * Author: The SmartFactory <www.smartfactory.ca> |
||
| 6 | * Licence: GNU |
||
| 7 | */ |
||
| 8 | |||
| 9 | use Xmf\Request; |
||
| 10 | use XoopsModules\Smartfaq; |
||
| 11 | use XoopsModules\Smartfaq\Constants; |
||
| 12 | use XoopsModules\Smartfaq\Helper; |
||
| 13 | |||
| 14 | $GLOBALS['xoopsOption']['template_main'] = 'smartfaq_index.tpl'; |
||
| 15 | |||
| 16 | require_once __DIR__ . '/header.php'; |
||
| 17 | |||
| 18 | global $xoopsConfig, $xoopsModule; |
||
| 19 | /** @var Smartfaq\Helper $helper */ |
||
| 20 | $helper = Helper::getInstance(); |
||
| 21 | |||
| 22 | // At which record shall we start for the Categories |
||
| 23 | $catstart = Request::getInt('catstart', 0, 'GET'); |
||
| 24 | |||
| 25 | // At which record shall we start for the FAQs |
||
| 26 | $start = Request::getInt('start', 0, 'GET'); |
||
| 27 | |||
| 28 | // Creating the category handler object |
||
| 29 | $categoryHandler = Helper::getInstance()->getHandler('Category'); |
||
| 30 | |||
| 31 | // Get the total number of categories |
||
| 32 | $totalCategories = count($categoryHandler->getCategories()); |
||
| 33 | |||
| 34 | // Creating the faq handler object |
||
| 35 | /** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */ |
||
| 36 | $faqHandler = Helper::getInstance()->getHandler('Faq'); |
||
| 37 | |||
| 38 | // Total number of published FAQ in the module |
||
| 39 | $totalFaqs = $faqHandler->getFaqsCount(-1, Constants::SF_STATUS_OPENED); |
||
| 40 | if (0 == $totalFaqs) { |
||
| 41 | redirect_header('request.php', 2, _MD_SF_NO_OPEN_QUESTION); |
||
| 42 | } |
||
| 43 | |||
| 44 | // Creating the categories objects |
||
| 45 | $categoriesObj = $categoryHandler->getCategories($helper->getConfig('catperpage'), $catstart); |
||
| 46 | |||
| 47 | // If no categories are found, exit |
||
| 48 | $totalCategoriesOnPage = count($categoriesObj); |
||
| 49 | if (0 == $totalCategoriesOnPage) { |
||
| 50 | redirect_header('<script>javascript:history.go(-1)</script>', 2, _AM_SF_NO_CAT_EXISTS); |
||
| 51 | } |
||
| 52 | |||
| 53 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||
| 54 | require_once __DIR__ . '/footer.php'; |
||
| 55 | |||
| 56 | //get all categories for future reference |
||
| 57 | $allcategories = $categoryHandler->getObjects(null, true); |
||
| 58 | |||
| 59 | // Arrays that will hold the information passed on to smarty variables |
||
| 60 | $qnas = []; |
||
| 61 | $categories = []; |
||
| 62 | $subcats = $categoryHandler->getSubCats($categoriesObj); |
||
| 63 | $totalQnas = $categoryHandler->faqsCount(0, [Constants::SF_STATUS_OPENED]); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 64 | |||
| 65 | $faqHandler = Helper::getInstance()->getHandler('Faq'); |
||
| 66 | $last_qnaObj = $faqHandler->getLastPublishedByCat([Constants::SF_STATUS_OPENED]); |
||
| 67 | |||
| 68 | foreach ($categoriesObj as $cat_id => $category) { |
||
| 69 | $total = 0; |
||
| 70 | if (isset($subcats[$cat_id]) && count($subcats[$cat_id]) > 0) { |
||
| 71 | foreach ($subcats[$cat_id] as $key => $subcat) { |
||
| 72 | $subcat_id = $subcat->getVar('categoryid'); |
||
| 73 | if (isset($totalQnas[$subcat_id]) && $totalQnas[$subcat_id] > 0) { |
||
| 74 | if (isset($last_qnaObj[$subcat_id])) { |
||
| 75 | $subcat->setVar('last_faqid', $last_qnaObj[$subcat_id]->getVar('faqid')); |
||
| 76 | $subcat->setVar('last_question_link', "<a href='faq.php?faqid=" . $last_qnaObj[$subcat_id]->getVar('faqid') . "'>" . $last_qnaObj[$subcat_id]->question(50) . '</a>'); |
||
| 77 | } |
||
| 78 | $subcat->setVar('faqcount', $totalQnas[$subcat_id]); |
||
| 79 | $categories[$cat_id]['subcats'][$subcat_id] = $subcat->toArray(null, true); |
||
| 80 | $total += $totalQnas[$subcat_id]; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 | if (isset($totalQnas[$cat_id]) && $totalQnas[$cat_id] > 0) { |
||
| 85 | $total += $totalQnas[$cat_id]; |
||
| 86 | } |
||
| 87 | if ($total > 0) { |
||
| 88 | $category->setVar('faqcount', $total); |
||
| 89 | if (!isset($categories[$cat_id])) { |
||
| 90 | $categories[$cat_id] = []; |
||
| 91 | } |
||
| 92 | $categories[$cat_id] = $category->toArray($categories[$cat_id], true); |
||
| 93 | $categories[$cat_id]['categoryPath'] = $category->getCategoryPath(); |
||
| 94 | } |
||
| 95 | } |
||
| 96 | $xoopsTpl->assign('categories', $categories); |
||
| 97 | |||
| 98 | $displaylastfaqs = $helper->getConfig('displaylastfaqs'); |
||
| 99 | if ($displaylastfaqs) { |
||
| 100 | // Creating the last FAQs |
||
| 101 | $faqsObj = $faqHandler->getFaqs($helper->getConfig('indexperpage'), $start, Constants::SF_STATUS_OPENED); |
||
| 102 | $totalQnasOnPage = count($faqsObj); |
||
| 103 | |||
| 104 | if ($faqsObj) { |
||
| 105 | $userids = []; |
||
| 106 | foreach ($faqsObj as $key => $thisfaq) { |
||
| 107 | $faqids[] = $thisfaq->getVar('faqid'); |
||
| 108 | $userids[$thisfaq->uid()] = 1; |
||
| 109 | } |
||
| 110 | |||
| 111 | /** @var \XoopsMemberHandler $memberHandler */ |
||
| 112 | $memberHandler = xoops_getHandler('member'); |
||
| 113 | $users = $memberHandler->getUsers(new \Criteria('uid', '(' . implode(',', array_keys($userids)) . ')', 'IN'), true); |
||
| 114 | for ($i = 0; $i < $totalQnasOnPage; ++$i) { |
||
| 115 | $faq = $faqsObj[$i]->toArray(null, $allcategories); |
||
| 116 | |||
| 117 | $faq['adminlink'] = Smartfaq\Utility::getAdminLinks($faqsObj[$i]->faqid(), true); |
||
| 118 | |||
| 119 | $faq['who_when'] = $faqsObj[$i]->getWhoAndWhen(null, $users); |
||
| 120 | |||
| 121 | $xoopsTpl->append('faqs', $faq); |
||
| 122 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 | // Language constants |
||
| 126 | $moduleName = &$myts->displayTarea($xoopsModule->getVar('name')); |
||
| 127 | $xoopsTpl->assign( |
||
| 128 | [ |
||
| 129 | 'lang_on' => _MD_SF_ON, |
||
| 130 | 'lang_postedby' => _MD_SF_POSTEDBY, |
||
| 131 | 'lang_total' => $totalQnasOnPage, |
||
| 132 | 'lang_faq' => _MD_SF_FAQ, |
||
| 133 | 'lang_datesub' => _MD_SF_DATESUB, |
||
| 134 | 'lang_hits' => _MD_SF_HITS, |
||
| 135 | ] |
||
| 136 | ); |
||
| 137 | |||
| 138 | $moduleName = &$myts->displayTarea($xoopsModule->getVar('name')); |
||
| 139 | $xoopsTpl->assign('lang_mainhead', sprintf(_MD_SF_OPEN_WELCOME, $xoopsConfig['sitename'])); |
||
| 140 | $xoopsTpl->assign('lang_mainintro', $myts->displayTarea($helper->getConfig('openquestionintromsg'), 1)); |
||
| 141 | $xoopsTpl->assign('lang_total', _MD_SF_TOTAL_QUESTIONS); |
||
| 142 | $xoopsTpl->assign('lang_home', _MD_SF_HOME); |
||
| 143 | $xoopsTpl->assign('lang_description', _MD_SF_DESCRIPTION); |
||
| 144 | $xoopsTpl->assign('lang_category', _MD_SF_CATEGORY); |
||
| 145 | $xoopsTpl->assign('sectionname', $moduleName); |
||
| 146 | $xoopsTpl->assign('whereInSection', "<a href='index.php'>" . $moduleName . '</a> > ' . _MD_SF_OPEN_SECTION); |
||
| 147 | |||
| 148 | $xoopsTpl->assign('displayFull', false); |
||
| 149 | $xoopsTpl->assign('displaylastfaqs', $helper->getConfig('displaylastfaqs')); |
||
| 150 | $xoopsTpl->assign('display_categoryname', true); |
||
| 151 | |||
| 152 | $xoopsTpl->assign('lang_reads', _MD_SF_READS); |
||
| 153 | $xoopsTpl->assign('lang_smartfaqs', _MD_SF_SMARTFAQS); |
||
| 154 | $xoopsTpl->assign('lang_last_smartfaq', _MD_SF_LAST_SMARTFAQ); |
||
| 155 | $xoopsTpl->assign('lang_categories_summary', _MD_SF_INDEX_CATEGORIES_SUMMARY); |
||
| 156 | $xoopsTpl->assign('lang_categories_summary_info', _MD_SF_INDEX_CATEGORIES_QUESTIONS_SUMMARY_INFO); |
||
| 157 | $xoopsTpl->assign('lang_index_faqs', _MD_SF_INDEX_QUESTIONS); |
||
| 158 | $xoopsTpl->assign('lang_index_faqs_info', _MD_SF_INDEX_QUESTIONS_INFO); |
||
| 159 | $xoopsTpl->assign('lang_category', _MD_SF_CATEGORY); |
||
| 160 | |||
| 161 | // Category Navigation Bar |
||
| 162 | require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||
| 163 | $pagenav = new \XoopsPageNav($totalCategories, $helper->getConfig('catperpage'), $catstart, 'catstart', ''); |
||
| 164 | if (1 == $helper->getConfig('useimagenavpage')) { |
||
| 165 | $xoopsTpl->assign('catnavbar', '<div style="text-align:right;">' . $pagenav->renderImageNav() . '</div>'); |
||
| 166 | } else { |
||
| 167 | $xoopsTpl->assign('catnavbar', '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>'); |
||
| 168 | } |
||
| 169 | |||
| 170 | // FAQ Navigation Bar |
||
| 171 | $pagenav = new \XoopsPageNav($totalFaqs, $helper->getConfig('indexperpage'), $start, 'start', ''); |
||
| 172 | if (1 == $helper->getConfig('useimagenavpage')) { |
||
| 173 | $xoopsTpl->assign('navbar', '<div style="text-align:right;">' . $pagenav->renderImageNav() . '</div>'); |
||
| 174 | } else { |
||
| 175 | $xoopsTpl->assign('navbar', '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>'); |
||
| 176 | } |
||
| 177 | |||
| 178 | // Page Title Hack by marcan |
||
| 179 | $module_name = htmlspecialchars($xoopsModule->getVar('name'), ENT_QUOTES | ENT_HTML5); |
||
| 180 | $xoopsTpl->assign('xoops_pagetitle', $module_name . ' - ' . $category->getVar('name')); |
||
| 181 | // End Page Title Hack by marcan |
||
| 182 | |||
| 183 | require_once XOOPS_ROOT_PATH . '/footer.php'; |
||
| 184 |