Cancelled
Push — master ( dd6e46...186ca8 )
by Michael
72:53 queued 72:53
created

post.php (4 issues)

Labels
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);
41
}
42
43
///** @var Newbb\ForumHandler $forumHandler */
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);
62
}
63
64
if ($GLOBALS['xoopsModuleConfig']['wol_enabled']) {
65
    //    /** @var Newbb\OnlineHandler $onlineHandler */
66
    //    $onlineHandler = Newbb\Helper::getInstance()->getHandler('Online');
67
    $onlineHandler->init($forumObject);
68
}
69
70
$error_message = [];
71
72
if (Request::getString('contents_submit', '', 'POST')) {
73
    $token_valid = false;
74
    $token_valid = $GLOBALS['xoopsSecurity']->check();
75
76
    $captcha_invalid = false;
77
    if (!is_object($GLOBALS['xoopsUser']) && Request::hasVar('uname', 'POST') && Request::hasVar('pass', 'POST')) {
78
        $uname = Request::getString('uname', '', 'POST');
79
        $pass  = Request::getString('pass', '', 'POST');
80
        /** @var \XoopsMemberHandler $memberHandler */
81
        $memberHandler = xoops_getHandler('member');
82
        $user          = $memberHandler->loginUser($uname, $pass);
83
        if (is_object($user) && 0 < $user->getVar('level')) {
84
            if (Request::getString('login', '', 'POST')) {
85
                $user->setVar('last_login', time());
86
                if (!$memberHandler->insertUser($user)) {
87
                }
88
                $_SESSION                    = [];
89
                $_SESSION['xoopsUserId']     = $user->getVar('uid');
90
                $_SESSION['xoopsUserGroups'] = $user->getGroups();
91
                if ($GLOBALS['xoopsConfig']['use_mysession'] && '' !== $GLOBALS['xoopsConfig']['session_name']) {
92
                    setcookie($GLOBALS['xoopsConfig']['session_name'], session_id(), time() + (60 * $GLOBALS['xoopsConfig']['session_expire']), '/', '', 0);
93
                }
94
                $user_theme = $user->getVar('theme');
95
                if (in_array($user_theme, $GLOBALS['xoopsConfig']['theme_set_allowed'])) {
96
                    $_SESSION['xoopsUserTheme'] = $user_theme;
97
                }
98
            }
99
            $GLOBALS['xoopsUser'] = $user;
100
            $xoopsUserIsAdmin     = $GLOBALS['xoopsUser']->isAdmin($xoopsModule->getVar('mid'));
101
        }
102
    }
103
    if (!is_object($GLOBALS['xoopsUser'])) {
104
        xoops_load('captcha');
105
        $xoopsCaptcha = \XoopsCaptcha::getInstance();
106
        if (!$xoopsCaptcha->verify()) {
107
            $captcha_invalid = true;
108
            $error_message[] = $xoopsCaptcha->getMessage();
109
        }
110
    }
111
112
    $isAdmin = newbbIsAdmin($forumObject);
113
114
    $time_valid = true;
115
    if (!$isAdmin && !empty($GLOBALS['xoopsModuleConfig']['post_timelimit'])) {
116
        $last_post = newbbGetSession('LP');
117
        if (time() - $last_post < $GLOBALS['xoopsModuleConfig']['post_timelimit']) {
118
            $time_valid = false;
119
        }
120
    }
121
122
    if ($captcha_invalid || !$token_valid || !$time_valid) {
123
        $_POST['contents_preview'] = 1;
124
        $_POST['contents_submit']  = null;
125
        $_POST['contents_upload']  = null;
126
        if (!$token_valid) {
127
            $error_message[] = _MD_NEWBB_INVALID_SUBMIT;
128
        }
129
        if (!$time_valid) {
130
            $error_message[] = sprintf(_MD_NEWBB_POSTING_LIMITED, $GLOBALS['xoopsModuleConfig']['post_timelimit']);
131
        }
132
    }
133
}
134
135
if (Request::getString('contents_submit', '', 'POST')) {
136
    $message = Request::getText('message', '', 'POST');
137
    if (empty($message)) {
138
        // irmtfan - issue with javascript:history.go(-1) - add error message
139
        redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 1, _MD_NEWBB_ERROR_BACK);
140
    }
