Completed
Branch master (c92e39)
by Michael
02:32
created

index.php (2 issues)

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
include_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, array(_SF_STATUS_PUBLISHED, _SF_STATUS_NEW_ANSWER));
26
27
if ($totalFaqs == 0) {
28
    if (($totalCategories > 0)
29
        && ($xoopsModuleConfig['allowrequest'] && $xoopsModuleConfig['anonpost']
30
            || is_object($xoopsUser))
31
    ) {
32
        redirect_header('request.php', 2, _AM_SF_NO_TOP_PERMISSIONS);
33
    } else {
34
        redirect_header('../../index.php', 2, _AM_SF_NO_TOP_PERMISSIONS);
35
    }
36
}
37
38
$GLOBALS['xoopsOption']['template_main'] = 'smartfaq_index.tpl';
39
40
include_once XOOPS_ROOT_PATH . '/header.php';
41
include_once __DIR__ . '/footer.php';
42
43
// Creating the categories objects
44
$categoriesObj = $categoryHandler->getCategories($xoopsModuleConfig['catperpage'], $catstart);
45
// If no categories are found, exit
46
$totalCategoriesOnPage = count($categoriesObj);
47
if ($totalCategoriesOnPage == 0) {
48
    redirect_header('javascript:history.go(-1)', 2, _AM_SF_NO_CAT_EXISTS);
49
}
50
// Arrays that will hold the informations passed on to smarty variables
51
52
$qnas = array();
53
54
//if ($xoopsModuleConfig['displaysubcatonindex']) {
55
$subcats = $categoryHandler->getSubCats($categoriesObj);
56
//}
57
$totalQnas  = $categoryHandler->publishedFaqsCount();
58
$faqHandler = sf_gethandler('faq');
59
60
if ($xoopsModuleConfig['displaylastfaq'] == 1) {
61
    // Get the last smartfaq in each category
62
    $last_qnaObj = $faqHandler->getLastPublishedByCat();
63
}
64
$lastfaqsize = (int)$xoopsModuleConfig['lastfaqsize'];
65
$categories  = array();
66
foreach ($categoriesObj as $cat_id => $category) {
67
    $total = 0;
68
    if (isset($subcats[$cat_id])) {
69 View Code Duplication
        foreach ($subcats[$cat_id] as $key => $subcat) {
70
            $subcat_id = $subcat->getVar('categoryid');
71
            if (isset($totalQnas[$subcat_id]) && $totalQnas[$subcat_id] > 0) {
72
                if (isset($last_qnaObj[$subcat_id])) {
73
                    $subcat->setVar('last_faqid', $last_qnaObj[$subcat_id]->getVar('faqid'));
74
                    $subcat->setVar('last_question_link', "<a href='faq.php?faqid=" . $last_qnaObj[$subcat_id]->getVar('faqid') . "'>" . $last_qnaObj[$subcat_id]->question($lastfaqsize) . '</a>');
75
                }
76
                $subcat->setVar('faqcount', $totalQnas[$subcat_id]);
77
                if ($xoopsModuleConfig['displaysubcatonindex']) {
78
                    $categories[$cat_id]['subcats'][$subcat_id] = $subcat->toArray();
79
                }
80
            }
81
            $total += $totalQnas[$subcat_id];
82
            //}replac� ligne 80
83
        }
84
    }
85
86 View Code Duplication
    if (isset($totalQnas[$cat_id]) && $totalQnas[$cat_id] > 0) {
87
        $total += $totalQnas[$cat_id];
88
    }
89
    if ($total > 0) {
90
        if (isset($last_qnaObj[$cat_id])) {
91
            $category->setVar('last_faqid', $last_qnaObj[$cat_id]->getVar('faqid'));
92
            $category->setVar('last_question_link', "<a href='faq.php?faqid=" . $last_qnaObj[$cat_id]->getVar('faqid') . "'>" . $last_qnaObj[$cat_id]->question($lastfaqsize) . '</a>');
93
        }
94
        $category->setVar('faqcount', $total);
95
        if (!isset($categories[$cat_id])) {
96
            $categories[$cat_id] = array();
97
        }
98
    }
99
100
    $categories[$cat_id]                 = $category->toArray(@$categories[$cat_id]);
101
    $categories[$cat_id]['categoryPath'] = $category->getCategoryPath();
102
    //}replac� ligne 97
103
}
104
/*echo count($categories);
105
echo "<br>";
106
var_dump($categories);
107
exit;*/
108
$xoopsTpl->assign('categories', $categories);
109
110
$displaylastfaqs = $xoopsModuleConfig['displaylastfaqs'];
111
if ($displaylastfaqs) {
112
    // Creating the last FAQs
113
    $faqsObj         = $faqHandler->getAllPublished($xoopsModuleConfig['indexperpage'], $start);
114
    $totalQnasOnPage = count($faqsObj);
115
    $allcategories   = $categoryHandler->getObjects(null, true);
116
    if ($faqsObj) {
117
        $userids = array();
118
        foreach ($faqsObj as $key => $thisfaq) {
119
            $faqids[]                 = $thisfaq->getVar('faqid');
120
            $userids[$thisfaq->uid()] = 1;
121
        }
122
        $answerHandler = sf_gethandler('answer');
123
        $allanswers    = $answerHandler->getLastPublishedByFaq($faqids);
124
125
        foreach ($allanswers as $key => $thisanswer) {
126
            $userids[$thisanswer->uid()] = 1;
127
        }
128
129
        $memberHandler = xoops_getHandler('member');
130
        $users         = $memberHandler->getUsers(new Criteria('uid', '(' . implode(',', array_keys($userids)) . ')', 'IN'), true);
131 View Code Duplication
        for ($i = 0; $i < $totalQnasOnPage; ++$i) {
132
            $faq = $faqsObj[$i]->toArray(null, $allcategories);
133
134
            // Creating the answer object
135
            $answerObj = $allanswers[$faqsObj[$i]->faqid()];
136
137
            $answerObj->setVar('dohtml', $faqsObj[$i]->getVar('html'));
138
            $answerObj->setVar('doxcode', $faqsObj[$i]->getVar('xcodes'));
139
            $answerObj->setVar('dosmiley', $faqsObj[$i]->getVar('smiley'));
140
            $answerObj->setVar('doimage', $faqsObj[$i]->getVar('image'));
141
            $answerObj->setVar('dobr', $faqsObj[$i]->getVar('linebreak'));
142
143
            $faq['answer']    = $answerObj->answer();
144
            $faq['answerid']  = $answerObj->answerid();
145
            $faq['datesub']   = $faqsObj[$i]->datesub();
146
            $faq['adminlink'] = sf_getAdminLinks($faqsObj[$i]->faqid());
147
148
            $faq['who_when'] = $faqsObj[$i]->getWhoAndWhen($answerObj, $users);
149
150
            $xoopsTpl->append('faqs', $faq);
151
        }
152
    }
153
}
154
155
// Language constants
156
$moduleName =& $myts->displayTarea($xoopsModule->getVar('name'));
157
$xoopsTpl->assign('whereInSection', $moduleName);
158
$xoopsTpl->assign('displaysubcatonindex', $xoopsModuleConfig['displaysubcatonindex']);
159
$xoopsTpl->assign('displaylastfaqs', $xoopsModuleConfig['displaylastfaqs']);
160
$xoopsTpl->assign('display_categoryname', true);
161
$xoopsTpl->assign('displayFull', $xoopsModuleConfig['displaytype'] === 'full');
162
163
$xoopsTpl->assign('lang_mainhead', _MD_SF_MAINHEAD . ' ' . $moduleName);
164
$xoopsTpl->assign('lang_mainintro', $myts->displayTarea($xoopsModuleConfig['indexwelcomemsg'], 1));
165
$xoopsTpl->assign('lang_total', _MD_SF_TOTAL_SMARTFAQS);
166
$xoopsTpl->assign('lang_home', _MD_SF_HOME);
167
$xoopsTpl->assign('lang_description', _MD_SF_DESCRIPTION);
168
$xoopsTpl->assign('lang_category', _MD_SF_CATEGORY);
169
170
$xoopsTpl->assign('lang_reads', _MD_SF_READS);
171
$xoopsTpl->assign('lang_smartfaqs', _MD_SF_SMARTFAQS);
172
$xoopsTpl->assign('lang_last_smartfaq', _MD_SF_LAST_SMARTFAQ);
173
$xoopsTpl->assign('lang_categories_summary', _MD_SF_INDEX_CATEGORIES_SUMMARY);
174
$xoopsTpl->assign('lang_categories_summary_info', _MD_SF_INDEX_CATEGORIES_SUMMARY_INFO);
175
$xoopsTpl->assign('lang_index_faqs', _MD_SF_INDEX_FAQS);
176
$xoopsTpl->assign('lang_index_faqs_info', _MD_SF_INDEX_FAQS_INFO);
177
$xoopsTpl->assign('lang_category', _MD_SF_CATEGORY);
178
$xoopsTpl->assign('lang_editcategory', _MD_SF_CATEGORY_EDIT);
179
$xoopsTpl->assign('lang_comments', _MD_SF_COMMENTS);
180
181
// Category Navigation Bar
182
include_once XOOPS_ROOT_PATH . '/class/pagenav.php';
183
$pagenav = new XoopsPageNav($totalCategories, $xoopsModuleConfig['catperpage'], $catstart, 'catstart', '');
184 View Code Duplication
if ($xoopsModuleConfig['useimagenavpage'] == 1) {
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...
185
    $xoopsTpl->assign('catnavbar', '<div style="text-align:right;">' . $pagenav->renderImageNav() . '</div>');
186
} else {
187
    $xoopsTpl->assign('catnavbar', '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>');
188
}
189
190
// FAQ Navigation Bar
191
$pagenav = new XoopsPageNav($totalFaqs, $xoopsModuleConfig['indexperpage'], $start, 'start', '');
192 View Code Duplication
if ($xoopsModuleConfig['useimagenavpage'] == 1) {
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...
193
    $xoopsTpl->assign('navbar', '<div style="text-align:right;">' . $pagenav->renderImageNav() . '</div>');
194
} else {
195
    $xoopsTpl->assign('navbar', '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>');
196
}
197
198
// Page Title Hack by marcan
199
$module_name = $myts->htmlSpecialChars($xoopsModule->getVar('name'));
200
$xoopsTpl->assign('xoops_pagetitle', $module_name);
201
// End Page Title Hack by marcan
202
203
include_once XOOPS_ROOT_PATH . '/footer.php';
204