Issues (340)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  Header Injection
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.
1
<?php declare(strict_types=1);
2
3
/**
4
 * Newbb module
5
 *
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 *
13
 * @copyright       XOOPS Project (https://xoops.org)
14
 * @license         GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
15
 * @since           4.0
16
 * @author          Taiwen Jiang <[email protected]>
17
 */
18
19
use Xmf\Request;
20
use XoopsModules\Newbb\{
21
    Uploader,
22
    Forum,
23
    ForumHandler,
24
    TopicHandler,
25
    OnlineHandler,
26
    Post,
27
    PostHandler
28
};
29
30
/** @var ForumHandler $forumHandler */
31
/** @var TopicHandler $topicHandler */
32
/** @var OnlineHandler $onlineHandler */
33
/** @var PostHandler $postHandler */
34
/** @var Post $postObject */
35
require_once __DIR__ . '/header.php';
36
37
foreach (
38
    [
39
        'forum',
40
        'topic_id',
41
        'post_id',
42
        'order',
43
        'pid',
44
        'start',
45
        'isreply',
46
        'isedit',
47
    ] as $getint
48
) {
49
    ${$getint} = Request::getInt($getint, 0, 'POST');
50
}
51
$token_valid = false;
52
$op          = Request::getCmd('op', '', 'POST');
53
$viewmode    = ('flat' !== Request::getString('viewmode', '', 'POST')) ? 'thread' : 'flat';
54
if (empty($forum)) {
55
    redirect_header('index.php', 2, _MD_NEWBB_ERRORFORUM);
56
}
57
58
//$forumHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Forum');
59
//$topicHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Topic');
60
//$postHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Post');
61
62
/** @var Post $postObject */
63
$postObject = null;
64
65
if (!empty($isedit) && $post_id > 0) {
66
    $postObject = $postHandler->get($post_id);
67
    $topic_id   = $postObject->getVar('topic_id');
68
} else {
69
    $postObject = $postHandler->create();
70
}
71
$topicObject = $topicHandler->get($topic_id);
72
$forum_id    = $topic_id ? $topicObject->getVar('forum_id') : $forum;
73
/** @var Forum $forumObject */
74
$forumObject = $forumHandler->get($forum_id);
75
if (!$forumHandler->getPermission($forumObject)) {
76
    redirect_header('index.php', 2, _NOPERM);
77
}
78
79
if ($GLOBALS['xoopsModuleConfig']['wol_enabled']) {
80
    //    $onlineHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Online');
81
    $onlineHandler->init($forumObject);
82
}
83
84
$error_message = [];
85
86
$isAdmin = null;
87
if (Request::getString('contents_submit', '', 'POST')) {
88
    $token_valid = $GLOBALS['xoopsSecurity']->check();
89
90
    $captcha_invalid = false;
91
    if (!is_object($GLOBALS['xoopsUser']) && Request::hasVar('uname', 'POST') && Request::hasVar('pass', 'POST')) {
92
        $uname = Request::getString('uname', '', 'POST');
93
        $pass  = Request::getString('pass', '', 'POST');
94
        /** @var \XoopsMemberHandler $memberHandler */
95
        $memberHandler = xoops_getHandler('member');
96
        $user          = $memberHandler->loginUser($uname, $pass);
97
        if (is_object($user) && $user->getVar('level') > 0) {
98
            if (Request::getString('login', '', 'POST')) {
99
                $user->setVar('last_login', time());
100
                if (!$memberHandler->insertUser($user)) {
101
                }
102
                $_SESSION                    = [];
103
                $_SESSION['xoopsUserId']     = $user->getVar('uid');
104
                $_SESSION['xoopsUserGroups'] = $user->getGroups();
105
                if ($GLOBALS['xoopsConfig']['use_mysession'] && '' !== $GLOBALS['xoopsConfig']['session_name']) {
106
                    setcookie($GLOBALS['xoopsConfig']['session_name'], session_id(), ['expires' => time() + (60 * $GLOBALS['xoopsConfig']['session_expire']), 'path' => '/', 'domain' => '', 'secure' => 0]);
107
                }
108
                $user_theme = $user->getVar('theme');
109
                if (in_array($user_theme, $GLOBALS['xoopsConfig']['theme_set_allowed'], true)) {
110
                    $_SESSION['xoopsUserTheme'] = $user_theme;
111
                }
112
            }
113
            $GLOBALS['xoopsUser'] = $user;
114
            $xoopsUserIsAdmin     = $GLOBALS['xoopsUser']->isAdmin($xoopsModule->getVar('mid'));
115
        }
116
    }
117
    if (!is_object($GLOBALS['xoopsUser'])) {
118
        xoops_load('captcha');
119
        $xoopsCaptcha = \XoopsCaptcha::getInstance();
120
        if (!$xoopsCaptcha->verify()) {
121
            $captcha_invalid = true;
122
            $error_message[] = $xoopsCaptcha->getMessage();
123
        }
124
    }
125
126
    $isAdmin = newbbIsAdmin($forumObject);
127
128
    $time_valid = true;
129
    if (!$isAdmin && !empty($GLOBALS['xoopsModuleConfig']['post_timelimit'])) {
130
        $last_post = newbbGetSession('LP');
131
        if (time() - $last_post < $GLOBALS['xoopsModuleConfig']['post_timelimit']) {
132
            $time_valid = false;
133
        }
134
    }
135
136
    if ($captcha_invalid || !$token_valid || !$time_valid) {
137
        $_POST['contents_preview'] = 1;
138
        $_POST['contents_submit']  = null;
139
        $_POST['contents_upload']  = null;
140
        if (!$token_valid) {
141
            $error_message[] = _MD_NEWBB_INVALID_SUBMIT;
142
        }
143
        if (!$time_valid) {
144
            $error_message[] = sprintf(_MD_NEWBB_POSTING_LIMITED, $GLOBALS['xoopsModuleConfig']['post_timelimit']);
145
        }
146
    }
147
}
148
149
$_tags = null;
150
$attachments_tmp = null;
151
if (Request::getString('contents_submit', '', 'POST')) {
152
    $message = Request::getText('message', '', 'POST');
153
    if (empty($message)) {
154
        // irmtfan - issue with javascript:history.go(-1) - add error message
155
        redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 1, _MD_NEWBB_ERROR_BACK);
156
    }
