Completed
Branch master (61995d)
by Michael
11:22 queued 08:18
created
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 (http://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
21
include_once __DIR__ . '/header.php';
22
23
foreach ([
24
             'forum',
25
             'topic_id',
26
             'post_id',
27
             'order',
28
             'pid',
29
             'start',
30
             'isreply',
31
             'isedit'
32
         ] as $getint) {
33
    ${$getint} = Request::getInt($getint, 0, 'POST');
34
}
35
36
$op       = Request::getCmd('op', '', 'POST');
37
$viewmode = ('flat' !== Request::getString('viewmode', '', 'POST')) ? 'thread' : 'flat';
38
if (empty($forum)) {
39
    redirect_header('index.php', 2, _MD_NEWBB_ERRORFORUM);
40
}
41
42
/** @var \NewbbForumHandler $forumHandler */
43
$forumHandler = xoops_getModuleHandler('forum', 'newbb');
44
/** @var \NewbbTopicHandler $topicHandler */
45
$topicHandler = xoops_getModuleHandler('topic', 'newbb');
46
/** @var \NewbbPostHandler $postHandler */
47
$postHandler = xoops_getModuleHandler('post', 'newbb');
48
49
if (!empty($isedit) && $post_id > 0) {
50
    /** @var NewbbPost $post_obj */
51
    $post_obj = $postHandler->get($post_id);
52
    $topic_id = $post_obj->getVar('topic_id');
53
} else {
54
    $post_obj = $postHandler->create();
55
}
56
$topic_obj = $topicHandler->get($topic_id);
57
$forum_id  = $topic_id ? $topic_obj->getVar('forum_id') : $forum;
58
$forum_obj = $forumHandler->get($forum_id);
59
if (!$forumHandler->getPermission($forum_obj)) {
60
    redirect_header('index.php', 2, _NOPERM);
61
}
62
63
if ($GLOBALS['xoopsModuleConfig']['wol_enabled']) {
64
    /** @var \NewbbOnlineHandler $onlineHandler */
65
    $onlineHandler = xoops_getModuleHandler('online', 'newbb');
66
    $onlineHandler->init($forum_obj);
67
}
68
69
$error_message = [];
70
71
if (Request::getString('contents_submit', '', 'POST')) {
72
    $token_valid = false;
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');
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)) {
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 View Code Duplication
    if (!is_object($GLOBALS['xoopsUser'])) {
103
        xoops_load('captcha');
104
        $xoopsCaptcha = XoopsCaptcha::getInstance();
105
        if (!$xoopsCaptcha->verify()) {
106
            $captcha_invalid = true;
107
            $error_message[] = $xoopsCaptcha->getMessage();
108
        }
109
    }
110
111
    $isadmin = newbb_isAdmin($forum_obj);
112
113
    $time_valid = true;
114
    if (!$isadmin && !empty($GLOBALS['xoopsModuleConfig']['post_timelimit'])) {
115
        $last_post = newbb_getsession('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 = $topic_obj->getVar('topic_status');
144
        if ($topicHandler->getPermission($forum_obj, $topic_status, 'edit')
145
            && ($isadmin
146
                || ($post_obj->checkTimelimit('edit_timelimit')
147
                    && $post_obj->checkIdentity()))) {
148
        } else {
149
            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);
150
        }
151
152
        $delete_attach = Request::getArray('delete_attach', [], 'POST');
153
        if (is_array($delete_attach) && count($delete_attach) > 0) {
154
            $post_obj->deleteAttachment($delete_attach);
155
        }
156
    } else {
157
        if ($topic_id) {
158
            $topic_status = $topic_obj->getVar('topic_status');
159
            if (!$topicHandler->getPermission($forum_obj, $topic_status, 'reply')) {
160
                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);
161
            }
162
        } else {
163
            $topic_status = 0;
164
            if (!$topicHandler->getPermission($forum_obj, $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
            $post_obj->setVar('pid', $pid);
180
        }
181
        if (!empty($topic_id)) {
182
            $post_obj->setVar('topic_id', $topic_id);
183
            $isreply = 1;
184
        }
185
        $post_obj->setVar('poster_ip', Xmf\IPAddress::fromRequest()->asReadable());
186
        $post_obj->setVar('uid', $uid);
187
        $post_obj->setVar('post_time', time());
188
    }
189
190
    $approved = $topicHandler->getPermission($forum_obj, $topic_status, 'noapprove');
191
    $post_obj->setVar('approved', $approved);
192
193
    $post_obj->setVar('forum_id', $forum_obj->getVar('forum_id'));
194
195
    $subject       = xoops_trim(Request::getString('subject', '', 'POST'));
196
    $subject       = ($subject === '') ? _NOTITLE : $subject;
197
    $poster_name   = xoops_trim(Request::getString('poster_name', '', 'POST'));
198
    $dohtml        = Request::getInt('dohtml', 0, 'POST')
199
                     && $topicHandler->getPermission($forum_obj, $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($forum_obj, $topic_status, 'signature');
207
    $view_require  = Request::getString('view_require', '', 'POST');
208
    $post_karma    = ($view_require === 'require_karma') ? Request::getInt('post_karma', 0, 'POST') : 0;
209
    $require_reply = ($view_require === 'require_reply');
210
    $post_obj->setVar('subject', $subject);
211
    $editwhy = xoops_trim(Request::getString('editwhy', '', 'POST')); // !empty($_POST['editwhy'])) ? xoops_trim($_POST['editwhy']) : "";
212
213
    if ($dohtml && !newbb_isAdmin($forum_obj)) {
0 ignored issues
show
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

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.

Loading history...
214
        //$message=newbb_textFilter($message);
215
    }
216
    $post_obj->setVar('post_text', $message);
217
    $post_obj->setVar('post_karma', $post_karma);
218
    $post_obj->setVar('require_reply', $require_reply);
219
    $post_obj->setVar('poster_name', $poster_name);
220
    $post_obj->setVar('dohtml', $dohtml);
221
    $post_obj->setVar('dosmiley', $dosmiley);
222
    $post_obj->setVar('doxcode', $doxcode);
223
    $post_obj->setVar('dobr', $dobr);
224
    $post_obj->setVar('icon', $icon);
225
    $post_obj->setVar('attachsig', $attachsig);
226
    $post_obj->setAttachment();
227
    if (!empty($post_id)) {
228
        $post_obj->setPostEdit($poster_name, $editwhy);
229
    } // is reply
230
231
    //    $attachments_tmp = array();
232
    //    if (!empty($_POST["attachments_tmp"])) {
233 View Code Duplication
    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]))) {
245
                $post_obj->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($forum_obj, $topic_status, 'attach')) {
253
        require_once $GLOBALS['xoops']->path('modules/' . $xoopsModule->getVar('dirname', 'n') . '/class/uploader.php');
254
        $maxfilesize = $forum_obj->getVar('attach_maxkb') * 1024;
255
        $uploaddir   = XOOPS_CACHE_PATH;
256
257
        $uploader = new NewbbUploader($uploaddir, $forum_obj->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 View Code Duplication
            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, $forum_obj->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
                            $post_obj->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($post_obj);
293
294
    if (!$postid) {
295
        include_once $GLOBALS['xoops']->path('header.php');
296
        xoops_error($post_obj->getErrors());
297
        include_once $GLOBALS['xoops']->path('footer.php');
298
    }
299
    newbb_setsession('LP', time()); // Recording last post time
300
    $topic_obj = $topicHandler->get($post_obj->getVar('topic_id'));
301
    $uid       = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
302
    if (newbb_isAdmin($forum_obj)
303
        || ($topicHandler->getPermission($forum_obj, $topic_status, 'type')
304
            && ($topic_id == 0
305
                || $uid == $topic_obj->getVar('topic_poster')))) {
306
        $topic_obj->setVar('type_id', Request::getInt('type_id', 0, 'POST'));
307
    }
308
309
    if (!empty($GLOBALS['xoopsModuleConfig']['do_tag']) && $post_obj->isTopic()) {
310
        $topic_obj->setVar('topic_tags', Request::getInt('topic_tags', 0, 'POST'));
311
    }
312
    $topicHandler->insert($topic_obj);
313
314
    // Set read mark
315
    if (!empty($isnew)) {
316
        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.read.php');
317
        newbb_setRead('topic', $topic_obj->getVar('topic_id'), $postid);
318
        if (!$post_obj->getVar('pid')) {
319
            newbb_setRead('forum', $forum_obj->getVar('forum_id'), $postid);
320
        }
321
    }
322
323
    //$post_obj->loadFilters(empty($isnew) ? 'update' : 'insert');
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
        include_once __DIR__ . '/include/notification.inc.php';
332
        $forum_info         = newbb_notify_iteminfo('forum', $forum_obj->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', $forum_obj->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', $forum_obj->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', $forum_obj->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', $post_obj->getVar('topic_id'), 'new_post');
362
        } elseif (Request::getInt('notify', 0, 'POST') > 0) {
363
            $notificationHandler->subscribe('thread', $post_obj->getVar('topic_id'), 'new_post');
364
        }
365
        // elseif ($_POST['notify']<0) keep it as it is
366
    }
