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

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

454
                                /** @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...
455
                                rename($newName, $fullPictureName);
456
                            }
457
                            $story->setPicture(basename($destname));
458
                        } else {
459
                            echo _AM_UPLOAD_ERROR . ' ' . $uploader->getErrors();
460
                        }
461
                    } else {
462
                        echo $uploader->getErrors();
463
                    }
464
                }
465
                $story->setPictureinfo($_POST['pictureinfo']);
466
            }
467
        }
468
        $destname = '';
469
470
        $result = $story->store();
471
        if ($result) {
472
            $helper = Helper::getInstance();
473
            if (1 == $helper->getConfig('tags') && \class_exists(\XoopsModules\Tag\TagHandler::class) && xoops_isActiveModule('tag')) {
474
                /** @var \XoopsModules\Tag\TagHandler $tagHandler */
475
                $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag');
476
                $tagHandler->updateByItem($_POST['item_tag'], $story->storyid(), $helper->getDirname(), 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