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

index.php (2 issues)

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
// At which record shall we start for the Categories
17
$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. 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...
18
19
// At which record shall we start for the FAQ
20
$start = \Xmf\Request::getInt('start', 0, 'GET');
21
22
// Creating the category handler object
23
/** @var \XoopsModules\Smartfaq\CategoryHandler $categoryHandler */
24
$categoryHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Category');
25
26
// Creating the faq handler object
27
/** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */
28
$faqHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Faq');
29
30
$totalCategories = $categoryHandler->getCategoriesCount(0);
31
32
// Total number of published FAQ in the module
33
$totalFaqs = $faqHandler->getFaqsCount(-1, [Constants::SF_STATUS_PUBLISHED, Constants::SF_STATUS_NEW_ANSWER]);
34
35
if (0 == $totalFaqs) {
36
    if (($totalCategories > 0)
37
        && ($helper->getConfig('allowrequest') && $helper->getConfig('anonpost')
38
            || is_object($xoopsUser))) {
39
        redirect_header('request.php', 2, _AM_SF_NO_TOP_PERMISSIONS);
40
    } else {
41
        redirect_header('../../index.php', 2, _AM_SF_NO_TOP_PERMISSIONS);
42
    }
43
}
44
45
$GLOBALS['xoopsOption']['template_main'] = 'smartfaq_index.tpl';
46
47
require_once XOOPS_ROOT_PATH . '/header.php';
48
require_once __DIR__ . '/footer.php';
49
50
// Creating the categories objects
51
$categoriesObj =& $categoryHandler->getCategories($helper->getConfig('catperpage'), $catstart);
52
// If no categories are found, exit
53
$totalCategoriesOnPage = count($categoriesObj);
54
if (0 == $totalCategoriesOnPage) {
55
    redirect_header('javascript:history.go(-1)', 2, _AM_SF_NO_CAT_EXISTS);
56
}
57
// Arrays that will hold the informations passed on to smarty variables
58
59
$qnas = [];
60
61
//if ($helper->getConfig('displaysubcatonindex')) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
62
$subcats = $categoryHandler->getSubCats($categoriesObj);
63
//}
64
$totalQnas  = $categoryHandler->publishedFaqsCount();
65
$faqHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Faq');
66
67
if (1 == $helper->getConfig('displaylastfaq')) {
68
    // Get the last smartfaq in each category
69
    $last_qnaObj = $faqHandler->getLastPublishedByCat();
70
}
71
$lastfaqsize = (int)$helper->getConfig('lastfaqsize');
72
$categories  = [];
73
foreach ($categoriesObj as $cat_id => $category) {
74
    $total = 0;
75
    if (isset($subcats[$cat_id])) {
76
        foreach ($subcats[$cat_id] as $key => $subcat) {
77
            $subcat_id = $subcat->getVar('categoryid');
78
            if (isset($totalQnas[$subcat_id]) && $totalQnas[$subcat_id] > 0) {
79
                if (isset($last_qnaObj[$subcat_id])) {
80
                    $subcat->setVar('last_faqid', $last_qnaObj[$subcat_id]->getVar('faqid'));
81
                    $subcat->setVar('last_question_link', "<a href='faq.php?faqid=" . $last_qnaObj[$subcat_id]->getVar('faqid') . "'>" . $last_qnaObj[$subcat_id]->question($lastfaqsize) . '</a>');
82
                }
83
                $subcat->setVar('faqcount', $totalQnas[$subcat_id]);
84
                if ($helper->getConfig('displaysubcatonindex')) {
85
                    $categories[$cat_id]['subcats'][$subcat_id] = $subcat->toArray();
86
                }
87
            }
88
            $total += $totalQnas[$subcat_id];
89
            //}replac� ligne 80
90
        }
91
    }
92
93
    if (isset($totalQnas[$cat_id]) && $totalQnas[$cat_id] > 0) {
94
        $total += $totalQnas[$cat_id];
95
    }
96
    if ($total > 0) {
97
        if (isset($last_qnaObj[$cat_id])) {
98
            $category->setVar('last_faqid', $last_qnaObj[$cat_id]->getVar('faqid'));
99
            $category->setVar('last_question_link', "<a href='faq.php?faqid=" . $last_qnaObj[$cat_id]->getVar('faqid') . "'>" . $last_qnaObj[$cat_id]->question($lastfaqsize) . '</a>');
100
        }
101
        $category->setVar('faqcount', $total);
102
        if (!isset($categories[$cat_id])) {
103
            $categories[$cat_id] = [];
104
        }
105
    }
106
107
    $categories[$cat_id]                 = $category->toArray(@$categories[$cat_id]);
108
    $categories[$cat_id]['categoryPath'] = $category->getCategoryPath();
109
    //}replac� ligne 97
110
}
111
/*echo count($categories);
112
echo "<br>";
113
var_dump($categories);
114
exit;*/
115
$xoopsTpl->assign('categories', $categories);
116
117
$displaylastfaqs = $helper->getConfig('displaylastfaqs');
118
if ($displaylastfaqs) {
119
    // Creating the last FAQs
120
    $faqsObj         = $faqHandler->getAllPublished($helper->getConfig('indexperpage'), $start);
121
    $totalQnasOnPage = count($faqsObj);
122
    $allcategories   = $categoryHandler->getObjects(null, true);
123
    if ($faqsObj) {
124
        $userids = [];
125
        foreach ($faqsObj as $key => $thisfaq) {
126
            $faqids[]                 = $thisfaq->getVar('faqid');
127
            $userids[$thisfaq->uid()] = 1;
128
        }
129
        /** @var \XoopsModules\Smartfaq\AnswerHandler $answerHandler */
130
        $answerHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Answer');
131
        $allanswers    = $answerHandler->getLastPublishedByFaq($faqids);
132
133
        foreach ($allanswers as $key => $thisanswer) {
134
            $userids[$thisanswer->uid()] = 1;
135
        }
136
137
        $memberHandler = xoops_getHandler('member');
138
        $users         = $memberHandler->getUsers(new \Criteria('uid', '(' . implode(',', array_keys($userids)) . ')', 'IN'), true);
139
        for ($i = 0; $i < $totalQnasOnPage; ++$i) {
140
            $faq = $faqsObj[$i]->toArray(null, $allcategories);
141
142
            // Creating the answer object
143
            $answerObj = $allanswers[$faqsObj[$i]->faqid()];
144
145
            $answerObj->setVar('dohtml', $faqsObj[$i]->getVar('html'));
146
            $answerObj->setVar('doxcode', $faqsObj[$i]->getVar('xcodes'));
147
            $answerObj->setVar('dosmiley', $faqsObj[$i]->getVar('smiley'));
148
            $answerObj->setVar('doimage', $faqsObj[$i]->getVar('image'));
149
            $answerObj->setVar('dobr', $faqsObj[$i]->getVar('linebreak'));
150
151
            $faq['answer']    = $answerObj->answer();
152
            $faq['answerid']  = $answerObj->answerid();
153
            $faq['datesub']   = $faqsObj[$i]->datesub();
154
            $faq['adminlink'] = Smartfaq\Utility::getAdminLinks($faqsObj[$i]->faqid());
155
156
            $faq['who_when'] = $faqsObj[$i]->getWhoAndWhen($answerObj, $users);
157
158
            $xoopsTpl->append('faqs', $faq);
159
        }
160
    }
161
}
162
163
// Language constants
164
$moduleName =& $myts->displayTarea($xoopsModule->getVar('name'));
165
$xoopsTpl->assign('whereInSection', $moduleName);
166
$xoopsTpl->assign('displaysubcatonindex', $helper->getConfig('displaysubcatonindex'));
167
$xoopsTpl->assign('displaylastfaqs', $helper->getConfig('displaylastfaqs'));
168
$xoopsTpl->assign('display_categoryname', true);
169
$xoopsTpl->assign('displayFull', 'full' === $helper->getConfig('displaytype'));
170
171
$xoopsTpl->assign('lang_mainhead', _MD_SF_MAINHEAD . ' ' . $moduleName);
172
$xoopsTpl->assign('lang_mainintro', $myts->displayTarea($helper->getConfig('indexwelcomemsg'), 1));
173
$xoopsTpl->assign('lang_total', _MD_SF_TOTAL_SMARTFAQS);
174
$xoopsTpl->assign('lang_home', _MD_SF_HOME);
175
$xoopsTpl->assign('lang_description', _MD_SF_DESCRIPTION);
176
$xoopsTpl->assign('lang_category', _MD_SF_CATEGORY);
177
178
$xoopsTpl->assign('lang_reads', _MD_SF_READS);
179
$xoopsTpl->assign('lang_smartfaqs', _MD_SF_SMARTFAQS);
180
$xoopsTpl->assign('lang_last_smartfaq', _MD_SF_LAST_SMARTFAQ);
181
$xoopsTpl->assign('lang_categories_summary', _MD_SF_INDEX_CATEGORIES_SUMMARY);
182
$xoopsTpl->assign('lang_categories_summary_info', _MD_SF_INDEX_CATEGORIES_SUMMARY_INFO);
183
$xoopsTpl->assign('lang_index_faqs', _MD_SF_INDEX_FAQS);
184
$xoopsTpl->assign('lang_index_faqs_info', _MD_SF_INDEX_FAQS_INFO);
185
$xoopsTpl->assign('lang_category', _MD_SF_CATEGORY);
186
$xoopsTpl->assign('lang_editcategory', _MD_SF_CATEGORY_EDIT);
187
$xoopsTpl->assign('lang_comments', _MD_SF_COMMENTS);
188
189
// Category Navigation Bar
190
require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
191
$pagenav = new \XoopsPageNav($totalCategories, $helper->getConfig('catperpage'), $catstart, 'catstart', '');
192
if (1 == $helper->getConfig('useimagenavpage')) {
193
    $xoopsTpl->assign('catnavbar', '<div style="text-align:right;">' . $pagenav->renderImageNav() . '</div>');
194
} else {
195
    $xoopsTpl->assign('catnavbar', '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>');
196
}
197
198
// FAQ Navigation Bar
199
$pagenav = new \XoopsPageNav($totalFaqs, $helper->getConfig('indexperpage'), $start, 'start', '');
200
if (1 == $helper->getConfig('useimagenavpage')) {
201
    $xoopsTpl->assign('navbar', '<div style="text-align:right;">' . $pagenav->renderImageNav() . '</div>');
202
} else {
203
    $xoopsTpl->assign('navbar', '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>');
204
}
205
206
// Page Title Hack by marcan
207
$module_name = $myts->htmlSpecialChars($xoopsModule->getVar('name'));
208
$xoopsTpl->assign('xoops_pagetitle', $module_name);
209
// End Page Title Hack by marcan
210
211
require_once XOOPS_ROOT_PATH . '/footer.php';
212