157
    if (!empty($isedit) && $post_id > 0) {
158
        $uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
159
160
        $topic_status = $topicObject->getVar('topic_status');
161
        /** @var Post $postObject */
162
        if ($topicHandler->getPermission($forumObject, $topic_status, 'edit')
163
            && ($isAdmin
164
                || ($postObject->checkTimelimit('edit_timelimit')
165
                    && $postObject->checkIdentity()))) {
166
        } else {
167
            redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?forum={$forum_id}&amp;topic_id={$topic_id}&amp;post_id={$post_id}&amp;order={$order}&amp;viewmode={$viewmode}", 2, _MD_NEWBB_NORIGHTTOEDIT);
168
        }
169
170
        $delete_attach = Request::getArray('delete_attach', [], 'POST');
171
        if ($delete_attach && is_array($delete_attach)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $delete_attach of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
172
            $postObject->deleteAttachment($delete_attach);
173
        }
174
    } else {
175
        if ($topic_id) {
176
            $topic_status = $topicObject->getVar('topic_status');
177
            if (!$topicHandler->getPermission($forumObject, $topic_status, 'reply')) {
178
                redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?forum={$forum_id}&amp;topic_id={$topic_id}&amp;post_id={$post_id}&amp;order={$order}&amp;viewmode={$viewmode}", 2, _MD_NEWBB_NORIGHTTOREPLY);
179
            }
180
        } else {
181
            $topic_status = 0;
182
            if (!$topicHandler->getPermission($forumObject, $topic_status, 'post')) {
183
                redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?forum={$forum_id}", 2, _MD_NEWBB_NORIGHTTOPOST);
184
            }
185
        }
186
187
        $isreply = 0;
188
        $isnew   = 1;
189
        if (!is_object($GLOBALS['xoopsUser'])
190
            || (Request::getString('noname', '', 'POST')
191
                && !empty($GLOBALS['xoopsModuleConfig']['allow_user_anonymous']))) {
192
            $uid = 0;
193
        } else {
194
            $uid = $GLOBALS['xoopsUser']->getVar('uid');
195
        }
196
        if (!empty($pid)) {
197
            $postObject->setVar('pid', $pid);
198
        }
199
        if (!empty($topic_id)) {
200
            $postObject->setVar('topic_id', $topic_id);
201
            $isreply = 1;
202
        }
203
        $postObject->setVar('poster_ip', Xmf\IPAddress::fromRequest()->asReadable());
204
        $postObject->setVar('uid', $uid);
205
        $postObject->setVar('post_time', time());
206
    }