367
368
    if ($approved) {
369
        if (!empty($GLOBALS['xoopsModuleConfig']['cache_enabled'])) {
370
            newbb_setsession('t' . $post_obj->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=' . $post_obj->getVar('forum_id');
393
        $message  = _MD_NEWBB_THANKSSUBMIT . '<br>' . _MD_NEWBB_WAITFORAPPROVAL . '<br>' . $error_upload;
394
    }
395
396
    if ($op === 'add') {
397
        redirect_header(XOOPS_URL . '/modules/newbb/polls.php?op=add&amp;forum=' . $post_obj->getVar('forum_id') . '&amp;topic_id=' . $post_obj->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
include_once $GLOBALS['xoops']->path('header.php');
409
//$xoopsTpl->assign('xoops_module_header', $xoops_module_header);
410
411
if (Request::getString('contents_upload', null, 'POST')) {
412
    $attachments_tmp = [];
413 View Code Duplication
    if (Request::getArray('attachments_tmp', null, 'POST')) {
414
        $attachments_tmp = unserialize(base64_decode(Request::getArray('attachments_tmp', [], 'POST')));
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');
426
        $maxfilesize = $forum_obj->getVar('attach_maxkb') * 1024;
427
        $uploaddir   = XOOPS_CACHE_PATH;
428
429
        $uploader = new NewbbUploader($uploaddir, $forum_obj->getVar('attach_ext'), (int)$maxfilesize, (int)$GLOBALS['xoopsModuleConfig']['max_img_width'], (int)$GLOBALS['xoopsModuleConfig']['max_img_height']);
430
        if ($_FILES['userfile']['error'] > 0) {
431 View Code Duplication
            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, $forum_obj->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());
479
    if ($post_obj->isNew()) {
480 View Code Duplication
        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 ($post_obj->getVar('uid')) {
487
        $p_name = newbb_getUnameFromId($post_obj->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')) : htmlspecialchars($GLOBALS['xoopsConfig']['anonymous']);
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;
515
    $isreply       = Request::getInt('isreply', 0, 'POST'); //!empty($_POST['isreply']) ? 1 : 0;
516
    $isedit        = Request::getInt('isedit', 0, 'POST'); //!empty($_POST['isedit']) ? 1 : 0;
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    = (($view_require === 'require_karma')
521
                      && !Request::getInt('post_karma', 0, 'POST')) ? Request::getInt('post_karma', 0, 'POST') : 0;
522
    $require_reply = ($view_require === 'require_reply') ? 1 : 0;
523
524
    if (!Request::getString('contents_upload', '', 'POST')) {
525
        $contents_preview = 1;
526
    }
527
    $attachments = $post_obj->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
include_once __DIR__ . '/footer.php';
534
include $GLOBALS['xoops']->path('footer.php');
535