-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathopen_index.php
183 lines (152 loc) · 7.34 KB
/
open_index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php declare(strict_types=1);
/**
* Module: SmartFAQ
* Author: The SmartFactory <www.smartfactory.ca>
* Licence: GNU
*/
use Xmf\Request;
use XoopsModules\Smartfaq;
use XoopsModules\Smartfaq\Constants;
use XoopsModules\Smartfaq\Helper;
$GLOBALS['xoopsOption']['template_main'] = 'smartfaq_index.tpl';
require_once __DIR__ . '/header.php';
global $xoopsConfig, $xoopsModule;
/** @var Smartfaq\Helper $helper */
$helper = Helper::getInstance();
// At which record shall we start for the Categories
$catstart = Request::getInt('catstart', 0, 'GET');
// At which record shall we start for the FAQs
$start = Request::getInt('start', 0, 'GET');
// Creating the category handler object
$categoryHandler = Helper::getInstance()->getHandler('Category');
// Get the total number of categories
$totalCategories = count($categoryHandler->getCategories());
// Creating the faq handler object
/** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */
$faqHandler = Helper::getInstance()->getHandler('Faq');
// Total number of published FAQ in the module
$totalFaqs = $faqHandler->getFaqsCount(-1, Constants::SF_STATUS_OPENED);
if (0 == $totalFaqs) {
redirect_header('request.php', 2, _MD_SF_NO_OPEN_QUESTION);
}
// Creating the categories objects
$categoriesObj = $categoryHandler->getCategories($helper->getConfig('catperpage'), $catstart);
// If no categories are found, exit
$totalCategoriesOnPage = count($categoriesObj);
if (0 == $totalCategoriesOnPage) {
redirect_header('<script>javascript:history.go(-1)</script>', 2, _AM_SF_NO_CAT_EXISTS);
}
require_once XOOPS_ROOT_PATH . '/header.php';
require_once __DIR__ . '/footer.php';
//get all categories for future reference
$allcategories = $categoryHandler->getObjects(null, true);
// Arrays that will hold the information passed on to smarty variables
$qnas = [];
$categories = [];
$subcats = $categoryHandler->getSubCats($categoriesObj);
$totalQnas = $categoryHandler->faqsCount(0, [Constants::SF_STATUS_OPENED]);
$faqHandler = Helper::getInstance()->getHandler('Faq');
$last_qnaObj = $faqHandler->getLastPublishedByCat([Constants::SF_STATUS_OPENED]);
foreach ($categoriesObj as $cat_id => $category) {
$total = 0;
if (isset($subcats[$cat_id]) && count($subcats[$cat_id]) > 0) {
foreach ($subcats[$cat_id] as $key => $subcat) {
$subcat_id = $subcat->getVar('categoryid');
if (isset($totalQnas[$subcat_id]) && $totalQnas[$subcat_id] > 0) {
if (isset($last_qnaObj[$subcat_id])) {
$subcat->setVar('last_faqid', $last_qnaObj[$subcat_id]->getVar('faqid'));
$subcat->setVar('last_question_link', "<a href='faq.php?faqid=" . $last_qnaObj[$subcat_id]->getVar('faqid') . "'>" . $last_qnaObj[$subcat_id]->question(50) . '</a>');
}
$subcat->setVar('faqcount', $totalQnas[$subcat_id]);
$categories[$cat_id]['subcats'][$subcat_id] = $subcat->toArray(null, true);
$total += $totalQnas[$subcat_id];
}
}
}
if (isset($totalQnas[$cat_id]) && $totalQnas[$cat_id] > 0) {
$total += $totalQnas[$cat_id];
}
if ($total > 0) {
$category->setVar('faqcount', $total);
if (!isset($categories[$cat_id])) {
$categories[$cat_id] = [];
}
$categories[$cat_id] = $category->toArray($categories[$cat_id], true);
$categories[$cat_id]['categoryPath'] = $category->getCategoryPath();
}
}
$xoopsTpl->assign('categories', $categories);
$displaylastfaqs = $helper->getConfig('displaylastfaqs');
if ($displaylastfaqs) {
// Creating the last FAQs
$faqsObj = $faqHandler->getFaqs($helper->getConfig('indexperpage'), $start, Constants::SF_STATUS_OPENED);
$totalQnasOnPage = count($faqsObj);
if ($faqsObj) {
$userids = [];
foreach ($faqsObj as $key => $thisfaq) {
$faqids[] = $thisfaq->getVar('faqid');
$userids[$thisfaq->uid()] = 1;
}
/** @var \XoopsMemberHandler $memberHandler */
$memberHandler = xoops_getHandler('member');
$users = $memberHandler->getUsers(new \Criteria('uid', '(' . implode(',', array_keys($userids)) . ')', 'IN'), true);
for ($i = 0; $i < $totalQnasOnPage; ++$i) {
$faq = $faqsObj[$i]->toArray(null, $allcategories);
$faq['adminlink'] = Smartfaq\Utility::getAdminLinks($faqsObj[$i]->faqid(), true);
$faq['who_when'] = $faqsObj[$i]->getWhoAndWhen(null, $users);
$xoopsTpl->append('faqs', $faq);
}
}
}
// Language constants
$moduleName = &$myts->displayTarea($xoopsModule->getVar('name'));
$xoopsTpl->assign(
[
'lang_on' => _MD_SF_ON,
'lang_postedby' => _MD_SF_POSTEDBY,
'lang_total' => $totalQnasOnPage,
'lang_faq' => _MD_SF_FAQ,
'lang_datesub' => _MD_SF_DATESUB,
'lang_hits' => _MD_SF_HITS,
]
);
$moduleName = &$myts->displayTarea($xoopsModule->getVar('name'));
$xoopsTpl->assign('lang_mainhead', sprintf(_MD_SF_OPEN_WELCOME, $xoopsConfig['sitename']));
$xoopsTpl->assign('lang_mainintro', $myts->displayTarea($helper->getConfig('openquestionintromsg'), 1));
$xoopsTpl->assign('lang_total', _MD_SF_TOTAL_QUESTIONS);
$xoopsTpl->assign('lang_home', _MD_SF_HOME);
$xoopsTpl->assign('lang_description', _MD_SF_DESCRIPTION);
$xoopsTpl->assign('lang_category', _MD_SF_CATEGORY);
$xoopsTpl->assign('sectionname', $moduleName);
$xoopsTpl->assign('whereInSection', "<a href='index.php'>" . $moduleName . '</a> > ' . _MD_SF_OPEN_SECTION);
$xoopsTpl->assign('displayFull', false);
$xoopsTpl->assign('displaylastfaqs', $helper->getConfig('displaylastfaqs'));
$xoopsTpl->assign('display_categoryname', true);
$xoopsTpl->assign('lang_reads', _MD_SF_READS);
$xoopsTpl->assign('lang_smartfaqs', _MD_SF_SMARTFAQS);
$xoopsTpl->assign('lang_last_smartfaq', _MD_SF_LAST_SMARTFAQ);
$xoopsTpl->assign('lang_categories_summary', _MD_SF_INDEX_CATEGORIES_SUMMARY);
$xoopsTpl->assign('lang_categories_summary_info', _MD_SF_INDEX_CATEGORIES_QUESTIONS_SUMMARY_INFO);
$xoopsTpl->assign('lang_index_faqs', _MD_SF_INDEX_QUESTIONS);
$xoopsTpl->assign('lang_index_faqs_info', _MD_SF_INDEX_QUESTIONS_INFO);
$xoopsTpl->assign('lang_category', _MD_SF_CATEGORY);
// Category Navigation Bar
require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
$pagenav = new \XoopsPageNav($totalCategories, $helper->getConfig('catperpage'), $catstart, 'catstart', '');
if (1 == $helper->getConfig('useimagenavpage')) {
$xoopsTpl->assign('catnavbar', '<div style="text-align:right;">' . $pagenav->renderImageNav() . '</div>');
} else {
$xoopsTpl->assign('catnavbar', '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>');
}
// FAQ Navigation Bar
$pagenav = new \XoopsPageNav($totalFaqs, $helper->getConfig('indexperpage'), $start, 'start', '');
if (1 == $helper->getConfig('useimagenavpage')) {
$xoopsTpl->assign('navbar', '<div style="text-align:right;">' . $pagenav->renderImageNav() . '</div>');
} else {
$xoopsTpl->assign('navbar', '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>');
}
// Page Title Hack by marcan
$module_name = htmlspecialchars($xoopsModule->getVar('name'), ENT_QUOTES | ENT_HTML5);
$xoopsTpl->assign('xoops_pagetitle', $module_name . ' - ' . $category->getVar('name'));
// End Page Title Hack by marcan
require_once XOOPS_ROOT_PATH . '/footer.php';