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