Passed
Pull Request — master (#34)
by
unknown
03:48
created

submit.php (4 issues)

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
use XoopsModules\News\Files;
21
use XoopsModules\News\NewsStory;
22
use XoopsModules\News\NewsTopic;
23
use XoopsModules\Tag\Helper;
24
25
if (!defined('XOOPS_ROOT_PATH')) {
26
    require_once \dirname(__DIR__, 2) . '/mainfile.php';
27
}
28
require_once __DIR__ . '/header.php';
29
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
30
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.sfiles.php';
31
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php';
32
require_once XOOPS_ROOT_PATH . '/class/uploader.php';
33
require_once XOOPS_ROOT_PATH . '/header.php';
34
35
/** @var News\Helper $helper */
36
$helper = News\Helper::getInstance();
37
38
/** @var News\Helper $helper */
39
$helper = News\Helper::getInstance();
40
$helper->loadLanguage('admin');
41
42
$myts      = \MyTextSanitizer::getInstance();
43
$module_id = $xoopsModule->getVar('mid');
44
$storyid   = 0;
45
46
if (is_object($xoopsUser)) {
47
    $groups = $xoopsUser->getGroups();
48
} else {
49
    $groups = XOOPS_GROUP_ANONYMOUS;
50
}
51
52
/** @var \XoopsGroupPermHandler $grouppermHandler */
53
$grouppermHandler = xoops_getHandler('groupperm');
54
55
if (Request::hasVar('topic_id', 'POST')) {
56
    $perm_itemid = Request::getInt('topic_id', 0, 'POST');
57
} else {
58
    $perm_itemid = 0;
59
}
60
//If no access
61
if (!$grouppermHandler->checkRight('news_submit', $perm_itemid, $groups, $module_id)) {
62
    redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
63
}
64
$op = 'form';
65
66
//If approve privileges
67
$approveprivilege = 0;
68
if (is_object($xoopsUser) && $grouppermHandler->checkRight('news_approve', $perm_itemid, $groups, $module_id)) {
69
    $approveprivilege = 1;
70
}
71
72
if (Request::hasVar('preview', 'POST')) {
73
    $op = 'preview';
74
} elseif (Request::hasVar('post', 'POST')) {
75
    $op = 'post';
76
} elseif (Request::hasVar('op', 'GET') && Request::hasVar('storyid', 'GET')) {
77
    // Verify that the user can edit or delete an article
78
    if ('edit' === $_GET['op'] || 'delete' === $_GET['op']) {
79
        if (1 == $helper->getConfig('authoredit')) {
80
            $tmpstory = new NewsStory(Request::getInt('storyid', 0, 'GET'));
81
            if (is_object($xoopsUser) && $xoopsUser->getVar('uid') != $tmpstory->uid() && !News\Utility::isAdminGroup()) {
82
                redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
83
            }
84
        } elseif (!News\Utility::isAdminGroup()) {
85
            // Users can't edit their articles
86
            redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
87
        }
88
    }
89
90
    if ($approveprivilege && 'edit' === $_GET['op']) {
91
        $op      = 'edit';
92
        $storyid = Request::getInt('storyid', 0, 'GET');
93
    } elseif ($approveprivilege && 'delete' === $_GET['op']) {
94
        $op      = 'delete';
95
        $storyid = Request::getInt('storyid', 0, 'GET');
96
    } elseif (News\Utility::getModuleOption('authoredit') && is_object($xoopsUser) && isset($_GET['storyid'])
97
              && ('edit' === $_GET['op']
98
                  || 'preview' === $_POST['op']
99
                  || 'post' === $_POST['op'])) {
100
        $storyid = 0;
101
        //            $storyid = isset($_GET['storyid']) ? \Xmf\Request::getInt('storyid', 0, 'GET') : \Xmf\Request::getInt('storyid', 0, 'POST');
102
        $storyid = Request::getInt('storyid', 0);
103
        if (!empty($storyid)) {
104
            $tmpstory = new NewsStory($storyid);
105
            if ($tmpstory->uid() == $xoopsUser->getVar('uid')) {
106
                $op = $_GET['op'] ?? $_POST['post'];
107
                unset($tmpstory);
108
                $approveprivilege = 1;
109
            } else {
110
                unset($tmpstory);
111
                if (!News\Utility::isAdminGroup()) {
112
                    redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
113
                } else {
114
                    $approveprivilege = 1;
115
                }
116
            }
117
        }
118
    } elseif (!News\Utility::isAdminGroup()) {
119
        unset($tmpstory);
120
        redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
121
    } else {
122
        $approveprivilege = 1;
123
    }
124
}
125
126
switch ($op) {
127
    case 'edit':
128
        if (!$approveprivilege) {
129
            redirect_header(XOOPS_URL . '/modules/news/index.php', 0, _NOPERM);
130
131
            break;
132
        }
133
        //if ($storyid==0 && isset($_POST['storyid'])) {
134
        //$storyid=(int)($_POST['storyid']);
135
        //}
136
        $story = new NewsStory($storyid);
137
        if (!$grouppermHandler->checkRight('news_view', $story->topicid(), $groups, $module_id)) {
138
            redirect_header(XOOPS_URL . '/modules/news/index.php', 0, _NOPERM);
139
        }
140
        echo "<table width='100%' border='0' cellspacing='1' class='outer'><tr><td class=\"odd\">";
141
        echo '<h4>' . _AM_EDITARTICLE . '</h4>';
142
        $title       = $story->title('Edit');
143
        $subtitle    = $story->subtitle('Edit');
0 ignored issues
show
The call to XoopsModules\News\NewsStory::subtitle() has too many arguments starting with 'Edit'. ( Ignorable by Annotation )

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

143
        /** @scrutinizer ignore-call */ 
144
        $subtitle    = $story->subtitle('Edit');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
144
        $hometext    = $story->hometext('Edit');
145
        $bodytext    = $story->bodytext('Edit');
146
        $nohtml      = $story->nohtml();
147
        $nosmiley    = $story->nosmiley();
148
        $description = $story->description();
149
        $keywords    = $story->keywords();
150
        $ihome       = $story->ihome();
151
        $newsauthor  = $story->uid();
152
        $topicid     = $story->topicid();
153
        $notifypub   = $story->notifypub();
154
        $picture     = $story->picture();
155
        $pictureinfo = $story->pictureinfo;
156
        $approve     = 0;
157
        $published   = $story->published();
158
        if (isset($published) && $published > 0) {
159
            $approve = 1;
160
        } elseif (1 == $helper->getConfig('moduleAdminApproveChecked') && (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->getVar('mid')))) {
161
            $approve = 1;
162
        }
163
        if (0 != $story->published()) {
164
            $published = $story->published();
165
        }
166
        if (0 != $story->expired()) {
167
            $expired = $story->expired();
168
        } else {
169
            $expired = 0;
170
        }
171
        $type         = $story->type();
172
        $topicdisplay = $story->topicdisplay();
173
        $topicalign   = $story->topicalign(false);
174
        if (!News\Utility::isAdminGroup()) {
175
            require_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.inc.php';
176
        } else {
177
            require_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.original.php';
178
        }
179
        echo '</td></tr></table>';
180
        break;
181
    case 'preview':
182
        $topic_id = Request::getInt('topic_id', 0, 'POST');
183
        $xt       = new NewsTopic($topic_id);
184
        if (Request::hasVar('storyid', 'GET')) {
185
            $storyid = Request::getInt('storyid', 0, 'GET');
186
        } elseif (Request::hasVar('storyid', 'POST')) {
187
            $storyid = Request::getInt('storyid', 0, 'POST');
188
        } else {
189
            $storyid = 0;
190
        }
191
192
        if (!empty($storyid)) {
193
            $story     = new NewsStory($storyid);
194
            $published = $story->published();
195
            $expired   = $story->expired();
196
        } else {
197
            $story     = new NewsStory();
198
            $published = Request::getInt('publish_date', 0, 'POST');
199
            if (!empty($published) && isset($_POST['autodate']) && (int)(1 == $_POST['autodate'])) {
200
                $published = strtotime($published['date']) + $published['time'];
201
            } else {
202
                $published = 0;
203
            }
204
            $expired = Request::getInt('expiry_date', 0, 'POST');
205
            if (!empty($expired) && isset($_POST['autoexpdate']) && (int)(1 == $_POST['autoexpdate'])) {
206
                $expired = strtotime($expired['date']) + $expired['time'];
207
            } else {
208
                $expired = 0;
209
            }
210
        }
211
        $topicid = $topic_id;
212
        if (Request::hasVar('topicdisplay', 'POST')) {
213
            $topicdisplay = Request::getInt('topicdisplay', 0, 'POST');
214
        } else {
215
            $topicdisplay = 1;
216
        }
217
218
        $approve    = Request::getInt('approve', 0, 'POST');
219
        $topicalign = 'R';
220
        if (Request::hasVar('topicalign', 'POST')) {
221
            $topicalign = $_POST['topicalign'];
222
        }
223
        $story->setTitle($_POST['title']);
224
        $story->setSubtitle($_POST['subtitle']);
225
        $story->setHometext($_POST['hometext']);
226
        if ($approveprivilege) {
227
            $story->setTopicdisplay($topicdisplay);
228
            $story->setTopicalign($topicalign);
229
            $story->setBodytext($_POST['bodytext']);
230
            if (News\Utility::getModuleOption('metadata')) {
231
                $story->setKeywords($_POST['keywords']);
232
                $story->setDescription($_POST['description']);
233
                $story->setIhome(Request::getInt('ihome', 0, 'POST'));
234
            }
235
        } else {
236
            $noname = Request::getInt('noname', 0, 'POST');
237
        }
238
239
        if ($approveprivilege || (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid()))) {
240
            if (Request::hasVar('author', 'POST')) {
241
                $story->setUid(Request::getInt('author', 0, 'POST'));
242
            }
243
        }