207
208
    $approved = $topicHandler->getPermission($forumObject, $topic_status, 'noapprove');
209
    $postObject->setVar('approved', $approved);
210
211
    $postObject->setVar('forum_id', $forumObject->getVar('forum_id'));
212
213
    $subject       = xoops_trim(Request::getString('subject', '', 'POST'));
214
    $subject       = ('' === $subject) ? _NOTITLE : $subject;
215
    $poster_name   = xoops_trim(Request::getString('poster_name', '', 'POST'));
216
    $dohtml        = Request::getInt('dohtml', 0, 'POST')
217
                     && $topicHandler->getPermission($forumObject, $topic_status, 'html');
218
    $dosmiley      = Request::getInt('dosmiley', 0, 'POST');
219
    $doxcode       = Request::getInt('doxcode', 0, 'POST') ? 1 : 0;
220
    $dobr          = Request::getInt('dobr', 0, 'POST') ? 1 : 0;
221
    $icon          = (Request::getString('icon', '', 'POST')
222
                      && is_file($GLOBALS['xoops']->path('images/subject/' . Request::getString('icon', '', 'POST'))) ? Request::getString('icon', '', 'POST') : '');
223
    $attachsig     = Request::getBool('attachsig', false, 'POST')
224
                     && $topicHandler->getPermission($forumObject, $topic_status, 'signature');
225
    $view_require  = Request::getString('view_require', '', 'POST');
226
    $post_karma    = ('require_karma' === $view_require) ? Request::getInt('post_karma', 0, 'POST') : 0;
227
    $require_reply = ('require_reply' === $view_require);
228
    $postObject->setVar('subject', $subject);
229
    $editwhy = xoops_trim(Request::getString('editwhy', '', 'POST')); // !empty($_POST['editwhy'])) ? xoops_trim($_POST['editwhy']) : "";
230
231
    if ($dohtml && !newbbIsAdmin($forumObject)) {
232
        //$message=newbb_textFilter($message);
233
    }
234
    $postObject->setVar('post_text', $message);
235
    $postObject->setVar('post_karma', $post_karma);
236
    $postObject->setVar('require_reply', $require_reply);
237
    $postObject->setVar('poster_name', $poster_name);
238
    $postObject->setVar('dohtml', $dohtml);
239
    $postObject->setVar('dosmiley', $dosmiley);
240
    $postObject->setVar('doxcode', $doxcode);
241
    $postObject->setVar('dobr', $dobr);
242
    $postObject->setVar('icon', $icon);
243
    $postObject->setVar('attachsig', $attachsig);
244
    $postObject->setAttachment();
245
    if (!empty($post_id)) {
246
        $postObject->setPostEdit($poster_name, $editwhy);
247
    } // is reply
248
249
    //    $attachments_tmp = [];
