1 | <?php |
||||||
2 | /** |
||||||
3 | * Newbb module |
||||||
4 | * |
||||||
5 | * You may not change or alter any portion of this comment or credits |
||||||
6 | * of supporting developers from this source code or any supporting source code |
||||||
7 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||||||
8 | * This program is distributed in the hope that it will be useful, |
||||||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||||
11 | * |
||||||
12 | * @copyright XOOPS Project (https://xoops.org) |
||||||
13 | * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
||||||
14 | * @package newbb |
||||||
15 | * @since 4.0 |
||||||
16 | * @author Taiwen Jiang <[email protected]> |
||||||
17 | */ |
||||||
18 | |||||||
19 | use Xmf\Request; |
||||||
20 | use XoopsModules\Newbb; |
||||||
21 | |||||||
22 | require_once __DIR__ . '/header.php'; |
||||||
23 | |||||||
24 | foreach ([ |
||||||
25 | 'forum', |
||||||
26 | 'topic_id', |
||||||
27 | 'post_id', |
||||||
28 | 'order', |
||||||
29 | 'pid', |
||||||
30 | 'start', |
||||||
31 | 'isreply', |
||||||
32 | 'isedit' |
||||||
33 | ] as $getint) { |
||||||
34 | ${$getint} = Request::getInt($getint, 0, 'POST'); |
||||||
35 | } |
||||||
36 | |||||||
37 | $op = Request::getCmd('op', '', 'POST'); |
||||||
38 | $viewmode = ('flat' !== Request::getString('viewmode', '', 'POST')) ? 'thread' : 'flat'; |
||||||
39 | if (empty($forum)) { |
||||||
40 | redirect_header('index.php', 2, _MD_NEWBB_ERRORFORUM); |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
41 | } |
||||||
42 | |||||||
43 | ///** @var Newbb\ForumHandler $forumHandler */ |
||||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
54% 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. ![]() |
|||||||
44 | //$forumHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
||||||
45 | ///** @var Newbb\TopicHandler $topicHandler */ |
||||||
46 | //$topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
||||||
47 | ///** @var Newbb\PostHandler $postHandler */ |
||||||
48 | //$postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
||||||
49 | |||||||
50 | if (!empty($isedit) && $post_id > 0) { |
||||||
51 | /** @var Post $postObject */ |
||||||
52 | $postObject = $postHandler->get($post_id); |
||||||
53 | $topic_id = $postObject->getVar('topic_id'); |
||||||
54 | } else { |
||||||
55 | $postObject = $postHandler->create(); |
||||||
56 | } |
||||||
57 | $topicObject = $topicHandler->get($topic_id); |
||||||
58 | $forum_id = $topic_id ? $topicObject->getVar('forum_id') : $forum; |
||||||
59 | $forumObject = $forumHandler->get($forum_id); |
||||||
60 | if (!$forumHandler->getPermission($forumObject)) { |
||||||
61 | redirect_header('index.php', 2, _NOPERM); |
||||||
0 ignored issues
–
show
|
|||||||
62 | } |
||||||
63 | |||||||
64 | if ($GLOBALS['xoopsModuleConfig']['wol_enabled']) { |
||||||
65 | // /** @var Newbb\OnlineHandler $onlineHandler */ |
||||||
66 | // $onlineHandler = Newbb\Helper::getInstance()->getHandler('Online'); |
||||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
57% 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. ![]() |
|||||||
67 | $onlineHandler->init($forumObject); |
||||||
68 | } |
||||||
69 | |||||||
70 | $error_message = []; |
||||||
71 | |||||||
72 | if (Request::getString('contents_submit', '', 'POST')) { |
||||||
73 | $token_valid = $GLOBALS['xoopsSecurity']->check(); |
||||||
74 | |||||||
75 | $captcha_invalid = false; |
||||||
76 | if (!is_object($GLOBALS['xoopsUser']) && Request::hasVar('uname', 'POST') && Request::hasVar('pass', 'POST')) { |
||||||
77 | $uname = Request::getString('uname', '', 'POST'); |
||||||
78 | $pass = Request::getString('pass', '', 'POST'); |
||||||
79 | /** @var \XoopsMemberHandler $memberHandler */ |
||||||
80 | $memberHandler = xoops_getHandler('member'); |
||||||
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
![]() |
|||||||
81 | $user = $memberHandler->loginUser($uname, $pass); |
||||||
82 | if (is_object($user) && 0 < $user->getVar('level')) { |
||||||
83 | if (Request::getString('login', '', 'POST')) { |
||||||
84 | $user->setVar('last_login', time()); |
||||||
85 | if (!$memberHandler->insertUser($user)) { |
||||||
0 ignored issues
–
show
This
if statement is empty and can be removed.
This check looks for the bodies of These if (rand(1, 6) > 3) {
//print "Check failed";
} else {
print "Check succeeded";
}
could be turned into if (rand(1, 6) <= 3) {
print "Check succeeded";
}
This is much more concise to read. ![]() |
|||||||
86 | } |
||||||
87 | $_SESSION = []; |
||||||
88 | $_SESSION['xoopsUserId'] = $user->getVar('uid'); |
||||||
89 | $_SESSION['xoopsUserGroups'] = $user->getGroups(); |
||||||
90 | if ($GLOBALS['xoopsConfig']['use_mysession'] && '' !== $GLOBALS['xoopsConfig']['session_name']) { |
||||||
91 | setcookie($GLOBALS['xoopsConfig']['session_name'], session_id(), time() + (60 * $GLOBALS['xoopsConfig']['session_expire']), '/', '', 0); |
||||||
92 | } |
||||||
93 | $user_theme = $user->getVar('theme'); |
||||||
94 | if (in_array($user_theme, $GLOBALS['xoopsConfig']['theme_set_allowed'])) { |
||||||
95 | $_SESSION['xoopsUserTheme'] = $user_theme; |
||||||
96 | } |
||||||
97 | } |
||||||
98 | $GLOBALS['xoopsUser'] = $user; |
||||||
99 | $xoopsUserIsAdmin = $GLOBALS['xoopsUser']->isAdmin($xoopsModule->getVar('mid')); |
||||||
100 | } |
||||||
101 | } |
||||||
102 | if (!is_object($GLOBALS['xoopsUser'])) { |
||||||
103 | xoops_load('captcha'); |
||||||
0 ignored issues
–
show
The function
xoops_load 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
![]() |
|||||||
104 | $xoopsCaptcha = \XoopsCaptcha::getInstance(); |
||||||
0 ignored issues
–
show
The type
XoopsCaptcha was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
105 | if (!$xoopsCaptcha->verify()) { |
||||||
106 | $captcha_invalid = true; |
||||||
107 | $error_message[] = $xoopsCaptcha->getMessage(); |
||||||
108 | } |
||||||
109 | } |
||||||
110 | |||||||
111 | $isAdmin = newbbIsAdmin($forumObject); |
||||||
112 | |||||||
113 | $time_valid = true; |
||||||
114 | if (!$isAdmin && !empty($GLOBALS['xoopsModuleConfig']['post_timelimit'])) { |
||||||
115 | $last_post = newbbGetSession('LP'); |
||||||
116 | if (time() - $last_post < $GLOBALS['xoopsModuleConfig']['post_timelimit']) { |
||||||
117 | $time_valid = false; |
||||||
118 | } |
||||||
119 | } |
||||||
120 | |||||||
121 | if ($captcha_invalid || !$token_valid || !$time_valid) { |
||||||
122 | $_POST['contents_preview'] = 1; |
||||||
123 | $_POST['contents_submit'] = null; |
||||||
124 | $_POST['contents_upload'] = null; |
||||||
125 | if (!$token_valid) { |
||||||
126 | $error_message[] = _MD_NEWBB_INVALID_SUBMIT; |
||||||
127 | } |
||||||
128 | if (!$time_valid) { |
||||||
129 | $error_message[] = sprintf(_MD_NEWBB_POSTING_LIMITED, $GLOBALS['xoopsModuleConfig']['post_timelimit']); |
||||||
130 | } |
||||||
131 | } |
||||||
132 | } |
||||||
133 | |||||||
134 | if (Request::getString('contents_submit', '', 'POST')) { |
||||||
135 | $message = Request::getText('message', '', 'POST'); |
||||||
136 | if (empty($message)) { |
||||||
137 | // irmtfan - issue with javascript:history.go(-1) - add error message |
||||||
138 | redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 1, _MD_NEWBB_ERROR_BACK); |
||||||
139 | } |
||||||
140 | if (!empty($isedit) && $post_id > 0) { |
||||||
141 | $uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
||||||
142 | |||||||
143 | $topic_status = $topicObject->getVar('topic_status'); |
||||||
144 | if ($topicHandler->getPermission($forumObject, $topic_status, 'edit') |
||||||
0 ignored issues
–
show
This
if statement is empty and can be removed.
This check looks for the bodies of These if (rand(1, 6) > 3) {
//print "Check failed";
} else {
print "Check succeeded";
}
could be turned into if (rand(1, 6) <= 3) {
print "Check succeeded";
}
This is much more concise to read. ![]() |
|||||||
145 | && ($isAdmin |
||||||
146 | || ($postObject->checkTimelimit('edit_timelimit') |
||||||
147 | && $postObject->checkIdentity()))) { |
||||||
148 | } else { |
||||||
149 | redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?forum={$forum_id}&topic_id={$topic_id}&post_id={$post_id}&order={$order}&viewmode={$viewmode}", 2, _MD_NEWBB_NORIGHTTOEDIT); |
||||||
0 ignored issues
–
show
|
|||||||
150 | } |
||||||
151 | |||||||
152 | $delete_attach = Request::getArray('delete_attach', [], 'POST'); |
||||||
153 | if (is_array($delete_attach) && count($delete_attach) > 0) { |
||||||
154 | $postObject->deleteAttachment($delete_attach); |
||||||
155 | } |
||||||
156 | } else { |
||||||
157 | if ($topic_id) { |
||||||
158 | $topic_status = $topicObject->getVar('topic_status'); |
||||||
159 | if (!$topicHandler->getPermission($forumObject, $topic_status, 'reply')) { |
||||||
160 | redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?forum={$forum_id}&topic_id={$topic_id}&post_id={$post_id}&order={$order}&viewmode={$viewmode}", 2, _MD_NEWBB_NORIGHTTOREPLY); |
||||||
161 | } |
||||||
162 | } else { |
||||||
163 | $topic_status = 0; |
||||||
164 | if (!$topicHandler->getPermission($forumObject, $topic_status, 'post')) { |
||||||
165 | redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?forum={$forum_id}", 2, _MD_NEWBB_NORIGHTTOPOST); |
||||||
166 | } |
||||||
167 | } |
||||||
168 | |||||||
169 | $isreply = 0; |
||||||
170 | $isnew = 1; |
||||||
171 | if (!is_object($GLOBALS['xoopsUser']) |
||||||
172 | || (Request::getString('noname', '', 'POST') |
||||||
173 | && !empty($GLOBALS['xoopsModuleConfig']['allow_user_anonymous']))) { |
||||||
174 | $uid = 0; |
||||||
175 | } else { |
||||||
176 | $uid = $GLOBALS['xoopsUser']->getVar('uid'); |
||||||
177 | } |
||||||
178 | if (!empty($pid)) { |
||||||
179 | $postObject->setVar('pid', $pid); |
||||||
180 | } |
||||||
181 | if (!empty($topic_id)) { |
||||||
182 | $postObject->setVar('topic_id', $topic_id); |
||||||
183 | $isreply = 1; |
||||||
184 | } |
||||||
185 | $postObject->setVar('poster_ip', Xmf\IPAddress::fromRequest()->asReadable()); |
||||||
186 | $postObject->setVar('uid', $uid); |
||||||
187 | $postObject->setVar('post_time', time()); |
||||||
188 | } |
||||||
189 | |||||||
190 | $approved = $topicHandler->getPermission($forumObject, $topic_status, 'noapprove'); |
||||||
191 | $postObject->setVar('approved', $approved); |
||||||
192 | |||||||
193 | $postObject->setVar('forum_id', $forumObject->getVar('forum_id')); |
||||||
194 | |||||||
195 | $subject = xoops_trim(Request::getString('subject', '', 'POST')); |
||||||
0 ignored issues
–
show
The function
xoops_trim 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
![]() |
|||||||
196 | $subject = ('' === $subject) ? _NOTITLE : $subject; |
||||||
0 ignored issues
–
show
|
|||||||
197 | $poster_name = xoops_trim(Request::getString('poster_name', '', 'POST')); |
||||||
198 | $dohtml = Request::getInt('dohtml', 0, 'POST') |
||||||
199 | && $topicHandler->getPermission($forumObject, $topic_status, 'html'); |
||||||
200 | $dosmiley = Request::getInt('dosmiley', 0, 'POST'); |
||||||
201 | $doxcode = Request::getInt('doxcode', 0, 'POST') ? 1 : 0; |
||||||
202 | $dobr = Request::getInt('dobr', 0, 'POST') ? 1 : 0; |
||||||
203 | $icon = (Request::getString('icon', '', 'POST') |
||||||
204 | && is_file($GLOBALS['xoops']->path('images/subject/' . Request::getString('icon', '', 'POST'))) ? Request::getString('icon', '', 'POST') : ''); |
||||||
205 | $attachsig = Request::getBool('attachsig', false, 'POST') |
||||||
206 | && $topicHandler->getPermission($forumObject, $topic_status, 'signature'); |
||||||
207 | $view_require = Request::getString('view_require', '', 'POST'); |
||||||
208 | $post_karma = ('require_karma' === $view_require) ? Request::getInt('post_karma', 0, 'POST') : 0; |
||||||
209 | $require_reply = ('require_reply' === $view_require); |
||||||
210 | $postObject->setVar('subject', $subject); |
||||||
211 | $editwhy = xoops_trim(Request::getString('editwhy', '', 'POST')); // !empty($_POST['editwhy'])) ? xoops_trim($_POST['editwhy']) : ""; |
||||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
76% 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. ![]() |
|||||||
212 | |||||||
213 | if ($dohtml && !newbbIsAdmin($forumObject)) { |
||||||
0 ignored issues
–
show
This
if statement is empty and can be removed.
This check looks for the bodies of These if (rand(1, 6) > 3) {
//print "Check failed";
} else {
print "Check succeeded";
}
could be turned into if (rand(1, 6) <= 3) {
print "Check succeeded";
}
This is much more concise to read. ![]() |
|||||||
214 | //$message=newbb_textFilter($message); |
||||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
72% 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. ![]() |
|||||||
215 | } |
||||||
216 | $postObject->setVar('post_text', $message); |
||||||
217 | $postObject->setVar('post_karma', $post_karma); |
||||||
218 | $postObject->setVar('require_reply', $require_reply); |
||||||
219 | $postObject->setVar('poster_name', $poster_name); |
||||||
220 | $postObject->setVar('dohtml', $dohtml); |
||||||
221 | $postObject->setVar('dosmiley', $dosmiley); |
||||||
222 | $postObject->setVar('doxcode', $doxcode); |
||||||
223 | $postObject->setVar('dobr', $dobr); |
||||||
224 | $postObject->setVar('icon', $icon); |
||||||
225 | $postObject->setVar('attachsig', $attachsig); |
||||||
226 | $postObject->setAttachment(); |
||||||
227 | if (!empty($post_id)) { |
||||||
228 | $postObject->setPostEdit($poster_name, $editwhy); |
||||||
229 | } // is reply |
||||||
230 | |||||||
231 | // $attachments_tmp = array(); |
||||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
56% 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. ![]() |
|||||||
232 | // if (!empty($_POST["attachments_tmp"])) { |
||||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
80% 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. ![]() |
|||||||
233 | if (Request::getString('attachments_tmp', '', 'POST')) { |
||||||
234 | $attachments_tmp = unserialize(base64_decode(Request::getString('attachments_tmp', '', 'POST'))); |
||||||
235 | if (Request::getArray('delete_tmp', null, 'POST') && count(Request::getArray('delete_tmp', null, 'POST')) > 1) { |
||||||
236 | foreach (Request::getArray('delete_tmp', null, 'POST') as $key) { |
||||||
237 | unlink($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $attachments_tmp[$key][0])); |
||||||
238 | unset($attachments_tmp[$key]); |
||||||
239 | } |
||||||
240 | } |
||||||
241 | } |
||||||
242 | if (isset($attachments_tmp) && count($attachments_tmp)) { |
||||||
243 | foreach ($attachments_tmp as $key => $attach) { |
||||||
244 | if (rename(XOOPS_CACHE_PATH . '/' . $attachments_tmp[$key][0], $GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $attachments_tmp[$key][0]))) { |
||||||
0 ignored issues
–
show
|
|||||||
245 | $postObject->setAttachment($attach[0], $attach[1], $attach[2]); |
||||||
246 | } |
||||||
247 | } |
||||||
248 | } |
||||||
249 | $error_upload = ''; |
||||||
250 | |||||||
251 | if (isset($_FILES['userfile']['name']) && '' !== $_FILES['userfile']['name'] |
||||||
252 | && $topicHandler->getPermission($forumObject, $topic_status, 'attach')) { |
||||||
253 | // require_once $GLOBALS['xoops']->path('modules/' . $xoopsModule->getVar('dirname', 'n') . '/class/uploader.php'); |
||||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
63% 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. ![]() |
|||||||
254 | $maxfilesize = $forumObject->getVar('attach_maxkb') * 1024; |
||||||
255 | $uploaddir = XOOPS_CACHE_PATH; |
||||||
256 | |||||||
257 | $uploader = new Newbb\Uploader($uploaddir, $forumObject->getVar('attach_ext'), (int)$maxfilesize, (int)$GLOBALS['xoopsModuleConfig']['max_img_width'], (int)$GLOBALS['xoopsModuleConfig']['max_img_height']); |
||||||
258 | |||||||
259 | if ($_FILES['userfile']['error'] > 0) { |
||||||
260 | switch ($_FILES['userfile']['error']) { |
||||||
261 | case 1: |
||||||
262 | $error_message[] = _MD_NEWBB_MAXUPLOADFILEINI; |
||||||
263 | break; |
||||||
264 | case 2: |
||||||
265 | $error_message[] = sprintf(_MD_NEWBB_MAXKB, $forumObject->getVar('attach_maxkb')); |
||||||
266 | break; |
||||||
267 | default: |
||||||
268 | $error_message[] = _MD_NEWBB_UPLOAD_ERRNODEF; |
||||||
269 | break; |
||||||
270 | } |
||||||
271 | } else { |
||||||
272 | $uploader->setCheckMediaTypeByExt(); |
||||||
273 | $temp = Request::getArray('xoops_upload_file', [], 'POST'); |
||||||
274 | if ($uploader->fetchMedia($temp[0])) { |
||||||
275 | $prefix = is_object($GLOBALS['xoopsUser']) ? (string)$GLOBALS['xoopsUser']->uid() . '_' : 'newbb_'; |
||||||
276 | $uploader->setPrefix($prefix); |
||||||
277 | if (!$uploader->upload()) { |
||||||
278 | $error_message[] = $error_upload = $uploader->getErrors(); |
||||||
279 | } else { |
||||||
280 | if (is_file($uploader->getSavedDestination())) { |
||||||
281 | if (rename(XOOPS_CACHE_PATH . '/' . $uploader->getSavedFileName(), $GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $uploader->getSavedFileName()))) { |
||||||
282 | $postObject->setAttachment($uploader->getSavedFileName(), $uploader->getMediaName(), $uploader->getMediaType()); |
||||||
283 | } |
||||||
284 | } |
||||||
285 | } |
||||||
286 | } else { |
||||||
287 | $error_message[] = $error_upload = $uploader->getErrors(); |
||||||
288 | } |
||||||
289 | } |
||||||
290 | } |
||||||
291 | |||||||
292 | $postid = $postHandler->insert($postObject); |
||||||
293 | |||||||
294 | if (!$postid) { |
||||||
295 | require_once $GLOBALS['xoops']->path('header.php'); |
||||||
296 | xoops_error($postObject->getErrors()); |
||||||
0 ignored issues
–
show
The function
xoops_error 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
![]() |
|||||||
297 | require_once $GLOBALS['xoops']->path('footer.php'); |
||||||
298 | } |
||||||
299 | newbbSetSession('LP', time()); // Recording last post time |
||||||
300 | $topicObject = $topicHandler->get($postObject->getVar('topic_id')); |
||||||
301 | $uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
||||||
302 | if (newbbIsAdmin($forumObject) |
||||||
303 | || ($topicHandler->getPermission($forumObject, $topic_status, 'type') |
||||||
304 | && (0 == $topic_id |
||||||
305 | || $uid == $topicObject->getVar('topic_poster')))) { |
||||||
306 | $topicObject->setVar('type_id', Request::getInt('type_id', 0, 'POST')); |
||||||
307 | } |
||||||
308 | |||||||
309 | if (!empty($GLOBALS['xoopsModuleConfig']['do_tag']) && $postObject->isTopic()) { |
||||||
310 | $topicObject->setVar('topic_tags', Request::getInt('topic_tags', 0, 'POST')); |
||||||
311 | } |
||||||
312 | $topicHandler->insert($topicObject); |
||||||
313 | |||||||
314 | // Set read mark |
||||||
315 | if (!empty($isnew)) { |
||||||
316 | require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.read.php'); |
||||||
317 | newbbSetRead('topic', $topicObject->getVar('topic_id'), $postid); |
||||||
318 | if (!$postObject->getVar('pid')) { |
||||||
319 | newbbSetRead('forum', $forumObject->getVar('forum_id'), $postid); |
||||||
320 | } |
||||||
321 | } |
||||||
322 | |||||||
323 | //$postObject->loadFilters(empty($isnew) ? 'update' : 'insert'); |
||||||
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. ![]() |
|||||||
324 | |||||||
325 | // Define tags for notification message |
||||||
326 | if (!empty($isnew) && $approved && !empty($GLOBALS['xoopsModuleConfig']['notification_enabled'])) { |
||||||
327 | $tags = []; |
||||||
328 | $tags['THREAD_NAME'] = Request::getString('subject', '', 'POST'); |
||||||
329 | $tags['THREAD_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/viewtopic.php?post_id=' . $postid; |
||||||
330 | $tags['POST_URL'] = $tags['THREAD_URL']; // . '#forumpost' . $postid; |
||||||
331 | require_once __DIR__ . '/include/notification.inc.php'; |
||||||
332 | $forum_info = newbb_notify_iteminfo('forum', $forumObject->getVar('forum_id')); |
||||||
333 | $tags['FORUM_NAME'] = $forum_info['name']; |
||||||
334 | $tags['FORUM_URL'] = $forum_info['url']; |
||||||
335 | /** @var \XoopsNotificationHandler $notificationHandler */ |
||||||
336 | $notificationHandler = xoops_getHandler('notification'); |
||||||
337 | if (empty($isreply)) { |
||||||
338 | // Notify of new thread |
||||||
339 | $notificationHandler->triggerEvent('forum', $forumObject->getVar('forum_id'), 'new_thread', $tags); |
||||||
340 | } else { |
||||||
341 | // Notify of new post |
||||||
342 | $notificationHandler->triggerEvent('thread', $topic_id, 'new_post', $tags); |
||||||
343 | $_tags['name'] = $tags['THREAD_NAME']; |
||||||
344 | $_tags['url'] = $tags['POST_URL']; |
||||||
345 | $_tags['uid'] = $uid; |
||||||
346 | $notificationHandler->triggerEvent('thread', $topic_id, 'post', $_tags); |
||||||
347 | } |
||||||
348 | $notificationHandler->triggerEvent('global', 0, 'new_post', $tags); |
||||||
349 | $notificationHandler->triggerEvent('forum', $forumObject->getVar('forum_id'), 'new_post', $tags); |
||||||
350 | $tags['POST_CONTENT'] = Request::getString('message', '', 'POST'); |
||||||
351 | $tags['POST_NAME'] = Request::getString('subject', '', 'POST'); |
||||||
352 | $notificationHandler->triggerEvent('global', 0, 'new_fullpost', $tags); |
||||||
353 | $notificationHandler->triggerEvent('forum', $forumObject->getVar('forum_id'), 'new_fullpost', $tags); |
||||||
354 | } |
||||||
355 | |||||||
356 | // If user checked notification box, subscribe them to the |
||||||
357 | // appropriate event; if unchecked, then unsubscribe |
||||||
358 | if (!empty($GLOBALS['xoopsUser']) && !empty($GLOBALS['xoopsModuleConfig']['notification_enabled'])) { |
||||||
359 | $notificationHandler = xoops_getHandler('notification'); |
||||||
360 | if (!Request::getInt('notify', 0, 'POST')) { |
||||||
361 | $notificationHandler->unsubscribe('thread', $postObject->getVar('topic_id'), 'new_post'); |
||||||
362 | } elseif (Request::getInt('notify', 0, 'POST') > 0) { |
||||||
363 | $notificationHandler->subscribe('thread', $postObject->getVar('topic_id'), 'new_post'); |
||||||
364 | } |
||||||
365 | // elseif ($_POST['notify']<0) keep it as it is |
||||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
43% 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. ![]() |
|||||||
366 | } |
||||||
367 | |||||||
368 | if ($approved) { |
||||||
369 | if (!empty($GLOBALS['xoopsModuleConfig']['cache_enabled'])) { |
||||||
370 | newbbSetSession('t' . $postObject->getVar('topic_id'), null); |
||||||
371 | } |
||||||
372 | // Update user |
||||||
373 | if ($uid > 0) { |
||||||
374 | $sql = 'SELECT count(*)' . ' FROM ' . $GLOBALS['xoopsDB']->prefix('newbb_topics') . ' WHERE approved=1 AND topic_poster =' . $uid; |
||||||
375 | $ret = $GLOBALS['xoopsDB']->query($sql); |
||||||
376 | list($topics) = $GLOBALS['xoopsDB']->fetchRow($ret); |
||||||
377 | |||||||
378 | $sql = ' SELECT count(*)' . ' FROM ' . $GLOBALS['xoopsDB']->prefix('newbb_topics') . ' WHERE approved=1 AND topic_digest > 0 AND topic_poster =' . $uid; |
||||||
379 | $ret = $GLOBALS['xoopsDB']->query($sql); |
||||||
380 | list($digests) = $GLOBALS['xoopsDB']->fetchRow($ret); |
||||||
381 | |||||||
382 | $sql = ' SELECT count(*), MAX(post_time)' . ' FROM ' . $GLOBALS['xoopsDB']->prefix('newbb_posts') . ' WHERE approved=1 AND uid =' . $uid; |
||||||
383 | $ret = $GLOBALS['xoopsDB']->query($sql); |
||||||
384 | list($posts, $lastpost) = $GLOBALS['xoopsDB']->fetchRow($ret); |
||||||
385 | |||||||
386 | $GLOBALS['xoopsDB']->queryF(' REPLACE INTO ' . $GLOBALS['xoopsDB']->prefix('newbb_user_stats') . " SET uid = '{$uid}', user_topics = '{$topics}', user_posts = '{$posts}', user_digests = '{$digests}', user_lastpost = '{$lastpost}'"); |
||||||
387 | } |
||||||
388 | |||||||
389 | $redirect = XOOPS_URL . '/modules/newbb/viewtopic.php?post_id=' . $postid; |
||||||
390 | $message = _MD_NEWBB_THANKSSUBMIT . '<br>' . $error_upload; |
||||||
391 | } else { |
||||||
392 | $redirect = XOOPS_URL . '/modules/newbb/viewforum.php?forum=' . $postObject->getVar('forum_id'); |
||||||
393 | $message = _MD_NEWBB_THANKSSUBMIT . '<br>' . _MD_NEWBB_WAITFORAPPROVAL . '<br>' . $error_upload; |
||||||
394 | } |
||||||
395 | |||||||
396 | if ('add' === $op) { |
||||||
397 | redirect_header(XOOPS_URL . '/modules/newbb/polls.php?op=add&forum=' . $postObject->getVar('forum_id') . '&topic_id=' . $postObject->getVar('topic_id'), 1, _MD_NEWBB_ADDPOLL); |
||||||
398 | } else { |
||||||
399 | redirect_header($redirect, 2, $message); |
||||||
400 | } |
||||||
401 | } |
||||||
402 | |||||||
403 | $xoopsOption['template_main'] = 'newbb_edit_post.tpl'; |
||||||
404 | $GLOBALS['xoopsConfig']['module_cache'][$xoopsModule->getVar('mid')] = 0; |
||||||
405 | // irmtfan remove and move to footer.php |
||||||
406 | //$xoopsOption['xoops_module_header']= $xoops_module_header; |
||||||
407 | // irmtfan include header.php after defining $xoopsOption['template_main'] |
||||||
408 | require_once $GLOBALS['xoops']->path('header.php'); |
||||||
409 | //$xoopsTpl->assign('xoops_module_header', $xoops_module_header); |
||||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
80% 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. ![]() |
|||||||
410 | |||||||
411 | if (Request::getString('contents_upload', null, 'POST')) { |
||||||
412 | $attachments_tmp = []; |
||||||
413 | if (Request::getArray('attachments_tmp', null, 'POST')) { |
||||||
414 | $attachments_tmp = unserialize(base64_decode(Request::getArray('attachments_tmp', [], 'POST'))); |
||||||
0 ignored issues
–
show
Xmf\Request::getArray('a..._tmp', array(), 'POST') of type array is incompatible with the type string expected by parameter $data of base64_decode() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
415 | if (Request::getArray('delete_tmp', null, 'POST') && count(Request::getArray('delete_tmp', null, 'POST'))) { |
||||||
416 | foreach (Request::getArray('delete_tmp', '', 'POST') as $key) { |
||||||
417 | unlink($uploaddir = $GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $attachments_tmp[$key][0])); |
||||||
418 | unset($attachments_tmp[$key]); |
||||||
419 | } |
||||||
420 | } |
||||||
421 | } |
||||||
422 | |||||||
423 | $error_upload = ''; |
||||||
424 | if (isset($_FILES['userfile']['name']) && '' !== $_FILES['userfile']['name']) { |
||||||
425 | // require_once $GLOBALS['xoops']->path('modules/' . $xoopsModule->getVar('dirname', 'n') . '/class/uploader.php'); |
||||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
63% 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. ![]() |
|||||||
426 | $maxfilesize = $forumObject->getVar('attach_maxkb') * 1024; |
||||||
427 | $uploaddir = XOOPS_CACHE_PATH; |
||||||
428 | |||||||
429 | $uploader = new Newbb\Uploader($uploaddir, $forumObject->getVar('attach_ext'), (int)$maxfilesize, (int)$GLOBALS['xoopsModuleConfig']['max_img_width'], (int)$GLOBALS['xoopsModuleConfig']['max_img_height']); |
||||||
430 | if ($_FILES['userfile']['error'] > 0) { |
||||||
431 | switch ($_FILES['userfile']['error']) { |
||||||
432 | case 1: |
||||||
433 | $error_message[] = _MD_NEWBB_MAXUPLOADFILEINI; |
||||||
434 | break; |
||||||
435 | case 2: |
||||||
436 | $error_message[] = sprintf(_MD_NEWBB_MAXKB, $forumObject->getVar('attach_maxkb')); |
||||||
437 | break; |
||||||
438 | default: |
||||||
439 | $error_message[] = _MD_NEWBB_UPLOAD_ERRNODEF; |
||||||
440 | break; |
||||||
441 | } |
||||||
442 | } else { |
||||||
443 | $uploader->setCheckMediaTypeByExt(); |
||||||
444 | $temp = Request::getArray('xoops_upload_file', [], 'POST'); |
||||||
445 | if ($uploader->fetchMedia($temp[0])) { |
||||||
446 | $prefix = is_object($GLOBALS['xoopsUser']) ? (string)$GLOBALS['xoopsUser']->uid() . '_' : 'newbb_'; |
||||||
447 | $uploader->setPrefix($prefix); |
||||||
448 | if (!$uploader->upload()) { |
||||||
449 | $error_message[] = $error_upload = $uploader->getErrors(); |
||||||
450 | } else { |
||||||
451 | if (is_file($uploader->getSavedDestination())) { |
||||||
452 | $attachments_tmp[(string)time()] = [ |
||||||
453 | $uploader->getSavedFileName(), |
||||||
454 | $uploader->getMediaName(), |
||||||
455 | $uploader->getMediaType() |
||||||
456 | ]; |
||||||
457 | } |
||||||
458 | } |
||||||
459 | } else { |
||||||
460 | $error_message[] = $error_upload = $uploader->getErrors(); |
||||||
461 | } |
||||||
462 | } |
||||||
463 | } |
||||||
464 | } |
||||||
465 | |||||||
466 | if (Request::getString('contents_preview', Request::getString('contents_preview', '', 'POST'), 'GET')) { |
||||||
467 | if (Request::getString('attachments_tmp', '', 'POST')) { |
||||||
468 | $attachments_tmp = unserialize(base64_decode(Request::getString('attachments_tmp', '', 'POST'))); |
||||||
469 | } |
||||||
470 | |||||||
471 | $p_subject = $myts->htmlSpecialChars(Request::getString('subject', '', 'POST')); |
||||||
472 | $dosmiley = Request::getInt('dosmiley', 0, 'POST'); |
||||||
473 | $dohtml = Request::getInt('dohtml', 0, 'POST'); |
||||||
474 | $doxcode = Request::getInt('doxcode', 0, 'POST'); |
||||||
475 | $dobr = Request::getInt('dobr', 0, 'POST'); |
||||||
476 | $p_message = Request::getString('message', '', 'POST'); |
||||||
477 | $p_message = $myts->previewTarea($p_message, $dohtml, $dosmiley, $doxcode, 1, $dobr); |
||||||
478 | $p_date = formatTimestamp(time()); |
||||||
0 ignored issues
–
show
The function
formatTimestamp 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
![]() |
|||||||
479 | if ($postObject->isNew()) { |
||||||
480 | if (is_object($GLOBALS['xoopsUser'])) { |
||||||
481 | $p_name = $GLOBALS['xoopsUser']->getVar('uname'); |
||||||
482 | if (!empty($GLOBALS['xoopsModuleConfig']['show_realname']) && $GLOBALS['xoopsUser']->getVar('name')) { |
||||||
483 | $p_name = $GLOBALS['xoopsUser']->getVar('name'); |
||||||
484 | } |
||||||
485 | } |
||||||
486 | } elseif ($postObject->getVar('uid')) { |
||||||
487 | $p_name = newbbGetUnameFromId($postObject->getVar('uid'), $GLOBALS['xoopsModuleConfig']['show_realname']); |
||||||
488 | } |
||||||
489 | if (empty($p_name)) { |
||||||
490 | $p_name = Request::getString('poster_name', '', 'POST') ? htmlspecialchars(Request::getString('poster_name', '', 'POST'), ENT_QUOTES | ENT_HTML5) : htmlspecialchars($GLOBALS['xoopsConfig']['anonymous'], ENT_QUOTES | ENT_HTML5); |
||||||
491 | } |
||||||
492 | |||||||
493 | $post_preview = [ |
||||||
494 | 'subject' => $p_subject, |
||||||
495 | 'meta' => _MD_NEWBB_BY . ' ' . $p_name . ' ' . _MD_NEWBB_ON . ' ' . $p_date, |
||||||
496 | 'content' => $p_message |
||||||
497 | ]; |
||||||
498 | $xoopsTpl->assign_by_ref('post_preview', $post_preview); |
||||||
499 | } |
||||||
500 | |||||||
501 | if (Request::getString('contents_upload', null, 'POST') || Request::getString('contents_preview', null, 'POST') |
||||||
502 | || Request::getString('contents_preview', null, 'GET') |
||||||
503 | || Request::getString('editor', '', 'POST')) { |
||||||
504 | $editor = Request::getString('editor', '', 'POST'); |
||||||
505 | $dosmiley = Request::getInt('dosmiley', 0, 'POST'); |
||||||
506 | $dohtml = Request::getInt('dohtml', 0, 'POST'); |
||||||
507 | $doxcode = Request::getInt('doxcode', 0, 'POST'); |
||||||
508 | $dobr = Request::getInt('dobr', 0, 'POST'); |
||||||
509 | $subject = Request::getString('subject', '', 'POST'); |
||||||
510 | $message = Request::getString('message', '', 'POST'); |
||||||
511 | $poster_name = Request::getString('poster_name', '', 'POST'); |
||||||
512 | $hidden = Request::getString('hidden', '', 'POST'); |
||||||
513 | $notify = Request::getInt('notify', 0, 'POST'); |
||||||
514 | $attachsig = Request::getInt('attachsig', 0, 'POST');//!empty($_POST['attachsig']) ? 1 : 0; |
||||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
77% 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. ![]() |
|||||||
515 | $isreply = Request::getInt('isreply', 0, 'POST'); //!empty($_POST['isreply']) ? 1 : 0; |
||||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
77% 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. ![]() |
|||||||
516 | $isedit = Request::getInt('isedit', 0, 'POST'); //!empty($_POST['isedit']) ? 1 : 0; |
||||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
77% 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. ![]() |
|||||||
517 | $icon = (Request::getString('icon', '', 'POST') |
||||||
518 | && is_file($GLOBALS['xoops']->path('images/subject/' . Request::getString('icon', '', 'POST'))) ? Request::getString('icon', '', 'POST') : ''); |
||||||
519 | $view_require = Request::getString('view_require', '', 'POST'); |
||||||
520 | $post_karma = (('require_karma' === $view_require) |
||||||
521 | && !Request::getInt('post_karma', 0, 'POST')) ? Request::getInt('post_karma', 0, 'POST') : 0; |
||||||
522 | $require_reply = ('require_reply' === $view_require) ? 1 : 0; |
||||||
523 | |||||||
524 | if (!Request::getString('contents_upload', '', 'POST')) { |
||||||
525 | $contents_preview = 1; |
||||||
526 | } |
||||||
527 | $attachments = $postObject->getAttachment(); |
||||||
528 | $xoopsTpl->assign('error_message', implode('<br>', $error_message)); |
||||||
529 | |||||||
530 | include __DIR__ . '/include/form.post.php'; |
||||||
531 | } |
||||||
532 | // irmtfan move to footer.php |
||||||
533 | require_once __DIR__ . '/footer.php'; |
||||||
534 | include $GLOBALS['xoops']->path('footer.php'); |
||||||
535 |