244
245
        $notifypub = Request::getInt('notifypub', 0, 'POST');
246
        $nosmiley  = Request::getInt('nosmiley', 0, 'POST');
247
        if (isset($nosmiley) && (0 == $nosmiley || 1 == $nosmiley)) {
248
            $story->setNosmiley($nosmiley);
249
        } else {
250
            $nosmiley = 0;
251
        }
252
        if ($approveprivilege) {
253
            $nohtml = Request::getInt('nohtml', 0, 'POST');
254
            $story->setNohtml($nohtml);
255
        } else {
256
            $story->setNohtml = 1;
0 ignored issues
show
The property setNohtml does not seem to exist on XoopsModules\News\NewsStory.
Loading history...
257
        }
258
259
        $title    = $story->title('InForm');
260
        $subtitle = $story->subtitle('InForm');
261
        $hometext = $story->hometext('InForm');
262
        if ($approveprivilege) {
263
            $bodytext    = $story->bodytext('InForm');
264
            $ihome       = $story->ihome();
265
            $description = $story->description('E');
266
            $keywords    = $story->keywords('E');
267
        }
268
        $pictureinfo = $story->pictureinfo('InForm');
0 ignored issues
show
The call to XoopsModules\News\NewsStory::pictureinfo() has too many arguments starting with 'InForm'. ( Ignorable by Annotation )

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