250
    //    if (!empty($_POST["attachments_tmp"])) {
251
    if (Request::getString('attachments_tmp', '', 'POST')) {
252
        $attachments_tmp = unserialize(base64_decode((string) Request::getString('attachments_tmp', '', 'POST'), true));
253
        if (Request::getArray('delete_tmp', null, 'POST') && (is_countable(Request::getArray('delete_tmp', null, 'POST')) ? count(Request::getArray('delete_tmp', null, 'POST')) : 0) > 1) {
254
            foreach (Request::getArray('delete_tmp', null, 'POST') as $key) {
255
                unlink($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $attachments_tmp[$key][0]));
256
                unset($attachments_tmp[$key]);
257
            }
258
        }
259
    }
260
    if (isset($attachments_tmp) && (is_countable($attachments_tmp) ? count($attachments_tmp) : 0)) {
261
        foreach ($attachments_tmp as $key => $attach) {
262
            if (rename(XOOPS_CACHE_PATH . '/' . $attach[0], $GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $attach[0]))) {
263
                $postObject->setAttachment($attach[0], $attach[1], $attach[2]);
264
            }
265
        }
266
    }
267
    $error_upload = '';
268
269
    if (isset($_FILES['userfile']['name']) && '' !== $_FILES['userfile']['name']
270
        && $topicHandler->getPermission($forumObject, $topic_status, 'attach')) {
271
        //        require_once $GLOBALS['xoops']->path('modules/' . $xoopsModule->getVar('dirname', 'n') . '/class/uploader.php');
272
        $maxfilesize = $forumObject->getVar('attach_maxkb') * 1024;
273
        $uploaddir   = XOOPS_CACHE_PATH;
274
275
        $uploader = new Uploader($uploaddir, $forumObject->getVar('attach_ext'), (int)$maxfilesize, (int)$GLOBALS['xoopsModuleConfig']['max_img_width'], (int)$GLOBALS['xoopsModuleConfig']['max_img_height']);
276
277
        if ($_FILES['userfile']['error'] > 0) {
278
            switch ($_FILES['userfile']['error']) {
279
                case 1:
280
                    $error_message[] = _MD_NEWBB_MAXUPLOADFILEINI;
281
                    break;
282
                case 2:
283
                    $error_message[] = sprintf(_MD_NEWBB_MAXKB, $forumObject->getVar('attach_maxkb'));
284
                    break;
285
                default:
286
                    $error_message[] = _MD_NEWBB_UPLOAD_ERRNODEF;
287
                    break;
288
            }
289
        } else {
290
            $uploader->setCheckMediaTypeByExt();
291
            $temp = Request::getArray('xoops_upload_file', [], 'POST');
292
            if ($uploader->fetchMedia($temp[0])) {
293
                $prefix = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->uid() . '_' : 'newbb_';
294
                $uploader->setPrefix($prefix);
295
                if (!$uploader->upload()) {
296
                    $error_message[] = $error_upload = $uploader->getErrors();
297
                } elseif (is_file($uploader->getSavedDestination())) {
298
                    if (rename(XOOPS_CACHE_PATH . '/' . $uploader->getSavedFileName(), $GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $uploader->getSavedFileName()))) {
299
                        $postObject->setAttachment($uploader->getSavedFileName(), $uploader->getMediaName(), $uploader->getMediaType());
300
                    }
301
                }
302
            } else {
303
                $error_message[] = $error_upload = $uploader->getErrors();
304
            }
305
        }
306
    }
307
308
    $postid = $postHandler->insert($postObject);
309
310
    if (!$postid) {
311
        require_once $GLOBALS['xoops']->path('header.php');
312
        xoops_error($postObject->getErrors());
313
        require_once $GLOBALS['xoops']->path('footer.php');
314
    }
315
    newbbSetSession('LP', time()); // Recording last post time
316
    /** @var Topic $topicObject */
317
    $topicObject = $topicHandler->get($postObject->getVar('topic_id'));