141
    if (!empty($isedit) && $post_id > 0) {
142
        $uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
143
144
        $topic_status = $topicObject->getVar('topic_status');
145
        if ($topicHandler->getPermission($forumObject, $topic_status, 'edit')
146
            && ($isAdmin
147
                || ($postObject->checkTimelimit('edit_timelimit')
148
                    && $postObject->checkIdentity()))) {
149
        } else {
150
            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);
151
        }
152
153
        $delete_attach = Request::getArray('delete_attach', [], 'POST');
154
        if (is_array($delete_attach) && count($delete_attach) > 0) {
155
            $postObject->deleteAttachment($delete_attach);
156
        }
157
    } else {
158
        if ($topic_id) {
159
            $topic_status = $topicObject->getVar('topic_status');
160
            if (!$topicHandler->getPermission($forumObject, $topic_status, 'reply')) {
161
                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);
162
            }
163
        } else {
164
            $topic_status = 0;
165
            if (!$topicHandler->getPermission($forumObject, $topic_status, 'post')) {
166
                redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?forum={$forum_id}", 2, _MD_NEWBB_NORIGHTTOPOST);
167
            }
168
        }
169
170
        $isreply = 0;
171
        $isnew   = 1;
172
        if (!is_object($GLOBALS['xoopsUser'])
173
            || (Request::getString('noname', '', 'POST')
174
                && !empty($GLOBALS['xoopsModuleConfig']['allow_user_anonymous']))) {
175
            $uid = 0;
176
        } else {
177
            $uid = $GLOBALS['xoopsUser']->getVar('uid');
178
        }
179
        if (!empty($pid)) {
180
            $postObject->setVar('pid', $pid);
181
        }
182
        if (!empty($topic_id)) {
183
            $postObject->setVar('topic_id', $topic_id);
184
            $isreply = 1;
185
        }
186
        $postObject->setVar('poster_ip', Xmf\IPAddress::fromRequest()->asReadable());
187
        $postObject->setVar('uid', $uid);
188
        $postObject->setVar('post_time', time());
189
    }
190
191
    $approved = $topicHandler->getPermission($forumObject, $topic_status, 'noapprove');
192
    $postObject->setVar('approved', $approved);
193
194
    $postObject->setVar('forum_id', $forumObject->getVar('forum_id'));
195
196
    $subject       = xoops_trim(Request::getString('subject', '', 'POST'));
197
    $subject       = ('' === $subject) ? _NOTITLE : $subject;
198
    $poster_name   = xoops_trim(Request::getString('poster_name', '', 'POST'));
199
    $dohtml        = Request::getInt('dohtml', 0, 'POST')
200
                     && $topicHandler->getPermission($forumObject, $topic_status, 'html');
201
    $dosmiley      = Request::getInt('dosmiley', 0, 'POST');
202
    $doxcode       = Request::getInt('doxcode', 0, 'POST') ? 1 : 0;
203
    $dobr          = Request::getInt('dobr', 0, 'POST') ? 1 : 0;
204
    $icon          = (Request::getString('icon', '', 'POST')
205
                      && is_file($GLOBALS['xoops']->path('images/subject/' . Request::getString('icon', '', 'POST'))) ? Request::getString('icon', '', 'POST') : '');
206
    $attachsig     = Request::getBool('attachsig', false, 'POST')
207
                     && $topicHandler->getPermission($forumObject, $topic_status, 'signature');
208
    $view_require  = Request::getString('view_require', '', 'POST');
209
    $post_karma    = ('require_karma' === $view_require) ? Request::getInt('post_karma', 0, 'POST') : 0;
210
    $require_reply = ('require_reply' === $view_require);
211
    $postObject->setVar('subject', $subject);
212
    $editwhy = xoops_trim(Request::getString('editwhy', '', 'POST')); // !empty($_POST['editwhy'])) ? xoops_trim($_POST['editwhy']) : "";
