Completed
Push — master ( 454ebd...de22fe )
by Michael
03:58
created

Upgrade to new PHP Analysis Engine

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
require_once __DIR__ . '/header.php';
9
10
// At which record shall we start for the Categories
11
$catstart = isset($_GET['catstart']) ? (int)$_GET['catstart'] : 0;
12
13
// At which record shall we start for the FAQ
14
$start = isset($_GET['start']) ? (int)$_GET['start'] : 0;
15
16
// Creating the category handler object
17
$categoryHandler = sf_gethandler('category');
18
19
// Creating the faq handler object
20
$faqHandler = sf_gethandler('faq');
21
22
$totalCategories = $categoryHandler->getCategoriesCount(0);
23
24
// Total number of published FAQ in the module
25
$totalFaqs = $faqHandler->getFaqsCount(-1, [_SF_STATUS_PUBLISHED, _SF_STATUS_NEW_ANSWER]);
26
27
if (0 == $totalFaqs) {
28
    if (($totalCategories > 0)
29
        && ($xoopsModuleConfig['allowrequest'] && $xoopsModuleConfig['anonpost']
30
            || is_object($xoopsUser))) {
31
        redirect_header('request.php', 2, _AM_SF_NO_TOP_PERMISSIONS);
32
    } else {
33
        redirect_header('../../index.php', 2, _AM_SF_NO_TOP_PERMISSIONS);
34
    }
35
}
36
37
$GLOBALS['xoopsOption']['template_main'] = 'smartfaq_index.tpl';
38
39
require_once XOOPS_ROOT_PATH . '/header.php';
40
require_once __DIR__ . '/footer.php';
41
42
// Creating the categories objects
43
$categoriesObj = $categoryHandler->getCategories($xoopsModuleConfig['catperpage'], $catstart);
44
// If no categories are found, exit
45
$totalCategoriesOnPage = count($categoriesObj);
46
if (0 == $totalCategoriesOnPage) {
47
    redirect_header('javascript:history.go(-1)', 2, _AM_SF_NO_CAT_EXISTS);
48
}
49
// Arrays that will hold the informations passed on to smarty variables
50
51
$qnas = [];
52
53
//if ($xoopsModuleConfig['displaysubcatonindex']) {
54
$subcats = $categoryHandler->getSubCats($categoriesObj);
55
//}
56
$totalQnas  = $categoryHandler->publishedFaqsCount();
57
$faqHandler = sf_gethandler('faq');
58
59
if (1 == $xoopsModuleConfig['displaylastfaq']) {
60
    // Get the last smartfaq in each category
61
    $last_qnaObj = $faqHandler->getLastPublishedByCat();
62
}
63
$lastfaqsize = (int)$xoopsModuleConfig['lastfaqsize'];
64
$categories  = [];
65
foreach ($categoriesObj as $cat_id => $category) {
66
    $total = 0;
67
    if (isset($subcats[$cat_id])) {
68 View Code Duplication
        foreach ($subcats[$cat_id] as $key => $subcat) {
69
            $subcat_id = $subcat->getVar('categoryid');
70
            if (isset($totalQnas[$subcat_id]) && $totalQnas[$subcat_id] > 0) {
71
                if (isset($last_qnaObj[$subcat_id])) {
72
                    $subcat->setVar('last_faqid', $last_qnaObj[$subcat_id]->getVar('faqid'));
73
                    $subcat->setVar('last_question_link', "<a href='faq.php?faqid=" . $last_qnaObj[$subcat_id]->getVar('faqid') . "'>" . $last_qnaObj[$subcat_id]->question($lastfaqsize) . '</a>');
74
                }
75
                $subcat->setVar('faqcount', $totalQnas[$subcat_id]);
76
                if ($xoopsModuleConfig['displaysubcatonindex']) {
77
                    $categories[$cat_id]['subcats'][$subcat_id] = $subcat->toArray();
78
                }
79
            }
80
            $total += $totalQnas[$subcat_id];
81
            //}replac� ligne 80
82
        }
83
    }
84
85 View Code Duplication
    if (isset($totalQnas[$cat_id]) && $totalQnas[$cat_id] > 0) {
86
        $total += $totalQnas[$cat_id];
87
    }
88
    if ($total > 0) {
89
        if (isset($last_qnaObj[$cat_id])) {
90
            $category->setVar('last_faqid', $last_qnaObj[$cat_id]->getVar('faqid'));
91
            $category->setVar('last_question_link', "<a href='faq.php?faqid=" . $last_qnaObj[$cat_id]->getVar('faqid') . "'>" . $last_qnaObj[$cat_id]->question($lastfaqsize) . '</a>');
92
        }
93
        $category->setVar('faqcount', $total);
94
        if (!isset($categories[$cat_id])) {
95
            $categories[$cat_id] = [];
96
        }
97
    }
98
99
    $categories[$cat_id]                 = $category->toArray(@$categories[$cat_id]);
100
    $categories[$cat_id]['categoryPath'] = $category->getCategoryPath();
101
    //}replac� ligne 97
102
}
103
/*echo count($categories);
104
echo "<br>";
105
var_dump($categories);
106
exit;*/
107
$xoopsTpl->assign('categories', $categories);
108
109
$displaylastfaqs = $xoopsModuleConfig['displaylastfaqs'];
110
if ($displaylastfaqs) {
111
    // Creating the last FAQs
112
    $faqsObj         = $faqHandler->getAllPublished($xoopsModuleConfig['indexperpage'], $start);
113
    $totalQnasOnPage = count($faqsObj);
114
    $allcategories   = $categoryHandler->getObjects(null, true);
115
    if ($faqsObj) {
116
        $userids = [];
117
        foreach ($faqsObj as $key => $thisfaq) {
118
            $faqids[]                 = $thisfaq->getVar('faqid');
119
            $userids[$thisfaq->uid()] = 1;
120
        }
121
        $answerHandler = sf_gethandler('answer');
122
        $allanswers    = $answerHandler->getLastPublishedByFaq($faqids);
123
124
        foreach ($allanswers as $key => $thisanswer) {
125
            $userids[$thisanswer->uid()] = 1;
126
        }
127
128
        $memberHandler = xoops_getHandler('member');
129
        $users         = $memberHandler->getUsers(new Criteria('uid', '(' . implode(',', array_keys($userids)) . ')', 'IN'), true);
130 View Code Duplication
        for ($i = 0; $i < $totalQnasOnPage; ++$i) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

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