Passed
Pull Request — master (#41)
by Michael
13:46
created

submit.php (1 issue)

Labels
Severity
1
<?php declare(strict_types=1);
2
/*
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright      {@link https://xoops.org/ XOOPS Project}
14
 * @license        {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @author         XOOPS Development Team
16
 */
17
18
use Xmf\Request;
19
use XoopsModules\News\{
20
    Files,
21
    Helper,
22
    NewsStory,
23
    NewsTopic,
24
    Utility
25
};
26
use XoopsModules\Tag\Helper as TagHelper;
27
28
if (!defined('XOOPS_ROOT_PATH')) {
29
    require_once \dirname(__DIR__, 2) . '/mainfile.php';
30
}
31
require_once __DIR__ . '/header.php';
32
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
33
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.sfiles.php';
34
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php';
35
require_once XOOPS_ROOT_PATH . '/class/uploader.php';
36
require_once XOOPS_ROOT_PATH . '/header.php';
37
38
require_once __DIR__ . '/include/common.php';
39
40
41
/** @var Helper $helper */
42
$helper = Helper::getInstance();
43
$helper->loadLanguage('admin');
44
45
$myts      = \MyTextSanitizer::getInstance();
46
$module_id = $xoopsModule->getVar('mid');
47
$storyid   = 0;
48
49
if (is_object($xoopsUser)) {
50
    $groups = $xoopsUser->getGroups();
51
} else {
52
    $groups = XOOPS_GROUP_ANONYMOUS;
53
}
54
55
/** @var \XoopsGroupPermHandler $grouppermHandler */
56
$grouppermHandler = xoops_getHandler('groupperm');
57
58
if (Request::hasVar('topic_id', 'POST')) {
59
    $perm_itemid = Request::getInt('topic_id', 0, 'POST');
60
} else {
61
    $perm_itemid = 0;
62
}
63
//If no access
64
if (!$grouppermHandler->checkRight('news_submit', $perm_itemid, $groups, $module_id)) {
65
    redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
66
}
67
$op = 'form';
68
69
//If approve privileges
70
$approveprivilege = 0;
71
if (is_object($xoopsUser) && $grouppermHandler->checkRight('news_approve', $perm_itemid, $groups, $module_id)) {
72
    $approveprivilege = 1;
73
}
74
75
if (Request::hasVar('preview', 'POST')) {
76
    $op = 'preview';
77
} elseif (Request::hasVar('post', 'POST')) {
78
    $op = 'post';
79
} elseif (Request::hasVar('op', 'GET') && Request::hasVar('storyid', 'GET')) {
80
    // Verify that the user can edit or delete an article
81
    if ('edit' === $_GET['op'] || 'delete' === $_GET['op']) {
82
        if (1 == $helper->getConfig('authoredit')) {
83
            $tmpstory = new NewsStory(Request::getInt('storyid', 0, 'GET'));
84
            if (is_object($xoopsUser) && $xoopsUser->getVar('uid') != $tmpstory->uid() && !Utility::isAdminGroup()) {
85
                redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
86
            }
87
        } elseif (!Utility::isAdminGroup()) {
88
            // Users can't edit their articles
89
            redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
90
        }
91
    }
92
93
    if ($approveprivilege && 'edit' === $_GET['op']) {
94
        $op      = 'edit';
95
        $storyid = Request::getInt('storyid', 0, 'GET');
96
    } elseif ($approveprivilege && 'delete' === $_GET['op']) {
97
        $op      = 'delete';
98
        $storyid = Request::getInt('storyid', 0, 'GET');
99
    } elseif (Utility::getModuleOption('authoredit') && is_object($xoopsUser) && isset($_GET['storyid'])
100
              && ('edit' === $_GET['op']
101
                  || 'preview' === $_POST['op']
102
                  || 'post' === $_POST['op'])) {
103
        $storyid = 0;
104
        //            $storyid = isset($_GET['storyid']) ? \Xmf\Request::getInt('storyid', 0, 'GET') : \Xmf\Request::getInt('storyid', 0, 'POST');
105
        $storyid = Request::getInt('storyid', 0);
106
        if (!empty($storyid)) {
107
            $tmpstory = new NewsStory($storyid);
108
            if ($tmpstory->uid() == $xoopsUser->getVar('uid')) {
109
                $op = $_GET['op'] ?? $_POST['post'];
110
                unset($tmpstory);
111
                $approveprivilege = 1;
112
            } else {
113
                unset($tmpstory);
114
                if (Utility::isAdminGroup()) {
115
                    $approveprivilege = 1;
116
                } else {
117
                    redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
118
                }
119
            }
120
        }
121
    } elseif (Utility::isAdminGroup()) {
122
        $approveprivilege = 1;
123
    } else {
124
        unset($tmpstory);
125
        redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
126
    }
127
}
128
129
switch ($op) {
130
    case 'edit':
131
        if (!$approveprivilege) {
132
            redirect_header(XOOPS_URL . '/modules/news/index.php', 0, _NOPERM);
133
134
            break;
135
        }
136
        //if ($storyid==0 && isset($_POST['storyid'])) {
137
        //$storyid=(int)($_POST['storyid']);
138
        //}
139
        $story = new NewsStory($storyid);
140
        if (!$grouppermHandler->checkRight('news_view', $story->topicid(), $groups, $module_id)) {
141
            redirect_header(XOOPS_URL . '/modules/news/index.php', 0, _NOPERM);
142
        }
143
        echo "<table width='100%' border='0' cellspacing='1' class='outer'><tr><td class=\"odd\">";
144
        echo '<h4>' . _AM_EDITARTICLE . '</h4>';
145
        $title       = $story->title('Edit');
146
        $subtitle    = $story->subtitle('Edit');
147
        $hometext    = $story->hometext('Edit');
148
        $bodytext    = $story->bodytext('Edit');
149
        $nohtml      = $story->nohtml();
150
        $nosmiley    = $story->nosmiley();
151
        $description = $story->description();
152
        $keywords    = $story->keywords();
153
        $ihome       = $story->ihome();
154
        $newsauthor  = $story->uid();
155
        $topicid     = $story->topicid();
156
        $notifypub   = $story->notifypub();
157
        $picture     = $story->picture();
158
        $pictureinfo = $story->pictureinfo;
159
        $approve     = 0;
160
        $published   = $story->published();
161
        if ((isset($published) && $published > 0) || (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->getVar('mid')))) {
162
            $approve = 1;
163
        }
164
        if (0 != $story->published()) {
165
            $published = $story->published();
166
        }
167
        if (0 != $story->expired()) {
168
            $expired = $story->expired();
169
        } else {
170
            $expired = 0;
171
        }
172
        $type         = $story->type();
173
        $topicdisplay = $story->topicdisplay();
174
        $topicalign   = $story->topicalign(false);
175
        if (Utility::isAdminGroup()) {
176
            require_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.original.php';
177
        } else {
178
            require_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.inc.php';
179
        }
180
        echo '</td></tr></table>';
181
        break;
182
    case 'preview':
183
        $topic_id = Request::getInt('topic_id', 0, 'POST');
184
        $xt       = new NewsTopic($topic_id);
185
        if (Request::hasVar('storyid', 'GET')) {
186
            $storyid = Request::getInt('storyid', 0, 'GET');
187
        } elseif (Request::hasVar('storyid', 'POST')) {
188
            $storyid = Request::getInt('storyid', 0, 'POST');
189
        } else {
190
            $storyid = 0;
191
        }
192
193
        if (!empty($storyid)) {
194
            $story     = new NewsStory($storyid);
195
            $published = $story->published();
196
            $expired   = $story->expired();
197
        } else {
198
            $story     = new NewsStory();
199
            $published = Request::getInt('publish_date', 0, 'POST');
200
            if (!empty($published) && isset($_POST['autodate']) && (int)(1 == $_POST['autodate'])) {
201
                $published = strtotime($published['date']) + $published['time'];
202
            } else {
203
                $published = 0;
204
            }
205
            $expired = Request::getInt('expiry_date', 0, 'POST');
206
            if (!empty($expired) && isset($_POST['autoexpdate']) && (int)(1 == $_POST['autoexpdate'])) {
207
                $expired = strtotime($expired['date']) + $expired['time'];
208
            } else {
209
                $expired = 0;
210
            }
211
        }
212
        $topicid = $topic_id;
213
        if (Request::hasVar('topicdisplay', 'POST')) {
214
            $topicdisplay = Request::getInt('topicdisplay', 0, 'POST');
215
        } else {
216
            $topicdisplay = 1;
217
        }
218
219
        $approve    = Request::getInt('approve', 0, 'POST');
220
        $topicalign = 'R';
221
        if (Request::hasVar('topicalign', 'POST')) {
222
            $topicalign = $_POST['topicalign'];
223
        }
224
        $story->setTitle($_POST['title']);
225
        $story->setSubtitle($_POST['subtitle']);
226
        $story->setHometext($_POST['hometext']);
227
        if ($approveprivilege) {
228
            $story->setTopicdisplay($topicdisplay);
229
            $story->setTopicalign($topicalign);
230
            $story->setBodytext($_POST['bodytext']);
231
            if (Utility::getModuleOption('metadata')) {
232
                $story->setKeywords($_POST['keywords']);
233
                $story->setDescription($_POST['description']);
234
                $story->setIhome(Request::getInt('ihome', 0, 'POST'));
235
            }
236
        } else {
237
            $noname = Request::getInt('noname', 0, 'POST');
238
        }
239
240
        if ($approveprivilege || (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid()))) {
241
            if (Request::hasVar('author', 'POST')) {
242
                $story->setUid(Request::getInt('author', 0, 'POST'));
243
            }
244
        }