213
214
    if ($dohtml && !newbbIsAdmin($forumObject)) {
215
        //$message=newbb_textFilter($message);
216
    }
217
    $postObject->setVar('post_text', $message);
218
    $postObject->setVar('post_karma', $post_karma);
219
    $postObject->setVar('require_reply', $require_reply);
220
    $postObject->setVar('poster_name', $poster_name);
221
    $postObject->setVar('dohtml', $dohtml);
222
    $postObject->setVar('dosmiley', $dosmiley);
223
    $postObject->setVar('doxcode', $doxcode);
224
    $postObject->setVar('dobr', $dobr);
225
    $postObject->setVar('icon', $icon);
226
    $postObject->setVar('attachsig', $attachsig);
227
    $postObject->setAttachment();
228
    if (!empty($post_id)) {
229
        $postObject->setPostEdit($poster_name, $editwhy);
230
    } // is reply
231
232
    //    $attachments_tmp = array();
233
    //    if (!empty($_POST["attachments_tmp"])) {
234
    if (Request::getString('attachments_tmp', '', 'POST')) {
235
        $attachments_tmp = unserialize(base64_decode(Request::getString('attachments_tmp', '', 'POST')));
236
        if (Request::getArray('delete_tmp', null, 'POST') && count(Request::getArray('delete_tmp', null, 'POST')) > 1) {
237
            foreach (Request::getArray('delete_tmp', null, 'POST') as $key) {
238
                unlink($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $attachments_tmp[$key][0]));
239
                unset($attachments_tmp[$key]);
240
            }
241
        }
242
    }
243
    if (isset($attachments_tmp) && count($attachments_tmp)) {
244
        foreach ($attachments_tmp as $key => $attach) {
245
            if (rename(XOOPS_CACHE_PATH . '/' . $attachments_tmp[$key][0], $GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $attachments_tmp[$key][0]))) {
246
                $postObject->setAttachment($attach[0], $attach[1], $attach[2]);
247
            }
248
        }
249
    }
250
    $error_upload = '';
251
252
    if (isset($_FILES['userfile']['name']) && '' !== $_FILES['userfile']['name']
253
        && $topicHandler->getPermission($forumObject, $topic_status, 'attach')) {
254
//        require_once $GLOBALS['xoops']->path('modules/' . $xoopsModule->getVar('dirname', 'n') . '/class/uploader.php');
255
        $maxfilesize = $forumObject->getVar('attach_maxkb') * 1024;
256
        $uploaddir   = XOOPS_CACHE_PATH;
257
258
        $uploader = new Newbb\Uploader($uploaddir, $forumObject->getVar('attach_ext'), (int)$maxfilesize, (int)$GLOBALS['xoopsModuleConfig']['max_img_width'], (int)$GLOBALS['xoopsModuleConfig']['max_img_height']);
259
260
        if ($_FILES['userfile']['error'] > 0) {
261
            switch ($_FILES['userfile']['error']) {
262
                case 1:
263
                    $error_message[] = _MD_NEWBB_MAXUPLOADFILEINI;
264
                    break;
265
                case 2:
266
                    $error_message[] = sprintf(_MD_NEWBB_MAXKB, $forumObject->getVar('attach_maxkb'));
267
                    break;
268
                default:
269
                    $error_message[] = _MD_NEWBB_UPLOAD_ERRNODEF;
270
                    break;
271
            }
272
        } else {
273
            $uploader->setCheckMediaTypeByExt();
274
            $temp = Request::getArray('xoops_upload_file', [], 'POST');
275
            if ($uploader->fetchMedia($temp[0])) {
276
                $prefix = is_object($GLOBALS['xoopsUser']) ? (string)$GLOBALS['xoopsUser']->uid() . '_' : 'newbb_';
277
                $uploader->setPrefix($prefix);
278
                if (!$uploader->upload()) {
279
                    $error_message[] = $error_upload = $uploader->getErrors();
280
                } else {
281
                    if (is_file($uploader->getSavedDestination())) {
282
                        if (rename(XOOPS_CACHE_PATH . '/' . $uploader->getSavedFileName(), $GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $uploader->getSavedFileName()))) {
283
                            $postObject->setAttachment($uploader->getSavedFileName(), $uploader->getMediaName(), $uploader->getMediaType());
284
                        }
285
                    }
286
                }
287
            } else {
288
                $error_message[] = $error_upload = $uploader->getErrors();
289
            }
290
        }