318
    $uid         = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
319
    if (newbbIsAdmin($forumObject)
320
        || ($topicHandler->getPermission($forumObject, $topic_status, 'type')
321
            && (0 == $topic_id
322
                || $uid == $topicObject->getVar('topic_poster')))) {
323
        $topicObject->setVar('type_id', Request::getInt('type_id', 0, 'POST'));
324
    }
325
326
    if (!empty($GLOBALS['xoopsModuleConfig']['do_tag']) && $postObject->isTopic()) {
327
        $topicObject->setVar('topic_tags', Request::getInt('topic_tags', 0, 'POST'));
328
    }
329
    $topicHandler->insert($topicObject);
330
331
    // Set read mark
332
    if (!empty($isnew)) {
333
        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.read.php');
334
        newbbSetRead('topic', $topicObject->getVar('topic_id'), $postid);
335
        if (!$postObject->getVar('pid')) {
336
            newbbSetRead('forum', $forumObject->getVar('forum_id'), $postid);
337
        }
338
    }
339
340
    //$postObject->loadFilters(empty($isnew) ? 'update' : 'insert');
341
342
    // Define tags for notification message
343
    if (!empty($isnew) && $approved && !empty($GLOBALS['xoopsModuleConfig']['notification_enabled'])) {
344
        $tags                = [];
345
        $tags['THREAD_NAME'] = Request::getString('subject', '', 'POST');
346
        $tags['THREAD_URL']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/viewtopic.php?topic_id=' . $topicObject->getVar('topic_id');
347
        $tags['POST_URL']    = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/viewtopic.php?topic_id=' . $topicObject->getVar('topic_id') . '&amp;post_id=' . $postid . '#forumpost' . $postid;
348
349
        require_once __DIR__ . '/include/notification.inc.php';
350
        $forum_info         = newbb_notify_iteminfo('forum', $forumObject->getVar('forum_id'));
351
        $tags['FORUM_NAME'] = $forum_info['name'];
352
        $tags['FORUM_URL']  = $forum_info['url'];
353
        /** @var \XoopsNotificationHandler $notificationHandler */
354
        $notificationHandler = xoops_getHandler('notification');
355
        if (empty($isreply)) {
356
            // Notify of new thread
357
            $notificationHandler->triggerEvent('forum', $forumObject->getVar('forum_id'), 'new_thread', $tags);
358
        } else {
359
            // Notify of new post
360
            $notificationHandler->triggerEvent('thread', $topic_id, 'new_post', $tags);
361
            $_tags['name'] = $tags['THREAD_NAME'];
362
            $_tags['url']  = $tags['POST_URL'];
363
            $_tags['uid']  = $uid;
364
            $notificationHandler->triggerEvent('thread', $topic_id, 'post', $_tags);
365
        }
366
        $notificationHandler->triggerEvent('global', 0, 'new_post', $tags);
367
        $notificationHandler->triggerEvent('forum', $forumObject->getVar('forum_id'), 'new_post', $tags);
368
        $tags['POST_CONTENT'] = Request::getString('message', '', 'POST');
369
        $tags['POST_NAME']    = Request::getString('subject', '', 'POST');
370
        $notificationHandler->triggerEvent('global', 0, 'new_fullpost', $tags);
371
        $notificationHandler->triggerEvent('forum', $forumObject->getVar('forum_id'), 'new_fullpost', $tags);
372
    }
373
374
    // If user checked notification box, subscribe them to the
375
    // appropriate event; if unchecked, then unsubscribe
