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