291
    }
292
293
    $postid = $postHandler->insert($postObject);
294
295
    if (!$postid) {
296
        require_once $GLOBALS['xoops']->path('header.php');
297
        xoops_error($postObject->getErrors());
298
        require_once $GLOBALS['xoops']->path('footer.php');
299
    }
300
    newbbSetSession('LP', time()); // Recording last post time
301
    $topicObject = $topicHandler->get($postObject->getVar('topic_id'));
302
    $uid         = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
303
    if (newbbIsAdmin($forumObject)
304
        || ($topicHandler->getPermission($forumObject, $topic_status, 'type')
305
            && (0 == $topic_id
306
                || $uid == $topicObject->getVar('topic_poster')))) {
307
        $topicObject->setVar('type_id', Request::getInt('type_id', 0, 'POST'));
308
    }
309
310
    if (!empty($GLOBALS['xoopsModuleConfig']['do_tag']) && $postObject->isTopic()) {
311
        $topicObject->setVar('topic_tags', Request::getInt('topic_tags', 0, 'POST'));
312
    }
313
    $topicHandler->insert($topicObject);
314
315
    // Set read mark
316
    if (!empty($isnew)) {
317
        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.read.php');
318
        newbbSetRead('topic', $topicObject->getVar('topic_id'), $postid);
319
        if (!$postObject->getVar('pid')) {
320
            newbbSetRead('forum', $forumObject->getVar('forum_id'), $postid);
321
        }
322
    }
323
324
    //$postObject->loadFilters(empty($isnew) ? 'update' : 'insert');
325
326
    // Define tags for notification message