268
        /** @scrutinizer ignore-call */ 
269
        $pictureinfo = $story->pictureinfo('InForm');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
269
270
        //Display post preview
271
        $newsauthor = $story->uid();
272
        $p_title    = $story->title('Preview');
273
        $p_hometext = $story->hometext('Preview');
274
        if ($approveprivilege) {
275
            $p_bodytext = $story->bodytext('Preview');
276
            $p_hometext .= '<br><br>' . $p_bodytext;
277
        }
278
        $topicalign2 = isset($story->topicalign) ? 'align="' . $story->topicalign() . '"' : '';
279
        $p_hometext  = (('' !== $xt->topic_imgurl()) && $topicdisplay) ? '<img src="assets/images/topics/' . $xt->topic_imgurl() . '" ' . $topicalign2 . ' alt="">' . $p_hometext : $p_hometext;
280
        themecenterposts($p_title, $p_hometext);
281
282
        //Display post edit form
283
        $returnside = Request::getInt('returnside', 0, 'POST');
284
        require_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.inc.php';
285
        break;
286
    case 'post':
287
        $nohtml_db = Request::getInt('nohtml', 1, 'POST');
288
        if (is_object($xoopsUser)) {
289
            $uid = $xoopsUser->getVar('uid');
290
            if ($approveprivilege) {
291
                $nohtml_db = empty($_POST['nohtml']) ? 0 : 1;
292
            }
293
            if (Request::hasVar('author', 'POST') && ($approveprivilege || $xoopsUser->isAdmin($xoopsModule->mid()))) {
294
                $uid = Request::getInt('author', 0, 'POST');
295
            }
296
        } else {
297
            $uid = 0;
298
        }
