Passed
Push — master ( 2744eb...81ba93 )
by Michael
02:46
created

category.php (1 issue)

Labels
Severity
1
<?php
2
3
/**
4
 * Module: SmartFAQ
5
 * Author: The SmartFactory <www.smartfactory.ca>
6
 * Licence: GNU
7
 */
8
9
use XoopsModules\Smartfaq;
10
/** @var Smartfaq\Helper $helper */
11
$helper = Smartfaq\Helper::getInstance();
12
13
require_once __DIR__ . '/header.php';
14
15
$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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
17
// Creating the category handler object
18
/** @var \XoopsModules\Smartfaq\CategoryHandler $categoryHandler */
19
$categoryHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Category');
20
21
// Creating the category object for the selected category
22
$categoryObj = new Smartfaq\Category($categoryid);
23
24
// If the selected category was not found, exit
25
if ($categoryObj->notLoaded()) {
26
    redirect_header('javascript:history.go(-1)', 1, _MD_SF_NOCATEGORYSELECTED);
27
}
28
29
// Check user permissions to access this category
30
if (!$categoryObj->checkPermission()) {
31
    redirect_header('javascript:history.go(-1)', 1, _NOPERM);
32
}
33
$totalQnas = $categoryHandler->publishedFaqsCount($categoryid);
34
// If there is no FAQ under this categories or the sub-categories, exit
35
if (!isset($totalQnas[$categoryid]) || 0 == $totalQnas[$categoryid]) {
36
    //redirect_header("index.php", 1, _MD_SF_MAINNOFAQS);
37
}
38
$GLOBALS['xoopsOption']['template_main'] = 'smartfaq_category.tpl';
39
40
require_once XOOPS_ROOT_PATH . '/header.php';
41
require_once __DIR__ . '/footer.php';
42
43
// At which record shall we start
44
$start = \Xmf\Request::getInt('start', 0, 'GET');
45
46
// Creating the faq handler object
47
/** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */
48
$faqHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Faq');
49
50
// creating the FAQ objects that belong to the selected category
51
if (1 == $helper->getConfig('orderbydate')) {
52
    $sort  = 'datesub';
53
    $order = 'DESC';
54
} else {
55
    $sort  = 'weight';
56
    $order = 'ASC';
57
}
58
$faqsObj = $faqHandler->getAllPublished($helper->getConfig('indexperpage'), $start, $categoryid, $sort, $order);
59
60
$totalQnasOnPage = 0;
61
if ($faqsObj) {
62
    $totalQnasOnPage = count($faqsObj);
63
}
64
65
// Arrays that will hold the informations passed on to smarty variables
66
$category = [];
67
$qnas     = [];
68
69
// Populating the smarty variables with informations related to the selected category
70
$category  = $categoryObj->toArray(null, true);
71
$totalQnas = $categoryHandler->publishedFaqsCount();
72
73
$category['categoryPath'] = $categoryObj->getCategoryPath();
74
75
if (1 == $helper->getConfig('displaylastfaq')) {
76
    // Get the last smartfaq
77
    $last_qnaObj = $faqHandler->getLastPublishedByCat();
78
}
79
$lastfaqsize = (int)$helper->getConfig('lastfaqsize');
80
// Creating the sub-categories objects that belong to the selected category
81
$subcatsObj    =& $categoryHandler->getCategories(0, 0, $categoryid);
82
$total_subcats = count($subcatsObj);
83
$total_faqs    = 0;
84
if (0 != $total_subcats) {
85
    $subcat_keys = array_keys($subcatsObj);
86
    foreach ($subcat_keys as $i) {
87
        $subcat_id = $subcatsObj[$i]->getVar('categoryid');
88
        if (isset($totalQnas[$subcat_id]) && $totalQnas[$subcat_id] > 0) {
89
            if (isset($last_qnaObj[$subcat_id])) {
90
                $subcatsObj[$i]->setVar('last_faqid', $last_qnaObj[$subcat_id]->getVar('faqid'));
91
                $subcatsObj[$i]->setVar('last_question_link', "<a href='faq.php?faqid=" . $last_qnaObj[$subcat_id]->getVar('faqid') . "'>" . $last_qnaObj[$subcat_id]->question($lastfaqsize) . '</a>');
92
            }
93
        }
94
        $subcatsObj[$i]->setVar('faqcount', $totalQnas[$subcat_id]);
95
        $subcats[$subcat_id] = $subcatsObj[$i]->toArray();
96
        $total_faqs          += $totalQnas[$subcat_id];
97
        //}replacé ligne 92
98
    }
99
    $xoopsTpl->assign('subcats', $subcats);
100
}
101
$thiscategory_faqcount = isset($totalQnas[$categoryid]) ? $totalQnas[$categoryid] : 0;
102
$category['total']     = $thiscategory_faqcount + $total_faqs;
103
104
if (count($faqsObj) > 0) {
105
    $userids = [];
106
    foreach ($faqsObj as $key => $thisfaq) {
107
        $faqids[]                 = $thisfaq->getVar('faqid');
108
        $userids[$thisfaq->uid()] = 1;
109
    }
110
    /** @var \XoopsModules\Smartfaq\AnswerHandler $answerHandler */
111
    $answerHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Answer');
112
    $allanswers    = $answerHandler->getLastPublishedByFaq($faqids);
113
114
    foreach ($allanswers as $key => $thisanswer) {
115
        $userids[$thisanswer->uid()] = 1;
116
    }
117
118
    $memberHandler = xoops_getHandler('member');
119
    $users         = $memberHandler->getUsers(new \Criteria('uid', '(' . implode(',', array_keys($userids)) . ')', 'IN'), true);
120
    // Adding the Q&As of the selected category
121
    foreach ($faqsObj as $iValue) {
122
        $faq = $iValue->toArray(null, $categoryObj);
123
124
        // Creating the answer object
125
        $answerObj = $allanswers[$iValue->faqid()];
126
127
        $answerObj->setVar('dohtml', $iValue->getVar('html'));
128
        $answerObj->setVar('doxcode', $iValue->getVar('xcodes'));
129
        $answerObj->setVar('dosmiley', $iValue->getVar('smiley'));
130
        $answerObj->setVar('doimage', $iValue->getVar('image'));
131
        $answerObj->setVar('dobr', $iValue->getVar('linebreak'));
132
133
        $faq['answer']    = $answerObj->answer();
134
        $faq['answerid']  = $answerObj->answerid();
135
        $faq['datesub']   = $iValue->datesub();
136
        $faq['adminlink'] = Smartfaq\Utility::getAdminLinks($iValue->faqid());
137
138
        $faq['who_when'] = $iValue->getWhoAndWhen($answerObj, $users);
139
140
        $xoopsTpl->append('faqs', $faq);
141
    }
142
143
    if (isset($last_qnaObj) && $last_qnaObj) {
144
        $category['last_faqid']         = $last_qnaObj[$categoryObj->getVar('categoryid')]->getVar('faqid');
145
        $category['last_question_link'] = "<a href='faq.php?faqid=" . $last_qnaObj[$categoryObj->getVar('categoryid')]->getVar('faqid') . "'>" . $last_qnaObj[$categoryObj->getVar('categoryid')]->question($lastfaqsize) . '</a>';
146
    }
147
}
148
149
$xoopsTpl->assign('whereInSection', $myts->displayTarea($xoopsModule->getVar('name')));
150
$xoopsTpl->assign('displaylastfaqs', true);
151
$xoopsTpl->assign('display_categoryname', true);
152
$xoopsTpl->assign('displayFull', 'full' === $helper->getConfig('displaytype'));
153
154
// Language constants
155
$xoopsTpl->assign('lang_index_faqs', _MD_SF_SMARTFAQS);
156
$xoopsTpl->assign('lang_index_faqs_info', _MD_SF_SMARTFAQS_INFO);
157
158
$xoopsTpl->assign('lang_category', $totalQnasOnPage);
159
$xoopsTpl->assign('lang_reads', _MD_SF_READS);
160
$xoopsTpl->assign('lang_home', _MD_SF_HOME);
161
$xoopsTpl->assign('lang_smartfaqs', _MD_SF_SMARTFAQS);
162
$xoopsTpl->assign('lang_last_smartfaq', _MD_SF_LAST_SMARTFAQ);
163
$xoopsTpl->assign('lang_category_summary', _MD_SF_CATEGORY_SUMMARY);
164
$xoopsTpl->assign('lang_category_summary_info', _MD_SF_CATEGORY_SUMMARY_INFO);
165
166
$xoopsTpl->assign('lang_category', _MD_SF_CATEGORY);
167
$xoopsTpl->assign('lang_comments', _MD_SF_COMMENTS);
168
169
// The Navigation Bar
170
require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
171
$pagenav = new \XoopsPageNav($thiscategory_faqcount, $helper->getConfig('indexperpage'), $start, 'start', 'categoryid=' . $categoryObj->getVar('categoryid'));
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
$xoopsTpl->assign('category', $category);
179
180
// Page Title Hack by marcan
181
$module_name = $myts->htmlSpecialChars($xoopsModule->getVar('name'));
182
$xoopsTpl->assign('xoops_pagetitle', $module_name . ' - ' . $category['name']);
183
// End Page Title Hack by marcan
184
185
//code to include smartie
186
if (file_exists(XOOPS_ROOT_PATH . '/modules/smarttie/smarttie_links.php')) {
187
    require_once XOOPS_ROOT_PATH . '/modules/smarttie/smarttie_links.php';
188
    $xoopsTpl->assign('smarttie', 1);
189
}
190
//end code for smarttie
191
192
require_once XOOPS_ROOT_PATH . '/footer.php';
193