327
    if (!empty($isnew) && $approved && !empty($GLOBALS['xoopsModuleConfig']['notification_enabled'])) {
328
        $tags                = [];
329
        $tags['THREAD_NAME'] = Request::getString('subject', '', 'POST');
330
        $tags['THREAD_URL']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/viewtopic.php?post_id=' . $postid;
331
        $tags['POST_URL']    = $tags['THREAD_URL']; // . '#forumpost' . $postid;
332
        require_once __DIR__ . '/include/notification.inc.php';
333
        $forum_info         = newbb_notify_iteminfo('forum', $forumObject->getVar('forum_id'));
334
        $tags['FORUM_NAME'] = $forum_info['name'];
335
        $tags['FORUM_URL']  = $forum_info['url'];
336
        /** @var \XoopsNotificationHandler $notificationHandler */
337
        $notificationHandler = xoops_getHandler('notification');
338
        if (empty($isreply)) {
339
            // Notify of new thread
340
            $notificationHandler->triggerEvent('forum', $forumObject->getVar('forum_id'), 'new_thread', $tags);
0 ignored issues
show
'new_thread' of type string is incompatible with the type integer expected by parameter $event of XoopsNotificationHandler::triggerEvent(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

340
            $notificationHandler->triggerEvent('forum', $forumObject->getVar('forum_id'), /** @scrutinizer ignore-type */ 'new_thread', $tags);
Loading history...
'forum' of type string is incompatible with the type integer expected by parameter $category of XoopsNotificationHandler::triggerEvent(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

340
            $notificationHandler->triggerEvent(/** @scrutinizer ignore-type */ 'forum', $forumObject->getVar('forum_id'), 'new_thread', $tags);
Loading history...
341
        } else {
342
            // Notify of new post
343
            $notificationHandler->triggerEvent('thread', $topic_id, 'new_post', $tags);
344
            $_tags['name'] = $tags['THREAD_NAME'];
345
            $_tags['url']  = $tags['POST_URL'];
346
            $_tags['uid']  = $uid;
347
            $notificationHandler->triggerEvent('thread', $topic_id, 'post', $_tags);
348
        }
349
        $notificationHandler->triggerEvent('global', 0, 'new_post', $tags);
350
        $notificationHandler->triggerEvent('forum', $forumObject->getVar('forum_id'), 'new_post', $tags);
351
        $tags['POST_CONTENT'] = Request::getString('message', '', 'POST');
352
        $tags['POST_NAME']    = Request::getString('subject', '', 'POST');
353
        $notificationHandler->triggerEvent('global', 0, 'new_fullpost', $tags);
354
        $notificationHandler->triggerEvent('forum', $forumObject->getVar('forum_id'), 'new_fullpost', $tags);
355
    }
356
357
    // If user checked notification box, subscribe them to the
358
    // appropriate event; if unchecked, then unsubscribe
359
    if (!empty($GLOBALS['xoopsUser']) && !empty($GLOBALS['xoopsModuleConfig']['notification_enabled'])) {
360
        $notificationHandler = xoops_getHandler('notification');
361
        if (!Request::getInt('notify', 0, 'POST')) {
362
            $notificationHandler->unsubscribe('thread', $postObject->getVar('topic_id'), 'new_post');
0 ignored issues
show
The method unsubscribe() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsNotificationHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

362
            $notificationHandler->/** @scrutinizer ignore-call */ 
363
                                  unsubscribe('thread', $postObject->getVar('topic_id'), 'new_post');
Loading history...
363
        } elseif (Request::getInt('notify', 0, 'POST') > 0) {
364
            $notificationHandler->subscribe('thread', $postObject->getVar('topic_id'), 'new_post');
0 ignored issues
show
The method subscribe() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsNotificationHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

364
            $notificationHandler->/** @scrutinizer ignore-call */ 
365
                                  subscribe('thread', $postObject->getVar('topic_id'), 'new_post');
Loading history...
365
        }
366
        // elseif ($_POST['notify']<0) keep it as it is
367
    }
368
369
    if ($approved) {
370
        if (!empty($GLOBALS['xoopsModuleConfig']['cache_enabled'])) {
371
            newbbSetSession('t' . $postObject->getVar('topic_id'), null);
372
        }
373
        // Update user
374
        if ($uid > 0) {
375
            $sql = 'SELECT count(*)' . '    FROM ' . $GLOBALS['xoopsDB']->prefix('newbb_topics') . '    WHERE approved=1 AND topic_poster =' . $uid;
376
            $ret = $GLOBALS['xoopsDB']->query($sql);
377
            list($topics) = $GLOBALS['xoopsDB']->fetchRow($ret);
378
379
            $sql = '    SELECT count(*)' . '    FROM ' . $GLOBALS['xoopsDB']->prefix('newbb_topics') . '    WHERE approved=1 AND topic_digest > 0 AND topic_poster =' . $uid;
380
            $ret = $GLOBALS['xoopsDB']->query($sql);
381
            list($digests) = $GLOBALS['xoopsDB']->fetchRow($ret);
382
383
            $sql = '    SELECT count(*), MAX(post_time)' . '    FROM ' . $GLOBALS['xoopsDB']->prefix('newbb_posts') . '    WHERE approved=1 AND uid =' . $uid;
384
            $ret = $GLOBALS['xoopsDB']->query($sql);
385
            list($posts, $lastpost) = $GLOBALS['xoopsDB']->fetchRow($ret);
386
387
            $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}'");
388
        }
389
390
        $redirect = XOOPS_URL . '/modules/newbb/viewtopic.php?post_id=' . $postid;
391
        $message  = _MD_NEWBB_THANKSSUBMIT . '<br>' . $error_upload;
392
    } else {
393
        $redirect = XOOPS_URL . '/modules/newbb/viewforum.php?forum=' . $postObject->getVar('forum_id');
394
        $message  = _MD_NEWBB_THANKSSUBMIT . '<br>' . _MD_NEWBB_WAITFORAPPROVAL . '<br>' . $error_upload;
395
    }
396
397
    if ('add' === $op) {
398
        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);
399
    } else {
400
        redirect_header($redirect, 2, $message);
401
    }
