1 | <?php |
||||||
2 | |||||||
3 | /** |
||||||
4 | * Module: SmartFAQ |
||||||
5 | * Author: The SmartFactory <www.smartfactory.ca> |
||||||
6 | * Licence: GNU |
||||||
7 | */ |
||||||
8 | |||||||
9 | use XoopsModules\Smartfaq; |
||||||
10 | use XoopsModules\Smartfaq\Constants; |
||||||
11 | |||||||
12 | require_once __DIR__ . '/header.php'; |
||||||
13 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
14 | |||||||
15 | global $xoopsUser, $xoopsConfig, $xoopsModuleConfig, $xoopsModule; |
||||||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||||||
16 | |||||||
17 | // Creating the category handler object |
||||||
18 | /** @var \XoopsModules\Smartfaq\CategoryHandler $categoryHandler */ |
||||||
19 | $categoryHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Category'); |
||||||
20 | |||||||
21 | // Creating the FAQ handler object |
||||||
22 | /** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */ |
||||||
23 | $faqHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Faq'); |
||||||
24 | |||||||
25 | // Get the total number of categories |
||||||
26 | $totalCategories = count($categoryHandler->getCategories()); |
||||||
27 | |||||||
28 | if (0 == $totalCategories) { |
||||||
29 | redirect_header('index.php', 1, _AM_SF_NOCOLEXISTS); |
||||||
0 ignored issues
–
show
The function
redirect_header was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
30 | } |
||||||
31 | |||||||
32 | // Find if the user is admin of the module |
||||||
33 | $isAdmin = Smartfaq\Utility::userIsAdmin(); |
||||||
34 | // If the user is not admin AND we don't allow user submission, exit |
||||||
35 | if (!($isAdmin |
||||||
36 | || (isset($xoopsModuleConfig['allowrequest']) |
||||||
37 | && 1 == $xoopsModuleConfig['allowrequest'] |
||||||
38 | && (is_object($xoopsUser) || (isset($xoopsModuleConfig['anonpost']) && 1 == $xoopsModuleConfig['anonpost']))))) { |
||||||
39 | redirect_header('index.php', 1, _NOPERM); |
||||||
0 ignored issues
–
show
|
|||||||
40 | } |
||||||
41 | |||||||
42 | $op = ''; |
||||||
43 | |||||||
44 | if (isset($_GET['op'])) { |
||||||
45 | $op = $_GET['op']; |
||||||
46 | } |
||||||
47 | if (isset($_POST['op'])) { |
||||||
48 | $op = $_POST['op']; |
||||||
49 | } |
||||||
50 | |||||||
51 | switch ($op) { |
||||||
52 | case 'post': |
||||||
53 | |||||||
54 | global $xoopsUser, $xoopsConfig, $xoopsModule, $xoopsModuleConfig, $xoopsDB; |
||||||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||||||
55 | |||||||
56 | $newFaqObj = $faqHandler->create(); |
||||||
57 | |||||||
58 | if (!$xoopsUser) { |
||||||
59 | if (1 == $xoopsModuleConfig['anonpost']) { |
||||||
60 | $uid = 0; |
||||||
61 | } else { |
||||||
62 | redirect_header('index.php', 3, _NOPERM); |
||||||
63 | } |
||||||
64 | } else { |
||||||
65 | $uid = $xoopsUser->uid(); |
||||||
66 | } |
||||||
67 | |||||||
68 | // Putting the values about the FAQ in the FAQ object |
||||||
69 | $newFaqObj->setVar('categoryid', $_POST['categoryid']); |
||||||
70 | $newFaqObj->setVar('uid', $uid); |
||||||
71 | $newFaqObj->setVar('question', $_POST['question']); |
||||||
72 | $notifypub = isset($_POST['notifypub']) ? $_POST['notifypub'] : 0; |
||||||
73 | $newFaqObj->setVar('notifypub', $notifypub); |
||||||
74 | |||||||
75 | // Setting the status of the FAQ |
||||||
76 | if (1 == $xoopsModuleConfig['autoapprove_request']) { |
||||||
77 | $newFaqObj->setVar('status', Constants::SF_STATUS_OPENED); |
||||||
78 | } else { |
||||||
79 | $newFaqObj->setVar('status', Constants::SF_STATUS_ASKED); |
||||||
80 | } |
||||||
81 | |||||||
82 | // Storing the FAQ object in the database |
||||||
83 | if (!$newFaqObj->store()) { |
||||||
84 | redirect_header('javascript:history.go(-1)', 3, _MD_SF_REQUEST_ERROR . Smartfaq\Utility::formatErrors($newFaqObj->getErrors())); |
||||||
85 | } |
||||||
86 | |||||||
87 | // Get the cateopry object related to that FAQ |
||||||
88 | // If autoapprove_requested |
||||||
89 | if (1 == $xoopsModuleConfig['autoapprove_request']) { |
||||||
90 | // We do not not subscribe user to notification on publish since we publish it right away |
||||||
91 | |||||||
92 | // Send notifications |
||||||
93 | $newFaqObj->sendNotifications([Constants::SF_NOT_QUESTION_PUBLISHED]); |
||||||
94 | |||||||
95 | $redirect_msg = _MD_SF_REQUEST_RECEIVED_AND_PUBLISHED; |
||||||
96 | } else { |
||||||
97 | // Subscribe the user to On Published notification, if requested |
||||||
98 | if (1 == $notifypub) { |
||||||
99 | require_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; |
||||||
100 | $notificationHandler = xoops_getHandler('notification'); |
||||||
0 ignored issues
–
show
The function
xoops_getHandler was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
101 | $notificationHandler->subscribe('question', $newFaqObj->faqid(), 'approved', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE); |
||||||
0 ignored issues
–
show
|
|||||||
102 | } |
||||||
103 | // Send notifications |
||||||
104 | $newFaqObj->sendNotifications([Constants::SF_NOT_QUESTION_SUBMITTED]); |
||||||
105 | |||||||
106 | $redirect_msg = _MD_SF_REQUEST_RECEIVED_NEED_APPROVAL; |
||||||
107 | } |
||||||
108 | |||||||
109 | //redirect_header("javascript:history.go(-2)", 3, $redirect_msg); |
||||||
110 | redirect_header('index.php', 2, $redirect_msg); |
||||||
111 | break; |
||||||
112 | |||||||
113 | case 'form': |
||||||
114 | default: |
||||||
115 | |||||||
116 | global $xoopsUser, $myts; |
||||||
117 | |||||||
118 | $GLOBALS['xoopsOption']['template_main'] = 'smartfaq_submit.tpl'; |
||||||
119 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||||||
120 | require_once __DIR__ . '/footer.php'; |
||||||
121 | |||||||
122 | $name = $xoopsUser ? ucwords($xoopsUser->getVar('uname')) : 'Anonymous'; |
||||||
123 | |||||||
124 | $moduleName =& $myts->displayTarea($xoopsModule->getVar('name')); |
||||||
125 | $xoopsTpl->assign('whereInSection', $moduleName); |
||||||
126 | $xoopsTpl->assign('lang_submit', _MD_SF_REQUEST); |
||||||
127 | |||||||
128 | $xoopsTpl->assign('lang_intro_title', _MD_SF_REQUEST); |
||||||
129 | $xoopsTpl->assign('lang_intro_text', _MD_SF_GOODDAY . "<b>$name</b>, " . $myts->displayTarea($xoopsModuleConfig['requestintromsg'])); |
||||||
130 | |||||||
131 | require_once __DIR__ . '/include/request.inc.php'; |
||||||
132 | |||||||
133 | $name = $xoopsUser ? ucwords($xoopsUser->getVar('uname')) : 'Anonymous'; |
||||||
134 | |||||||
135 | $sectionname = $myts->htmlSpecialChars($xoopsModule->getVar('name')); |
||||||
136 | |||||||
137 | require_once __DIR__ . '/include/request.inc.php'; |
||||||
138 | |||||||
139 | require_once XOOPS_ROOT_PATH . '/footer.php'; |
||||||
140 | |||||||
141 | break; |
||||||
142 | } |
||||||
143 |