245
246
        $notifypub = Request::getInt('notifypub', 0, 'POST');
247
        $nosmiley  = Request::getInt('nosmiley', 0, 'POST');
248
        if (isset($nosmiley) && (0 == $nosmiley || 1 == $nosmiley)) {
249
            $story->setNosmiley($nosmiley);
250
        } else {
251
            $nosmiley = 0;
252
        }
253
        if ($approveprivilege) {
254
            $nohtml = Request::getInt('nohtml', 0, 'POST');
255
            $story->setNohtml($nohtml);
256
        } else {
257
            $story->setNohtml = 1;
258
        }
259
260
        $title    = $story->title('InForm');
261
        $subtitle = $story->subtitle('InForm');
262
        $hometext = $story->hometext('InForm');
263
        if ($approveprivilege) {
264
            $bodytext    = $story->bodytext('InForm');
265
            $ihome       = $story->ihome();
266
            $description = $story->description('E');
267
            $keywords    = $story->keywords('E');
268
        }
269
        $pictureinfo = $story->pictureinfo('InForm');
270
271
        //Display post preview
272
        $newsauthor = $story->uid();
273
        $p_title    = $story->title('Preview');
274
        $p_hometext = $story->hometext('Preview');
275
        if ($approveprivilege) {
276
            $p_bodytext = $story->bodytext('Preview');
277
            $p_hometext .= '<br><br>' . $p_bodytext;
278
        }