402
}
403
404
$xoopsOption['template_main']                                        = 'newbb_edit_post.tpl';
405
$GLOBALS['xoopsConfig']['module_cache'][$xoopsModule->getVar('mid')] = 0;
406
// irmtfan remove and move to footer.php
407
//$xoopsOption['xoops_module_header']= $xoops_module_header;
408
// irmtfan include header.php after defining $xoopsOption['template_main']
409
require_once $GLOBALS['xoops']->path('header.php');
410
//$xoopsTpl->assign('xoops_module_header', $xoops_module_header);
411
412
if (Request::getString('contents_upload', null, 'POST')) {
413
    $attachments_tmp = [];
414
    if (Request::getArray('attachments_tmp', null, 'POST')) {
415
        $attachments_tmp = unserialize(base64_decode(Request::getArray('attachments_tmp', [], 'POST')));
416
        if (Request::getArray('delete_tmp', null, 'POST') && count(Request::getArray('delete_tmp', null, 'POST'))) {
417
            foreach (Request::getArray('delete_tmp', '', 'POST') as $key) {
418
                unlink($uploaddir = $GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $attachments_tmp[$key][0]));
419
                unset($attachments_tmp[$key]);
420
            }
421
        }
422
    }
423
424
    $error_upload = '';
425
    if (isset($_FILES['userfile']['name']) && '' !== $_FILES['userfile']['name']) {
426
//        require_once $GLOBALS['xoops']->path('modules/' . $xoopsModule->getVar('dirname', 'n') . '/class/uploader.php');
427
        $maxfilesize = $forumObject->getVar('attach_maxkb') * 1024;
428
        $uploaddir   = XOOPS_CACHE_PATH;
429
430
        $uploader = new Newbb\Uploader($uploaddir, $forumObject->getVar('attach_ext'), (int)$maxfilesize, (int)$GLOBALS['xoopsModuleConfig']['max_img_width'], (int)$GLOBALS['xoopsModuleConfig']['max_img_height']);
431
        if ($_FILES['userfile']['error'] > 0) {
432
            switch ($_FILES['userfile']['error']) {
433
                case 1:
434
                    $error_message[] = _MD_NEWBB_MAXUPLOADFILEINI;
435
                    break;
436
                case 2:
437
                    $error_message[] = sprintf(_MD_NEWBB_MAXKB, $forumObject->getVar('attach_maxkb'));
438
                    break;
439
                default:
440
                    $error_message[] = _MD_NEWBB_UPLOAD_ERRNODEF;
441
                    break;
442
            }
443
        } else {
444
            $uploader->setCheckMediaTypeByExt();
445
            $temp = Request::getArray('xoops_upload_file', [], 'POST');
446
            if ($uploader->fetchMedia($temp[0])) {
447
                $prefix = is_object($GLOBALS['xoopsUser']) ? (string)$GLOBALS['xoopsUser']->uid() . '_' : 'newbb_';
448
                $uploader->setPrefix($prefix);
449
                if (!$uploader->upload()) {
450
                    $error_message[] = $error_upload = $uploader->getErrors();
451
                } else {
452
                    if (is_file($uploader->getSavedDestination())) {
453
                        $attachments_tmp[(string)time()] = [
454
                            $uploader->getSavedFileName(),
455
                            $uploader->getMediaName(),
456
                            $uploader->getMediaType()
457
                        ];
458
                    }
459
                }
460
            } else {
461
                $error_message[] = $error_upload = $uploader->getErrors();
462
            }
463
        }
464
    }
