mambax7 /
smartfaq
| 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'; |
||||||
| 14 | |||||||
| 15 | global $xoopsUser, $xoopsConfig, $xoopsModule; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 16 | /** @var Smartfaq\Helper $helper */ |
||||||
| 17 | $helper = Smartfaq\Helper::getInstance(); |
||||||
| 18 | |||||||
| 19 | // Creating the category handler object |
||||||
| 20 | /** @var \XoopsModules\Smartfaq\CategoryHandler $categoryHandler */ |
||||||
| 21 | $categoryHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Category'); |
||||||
| 22 | |||||||
| 23 | // Creating the FAQ handler object |
||||||
| 24 | /** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */ |
||||||
| 25 | $faqHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Faq'); |
||||||
| 26 | |||||||
| 27 | // Get the total number of categories |
||||||
| 28 | $totalCategories = count($categoryHandler->getCategories()); |
||||||
| 29 | |||||||
| 30 | if (0 == $totalCategories) { |
||||||
| 31 | redirect_header('index.php', 1, _AM_SF_NOCOLEXISTS); |
||||||
| 32 | } |
||||||
| 33 | |||||||
| 34 | // Find if the user is admin of the module |
||||||
| 35 | $isAdmin = Smartfaq\Utility::userIsAdmin(); |
||||||
| 36 | // If the user is not admin AND we don't allow user submission, exit |
||||||
| 37 | if (!($isAdmin |
||||||
| 38 | || (null !== ($helper->getConfig('allowrequest')) |
||||||
| 39 | && 1 == $helper->getConfig('allowrequest') |
||||||
| 40 | && (is_object($xoopsUser) || (null !== ($helper->getConfig('anonpost')) && 1 == $helper->getConfig('anonpost')))))) { |
||||||
| 41 | redirect_header('index.php', 1, _NOPERM); |
||||||
| 42 | } |
||||||
| 43 | |||||||
| 44 | $op = ''; |
||||||
| 45 | |||||||
| 46 | if (isset($_GET['op'])) { |
||||||
| 47 | $op = $_GET['op']; |
||||||
| 48 | } |
||||||
| 49 | if (isset($_POST['op'])) { |
||||||
| 50 | $op = $_POST['op']; |
||||||
| 51 | } |
||||||
| 52 | |||||||
| 53 | switch ($op) { |
||||||
| 54 | case 'post': |
||||||
| 55 | |||||||
| 56 | global $xoopsUser, $xoopsConfig, $xoopsModule, $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
}
}
Loading history...
|
|||||||
| 57 | |||||||
| 58 | $newFaqObj = $faqHandler->create(); |
||||||
| 59 | |||||||
| 60 | if (!$xoopsUser) { |
||||||
| 61 | if (1 == $helper->getConfig('anonpost')) { |
||||||
| 62 | $uid = 0; |
||||||
| 63 | } else { |
||||||
| 64 | redirect_header('index.php', 3, _NOPERM); |
||||||
| 65 | } |
||||||
| 66 | } else { |
||||||
| 67 | $uid = $xoopsUser->uid(); |
||||||
| 68 | } |
||||||
| 69 | |||||||
| 70 | // Putting the values about the FAQ in the FAQ object |
||||||
| 71 | $newFaqObj->setVar('categoryid', $_POST['categoryid']); |
||||||
| 72 | $newFaqObj->setVar('uid', $uid); |
||||||
| 73 | $newFaqObj->setVar('question', $_POST['question']); |
||||||
| 74 | $notifypub = \Xmf\Request::getInt('notifypub', 0, POST); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 75 | $newFaqObj->setVar('notifypub', $notifypub); |
||||||
| 76 | |||||||
| 77 | // Setting the status of the FAQ |
||||||
| 78 | if (1 == $helper->getConfig('autoapprove_request')) { |
||||||
| 79 | $newFaqObj->setVar('status', Constants::SF_STATUS_OPENED); |
||||||
| 80 | } else { |
||||||
| 81 | $newFaqObj->setVar('status', Constants::SF_STATUS_ASKED); |
||||||
| 82 | } |
||||||
| 83 | |||||||
| 84 | // Storing the FAQ object in the database |
||||||
| 85 | if (!$newFaqObj->store()) { |
||||||
| 86 | redirect_header('javascript:history.go(-1)', 3, _MD_SF_REQUEST_ERROR . Smartfaq\Utility::formatErrors($newFaqObj->getErrors())); |
||||||
| 87 | } |
||||||
| 88 | |||||||
| 89 | // Get the cateopry object related to that FAQ |
||||||
| 90 | // If autoapprove_requested |
||||||
| 91 | if (1 == $helper->getConfig('autoapprove_request')) { |
||||||
| 92 | // We do not not subscribe user to notification on publish since we publish it right away |
||||||
| 93 | |||||||
| 94 | // Send notifications |
||||||
| 95 | $newFaqObj->sendNotifications([Constants::SF_NOT_QUESTION_PUBLISHED]); |
||||||
| 96 | |||||||
| 97 | $redirect_msg = _MD_SF_REQUEST_RECEIVED_AND_PUBLISHED; |
||||||
| 98 | } else { |
||||||
| 99 | // Subscribe the user to On Published notification, if requested |
||||||
| 100 | if (1 == $notifypub) { |
||||||
| 101 | require_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; |
||||||
| 102 | $notificationHandler = xoops_getHandler('notification'); |
||||||
| 103 | $notificationHandler->subscribe('question', $newFaqObj->faqid(), 'approved', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE); |
||||||
|
0 ignored issues
–
show
The method
subscribe() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsNotificationHandler or XoopsPersistableObjectHandler.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 104 | } |
||||||
| 105 | // Send notifications |
||||||
| 106 | $newFaqObj->sendNotifications([Constants::SF_NOT_QUESTION_SUBMITTED]); |
||||||
| 107 | |||||||
| 108 | $redirect_msg = _MD_SF_REQUEST_RECEIVED_NEED_APPROVAL; |
||||||
| 109 | } |
||||||
| 110 | |||||||
| 111 | //redirect_header("javascript:history.go(-2)", 3, $redirect_msg); |
||||||
| 112 | redirect_header('index.php', 2, $redirect_msg); |
||||||
| 113 | break; |
||||||
| 114 | |||||||
| 115 | case 'form': |
||||||
| 116 | default: |
||||||
| 117 | |||||||
| 118 | global $xoopsUser, $myts; |
||||||
| 119 | |||||||
| 120 | $GLOBALS['xoopsOption']['template_main'] = 'smartfaq_submit.tpl'; |
||||||
| 121 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||||||
| 122 | require_once __DIR__ . '/footer.php'; |
||||||
| 123 | |||||||
| 124 | $name = $xoopsUser ? ucwords($xoopsUser->getVar('uname')) : 'Anonymous'; |
||||||
| 125 | |||||||
| 126 | $moduleName =& $myts->displayTarea($xoopsModule->getVar('name')); |
||||||
| 127 | $xoopsTpl->assign('whereInSection', $moduleName); |
||||||
| 128 | $xoopsTpl->assign('lang_submit', _MD_SF_REQUEST); |
||||||
| 129 | |||||||
| 130 | $xoopsTpl->assign('lang_intro_title', _MD_SF_REQUEST); |
||||||
| 131 | $xoopsTpl->assign('lang_intro_text', _MD_SF_GOODDAY . "<b>$name</b>, " . $myts->displayTarea($helper->getConfig('requestintromsg'))); |
||||||
| 132 | |||||||
| 133 | require_once __DIR__ . '/include/request.inc.php'; |
||||||
| 134 | |||||||
| 135 | $name = $xoopsUser ? ucwords($xoopsUser->getVar('uname')) : 'Anonymous'; |
||||||
| 136 | |||||||
| 137 | $sectionname = $myts->htmlSpecialChars($xoopsModule->getVar('name')); |
||||||
| 138 | |||||||
| 139 | require_once __DIR__ . '/include/request.inc.php'; |
||||||
| 140 | |||||||
| 141 | require_once XOOPS_ROOT_PATH . '/footer.php'; |
||||||
| 142 | |||||||
| 143 | break; |
||||||
| 144 | } |
||||||
| 145 |
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state