Passed
Push — master ( 82618a...1e389b )
by Michael
03:58
created

index.php (4 issues)

Labels
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
require_once __DIR__ . '/header.php';
13
14
/** @var Smartfaq\Helper $helper */
15
$helper = Smartfaq\Helper::getInstance();
16
17
// At which record shall we start for the Categories
18
$catstart = \Xmf\Request::getInt('catstart', 0, 'GET');
19
20
// At which record shall we start for the FAQ
21
$start = \Xmf\Request::getInt('start', 0, 'GET');
22
23
// Creating the category handler object
24
/** @var \XoopsModules\Smartfaq\CategoryHandler $categoryHandler */
25
$categoryHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Category');
26
27
// Creating the faq handler object
28
/** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */
29
$faqHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Faq');
30
31
$totalCategories = $categoryHandler->getCategoriesCount(0);
32
33
// Total number of published FAQ in the module
34
$totalFaqs = $faqHandler->getFaqsCount(-1, [Constants::SF_STATUS_PUBLISHED, Constants::SF_STATUS_NEW_ANSWER]);
0 ignored issues
show
array(XoopsModules\Smart...::SF_STATUS_NEW_ANSWER) of type array<integer,integer> is incompatible with the type string expected by parameter $status of XoopsModules\Smartfaq\FaqHandler::getFaqsCount(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
$totalFaqs = $faqHandler->getFaqsCount(-1, /** @scrutinizer ignore-type */ [Constants::SF_STATUS_PUBLISHED, Constants::SF_STATUS_NEW_ANSWER]);
Loading history...
35
36
if (0 == $totalFaqs) {
37
    if (($totalCategories > 0)
38
        && ($helper->getConfig('allowrequest') && $helper->getConfig('anonpost')
39
            || is_object($xoopsUser))) {
40
        redirect_header('request.php', 2, _AM_SF_NO_TOP_PERMISSIONS);
41
    } else {
42
        redirect_header('../../index.php', 2, _AM_SF_NO_TOP_PERMISSIONS);
43
    }
44
}
45
46
$GLOBALS['xoopsOption']['template_main'] = 'smartfaq_index.tpl';
47
48
require_once XOOPS_ROOT_PATH . '/header.php';
49
require_once __DIR__ . '/footer.php';
50
51
// Creating the categories objects
52
$categoriesObj = &$categoryHandler->getCategories($helper->getConfig('catperpage'), $catstart);
53
// If no categories are found, exit
54
$totalCategoriesOnPage = count($categoriesObj);
55
if (0 == $totalCategoriesOnPage) {
56
    redirect_header('<script>javascript:history.go(-1)</script>', 2, _AM_SF_NO_CAT_EXISTS);
57
}
58
// Arrays that will hold the informations passed on to smarty variables
59
60
$qnas = [];
61
62
//if ($helper->getConfig('displaysubcatonindex')) {
63
$subcats = $categoryHandler->getSubCats($categoriesObj);
64
//}
65
$totalQnas  = $categoryHandler->publishedFaqsCount();
66
$faqHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Faq');
67
68
if (1 == $helper->getConfig('displaylastfaq')) {
69
    // Get the last smartfaq in each category
70
    $last_qnaObj = $faqHandler->getLastPublishedByCat();
0 ignored issues
show
The method getLastPublishedByCat() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsModules\Smartfaq\FaqHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

70
    /** @scrutinizer ignore-call */ 
71
    $last_qnaObj = $faqHandler->getLastPublishedByCat();
Loading history...
71
}
72
$lastfaqsize = (int)$helper->getConfig('lastfaqsize');
73
$categories  = [];
74
foreach ($categoriesObj as $cat_id => $category) {
75
    $total = 0;
76
    if (isset($subcats[$cat_id])) {
77
        foreach ($subcats[$cat_id] as $key => $subcat) {
78
            $subcat_id = $subcat->getVar('categoryid');
79
            if (isset($totalQnas[$subcat_id]) && $totalQnas[$subcat_id] > 0) {
80
                if (isset($last_qnaObj[$subcat_id])) {
81
                    $subcat->setVar('last_faqid', $last_qnaObj[$subcat_id]->getVar('faqid'));
82
                    $subcat->setVar('last_question_link', "<a href='faq.php?faqid=" . $last_qnaObj[$subcat_id]->getVar('faqid') . "'>" . $last_qnaObj[$subcat_id]->question($lastfaqsize) . '</a>');
83
                }
84
                $subcat->setVar('faqcount', $totalQnas[$subcat_id]);
85
                if ($helper->getConfig('displaysubcatonindex')) {
86
                    $categories[$cat_id]['subcats'][$subcat_id] = $subcat->toArray();
87
                }
88
            }
89
            $total += $totalQnas[$subcat_id];
90
            //}replac� ligne 80
91
        }
92
    }
93
94
    if (isset($totalQnas[$cat_id]) && $totalQnas[$cat_id] > 0) {
95
        $total += $totalQnas[$cat_id];
96
    }
97
    if ($total > 0) {
98
        if (isset($last_qnaObj[$cat_id])) {
99
            $category->setVar('last_faqid', $last_qnaObj[$cat_id]->getVar('faqid'));
100
            $category->setVar('last_question_link', "<a href='faq.php?faqid=" . $last_qnaObj[$cat_id]->getVar('faqid') . "'>" . $last_qnaObj[$cat_id]->question($lastfaqsize) . '</a>');
101
        }
102
        $category->setVar('faqcount', $total);
103
        if (!isset($categories[$cat_id])) {
104
            $categories[$cat_id] = [];
105
        }
106
    }
107
108
    $categories[$cat_id]                 = $category->toArray(@$categories[$cat_id]);
109
    $categories[$cat_id]['categoryPath'] = $category->getCategoryPath();
110
    //}replac� ligne 97
111
}
112
/*echo count($categories);
113
echo "<br>";
114
var_dump($categories);
115
exit;*/
116
$xoopsTpl->assign('categories', $categories);
117
118
$displaylastfaqs = $helper->getConfig('displaylastfaqs');
119
if ($displaylastfaqs) {
120
    // Creating the last FAQs
121
    $faqsObj         = $faqHandler->getAllPublished($helper->getConfig('indexperpage'), $start);
0 ignored issues
show
The method getAllPublished() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsModules\Smartfaq\FaqHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

121
    /** @scrutinizer ignore-call */ 
122
    $faqsObj         = $faqHandler->getAllPublished($helper->getConfig('indexperpage'), $start);
Loading history...
122
    $totalQnasOnPage = count($faqsObj);
123
    $allcategories   = $categoryHandler->getObjects(null, true);
124
    if ($faqsObj) {
125
        $userids = [];
126
        foreach ($faqsObj as $key => $thisfaq) {
127
            $faqids[]                 = $thisfaq->getVar('faqid');
128
            $userids[$thisfaq->uid()] = 1;
129
        }
130
        /** @var \XoopsModules\Smartfaq\AnswerHandler $answerHandler */
131
        $answerHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Answer');
132
        $allanswers    = $answerHandler->getLastPublishedByFaq($faqids);
133
134
        foreach ($allanswers as $key => $thisanswer) {
135
            $userids[$thisanswer->uid()] = 1;
136
        }
137
138
        $memberHandler = xoops_getHandler('member');
139
        $users         = $memberHandler->getUsers(new \Criteria('uid', '(' . implode(',', array_keys($userids)) . ')', 'IN'), true);
0 ignored issues
show
The method getUsers() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

139
        /** @scrutinizer ignore-call */ 
140
        $users         = $memberHandler->getUsers(new \Criteria('uid', '(' . implode(',', array_keys($userids)) . ')', 'IN'), true);
Loading history...
140
        for ($i = 0; $i < $totalQnasOnPage; ++$i) {
141
            $faq = $faqsObj[$i]->toArray(null, $allcategories);
142
143
            // Creating the answer object
144
            $answerObj = $allanswers[$faqsObj[$i]->faqid()];
145
146
            $answerObj->setVar('dohtml', $faqsObj[$i]->getVar('html'));
147
            $answerObj->setVar('doxcode', $faqsObj[$i]->getVar('xcodes'));
148
            $answerObj->setVar('dosmiley', $faqsObj[$i]->getVar('smiley'));
149
            $answerObj->setVar('doimage', $faqsObj[$i]->getVar('image'));
150
            $answerObj->setVar('dobr', $faqsObj[$i]->getVar('linebreak'));
151
152
            $faq['answer']    = $answerObj->answer();
153
            $faq['answerid']  = $answerObj->answerid();
154
            $faq['datesub']   = $faqsObj[$i]->datesub();
155
            $faq['adminlink'] = Smartfaq\Utility::getAdminLinks($faqsObj[$i]->faqid());
156
157
            $faq['who_when'] = $faqsObj[$i]->getWhoAndWhen($answerObj, $users);
158
159
            $xoopsTpl->append('faqs', $faq);
160
        }
161
    }
162
}
163
164
// Language constants
165
$moduleName = &$myts->displayTarea($xoopsModule->getVar('name'));
166
$xoopsTpl->assign('whereInSection', $moduleName);
167
$xoopsTpl->assign('displaysubcatonindex', $helper->getConfig('displaysubcatonindex'));
168
$xoopsTpl->assign('displaylastfaqs', $helper->getConfig('displaylastfaqs'));
169
$xoopsTpl->assign('display_categoryname', true);
170
$xoopsTpl->assign('displayFull', 'full' === $helper->getConfig('displaytype'));
171
172
$xoopsTpl->assign('lang_mainhead', _MD_SF_MAINHEAD . ' ' . $moduleName);
173
$xoopsTpl->assign('lang_mainintro', $myts->displayTarea($helper->getConfig('indexwelcomemsg'), 1));
174
$xoopsTpl->assign('lang_total', _MD_SF_TOTAL_SMARTFAQS);
175
$xoopsTpl->assign('lang_home', _MD_SF_HOME);
176
$xoopsTpl->assign('lang_description', _MD_SF_DESCRIPTION);
177
$xoopsTpl->assign('lang_category', _MD_SF_CATEGORY);
178
179
$xoopsTpl->assign('lang_reads', _MD_SF_READS);
180
$xoopsTpl->assign('lang_smartfaqs', _MD_SF_SMARTFAQS);
181
$xoopsTpl->assign('lang_last_smartfaq', _MD_SF_LAST_SMARTFAQ);
182
$xoopsTpl->assign('lang_categories_summary', _MD_SF_INDEX_CATEGORIES_SUMMARY);
183
$xoopsTpl->assign('lang_categories_summary_info', _MD_SF_INDEX_CATEGORIES_SUMMARY_INFO);
184
$xoopsTpl->assign('lang_index_faqs', _MD_SF_INDEX_FAQS);
185
$xoopsTpl->assign('lang_index_faqs_info', _MD_SF_INDEX_FAQS_INFO);
186
$xoopsTpl->assign('lang_category', _MD_SF_CATEGORY);
187
$xoopsTpl->assign('lang_editcategory', _MD_SF_CATEGORY_EDIT);
188
$xoopsTpl->assign('lang_comments', _MD_SF_COMMENTS);
189
190
// Category Navigation Bar
191
require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
192
$pagenav = new \XoopsPageNav($totalCategories, $helper->getConfig('catperpage'), $catstart, 'catstart', '');
193
if (1 == $helper->getConfig('useimagenavpage')) {
194
    $xoopsTpl->assign('catnavbar', '<div style="text-align:right;">' . $pagenav->renderImageNav() . '</div>');
195
} else {
196
    $xoopsTpl->assign('catnavbar', '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>');
197
}
198
199
// FAQ Navigation Bar
200
$pagenav = new \XoopsPageNav($totalFaqs, $helper->getConfig('indexperpage'), $start, 'start', '');
201
if (1 == $helper->getConfig('useimagenavpage')) {
202
    $xoopsTpl->assign('navbar', '<div style="text-align:right;">' . $pagenav->renderImageNav() . '</div>');
203
} else {
204
    $xoopsTpl->assign('navbar', '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>');
205
}
206
207
// Page Title Hack by marcan
208
$module_name = $myts->htmlSpecialChars($xoopsModule->getVar('name'));
209
$xoopsTpl->assign('xoops_pagetitle', $module_name);
210
// End Page Title Hack by marcan
211
212
require_once XOOPS_ROOT_PATH . '/footer.php';
213