279
        $topicalign2 = isset($story->topicalign) ? 'align="' . $story->topicalign() . '"' : '';
280
        $p_hometext  = (('' !== $xt->topic_imgurl()) && $topicdisplay) ? '<img src="assets/images/topics/' . $xt->topic_imgurl() . '" ' . $topicalign2 . ' alt="">' . $p_hometext : $p_hometext;
281
        themecenterposts($p_title, $p_hometext);
282
283
        //Display post edit form
284
        $returnside = Request::getInt('returnside', 0, 'POST');
285
        require_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.inc.php';
286
        break;
287
    case 'post':
288
        $nohtml_db = Request::getInt('nohtml', 1, 'POST');
289
        if (is_object($xoopsUser)) {
290
            $uid = $xoopsUser->getVar('uid');
291
            if ($approveprivilege) {
292
                $nohtml_db = empty($_POST['nohtml']) ? 0 : 1;
293
            }
294
            if (Request::hasVar('author', 'POST') && ($approveprivilege || $xoopsUser->isAdmin($xoopsModule->mid()))) {
295
                $uid = Request::getInt('author', 0, 'POST');
296
            }
297
        } else {
298
            $uid = 0;
299
        }
300
301
        if (Request::hasVar('storyid', 'GET')) {
302
            $storyid = Request::getInt('storyid', 0, 'GET');
303
        } elseif (Request::hasVar('storyid', 'POST')) {
304
            $storyid = Request::getInt('storyid', 0, 'POST');
305
        } else {
306
            $storyid = 0;
307
        }
308
309
        if (empty($storyid)) {
310
            $story    = new NewsStory();
311
            $editmode = false;
312
        } else {
313
            $story    = new NewsStory($storyid);
314
            $editmode = true;
315
        }