299
300
        if (Request::hasVar('storyid', 'GET')) {
301
            $storyid = Request::getInt('storyid', 0, 'GET');
302
        } elseif (Request::hasVar('storyid', 'POST')) {
303
            $storyid = Request::getInt('storyid', 0, 'POST');
304
        } else {
305
            $storyid = 0;
306
        }
307
308
        if (empty($storyid)) {
309
            $story    = new NewsStory();
310
            $editmode = false;
311
        } else {
312
            $story    = new NewsStory($storyid);
313
            $editmode = true;
314
        }
315
        $story->setUid($uid);
316
        $story->setTitle($_POST['title']);
317
        $story->setSubtitle($_POST['subtitle']);
318
        $story->setHometext($_POST['hometext']);
319
        $story->setTopicId(Request::getInt('topic_id', 0, 'POST'));
320
        $story->setHostname(xoops_getenv('REMOTE_ADDR'));
321
        $story->setNohtml($nohtml_db);
322
        $nosmiley = Request::getInt('nosmiley', 0, 'POST');
323
        $story->setNosmiley($nosmiley);
324
        $notifypub = Request::getInt('notifypub', 0, 'POST');
325
        $story->setNotifyPub($notifypub);
326
        $story->setType($_POST['type']);
327
328
        if (!empty($_POST['autodate']) && $approveprivilege) {
329
            $publish_date = $_POST['publish_date'];
330
            $pubdate      = strtotime($publish_date['date']) + $publish_date['time'];
331
            //$offset = $xoopsUser -> timezone() - $xoopsConfig['server_TZ'];
332
            //$pubdate = $pubdate - ( $offset * 3600 );
333
            $story->setPublished($pubdate);
334
        }
335
        if (!empty($_POST['autoexpdate']) && $approveprivilege) {
336
            $expiry_date = $_POST['expiry_date'];
337
            $expiry_date = strtotime($expiry_date['date']) + $expiry_date['time'];
338
            $offset      = $xoopsUser->timezone() - $xoopsConfig['server_TZ'];
339
            $expiry_date -= ($offset * 3600);
340
            $story->setExpired($expiry_date);
341
        } else {
342
            $story->setExpired(0);
343
        }
344
345
        if ($approveprivilege) {
346
            if (News\Utility::getModuleOption('metadata')) {
347
                $story->setDescription($_POST['description']);
348
                $story->setKeywords($_POST['keywords']);
349
            }
350
            $story->setTopicdisplay($_POST['topicdisplay']); // Display Topic Image ? (Yes or No)
351
            $story->setTopicalign($_POST['topicalign']); // Topic Align, 'Right' or 'Left'
352
            $story->setIhome($_POST['ihome']); // Publish in home ? (Yes or No)
353
            if (Request::hasVar('bodytext', 'POST')) {
354
                $story->setBodytext($_POST['bodytext']);
355
            } else {
356
                $story->setBodytext(' ');
357
            }
358
            $approve = Request::getInt('approve', 0, 'POST');
359
360
            if (!$story->published() && $approve) {
361
                $story->setPublished(time());
362
            }
363
            if (!$story->expired()) {
364
                $story->setExpired(0);
365
            }
366
367
            if (!$approve) {
368
                $story->setPublished(0);
369
            }
370
        } elseif (1 == $helper->getConfig('autoapprove')) {
371
            if (empty($storyid)) {
372
                $approve = 1;
373
            } else {
374
                $approve = Request::getInt('approve', 0, 'POST');
375
            }
376
            if ($approve) {
377
                $story->setPublished(time());
378
            } else {
379
                $story->setPublished(0);
380
            }
381
            $story->setExpired(0);
382
            $story->setTopicalign('R');
383
        } else {
384
            $approve = 0;
385
        }
386
        $story->setApproved($approve);
387
388
        if ($approve) {
389
            News\Utility::updateCache();
390
        }
391
392
        // Increment author's posts count (only if it's a new article)
393
        // First case, it's not an anonyous, the story is approved and it's a new story
394
        if ($uid && $approve && empty($storyid)) {
395
            $tmpuser = new xoopsUser($uid);
396
            /** @var \XoopsMemberHandler $memberHandler */
397
            $memberHandler = xoops_getHandler('member');
398
            $memberHandler->updateUserByField($tmpuser, 'posts', $tmpuser->getVar('posts') + 1);
399
        }
400
401
        // 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)
