Passed
Pull Request — master (#21)
by Michael
02:48
created

submit.php (4 issues)

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

145
        /** @scrutinizer ignore-call */ 
146
        $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...
146
        $hometext    = $story->hometext('Edit');
147
        $bodytext    = $story->bodytext('Edit');
148
        $nohtml      = $story->nohtml();
149
        $nosmiley    = $story->nosmiley();
150
        $description = $story->description();
151
        $keywords    = $story->keywords();
152
        $ihome       = $story->ihome();
153
        $newsauthor  = $story->uid();
154
        $topicid     = $story->topicid();
155
        $notifypub   = $story->notifypub();
156
        $picture     = $story->picture();
157
        $pictureinfo = $story->pictureinfo;
158
        $approve     = 0;
159
        $published   = $story->published();
160
        if (isset($published) && $published > 0) {
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
            if (!isset($_POST['approve'])) {
256
                $approve = 0;
257
            }
258
        } else {
259
            $story->setNohtml = 1;
0 ignored issues
show
The property setNohtml does not seem to exist on XoopsModules\News\NewsStory.
Loading history...
260
        }
261
262
        $title    = $story->title('InForm');
263
        $subtitle = $story->subtitle('InForm');
264
        $hometext = $story->hometext('InForm');
265
        if ($approveprivilege) {
266
            $bodytext    = $story->bodytext('InForm');
267
            $ihome       = $story->ihome();
268
            $description = $story->description('E');
269
            $keywords    = $story->keywords('E');
270
        }
271
        $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

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

459
                                /** @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...
460
                                rename($newName, $fullPictureName);
461
                            }
462
                            $story->setPicture(basename($destname));
463
                        } else {
464
                            echo _AM_UPLOAD_ERROR . ' ' . $uploader->getErrors();
465
                        }
466
                    } else {
467
                        echo $uploader->getErrors();
468
                    }
469
                }
470
                $story->setPictureinfo($_POST['pictureinfo']);
471
            }
472
        }
473
        $destname = '';
474
475
        $result = $story->store();
476
        if ($result) {
477
            if (xoops_isActiveModule('tag') && News\Utility::getModuleOption('tags')) {
478
                $tagHandler = Helper::getInstance()->getHandler('Tag');
479
                $tagHandler->updateByItem($_POST['item_tag'], $story->storyid(), $xoopsModule->getVar('dirname'), 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", '', News\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/index.php', 2, _NW_THANKS);
553
        } else {
554
            redirect_header(XOOPS_URL . '/modules/news/admin/index.php?op=newarticle', 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')) {
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