316
        $story->setUid($uid);
317
        $story->setTitle($_POST['title']);
318
        $story->setSubtitle($_POST['subtitle']);
319
        $story->setHometext($_POST['hometext']);
320
        $story->setTopicId(Request::getInt('topic_id', 0, 'POST'));
321
        $story->setHostname(xoops_getenv('REMOTE_ADDR'));
322
        $story->setNohtml($nohtml_db);
323
        $nosmiley = Request::getInt('nosmiley', 0, 'POST');
324
        $story->setNosmiley($nosmiley);
325
        $notifypub = Request::getInt('notifypub', 0, 'POST');
326
        $story->setNotifyPub($notifypub);
327
        $story->setType($_POST['type']);
328
329
        if (!empty($_POST['autodate']) && $approveprivilege) {
330
            $publish_date = $_POST['publish_date'];
331
            $pubdate      = strtotime($publish_date['date']) + $publish_date['time'];
332
            //$offset = $xoopsUser -> timezone() - $xoopsConfig['server_TZ'];
333
            //$pubdate = $pubdate - ( $offset * 3600 );
334
            $story->setPublished($pubdate);
335
        }
336
        if (!empty($_POST['autoexpdate']) && $approveprivilege) {
337
            $expiry_date = $_POST['expiry_date'];
338
            $expiry_date = strtotime($expiry_date['date']) + $expiry_date['time'];
339
            $offset      = $xoopsUser->timezone() - $xoopsConfig['server_TZ'];
340
            $expiry_date -= ($offset * 3600);
341
            $story->setExpired($expiry_date);
342
        } else {
343
            $story->setExpired(0);
344
        }
345
346
        if ($approveprivilege) {
347
            if (Utility::getModuleOption('metadata')) {
348
                $story->setDescription($_POST['description']);
349
                $story->setKeywords($_POST['keywords']);
350
            }
351
            $story->setTopicdisplay($_POST['topicdisplay']); // Display Topic Image ? (Yes or No)
352
            $story->setTopicalign($_POST['topicalign']); // Topic Align, 'Right' or 'Left'
353
            $story->setIhome($_POST['ihome']); // Publish in home ? (Yes or No)
354
            if (Request::hasVar('bodytext', 'POST')) {
355
                $story->setBodytext($_POST['bodytext']);
356
            } else {
357
                $story->setBodytext(' ');
358
            }
359
            $approve = Request::getInt('approve', 0, 'POST');
360
361
            if (!$story->published() && $approve) {
362
                $story->setPublished(time());
363
            }
364
            if (!$story->expired()) {
365
                $story->setExpired(0);
366
            }
367
368
            if (!$approve) {
369
                $story->setPublished(0);
370
            }
371
        } elseif (1 == $helper->getConfig('autoapprove')) {
372
            if (empty($storyid)) {
373
                $approve = 1;
374
            } else {
375
                $approve = Request::getInt('approve', 0, 'POST');
376
            }
377
            if ($approve) {
378
                $story->setPublished(time());
379
            } else {
380
                $story->setPublished(0);
381
            }
382
            $story->setExpired(0);
383
            $story->setTopicalign('R');
384
        } else {
385
            $approve = 0;
386
        }
387
        $story->setApproved($approve);
388
389
        if ($approve) {
390
            Utility::updateCache();
391
        }
392
393
        // Increment author's posts count (only if it's a new article)
394
        // First case, it's not an anonyous, the story is approved and it's a new story
395
        if ($uid && $approve && empty($storyid)) {
396
            $tmpuser = new xoopsUser($uid);
397
            /** @var \XoopsMemberHandler $memberHandler */
398
            $memberHandler = xoops_getHandler('member');
399
            $memberHandler->updateUserByField($tmpuser, 'posts', $tmpuser->getVar('posts') + 1);
400
        }
401
402
        // Second case, it's not an anonymous, the story is NOT approved and it's NOT a new story (typical when someone is approving a submited story)