376
    if (!empty($GLOBALS['xoopsUser']) && !empty($GLOBALS['xoopsModuleConfig']['notification_enabled'])) {
377
        /** @var \XoopsNotificationHandler $notificationHandler */
378
        $notificationHandler = xoops_getHandler('notification');
379
        if (!Request::getInt('notify', 0, 'POST')) {
380
            $notificationHandler->unsubscribe('thread', $postObject->getVar('topic_id'), 'new_post');
381
        } elseif (Request::getInt('notify', 0, 'POST') > 0) {
382
            $notificationHandler->subscribe('thread', $postObject->getVar('topic_id'), 'new_post');
383
        }
384
        // elseif ($_POST['notify']<0) keep it as it is
385
    }
386
387
    if ($approved) {
388
        if (!empty($GLOBALS['xoopsModuleConfig']['cache_enabled'])) {
389
            newbbSetSession('t' . $postObject->getVar('topic_id'), '');
390
        }
391
        // Update user
392
        if ($uid > 0) {
393
            $sql = 'SELECT count(*)' . '    FROM ' . $GLOBALS['xoopsDB']->prefix('newbb_topics') . '    WHERE approved=1 AND topic_poster =' . $uid;
394
            $result = $GLOBALS['xoopsDB']->query($sql);
395
            if (!$xoopsDB->isResultSet($result)) {
396
                \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR);
397
            }
398
            [$topics] = $GLOBALS['xoopsDB']->fetchRow($result);
399
400
            $sql = '    SELECT count(*)' . '    FROM ' . $GLOBALS['xoopsDB']->prefix('newbb_topics') . '    WHERE approved=1 AND topic_digest > 0 AND topic_poster =' . $uid;
401
            $result = $GLOBALS['xoopsDB']->query($sql);
402
            if (!$xoopsDB->isResultSet($result)) {
403
                \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR);
404
            }
405
            [$digests] = $GLOBALS['xoopsDB']->fetchRow($result);
406
407
            $sql = '    SELECT count(*), MAX(post_time)' . '    FROM ' . $GLOBALS['xoopsDB']->prefix('newbb_posts') . '    WHERE approved=1 AND uid =' . $uid;
408
            $result = $GLOBALS['xoopsDB']->query($sql);
409
            if (!$xoopsDB->isResultSet($result)) {
410
                \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR);
411
            }
412
            [$posts, $lastpost] = $GLOBALS['xoopsDB']->fetchRow($result);
413
414
            $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}'");
415
        }
416
417
        $redirect = XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $topicObject->getVar('topic_id') . '&amp;post_id=' . $postid . '#forumpost' . $postid;
418
        $message  = _MD_NEWBB_THANKSSUBMIT . '<br>' . $error_upload;
419
    } else {
420
        $redirect = XOOPS_URL . '/modules/newbb/viewforum.php?forum=' . $postObject->getVar('forum_id');
421
        $message  = _MD_NEWBB_THANKSSUBMIT . '<br>' . _MD_NEWBB_WAITFORAPPROVAL . '<br>' . $error_upload;
422
    }
423
424
    if ('add' === $op) {
425
        redirect_header(XOOPS_URL . '/modules/newbb/polls.php?op=add&amp;forum=' . $postObject->getVar('forum_id') . '&amp;topic_id=' . $postObject->getVar('topic_id'), 1, _MD_NEWBB_ADDPOLL);
426
    } else {
427
        redirect_header($redirect, 2, $message);
428
    }
