1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Module: SmartFAQ |
5
|
|
|
* Author: The SmartFactory <www.smartfactory.ca> |
6
|
|
|
* Licence: GNU |
7
|
|
|
* @param $options |
8
|
|
|
* @return array |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
use XoopsModules\Smartfaq; |
12
|
|
|
use XoopsModules\Smartfaq\Helper; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @param $options |
16
|
|
|
* @return array |
17
|
|
|
*/ |
18
|
|
|
function b_faqs_recent_show($options) |
19
|
|
|
{ |
20
|
|
|
// require_once XOOPS_ROOT_PATH . '/modules/smartfaq/include/functions.php'; |
21
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
|
|
|
|
22
|
|
|
|
23
|
|
|
/** @var \XoopsModules\Smartfaq\Helper $helper */ |
24
|
|
|
$helper = Helper::getInstance(); |
25
|
|
|
$smartModule = $helper->getModule(); |
26
|
|
|
$smartModuleConfig = $helper->getConfig(); |
27
|
|
|
|
28
|
|
|
$block = []; |
29
|
|
|
|
30
|
|
|
if (0 == $options[0]) { |
31
|
|
|
$categoryid = -1; |
32
|
|
|
} else { |
33
|
|
|
$categoryid = $options[0]; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$sort = $options[1]; |
37
|
|
|
$limit = $options[2]; |
38
|
|
|
$maxQuestionLength = $options[3]; |
39
|
|
|
|
40
|
|
|
// Creating the faq handler object |
41
|
|
|
/** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */ |
42
|
|
|
$faqHandler = $helper->getHandler('Faq'); |
43
|
|
|
|
44
|
|
|
// Creating the category handler object |
45
|
|
|
/** @var \XoopsModules\Smartfaq\CategoryHandler $categoryHandler */ |
46
|
|
|
$categoryHandler = $helper->getHandler('Category'); |
47
|
|
|
|
48
|
|
|
// Creating the last FAQs |
49
|
|
|
$faqsObj = $faqHandler->getAllPublished($limit, 0, $categoryid, $sort); |
50
|
|
|
$allcategories = $categoryHandler->getObjects(null, true); |
51
|
|
|
if ($faqsObj) { |
52
|
|
|
$userids = []; |
53
|
|
|
foreach ($faqsObj as $key => $thisfaq) { |
54
|
|
|
$faqids[] = $thisfaq->getVar('faqid'); |
55
|
|
|
$userids[$thisfaq->uid()] = 1; |
56
|
|
|
} |
57
|
|
|
/** @var \XoopsModules\Smartfaq\AnswerHandler $answerHandler */ |
58
|
|
|
$answerHandler = $helper->getHandler('Answer'); |
59
|
|
|
$allanswers = $answerHandler->getLastPublishedByFaq($faqids); |
|
|
|
|
60
|
|
|
|
61
|
|
|
foreach ($allanswers as $key => $thisanswer) { |
62
|
|
|
$userids[$thisanswer->uid()] = 1; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** @var \XoopsMemberHandler $memberHandler */ |
66
|
|
|
$memberHandler = xoops_getHandler('member'); |
67
|
|
|
$users = $memberHandler->getUsers(new \Criteria('uid', '(' . implode(',', array_keys($userids)) . ')', 'IN'), true); |
68
|
|
|
foreach ($faqsObj as $iValue) { |
69
|
|
|
$faqs['categoryid'] = $iValue->categoryid(); |
70
|
|
|
$faqs['question'] = $iValue->question($maxQuestionLength); |
71
|
|
|
$faqs['faqid'] = $iValue->faqid(); |
72
|
|
|
$faqs['categoryname'] = $allcategories[$iValue->categoryid()]->getVar('name'); |
73
|
|
|
|
74
|
|
|
// Creating the answer object |
75
|
|
|
$faqid = $iValue->faqid(); |
76
|
|
|
$answerObj = $allanswers[$faqid]; |
77
|
|
|
|
78
|
|
|
$faqs['date'] = $iValue->datesub(); |
79
|
|
|
$faqs['poster'] = ''; |
80
|
|
|
if (null !== $answerObj) { |
81
|
|
|
$faqs['poster'] = Smartfaq\Utility::getLinkedUnameFromId($answerObj->uid(), $smartModuleConfig['userealname'], $users); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$block['faqs'][] = $faqs; |
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$block['lang_question'] = _MB_SF_FAQS; |
88
|
|
|
$block['lang_category'] = _MB_SF_CATEGORY; |
89
|
|
|
$block['lang_poster'] = _MB_SF_ANSWEREDBY; |
90
|
|
|
$block['lang_date'] = _MB_SF_DATE; |
91
|
|
|
$modulename = htmlspecialchars($smartModule->getVar('name'), ENT_QUOTES | ENT_HTML5); |
92
|
|
|
$block['lang_visitfaq'] = _MB_SF_VISITFAQ . ' ' . $modulename; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return $block; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param $options |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
function b_faqs_recent_edit($options) |
103
|
|
|
{ |
104
|
|
|
// require_once XOOPS_ROOT_PATH . '/modules/smartfaq/include/functions.php'; |
105
|
|
|
|
106
|
|
|
$form = Smartfaq\Utility::createCategorySelect($options[0]); |
107
|
|
|
|
108
|
|
|
$form .= ' <br>' . _MB_SF_ORDER . " <select name='options[]'>"; |
109
|
|
|
|
110
|
|
|
$form .= "<option value='datesub'"; |
111
|
|
|
if ('datesub' === $options[1]) { |
112
|
|
|
$form .= ' selected'; |
113
|
|
|
} |
114
|
|
|
$form .= '>' . _MB_SF_DATE . "</option>\n"; |
115
|
|
|
|
116
|
|
|
$form .= "<option value='counter'"; |
117
|
|
|
if ('counter' === $options[1]) { |
118
|
|
|
$form .= ' selected'; |
119
|
|
|
} |
120
|
|
|
$form .= '>' . _MB_SF_HITS . "</option>\n"; |
121
|
|
|
|
122
|
|
|
$form .= "<option value='weight'"; |
123
|
|
|
if ('weight' === $options[1]) { |
124
|
|
|
$form .= ' selected'; |
125
|
|
|
} |
126
|
|
|
$form .= '>' . _MB_SF_WEIGHT . "</option>\n"; |
127
|
|
|
|
128
|
|
|
$form .= "</select>\n"; |
129
|
|
|
|
130
|
|
|
$form .= ' ' . _MB_SF_DISP . " <input type='text' name='options[]' value='" . $options[2] . "'> " . _MB_SF_FAQS; |
131
|
|
|
$form .= ' <br>' . _MB_SF_CHARS . " <input type='text' name='options[]' value='" . $options[3] . "'> " . _MB_SF_LENGTH; |
132
|
|
|
|
133
|
|
|
return $form; |
134
|
|
|
} |
135
|
|
|
|