403
        if (is_object($xoopsUser) && $approve && !empty($storyid)) {
404
            $storytemp = new NewsStory($storyid);
405
            if (!$storytemp->published() && $storytemp->uid() > 0) { // the article has been submited but not approved
406
                $tmpuser = new xoopsUser($storytemp->uid());
0 ignored issues
show
$storytemp->uid() of type integer is incompatible with the type array|null expected by parameter $id of xoopsUser::__construct(). ( Ignorable by Annotation )

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

406
                $tmpuser = new xoopsUser(/** @scrutinizer ignore-type */ $storytemp->uid());
Loading history...
407
                /** @var \XoopsMemberHandler $memberHandler */
408
                $memberHandler = xoops_getHandler('member');
409
                $memberHandler->updateUserByField($tmpuser, 'posts', $tmpuser->getVar('posts') + 1);
410
            }
411
            unset($storytemp);
412
        }
413
414
        $allowupload = false;
415
        switch ($helper->getConfig('uploadgroups')) {
416
            case 1: //Submitters and Approvers
417
                $allowupload = true;
418
                break;
419
            case 2: //Approvers only
420
                $allowupload = $approveprivilege;
421
                break;
422
            case 3: //Upload Disabled
423
                $allowupload = false;
424
                break;
425
        }
426
427
        if ($allowupload && isset($_POST['deleteimage']) && 1 == Request::getInt('deleteimage', 0, 'POST')) {
428
            $currentPicture = $story->picture();
429
            if ('' !== xoops_trim($currentPicture)) {
430
                $currentPicture = XOOPS_ROOT_PATH . '/uploads/news/image/' . xoops_trim($story->picture());
431
                if (\is_file($currentPicture) && file_exists($currentPicture)) {
432
                    if (!unlink($currentPicture)) {
433
                        trigger_error('Error, impossible to delete the picture attached to this article');
434
                    }
435
                }
436
            }
437
            $story->setPicture('');
438
            $story->setPictureinfo('');
439
        }
440
441
        if ($allowupload) { // L'image
442
            if (Request::hasVar('xoops_upload_file', 'POST')) {
443
                $fldname = $_FILES[$_POST['xoops_upload_file'][1]];
444
                $fldname = $fldname['name'];
445
                if (xoops_trim('' !== $fldname)) {
446
                    $sfiles         = new Files();
447
                    $destname       = $sfiles->createUploadName(XOOPS_ROOT_PATH . '/uploads/news/image', $fldname);
448
                    $permittedtypes = ['image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png'];
449
                    $uploader       = new \XoopsMediaUploader(XOOPS_ROOT_PATH . '/uploads/news/image', $permittedtypes, $helper->getConfig('maxuploadsize'));
450
                    $uploader->setTargetFileName($destname);
451
                    if ($uploader->fetchMedia($_POST['xoops_upload_file'][1])) {
452
                        if ($uploader->upload()) {
453
                            $fullPictureName = XOOPS_ROOT_PATH . '/uploads/news/image/' . basename($destname);
454
                            $newName         = XOOPS_ROOT_PATH . '/uploads/news/image/redim_' . basename($destname);
455
                            Utility::resizePicture($fullPictureName, $newName, $helper->getConfig('maxwidth'), $helper->getConfig('maxheight'));
456
                            if (file_exists($newName)) {
457
                                @unlink($fullPictureName);
458
                                rename($newName, $fullPictureName);
459
                            }
460
                            $story->setPicture(basename($destname));
461
                        } else {
462
                            echo _AM_UPLOAD_ERROR . ' ' . $uploader->getErrors();
463
                        }
464
                    } else {
465
                        echo $uploader->getErrors();
466
                    }
467
                }
468
                $story->setPictureinfo($_POST['pictureinfo']);
469
            }
470
        }
471
        $destname = '';
472
473
        $result = $story->store();