429
}
430
431
$xoopsOption['template_main']                                        = 'newbb_edit_post.tpl';
432
$GLOBALS['xoopsConfig']['module_cache'][$xoopsModule->getVar('mid')] = 0;
433
// irmtfan remove and move to footer.php
434
//$xoopsOption['xoops_module_header']= $xoops_module_header;
435
// irmtfan include header.php after defining $xoopsOption['template_main']
436
require_once $GLOBALS['xoops']->path('header.php');
437
//$xoopsTpl->assign('xoops_module_header', $xoops_module_header);
438
439
if (Request::getString('contents_upload', '', 'POST')) {
440
    // BigKev73 > This line needs to be removed as it will cause any attachment already added in this editing session to be throw away. This is one of the reasons why multi-file attachment
441
    // was not working like it used to in CBB.
442
    //  $attachments_tmp = [];
443
444
    // This should be Request::getString, not Request::getArray, otherwise this will always return a null value. This is one of the reasons why multi-file attachment
445
    // was not working like it used to in CBB.
446
    //  if (Request::getArray('attachments_tmp', null, 'POST')) {
447
    //      $attachments_tmp = unserialize(base64_decode(Request::getArray('attachments_tmp', [], 'POST'), true));
448
    if (Request::getString('attachments_tmp', '', 'POST')) {
449
        $attachments_tmp = unserialize(base64_decode((string) Request::getString('attachments_tmp', '', 'POST'), true));
450
        if (Request::getArray('delete_tmp', [], 'POST') && (is_countable(Request::getArray('delete_tmp', [], 'POST')) ? count(Request::getArray('delete_tmp', [], 'POST')) : 0)) {
451
            foreach (Request::getArray('delete_tmp', '', 'POST') as $key) {
452
                unlink($uploaddir = $GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $attachments_tmp[$key][0]));
453
                unset($attachments_tmp[$key]);
454
            }
455
        }
456
    }
457
458
    $error_upload = '';
459
    if (isset($_FILES['userfile']['name']) && '' !== $_FILES['userfile']['name']) {
460
        //        require_once $GLOBALS['xoops']->path('modules/' . $xoopsModule->getVar('dirname', 'n') . '/class/uploader.php');
461
        $maxfilesize = $forumObject->getVar('attach_maxkb') * 1024;
462
        $uploaddir   = XOOPS_CACHE_PATH;
463
464
        $uploader = new Uploader($uploaddir, $forumObject->getVar('attach_ext'), (int)$maxfilesize, (int)$GLOBALS['xoopsModuleConfig']['max_img_width'], (int)$GLOBALS['xoopsModuleConfig']['max_img_height']);
465
        if ($_FILES['userfile']['error'] > 0) {
466
            switch ($_FILES['userfile']['error']) {
467
                case 1:
468
                    $error_message[] = _MD_NEWBB_MAXUPLOADFILEINI;
469
                    break;
470
                case 2:
471
                    $error_message[] = sprintf(_MD_NEWBB_MAXKB, $forumObject->getVar('attach_maxkb'));
472
                    break;
473
                default:
474
                    $error_message[] = _MD_NEWBB_UPLOAD_ERRNODEF;
475
                    break;
476
            }
477
        } else {
478
            $uploader->setCheckMediaTypeByExt();
479
            $temp = Request::getArray('xoops_upload_file', [], 'POST');
480
            if ($uploader->fetchMedia($temp[0])) {
481
                $prefix = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->uid() . '_' : 'newbb_';
482
                $uploader->setPrefix($prefix);
483
                if (!$uploader->upload()) {
484
                    $error_message[] = $error_upload = $uploader->getErrors();
485
                } elseif (is_file($uploader->getSavedDestination())) {
486
                    $attachments_tmp[(string)time()] = [
487
                        $uploader->getSavedFileName(),
488
                        $uploader->getMediaName(),
489
                        $uploader->getMediaType(),
490
                    ];
491
                }
492
            } else {
493
                $error_message[] = $error_upload = $uploader->getErrors();
494
            }
495
        }
496
    }