465
}
466
467
if (Request::getString('contents_preview', Request::getString('contents_preview', '', 'POST'), 'GET')) {
468
    if (Request::getString('attachments_tmp', '', 'POST')) {
469
        $attachments_tmp = unserialize(base64_decode(Request::getString('attachments_tmp', '', 'POST')));
470
    }
471
472
    $p_subject = $myts->htmlSpecialChars(Request::getString('subject', '', 'POST'));
473
    $dosmiley  = Request::getInt('dosmiley', 0, 'POST');
474
    $dohtml    = Request::getInt('dohtml', 0, 'POST');
475
    $doxcode   = Request::getInt('doxcode', 0, 'POST');
476
    $dobr      = Request::getInt('dobr', 0, 'POST');
477
    $p_message = Request::getString('message', '', 'POST');
478
    $p_message = $myts->previewTarea($p_message, $dohtml, $dosmiley, $doxcode, 1, $dobr);
479
    $p_date    = formatTimestamp(time());
480
    if ($postObject->isNew()) {
481
        if (is_object($GLOBALS['xoopsUser'])) {
482
            $p_name = $GLOBALS['xoopsUser']->getVar('uname');
483
            if (!empty($GLOBALS['xoopsModuleConfig']['show_realname']) && $GLOBALS['xoopsUser']->getVar('name')) {
484
                $p_name = $GLOBALS['xoopsUser']->getVar('name');
485
            }
486
        }
487
    } elseif ($postObject->getVar('uid')) {
488
        $p_name = newbbGetUnameFromId($postObject->getVar('uid'), $GLOBALS['xoopsModuleConfig']['show_realname']);
489
    }
490
    if (empty($p_name)) {
491
        $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);
492
    }
493
494
    $post_preview = [
495
        'subject' => $p_subject,
496
        'meta'    => _MD_NEWBB_BY . ' ' . $p_name . ' ' . _MD_NEWBB_ON . ' ' . $p_date,
497
        'content' => $p_message
498
    ];
499
    $xoopsTpl->assign_by_ref('post_preview', $post_preview);
500
}
501
502
if (Request::getString('contents_upload', null, 'POST') || Request::getString('contents_preview', null, 'POST')
503
    || Request::getString('contents_preview', null, 'GET')
504
    || Request::getString('editor', '', 'POST')) {
505
    $editor        = Request::getString('editor', '', 'POST');
506
    $dosmiley      = Request::getInt('dosmiley', 0, 'POST');
507
    $dohtml        = Request::getInt('dohtml', 0, 'POST');
508
    $doxcode       = Request::getInt('doxcode', 0, 'POST');
509
    $dobr          = Request::getInt('dobr', 0, 'POST');
510
    $subject       = Request::getString('subject', '', 'POST');
511
    $message       = Request::getString('message', '', 'POST');
512
    $poster_name   = Request::getString('poster_name', '', 'POST');
513
    $hidden        = Request::getString('hidden', '', 'POST');
514
    $notify        = Request::getInt('notify', 0, 'POST');
515
    $attachsig     = Request::getInt('attachsig', 0, 'POST');//!empty($_POST['attachsig']) ? 1 : 0;
516
    $isreply       = Request::getInt('isreply', 0, 'POST'); //!empty($_POST['isreply']) ? 1 : 0;
517
    $isedit        = Request::getInt('isedit', 0, 'POST'); //!empty($_POST['isedit']) ? 1 : 0;
518
    $icon          = (Request::getString('icon', '', 'POST')
519
                      && is_file($GLOBALS['xoops']->path('images/subject/' . Request::getString('icon', '', 'POST'))) ? Request::getString('icon', '', 'POST') : '');
520
    $view_require  = Request::getString('view_require', '', 'POST');
521
    $post_karma    = (('require_karma' === $view_require)
522
                      && !Request::getInt('post_karma', 0, 'POST')) ? Request::getInt('post_karma', 0, 'POST') : 0;
523
    $require_reply = ('require_reply' === $view_require) ? 1 : 0;
524
525
    if (!Request::getString('contents_upload', '', 'POST')) {
526
        $contents_preview = 1;
527
    }
528
    $attachments = $postObject->getAttachment();
529
    $xoopsTpl->assign('error_message', implode('<br>', $error_message));
530
531
    include __DIR__ . '/include/form.post.php';
532
}
533
// irmtfan move to footer.php
534
require_once __DIR__ . '/footer.php';
535
include $GLOBALS['xoops']->path('footer.php');
536