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 | /** @var Smartfaq\Helper $helper */ |
||
| 12 | $helper = Smartfaq\Helper::getInstance(); |
||
| 13 | |||
| 14 | require_once __DIR__ . '/header.php'; |
||
| 15 | |||
| 16 | global $xoopsConfig, $xoopsModule; |
||
|
0 ignored issues
–
show
|
|||
| 17 | |||
| 18 | $GLOBALS['xoopsOption']['template_main'] = 'smartfaq_category.tpl'; |
||
| 19 | |||
| 20 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||
| 21 | require_once __DIR__ . '/footer.php'; |
||
| 22 | |||
| 23 | $categoryid = \Xmf\Request::getInt('categoryid', 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...
|
|||
| 24 | |||
| 25 | // Creating the category object for the selected category |
||
| 26 | $categoryObj = new Smartfaq\Category($categoryid); |
||
| 27 | |||
| 28 | // If the selected category was not found, exit |
||
| 29 | if ($categoryObj->notLoaded()) { |
||
| 30 | redirect_header('javascript:history.go(-1)', 1, _MD_SF_NOCATEGORYSELECTED); |
||
| 31 | } |
||
| 32 | |||
| 33 | // Check user permissions to access this category |
||
| 34 | if (!$categoryObj->checkPermission()) { |
||
| 35 | redirect_header('javascript:history.go(-1)', 1, _NOPERM); |
||
| 36 | } |
||
| 37 | |||
| 38 | // Creating the category handler object |
||
| 39 | /** @var \XoopsModules\Smartfaq\CategoryHandler $categoryHandler */ |
||
| 40 | $categoryHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Category'); |
||
| 41 | |||
| 42 | // At which record shall we start |
||
| 43 | $start = \Xmf\Request::getInt('start', 0, 'GET'); |
||
| 44 | |||
| 45 | // Creating the faq handler object |
||
| 46 | /** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */ |
||
| 47 | $faqHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Faq'); |
||
| 48 | |||
| 49 | // creating the FAQ objects that belong to the selected category |
||
| 50 | $faqsObj = $faqHandler->getFaqs($helper->getConfig('indexperpage'), $start, Constants::SF_STATUS_OPENED, $categoryid); |
||
| 51 | |||
| 52 | $totalQnasOnPage = 0; |
||
| 53 | if ($faqsObj) { |
||
| 54 | $totalQnasOnPage = count($faqsObj); |
||
| 55 | } |
||
| 56 | |||
| 57 | // If there is no Q&As to display, exit |
||
| 58 | /*if ($totalQnasOnPage == 0) { |
||
| 59 | redirect_header("javascript:history.go(-1)", 2, _AM_SF_NO_TOP_PERMISSIONS); |
||
| 60 | }*/ |
||
| 61 | |||
| 62 | // Arrays that will hold the informations passed on to smarty variables |
||
| 63 | $category = []; |
||
| 64 | $qnas = []; |
||
| 65 | $last_qnaObj = $faqHandler->getLastPublishedByCat([Constants::SF_STATUS_OPENED]); |
||
| 66 | if (isset($last_qnaObj[$categoryid])) { |
||
| 67 | $categoryObj->setVar('last_faqid', $last_qnaObj[$categoryid]->getVar('faqid')); |
||
| 68 | $categoryObj->setVar('last_question_link', "<a href='faq.php?faqid=" . $last_qnaObj[$categoryid]->getVar('faqid') . "'>" . $last_qnaObj[$categoryid]->question(50) . '</a>'); |
||
| 69 | } |
||
| 70 | // Populating the smarty variables with informations related to the selected category |
||
| 71 | $category = $categoryObj->toArray(null, true); |
||
| 72 | $totalQnas = $categoryHandler->faqsCount(0, [Constants::SF_STATUS_OPENED]); |
||
| 73 | $category['categoryPath'] = $categoryObj->getCategoryPath(false, true); |
||
| 74 | |||
| 75 | // Creating the sub-categories objects that belong to the selected category |
||
| 76 | $subcatsObj =& $categoryHandler->getCategories(0, 0, $categoryid); |
||
| 77 | $total_subcats = count($subcatsObj); |
||
| 78 | $catQnasWithSub = 0; |
||
| 79 | if (0 != $total_subcats) { |
||
| 80 | $faqHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Faq'); |
||
| 81 | // Arrays that will hold the informations passed on to smarty variables |
||
| 82 | foreach ($subcatsObj as $key => $subcat) { |
||
| 83 | $subcat_id = $subcat->getVar('categoryid'); |
||
| 84 | if (isset($totalQnas[$subcat_id]) && $totalQnas[$subcat_id] > 0) { |
||
| 85 | if (isset($last_qnaObj[$subcat_id])) { |
||
| 86 | $subcat->setVar('last_faqid', $last_qnaObj[$subcat_id]->getVar('faqid')); |
||
| 87 | $subcat->setVar('last_question_link', "<a href='faq.php?faqid=" . $last_qnaObj[$subcat_id]->getVar('faqid') . "'>" . $last_qnaObj[$subcat_id]->question(50) . '</a>'); |
||
| 88 | } |
||
| 89 | $subcat->setVar('faqcount', $totalQnas[$subcat_id]); |
||
| 90 | $subcats[$subcat_id] = $subcat->toArray(null, true); |
||
| 91 | $catQnasWithSub += $subcats[$subcat_id]['total']; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | $xoopsTpl->assign('subcats', $subcats); |
||
| 95 | } |
||
| 96 | $category['total'] = $catQnasWithSub + $totalQnas[$categoryid]; |
||
| 97 | if ($faqsObj) { |
||
| 98 | $userids = []; |
||
| 99 | foreach ($faqsObj as $key => $thisfaq) { |
||
| 100 | $faqids[] = $thisfaq->getVar('faqid'); |
||
| 101 | $userids[$thisfaq->uid()] = 1; |
||
| 102 | } |
||
| 103 | |||
| 104 | $memberHandler = xoops_getHandler('member'); |
||
| 105 | $users = $memberHandler->getUsers(new \Criteria('uid', '(' . implode(',', array_keys($userids)) . ')', 'IN'), true); |
||
| 106 | foreach ($faqsObj as $iValue) { |
||
| 107 | $faq = $iValue->toArray(null, $allcategories); |
||
| 108 | |||
| 109 | $faq['adminlink'] = Smartfaq\Utility::getAdminLinks($iValue->faqid(), true); |
||
| 110 | |||
| 111 | $faq['who_when'] = $iValue->getWhoAndWhen(null, $users); |
||
| 112 | |||
| 113 | $xoopsTpl->append('faqs', $faq); |
||
| 114 | } |
||
| 115 | } |
||
| 116 | // Language constants |
||
| 117 | $xoopsTpl->assign('whereInSection', $myts->htmlSpecialChars($xoopsModule->getVar('name')) . " > <a href='open_index.php'>" . _MD_SF_OPEN_SECTION . '</a>'); |
||
| 118 | $xoopsTpl->assign('modulename', $xoopsModule->dirname()); |
||
| 119 | |||
| 120 | $xoopsTpl->assign('displaylastfaqs', true); |
||
| 121 | $xoopsTpl->assign('display_categoryname', false); |
||
| 122 | |||
| 123 | $xoopsTpl->assign('lang_reads', _MD_SF_READS); |
||
| 124 | $xoopsTpl->assign('lang_home', _MD_SF_HOME); |
||
| 125 | $xoopsTpl->assign('lang_smartfaqs_info', _MD_SF_OPENED_INFO); |
||
| 126 | $xoopsTpl->assign('lang_smartfaqs', _MD_SF_QUESTIONS); |
||
| 127 | $xoopsTpl->assign('lang_cat_title', _MD_SF_OPENED_QUESTIONS); |
||
| 128 | $xoopsTpl->assign('lang_subcat_title', _MD_SF_CATEGORY_SUMMARY); |
||
| 129 | $xoopsTpl->assign('lang_category_summary', _MD_SF_CATEGORY_SUMMARY); |
||
| 130 | $xoopsTpl->assign('lang_category_summary_info', _MD_SF_CATEGORY_SUMMARY_INFO); |
||
| 131 | $xoopsTpl->assign('lang_category', _MD_SF_CATEGORY); |
||
| 132 | |||
| 133 | // The Navigation Bar |
||
| 134 | require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||
| 135 | $pagenav = new \XoopsPageNav($totalQnas[$categoryid], $helper->getConfig('indexperpage'), $start, 'start', 'categoryid=' . $categoryObj->getVar('categoryid')); |
||
| 136 | if (1 == $helper->getConfig('useimagenavpage')) { |
||
| 137 | $category['navbar'] = '<div style="text-align:right;">' . $pagenav->renderImageNav() . '</div>'; |
||
| 138 | } else { |
||
| 139 | $category['navbar'] = '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>'; |
||
| 140 | } |
||
| 141 | |||
| 142 | $xoopsTpl->assign('category', $category); |
||
| 143 | |||
| 144 | // Page Title Hack by marcan |
||
| 145 | $module_name = $myts->htmlSpecialChars($xoopsModule->getVar('name')); |
||
| 146 | $xoopsTpl->assign('xoops_pagetitle', $module_name . ' - ' . $category['name']); |
||
| 147 | // End Page Title Hack by marcan |
||
| 148 | |||
| 149 | require_once XOOPS_ROOT_PATH . '/footer.php'; |
||
| 150 |
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