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 | include_once(XOOPS_ROOT_PATH . '/header.php'); |
||
11 | |||
12 | global $xoopsUser, $xoopsConfig, $xoopsModuleConfig, $xoopsModule; |
||
0 ignored issues
–
show
|
|||
13 | |||
14 | // Creating the category handler object |
||
15 | $categoryHandler = sf_gethandler('category'); |
||
16 | |||
17 | // Creating the FAQ handler object |
||
18 | $faqHandler = sf_gethandler('faq'); |
||
19 | |||
20 | // Get the total number of categories |
||
21 | $totalCategories = count($categoryHandler->getCategories()); |
||
22 | |||
23 | if ($totalCategories == 0) { |
||
24 | redirect_header('index.php', 1, _AM_SF_NOCOLEXISTS); |
||
25 | } |
||
26 | |||
27 | // Find if the user is admin of the module |
||
28 | $isAdmin = sf_userIsAdmin(); |
||
29 | // If the user is not admin AND we don't allow user submission, exit |
||
30 | View Code Duplication | if (!($isAdmin || (isset($xoopsModuleConfig['allowrequest']) && $xoopsModuleConfig['allowrequest'] == 1 && (is_object($xoopsUser) || (isset($xoopsModuleConfig['anonpost']) && $xoopsModuleConfig['anonpost'] == 1))))) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
31 | redirect_header('index.php', 1, _NOPERM); |
||
32 | } |
||
33 | |||
34 | $op = ''; |
||
35 | |||
36 | if (isset($_GET['op'])) { |
||
37 | $op = $_GET['op']; |
||
38 | } |
||
39 | if (isset($_POST['op'])) { |
||
40 | $op = $_POST['op']; |
||
41 | } |
||
42 | |||
43 | switch ($op) { |
||
44 | case 'post': |
||
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
45 | |||
46 | 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
}
}
![]() |
|||
47 | |||
48 | $newFaqObj = $faqHandler->create(); |
||
49 | |||
50 | View Code Duplication | if (!$xoopsUser) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
51 | if ($xoopsModuleConfig['anonpost'] == 1) { |
||
52 | $uid = 0; |
||
53 | } else { |
||
54 | redirect_header('index.php', 3, _NOPERM); |
||
55 | } |
||
56 | } else { |
||
57 | $uid = $xoopsUser->uid(); |
||
0 ignored issues
–
show
|
|||
58 | } |
||
59 | |||
60 | // Putting the values about the FAQ in the FAQ object |
||
61 | $newFaqObj->setVar('categoryid', $_POST['categoryid']); |
||
62 | $newFaqObj->setVar('uid', $uid); |
||
63 | $newFaqObj->setVar('question', $_POST['question']); |
||
64 | $notifypub = isset($_POST['notifypub']) ? $_POST['notifypub'] : 0; |
||
65 | $newFaqObj->setVar('notifypub', $notifypub); |
||
66 | |||
67 | // Setting the status of the FAQ |
||
68 | if ($xoopsModuleConfig['autoapprove_request'] == 1) { |
||
69 | $newFaqObj->setVar('status', _SF_STATUS_OPENED); |
||
70 | } else { |
||
71 | $newFaqObj->setVar('status', _SF_STATUS_ASKED); |
||
72 | } |
||
73 | |||
74 | // Storing the FAQ object in the database |
||
75 | if (!$newFaqObj->store()) { |
||
76 | redirect_header('javascript:history.go(-1)', 3, _MD_SF_REQUEST_ERROR . sf_formatErrors($newFaqObj->getErrors())); |
||
77 | } |
||
78 | |||
79 | // Get the cateopry object related to that FAQ |
||
80 | // If autoapprove_requested |
||
81 | if ($xoopsModuleConfig['autoapprove_request'] == 1) { |
||
82 | // We do not not subscribe user to notification on publish since we publish it right away |
||
83 | |||
84 | // Send notifications |
||
85 | $newFaqObj->sendNotifications(array(_SF_NOT_QUESTION_PUBLISHED)); |
||
86 | |||
87 | $redirect_msg = _MD_SF_REQUEST_RECEIVED_AND_PUBLISHED; |
||
88 | View Code Duplication | } else { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
89 | // Subscribe the user to On Published notification, if requested |
||
90 | if ($notifypub == 1) { |
||
91 | include_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; |
||
92 | $notificationHandler = xoops_getHandler('notification'); |
||
93 | $notificationHandler->subscribe('question', $newFaqObj->faqid(), 'approved', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE); |
||
94 | } |
||
95 | // Send notifications |
||
96 | $newFaqObj->sendNotifications(array(_SF_NOT_QUESTION_SUBMITTED)); |
||
97 | |||
98 | $redirect_msg = _MD_SF_REQUEST_RECEIVED_NEED_APPROVAL; |
||
99 | } |
||
100 | |||
101 | //redirect_header("javascript:history.go(-2)", 3, $redirect_msg); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
73% 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. ![]() |
|||
102 | redirect_header('index.php', 2, $redirect_msg); |
||
103 | break; |
||
104 | |||
105 | case 'form': |
||
106 | default: |
||
0 ignored issues
–
show
The default body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a default statement must start on the line immediately following the statement. switch ($expr) {
default:
doSomething(); //right
break;
}
switch ($expr) {
default:
doSomething(); //wrong
break;
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
107 | |||
108 | global $xoopsUser, $myts; |
||
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
}
}
![]() |
|||
109 | |||
110 | $xoopsOption['template_main'] = 'smartfaq_submit.tpl'; |
||
111 | include_once(XOOPS_ROOT_PATH . '/header.php'); |
||
112 | include_once __DIR__ . '/footer.php'; |
||
113 | |||
114 | $name = $xoopsUser ? ucwords($xoopsUser->getVar('uname')) : 'Anonymous'; |
||
0 ignored issues
–
show
|
|||
115 | |||
116 | $moduleName =& $myts->displayTarea($xoopsModule->getVar('name')); |
||
117 | $xoopsTpl->assign('whereInSection', $moduleName); |
||
118 | $xoopsTpl->assign('lang_submit', _MD_SF_REQUEST); |
||
119 | |||
120 | $xoopsTpl->assign('lang_intro_title', _MD_SF_REQUEST); |
||
121 | $xoopsTpl->assign('lang_intro_text', _MD_SF_GOODDAY . "<b>$name</b>, " . $myts->displayTarea($xoopsModuleConfig['requestintromsg'])); |
||
122 | |||
123 | include_once 'include/request.inc.php'; |
||
124 | |||
125 | $name = $xoopsUser ? ucwords($xoopsUser->getVar('uname')) : 'Anonymous'; |
||
0 ignored issues
–
show
|
|||
126 | |||
127 | $sectionname = $myts->htmlSpecialChars($xoopsModule->getVar('name')); |
||
128 | |||
129 | include_once 'include/request.inc.php'; |
||
130 | |||
131 | include_once XOOPS_ROOT_PATH . '/footer.php'; |
||
132 | |||
133 | break; |
||
134 | } |
||
135 |
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state