474
        if ($result) {
475
            $helper = Helper::getInstance();
476
            if (1 == $helper->getConfig('tags') && \class_exists(\XoopsModules\Tag\TagHandler::class) && xoops_isActiveModule('tag')) {
477
                /** @var \XoopsModules\Tag\TagHandler $tagHandler */
478
                $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag');
479
                $tagHandler->updateByItem($_POST['item_tag'], (int)$story->storyid(), $helper->getDirname(), 0);
480
            }
481
482
            if (!$editmode) {
483
                //  Notification
484
                // TODO: modify so that in case of pre-publication, the notification is not made
485
                /** @var \XoopsNotificationHandler $notificationHandler */
486
                $notificationHandler = xoops_getHandler('notification');
487
                $tags                = [];
488
                $tags['STORY_NAME']  = $story->title();
489
                $tags['STORY_URL']   = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/article.php?storyid=' . $story->storyid();
490
                // If notify checkbox is set, add subscription for approve
491
                if ($notifypub && $approve) {
492
                    require_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
493
                    $notificationHandler->subscribe('story', $story->storyid(), 'approve', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE, $xoopsModule->getVar('mid'), $story->uid());
494
                }
495
496
                if (1 == $approve) {
497
                    $notificationHandler->triggerEvent('global', 0, 'new_story', $tags);
498
                    $notificationHandler->triggerEvent('story', $story->storyid(), 'approve', $tags);
499
                    // Added by Lankford on 2007/3/23
500
                    $notificationHandler->triggerEvent('category', $story->topicid(), 'new_story', $tags);
501
                } else {
502
                    $tags['WAITINGSTORIES_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/index.php?op=newarticle';
503
                    $notificationHandler->triggerEvent('global', 0, 'story_submit', $tags);
504
                }
505
            }
506
507
            if ($allowupload) {
508
                // Manage upload(s)
509
                if (Request::hasVar('delupload', 'POST') && count($_POST['delupload']) > 0) {
510
                    foreach ($_POST['delupload'] as $onefile) {
511
                        $sfiles = new Files($onefile);
512
                        $sfiles->delete();
513
                    }
514
                }
515
516
                if (Request::hasVar('xoops_upload_file', 'POST')) {
517
                    $fldname = $_FILES[$_POST['xoops_upload_file'][0]];
518
                    $fldname = $fldname['name'];
519
                    if (xoops_trim('' !== $fldname)) {
520
                        $sfiles   = new Files();
521
                        $destname = $sfiles->createUploadName(XOOPS_UPLOAD_PATH, $fldname);
522
                        /**
523
                         * You can attach files to your news
524
                         */
525
                        $permittedtypes = explode("\n", str_replace("\r", '', Utility::getModuleOption('mimetypes')));
526
                        array_walk($permittedtypes, '\trim');
527
                        $uploader = new \XoopsMediaUploader(XOOPS_UPLOAD_PATH, $permittedtypes, $helper->getConfig('maxuploadsize'));
528
                        $uploader->setTargetFileName($destname);
529
                        if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
530
                            if ($uploader->upload()) {
531
                                $sfiles->setFileRealName($uploader->getMediaName());
532
                                $sfiles->setStoryid($story->storyid());
533
                                $sfiles->setMimetype($sfiles->giveMimetype(XOOPS_UPLOAD_PATH . '/' . $uploader->getMediaName()));
534
                                $sfiles->setDownloadname($destname);
535
                                if (!$sfiles->store()) {
536
                                    echo _AM_UPLOAD_DBERROR_SAVE;
537
                                }
538
                            } else {
539
                                echo _AM_UPLOAD_ERROR . ' ' . $uploader->getErrors();
540
                            }
541
                        } else {
542
                            echo $uploader->getErrors();
543
                        }
544
                    }
545
                }
546
            }
547
        } else {
548
            echo _ERRORS;
549
        }
550
        $returnside = Request::getInt('returnside', 0, 'POST');
551
        if ($returnside) {
552
            redirect_header(XOOPS_URL . '/modules/news/admin/index.php?op=newarticle', 2, _NW_THANKS);
553
        } else {
554
            redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_THANKS);
555
        }
556
        break;
557
    case 'form':
558
        $xt        = new NewsTopic();
559
        $title     = '';
560
        $subtitle  = '';
561
        $hometext  = '';
562
        $noname    = 0;
563
        $nohtml    = 0;
564
        $nosmiley  = 0;
565
        $notifypub = 1;
566
        $topicid   = 0;
567
        if ($approveprivilege) {
568
            $description  = '';
569
            $keywords     = '';
570
            $topicdisplay = 0;
571
            $topicalign   = 'R';
572
            $ihome        = 0;
573
            $bodytext     = '';
574
            $approve      = 0;
575
            $autodate     = '';
576
            $expired      = 0;
577
            $published    = 0;
578
        }
579
        if (1 == $helper->getConfig('autoapprove') || (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->getVar('mid')))) {
580
            $approve = 1;
581
        }
582
        require_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.inc.php';
583
        break;
584
}
585
require_once XOOPS_ROOT_PATH . '/footer.php';
586