This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
1 | <?php declare(strict_types=1); |
||||
2 | |||||
3 | namespace XoopsModules\Smartfaq; |
||||
4 | |||||
5 | /** |
||||
6 | * Module: SmartFAQ |
||||
7 | * Author: The SmartFactory <www.smartfactory.ca> |
||||
8 | * Licence: GNU |
||||
9 | */ |
||||
10 | |||||
11 | use MyTextSanitizer; |
||||
12 | use XoopsDatabaseFactory; |
||||
13 | use XoopsModules\Smartfaq; |
||||
14 | use XoopsObject; |
||||
15 | |||||
16 | //require_once XOOPS_ROOT_PATH . '/modules/smartfaq/class/category.php'; |
||||
17 | |||||
18 | /** |
||||
19 | * Class Faq |
||||
20 | */ |
||||
21 | class Faq extends XoopsObject |
||||
22 | { |
||||
23 | public $db; |
||||
24 | /** |
||||
25 | * @var Smartfaq\Category|null |
||||
26 | */ |
||||
27 | private $category; |
||||
28 | /** |
||||
29 | * @var Answer|null |
||||
30 | */ |
||||
31 | private $answer; |
||||
32 | /** |
||||
33 | * @var array|null |
||||
34 | */ |
||||
35 | private $_notifications; |
||||
36 | // TODO : Create a seperated class for notifications |
||||
37 | /** |
||||
38 | * @var array|null |
||||
39 | */ |
||||
40 | private $groups_read; |
||||
41 | /** |
||||
42 | * @var object|null |
||||
43 | */ |
||||
44 | // Is this still usefull?? |
||||
45 | private $_smartModule; |
||||
46 | private $_smartModuleConfig; |
||||
47 | |||||
48 | /** |
||||
49 | * constructor |
||||
50 | * @param null $id |
||||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||||
51 | */ |
||||
52 | public function __construct($id = null) |
||||
53 | { |
||||
54 | $this->db = XoopsDatabaseFactory::getDatabaseConnection(); |
||||
55 | $this->initVar('faqid', \XOBJ_DTYPE_INT, -1, false); |
||||
56 | $this->initVar('categoryid', \XOBJ_DTYPE_INT, 0, false); |
||||
57 | $this->initVar('question', \XOBJ_DTYPE_TXTBOX, null, true, 100000); |
||||
58 | $this->initVar('howdoi', \XOBJ_DTYPE_TXTBOX, null, false, 255); |
||||
59 | $this->initVar('diduno', \XOBJ_DTYPE_TXTBOX, null, false, 255); |
||||
60 | $this->initVar('uid', \XOBJ_DTYPE_INT, 0, false); |
||||
61 | $this->initVar('datesub', \XOBJ_DTYPE_INT, null, false); |
||||
62 | $this->initVar('status', \XOBJ_DTYPE_INT, -1, false); |
||||
63 | $this->initVar('counter', \XOBJ_DTYPE_INT, 0, false); |
||||
64 | $this->initVar('weight', \XOBJ_DTYPE_INT, 0, false); |
||||
65 | $this->initVar('html', \XOBJ_DTYPE_INT, 1, false); |
||||
66 | $this->initVar('smiley', \XOBJ_DTYPE_INT, 1, false); |
||||
67 | $this->initVar('image', \XOBJ_DTYPE_INT, 1, false); |
||||
68 | $this->initVar('linebreak', \XOBJ_DTYPE_INT, 1, false); |
||||
69 | $this->initVar('xcodes', \XOBJ_DTYPE_INT, 1, false); |
||||
70 | $this->initVar('cancomment', \XOBJ_DTYPE_INT, 1, false); |
||||
71 | $this->initVar('comments', \XOBJ_DTYPE_INT, 0, false); |
||||
72 | $this->initVar('notifypub', \XOBJ_DTYPE_INT, 1, false); |
||||
73 | $this->initVar('modulelink', \XOBJ_DTYPE_TXTBOX, 'None', false, 50); |
||||
74 | $this->initVar('contextpage', \XOBJ_DTYPE_TXTBOX, null, false, 255); |
||||
75 | $this->initVar('exacturl', \XOBJ_DTYPE_INT, 0, false); |
||||
76 | $this->initVar('partialview', \XOBJ_DTYPE_INT, 0, false); |
||||
77 | |||||
78 | if (null !== $id) { |
||||
79 | $faqHandler = new Smartfaq\FaqHandler($this->db); |
||||
80 | $faq = $faqHandler->get($id); |
||||
81 | foreach ($faq->vars as $k => $v) { |
||||
82 | $this->assignVar($k, $v['value']); |
||||
83 | } |
||||
84 | $this->assignOtherProperties(); |
||||
85 | } |
||||
86 | } |
||||
87 | |||||
88 | public function assignOtherProperties(): void |
||||
89 | { |
||||
90 | $smartModule = Smartfaq\Utility::getModuleInfo(); |
||||
91 | $module_id = $smartModule->getVar('mid'); |
||||
92 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||||
93 | $grouppermHandler = \xoops_getHandler('groupperm'); |
||||
94 | |||||
95 | $this->category = new Smartfaq\Category($this->getVar('categoryid')); |
||||
96 | $this->groups_read = $grouppermHandler->getGroupIds('item_read', $this->faqid(), $module_id); |
||||
97 | } |
||||
98 | |||||
99 | /** |
||||
100 | * @return bool |
||||
101 | */ |
||||
102 | public function checkPermission() |
||||
103 | { |
||||
104 | // require_once XOOPS_ROOT_PATH . '/modules/smartfaq/include/functions.php'; |
||||
105 | |||||
106 | $userIsAdmin = Smartfaq\Utility::userIsAdmin(); |
||||
107 | if ($userIsAdmin) { |
||||
108 | return true; |
||||
109 | } |
||||
110 | /** @var Smartfaq\PermissionHandler $smartPermHandler */ |
||||
111 | $smartPermHandler = Smartfaq\Helper::getInstance()->getHandler('Permission'); |
||||
112 | // $smartPermHandler = xoops_getModuleHandler('permission', 'smartfaq'); |
||||
113 | |||||
114 | $faqsGranted = $smartPermHandler->getPermissions('item'); |
||||
115 | if (\in_array($this->categoryid(), $faqsGranted, true)) { |
||||
116 | $ret = true; |
||||
117 | } |
||||
118 | |||||
119 | return $ret; |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
120 | } |
||||
121 | |||||
122 | /** |
||||
123 | * @return array |
||||
124 | */ |
||||
125 | public function getGroups_read() |
||||
126 | { |
||||
127 | if (\count($this->groups_read) < 1) { |
||||
0 ignored issues
–
show
It seems like
$this->groups_read can also be of type null ; however, parameter $value of count() does only seem to accept Countable|array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
128 | $this->assignOtherProperties(); |
||||
129 | } |
||||
130 | |||||
131 | return $this->groups_read; |
||||
132 | } |
||||
133 | |||||
134 | /** |
||||
135 | * @param array $groups_read |
||||
136 | */ |
||||
137 | public function setGroups_read($groups_read = ['0']): void |
||||
138 | { |
||||
139 | $this->groups_read = $groups_read; |
||||
140 | } |
||||
141 | |||||
142 | /** |
||||
143 | * @return mixed |
||||
144 | */ |
||||
145 | public function faqid() |
||||
146 | { |
||||
147 | return $this->getVar('faqid'); |
||||
148 | } |
||||
149 | |||||
150 | /** |
||||
151 | * @return mixed |
||||
152 | */ |
||||
153 | public function categoryid() |
||||
154 | { |
||||
155 | return $this->getVar('categoryid'); |
||||
156 | } |
||||
157 | |||||
158 | /** |
||||
159 | * @return Smartfaq\Category |
||||
160 | */ |
||||
161 | public function category() |
||||
162 | { |
||||
163 | return $this->category; |
||||
164 | } |
||||
165 | |||||
166 | /** |
||||
167 | * @param int $maxLength |
||||
168 | * @param string $format |
||||
169 | * @return mixed|string |
||||
170 | */ |
||||
171 | public function question($maxLength = 0, $format = 'S') |
||||
172 | { |
||||
173 | $ret = $this->getVar('question', $format); |
||||
174 | if (('s' === $format) || ('S' === $format) || ('show' === $format)) { |
||||
175 | $myts = MyTextSanitizer::getInstance(); |
||||
176 | $ret = $myts->displayTarea($ret); |
||||
0 ignored issues
–
show
It seems like
$ret can also be of type array and array ; however, parameter $text of MyTextSanitizer::displayTarea() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
177 | } |
||||
178 | if (0 != $maxLength) { |
||||
179 | if (!XOOPS_USE_MULTIBYTES) { |
||||
180 | if (mb_strlen($ret) >= $maxLength) { |
||||
181 | $ret = mb_substr($ret, 0, $maxLength - 1) . '...'; |
||||
182 | } |
||||
183 | } |
||||
184 | } |
||||
185 | |||||
186 | return $ret; |
||||
187 | } |
||||
188 | |||||
189 | /** |
||||
190 | * @param string $format |
||||
191 | * @return mixed |
||||
192 | */ |
||||
193 | public function howdoi($format = 'S') |
||||
194 | { |
||||
195 | $ret = $this->getVar('howdoi', $format); |
||||
196 | if (('s' === $format) || ('S' === $format) || ('show' === $format)) { |
||||
197 | $myts = MyTextSanitizer::getInstance(); |
||||
198 | $ret = $myts->displayTarea($ret); |
||||
0 ignored issues
–
show
It seems like
$ret can also be of type array and array ; however, parameter $text of MyTextSanitizer::displayTarea() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
199 | } |
||||
200 | |||||
201 | return $ret; |
||||
202 | } |
||||
203 | |||||
204 | /** |
||||
205 | * @param string $format |
||||
206 | * @return mixed |
||||
207 | */ |
||||
208 | public function diduno($format = 'S') |
||||
209 | { |
||||
210 | $ret = $this->getVar('diduno', $format); |
||||
211 | if (('s' === $format) || ('S' === $format) || ('show' === $format)) { |
||||
212 | $myts = MyTextSanitizer::getInstance(); |
||||
213 | $ret = $myts->displayTarea($ret); |
||||
0 ignored issues
–
show
It seems like
$ret can also be of type array and array ; however, parameter $text of MyTextSanitizer::displayTarea() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
214 | } |
||||
215 | |||||
216 | return $ret; |
||||
217 | } |
||||
218 | |||||
219 | /** |
||||
220 | * @return mixed |
||||
221 | */ |
||||
222 | public function uid() |
||||
223 | { |
||||
224 | return $this->getVar('uid'); |
||||
225 | } |
||||
226 | |||||
227 | /** |
||||
228 | * @param string $dateFormat |
||||
229 | * @param string $format |
||||
230 | * @return string |
||||
231 | */ |
||||
232 | public function datesub($dateFormat = 'none', $format = 'S') |
||||
233 | { |
||||
234 | if ('none' === $dateFormat) { |
||||
235 | $smartConfig = Smartfaq\Utility::getModuleConfig(); |
||||
236 | $dateFormat = $smartConfig['dateformat']; |
||||
237 | } |
||||
238 | |||||
239 | return \formatTimestamp($this->getVar('datesub', $format), $dateFormat); |
||||
240 | } |
||||
241 | |||||
242 | /** |
||||
243 | * @return mixed |
||||
244 | */ |
||||
245 | public function status() |
||||
246 | { |
||||
247 | return $this->getVar('status'); |
||||
248 | } |
||||
249 | |||||
250 | /** |
||||
251 | * @return mixed |
||||
252 | */ |
||||
253 | public function counter() |
||||
254 | { |
||||
255 | return $this->getVar('counter'); |
||||
256 | } |
||||
257 | |||||
258 | /** |
||||
259 | * @return mixed |
||||
260 | */ |
||||
261 | public function weight() |
||||
262 | { |
||||
263 | return $this->getVar('weight'); |
||||
264 | } |
||||
265 | |||||
266 | /** |
||||
267 | * @return mixed |
||||
268 | */ |
||||
269 | public function html() |
||||
270 | { |
||||
271 | return $this->getVar('html'); |
||||
272 | } |
||||
273 | |||||
274 | /** |
||||
275 | * @return mixed |
||||
276 | */ |
||||
277 | public function smiley() |
||||
278 | { |
||||
279 | return $this->getVar('smiley'); |
||||
280 | } |
||||
281 | |||||
282 | /** |
||||
283 | * @return mixed |
||||
284 | */ |
||||
285 | public function xcodes() |
||||
286 | { |
||||
287 | return $this->getVar('xcodes'); |
||||
288 | } |
||||
289 | |||||
290 | /** |
||||
291 | * @return mixed |
||||
292 | */ |
||||
293 | public function cancomment() |
||||
294 | { |
||||
295 | return $this->getVar('cancomment'); |
||||
296 | } |
||||
297 | |||||
298 | /** |
||||
299 | * @return mixed |
||||
300 | */ |
||||
301 | public function comments() |
||||
302 | { |
||||
303 | return $this->getVar('comments'); |
||||
304 | } |
||||
305 | |||||
306 | /** |
||||
307 | * @return mixed |
||||
308 | */ |
||||
309 | public function notifypub() |
||||
310 | { |
||||
311 | return $this->getVar('notifypub'); |
||||
312 | } |
||||
313 | |||||
314 | /** |
||||
315 | * @param string $format |
||||
316 | * @return mixed |
||||
317 | */ |
||||
318 | public function modulelink($format = 'S') |
||||
319 | { |
||||
320 | return $this->getVar('modulelink', $format); |
||||
321 | } |
||||
322 | |||||
323 | /** |
||||
324 | * @param string $format |
||||
325 | * @return mixed |
||||
326 | */ |
||||
327 | public function contextpage($format = 'S') |
||||
328 | { |
||||
329 | return $this->getVar('contextpage', $format); |
||||
330 | } |
||||
331 | |||||
332 | /** |
||||
333 | * @return mixed |
||||
334 | */ |
||||
335 | public function exacturl() |
||||
336 | { |
||||
337 | return $this->getVar('exacturl'); |
||||
338 | } |
||||
339 | |||||
340 | /** |
||||
341 | * @return mixed |
||||
342 | */ |
||||
343 | public function partialview() |
||||
344 | { |
||||
345 | return $this->getVar('partialview'); |
||||
346 | } |
||||
347 | |||||
348 | /** |
||||
349 | * @param int $realName |
||||
350 | * @return string |
||||
351 | */ |
||||
352 | public function posterName($realName = -1) |
||||
353 | { |
||||
354 | if (-1 == $realName) { |
||||
355 | $smartConfig = Smartfaq\Utility::getModuleConfig(); |
||||
356 | $realName = $smartConfig['userealname']; |
||||
357 | } |
||||
358 | |||||
359 | return Smartfaq\Utility::getLinkedUnameFromId($this->uid(), $realName); |
||||
360 | } |
||||
361 | |||||
362 | /** |
||||
363 | * @return mixed|object|Smartfaq\Answer |
||||
364 | */ |
||||
365 | public function answer() |
||||
366 | { |
||||
367 | $answerHandler = new Smartfaq\AnswerHandler($this->db); |
||||
368 | switch ($this->status()) { |
||||
369 | case Constants::SF_STATUS_SUBMITTED: |
||||
370 | $theAnswers = $answerHandler->getAllAnswers($this->faqid(), Constants::SF_AN_STATUS_APPROVED, 1, 0); |
||||
371 | //echo "test"; |
||||
372 | //exit; |
||||
373 | $this->answer = &$theAnswers[0]; |
||||
374 | break; |
||||
375 | case Constants::SF_STATUS_ANSWERED: |
||||
376 | $theAnswers = $answerHandler->getAllAnswers($this->faqid(), Constants::SF_AN_STATUS_PROPOSED, 1, 0); |
||||
377 | //echo "test"; |
||||
378 | //exit; |
||||
379 | $this->answer = &$theAnswers[0]; |
||||
380 | break; |
||||
381 | case Constants::SF_STATUS_PUBLISHED: |
||||
382 | case Constants::SF_STATUS_NEW_ANSWER: |
||||
383 | case Constants::SF_STATUS_OFFLINE: |
||||
384 | $this->answer = $answerHandler->getOfficialAnswer($this->faqid()); |
||||
385 | break; |
||||
386 | case Constants::SF_STATUS_ASKED: |
||||
387 | case Constants::SF_STATUS_OPENED: |
||||
388 | $this->answer = $answerHandler->create(); |
||||
389 | break; |
||||
390 | } |
||||
391 | |||||
392 | if ($this->answer) { |
||||
393 | $this->answer->setVar('dohtml', $this->getVar('html')); |
||||
394 | $this->answer->setVar('doxcode', $this->getVar('xcodes')); |
||||
395 | $this->answer->setVar('dosmiley', $this->getVar('smiley')); |
||||
396 | $this->answer->setVar('doimage', $this->getVar('image')); |
||||
397 | $this->answer->setVar('dobr', $this->getVar('linebreak')); |
||||
398 | } |
||||
399 | |||||
400 | return $this->answer; |
||||
401 | } |
||||
402 | |||||
403 | /** |
||||
404 | * @return array |
||||
405 | */ |
||||
406 | public function getAllAnswers() |
||||
407 | { |
||||
408 | $answerHandler = new Smartfaq\AnswerHandler($this->db); |
||||
409 | |||||
410 | return $answerHandler->getAllAnswers($this->faqid()); |
||||
411 | } |
||||
412 | |||||
413 | /** |
||||
414 | * @return bool |
||||
415 | */ |
||||
416 | public function updateCounter() |
||||
417 | { |
||||
418 | $faqHandler = new Smartfaq\FaqHandler($this->db); |
||||
419 | |||||
420 | return $faqHandler->updateCounter($this->faqid()); |
||||
421 | } |
||||
422 | |||||
423 | /** |
||||
424 | * @param bool $force |
||||
425 | * @return bool |
||||
426 | */ |
||||
427 | public function store($force = true) |
||||
428 | { |
||||
429 | $faqHandler = new Smartfaq\FaqHandler($this->db); |
||||
430 | |||||
431 | return $faqHandler->insert($this, $force); |
||||
432 | } |
||||
433 | |||||
434 | /** |
||||
435 | * @return mixed |
||||
436 | */ |
||||
437 | public function getCategoryName() |
||||
438 | { |
||||
439 | if (!isset($this->category)) { |
||||
440 | $this->category = new Smartfaq\Category($this->getVar('categoryid')); |
||||
441 | } |
||||
442 | |||||
443 | return $this->category->name(); |
||||
444 | } |
||||
445 | |||||
446 | /** |
||||
447 | * @param array $notifications |
||||
448 | */ |
||||
449 | public function sendNotifications($notifications = []): void |
||||
450 | { |
||||
451 | $smartModule = Smartfaq\Utility::getModuleInfo(); |
||||
452 | |||||
453 | $myts = MyTextSanitizer::getInstance(); |
||||
454 | /** @var \XoopsNotificationHandler $notificationHandler */ |
||||
455 | $notificationHandler = \xoops_getHandler('notification'); |
||||
456 | //$categoryObj = $this->category(); |
||||
457 | |||||
458 | $tags = []; |
||||
459 | $tags['MODULE_NAME'] = $myts->displayTarea($smartModule->getVar('name')); |
||||
460 | $tags['FAQ_NAME'] = $this->question(); |
||||
461 | $tags['CATEGORY_NAME'] = $this->getCategoryName(); |
||||
462 | $tags['CATEGORY_URL'] = XOOPS_URL . '/modules/' . $smartModule->getVar('dirname') . '/category.php?categoryid=' . $this->categoryid(); |
||||
463 | $tags['FAQ_QUESTION'] = $this->question(); |
||||
464 | $answerObj = $this->answer(); |
||||
465 | if (\is_object($answerObj)) { |
||||
466 | // TODO : Not sure about the 'formpreview' ... |
||||
467 | $tags['FAQ_ANSWER'] = $answerObj->answer('formpreview'); |
||||
468 | } |
||||
469 | $tags['DATESUB'] = $this->datesub(); |
||||
470 | |||||
471 | foreach ($notifications as $notification) { |
||||
472 | switch ($notification) { |
||||
473 | case Constants::SF_NOT_FAQ_PUBLISHED: |
||||
474 | $tags['FAQ_URL'] = XOOPS_URL . '/modules/' . $smartModule->getVar('dirname') . '/faq.php?faqid=' . $this->faqid(); |
||||
475 | |||||
476 | $notificationHandler->triggerEvent('global_faq', 0, 'published', $tags); |
||||
477 | $notificationHandler->triggerEvent('category_faq', $this->categoryid(), 'published', $tags); |
||||
478 | $notificationHandler->triggerEvent('faq', $this->faqid(), 'approved', $tags); |
||||
479 | break; |
||||
480 | case Constants::SF_NOT_FAQ_SUBMITTED: |
||||
481 | $tags['WAITINGFILES_URL'] = XOOPS_URL . '/modules/' . $smartModule->getVar('dirname') . '/admin/faq.php?faqid=' . $this->faqid(); |
||||
482 | $notificationHandler->triggerEvent('global_faq', 0, 'submitted', $tags); |
||||
483 | $notificationHandler->triggerEvent('category_faq', $this->categoryid(), 'submitted', $tags); |
||||
484 | break; |
||||
485 | case Constants::SF_NOT_QUESTION_PUBLISHED: |
||||
486 | $tags['FAQ_URL'] = XOOPS_URL . '/modules/' . $smartModule->getVar('dirname') . '/answer.php?faqid=' . $this->faqid(); |
||||
487 | $notificationHandler->triggerEvent('global_question', 0, 'published', $tags); |
||||
488 | $notificationHandler->triggerEvent('category_question', $this->categoryid(), 'published', $tags); |
||||
489 | $notificationHandler->triggerEvent('question', $this->faqid(), 'approved', $tags); |
||||
490 | break; |
||||
491 | case Constants::SF_NOT_QUESTION_SUBMITTED: |
||||
492 | $tags['WAITINGFILES_URL'] = XOOPS_URL . '/modules/' . $smartModule->getVar('dirname') . '/admin/question.php?op=mod&faqid=' . $this->faqid(); |
||||
493 | $notificationHandler->triggerEvent('global_question', 0, 'submitted', $tags); |
||||
494 | $notificationHandler->triggerEvent('category_question', $this->categoryid(), 'submitted', $tags); |
||||
495 | break; |
||||
496 | case Constants::SF_NOT_FAQ_REJECTED: |
||||
497 | $notificationHandler->triggerEvent('faq', $this->faqid(), 'rejected', $tags); |
||||
498 | break; |
||||
499 | case Constants::SF_NOT_NEW_ANSWER_PROPOSED: |
||||
500 | $tags['WAITINGFILES_URL'] = XOOPS_URL . '/modules/' . $smartModule->getVar('dirname') . '/admin/answer.php?op=mod&faqid=' . $this->faqid(); |
||||
501 | $notificationHandler->triggerEvent('global_faq', 0, 'answer_proposed', $tags); |
||||
502 | $notificationHandler->triggerEvent('category_faq', $this->categoryid(), 'answer_proposed', $tags); |
||||
503 | break; |
||||
504 | case Constants::SF_NOT_NEW_ANSWER_PUBLISHED: |
||||
505 | $notificationHandler->triggerEvent('global_faq', 0, 'answer_published', $tags); |
||||
506 | $notificationHandler->triggerEvent('category_faq', $this->categoryid(), 'answer_published', $tags); |
||||
507 | break; |
||||
508 | // TODO : I commented out this one because I'm not sure. The $this->faqid() should probably be the |
||||
509 | // answerid not the faqid.... |
||||
510 | /* |
||||
511 | case Constants::SF_NOT_ANSWER_APPROVED: |
||||
512 | $notificationHandler->triggerEvent('faq', $this->faqid(), 'answer_approved', $tags); |
||||
513 | break; |
||||
514 | */ |
||||
515 | |||||
516 | // TODO : I commented out this one because I'm not sure. The $this->faqid() should probably be the |
||||
517 | // answerid not the faqid.... |
||||
518 | /* |
||||
519 | case Constants::SF_NOT_ANSWER_REJECTED: |
||||
520 | $notificationHandler->triggerEvent('faq', $this->faqid(), 'answer_approved', $tags); |
||||
521 | break; |
||||
522 | */ |
||||
523 | |||||
524 | case -1: |
||||
525 | default: |
||||
526 | break; |
||||
527 | } |
||||
528 | } |
||||
529 | } |
||||
530 | |||||
531 | public function setDefaultPermissions(): void |
||||
532 | { |
||||
533 | $memberHandler = \xoops_getHandler('member'); |
||||
534 | $groups = $memberHandler->getGroupList(); |
||||
535 | |||||
536 | $j = 0; |
||||
537 | $group_ids = []; |
||||
538 | foreach (\array_keys($groups) as $i) { |
||||
539 | $group_ids[$j] = $i; |
||||
540 | ++$j; |
||||
541 | } |
||||
542 | $this->groups_read = $group_ids; |
||||
543 | } |
||||
544 | |||||
545 | /** |
||||
546 | * @param $group_ids |
||||
547 | */ |
||||
548 | public function setPermissions($group_ids): void |
||||
549 | { |
||||
550 | if (!isset($group_ids)) { |
||||
551 | $memberHandler = \xoops_getHandler('member'); |
||||
552 | $groups = $memberHandler->getGroupList(); |
||||
553 | |||||
554 | $j = 0; |
||||
555 | $group_ids = []; |
||||
556 | foreach (\array_keys($groups) as $i) { |
||||
557 | $group_ids[$j] = $i; |
||||
558 | ++$j; |
||||
559 | } |
||||
560 | } |
||||
561 | } |
||||
562 | |||||
563 | /** |
||||
564 | * @return bool |
||||
565 | */ |
||||
566 | public function notLoaded() |
||||
567 | { |
||||
568 | return (-1 == $this->getVar('faqid')); |
||||
569 | } |
||||
570 | |||||
571 | /** |
||||
572 | * @param null $answerObj |
||||
0 ignored issues
–
show
|
|||||
573 | * @param array $users |
||||
574 | * @return string |
||||
575 | */ |
||||
576 | public function getWhoAndWhen($answerObj = null, $users = []) |
||||
577 | { |
||||
578 | /** @var Smartfaq\Helper $helper */ |
||||
579 | $helper = Smartfaq\Helper::getInstance(); |
||||
580 | $smartModuleConfig = $helper->getConfig(); |
||||
581 | |||||
582 | $requester = Smartfaq\Utility::getLinkedUnameFromId($this->uid(), $smartModuleConfig['userealname'], $users); |
||||
583 | $requestdate = $this->datesub(); |
||||
584 | |||||
585 | if ((Constants::SF_STATUS_PUBLISHED == $this->status()) || Constants::SF_STATUS_NEW_ANSWER == $this->status()) { |
||||
586 | if (null === $answerObj) { |
||||
587 | $answerObj = $this->answer(); |
||||
588 | } |
||||
589 | $submitdate = $answerObj->datesub(); |
||||
590 | if ($this->uid() == $answerObj->uid()) { |
||||
591 | $result = \sprintf(\_MD_SF_REQUESTEDANDANSWERED, $requester, $submitdate); |
||||
592 | } else { |
||||
593 | $submitter = Smartfaq\Utility::getLinkedUnameFromId($answerObj->uid(), $smartModuleConfig['userealname'], $users); |
||||
594 | $result = \sprintf(\_MD_SF_REQUESTEDBYANDANSWEREDBY, $requester, $submitter, $submitdate); |
||||
595 | } |
||||
596 | } else { |
||||
597 | $result = \sprintf(\_MD_SF_REQUESTEDBY, $requester, $requestdate); |
||||
598 | } |
||||
599 | |||||
600 | return $result; |
||||
601 | } |
||||
602 | |||||
603 | /** |
||||
604 | * @return string |
||||
605 | */ |
||||
606 | public function getComeFrom() |
||||
607 | { |
||||
608 | global $xoopsConfig; |
||||
609 | $text = \_MD_SF_QUESTIONCOMEFROM; |
||||
610 | if ((Constants::SF_STATUS_PUBLISHED == $this->status()) || Constants::SF_STATUS_NEW_ANSWER == $this->status()) { |
||||
611 | $text = \_MD_SF_FAQCOMEFROM; |
||||
612 | } |
||||
613 | |||||
614 | return $text . $xoopsConfig['sitename'] . ' : <a href=' . XOOPS_URL . '/modules/smartfaq/faq.php?faqid=' . $this->faqid() . '>' . XOOPS_URL . '/modules/smartfaq/faq.php?faqid=' . $this->faqid() . '</a>'; |
||||
615 | } |
||||
616 | |||||
617 | /** |
||||
618 | * @param array $faq |
||||
619 | * @param null $category |
||||
0 ignored issues
–
show
|
|||||
620 | * @param bool $linkInQuestion |
||||
621 | * @return array |
||||
622 | */ |
||||
623 | public function toArray($faq = [], $category = null, $linkInQuestion = true) |
||||
624 | { |
||||
625 | /** @var Smartfaq\Helper $helper */ |
||||
626 | $helper = Smartfaq\Helper::getInstance(); |
||||
627 | |||||
628 | $lastfaqsize = (int)$helper->getConfig('lastfaqsize'); |
||||
629 | |||||
630 | $faq['id'] = $this->faqid(); |
||||
631 | $faq['categoryid'] = $this->categoryid(); |
||||
632 | $faq['question'] = $this->question(); |
||||
633 | $page = (Constants::SF_STATUS_OPENED == $this->status()) ? 'answer.php' : 'faq.php'; |
||||
634 | |||||
635 | $faq['questionlink'] = "<a href='$page?faqid=" . $this->faqid() . "'>" . $this->question($lastfaqsize) . '</a>'; |
||||
636 | if ($linkInQuestion) { |
||||
637 | $faq['fullquestionlink'] = "<a href='$page?faqid=" . $this->faqid() . "'>" . $this->question() . '</a>'; |
||||
638 | } else { |
||||
639 | $faq['fullquestionlink'] = $this->question(); |
||||
640 | } |
||||
641 | $faq['faqid'] = $this->faqid(); |
||||
642 | $faq['counter'] = $this->counter(); |
||||
643 | $faq['cancomment'] = $this->cancomment(); |
||||
644 | $faq['comments'] = $this->comments(); |
||||
645 | $faq['datesub'] = $this->datesub(); |
||||
646 | if (null !== $category) { |
||||
647 | if (\is_object($category) && 'xoopsmodules\smartfaq\category' === \mb_strtolower(\get_class($category))) { |
||||
648 | $categoryObj = $category; |
||||
649 | } elseif (\is_array($category)) { |
||||
650 | $categoryObj = $category[$this->categoryid()]; |
||||
651 | } |
||||
652 | $faq['categoryname'] = $categoryObj->getVar('name'); |
||||
653 | $faq['categorylink'] = "<a href='" . XOOPS_URL . '/modules/smartfaq/category.php?categoryid=' . $this->categoryid() . "'>" . $categoryObj->getVar('name') . '</a>'; |
||||
654 | } |
||||
655 | |||||
656 | return $faq; |
||||
657 | } |
||||
658 | } |
||||
659 |