Completed
Branch master (1b2f30)
by Michael
06:29 queued 03:22
created

category.php (1 issue)

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