402
        if (is_object($xoopsUser) && $approve && !empty($storyid)) {
403
            $storytemp = new NewsStory($storyid);
404
            if (!$storytemp->published() && $storytemp->uid() > 0) { // the article has been submited but not approved
405
                $tmpuser = new xoopsUser($storytemp->uid());
406
                /** @var \XoopsMemberHandler $memberHandler */
407
                $memberHandler = xoops_getHandler('member');
408
                $memberHandler->updateUserByField($tmpuser, 'posts', $tmpuser->getVar('posts') + 1);
409
            }
410
            unset($storytemp);
411
        }
412
413
        $allowupload = false;
414
        switch ($helper->getConfig('uploadgroups')) {
415
            case 1: //Submitters and Approvers
416
                $allowupload = true;
417
                break;
418
            case 2: //Approvers only
419
                $allowupload = $approveprivilege;
420
                break;
421
            case 3: //Upload Disabled
422
                $allowupload = false;
423
                break;
424
        }
425
426
        if ($allowupload && isset($_POST['deleteimage']) && 1 == Request::getInt('deleteimage', 0, 'POST')) {
427
            $currentPicture = $story->picture();
428
            if ('' !== xoops_trim($currentPicture)) {
429
                $currentPicture = XOOPS_ROOT_PATH . '/uploads/news/image/' . xoops_trim($story->picture());
430
                if (is_file($currentPicture) && file_exists($currentPicture)) {
431
                    if (!unlink($currentPicture)) {
432
                        trigger_error('Error, impossible to delete the picture attached to this article');
433
                    }
434
                }
435
            }
436
            $story->setPicture('');
437
            $story->setPictureinfo('');
438
        }
439
440
        if ($allowupload) { // L'image
441
            if (Request::hasVar('xoops_upload_file', 'POST')) {
442
                $fldname = $_FILES[$_POST['xoops_upload_file'][1]];
443
                $fldname = $fldname['name'];
444
                if (xoops_trim('' !== $fldname)) {
445
                    $sfiles         = new Files();
446
                    $destname       = $sfiles->createUploadName(XOOPS_ROOT_PATH . '/uploads/news/image', $fldname);
447
                    $permittedtypes = ['image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png'];
448
                    $uploader       = new \XoopsMediaUploader(XOOPS_ROOT_PATH . '/uploads/news/image', $permittedtypes, $helper->getConfig('maxuploadsize'));
449
                    $uploader->setTargetFileName($destname);
450
                    if ($uploader->fetchMedia($_POST['xoops_upload_file'][1])) {
451
                        if ($uploader->upload()) {
452
                            $fullPictureName = XOOPS_ROOT_PATH . '/uploads/news/image/' . basename($destname);
453
                            $newName         = XOOPS_ROOT_PATH . '/uploads/news/image/redim_' . basename($destname);
454
                            News\Utility::resizePicture($fullPictureName, $newName, $helper->getConfig('maxwidth'), $helper->getConfig('maxheight'));
455
                            if (file_exists($newName)) {
456
                                @unlink($fullPictureName);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

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

456
                                /** @scrutinizer ignore-unhandled */ @unlink($fullPictureName);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
457
                                rename($newName, $fullPictureName);
458
                            }
459
                            $story->setPicture(basename($destname));
460
                        } else {
461
                            echo _AM_UPLOAD_ERROR . ' ' . $uploader->getErrors();
462
                        }
463
                    } else {
464
                        echo $uploader->getErrors();
465
                    }
466
                }
467
                $story->setPictureinfo($_POST['pictureinfo']);
468
            }
469
        }
470
        $destname = '';
471
472
        $result = $story->store();
