Issues (384)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  Header Injection
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

submit.php (5 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;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Request. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

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

146
        /** @scrutinizer ignore-call */ 
147
        $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...
147
        $hometext    = $story->hometext('Edit');
148
        $bodytext    = $story->bodytext('Edit');
149
        $nohtml      = $story->nohtml();
150
        $nosmiley    = $story->nosmiley();
151
        $description = $story->description();
152
        $keywords    = $story->keywords();
153
        $ihome       = $story->ihome();
154
        $newsauthor  = $story->uid();
155
        $topicid     = $story->topicid();
156
        $notifypub   = $story->notifypub();
157
        $picture     = $story->picture();
158
        $pictureinfo = $story->pictureinfo;
159
        $approve     = 0;
160
        $published   = $story->published();
161
        if (isset($published) && $published > 0) {
162
            $approve = 1;
163
        } elseif (1 == $helper->getConfig('moduleAdminApproveChecked') && (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->getVar('mid')))) {
164
            $approve = 1;
165
        }
166
        if (0 != $story->published()) {
167
            $published = $story->published();
168
        }
169
        if (0 != $story->expired()) {
170
            $expired = $story->expired();
171
        } else {
172
            $expired = 0;
173
        }
174
        $type         = $story->type();
175
        $topicdisplay = $story->topicdisplay();
176
        $topicalign   = $story->topicalign(false);
177
        if (!Utility::isAdminGroup()) {
178
            require_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.inc.php';
179
        } else {
180
            require_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.original.php';
181
        }
182
        echo '</td></tr></table>';
183
        break;
184
    case 'preview':
185
        $topic_id = Request::getInt('topic_id', 0, 'POST');
186
        $xt       = new NewsTopic($topic_id);
187
        if (Request::hasVar('storyid', 'GET')) {
188
            $storyid = Request::getInt('storyid', 0, 'GET');
189
        } elseif (Request::hasVar('storyid', 'POST')) {
190
            $storyid = Request::getInt('storyid', 0, 'POST');
191
        } else {
192
            $storyid = 0;
193
        }
194
195
        if (!empty($storyid)) {
196
            $story     = new NewsStory($storyid);
197
            $published = $story->published();
198
            $expired   = $story->expired();
199
        } else {
200
            $story     = new NewsStory();
201
            $published = Request::getInt('publish_date', 0, 'POST');
202
            if (!empty($published) && isset($_POST['autodate']) && (int)(1 == $_POST['autodate'])) {
203
                $published = strtotime($published['date']) + $published['time'];
204
            } else {
205
                $published = 0;
206
            }
207
            $expired = Request::getInt('expiry_date', 0, 'POST');
208
            if (!empty($expired) && isset($_POST['autoexpdate']) && (int)(1 == $_POST['autoexpdate'])) {
209
                $expired = strtotime($expired['date']) + $expired['time'];
210
            } else {
211
                $expired = 0;
212
            }
213
        }
214
        $topicid = $topic_id;
215
        if (Request::hasVar('topicdisplay', 'POST')) {
216
            $topicdisplay = Request::getInt('topicdisplay', 0, 'POST');
217
        } else {
218
            $topicdisplay = 1;
219
        }
220
221
        $approve    = Request::getInt('approve', 0, 'POST');
222
        $topicalign = 'R';
223
        if (Request::hasVar('topicalign', 'POST')) {
224
            $topicalign = $_POST['topicalign'];
225
        }
226
        $story->setTitle($_POST['title']);
227
        $story->setSubtitle($_POST['subtitle']);
228
        $story->setHometext($_POST['hometext']);
229
        if ($approveprivilege) {
230
            $story->setTopicdisplay($topicdisplay);
231
            $story->setTopicalign($topicalign);
232
            $story->setBodytext($_POST['bodytext']);
233
            if (Utility::getModuleOption('metadata')) {
234
                $story->setKeywords($_POST['keywords']);
235
                $story->setDescription($_POST['description']);
236
                $story->setIhome(Request::getInt('ihome', 0, 'POST'));
237
            }
238
        } else {
239
            $noname = Request::getInt('noname', 0, 'POST');
240
        }
241
242
        if ($approveprivilege || (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid()))) {
243
            if (Request::hasVar('author', 'POST')) {
244
                $story->setUid(Request::getInt('author', 0, 'POST'));
245
            }
246
        }
247
248
        $notifypub = Request::getInt('notifypub', 0, 'POST');
249
        $nosmiley  = Request::getInt('nosmiley', 0, 'POST');
250
        if (isset($nosmiley) && (0 == $nosmiley || 1 == $nosmiley)) {
251
            $story->setNosmiley($nosmiley);
252
        } else {
253
            $nosmiley = 0;
254
        }
