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