473
        if ($result) {
474
            $helper = Helper::getInstance();
475
            if (1 == $helper->getConfig('tags') && \class_exists(\XoopsModules\Tag\TagHandler::class) && xoops_isActiveModule('tag')) {
476
                /** @var \XoopsModules\Tag\TagHandler $tagHandler */
477
                $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag');
478
                $tagHandler->updateByItem($_POST['item_tag'], $story->storyid(), $helper->getDirname(), 0);
479
            }
480
481
            if (!$editmode) {
482
                //  Notification
483
                // TODO: modify so that in case of pre-publication, the notification is not made
484
                /** @var \XoopsNotificationHandler $notificationHandler */
485
                $notificationHandler = xoops_getHandler('notification');
486
                $tags                = [];
487
                $tags['STORY_NAME']  = $story->title();
488
                $tags['STORY_URL']   = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/article.php?storyid=' . $story->storyid();
489
                // If notify checkbox is set, add subscription for approve
490
                if ($notifypub && $approve) {
491
                    require_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
492
                    $notificationHandler->subscribe('story', $story->storyid(), 'approve', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE, $xoopsModule->getVar('mid'), $story->uid());
493
                }
494
495
                if (1 == $approve) {
496
                    $notificationHandler->triggerEvent('global', 0, 'new_story', $tags);
497
                    $notificationHandler->triggerEvent('story', $story->storyid(), 'approve', $tags);
498
                    // Added by Lankford on 2007/3/23
499
                    $notificationHandler->triggerEvent('category', $story->topicid(), 'new_story', $tags);
500
                } else {
501
                    $tags['WAITINGSTORIES_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/index.php?op=newarticle';
502
                    $notificationHandler->triggerEvent('global', 0, 'story_submit', $tags);
503
                }
504
            }
505
506
            if ($allowupload) {
507
                // Manage upload(s)
508
                if (Request::hasVar('delupload', 'POST') && count($_POST['delupload']) > 0) {
509
                    foreach ($_POST['delupload'] as $onefile) {
510
                        $sfiles = new Files($onefile);
511
                        $sfiles->delete();
512
                    }
513
                }
514
515
                if (Request::hasVar('xoops_upload_file', 'POST')) {
516
                    $fldname = $_FILES[$_POST['xoops_upload_file'][0]];
517
                    $fldname = $fldname['name'];
518
                    if (xoops_trim('' !== $fldname)) {
519
                        $sfiles   = new Files();
520
                        $destname = $sfiles->createUploadName(XOOPS_UPLOAD_PATH, $fldname);
521
                        /**
522
                         * You can attach files to your news
523
                         */
524
                        $permittedtypes = explode("\n", str_replace("\r", '', News\Utility::getModuleOption('mimetypes')));
525
                        array_walk($permittedtypes, '\trim');
526
                        $uploader = new \XoopsMediaUploader(XOOPS_UPLOAD_PATH, $permittedtypes, $helper->getConfig('maxuploadsize'));
527
                        $uploader->setTargetFileName($destname);
528
                        if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
529
                            if ($uploader->upload()) {
530
                                $sfiles->setFileRealName($uploader->getMediaName());
531
                                $sfiles->setStoryid($story->storyid());
532
                                $sfiles->setMimetype($sfiles->giveMimetype(XOOPS_UPLOAD_PATH . '/' . $uploader->getMediaName()));
533
                                $sfiles->setDownloadname($destname);
534
                                if (!$sfiles->store()) {
535
                                    echo _AM_UPLOAD_DBERROR_SAVE;
536
                                }
537
                            } else {
538
                                echo _AM_UPLOAD_ERROR . ' ' . $uploader->getErrors();
539
                            }
540
                        } else {
541
                            echo $uploader->getErrors();
542
                        }
543
                    }
544
                }
545
            }
546
        } else {
547
            echo _ERRORS;
548
        }
549
        $returnside = Request::getInt('returnside', 0, 'POST');
550
        if (!$returnside) {
551
            redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_THANKS);
552
        } else {
553
            redirect_header(XOOPS_URL . '/modules/news/admin/index.php?op=newarticle', 2, _NW_THANKS);
554
        }
555
        break;
556
    case 'form':
557
        $xt        = new NewsTopic();
558
        $title     = '';
559
        $subtitle  = '';
560
        $hometext  = '';
561
        $noname    = 0;
562
        $nohtml    = 0;
563
        $nosmiley  = 0;
564
        $notifypub = 1;
565
        $topicid   = 0;
566
        if ($approveprivilege) {
567
            $description  = '';
568
            $keywords     = '';
569
            $topicdisplay = 0;
570
            $topicalign   = 'R';
571
            $ihome        = 0;
572
            $bodytext     = '';
573
            $approve      = 0;
574
            $autodate     = '';
575
            $expired      = 0;
576
            $published    = 0;
577
        }
578
        if (1 == $helper->getConfig('autoapprove')) {
579
            $approve = 1;
580
        } elseif (1 == $helper->getConfig('moduleAdminApproveChecked') && (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->getVar('mid')))) {
581
            $approve = 1;
582
        }
583
        require_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.inc.php';
584
        break;
585
}
586
require_once XOOPS_ROOT_PATH . '/footer.php';
587