497
}
498
499
if (Request::getString('contents_preview', Request::getString('contents_preview', '', 'POST'), 'GET')) {
500
    if (Request::getString('attachments_tmp', '', 'POST')) {
501
        $attachments_tmp = unserialize(base64_decode((string) Request::getString('attachments_tmp', '', 'POST'), true));
502
    }
503
504
    $p_subject = htmlspecialchars((string) Request::getString('subject', '', 'POST'), ENT_QUOTES | ENT_HTML5);
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
    $p_message = Request::getString('message', '', 'POST');
510
    $p_message = $myts->previewTarea($p_message, $dohtml, $dosmiley, $doxcode, 1, $dobr);
511
    $p_date    = formatTimestamp(time());
512
    if ($postObject->isNew()) {
513
        if (is_object($GLOBALS['xoopsUser'])) {
514
            $p_name = $GLOBALS['xoopsUser']->getVar('uname');
515
            if (!empty($GLOBALS['xoopsModuleConfig']['show_realname']) && $GLOBALS['xoopsUser']->getVar('name')) {
516
                $p_name = $GLOBALS['xoopsUser']->getVar('name');
517
            }
518
        }
519
    } elseif ($postObject->getVar('uid')) {
520
        $p_name = newbbGetUnameFromId($postObject->getVar('uid'), $GLOBALS['xoopsModuleConfig']['show_realname']);
521
    }
522
    if (empty($p_name)) {
523
        $p_name = Request::getString('poster_name', '', 'POST') ? htmlspecialchars((string) Request::getString('poster_name', '', 'POST'), ENT_QUOTES | ENT_HTML5) : htmlspecialchars((string)$GLOBALS['xoopsConfig']['anonymous'], ENT_QUOTES | ENT_HTML5);
524
    }
525
526
    $post_preview = [
527
        'subject' => $p_subject,
528
        'meta'    => _MD_NEWBB_BY . ' ' . $p_name . ' ' . _MD_NEWBB_ON . ' ' . $p_date,
529
        'content' => $p_message,
530
    ];
531
    $xoopsTpl->assign_by_ref('post_preview', $post_preview);
532
}
533
534
if (Request::getString('contents_upload', '', 'POST') || Request::getString('contents_preview', '', 'POST')
535
    || Request::getString('contents_preview', '', 'GET')
536
    || Request::getString('editor', '', 'POST')) {
537
    $editor        = Request::getString('editor', '', 'POST');
538
    $dosmiley      = Request::getInt('dosmiley', 0, 'POST');
539
    $dohtml        = Request::getInt('dohtml', 0, 'POST');
540
    $doxcode       = Request::getInt('doxcode', 0, 'POST');
541
    $dobr          = Request::getInt('dobr', 0, 'POST');
542
    $subject       = Request::getString('subject', '', 'POST');
543
    $message       = Request::getString('message', '', 'POST');
544
    $poster_name   = Request::getString('poster_name', '', 'POST');
545
    $hidden        = Request::getString('hidden', '', 'POST');
546
    $notify        = Request::getInt('notify', 0, 'POST');
547
    $attachsig     = Request::getInt('attachsig', 0, 'POST'); //!empty($_POST['attachsig']) ? 1 : 0;
548
    $isreply       = Request::getInt('isreply', 0, 'POST'); //!empty($_POST['isreply']) ? 1 : 0;
549
    $isedit        = Request::getInt('isedit', 0, 'POST'); //!empty($_POST['isedit']) ? 1 : 0;
550
    $icon          = (Request::getString('icon', '', 'POST')
551
                      && is_file($GLOBALS['xoops']->path('images/subject/' . Request::getString('icon', '', 'POST'))) ? Request::getString('icon', '', 'POST') : '');
552
    $view_require  = Request::getString('view_require', '', 'POST');
553
    $post_karma    = (('require_karma' === $view_require)
554
                      && !Request::getInt('post_karma', 0, 'POST')) ? Request::getInt('post_karma', 0, 'POST') : 0;
555
    $require_reply = ('require_reply' === $view_require) ? 1 : 0;
556
557
    if (!Request::getString('contents_upload', '', 'POST')) {
558
        $contents_preview = 1;
559
    }
560
    $attachments = $postObject->getAttachment();
561
    $xoopsTpl->assign('error_message', implode('<br>', $error_message));
562
563
    require_once __DIR__ . '/include/form.post.php';
564
}
565
// irmtfan move to footer.php
566
require_once __DIR__ . '/footer.php';
567
require_once $GLOBALS['xoops']->path('footer.php');
568