255
        if ($approveprivilege) {
256
            $nohtml = Request::getInt('nohtml', 0, 'POST');
257
            $story->setNohtml($nohtml);
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 (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')) {
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
            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;
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
                            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
            $helper = Helper::getInstance();
478
            if (1 == $helper->getConfig('tags') && \class_exists(\XoopsModules\Tag\TagHandler::class) && xoops_isActiveModule('tag')) {
479
                /** @var \XoopsModules\Tag\TagHandler $tagHandler */
480
                $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag');
481
                $tagHandler->updateByItem($_POST['item_tag'], $story->storyid(), $helper->getDirname(), 0);
482
            }
483
484
            if (!$editmode) {
485
                //  Notification
486
                // TODO: modify so that in case of pre-publication, the notification is not made
487
                /** @var \XoopsNotificationHandler $notificationHandler */
488
                $notificationHandler = xoops_getHandler('notification');
489
                $tags                = [];
490
                $tags['STORY_NAME']  = $story->title();
491
                $tags['STORY_URL']   = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/article.php?storyid=' . $story->storyid();
492
                // If notify checkbox is set, add subscription for approve
493
                if ($notifypub && $approve) {
494
                    require_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
495
                    $notificationHandler->subscribe('story', $story->storyid(), 'approve', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE, $xoopsModule->getVar('mid'), $story->uid());
496
                }
497
498
                if (1 == $approve) {
499
                    $notificationHandler->triggerEvent('global', 0, 'new_story', $tags);
500
                    $notificationHandler->triggerEvent('story', $story->storyid(), 'approve', $tags);
501
                    // Added by Lankford on 2007/3/23
502
                    $notificationHandler->triggerEvent('category', $story->topicid(), 'new_story', $tags);
503
                } else {
504
                    $tags['WAITINGSTORIES_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/index.php?op=newarticle';
505
                    $notificationHandler->triggerEvent('global', 0, 'story_submit', $tags);
506
                }
507
            }
508
509
            if ($allowupload) {
510
                // Manage upload(s)
511
                if (Request::hasVar('delupload', 'POST') && count($_POST['delupload']) > 0) {
512
                    foreach ($_POST['delupload'] as $onefile) {
513
                        $sfiles = new Files($onefile);
514
                        $sfiles->delete();
515
                    }
516
                }
517
518
                if (Request::hasVar('xoops_upload_file', 'POST')) {
519
                    $fldname = $_FILES[$_POST['xoops_upload_file'][0]];
520
                    $fldname = $fldname['name'];
521
                    if (xoops_trim('' !== $fldname)) {
522
                        $sfiles   = new Files();
523
                        $destname = $sfiles->createUploadName(XOOPS_UPLOAD_PATH, $fldname);
524
                        /**
525
                         * You can attach files to your news
526
                         */
527
                        $permittedtypes = explode("\n", str_replace("\r", '', Utility::getModuleOption('mimetypes')));
528
                        array_walk($permittedtypes, '\trim');
529
                        $uploader = new \XoopsMediaUploader(XOOPS_UPLOAD_PATH, $permittedtypes, $helper->getConfig('maxuploadsize'));
530
                        $uploader->setTargetFileName($destname);
531
                        if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
532
                            if ($uploader->upload()) {
533
                                $sfiles->setFileRealName($uploader->getMediaName());
534
                                $sfiles->setStoryid($story->storyid());
535
                                $sfiles->setMimetype($sfiles->giveMimetype(XOOPS_UPLOAD_PATH . '/' . $uploader->getMediaName()));
536
                                $sfiles->setDownloadname($destname);
537
                                if (!$sfiles->store()) {
538
                                    echo _AM_UPLOAD_DBERROR_SAVE;
539
                                }
540
                            } else {
541
                                echo _AM_UPLOAD_ERROR . ' ' . $uploader->getErrors();
542
                            }
543
                        } else {
544
                            echo $uploader->getErrors();
545
                        }
546
                    }
547
                }
548
            }
549
        } else {
550
            echo _ERRORS;
551
        }
552
        $returnside = Request::getInt('returnside', 0, 'POST');
553
        if (!$returnside) {
554
            redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_THANKS);
555
        } else {
556
            redirect_header(XOOPS_URL . '/modules/news/admin/index.php?op=newarticle', 2, _NW_THANKS);
557
        }
558
        break;
559
    case 'form':
560
        $xt        = new NewsTopic();
561
        $title     = '';
562
        $subtitle  = '';
563
        $hometext  = '';
564
        $noname    = 0;
565
        $nohtml    = 0;
566
        $nosmiley  = 0;
567
        $notifypub = 1;
568
        $topicid   = 0;
569
        if ($approveprivilege) {
570
            $description  = '';
571
            $keywords     = '';
572
            $topicdisplay = 0;
573
            $topicalign   = 'R';
574
            $ihome        = 0;
575
            $bodytext     = '';
576
            $approve      = 0;
577
            $autodate     = '';
578
            $expired      = 0;
579
            $published    = 0;
580
        }
581
        if (1 == $helper->getConfig('autoapprove')) {
582
            $approve = 1;
583
        } elseif (1 == $helper->getConfig('moduleAdminApproveChecked') && (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->getVar('mid')))) {
584
            $approve = 1;
585
        }
586
        require_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.inc.php';
587
        break;
588
}
589
require_once XOOPS_ROOT_PATH . '/footer.php';
590